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

Commit d6ff659

Browse files
author
Andrey Okonetchnikov
committed
docs: Add a theme example
1 parent 4fd9f4c commit d6ff659

File tree

3 files changed

+139
-0
lines changed

3 files changed

+139
-0
lines changed

src/examples/Readme.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
### Component-driven Design Systems Workshop
2+
3+
```jsx harmony
4+
import theme from "./cdds";
5+
import { Colors, Spacing, Typography } from "../";
6+
7+
<>
8+
<Colors theme={theme} />
9+
<Spacing theme={theme} />
10+
<Typography theme={theme} />
11+
</>;
12+
```

src/examples/cdds.js

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import { modularScale } from "polished";
2+
3+
const scale = value => modularScale(value, "1rem", "goldenSection");
4+
5+
const fontSizes = {
6+
xl: scale(3),
7+
lg: scale(1),
8+
md: scale(0),
9+
sm: scale(-0.5),
10+
xs: scale(-0.75)
11+
};
12+
13+
const palette = {
14+
grey: [
15+
"rgb(255, 255, 255)",
16+
"rgb(250, 250, 250)",
17+
"rgb(246, 246, 246)",
18+
"rgb(225, 225, 225)",
19+
"rgb(187, 187, 187)",
20+
"rgb(126, 126, 126)",
21+
"rgb(51, 51, 51)"
22+
],
23+
purple: [
24+
"rgb(255, 230, 242)",
25+
"rgb(251, 209, 234)",
26+
"rgb(248, 188, 229)",
27+
"rgb(231, 143, 222)",
28+
"rgb(189, 96, 200)",
29+
"rgb(120, 51, 150)",
30+
"rgb(52, 18, 90)"
31+
]
32+
};
33+
34+
let invertedPalette = {};
35+
36+
Object.keys(palette).forEach(key => {
37+
invertedPalette[key] = [...palette[key]].reverse();
38+
});
39+
40+
function getColors(palette) {
41+
return {
42+
...palette,
43+
bg: palette.grey[0],
44+
base: palette.grey[6],
45+
primary: palette.purple[5],
46+
secondary: palette.grey[5],
47+
muted: palette.grey[2],
48+
hover: palette.purple[2],
49+
focus: palette.purple[1],
50+
error: "#d0453e",
51+
rating: "#f8c124"
52+
};
53+
}
54+
55+
const theme = {
56+
fonts: {
57+
body: "Helvetica Neue, Helvetica, Arial, sans-serif",
58+
heading: "Helvetica Neue, Helvetica, Arial, sans-serif",
59+
monospace: "Menlo, monospace"
60+
},
61+
fontSizes: {
62+
base: fontSizes.m,
63+
...fontSizes
64+
},
65+
fontWeights: {
66+
normal: 400,
67+
bold: 700
68+
},
69+
headingFontWeights: {
70+
xl: 400,
71+
l: 400,
72+
m: 700
73+
},
74+
lineHeights: {
75+
base: 1.5,
76+
heading: 1.1
77+
},
78+
palette,
79+
colors: getColors(palette),
80+
borders: {
81+
none: "none",
82+
thin: "1px solid"
83+
},
84+
radii: {
85+
base: "0.15em"
86+
},
87+
space: [
88+
0,
89+
"0.125rem", // 2px
90+
"0.25rem", // 4px
91+
"0.5rem", // 8px
92+
"1rem", // 16px
93+
"2rem", // 32px
94+
"4rem", // 64px
95+
"8rem", // 128px
96+
"16rem" // 256px
97+
],
98+
textStyles: {
99+
base: {},
100+
secondary: {
101+
color: palette.grey[5]
102+
},
103+
tertiary: {
104+
color: palette.grey[5],
105+
fontSize: fontSizes.s
106+
},
107+
error: {
108+
color: getColors(palette).error
109+
}
110+
}
111+
};
112+
113+
export default theme;
114+
115+
export const inverted = {
116+
...theme,
117+
colors: {
118+
...getColors(invertedPalette),
119+
primary: invertedPalette.grey[4],
120+
hover: invertedPalette.grey[6],
121+
focus: invertedPalette.grey[1]
122+
}
123+
};

styleguide.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ module.exports = {
2020
{
2121
name: "Components",
2222
components: "src/components/*.jsx"
23+
},
24+
{
25+
name: "Examples",
26+
content: "src/examples/Readme.md"
2327
}
2428
],
2529
ribbon: {

0 commit comments

Comments
 (0)