The carbon theme uses Sass to take advantage of the carbon-components styles and variables while authoring novel components. In addition, we use css modules to ensure we don’t collide with devs and make sure our components are portable and shadowable.
For your application’s local styles, you can just import your style sheet directly into a gatsby-browser.js
file at the root of your project.
You can also use sass modules like we do in the theme, this would make it easier for you to share your component with other theme consumers down the line.
Every Sass file in your project automatically has access to the the following carbon resources:
background: carbon--gray-10;
margin: $spacing-05;
color: $text-01;
transition: all $duration--moderate-01 motion(entrance, productive);
z-index: z('overlay');
@include carbon--type-style('body-long-01');
Theme component classes have a hash of their styles tacked on to the end. This is both to prevent collisions, and also to prevent sneaky breaking changes to your styles if we update the class underneath you and you were relying on our styles.
However, you can target the classes without the hash by using a partial selector:
[class^='Banner-module--column'] {
color: $text-04;
}
This will match the class that starts with Banner-module--column
and would be immune to any changes to the hash. We may at some point remove the hash if this becomes an issue.
You normally shouldn’t need this unless you’re using a carbon-component that isn’t in the theme yet.
If you have node_module
dependencies that assume a single bundle (such as individual carbon-components
),
You can inject global dependancies into the theme’s style bundle. To do this, shadow gatsby-theme-carbon/styles/_global.scss
in your project’s src
directory. This technique