Replies: 1 comment 1 reply
-
Thank you for the suggestion! For the button with multiple sizes and schemes, it depends. I would separate them by what feels easier to understand rather than using conditionals that take longer time to "get". e.g I would separate them by colorschemes classnames composed into variables, and then nest them into a base button classnames and export more general usages from these. // base button styles that does not include the color schemes or sizes
const baseStyles = classnames();
// color scheme stylings/classnames
const dangerButtonStyles = classnames("bg-red-500", "hover:bg-red-300", "focus:bg-red-700");
const primaryButtonStyles = .........
..........
// sizing
const smallSizeButtonStyles = classnames("p-2",...);
const normalSizeButtonStyles = classnames("p-4",...);
const largeSizeButtonStyles = classnames("p-8",...);
// Now we could mix and match between these styles as we like
const largeDangerButton = classnames(baseStyles, dangerButtonStyles, largeSizeButtonStyles);
const normalPrimaryButton = classnames(baseStyles, primaryButtonStyles, normalSizeButtonStyles); depending on your use case, it would be more complex of course |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey there!
The title says it all.
The React example in the README is already great, but isn't very complex in terms of conditional logic.
Do you personally have some code that you like to use as a referrence / that you learned a lot from?
What are your personal best practices for complex use cases?
As an example: A buy button that has several color schemes each with different hover and addedToCart states, should change it's sizing completely if used in different places, ....
Would you go for an object with the 6 color schemes and then somehow nest the conditional logic within the different styles? Would you separate size, layout and color classNames?
What do you think about adding additional examples to the repo in general?
Beta Was this translation helpful? Give feedback.
All reactions