Skip to content
This repository was archived by the owner on Mar 14, 2021. It is now read-only.

Commit b8d45ef

Browse files
Andrey Okonetchnikovokonet
authored andcommitted
feat: Migrate to Theme UI
1 parent e9d6df0 commit b8d45ef

File tree

12 files changed

+380
-237
lines changed

12 files changed

+380
-237
lines changed

package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,21 @@
3333
"react-dom": "^16.8.0"
3434
},
3535
"dependencies": {
36-
"@emotion/core": "^10.0.10",
37-
"@emotion/styled": "^10.0.11",
38-
"@mdx-js/react": "^1.0.20",
3936
"clipboard-copy": "^3.0.0",
4037
"lodash": "^4.17.11",
4138
"polished": "^3.4.0",
4239
"prop-types": "^15.7.2",
4340
"react": "^16.8.6",
4441
"react-dom": "^16.8.6",
45-
"stack-styled": "^2.0.0",
46-
"theme-ui": "^0.1.3"
42+
"theme-ui": "^0.3.1"
4743
},
4844
"devDependencies": {
4945
"@babel/cli": "^7.4.4",
5046
"@babel/core": "^7.4.5",
5147
"@babel/preset-env": "^7.4.5",
5248
"@babel/preset-react": "^7.0.0",
5349
"@babel/preset-typescript": "^7.3.3",
50+
"@emotion/styled": "^10.0.11",
5451
"@emotion/babel-preset-css-prop": "^10.0.9",
5552
"babel-loader": "^8.0.6",
5653
"husky": "^2.4.0",

src/components/ColorSwatch.jsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
1+
/* @jsx jsx */
2+
import { jsx } from "theme-ui";
13
import React from "react";
2-
import PropTypes from "prop-types";
34
import { readableColor } from "polished";
45
import { Swatch, SwatchToken, SwatchValue } from "../";
5-
import { css } from "theme-ui";
66
import { tokenPropType, valuePropType } from "../propTypes";
77

88
export const ColorSwatch = ({ value, token }) => {
9-
const color = readableColor(
10-
value,
11-
"rgba(0, 0, 0, 0.75)",
12-
"rgba(255, 255, 255, 0.75)"
13-
);
9+
const color = readableColor(value, "black", "white");
1410
return (
1511
<Swatch token={token} value={value}>
1612
<div
17-
css={css({
13+
sx={{
1814
p: 3,
1915
pt: 6,
2016
bg: value,
2117
overflow: "hidden"
22-
})}
18+
}}
2319
>
2420
<SwatchToken color={color}>{token}</SwatchToken>
2521
<SwatchValue color={color}>{value}</SwatchValue>

src/components/Colors.jsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from "react";
2-
import { ThemeProvider } from "theme-ui";
2+
import { Grid, ThemeProvider } from "theme-ui";
33
import { omitBy, pickBy, isString } from "lodash";
4-
import Stack from "stack-styled/emotion/Stack.js";
54
import { Swatches, ColorSwatch, PaletteSwatch } from "../index";
65

76
export default function Colors({ theme }) {
@@ -10,22 +9,33 @@ export default function Colors({ theme }) {
109
const palettes = omitBy(theme.colors, isString);
1110
return (
1211
<ThemeProvider theme={theme}>
13-
<Stack gap={gap}>
12+
<Grid gap={gap}>
1413
<Swatches theme={theme} items={palettes}>
1514
{(token, value) => (
16-
<Stack gap={0} minWidth={100} key={token}>
15+
<Grid
16+
gap={0}
17+
key={token}
18+
sx={{
19+
gridTemplateColumns: "repeat(auto-fit, minmax(90px, 1fr))"
20+
}}
21+
>
1722
<PaletteSwatch token={token} value={value} />
18-
</Stack>
23+
</Grid>
1924
)}
2025
</Swatches>
21-
<Stack gap={gap} minWidth={150}>
26+
<Grid
27+
gap={gap}
28+
sx={{
29+
gridTemplateColumns: "repeat(auto-fit, minmax(90px, 1fr))"
30+
}}
31+
>
2232
<Swatches theme={theme} items={colors}>
2333
{(token, value) => (
2434
<ColorSwatch token={token} value={value} key={token} />
2535
)}
2636
</Swatches>
27-
</Stack>
28-
</Stack>
37+
</Grid>
38+
</Grid>
2939
</ThemeProvider>
3040
);
3141
}

src/components/Spacing.jsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1+
/* @jsx jsx */
12
import React from "react";
2-
import { css, ThemeProvider } from "theme-ui";
3-
import { Swatches, Swatch, SpacingSwatch, SwatchToken } from "../index";
4-
import Stack from "stack-styled/emotion/Stack.js";
3+
import { Grid, jsx, ThemeProvider } from "theme-ui";
4+
import { SpacingSwatch, Swatch, Swatches, SwatchToken } from "../index";
55

66
export default function Spacing({ theme }) {
77
return (
88
<ThemeProvider theme={theme}>
9-
<Stack gap={4}>
9+
<Grid gap={4}>
1010
<Swatches items={theme.space}>
1111
{(token, value) => (
1212
<Swatch token={token} value={value} key={token}>
13-
<Stack gap={3} gridTemplateColumns="auto 1fr">
14-
<SwatchToken css={css({ p: 1 })}>{token}</SwatchToken>
13+
<Grid
14+
gap={3}
15+
sx={{ alignItems: "center", gridTemplateColumns: "auto 1fr" }}
16+
>
17+
<SwatchToken>{token}</SwatchToken>
1518
<SpacingSwatch value={value} />
16-
</Stack>
19+
</Grid>
1720
</Swatch>
1821
)}
1922
</Swatches>
20-
</Stack>
23+
</Grid>
2124
</ThemeProvider>
2225
);
2326
}

src/components/SpacingSwatch.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1+
/* @jsx jsx */
12
import React from "react";
2-
import PropTypes from "prop-types";
3-
import { css } from "theme-ui";
3+
import { jsx } from "theme-ui";
44
import { SwatchValue } from "../";
55
import { valuePropType } from "../propTypes";
66

77
const SpacingSwatch = ({ value, css: componentCSS, ...rest }) => {
88
return (
99
<div
10-
css={css({
10+
sx={{
1111
p: 2,
1212
color: "secondary",
1313
bg: "muted",
1414
width: value,
1515
...componentCSS
16-
})}
16+
}}
1717
{...rest}
1818
>
1919
<SwatchValue color="inherit">{value}</SwatchValue>

src/components/SwatchToken.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
/* @jsx jsx */
2+
import { jsx } from "theme-ui";
13
import React from "react";
2-
import { css } from "theme-ui";
34

45
function SwatchToken({ color = "text", css: componentCSS, ...rest }) {
56
return (
67
<h3
7-
css={css({
8+
sx={{
89
m: 0,
910
fontFamily: "body",
1011
fontSize: "sm",
1112
fontWeight: "normal",
1213
color,
1314
...componentCSS
14-
})}
15+
}}
1516
{...rest}
1617
/>
1718
);

src/components/SwatchValue.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
/* @jsx jsx */
2+
import { jsx } from "theme-ui";
13
import React from "react";
2-
import { css } from "theme-ui";
34

45
function SwatchValue({ color = "secondary", css: componentCSS, ...rest }) {
56
return (
67
<p
7-
css={css({
8+
sx={{
89
m: 0,
910
fontFamily: "monospace",
1011
fontSize: "xs",
1112
whiteSpace: "nowrap",
1213
color,
1314
...componentCSS
14-
})}
15+
}}
1516
{...rest}
1617
/>
1718
);

src/components/Swatches.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
```jsx harmony
2-
import Stack from "stack-styled/emotion/Stack.js";
2+
import { Grid } from "theme-ui";
33
import theme from "../theme";
4-
import { Swatch, SwatchToken, SpacingSwatch } from "../";
4+
import { Swatch, Swatches, SwatchToken, SpacingSwatch } from "../";
55

6-
<Stack gap={2}>
6+
<Grid gap={4}>
77
<Swatches theme={theme} items={theme.space}>
88
{(token, value) => (
99
<Swatch token={token} value={value} key={token}>
@@ -12,5 +12,5 @@ import { Swatch, SwatchToken, SpacingSwatch } from "../";
1212
</Swatch>
1313
)}
1414
</Swatches>
15-
</Stack>;
15+
</Grid>;
1616
```

src/components/TextStyleSwatch.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
/* @jsx jsx */
2+
import { jsx } from "theme-ui";
13
import React from "react";
2-
import { css } from "theme-ui";
34
import { valuePropType } from "../propTypes";
45

56
/**
@@ -12,12 +13,12 @@ import { valuePropType } from "../propTypes";
1213
*/
1314
const TextStyleSwatch = ({ value, css: componentCSS, ...rest }) => (
1415
<p
15-
css={css({
16+
sx={{
1617
alignSelf: "center",
1718
m: 0,
1819
...value,
1920
...componentCSS
20-
})}
21+
}}
2122
{...rest}
2223
/>
2324
);

src/components/Typography.jsx

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
/* @jsx jsx */
2+
import { Grid, jsx, ThemeProvider } from "theme-ui";
13
import React from "react";
2-
import { ThemeProvider, css } from "theme-ui";
3-
import Stack from "stack-styled/emotion/Stack.js";
44
import { Swatch, Swatches, SwatchToken, TextStyleSwatch } from "../";
55

66
/**
@@ -13,29 +13,27 @@ import { Swatch, Swatches, SwatchToken, TextStyleSwatch } from "../";
1313
export default function Typography({ theme }) {
1414
return (
1515
<ThemeProvider theme={theme}>
16-
<Stack gap={5}>
16+
<Grid gap={5}>
1717
<Swatches theme={theme} items={theme.textStyles || {}}>
1818
{(token, value) => (
1919
<Swatch token={token} value={value} key={token}>
20-
<Stack gap={2}>
21-
<div>
22-
<SwatchToken
23-
css={css({
24-
display: "inline-block",
25-
fontFamily: "monospace"
26-
})}
27-
>
28-
{token}
29-
</SwatchToken>
30-
</div>
20+
<Grid gap={3}>
21+
<SwatchToken
22+
sx={{
23+
display: "inline-block",
24+
fontFamily: "monospace"
25+
}}
26+
>
27+
{token}
28+
</SwatchToken>
3129
<TextStyleSwatch token={token} value={value}>
3230
The quick brown fox jumps over the lazy dog
3331
</TextStyleSwatch>
34-
</Stack>
32+
</Grid>
3533
</Swatch>
3634
)}
3735
</Swatches>
38-
</Stack>
36+
</Grid>
3937
</ThemeProvider>
4038
);
4139
}

0 commit comments

Comments
 (0)