Theme
Paste Design System Theme Package which provides support for APIs to theme UIs and components.
This package allows for straight-forward access to Paste design tokens via a Theme Provider to React components. By using this package, you can express your UIs with each of our supported themes, and get their associated token values.
For more information about how Paste is built and where themes fit into that hierarchy, read About Paste.
Paste components are built using our Styling Library, which currently wraps Emotion and
Styled System. Our Styling Library provide a Theme object containing our
design tokens. This enables our components to be themed, and also provide styling properties to some of
our design primtive components like Box
and Text
. The theme object is grouped by categories,
and within each category a camelCase key represents a design token name. To see our supported themes
and their values, check out the Token List page.
For example: If you were looking for token $color-background-success
, you would see it listed on key backgroundColors
as colorBackgroundSuccess
i.e. theme.backgroundColors.colorBackgroundSuccess
.
The shape of the Theme object currently looks like this:
Object {
"backgroundColors": Object {},
"borderColors": Object {},
"borderWidths": Object {},
"breakpoints": Object {},
"colorSchemes": Object {},
"dataVisualization": Object {},
"fontSizes": Object {},
"fontWeights": Object {},
"fonts": Object {},
"heights": Object {},
"iconSizes": Object {},
"lineHeights": Object {},
"maxHeights": Object {},
"maxWidths": Object {},
"minHeights": Object {},
"minWidths": Object {},
"radii": Object {},
"shadows": Object {},
"sizes": Object {},
"space": Object {},
"textColors": Object {},
"widths": Object {},
"zIndices": Object {},
}
The Paste ThemeProvider
leverages React's Context to provide
the theme object to any descendant components in the tree. For that reason, we recommend wrapping your
application at the root level with the Paste ThemeProvider
. This allows all sub-components to retrieve
the correct token value for the supplied theme.
import {Theme} from '@twilio-paste/theme';
<Theme.Provider theme="default">
<App />
</Theme.Provider>;
Prop | Type | Description | Default |
---|---|---|---|
theme? | enum | 'default', 'dark', 'twilio', 'twilio-dark' and 'evergreen' | 'default' |
customBreakpoints? | string[] | An optional array of string values for custom screen sizes in the usual CSS width formats | theme.breakpoints |
Paste includes a number of themes out of the box. Choosing the right one for your project will depend on who you are and what you are building.
Theme | When to use |
---|---|
Default | If you are not building an application for Twilio, use this theme |
Dark | If you are not building an application for Twilio and want a dark mode, use this theme |
Twilio | If you are building an application for Twilio, use this theme |
Twilio Dark | If you are building an application for Twilio and want a dark mode, use this theme |
Evergreen | If you are building an application for Segment, use this theme |
Sometimes you will need to create something custom that is not available in Paste but you need that component to still look like it's from Paste. The use of Paste Tokens in your styles is the way that you can access global design properties used in all Paste Components.
By using the Theme.Provider
, when you create a custom component using Styling-Library, the theme object is available on props
via context. You can access those via the css
utility or props object directly.
This is the preferred method.
import {styled, css} from '@twilio-paste/styling-library';
const custom = styled.div(
css({
backgroundColor: 'colorBackgroundPrimary',
padding: 'spacing20',
})
);
Careful!
This is not a recommended approach for using Tokens. If you must do so, we strongly recommend reaching out at #help-design-system
If you are not using Styled Components or want to access the values of tokens in your React components outside of styling, there are three ways this can be achieved.
Paste Theme provides Theme.Consumer
- a React Context Consumer for the theme. It takes a function as a child, which provides the theme object as an argument.
import {Theme} from '@twilio-paste/theme';
<Theme.Consumer>
{({theme}) => {
return <p>What is the default text color {theme.textColors.colorText}</p>;
}}
</Theme.Consumer>;
Paste Theme provides a React Hook called useTheme
which returns the theme object from the React Context via the Theme Provider.
import React from 'react';
import {useTheme} from '@twilio-paste/theme';
const HookExampleComponent = (): React.ReactElement => {
const theme = useTheme();
return <p>What is the default text color {theme.textColors.colorText}</p>;
};
Paste also provides a HoC to be able to access the theme object.
import React from 'react';
import {withTheme} from '@twilio-paste/theme';
const ExampleComponent = ({theme}) => <p>What is the default text color {theme.textColors.colorText}</p>;
// Provides this component with the theme object as a prop
const ExampleComponentwithTheme = withTheme(ExampleComponent);
As you use Paste, you'll likely encounter things that don't seem right. Please reach out with your feedback! Here's some prompts to consider:
- Is this page easy for me to consume?
- Is the information supporting it sufficient / well-described?
- What information is missing?
- How approachable is the documentation? Can a new engineer / PM / designer at Twilio get started with it easily?
Changelog
611a2daaf
#3456 Thanks @nkrantz! - [Theme] Change the type of sizeIcon tokens in the GenericThemeShape to beany
. Previously they were incorrectly typed as the value of the token in the Twilio theme, which was preventing consumers from passing custom icon sizes using the Customization Provider.
733709127
#3395 Thanks @SiTaggart! - Modified the compile target of our JavaScript bundles fromnode
tobrowser
to minimize the risk of clashing with RequireJS. This is marked as a major out of an abundance of caution. You shouldn't need to do anything but we wanted you to be aware of the change on the off chance it has unintended consequences
- Updated dependencies [
733709127
]:- @twilio-paste/color-contrast-utils@5.0.0
- @twilio-paste/design-tokens@10.0.0
- @twilio-paste/animation-library@2.0.0
- @twilio-paste/styling-library@3.0.0
- @twilio-paste/types@6.0.0
8f96d66a9
#3327 Thanks @TheSisb! - [Theme] Update Inter font version from 3.15 to 3.19, which fixes a Chrome issue with number emojis
0c3861824
#3154 Thanks @TheSisb! - [Theme] theme breakpoint values are now represented aspx
values instead ofrem
values. MediaQueries are more easily grokked aspx
values, and it simplifies development by eliminating variability in widths. In rare cases, some tests - like snapshot tests - may need to be updated.
c42ad640b
#3130 Thanks @SiTaggart! - Enable the ability to theme the color-scheme css property which can be used to control native HTML elements and the way they render in light or dark mode
3ab2bb6f4
#3114 Thanks @SiTaggart! - ### Breaking changeWe have moved
@types/react
and@types/react-dom
to peer dependencies of the library. This should allow for greater control and backwards compatibility with older versions of React as Paste is no longer bundling the type libraries.Your application likely has both of these as dependencies anyway, but it is now up to you to manage that version number.
Action needed
Ensure
@types/react
and@types/react-dom
are installed as dependencies of your application.
bce889344
#3090 Thanks @SiTaggart! - [Design Tokens, Theme] add ability to override the base font size that Paste uses from the HTML element tag via the new token$font-size-base
. Also removes setting font size from the body element for when Paste is embedded into another application with its own stylesUpdated dependencies [
3ab2bb6f4
]:- @twilio-paste/types@5.0.0
b942178ad
#3052 Thanks @TheSisb! - [Theme] Add theme override via url by using#paste-theme-override=[newtheme]
.
0acdf3486
#3049 Thanks @SiTaggart! - [Box, Text, Style Props, Theme]: remove checking and warning for deprecated design tokens and themes that have been removed from the system
- Updated dependencies [
dbd9bf992
,3c89fd83d
,0acdf3486
,ef094db4a
]:- @twilio-paste/design-tokens@9.0.0
- @twilio-paste/animation-library@1.0.0
- @twilio-paste/styling-library@2.0.0
- @twilio-paste/types@4.0.0
- @twilio-paste/color-contrast-utils@4.0.0
2bde84f96
#3006 Thanks @brandongregoryscott! - [Theme] Export EvergreenTheme, TwilioTheme and TwilioDarkTheme objects and types
c056da73e
#2927 Thanks @jb-twilio! - [Theme, Design Tokens] Add evergreen design tokens and theme
b7e429ef5
#2948 Thanks @Niznikr! - [Theme] Add new themestwilio
andtwilio-dark
as part of our new unified design language to be used for Twilio products. Add Twilio Sans Text and Twilio Sans Display fonts used in the themes.
4ae8972b4
#2971 Thanks @TheSisb! - [Theme] AddcacheProviderProps
to the ThemeProvider which allows passing a customkey
andnonce
into Emotion's CacheProvider to get around CSP limitations.
026bf7f52
#2799 Thanks @SiTaggart! - [design-tokens, theme] updated mono spaced font in default and dark themes to use the new Twilio Sans Mono font
a4c9e70b0
#2763 Thanks @shleewhite! - Update ESLint rules, which changed some formatting.
4a3974fce
#2745 Thanks @TheSisb! - [Theme] Fix type for theiconSizes
token bucket under the theme object
364083627
#2577 Thanks @zahnster! - [Theme] Updated Data Visualization colors to use the new Data Visualization category from the Design Tokens package.Updated dependencies [
364083627
,364083627
,364083627
]:- @twilio-paste/design-tokens@8.0.0
- @twilio-paste/color-contrast-utils@3.0.0
eb490746c
#2480 Thanks @shleewhite! - [Theme] fix isDeprecatedTheme to only throw a console error if a theme is deprecated.
ae9dd50f
#2466 Thanks @TheSisb! - [All packages] Update our ESBuild version and remove minification of identifiers in our production builds.
09762f0f1
#2376 Thanks @andipants12! - [Theme] Small edit to cased named imports and usage ofkeyof
in types.Updated dependencies [
09762f0f1
]:- @twilio-paste/styling-library@1.0.0
91d20b99
#2328 Thanks @TheSisb! - [Theme & Customization] Fix an issue where animations would run once regardless of if animations should be disabled.
8e5dfe1e6
#2298 Thanks @shleewhite! - [ThemeProvider] use non-latin fonts based on the HTML lang attribute to support i18n.
73c596919
#2269 Thanks @SiTaggart! - Fixed a regression with the compilation script that caused incompatible ESM module importing of JSON files.
c867e3f48
#2237 Thanks @SiTaggart! - Updated a build dependency (esbuild) which changes the output of our builds slightly, without materially changing anything about the code.
0a52eeee
#2168 Thanks @shleewhite! - [Theme] Deprecated the console theme. Using theme="console" in the Theme.Provider returns the default theme and ConsoleThemeShape returns the DefaultThemeShape. The default theme should be used instead.
- Updated dependencies [
0a52eeee
,04de0d1d
,04de0d1d
]:- @twilio-paste/design-tokens@7.0.0
- @twilio-paste/color-contrast-utils@2.0.0
8bedb9fd
#2021 Thanks @TheSisb! - [Theme and Customization] Slight tweak to prevent animations from running once on app load when they should be disabled from the beginning.
b7675915
#1985 Thanks @TheSisb! - For debugging purposes we now ship afilename.debug.js
unminified version of each component or library in Paste.
ed5c0a49c
#1965 Thanks @shleewhite! - Upgrade Paste to use React 17 by default, but maintain React 16 support for consumers.
01baddcd
#1925 Thanks @shleewhite! - Add displayNames to all components
10f4a285
#1310 Thanks @SiTaggart! - [design tokens] export design token types from the design-tokens page [theme]GenericTokenShape
is now calledGenericTokensShape
and exported from@twilio-paste/design-tokens
e268bfd1
#1310 Thanks @SiTaggart! - [theme]generateThemeFromTokens
andgenerateTokensFromTheme
now take objects as arguments
e268bfd1
#1310 Thanks @SiTaggart! - [theme] provide a hook that will calculate the color contrast rating of the current Paste themeuseThemeContrastCheck
c42f86ca
#1434 Thanks @SiTaggart! - Adding a body background color for purposes of applying the color background body design token so that you can see the affect it has when theming the website
25a1f632
#1404 Thanks @SiTaggart! - Add a dark theme to Paste
0eded1fd
#1319 Thanks @SiTaggart! - Change internal dependencies to have minor range matching on version numbers
514bd5aa
#1299 Thanks @SiTaggart! - Correctly type the generic theme type to only include icon sizes in the iconSizes key
26c828d8
#1236 Thanks @richbachman! - Changed SendGrid theme link test so it passes with the correct color.Updated dependencies [
4c9ed5ca
]:- @twilio-paste/design-tokens@6.6.0
- Updated dependencies [
944c3407
]:- @twilio-paste/design-tokens@6.5.2
a12acb61
#1158 Thanks @richbachman! - Pinned all twilio-paste package versions in order to keep them in sync with core when they are updated by changesets.y
All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.
4.2.1 (2021-01-25)
Note: Version bump only for package @twilio-paste/theme
4.1.2 (2021-01-15)
Note: Version bump only for package @twilio-paste/theme
4.1.1 (2021-01-07)
Note: Version bump only for package @twilio-paste/theme
- theme: load fonts.css file from theme provider (acef2a5)
4.0.1 (2020-12-11)
- theme: add public access for npm publish (ac823f8)
- theme: add ability to generate a theme from design tokens (9b81663)
- theme: add ability to map a theme back to design token groupings (8f7e6f9)
- theme: export paste global styles (b0e5d75)
- theme: remove the color key from theme (d5f9e68)
- theme: Color key is removed from the theme. This makes for a better experience as there are no duplicate colors. Each type of color has their own key on theme
3.3.3 (2020-12-09)
Note: Version bump only for package @twilio-paste/theme
3.3.2 (2020-11-11)
Note: Version bump only for package @twilio-paste/theme
3.3.1 (2020-11-06)
Note: Version bump only for package @twilio-paste/theme
3.2.27 (2020-10-23)
Note: Version bump only for package @twilio-paste/theme
3.2.26 (2020-10-15)
Note: Version bump only for package @twilio-paste/theme
3.2.25 (2020-10-13)
Note: Version bump only for package @twilio-paste/theme
3.2.24 (2020-10-07)
Note: Version bump only for package @twilio-paste/theme
3.2.23 (2020-10-07)
3.2.22 (2020-09-22)
Note: Version bump only for package @twilio-paste/theme
3.2.21 (2020-09-15)
Note: Version bump only for package @twilio-paste/theme
3.2.20 (2020-09-15)
Note: Version bump only for package @twilio-paste/theme
3.2.19 (2020-09-08)
Note: Version bump only for package @twilio-paste/theme
3.2.18 (2020-08-31)
Note: Version bump only for package @twilio-paste/theme
3.2.17 (2020-08-31)
Note: Version bump only for package @twilio-paste/theme
3.2.16 (2020-08-24)
Note: Version bump only for package @twilio-paste/theme
3.2.15 (2020-08-19)
Note: Version bump only for package @twilio-paste/theme
3.2.14 (2020-08-12)
Note: Version bump only for package @twilio-paste/theme
3.2.13 (2020-08-12)
Note: Version bump only for package @twilio-paste/theme
3.2.12 (2020-08-04)
Note: Version bump only for package @twilio-paste/theme
3.2.11 (2020-08-04)
Note: Version bump only for package @twilio-paste/theme
3.2.10 (2020-07-22)
Note: Version bump only for package @twilio-paste/theme
3.2.9 (2020-07-14)
Note: Version bump only for package @twilio-paste/theme
3.2.8 (2020-07-14)
Note: Version bump only for package @twilio-paste/theme
3.2.7 (2020-07-01)
Note: Version bump only for package @twilio-paste/theme
3.2.6 (2020-06-25)
Note: Version bump only for package @twilio-paste/theme
3.2.5 (2020-06-22)
Note: Version bump only for package @twilio-paste/theme
3.2.4 (2020-06-18)
Note: Version bump only for package @twilio-paste/theme
3.2.3 (2020-06-16)
- theme: export StyledBase (fb25eeb)
3.2.2 (2020-06-12)
Note: Version bump only for package @twilio-paste/theme
3.2.1 (2020-06-01)
Note: Version bump only for package @twilio-paste/theme
- theme: disable animations when prefers-reduced-motion, cleanup (2cbe919)
3.1.7 (2020-05-20)
Note: Version bump only for package @twilio-paste/theme
3.1.6 (2020-05-07)
Note: Version bump only for package @twilio-paste/theme
3.1.5 (2020-05-07)
Note: Version bump only for package @twilio-paste/theme
3.1.4 (2020-05-01)
Note: Version bump only for package @twilio-paste/theme
3.1.3 (2020-04-25)
Note: Version bump only for package @twilio-paste/theme
3.1.2 (2020-04-22)
Note: Version bump only for package @twilio-paste/theme
3.1.1 (2020-04-07)
- theme: export theme base styles to be reusable (28f04af)
- theme: merge theme-tokens into theme package (f913561)
3.0.8 (2020-03-11)
Note: Version bump only for package @twilio-paste/theme
3.0.7 (2020-03-06)
Note: Version bump only for package @twilio-paste/theme
3.0.6 (2020-03-02)
Note: Version bump only for package @twilio-paste/theme
3.0.5 (2020-02-28)
Note: Version bump only for package @twilio-paste/theme
3.0.4 (2020-02-26)
3.0.3 (2020-02-13)
Note: Version bump only for package @twilio-paste/theme
3.0.2 (2020-02-03)
Note: Version bump only for package @twilio-paste/theme
3.0.1 (2020-01-17)
Note: Version bump only for package @twilio-paste/theme
- theme: add the console theme and update default theme (3951f82)
- theme: Theme provider default theme is now DEFAULT, not CONSOLE. If you are not providing a theme prop but want the console theme you must now explicitly set the theme to console
2.0.5 (2019-12-19)
Note: Version bump only for package @twilio-paste/theme
2.0.4 (2019-12-05)
Note: Version bump only for package @twilio-paste/theme
2.0.3 (2019-11-20)
Note: Version bump only for package @twilio-paste/theme
2.0.2 (2019-11-18)
2.0.1 (2019-11-12)
Note: Version bump only for package @twilio-paste/theme
- icons: delete old icons, add new streamline icons (#129) (571791d)
- enable theme switching on the docsite (#124) (df797e5)
- icons: removed all the inherited icons since we're moving to a new system
1.0.1 (2019-10-31)
Note: Version bump only for package @twilio-paste/theme
- design token and theme package documentation (#103) (3060113)
- box: polish and fix (#125) (d151bad)
- upgrading to styled-system v5 (#18) (2b3ebd8)
- box: many Box API changes
0.4.1 (2019-09-16)
- change @paste scope to @twilio-paste (#2) (1d8d2ff)