How should the code layout be for multiple variants? #439
-
// Button variant styles
export const buttonVariant = {
// Solid variant
solid: stylex.create({
primary: {
backgroundColor: 'red',
},
secondary: {
backgroundColor: 'purple',
},
}),
// Outline variant
outline: stylex.create({
primary: {
border: '1px solid blue',
},
secondary: {},
}),
// Light variant
light: stylex.create({
primary: {},
secondary: {},
}),
};export const Button = ({
children,
variant = 'solid',
color = 'primary',
}: buttonProps) => {
return (
<button
{...stylex.props(buttonBaseStyle.base, buttonVariant[variant][color])}
>
{children}
</button>
);}; Is this the right way to use it? Does it make sense to call a nested create function like this? Is there a better way to use it? |
Beta Was this translation helpful? Give feedback.
Answered by
nmn
Feb 10, 2024
Replies: 1 comment 6 replies
-
No. This is not allowed. Create multiple top-level variables instead named |
Beta Was this translation helpful? Give feedback.
6 replies
Answer selected by
selcukgiray
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No. This is not allowed. Create multiple top-level variables instead named
buttonVariant,buttonColoretc.