Skip to content

Commit 04b2042

Browse files
committed
Improve the structure of global and semantic design tokens and explain how they are related
Breaking changes: - Renamed link color tokens from `--rui-color-action-link(-*)` to `--rui-color-text-link(-*)`. - Removed internal design token `--rui-ratio-disabled-cursor` in favour of `--rui-cursor-not-allowed`.
1 parent ff6205b commit 04b2042

File tree

10 files changed

+253
-228
lines changed

10 files changed

+253
-228
lines changed

doczrc.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,14 @@ export default {
244244
},
245245
a: {
246246
'&:active': {
247-
color: 'var(--rui-color-action-link-active)',
247+
color: 'var(--rui-color-text-link-active)',
248248
textDecoration: 'var(--rui-text-decoration-link-active)',
249249
},
250250
'&:hover': {
251-
color: 'var(--rui-color-action-link-hover)',
251+
color: 'var(--rui-color-text-link-hover)',
252252
textDecoration: 'var(--rui-text-decoration-link-hover)',
253253
},
254-
color: 'var(--rui-color-action-link)',
254+
color: 'var(--rui-color-text-link)',
255255
textDecoration: 'var(--rui-text-decoration-link)',
256256
},
257257
root: {

src/docs/customize/theming/overview.mdx

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,34 @@ route: /customize/theming/overview
88
# Theming
99

1010
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
1212
for 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

1818
2. 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

3630
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.
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

7772
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.
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

8681
Where:
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`,
@@ -97,7 +92,7 @@ Where:
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

117131
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:
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

124138
It's entirely up to you what format you decide to use for storing the theme.
125139
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.
127141

128142
👉 Just remember everything in the [theme constants] directory is intended only
129143
for usage within `theme.scss`. Otherwise, the theming system may not work as
130144
expected. We recommend calling custom properties from `theme.scss` either
131145
directly 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

src/docs/foundation/accessibility.mdx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ The active area of interactive elements should be properly sized so that the
1818
elements can be easily targeted on touch screens. Recommended dimensions may
1919
vary from platform to platform, however a commonly used size is 7–10 mm.
2020

21-
Default tap target size in React UI is set to **10 mm** and is used by all
22-
potentially small interactive components like [Alert](/components/alert)
23-
close button, [CheckboxField](/components/checkbox-field), or
24-
[Toggle](/components/toggle). Tap target size can be adjusted via the
25-
`--rui-dimension-tap-target-size` custom property (see
26-
[Theming](/customize/theming/overview) to learn how).
21+
Default tap target size in React UI is used by all potentially small interactive
22+
components like [Alert](/components/alert) close button,
23+
[CheckboxField](/components/checkbox-field), or [Toggle](/components/toggle).
24+
Tap target size can be adjusted via the `--rui-dimension-tap-target-size`
25+
custom property (see [Theming](/customize/theming/overview) to learn how).
2726

2827
📖 [Read more about touch targets at Norman Nielsen Group.][nn-group]
2928

src/docs/foundation/colors.mdx

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,58 @@ import Swatch from '../_components/Swatch'
1010

1111
Colors help you communicate the structure of your UI, emphasize any important
1212
information, or signal different states of the UI. **Use colors intentionally**
13-
— they are not a decoration, they should always serve a purpose.
13+
— they are not decoration and should always serve a purpose.
1414

1515
👉 All colors on this page can be changed by
1616
[overriding](/customize/theming/overview) values in your
1717
[design tokens](/foundation/design-tokens).
1818

1919
## General Guidelines
2020

21-
- **All colors in React UI are strictly semantic: they always target a specific
22-
use case. You are encouraged to apply any color palettes you want and map them
23-
onto the semantic colors of React UI.**
24-
- In general, all colors in React UI are for either **static** (text colors and
25-
most of the background colors) or **interactive** use cases (action colors,
26-
feedback colors). However, some colors are designed to be either of them:
27-
neutral colors can be used for both static and interactive parts, similarly to
28-
primary border color.
21+
- **Most colors in React UI are semantic: they bear a meaning and target a
22+
specific use case.** The only non-semantic exception is the
23+
[neutral colors](#neutral-colors) that are included in React UI due to their
24+
frequent usage in UI designs.
25+
- **React UI does not try to suggest any global color palettes.** Instead, you
26+
are encouraged to pick any color palettes you want and map them onto the
27+
semantic colors of React UI.
28+
- In general, colors in React UI can be used for either **static**
29+
(most of the [text colors](#text-colors) and most of the
30+
[background colors](#background-colors)) or **interactive** use cases
31+
([action colors](#action-colors), [feedback colors](#feedback-colors)).
32+
However, some colors are designed to be either:
33+
[neutral colors](#neutral-colors) can be used for static and interactive parts
34+
similarly to the primary [border color](#border-colors).
2935
- Interactive color variants always define **hover** and **active** (pressed)
3036
states.
31-
- Many colors suggest **what color should be used for text** placed on them. You
32-
don't have to think if black or white is better — just use `on-primary` for
33-
text on primary color background or `on-success` for success color background,
34-
and you should be safe.
37+
- Action, feedback, and neutral colors suggest **what color should be used** for
38+
the text placed on them. You don't have to think if black or white makes a
39+
better contrast — just use `on-primary` for text on primary color background
40+
or `on-success` for success color background, and you should be safe.
3541

3642
## Text Colors
3743

38-
Colors reserved for text. The text can have primary or secondary priority. Both
39-
priorities can be suppressed with the `disabled` variants.
44+
Colors reserved for text. Base text can have primary or secondary priority,
45+
while both priorities can be suppressed with the `disabled` variants. Last but
46+
not least, the text colors define the color of links.
4047

4148
<div>
4249
<Swatch color="text-primary" />
4350
<Swatch color="text-primary-disabled" />
4451
<Swatch color="text-secondary" />
4552
<Swatch color="text-secondary-disabled" />
4653
</div>
54+
<div>
55+
<Swatch color="text-link" />
56+
<Swatch color="text-link-hover" />
57+
<Swatch color="text-link-active" />
58+
</div>
4759

4860
## Action Colors
4961

5062
Action colors communicate the **importance** of an action which can be primary
51-
or secondary. Using the `selected` color, you can also mark an action as the one
52-
currently selected. Last but not least, the action colors define the color of
53-
links, too.
63+
or secondary. Using the _selected_ color, you can also mark an action as the
64+
currently selected.
5465

5566
<div>
5667
<Swatch color="action-primary" />
@@ -70,17 +81,12 @@ links, too.
7081
<Swatch color="action-selected-active" />
7182
<Swatch color="action-on-selected" />
7283
</div>
73-
<div>
74-
<Swatch color="action-link" />
75-
<Swatch color="action-link-hover" />
76-
<Swatch color="action-link-active" />
77-
</div>
7884

7985
## Feedback Colors
8086

81-
Feedback colors help communicate a **meaning**: green means success, orange
82-
means warning, and red means danger or error. On top of that, there are a few
83-
more feedback colors to fit various situations.
87+
Feedback colors help communicate a meaning: green means success, orange means
88+
warning, and red means danger or error. On top of that, there are a few more
89+
feedback colors to fit various design situations.
8490

8591
<div>
8692
<Swatch color="feedback-success" />
@@ -144,7 +150,7 @@ Colors reserved for backgrounds.
144150

145151
### Content Layers
146152

147-
Backgrounds for the fundamental UI areas and layered content.
153+
Backgrounds for the fundamental UI areas and content layering.
148154

149155
👉 Content layers can be separated from background using their
150156
[shadow counterparts](/foundation/shadows): `background-layer-1` +
@@ -173,8 +179,8 @@ the _basic_ background is the default go-to background for components.
173179

174180
Backgrounds to highlight interactive areas on hover and during interaction.
175181

176-
💡 Please note the default interactive background is always transparent so it
177-
does not get in the way of the underlying component background.
182+
💡 Please note the default interactive background is always transparent, so it
183+
does not stand in the way of the underlying component background.
178184

179185
<div>
180186
<Swatch color="background-interactive" />
@@ -229,23 +235,22 @@ primary border.
229235

230236
## Applying Colors
231237

232-
Components can apply colors above using one or more of the following color
233-
palettes.
238+
Components can apply colors above using one or more following color groups.
234239

235240
### Component Colors
236241

237242
Some components ([Alert](/components/alert), [Badge](/components/badge),
238243
[Button](/components/button), and more) come in more color variants to help you
239-
better reflect their importance or nature of their content. Following colors
240-
are available in such cases:
244+
better reflect their place in content hierarchy or the meaning of their content.
245+
Following colors are available in such cases:
241246

242247
- **action colors (actionable components only):** `primary`, `secondary`, and
243248
`selected`,
244249
- **feedback colors:** `success`, `warning`, `danger`, `help`, `info`, and
245250
`note`,
246251
- **neutral colors:** `light` and `dark`.
247252

248-
There is always a reasonable default for the component in question which can be
253+
There is always a reasonable default for the component in question that can be
249254
changed to any of supported values above through the `color` prop.
250255

251256
### Validation States
@@ -259,5 +264,5 @@ apply selected [feedback colors](#feedback-colors) for individual states:
259264
- `warning` feedback color for **warning** state,
260265
- `danger` feedback color for **invalid** state.
261266

262-
Validation state is always optional so default styling is applied for the
267+
Validation state is always optional. Default styling is applied for the given
263268
component when its `validationState` prop is not specified.

0 commit comments

Comments
 (0)