Skip to content

Commit ad78761

Browse files
committed
Notes: Add more notes on component API and how theming works
1 parent 27201bc commit ad78761

File tree

4 files changed

+31
-19
lines changed

4 files changed

+31
-19
lines changed

README.md

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,43 @@
11
# Design System Boilerplate
22

3-
Boilerplate monorepo setup with the design system as an internal package and two example apps using the monorepo.
3+
Boilerplate monorepo setup with the design system as an internal package and two example apps built with the design system.
44

55
## Design System
66

7-
A strongly typed opinionated design system based on system ui theme specification and styled system component API.
7+
A strongly typed opinionated design system based on [System UI Theme Specification](https://system-ui.com/theme/) and [Styled System](https://styled-system.com/) component API for rapid UI development.
88

99
### Principles
1010

11-
- Predefine all your themes. i.e no runtime theme creation. This allows us to statically define themes using css variables and create strongly typed themes. Strong types help with full autocomplete support in component APIs.
12-
- Token groups are identified and based on theme ui specification. Eg. `colors`, `space`, `fontSizes`, etc.
11+
The design system follows a set of constraints that allows us to statically compile theme definitions and build flexibile APIs.
12+
13+
- Predefine all your themes. i.e no runtime theme creation. This allows us to statically define themes using css variables and create strongly typed themes. Strong types help with full autocomplete support in component APIs. Eg.
14+
- `Box` component `backgroundColor` prop autocompletes with available color tokens - `primary`, `secondary`, etc.
15+
- `Box` component `padding` prop autocompletes with available spacing tokens - `small`, `large`, etc.
16+
17+
- Token groups are identified and based on [System UI Theme Specification](https://system-ui.com/theme/). Eg. `colors`, `space`, `fontSizes`, etc.
18+
1319
- Keep your token groups flat. Don't nest your tokens within token groups. Eg. `colors.primary` is allowed. `colors.primary.success` is not allowed.
20+
21+
- All themes should have the same set of tokens. Eg. dark theme cannot have a token that's not available in light theme.
22+
1423
- Theming is driven using CSS custom properties (variables). This allows all themes to have the same tokens values which makes it easy to switch or server render themes. Eg. `token.colors.primary` has the same css variable across themes and makes it easy to statically define styles instead of defining the styles during runtime based on theme. `background: ${tokens.colors.primary}` instead of `background: ${(prop) => prop.theme.colors.primary}`.
1524

25+
### How does theming work?
26+
27+
- Theme definitions are automatically converted to css variables using the `createTheme` utility.
28+
- The generated css variables are theme-name scoped in `ThemeProvider`.
29+
30+
```
31+
body[data-theme="light"] {
32+
--theme-colors-primary: blue;
33+
--theme-colors-secondary: lightblue;
34+
}
35+
body[data-theme="dark"] {
36+
--theme-colors-primary: green;
37+
--theme-colors-secondary: lightgreen;
38+
}
39+
```
40+
1641
### Stack
1742

1843
- Components are styled using emotion
@@ -43,19 +68,6 @@ const Example = () => {
4368
};
4469
```
4570

46-
How does that work? css variables names are theme name scoped.
47-
48-
```
49-
body[data-theme="light"] {
50-
--theme-colors-primary: blue;
51-
--theme-colors-secondary: lightblue;
52-
}
53-
body[data-theme="dark"] {
54-
--theme-colors-primary: green;
55-
--theme-colors-secondary: lightgreen;
56-
}
57-
```
58-
5971
#### Getting current theme name
6072

6173
Getting current theme is as simple as querying the DOM attribute. You don't need Context or fancy hooks to provide you the value. Although you do have a hook if you need — `useTheme`.

packages/design-system/src/core/theme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
fontFamily,
88
lineHeights,
99
} from '../tokens/typography';
10-
import { createTheme } from '../util/theme';
10+
import { createTheme } from '../util/create-theme';
1111

1212
/* light mode - default */
1313
const light = createTheme({

packages/design-system/src/util/__tests__/theme.test.ts renamed to packages/design-system/src/util/__tests__/create-theme.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createTheme } from '../theme';
1+
import { createTheme } from '../create-theme';
22

33
describe('util/theme', () => {
44
it('createTheme', () => {

0 commit comments

Comments
 (0)