Skip to content

Commit

Permalink
fix color system
Browse files Browse the repository at this point in the history
  • Loading branch information
vassbence committed Jul 11, 2024
1 parent 69dd562 commit 04f74de
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 148 deletions.
46 changes: 23 additions & 23 deletions src/assets/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,32 @@

/* Semantic colors */
--color-neutral-5: var(--color-black-5);
--color-neutral-10-background: var(--color-white-100);
--color-neutral-10-adjusted: var(--color-black-5);
--color-neutral-10: var(--color-black-10);
--color-neutral-20: var(--color-black-20);
--color-neutral-20-adjusted: var(--color-black-10);
--color-neutral-60: var(--color-black-60);
--color-neutral-80: var(--color-black-80);
--color-neutral-100: var(--color-black-100);
--color-neutral-inverted-5: var(--color-white-5);
--color-neutral-inverted-10: var(--color-white-10);
--color-neutral-inverted-5: var(--color-white-10);
--color-neutral-inverted-10: var(--color-white-20);
--color-neutral-inverted-20: var(--color-white-20);
--color-neutral-inverted-60: var(--color-white-60);
--color-neutral-inverted-60: var(--color-white-40);
--color-neutral-inverted-80: var(--color-white-80);
--color-neutral-inverted-100: var(--color-white-100);
--color-accent-5: var(--color-indigo-5);
--color-accent-10: var(--color-indigo-10);
--color-accent-20: var(--color-indigo-20);
--color-accent-60: var(--color-indigo-60);
--color-accent-80: var(--color-indigo-80);
--color-accent-100: var(--color-indigo-100);
--color-highlight-5: var(--color-indigo-5);
--color-highlight-10: var(--color-indigo-10);
--color-highlight-20: var(--color-indigo-20);
--color-highlight-60: var(--color-indigo-60);
--color-highlight-80: var(--color-indigo-80);
--color-highlight-100: var(--color-indigo-100);
--color-alert-5: var(--color-amber-5);
--color-alert-10: var(--color-amber-10);
--color-alert-20: var(--color-amber-20);
--color-alert-60: var(--color-amber-60);
--color-alert-80: var(--color-amber-80);
--color-alert-100: var(--color-amber-100);
--color-destructive-5: var(--color-red-5);
--color-destructive-10: var(--color-red-10);
--color-destructive-20: var(--color-red-20);
Expand Down Expand Up @@ -103,10 +112,13 @@

@media (prefers-color-scheme: dark) {
:root {
--color-neutral-5: var(--color-white-5);
--color-neutral-5: var(--color-black-5);
--color-neutral-10-background: var(--color-white-10);
--color-neutral-10-adjusted: var(--color-white-10);
--color-neutral-10: var(--color-white-10);
--color-neutral-20: var(--color-white-20);
--color-neutral-60: var(--color-white-60);
--color-neutral-20-adjusted: var(--color-white-20);
--color-neutral-60: var(--color-white-40);
--color-neutral-80: var(--color-white-80);
--color-neutral-100: var(--color-white-100);
--color-neutral-inverted-5: var(--color-black-5);
Expand All @@ -115,18 +127,6 @@
--color-neutral-inverted-60: var(--color-black-60);
--color-neutral-inverted-80: var(--color-black-80);
--color-neutral-inverted-100: var(--color-black-100);
--color-accent-5: var(--color-indigo-5);
--color-accent-10: var(--color-indigo-10);
--color-accent-20: var(--color-indigo-20);
--color-accent-60: var(--color-indigo-60);
--color-accent-80: var(--color-indigo-80);
--color-accent-100: var(--color-indigo-100);
--color-destructive-5: var(--color-red-5);
--color-destructive-10: var(--color-red-10);
--color-destructive-20: var(--color-red-20);
--color-destructive-60: var(--color-red-60);
--color-destructive-80: var(--color-red-80);
--color-destructive-100: var(--color-red-100);
}
}

Expand Down
16 changes: 15 additions & 1 deletion src/components/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,22 @@ export default {
component: Button,
}

export const Default = {
export const Primary = {
args: {
children: 'Button label',
variant: 'primary',
color: 'neutral',
disabled: false,
leadIcon: 'add',
},
}

export const Secondary = {
args: {
children: 'Button label',
variant: 'secondar',
color: 'neutral',
disabled: false,
leadIcon: 'add',
},
}
26 changes: 13 additions & 13 deletions src/components/Button/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react'
import { borderRadius } from '../../utils/border.js'
import { color, colorSwatch } from '../../utils/colors.js'
import { color } from '../../utils/colors.js'
import { Icon, IconProps } from '../Icon/index.js'
import { Text } from '../Text/index.js'

Expand Down Expand Up @@ -56,32 +56,32 @@ function Button({
outlineStyle: 'none',
...(variant === 'primary' &&
colorProp === 'neutral' && {
color: color('neutral-inverted', 100),
background: color('neutral', 100),
color: color('neutral-inverted-100'),
background: color('neutral-100'),
...(focus &&
!disabled && {
outlineWidth: 4,
outlineStyle: 'solid',
outlineColor: color('neutral', 20),
outlineColor: color('neutral-20'),
}),
...(disabled && {
color: color('neutral-inverted', 60),
background: color('neutral', 20),
color: color('neutral-inverted-60'),
background: color('neutral-20'),
}),
}),
...(variant === 'primary' &&
colorProp === 'destructive' && {
color: colorSwatch('white', 100),
background: color('destructive', 100),
color: color('white-100'),
background: color('destructive-100'),
...(focus &&
!disabled && {
outlineWidth: 4,
outlineStyle: 'solid',
outlineColor: color('destructive', 60),
outlineColor: color('destructive-60'),
}),
...(disabled && {
color: colorSwatch('white', 20),
background: color('destructive', 20),
color: color('white-20'),
background: color('destructive-20'),
}),
}),
}}
Expand All @@ -95,13 +95,13 @@ function Button({
colorProp === 'neutral' &&
(hover || focus) &&
!disabled && {
background: color('neutral-inverted', 20),
background: color('neutral-inverted-20'),
}),
...(variant === 'primary' &&
colorProp === 'destructive' &&
(hover || focus) &&
!disabled && {
background: color('neutral', 10),
background: color('neutral-10'),
}),
}}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Icon/Icon.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const Default = {
gap: 8,
padding: 16,
borderRadius: borderRadius(8),
background: color('neutral', 10),
background: color('neutral-10'),
cursor: 'pointer',
}}
onClick={() => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Text/Text.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export const Default = {
children: 'The quick brown fox jumps over the lazy dog',
align: 'left',
variant: 'display-regular',
color: 'neutral',
color: 'neutral-100',
},
}
19 changes: 4 additions & 15 deletions src/components/Text/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
COLORS,
Color,
ColorSwatch,
color,
colorSwatch,
} from '../../utils/colors.js'
import { Color, color } from '../../utils/colors.js'

