question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[carbon-components]: component tokens.scss files import CSS reset and base styles

See original GitHub issue

What package(s) are you using?

  • carbon-components
  • carbon-components-react

Detailed description

Describe in detail the issue you’re having.

We are trying to create a global theme file (containing multiple themes) that can be used across independent microservices. Ideally, the theme file should only contain CSS variables that can be consumed by any microservice without altering their base (h1, p, img) styles.

Our approach to creating such a theme file:

// theme.scss
@import 'carbon-components/scss/globals/scss/feature-flags';
$feature-flags: map-merge($feature-flags, ('enable-css-custom-properties': true));

@import '@carbon/themes/scss/themes';
@import 'carbon-components/scss/globals/scss/import-once';

// components that emit tokens
@import 'carbon-components/scss/components/tags/tokens'; // <--- imports reset and base styles
@import 'carbon-components/scss/components/notification/tokens'; // <--- imports reset and base styles

@include exports('theme') {
  :root {
    @include carbon--theme($carbon--theme--g10, true) {
      @include emit-component-tokens($tag-colors);
      @include emit-component-tokens($notification-colors);
    }
  }

  body.dark-theme {
    @include carbon--theme($carbon--theme--g100, true) {
      @include emit-component-tokens($tag-colors);
      @include emit-component-tokens($notification-colors);
    }
  }
}

Unfortunately, the component imports (e.g. carbon-components/scss/components/tags/tokens, carbon-components/scss/components/notification/tokens, etc) also include CSS reset and base styles.

So the resulting CSS will look like this:

@charset "UTF-8";
html,
body,
div,
span,
applet,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
big,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
s,
samp,
small,
strike,
strong,
sub,
sup,
tt,
var,
b,
u,
i,
center,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
embed,
figure,
figcaption,
footer,
header,
hgroup,
menu,
nav,
output,
ruby,
section,
summary,
time,
mark,
audio,
video {
  margin: 0;
  padding: 0;
  font: inherit;
  font-size: 100%;
  vertical-align: baseline;
  border: 0; }

...

h1 {
  font-size: var(--cds-productive-heading-06-font-size, 2.625rem);
  font-weight: var(--cds-productive-heading-06-font-weight, 300);
  line-height: var(--cds-productive-heading-06-line-height, 1.199);
  letter-spacing: var(--cds-productive-heading-06-letter-spacing, 0); }

h2 {
  font-size: var(--cds-productive-heading-05-font-size, 2rem);
  font-weight: var(--cds-productive-heading-05-font-weight, 400);
  line-height: var(--cds-productive-heading-05-line-height, 1.25);
  letter-spacing: var(--cds-productive-heading-05-letter-spacing, 0); }

...

:root {
  --cds-interactive-01: #0f62fe;
  --cds-interactive-02: #393939;
  --cds-interactive-03: #0f62fe;
  --cds-interactive-04: #0f62fe;
  --cds-ui-background: #f4f4f4;
  --cds-ui-01: #ffffff;
  --cds-ui-02: #f4f4f4;
  --cds-ui-03: #e0e0e0;
  --cds-ui-04: #8d8d8d;
  --cds-ui-05: #161616;
  --cds-text-01

...

This causes various styling issues across the consuming microservices, and as such, we can’t rely on any component _tokens.scss for theming purposes right now.

Is this issue related to a specific component?

It is related to all Carbon component that use their own tokens for styling (e.g. tag, notification, etc).

What did you expect to happen? What happened instead? What would you like to see changed?

We would like to be able to include component _tokens.scss files without any additional styling changes.

Alternatively, component tokens could be part of the theme imports, so that there is no need to import _tokens.scss separately at all.

What version of the Carbon Design System are you using?

  • carbon-components: 10.33.0
  • carbon-components-react: 7.33.0

What offering/product do you work on? Any pressing ship or release dates we should be aware of?

Related issue on Cloud PAL: https://github.ibm.com/ibmcloud/pal/issues/4430

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tw15egancommented, Apr 28, 2021

@joshblack Yeah I think that may do the trick

0reactions
joshblackcommented, Apr 28, 2021

Awesome, thanks so much @vronjec that helps a ton 🙏

I think the reset is ultimately coming from the import to scss/globals/scss/theme in component-tokens. I think we can have the component token files for tag/notification import from theme-tokens directly instead of the component-tokens file / theme file directly and it should get around this reset issue.

Curious what you think @tw15egan 🤔

Read more comments on GitHub >

github_iconTop Results From Across the Web

carbon/v11.md at main - GitHub
In v11, you can import this file directly and reference the current theme, tokens defined in the theme, as well as dynamically retrieve...
Read more >
Guide - Carbon Design System
This guide helps you update your project to Carbon v11. It is broken into sections based on packages that you are using in...
Read more >
Minimal CSS with Carbon - Medium
In your sass files, you include the following import to include all of the styles for Carbon: @import 'carbon-components/scss/globals/scss/ ...
Read more >
Error: File to import not found or unreadable: ~bootstrap/scss ...
This happens when you give import from node_modules in any scss file other than the base root style.scss . Try placing it in...
Read more >
Carbon Components CSS - StackBlitz
$css--reset: true;. $css--default-type: true;. $css--plex: true;. @import 'carbon-components/scss/globals/scss/ ... component-tokens';. @import ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found