Tailwind-variants #822
Replies: 2 comments 4 replies
-
No but keen on starting to think about this. I'm unsure how TypeScript would work with this integration, so that's an area that needs some thought. But perhaps the tw import could do a simple conversion that passes no config: import tw from 'twin.macro';
const Button = tw.button`block`;
<Button>Click me</Button>
// ↓ ↓ ↓ ↓ ↓ ↓
import { tv } from 'tailwind-variants';
const button = tv({ base: "block" });
<button className={button()}>Click me</button> And the tw prop would be similar: import 'twin.macro';
<button tw="block">Click me</Button>
// ↓ ↓ ↓ ↓ ↓ ↓
import { tv } from 'tailwind-variants';
const button = tv({ base: "block" });
<button className={button()}>Click me</button> The styled import could allow the full tailwind-variants component config: import { styled } from 'twin.macro';
const Button = styled.button({
base: "...",
variants: {...},
compoundVariants: [...],
defaultVariants: {...}
});
<Button data={{ size: 'sm', color: 'secondary' }}>Click me</Button> // < Unsure of calling this prop "data"
// ↓ ↓ ↓ ↓ ↓ ↓
import { tv } from 'tailwind-variants';
const button = tv({
base: "...",
variants: {...},
compoundVariants: [...],
defaultVariants: {...}
});
<button className={button({ size: 'sm', color: 'secondary' })}>Click me</button> And the css prop syntax could look like you're passing the config into the css prop as an argument: import { styled } from 'twin.macro';
const config = ({
base: "...",
variants: {...},
compoundVariants: [...],
defaultVariants: {...}
});
<button css={[{ size: 'sm', color: 'secondary' }, config]}>Click me</button>
// ↓ ↓ ↓ ↓ ↓ ↓
import { tv } from 'tailwind-variants';
const button = tv({
base: "...",
variants: {...},
compoundVariants: [...],
defaultVariants: {...}
});
<button className={button({ size: 'sm', color: 'secondary' })}>Click me</button> It would be pretty crazy if twin supported the slot syntax like this: import { styled } from 'twin.macro';
const Card = styled({
slots: {
base: "block",
small: "text-sm"
},
});
<Card.figure slot="base">...</Card.figure>
<Card.div slot="small" />...</Card.div>
// Could alternatively use an as prop, eg: `<Card as="div" slot="small" />`
// ↓ ↓ ↓ ↓ ↓ ↓
import { tv } from "tailwind-variants";
const card = tv({
slots: {
base: "block",
small: "text-sm"
},
});
const { base, small } = card();
<figure className={base()}>...</figure>
<div className={small()}>...</div> |
Beta Was this translation helpful? Give feedback.
-
@ben-rogerson Thank you for responding, it would be truly amazing if you could pass slots directly to the export. Do you think this might be possible soon? If there were a way to place 'tv' just like you put 'tw' inside the code, using ${tw``}. I believe there must be some alternative or way to do it. |
Beta Was this translation helpful? Give feedback.
-
Any way to use tailwind-variants?
https://www.tailwind-variants.org/docs/introduction
Beta Was this translation helpful? Give feedback.
All reactions