@morfeo/react
TypeScript icon, indicating that this package has built-in type declarations

0.9.3 • Public • Published

@morfeo/react

Morfeo logo

@morfeo/react is part of the @morfeo eco-system, a set of framework-agnostic tools that help you to create beautiful design systems for your web and mobile apps.


Documentation | API | Contributing | Discord


Installation

# npm
npm i @morfeo/react

# yarn
yarn add @morfeo/react

@morfeo/react re-expose @morfeo/hooks and @morfeo/web, we suggest you to read their documentations.

@morfeo/react re-expose @morfeo/hooks and @morfeo/web, we suggest you to read their documentations.

In addition to @morfeo/hooks, this package add 2 other hooks:

These hooks are similar to useStyles and useStyle of @morfeo/hooks, but instead of returning a css object they return a class (or a set of classes) to apply to the component; they are needed because with inline styles we cannot handle media queries or pseudo classes:

function Button() {
  const className = useClassName({
    p: { lg: 'm', sm: 's' }, // <--- Unhandled by useStyle(s)
    bg: 'primary',
    '&:hover': {
      opacity: 'light', // <--- Unhandled by useStyle(s)
    },
  });

  return <button className={className}>Click me</button>;
}

useClassNames

function useClassNames<Key extends string>(
  styles: Record<Key, Style>,
): Record<Key, string>;

Example

function Button() {
  const classes = useClassNames({
    container: {
      px: 'm',
    },
    button: {
      p: { lg: 'm', sm: 's' },
      bg: 'primary',
      '&:hover': {
        opacity: 'light',
      },
    },
  });

  return (
    <div className={classes.container}>
      <button className={classes.button}>Click me</button>
    </div>
  );
}

useClassName

function useClassName(style: Style): string;

Example

function Button() {
  const className = useClassName({
    p: { lg: 'm', sm: 's' },
    bg: 'primary',
    '&:hover': {
      opacity: 'light',
    },
  });

  return <button className={className}>Click me</button>;
}

Package Sidebar

Install

npm i @morfeo/react

Homepage

morfeo.dev

Weekly Downloads

1

Version

0.9.3

License

MIT

Unpacked Size

27.6 kB

Total Files

21

Last publish

Collaborators

  • maurohertz