|
1 | 1 | import React from 'react'; |
2 | 2 | import { storiesOf } from '@storybook/react'; |
| 3 | +import Color from 'color'; |
3 | 4 |
|
4 | | -const BLUES = [ |
5 | | - 'ray-color-blue-10', |
6 | | - 'ray-color-blue-20', |
7 | | - 'ray-color-blue-50', |
8 | | - 'ray-color-blue-60', |
9 | | - 'ray-color-blue-70' |
10 | | -]; |
| 5 | +import * as rayVars from '../src/ray-exports.scss'; |
11 | 6 |
|
12 | | -const REDS = [ |
13 | | - 'ray-color-red-10', |
14 | | - 'ray-color-red-20', |
15 | | - 'ray-color-red-50', |
16 | | - 'ray-color-red-60', |
17 | | - 'ray-color-red-70' |
18 | | -]; |
19 | | - |
20 | | -const GREENS = [ |
21 | | - 'ray-color-green-10', |
22 | | - 'ray-color-green-20', |
23 | | - 'ray-color-green-70', |
24 | | - 'ray-color-green-80', |
25 | | - 'ray-color-green-90' |
26 | | -]; |
27 | | - |
28 | | -const GRAYS = [ |
29 | | - 'ray-color-gray-02', |
30 | | - 'ray-color-gray-10', |
31 | | - 'ray-color-gray-30', |
32 | | - 'ray-color-gray-50', |
33 | | - 'ray-color-gray-60' |
34 | | -]; |
| 7 | +storiesOf('Colors', module).add('all', () => { |
| 8 | + const colorKeys = Object.keys(rayVars).filter(rayVariable => |
| 9 | + rayVariable.startsWith('ray-color-') |
| 10 | + ); |
35 | 11 |
|
36 | | -const Color = function(props) { |
37 | 12 | return ( |
38 | | - <div |
39 | | - {...props} |
40 | | - style={{ |
41 | | - width: '100%', |
42 | | - height: `calc(${100 / 6}vh - 4px)`, |
43 | | - marginRight: '0.5rem', |
44 | | - fontSize: '1.25rem', |
45 | | - fontWeight: 600, |
46 | | - color: '#fff', |
47 | | - display: 'flex', |
48 | | - flexDirection: 'column', |
49 | | - textShadow: '0 1px 4px rgba(0,0,0,.1)' |
50 | | - }} |
51 | | - /> |
52 | | - ); |
53 | | -}; |
| 13 | + <div className="ray-grid"> |
| 14 | + <div className="ray-grid__inner"> |
| 15 | + <table className="ray-table color-table"> |
| 16 | + <thead> |
| 17 | + <tr> |
| 18 | + <th>variable</th> |
| 19 | + <th>hsl</th> |
| 20 | + <th>rgb</th> |
| 21 | + <th>hex</th> |
| 22 | + </tr> |
| 23 | + </thead> |
| 24 | + <tbody> |
| 25 | + {colorKeys.map(colorKey => { |
| 26 | + const color = Color(rayVars[colorKey]); |
| 27 | + const textColor = color.isDark() ? 'white' : 'black'; |
54 | 28 |
|
55 | | -storiesOf('Colors', module).add('all', () => ( |
56 | | - <div className="ray-grid"> |
57 | | - <div className="ray-grid__inner"> |
58 | | - <div |
59 | | - className="ray-grid__cell--span-2-phone ray-grid__cell--span-4-tablet ray-grid__cell--span-6-desktop" |
60 | | - style={{ |
61 | | - marginBottom: '24px' |
62 | | - }} |
63 | | - > |
64 | | - <Color className="ray-color-white" /> |
65 | | - </div> |
66 | | - <div |
67 | | - className="ray-grid__cell--span-2-phone ray-grid__cell--span-4-tablet ray-grid__cell--span-6-desktop" |
68 | | - style={{ |
69 | | - marginBottom: '24px' |
70 | | - }} |
71 | | - > |
72 | | - <Color className="ray-color-black" /> |
73 | | - </div> |
74 | | - <div className="ray-grid__cell--span-1-phone ray-grid__cell--span-2-tablet ray-grid__cell--span-3-desktop"> |
75 | | - {GRAYS.map(color => ( |
76 | | - <Color className={color} /> |
77 | | - ))} |
78 | | - </div> |
79 | | - <div className="ray-grid__cell--span-1-phone ray-grid__cell--span-2-tablet ray-grid__cell--span-3-desktop"> |
80 | | - {BLUES.map(color => ( |
81 | | - <Color className={color} /> |
82 | | - ))} |
83 | | - </div> |
84 | | - <div className="ray-grid__cell--span-1-phone ray-grid__cell--span-2-tablet ray-grid__cell--span-3-desktop"> |
85 | | - {REDS.map(color => ( |
86 | | - <Color className={color} /> |
87 | | - ))} |
88 | | - </div> |
89 | | - <div className="ray-grid__cell--span-1-phone ray-grid__cell--span-2-tablet ray-grid__cell--span-3-desktop"> |
90 | | - {GREENS.map(color => ( |
91 | | - <Color className={color} /> |
92 | | - ))} |
| 29 | + return ( |
| 30 | + <tr |
| 31 | + key={colorKey} |
| 32 | + style={{ |
| 33 | + padding: 0 |
| 34 | + }} |
| 35 | + > |
| 36 | + <td> |
| 37 | + <div |
| 38 | + style={{ |
| 39 | + backgroundColor: rayVars[colorKey], |
| 40 | + display: 'inline-block', |
| 41 | + padding: '.25rem .5rem', |
| 42 | + marginRight: '1rem', |
| 43 | + verticalAlign: 'middle', |
| 44 | + color: textColor, |
| 45 | + borderRadius: '0.25rem' |
| 46 | + }} |
| 47 | + > |
| 48 | + <pre>${colorKey}</pre> |
| 49 | + </div> |
| 50 | + </td> |
| 51 | + <td> |
| 52 | + <pre |
| 53 | + style={{ |
| 54 | + display: 'inline-block', |
| 55 | + verticalAlign: 'middle' |
| 56 | + }} |
| 57 | + > |
| 58 | + {color |
| 59 | + .hsl() |
| 60 | + .round() |
| 61 | + .string()} |
| 62 | + </pre> |
| 63 | + </td> |
| 64 | + <td> |
| 65 | + <pre |
| 66 | + style={{ |
| 67 | + display: 'inline-block', |
| 68 | + verticalAlign: 'middle' |
| 69 | + }} |
| 70 | + > |
| 71 | + {color.rgb().string()} |
| 72 | + </pre> |
| 73 | + </td> |
| 74 | + <td> |
| 75 | + <pre |
| 76 | + style={{ |
| 77 | + display: 'inline-block', |
| 78 | + verticalAlign: 'middle' |
| 79 | + }} |
| 80 | + > |
| 81 | + {color.hex().toString()} |
| 82 | + </pre> |
| 83 | + </td> |
| 84 | + </tr> |
| 85 | + ); |
| 86 | + })} |
| 87 | + </tbody> |
| 88 | + </table> |
93 | 89 | </div> |
94 | 90 | </div> |
95 | | - </div> |
96 | | -)); |
| 91 | + ); |
| 92 | +}); |
0 commit comments