Is a withClasses helper function a good idea ...or maybe not? (for React) #130
Replies: 2 comments 1 reply
-
This is a stylistic thing that some people prefer. I think the culmination of this idea is something like the Stitches API where you can define an entire component interface through config. I actually experimented with this idea before which you can see here. Ideally you would also create the component and the styles in the same file. Using our recipe system (how Sprinkles works) you could make something like the following on top of vanilla-extract. // Heading.css.ts
import { styled } from 'some-library'
export const Heading = styled('h1', {
fontSize: '24px',
variants: {
color: {
violet: {
color: 'blueviolet',
},
gray: {
color: 'gainsboro',
},
},
},
}) // App.tsx
import { Heading } from './Heading.css';
const Example2 = () => <Heading color="violet">My example</Heading> |
Beta Was this translation helpful? Give feedback.
-
After playing with a proper design system like Seek's Braid Design System (soon to be based on vanilla-extract) I can see this idea fades into insignificance. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Okay so this really is just throwing out something I've been playing with (not strictly related to vanilla-extract).
Do people think this is good, bad or ugly?
Instead of...
...I've been playing with a
withClasses
helper function to let me write...I appreciate this is just a cosmetic thing but I kind of like the cleaner look of
Example2
.Here is the code for
withClasses
which seems to work fine with intrinsic components (likediv
) as well as custom components...Does this already exist? Any downside? Any suggestions? All comments are welcome.
Beta Was this translation helpful? Give feedback.
All reactions