-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change themes issue #11668
Comments
Hi @cosmin-z! What version of Carbon are you looking to work with? This will change between v10 and v11 so wanted to make sure I was giving you the correct guidance. For v11, a custom theme will look like: @use '@carbon/styles/scss/theme' with (
$theme: (
background: #000000,
// ...
),
);
@use '@carbon/styles'; Or, if you're using React, it should be: @use '@carbon/react/scss/theme' with (
$theme: (
background: #000000,
// ...
),
);
@use '@carbon/react'; |
Hi @joshblack, I tried your suggestion (my carbon version is v11) but it doesn't work.
The output of the sass doesn't contain any kind of value reported in the variable $theme. Did I do something wrong? thanks for you help. |
@cosmin-z I'm sorry that you're still running into issues! It could be due to mixing and matching packages. If you're on v11, you should be able to use only Based on your example, does this work? @use '../../node_modules/@carbon/styles/scss/theme' with (
$theme: (
background: #ff0000,
button-primary: #0f62fe,
button-primary-active: #002d9c,
button-primary-hover: #0353e9,
button-secondary: #61e59c,
button-secondary-active: #61e59c,
button-secondary-hover: #61e59c,
button-tertiary: #0f62fe,
button-tertiary-active: #002d9c,
button-tertiary-hover: #0353e9,
),
);
@use '../../node_modules/@carbon/styles';
@use '../../node_modules/@carbon/styles/scss/grid/flexbox'; |
button-primary coverthemes.scss @use '@carbon/react';
@use '@carbon/layout';
@use '@carbon/type';
@use "@carbon/themes/scss/utilities";
$theme--diy01: (
// Button
button-primary: #3f51b5,
button-primary-active: #5c6bc0,
button-primary-hover: #5c6bc0
)
$theme--diy01: utilities.merge(
$theme--diy01,
layout.$spacing,
layout.$fluid-spacing,
type.$tokens
);
index.scss [data-carbon-theme="diy"] {
@include theme(themes.$$theme--diy01);
} |
@joshblack Why can't the color of the button be overridden by the theme |
hi @joshblack
I try it, but the button token default color not changed. https://github.com/carbon-design-system/carbon/blob/main/packages/styles/docs/sass.md#theme
|
I have the same issue. The theme customization is working fine on the generated CSS variables, but the custom tokens are all overwritten by the standard tokens. Any thoughts? |
I am experiencing a similar problem. For the purpose of this example I am trying to style a button so it has background-color: red;
border-radius: 20px; Styling from
|
Thanks @mvisintin, for the detailed explanation. I'm wondering where you learned about the However, since I defined a custom theme for my CDS application, it seems that the /vars customization is working, while the /tokens are not having any effect. On your CodeSandbox example, it's working just fine. I prepared a CodeSandbox example with a full custom theme applied (with https://codesandbox.io/s/cds-custom-theme-issue-forked-wi7m6s You can notice how My question at this point is how we should apply custom themes. Globally and using |
After looking at this more closely, I was able to override component tokens by adding them to the theme via the @use '@carbon/react/scss/themes';
@use '@carbon/react/scss/theme';
@use '@carbon/react/scss/components/button/tokens' as button-tokens;
@use '@carbon/themes/scss/utilities';
@use '@carbon/react/scss/components/button';
$button-token-overrides: (
// Button
button-primary: #fe0,
button-primary-active: #fe0,
button-primary-hover: #fe0
);
$button-tokens: utilities.merge(
button-tokens.$button-tokens,
$button-token-overrides
);
@include theme.add-component-tokens($button-tokens);
:root {
@include theme.theme();
} This also works if you choose to include all styles instead of only a single component @use '@carbon/react/scss/themes';
@use '@carbon/react/scss/theme';
@use '@carbon/react/scss/components/button/tokens' as button-tokens;
@use '@carbon/themes/scss/utilities';
- @use '@carbon/react/scss/components/button';
+ @use '@carbon/react';
$button-token-overrides: (
// Button
button-primary: #fe0,
button-primary-active: #fe0,
button-primary-hover: #fe0
);
$button-tokens: utilities.merge(
button-tokens.$button-tokens,
$button-token-overrides
);
@include theme.add-component-tokens($button-tokens);
:root {
@include theme.theme();
} Note: this only applies to components that use component tokens (Tag, Notification, and Button). All other tokens should be able to be overridden via module configuration using @use '@carbon/react/scss/theme' with (
$theme: (
text-on-color: #fe0,
)
);
@use '@carbon/react'; All of the above examples only override the given token for a single theme. If you want to override each theme, you'll have to express a value for each theme just as the source does. @use '@carbon/react/scss/themes';
@use '@carbon/react/scss/theme';
@use '@carbon/react/scss/components/button/tokens' as button-tokens;
@use '@carbon/themes/scss/utilities';
@use '@carbon/react/scss/components/button';
$button-token-overrides: (
// Button
button-primary:
(
fallback: #3f51b5,
values: (
(
theme: themes.$white,
value: #3f51b5,
),
(
theme: themes.$g10,
value: #3f51b5,
),
(
theme: themes.$g90,
value: #3f51b5,
),
(
theme: themes.$g100,
value: #3f51b5,
),
),
),
button-primary-active: (...),
button-primary-hover: (...)
);
$button-tokens: utilities.merge(
button-tokens.$button-tokens,
$button-token-overrides
);
@include theme.add-component-tokens($button-tokens);
:root {
@include theme.theme();
}
.g10 {
@include theme.theme(themes.$g10);
}
.g90 {
@include theme.theme(themes.$g90);
}
.g100 {
@include theme.theme(themes.$g100);
} We'll work on getting this all documented and the old examples cleaned up. |
Question for Carbon
I'm trying to create a custom themes, based on the documentation https://carbondesignsystem.com/guidelines/themes/overview, I've created a mixin file:
@mixin my-theme {
$theme--white: (
// Background
background: #ff0000,
background-active: #ff0000,
background-hover: #ff0000,
background-selected: #ff0000,
background-selected-hover: #ff0000,
background-inverse: #393939,
background-inverse-hover: #4c4c4c,
background-brand: #0f62fe,
.....
.....)
}
and after that I imported it into my scss file:
@use '../../node_modules/@carbon/styles';
@use '../../node_modules/@carbon/grid';
@use "myTheme";
@include myTheme.my-theme();
@import '../../node_modules/@carbon/themes/scss/themes';
@include grid.flex-grid();
@import '../../node_modules/carbon-components/scss/globals/scss/styles.scss';
but it doesn't work, I don't understand what I'm doing wrong.
Thanks for the help.
Code of Conduct
The text was updated successfully, but these errors were encountered: