跳至正文
Wener Notes

TWC

约 1 分钟阅读
    • MIT, TS
    • reusable React + Tailwind CSS components

cva

TSX
import { twc, TwcComponentProps } from 'react-twc';
import { cva } from 'class-variance-authority';

const button = cva('font-semibold border border-blue-500 rounded', {
  variants: {
    $intent: {
      primary: 'bg-blue-500 text-white',
      secondary: 'bg-white text-gray-800',
    },
  },
  defaultVariants: {
    $intent: 'primary',
  },
});

type ButtonProps = TwcComponentProps<'button'> & VariantProps<typeof button>;

const Button = twc.button<ButtonProps>(({ $intent }) => button({ $intent }));

export default () => (
  <div>
    <Button>Primary button (default)</Button>
    <Button $intent='primary'>Primary button</Button>
    <Button $intent='secondary'>Secondary button</Button>
  </div>
);

关联信息

反向链接、本文链接的其他页面和外部资料。

参考资料

GitHub1 条
最近更新commit 3124beb编辑