Carbon multiple custom themes help #12839
-
Say you have an app with multiple custom themes 20-30 (basically a separate skin for each client)). What approach one should take when using carbon? Any advice is welcome! Thx |
Beta Was this translation helpful? Give feedback.
Answered by
tay1orjones
Dec 13, 2022
Replies: 1 comment 2 replies
-
Interesting question! I don't think we've directly thought about the use case of that many themes being emitted. One option that might work in this case is to define each theme and then emit each one using the @use '@carbon/react';
// Full token list: https://github.com/carbon-design-system/carbon/blob/main/packages/themes/docs/sass.md#api
$defaultTheme0: (background: rebeccapurple, background-active: green, ... );
$anotherTheme1: (background: rebeccapurple, background-active: yellow, ... );
$anotherTheme2: (background: rebeccapurple, background-active: red, ... );
$anotherTheme3: (background: rebeccapurple, background-active: blue, ... );
// emit the default to the root
:root {
@include react.theme($defaultTheme0);
}
// Scope additional themes to different selectors.
// Switch out these data attributes at runtime on the `html` element
// and the theme should switch to the new values.
[data-theme='theme1'] {
@include react.theme($anotherTheme1);
}
[data-theme='theme2'] {
@include react.theme($anotherTheme2);
}
[data-theme='theme3'] {
@include react.theme($anotherTheme3);
} |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
tay1orjones
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting question! I don't think we've directly thought about the use case of that many themes being emitted.
One option that might work in this case is to define each theme and then emit each one using the
theme()
mixin. This way you can scope each theme to a selector you can switch out at runtime.