Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

aesthetic-react

milesj4.2kMIT2.2.1TypeScript support: included

React hooks, composers, and more for styling components with Aesthetic.

aesthetic, react, styles, hook, hoc, composer

readme

Aesthetic via React

Build Status npm version npm deps

Style React components with hooks or HOCs, using the powerful Aesthetic library.

import React from 'react';
import { useStyles } from 'aesthetic-react';

export type Props = {
  children: React.ReactNode;
};

export default function Button({ children }: Props) {
  const [styles, cx] = useStyles(({ unit }) => ({
    button: {
      textAlign: 'center',
      display: 'inline-block',
      padding: unit,
    },
  }));

  return (
    <button type="button" className={cx(styles.button)}>
      {children}
    </button>
  );
}

Requirements

  • React 16.6+

Installation

yarn add aesthetic aesthetic-react react
// Or
npm install aesthetic aesthetic-react react

Documentation

https://milesj.gitbook.io/aesthetic/integrations/react

changelog

2.2.1 - 2020-04-07

🛠 Internals

  • Updated useStyles to render styles immediately when testing.

2.2.0 - 2020-04-06

🚀 Updates

  • useStyles will now cache the style sheet to reduce createStyleSheet calls.

2.1.0 - 2020-01-26

🚀 Updates

  • Migrated to Rollup for a smaller filesize.

📦 Dependencies

  • Updated all to latest.
  • Fixed aesthetic peer dependency pointing to the wrong version.

2.0.1 - 2019-12-19

⚙️ Types

  • Fixed an issue with neverization where deeply nested objects cannot be typed correctly, and would error with "Type instantiation is excessively deep and possibly infinite.".

2.0.0 - 2019-12-19

💥 Breaking

  • Rewritten to support the core 5.0 changes.
  • Hooks and HOCs are no longer factories and can be used as-is when imported.
    • useStylesFactory -> useStyles
    • useThemeFactory -> useTheme
    • withStylesFactory -> withStyles
    • withThemeFactory -> withTheme
  • Removed the aesthetic prop from DirectionProvider and ThemeProvider.
  • [TS] The StyledComponent type no longer accepts a theme generic.

1.1.3 - 2019-09-23

⚙️ Types

  • Updated React.Ref to use any instead of unknown.

1.1.2 - 2019-09-15

📦 Dependencies

  • Updated all to latest.

⚙️ Types

  • Refine types and replace any with unknown.

1.1.1 - 2019-07-24

🐞 Fixes

  • [TS] Updated StyledComponent to extend from React.memos NamedExoticComponent instead of FunctionComponent.

1.1.0 - 2019-07-12

🚀 Updates

  • Wrapped withStyles function component with React.memo for performance gains (this mimics the previous pure functionality).

1.0.0 - 2019-07-07

🎉 Release

  • Initial release!

💥 Breaking

  • Updated react requirement to v16.6.
  • Updated withStyles HOC to receive the CSS transformer function as a cx prop.
  • Updated withStyles and withTheme HOCs to internally use function components with hooks instead of class components.
  • [TS] Renamed the WithStylesProps interface to WithStylesWrappedProps.
  • [TS] Renamed the WithThemeProps interface to WithThemeWrappedProps.

🚀 Updates

  • Added a cxPropName option to withStyles.
  • Added DirectionContext and DirectionProvider to support RTL.
  • Added ThemeContext and ThemeProvider to support regional themes.
  • Updated useStyles and withStyles to support RTL.

🛠 Internals

  • Moved some @types dependencies to development only.
  • Updated some @types dependencies to use * version.
  • Updated useStyles and withStyles to consume DirectionProvider and ThemeProvider.
  • Updated useTheme and withTheme to consume ThemeProvider.