@@ -7,34 +7,40 @@ import {
77 DIRECTION_ROW ,
88 Flex ,
99 JUSTIFY_SPACE_BETWEEN ,
10- LegacyStyledText ,
1110 SPACING ,
11+ StyledText ,
1212 TYPOGRAPHY ,
1313} from '@opentrons/components'
1414
15- import type { Meta , Story } from '@storybook/react'
15+ import type { Meta , StoryFn } from '@storybook/react'
1616
1717export default {
1818 title : 'Design Tokens/Colors' ,
1919} as Meta
2020
2121interface ColorsStorybookProps {
22- colors : string [ ]
22+ colors : Array < [ string , string ] >
2323}
2424
25- const Template : Story < ColorsStorybookProps > = args => {
25+ const Template : StoryFn < ColorsStorybookProps > = args => {
2626 const targetColors = args . colors
27- const colorCategories = targetColors . reduce ( ( acc , color ) => {
28- const match = color [ 0 ] . match ( / [ a - z A - Z ] + / )
29- const category = match ?. [ 0 ]
30- if ( category ) {
31- if ( ! acc [ category ] ) {
32- acc [ category ] = [ ]
27+ const colorCategories : Record <
28+ string ,
29+ Array < [ string , string ] >
30+ > = targetColors . reduce (
31+ ( acc : Record < string , Array < [ string , string ] > > , color : [ string , string ] ) => {
32+ const match = color [ 0 ] . match ( / [ a - z A - Z ] + / )
33+ const category = match ?. [ 0 ]
34+ if ( category ) {
35+ if ( ! acc [ category ] ) {
36+ acc [ category ] = [ ]
37+ }
38+ acc [ category ] . push ( color )
3339 }
34- acc [ category ] . push ( color )
35- }
36- return acc
37- } , { } )
40+ return acc
41+ } ,
42+ { } as Record < string , Array < [ string , string ] > >
43+ )
3844
3945 const invertColor = ( hex : string ) : string => {
4046 if ( hex . indexOf ( '#' ) === 0 ) {
@@ -58,44 +64,47 @@ const Template: Story<ColorsStorybookProps> = args => {
5864
5965 return (
6066 < Flex flexDirection = { DIRECTION_ROW } padding = { SPACING . spacing16 } >
61- { Object . entries ( colorCategories ) . map ( ( [ category , colors ] , index ) => (
62- < Flex key = { `category_${ index } ` } flexDirection = { DIRECTION_COLUMN } >
63- { colors . map ( ( color , colorIndex ) => (
64- < Flex
65- className = { `color_${ colorIndex } ` }
66- key = { `color_${ colorIndex } ` }
67- flexDirection = { DIRECTION_COLUMN }
68- alignItems = { ALIGN_FLEX_START }
69- justifyContent = { JUSTIFY_SPACE_BETWEEN }
70- backgroundColor = { color [ 1 ] }
71- padding = { SPACING . spacing40 }
72- width = "12rem"
73- height = "12rem"
74- margin = { SPACING . spacing2 } // Add some margin between color rows
75- borderRadius = { BORDERS . borderRadius4 }
76- style = { {
77- cursor : CURSOR_POINTER ,
78- border : `1px solid ${ COLORS . grey20 } ` ,
79- } }
80- >
81- < LegacyStyledText
82- color = { invertColor ( color [ 1 ] as string ) }
83- fontSize = { TYPOGRAPHY . fontSizeP }
84- fontWeight = { TYPOGRAPHY . fontWeightBold }
85- >
86- { color [ 0 ] }
87- </ LegacyStyledText >
88- < LegacyStyledText
89- fontSize = { TYPOGRAPHY . fontSizeP }
90- color = { invertColor ( color [ 1 ] as string ) }
91- fontWeight = { TYPOGRAPHY . fontWeightRegular }
67+ { Object . keys ( colorCategories ) . map ( ( category , index ) => {
68+ const colors = colorCategories [ category ]
69+ return (
70+ < Flex key = { `category_${ index } ` } flexDirection = { DIRECTION_COLUMN } >
71+ { colors . map ( ( color : [ string , string ] , colorIndex ) => (
72+ < Flex
73+ className = { `color_${ colorIndex } ` }
74+ key = { `color_${ colorIndex } ` }
75+ flexDirection = { DIRECTION_COLUMN }
76+ alignItems = { ALIGN_FLEX_START }
77+ justifyContent = { JUSTIFY_SPACE_BETWEEN }
78+ backgroundColor = { color [ 1 ] }
79+ padding = { SPACING . spacing40 }
80+ width = "12rem"
81+ height = "12rem"
82+ margin = { SPACING . spacing2 } // Add some margin between color rows
83+ borderRadius = { BORDERS . borderRadius4 }
84+ style = { {
85+ cursor : CURSOR_POINTER ,
86+ border : `1px solid ${ COLORS . grey20 } ` ,
87+ } }
9288 >
93- { color [ 1 ] }
94- </ LegacyStyledText >
95- </ Flex >
96- ) ) }
97- </ Flex >
98- ) ) }
89+ < StyledText
90+ color = { invertColor ( color [ 1 ] as string ) }
91+ fontSize = { TYPOGRAPHY . fontSizeP }
92+ fontWeight = { TYPOGRAPHY . fontWeightBold }
93+ >
94+ { color [ 0 ] }
95+ </ StyledText >
96+ < StyledText
97+ fontSize = { TYPOGRAPHY . fontSizeP }
98+ color = { invertColor ( color [ 1 ] as string ) }
99+ fontWeight = { TYPOGRAPHY . fontWeightRegular }
100+ >
101+ { color [ 1 ] }
102+ </ StyledText >
103+ </ Flex >
104+ ) ) }
105+ </ Flex >
106+ )
107+ } ) }
99108 </ Flex >
100109 )
101110}
0 commit comments