type TextProps = {
children: string
Expand All @@ -19,26 +13,21 @@ type TextProps = {
| 'subtext-medium'
| 'subtext-bold'
align?: 'left' | 'center' | 'right'
color?: 'inherit' | Color | ColorSwatch
color?: 'inherit' | Color
}

function Text({
children,
variant = 'display-regular',
color: colorProp = 'neutral',
color: colorProp = 'neutral-100',
align = 'left',
}: TextProps) {
return (
<div
style={{
textAlign: align,
overflowWrap: 'break-word',
color:
colorProp === 'inherit'
? 'inherit'
: COLORS.includes(colorProp as Color)
? color(colorProp as Color)
: colorSwatch(colorProp as ColorSwatch),
color: colorProp === 'inherit' ? 'inherit' : color(colorProp),
fontFamily: 'var(--font-sans)',
lineHeight: 1,
letterSpacing: 'normal',
Expand Down
6 changes: 3 additions & 3 deletions src/utils/Border.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { COLORS, COLOR_ALPHAS, color } from './colors'
import { color } from './colors'
import { borderRadius, BORDER_RADII } from './border'
import { Text } from '../components/Text'

Expand Down Expand Up @@ -31,9 +31,9 @@ export const Default = {
style={{
width: 100,
height: 100,
background: color('neutral', 20),
background: color('neutral-20'),
borderRadius: borderRadius(b),
border: `1px solid ${color('neutral', 10)}`,
border: `1px solid ${color('neutral-10')}`,
}}
/>
<Text variant="subtext-bold">{b as string}</Text>
Expand Down
97 changes: 41 additions & 56 deletions src/utils/Colors.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import React from 'react'
import {
COLORS,
COLOR_ALPHAS,
COLOR_SWATCHES,
COLOR_SWATCH_ALPHAS,
color,
colorSwatch,
} from './colors'
import { COLORS, COLOR_SWATCHES, color } from './colors'
import { borderRadius } from './border'
import { Text } from '../components/Text'

Expand All @@ -22,32 +15,28 @@ export const Semantics = {
display: 'grid',
gap: 24,
gridAutoRows: '1fr',
gridTemplateColumns: `repeat(${COLOR_ALPHAS.length}, 1fr)`,
gridTemplateColumns: `repeat(9, 1fr)`,
}}
>
{COLORS.map((c) =>
[...COLOR_ALPHAS]
.sort((a, b) => b - a)
.map((alpha) => (
<div>
<div
style={{
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
gap: 8,
height: 64,
background: color(c, alpha),
borderRadius: borderRadius(8),
border: `1px solid ${color('neutral', 10)}`,
marginBottom: 16,
}}
/>
<Text variant="subtext-bold">{`${c.charAt(0).toUpperCase() + c.slice(1)} ${alpha}`}</Text>
</div>
)),
)}
{[...COLORS].map((c) => (
<div>
<div
style={{
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
gap: 8,
height: 64,
background: color(c),
borderRadius: borderRadius(8),
border: `1px solid ${color('neutral-10')}`,
marginBottom: 16,
}}
/>
<Text variant="subtext-bold">{c}</Text>
</div>
))}
</div>
),
}
Expand All @@ -59,32 +48,28 @@ export const Swatches = {
display: 'grid',
gap: 24,
gridAutoRows: '1fr',
gridTemplateColumns: `repeat(${COLOR_SWATCH_ALPHAS.length}, 1fr)`,
gridTemplateColumns: `repeat(9, 1fr)`,
}}
>
{COLOR_SWATCHES.map((swatch) =>
[...COLOR_SWATCH_ALPHAS]
.sort((a, b) => b - a)
.map((alpha) => (
<div>
<div
style={{
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
gap: 8,
height: 64,
background: colorSwatch(swatch, alpha),
borderRadius: borderRadius(8),
border: `1px solid ${color('neutral', 10)}`,
marginBottom: 16,
}}
/>
<Text variant="subtext-bold">{`${swatch.charAt(0).toUpperCase() + swatch.slice(1)} ${alpha}`}</Text>
</div>
)),
)}
{[...COLOR_SWATCHES].map((c) => (
<div>
<div
style={{
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
gap: 8,
height: 64,
background: color(c),
borderRadius: borderRadius(8),
border: `1px solid ${color('neutral-10')}`,
marginBottom: 16,
}}
/>
<Text variant="subtext-bold">{c}</Text>
</div>
))}
</div>
),
}
Loading

0 comments on commit 04f74de

Please sign in to comment.