@@ -8,40 +8,34 @@ route: /customize/theming/overview
88# Theming
99
1010From the very beginning, React UI has been designed with a great emphasis on
11- customizability. We decided to leverage CSS custom properties for this feature
11+ customizability. We decided to leverage [ CSS custom properties] for this feature
1212for two main reasons:
1313
14- 1 . We take advantage of possibilities of ** native CSS** . Preprocessors are still
15- a thing, but it's not necessary to go as far as for CSS-in-JS to make a UI
16- customizable.
14+ 1 . We take advantage of the possibilities of ** native CSS** . Preprocessors are
15+ still a thing, but it's not necessary to go as far as for CSS-in-JS to make
16+ a UI customizable, not even speaking of performance .
1717
18182 . Thanks to JavaScript API, CSS custom properties are both ** readable and
1919 writable by JS** .
2020
2121## Theming Options
2222
23- [ Design tokens] ( /foundation/design-tokens ) are used to define common visual
24- properties like colors, fonts, borders, shadows, or spacing. CSS custom
25- properties are the technical representation of the design tokens in React UI.
23+ [ Design tokens] ( /foundation/design-tokens ) define common visual properties like
24+ colors, fonts, borders, shadows, or spacing. [ CSS custom properties ] are the
25+ technical representation of the design tokens in React UI.
2626
27- All CSS custom properties in React UI come prefixed with ` rui- ` so they don't
28- get in way of other custom properties in your project.
29-
30- Just like the design tokens, the custom properties come grouped according to
31- their type:
32-
33- 1 . alias design tokens,
34- 2 . component-specific tokens.
27+ All CSS custom properties in React UI come prefixed with ` rui ` so they don't
28+ get in the way of other custom properties in your project.
3529
3630You can adjust any of the properties in your styles. See the [ default theme] for
37- the full list of available custom properties .
31+ the full list of available design tokens .
3832
39- ### Alias Design Tokens
33+ ### Global and Semantic Design Tokens
4034
41- The alias token names are not complex nor long, so they are simply lowercase and
42- hyphenated.
35+ Global and semantic token names are not complex or long. That is why they are
36+ simply lowercase and hyphenated.
4337
44- The alias token names are written in the following format:
38+ The names are written in the following format:
4539
4640` --rui-<type>-[<group>]-<name>-[<state>] `
4741
@@ -50,15 +44,15 @@ Where:
5044- ` <type> ` is one of: ` color ` , ` dimension ` , ` font-family ` , ` font-weight ` ,
5145 ` shadow ` , as suggested by the [ Design Tokens Format] [ dtf ] proposal. However,
5246 additional custom types like ` font-size ` , ` line-height ` , or ` text-decoration `
53- are also used as they prove necessary.
47+ have been added as they proved necessary.
5448- ` <group> ` optionally groups multiple related values, e.g. ` text ` ,
5549 ` background ` , ` action ` , etc.
5650- ` <name> ` is the name of the token, e.g. ` primary ` , ` base ` , or ` light ` . Scales
5751 can be presented as numbered sequences, e.g. ` space-[0-7] ` , ` size-[1-6] ` , etc.
5852- ` <state> ` describes additional interaction variants of the token: ` hover ` ,
59- ` active ` , ` disabled ` .
53+ ` focus ` , ` active ` , or ` disabled ` .
6054
61- Example alias design tokens represented by CSS custom properties:
55+ Example global and semantic design tokens represented by CSS custom properties:
6256
6357``` css
6458:root {
@@ -68,25 +62,26 @@ Example alias design tokens represented by CSS custom properties:
6862}
6963```
7064
71- ️👉 Please note that ** breakpoint values are exported as read-only** since CSS
72- custom properties [ cannot be used within media queries] [ w3c-custom-properties ]
73- (because a media query is not a CSS property).
65+ ️👉 Please note that ** breakpoint values are read-only** (e.g. for JavaScript)
66+ since CSS custom properties
67+ [ cannot be used within media queries] [ w3c-custom-properties ] (because a media
68+ query is not a CSS property).
7469
75- ### Component-Specific Tokens
70+ ### Component Tokens
7671
7772It is also possible to adjust some properties on individual components level,
78- preferably by reusing (inheriting) the alias design tokens.
73+ preferably by reusing (inheriting) the semantic design tokens.
7974
80- Due to higher complexity, component-specific tokens use a naming convention that
81- many web developers will find familiar because it works like [ BEM] (with
82- prefixes and component name syntax taken from [ SUIT CSS] , to be precise):
75+ Due to higher complexity, component tokens use a naming convention that many web
76+ developers will find familiar because it works like [ BEM] (with prefixes and
77+ component name syntax taken from [ SUIT CSS] , to be precise):
8378
8479` --rui-<ComponentName>--[<modification(s)>]__[<element>]--[<modification(s)>]__<property>--[<modification>] `
8580
8681Where:
8782
88- - ` <ComponentName> ` stands for actual component name (e.g. ` Button ` ,
89- ` FormField ` etc.) with a reasonable exception to form fields whose settings
83+ - ` <ComponentName> ` stands for the actual component name (e.g. ` Button ` ,
84+ ` FormField ` , etc.) with a reasonable exception to form fields whose settings
9085 are widely shared and therefore grouped as ` FormField ` options.
9186- ` <modifications(s)> ` can be one or more modifiers, typically a variant (e.g.
9287 ` primary ` , ` filled ` , ` box ` ) or interaction state (` default ` , ` hover ` ,
9792 where a CSS property wouldn't tell enough (e.g. ` initial-offset ` ,
9893 ` check-background-color ` , ` tap-target-size ` ).
9994
100- Example component-specific custom properties :
95+ Example component tokens :
10196
10297``` css
10398:root {
@@ -112,41 +107,47 @@ Example component-specific custom properties:
112107}
113108```
114109
115- ### CSS, or SCSS?
110+ ## Best Practices
111+
112+ 1 . It's a good idea to start with changing the ** global tokens first** . Adjust
113+ any context-agnostic values to see how the system reacts and scales.
114+
115+ 2 . Widely reused context-aware settings such as semantic colors, typography, or
116+ borders define the character of your design system which is stored in the
117+ ** semantic tokens** layer.
118+
119+ 3 . Having finished the customization at the global and semantic level, you can
120+ ** then proceed to customize the appearance of individual components** — if
121+ necessary at all.
122+
123+ Even then you should also reuse existing semantic design tokens as much as
124+ possible to ensure that your UI is consistent and works as a system.
125+
126+ For the same reason, if you have any custom components in your UI, you should
127+ ** reuse the semantic design tokens in your own CSS** too.
128+
129+ ## CSS, or Sass?
116130
117131Colors, breakpoints, and SVG definitions used in ` theme.scss ` are preprocessed
118- with SCSS first. This enables us to:
132+ with Sass first. This enables us to:
119133
120134- generate our internal color palette programmatically,
121135- keep actual breakpoint values in a single place in the code,
122136- keep ` theme.scss ` uncluttered by inline SVG.
123137
124138It's entirely up to you what format you decide to use for storing the theme.
125139Both ` theme.scss ` and ` theme.css ` will work equally well. It only matters if the
126- custom properties make it from the theme file to browser.
140+ custom properties make it from the theme file to the browser.
127141
128142👉 Just remember everything in the [ theme constants] directory is intended only
129143for usage within ` theme.scss ` . Otherwise, the theming system may not work as
130144expected. We recommend calling custom properties from ` theme.scss ` either
131145directly in your stylesheet, or through an intermediate, shareable layer like
132146` MyComponent/_theme.scss ` or
133147` styles/shared-by-components/_my-sass-variables-referring-to-theme.scss `
134- (latter of which is the approach we use).
135-
136- ## Best Practices
137-
138- It's a good idea to start with changing the ** alias design tokens first** .
139- Widely reused settings such as colors, typography, borders, or spacing values
140- should be adjusted first because they define basic appearance of all components.
141-
142- Having finished the customization at the global level, you can ** then proceed to
143- customizing the appearance of individual components** — if necessary at all.
144- Even then you should also reuse existing alias design tokens as much as
145- possible to ensure that your UI is consistent and works as a system.
146-
147- For the same reason, if you have any custom components in your UI, you should
148- ** reuse the alias design tokens in your own CSS** too.
148+ (the latter of which is the approach we use).
149149
150+ [ CSS custom properties ] : https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties
150151[ default theme ] : https://github.com/react-ui-org/react-ui/blob/master/src/lib/theme.scss
151152[ dtf ] : https://design-tokens.github.io/community-group/format/
152153[ theme constants ] : https://github.com/react-ui-org/react-ui/blob/master/src/lib/styles/theme-constants
0 commit comments