-
In the theming docs there's a hint of a In my case, the design has a set of base tokens ("primary background", "secondary background", "accent background", etc.) and then components are styled according to these. However, if you simply define the stylesheet as "secondary buttons have a background of const tokens = {
colors: { background: { primary: …, secondary: … }, … },
…,
} as const;
const theme = {
tokens,
components: {
button: { secondary: { background: tokens.colors.background.secondary }, … },
…,
},
} as const; However, if I realise this has some conceptual overlap with variants, but variant styles are not defined near the theme, and can't be directly modified by My initial thought on this was to provide some kind of factory for component tokens: function updateComponents(name, componentsFn) {
UnistylesRuntime.updateTheme(name, (current) => {
return {...current, merge({}, current.components, componentsFn(current.tokens))};
});
} Do you have any advice or suggestions? Edit: Some other theme systems allow the use of special identifiers like |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hello 👋
I would simply create a base button component, and then use variants to change desired style keys. You can also define anything in the const stylesheet = createStyleSheet(theme => ({
baseButton: {
// variants
variants: {},
// or usage with theme
...theme.components.button
}
})) or mix with dynamic function: const stylesheet = createStyleSheet(theme => ({
baseButton: (someExternalParamsFromJSX) => ({
...theme.components.button(someExternalParamsFromJSX)
})
})) I would need some example to see what you're trying to achieve |
Beta Was this translation helpful? Give feedback.
Oh then that's easy 😎
Define variant in your theme:
component: