Skip to content

Commit 0695253

Browse files
authored
Merge pull request #741 from system-ui/update-theming-docs
Update theming docs
2 parents 5679f6e + ac0c213 commit 0695253

File tree

8 files changed

+110
-25
lines changed

8 files changed

+110
-25
lines changed

packages/docs/src/components/banner.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,13 @@ export default props => (
66
theme={{
77
styles: {
88
p: {
9-
':first-of-type': {
10-
variant: 'text.display',
11-
fontSize: [3, null, 4],
12-
mt: 4,
13-
},
14-
fontWeight: 'bold',
15-
mt: 0,
16-
mb: 3,
9+
maxWidth: '40em',
10+
my: 4,
1711
},
1812
h1: {
1913
fontSize: [3, 3, 4],
20-
fontWeight: 'heading',
21-
letterSpacing: 'initial',
22-
mt: 0,
23-
mb: 4,
14+
letterSpacing: '0',
15+
my: 4,
2416
},
2517
a: {
2618
variant: 'links.button',
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Design Graph
3+
---
4+
5+
# Design Graph
6+
7+
The core organizing principle for styles in Theme UI is based
8+
on a conceptual model called the *Design Graph*.
9+
10+
The Design Graph is composed of the following nodes:
11+
12+
- **Scales** are limited collections of raw values that map to specific style properties.
13+
For example, values for `font-size` are stored in the `fontSizes` scale.
14+
- **Components** are elements that have styles constrained by *scales*.
15+
- **Variants** are partial styles that map to specific components.
16+
For example, a button might have *primary* and *secondary* variants, or *large* and *small* variants.
17+
- **Themes** are collections of *scales* (and possibly *variants*) that encapsulate a particular visual design language.
18+
Ideally, themes follow a common interface (or schema) and can be swapped out in different implementations.
19+
20+
The Design Graph provides a way to think and talk about the styles in Theme UI,
21+
and the [Theme Specification][] is the primary interface for theme objects.
22+
23+
To read more about the Design Graph, see the original [blog post][].
24+
25+
26+
[blog post]: https://jxnblk.com/blog/design-graph
27+
[theme specification]: /theme-spec

packages/docs/src/pages/getting-started/index.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ export default props => (
5252
Use the `sx` prop throughout your application to add styles based on your theme to any component.
5353
Enable the `sx` prop by adding the `/** @jsx jsx */` comment to the top of your file and importing `jsx` from Theme UI.
5454

55+
The `sx` prop lets you add any valid CSS to an element,
56+
while using values from your theme to keep styles consistent.
57+
You can think of the style object that the `sx` prop accepts as a *superset* of CSS.
58+
5559

5660
```jsx
5761
/** @jsx jsx */
@@ -96,9 +100,23 @@ The values used for media queries can be defined in a [`theme.breakpoints`](/the
96100

97101
</Note>
98102

103+
If you prefer standard CSS syntax, you can use nested objects for responsive styles as well.
104+
105+
```jsx
106+
<div
107+
sx={{
108+
width: '100%',
109+
'@media screen and (min-width: 40em)': {
110+
width: '50%',
111+
}
112+
}}
113+
/>
114+
```
115+
99116
## Components
100117

101118
Theme UI includes a library of primitive UI components, which can be completely customized with your theme and include support for [variants](/components/variants).
119+
You can use variants to encapsulate more complex, component-specific styles that can be changed with props.
102120
Import and use these components to handle layout, images, forms, and more.
103121

104122
```jsx

packages/docs/src/pages/guides/object-styles.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ This also means that you can use JS math expressions to derive values.
4141
}
4242
```
4343

44+
To use other CSS units, use strings as values instead.
45+
46+
```js
47+
{
48+
fontSize: '2em',
49+
}
50+
```
51+
4452
## Commas
4553

4654
All properties should be separated by commas, not semicolons.

packages/docs/src/pages/index.mdx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ import Hexo from '../components/hexo'
77

88
<Hexo />
99

10-
Theme UI
10+
# Theme UI: The Design Graph Framework
11+
12+
Theme UI is a library for creating themeable user interfaces based on constraint-based design principles.
13+
Build custom component libraries, design systems, web applications, Gatsby themes, and more
14+
with a flexible API for best-in-class developer ergonomics.
1115

12-
# Build themeable design systems based on constraint-based design principles
1316

1417
[Documentation](/getting-started)
1518
[GitHub](https://github.com/system-ui/theme-ui)

packages/docs/src/pages/sx-prop.mdx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ title: 'The `sx` Prop'
88
The `sx` prop lets you style elements inline, using values from your theme.
99
To use the `sx` prop, add the custom `/** @jsx jsx */` pragma comment to the top of your module and import the `jsx` function.
1010

11+
The `sx` prop lets you add any valid CSS to an element,
12+
while using values from your theme to keep styles consistent.
13+
You can think of the style object that the `sx` prop accepts as a *superset* of CSS.
14+
1115
```jsx
1216
/** @jsx jsx */
1317
import { jsx } from 'theme-ui'
@@ -124,6 +128,21 @@ export default props => (
124128
)
125129
```
126130

131+
### Media Queries
132+
133+
If you prefer standard CSS media query syntax, you can use nested objects for responsive styles as well.
134+
135+
```jsx
136+
<div
137+
sx={{
138+
width: '100%',
139+
'@media screen and (min-width: 40em)': {
140+
width: '50%',
141+
}
142+
}}
143+
/>
144+
```
145+
127146
## Margin and Padding
128147

129148
Margin and padding are treated as first-class citizens in Theme UI,
@@ -167,7 +186,7 @@ export default props => (
167186
In some cases you might want to apply styles to children of the current element.
168187
You can do so with Emotion's [nested selectors](https://emotion.sh/docs/nested).
169188

170-
If you want to reference the current class of the component, you can use the [`&`](https://emotion.sh/docs/object-styles#child-selectors) symbol.
189+
If you want to reference the current class selector of the component, you can use the [`&`](https://emotion.sh/docs/object-styles#child-selectors) symbol.
171190

172191
```jsx
173192
/** @jsx jsx */
@@ -230,3 +249,7 @@ import { Box } from 'theme-ui'
230249
</Box>
231250
```
232251

252+
## Object Styles
253+
254+
If you're new to using JavaScript object notation for authoring styles, see the [guide to using objects for styling](/guides/object-styles).
255+

packages/docs/src/pages/theme-spec.mdx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ import ThemeScales from '../components/theme-scales'
66

77
# Theme Specification
88

9-
Theme UI is based on the [System UI Theme Specification][], with a few **optional** additions.
10-
The top-level naming convention used in the `theme` object come from this specification.
11-
Additionally, naming conventions for colors and typography are included
12-
to help ensure deeper interoperability with components from various other libraries.
13-
This is also intended to help ensure that themes created for Theme UI are suitable for white-label applications and general purpose theming.
9+
Theme UI is based on a theme specification, which can be used in other libraries and applications for increased interoperability.
10+
This specification is also intended to help ensure that themes created for Theme UI are suitable for white-label applications and general purpose theming.
1411

1512
The theme object is made up of the following data types:
1613

@@ -73,11 +70,6 @@ The `theme.colors` scale (i.e. color palette) should be an object literal with t
7370

7471
Other color keys can be added, including raw color values for aliasing the values above.
7572

76-
<!--
77-
## Aliasing Colors
78-
TK
79-
-->
80-
8173
## Color Modes
8274

8375
To use Theme UI color modes, color scales should include _at least_ a `text` and `background` color.
@@ -151,6 +143,8 @@ Font sizes are typically defined as an array, from smallest to largest.
151143
}
152144
```
153145

146+
Number values will be converted to pixel units. For other units, use string values, e.g. `'1em'`.
147+
154148
<Note>
155149

156150
Arrays are _not_ required, and plain objects will work as well.
@@ -252,6 +246,13 @@ The Theme UI `styles` object is primarily used as a way to style MDX content
252246
and helps avoid the need to use global CSS.
253247
The styles defined within this object can also be used with the [`Styled`](/styled) component.
254248

249+
<Note>
250+
251+
The `styles` object is essentially an MDX-specific *variant*
252+
that maps directly to each MDX component.
253+
254+
</Note>
255+
255256
The `theme.styles` object may include the following keys, which map to elements that can be rendered by markdown:
256257

257258
- `p` (paragraph)
@@ -332,6 +333,12 @@ Variants can also be used within the `theme.styles` object.
332333
}
333334
```
334335

336+
## Aliasing Colors and Other Scales
337+
338+
In many design systems, developers choose to create an additional layer of abstraction for mapping individual components to specific scale values.
339+
With Theme UI, *variants* are the mechanism to use for such abstractions.
340+
341+
335342
## Breakpoints
336343

337344
To configure the default breakpoints used in responsive array values, add a `breakpoints` array to your theme.

packages/docs/src/pages/theming.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ Core typographic values can be stored in the following theme keys:
5858
- `lineHeights`
5959
- `letterSpacings`
6060

61+
<Note>
62+
63+
Values defined as numbers are converted to pixel units where appropriate.
64+
For other units, use string values, e.g. `'1em'`.
65+
66+
</Note>
67+
6168
```js
6269
// example theme object
6370
{

0 commit comments

Comments
 (0)