How to use style variables in CSS/SCSS files #1535
Answered
by
TheSisb
HartiganHM
asked this question in
Q&A
-
Hello, Paste friends! I've looked through the docs and tried poking around, but haven't been able to figure out a way to use Paste style variables (aka tokens) in our CSS/SCSS files. Would someone be able to share some insight with me or point me in the right direction? I've posted an example below for clarity, but let me know if you need more details. Thank you! @import '~@twilio-paste/core/styles';
body {
background-colors: $color-background;
} |
Beta Was this translation helpful? Give feedback.
Answered by
TheSisb
Jun 8, 2021
Replies: 1 comment 2 replies
-
Hi @HartiganHM, There are several ways to consume tokens from Paste, ordered from our most preferred to least: Using the Box primitive<Box backgroundColor="colorBackground"> ... Using our CSS-in-JSimport {styled, css} from '@twilio-paste/core/styling-library';
const custom = styled.div(
css({
backgroundColor: 'colorBackgroundPrimary',
padding: 'spacing20',
})
); Grabbing tokens from theme contextimport {Theme} from '@twilio-paste/core/theme';
<Theme.Consumer>
{({theme}) => {
return <p>What is the default text color {theme.textColors.colorText}</p>;
}}
</Theme.Consumer> or import {useTheme} from '@twilio-paste/core/theme';
const HookExampleComponent = (): React.ReactElement => {
const theme = useTheme();
return <p>What is the default text color {theme.textColors.colorText}</p>;
}; Importing tokens into your CSS/* SCSS */
@import '@twilio-paste/design-tokens/dist/tokens.default.scss'; or
|
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
TheSisb
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @HartiganHM,
There are several ways to consume tokens from Paste, ordered from our most preferred to least:
Using the Box primitive
docs for Box primitive
Using our CSS-in-JS
docs for css-in-js
Grabbing tokens from theme context
or