Skip to content

Commit 1d618cf

Browse files
authored
Merge pull request #37 from component-driven/move-react-design-tokens
Move react-design-tokens package
2 parents 9327c79 + c4cea4f commit 1d618cf

40 files changed

+10100
-1195
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@component-driven/react-design-tokens": minor
3+
---
4+
5+
Move react-design-tokens package to https://github.com/component-driven/ui

README.md renamed to Readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
![Release](https://github.com/component-driven/ui/workflows/Release/badge.svg)
44

5-
This package includes:
5+
Includes following packages:
66

7+
- `react-design-tokens` — React components to document design tokens in a styleguide.
78
- `FocusWithin` component — the missing JS API of the CSS `:focus-within` for React
89
- `WithSelector` component to allow preview of pseudo-styles like `:hover` and `:focus` in styleguides
910
- `mixins` — a collection of mixins for pseudo styles (`:focus`, `:disabled`) to work with CSS-in-JS libraries

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
},
2727
"homepage": "https://react-focus-utils.netlify.com",
2828
"dependencies": {
29+
"find-up": "^5.0.0",
2930
"react": "^16.13.0",
3031
"react-dom": "^16.13.0",
3132
"styled-components": "^5.0.1"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# react-design-tokens
2+
3+
[![Build Status](https://travis-ci.org/component-driven/react-design-tokens.svg)](https://travis-ci.org/component-driven/react-design-tokens) [![npm](https://img.shields.io/npm/v/@component-driven/react-design-tokens.svg)](https://www.npmjs.com/package/@component-driven/react-design-tokens)
4+
5+
React components to document design tokens in a styleguide.
6+
7+
## Examples
8+
9+
### [Component-driven Design Systems Workshop](https://github.com/component-driven/component-driven-development) Design System
10+
11+
```jsx harmony
12+
import { Grid } from 'theme-ui'
13+
import theme from './src/examples/cdds'
14+
import { Colors, Spacing, Typography } from './src'
15+
16+
;<Grid gap={5}>
17+
<Colors theme={theme} />
18+
<Spacing theme={theme} />
19+
<Typography theme={theme} />
20+
</Grid>
21+
```
22+
23+
### GitHub Primer Design System
24+
25+
```jsx harmony
26+
import { Grid } from 'theme-ui'
27+
import theme from './src/examples/primer'
28+
import { Colors, Spacing, Typography } from './src'
29+
30+
;<Grid gap={5}>
31+
<Colors theme={theme} />
32+
<Spacing theme={theme} />
33+
<Typography theme={theme} />
34+
</Grid>
35+
```
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "@component-driven/react-design-tokens",
3+
"description": "React components to document design tokens in a styleguide",
4+
"version": "2.1.1",
5+
"main": "dist/react-design-tokens.cjs.js",
6+
"module": "dist/react-design-tokens.esm.js",
7+
"peerDependencies": {
8+
"react": ">=16.8.0",
9+
"react-dom": ">=16.8.0"
10+
},
11+
"dependencies": {
12+
"clipboard-copy": "^3.0.0",
13+
"lodash": "^4.17.11",
14+
"polished": "^3.4.0",
15+
"theme-ui": "^0.3.5"
16+
},
17+
"devDependencies": {
18+
"primer-colors": "^1.0.1",
19+
"primer-spacing": "^1.0.2",
20+
"primer-typography": "^1.0.1",
21+
"prop-types": "^15.7.2"
22+
},
23+
"author": "Andrey Okonetchnikov <andrey@okonet.ru>",
24+
"license": "MIT",
25+
"publishConfig": {
26+
"access": "public"
27+
}
28+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* @jsx jsx */
2+
import { jsx } from "theme-ui";
3+
import React from "react";
4+
import { readableColor } from "polished";
5+
import { Swatch, SwatchToken, SwatchValue } from "../";
6+
import { tokenPropType, valuePropType } from "../propTypes";
7+
8+
export const ColorSwatch = ({ value, token }) => {
9+
const color = readableColor(value, "black", "white");
10+
return (
11+
<Swatch token={token} value={value}>
12+
<div
13+
sx={{
14+
p: 3,
15+
pt: 6,
16+
bg: value,
17+
overflow: "hidden"
18+
}}
19+
>
20+
<SwatchToken color={color}>{token}</SwatchToken>
21+
<SwatchValue color={color}>{value}</SwatchValue>
22+
</div>
23+
</Swatch>
24+
);
25+
};
26+
27+
ColorSwatch.propTypes = {
28+
...tokenPropType,
29+
...valuePropType
30+
};
31+
32+
/** @component */
33+
export default ColorSwatch;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Renders a color swatch with a readable text.
2+
3+
```jsx harmony
4+
<ColorSwatch token={'accent'} value={'#C0100F'} />
5+
```
6+
7+
When clicked, the value of the token is copied to clipboard.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from "react";
2+
import { Grid, ThemeProvider } from "theme-ui";
3+
import { omitBy, pickBy, isString } from "lodash";
4+
import { Swatches, ColorSwatch, PaletteSwatch } from "../index";
5+
6+
export default function Colors({ theme }) {
7+
const gap = 2;
8+
const colors = pickBy(theme.colors, isString);
9+
const palettes = omitBy(theme.colors, isString);
10+
return (
11+
<ThemeProvider theme={theme}>
12+
<Grid gap={gap}>
13+
<Swatches theme={theme} items={palettes}>
14+
{(token, value) => (
15+
<Grid
16+
gap={0}
17+
key={token}
18+
sx={{
19+
gridTemplateColumns: "repeat(auto-fit, minmax(90px, 1fr))"
20+
}}
21+
>
22+
<PaletteSwatch token={token} value={value} />
23+
</Grid>
24+
)}
25+
</Swatches>
26+
<Grid
27+
gap={gap}
28+
sx={{
29+
gridTemplateColumns: "repeat(auto-fit, minmax(90px, 1fr))"
30+
}}
31+
>
32+
<Swatches theme={theme} items={colors}>
33+
{(token, value) => (
34+
<ColorSwatch token={token} value={value} key={token} />
35+
)}
36+
</Swatches>
37+
</Grid>
38+
</Grid>
39+
</ThemeProvider>
40+
);
41+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
```jsx harmony
2+
import theme from '../theme'
3+
4+
;<Colors theme={theme} />
5+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from "react";
2+
import PropTypes from "prop-types";
3+
import { Swatches, ColorSwatch } from "../index";
4+
import { tokenPropType, valuePropType } from "../propTypes";
5+
6+
export const PaletteSwatch = ({ token, value }) => (
7+
<Swatches items={value}>
8+
{(key, value) => (
9+
<ColorSwatch
10+
value={value}
11+
token={`${token}.${key}`}
12+
key={`${token}.${key}`}
13+
/>
14+
)}
15+
</Swatches>
16+
);
17+
18+
PaletteSwatch.propTypes = {
19+
...tokenPropType,
20+
...valuePropType
21+
};
22+
23+
/** @component */
24+
export default PaletteSwatch;

0 commit comments

Comments
 (0)