Skip to content

emotion-variantsEmotion을 위한 Type-safe variant API

반복적인 css() 호출 없이, 여러 variant를 가진 컴포넌트 스타일을 깔끔하게 정의해요.

emotion-variants
tsx
import { ev } from 'emotion-variants';

const button = ev({
  base: {
    padding: '10px 20px',
    borderRadius: '8px',
    cursor: 'pointer',
  },
  variants: {
    size: {
      small: {
        fontSize: '12px',
      },
      large: {
        fontSize: '16px',
      },
    },
    color: {
      primary: {
        background: '#d36ac2',
        color: 'white',
      },
      secondary: {
        background: '#6c757d',
        color: 'white',
      },
    },
  },
  defaultVariants: {
    size: 'small',
    color: 'primary',
  },
});

type ButtonProps = NonNullable<Parameters<typeof button>[0]> & {
  children: React.ReactNode;
};

function Button({ size, color, children }: ButtonProps) {
  return <button css={button({ size, color })}>{children}</button>;
}

MIT 라이선스에 따라 배포돼요.