Skip to content
This repository was archived by the owner on Nov 26, 2024. It is now read-only.

Commit a6865ed

Browse files
chore: updating doc components and helpers
1 parent 779f1ef commit a6865ed

File tree

8 files changed

+314
-132
lines changed

8 files changed

+314
-132
lines changed

docs/BrandColors.stories.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import React from 'react';
22
import type { Meta, StoryObj } from '@storybook/react';
33
import { brandColor as brandColorJS } from '../src/js';
4-
import { getCSSVariablesFromStylesheet, useJsonColor } from './utils';
4+
import {
5+
getCSSVariablesFromStylesheet,
6+
getContrastYIQ,
7+
useJsonColor,
8+
} from './utils';
59
import { ColorSwatchGroup, ColorSwatch } from './components';
610
import README from './BrandColors.mdx';
711

@@ -22,6 +26,7 @@ type Story = StoryObj<typeof ColorSwatchGroup>;
2226
export const Figma: Story = {
2327
render: () => {
2428
const { brandColor } = useJsonColor();
29+
console.log(brandColor);
2530
return <ColorSwatchGroup swatchData={brandColor} />;
2631
},
2732
};
@@ -43,6 +48,8 @@ export const CSS: Story = {
4348
key={name}
4449
color={color}
4550
backgroundColor={name}
51+
textBackgroundColor="transparent"
52+
textColor={getContrastYIQ(color, color)}
4653
name={name}
4754
/>
4855
))}
@@ -62,7 +69,13 @@ export const JS: Story = {
6269
>
6370
{/* Mapping through each brand color and rendering a ColorSwatch component for it */}
6471
{Object.entries(brandColorJS).map(([name, color]) => (
65-
<ColorSwatch key={name} color={color} name={`brandColor.${name}`} />
72+
<ColorSwatch
73+
key={name}
74+
color={color}
75+
textBackgroundColor="transparent"
76+
textColor={getContrastYIQ(color, color)}
77+
name={`brandColor.${name}`}
78+
/>
6679
))}
6780
</div>
6881
),

docs/ThemeColors.stories.tsx

Lines changed: 58 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import React from 'react';
2-
32
import { lightTheme as lightThemeJS, darkTheme as darkThemeJS } from '../src';
43
import brandColor from '../src/figma/brandColors.json';
54
import { ColorSwatch, ColorSwatchGroup } from './components';
65
import README from './ThemeColors.mdx';
7-
import { getCSSVariablesFromStylesheet, useJsonColor } from './utils';
6+
import {
7+
getCSSVariablesFromStylesheet,
8+
getContrastYIQ,
9+
getJSColors,
10+
useJsonColor,
11+
} from './utils';
812

913
export 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

139149
export 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

161177
export 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

Comments
 (0)