@@ -8,40 +8,34 @@ route: /customize/theming/overview
8
8
# Theming
9
9
10
10
From 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
12
12
for two main reasons:
13
13
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 .
17
17
18
18
2 . Thanks to JavaScript API, CSS custom properties are both ** readable and
19
19
writable by JS** .
20
20
21
21
## Theming Options
22
22
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.
26
26
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.
35
29
36
30
You 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 .
38
32
39
- ### Alias Design Tokens
33
+ ### Global and Semantic Design Tokens
40
34
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.
43
37
44
- The alias token names are written in the following format:
38
+ The names are written in the following format:
45
39
46
40
` --rui-<type>-[<group>]-<name>-[<state>] `
47
41
@@ -50,15 +44,15 @@ Where:
50
44
- ` <type> ` is one of: ` color ` , ` dimension ` , ` font-family ` , ` font-weight ` ,
51
45
` shadow ` , as suggested by the [ Design Tokens Format] [ dtf ] proposal. However,
52
46
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.
54
48
- ` <group> ` optionally groups multiple related values, e.g. ` text ` ,
55
49
` background ` , ` action ` , etc.
56
50
- ` <name> ` is the name of the token, e.g. ` primary ` , ` base ` , or ` light ` . Scales
57
51
can be presented as numbered sequences, e.g. ` space-[0-7] ` , ` size-[1-6] ` , etc.
58
52
- ` <state> ` describes additional interaction variants of the token: ` hover ` ,
59
- ` active ` , ` disabled ` .
53
+ ` focus ` , ` active ` , or ` disabled ` .
60
54
61
- Example alias design tokens represented by CSS custom properties:
55
+ Example global and semantic design tokens represented by CSS custom properties:
62
56
63
57
``` css
64
58
:root {
@@ -68,25 +62,26 @@ Example alias design tokens represented by CSS custom properties:
68
62
}
69
63
```
70
64
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).
74
69
75
- ### Component-Specific Tokens
70
+ ### Component Tokens
76
71
77
72
It 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.
79
74
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):
83
78
84
79
` --rui-<ComponentName>--[<modification(s)>]__[<element>]--[<modification(s)>]__<property>--[<modification>] `
85
80
86
81
Where:
87
82
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
90
85
are widely shared and therefore grouped as ` FormField ` options.
91
86
- ` <modifications(s)> ` can be one or more modifiers, typically a variant (e.g.
92
87
` primary ` , ` filled ` , ` box ` ) or interaction state (` default ` , ` hover ` ,
97
92
where a CSS property wouldn't tell enough (e.g. ` initial-offset ` ,
98
93
` check-background-color ` , ` tap-target-size ` ).
99
94
100
- Example component-specific custom properties :
95
+ Example component tokens :
101
96
102
97
``` css
103
98
:root {
@@ -112,41 +107,47 @@ Example component-specific custom properties:
112
107
}
113
108
```
114
109
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?
116
130
117
131
Colors, 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:
119
133
120
134
- generate our internal color palette programmatically,
121
135
- keep actual breakpoint values in a single place in the code,
122
136
- keep ` theme.scss ` uncluttered by inline SVG.
123
137
124
138
It's entirely up to you what format you decide to use for storing the theme.
125
139
Both ` 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.
127
141
128
142
👉 Just remember everything in the [ theme constants] directory is intended only
129
143
for usage within ` theme.scss ` . Otherwise, the theming system may not work as
130
144
expected. We recommend calling custom properties from ` theme.scss ` either
131
145
directly in your stylesheet, or through an intermediate, shareable layer like
132
146
` MyComponent/_theme.scss ` or
133
147
` 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).
149
149
150
+ [ CSS custom properties ] : https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties
150
151
[ default theme ] : https://github.com/react-ui-org/react-ui/blob/master/src/lib/theme.scss
151
152
[ dtf ] : https://design-tokens.github.io/community-group/format/
152
153
[ theme constants ] : https://github.com/react-ui-org/react-ui/blob/master/src/lib/styles/theme-constants
0 commit comments