11import React from 'react' ;
2-
32import { lightTheme as lightThemeJS , darkTheme as darkThemeJS } from '../src' ;
43import brandColor from '../src/figma/brandColors.json' ;
54import { ColorSwatch , ColorSwatchGroup } from './components' ;
65import README from './ThemeColors.mdx' ;
7- import { getCSSVariablesFromStylesheet , useJsonColor } from './utils' ;
6+ import {
7+ getCSSVariablesFromStylesheet ,
8+ getContrastYIQ ,
9+ getJSColors ,
10+ useJsonColor ,
11+ } from './utils' ;
812
913export default {
1014 title : 'Colors/Theme Colors' ,
@@ -43,9 +47,7 @@ export const FigmaDarkTheme = {
4347 >
4448 < ColorSwatchGroup
4549 swatchData = { darkTheme }
46- borderColor = { darkTheme . border . muted . value }
47- textBackgroundColor = { darkTheme . background . default . value }
48- textColor = { darkTheme . text . default . value }
50+ theme = { darkTheme ?. background ?. default ?. value }
4951 />
5052 </ div >
5153 ) ;
@@ -74,6 +76,11 @@ export const CSSLightTheme = {
7476 < ColorSwatch
7577 key = { name }
7678 color = { color }
79+ textBackgroundColor = "transparent"
80+ textColor = { getContrastYIQ (
81+ color ,
82+ lightThemeJS . colors . background . default , // TODO Use CSS instead of JS object once CSS object is cleaned up
83+ ) }
7784 backgroundColor = { colorName }
7885 name = { colorName }
7986 />
@@ -110,8 +117,11 @@ export const CSSDarkTheme = {
110117 name = { colorName }
111118 backgroundColor = { colorName }
112119 borderColor = "var(--color-border-muted)"
113- textBackgroundColor = "var(--color-background-default)"
114- textColor = "var(--color-text-default)"
120+ textBackgroundColor = "transparent"
121+ textColor = { getContrastYIQ (
122+ color ,
123+ darkThemeJS . colors . background . default , // TODO Use CSS instead of JS object once CSS object is cleaned up
124+ ) }
115125 />
116126 ) ,
117127 ) }
@@ -137,62 +147,60 @@ export const CSSDarkTheme = {
137147} ;
138148
139149export const JSLightTheme = {
140- render : ( ) => (
141- < div
142- style = { {
143- display : 'grid' ,
144- gap : '16px' ,
145- gridTemplateColumns : 'repeat(auto-fill, 300px)' ,
146- } }
147- >
148- { Object . entries ( lightThemeJS . colors ) . flatMap ( ( [ category , colorObj ] ) =>
149- Object . entries ( colorObj ) . map ( ( [ name , color ] ) => (
150+ render : ( ) => {
151+ const colors = getJSColors ( lightThemeJS . colors ) ;
152+ return (
153+ < div
154+ style = { {
155+ display : 'grid' ,
156+ gap : '16px' ,
157+ gridTemplateColumns : 'repeat(auto-fill, 300px)' ,
158+ } }
159+ >
160+ { colors . map ( ( { name, color } ) => (
150161 < ColorSwatch
151- key = { ` ${ category } - ${ name } ` }
162+ key = { name }
152163 color = { color }
153- name = { `color.${ category } .${ name } ` }
164+ textBackgroundColor = "transparent"
165+ textColor = { getContrastYIQ (
166+ color ,
167+ lightThemeJS . colors . background . default ,
168+ ) }
169+ name = { name }
154170 />
155- ) ) ,
156- ) }
157- </ div >
158- ) ,
171+ ) ) }
172+ </ div >
173+ ) ;
174+ } ,
159175} ;
160176
161177export const JSDarkTheme = {
162- render : ( ) => (
163- < div
164- style = { {
165- backgroundColor : darkThemeJS . colors . background . default ,
166- margin : '-1rem' ,
167- padding : '1rem' ,
168- } }
169- >
178+ render : ( ) => {
179+ const colors = getJSColors ( darkThemeJS . colors ) ;
180+ return (
170181 < div
171182 style = { {
172183 display : 'grid' ,
173184 gap : '16px' ,
174185 gridTemplateColumns : 'repeat(auto-fill, 300px)' ,
186+ padding : '1rem' ,
187+ margin : '-1rem' , // negates storybook padding and removes white border
188+ backgroundColor : darkThemeJS . colors . background . default ,
175189 } }
176190 >
177- { Object . entries ( darkThemeJS . colors ) . flatMap ( ( [ category , colorObj ] ) =>
178- Object . entries ( colorObj ) . map ( ( [ name , color ] ) => (
179- < ColorSwatch
180- key = { ` ${ category } - ${ name } ` }
181- color = { color }
182- name = { `color. ${ category } . ${ name } ` }
183- borderColor = { darkThemeJS . colors . border . muted }
184- textBackgroundColor = { darkThemeJS . colors . background . default }
185- textColor = { darkThemeJS . colors . text . default }
186- />
187- ) ) ,
188- ) }
191+ { colors . map ( ( { name , color } ) => (
192+ < ColorSwatch
193+ key = { name }
194+ color = { color }
195+ textBackgroundColor = "transparent"
196+ textColor = { getContrastYIQ (
197+ color ,
198+ darkThemeJS . colors . background . default ,
199+ ) }
200+ name = { name }
201+ />
202+ ) ) }
189203 </ div >
190- </ div >
191- ) ,
192- parameters : {
193- backgrounds : {
194- default : 'dark' ,
195- values : [ { name : 'dark' , value : darkThemeJS . colors . background . default } ] ,
196- } ,
204+ ) ;
197205 } ,
198206} ;
0 commit comments