🎯
완전한 타입 추론
variant 키와 값, 그리고 조합까지 TypeScript가 자동으로 추론해요. 캐스팅이나 `any`가 필요 없어요.
반복적인 css() 호출 없이, 여러 variant를 가진 컴포넌트 스타일을 깔끔하게 정의해요.
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>;
}