Skip to content

Commit

Permalink
remove withColor
Browse files Browse the repository at this point in the history
  • Loading branch information
talentlessguy committed Dec 5, 2024
1 parent 716471a commit 56b3694
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 46 deletions.
8 changes: 4 additions & 4 deletions components/src/components/atoms/Heading/Heading.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import * as React from 'react'

import type { WithColor } from '@/src/interfaces/withColor'

import type { BoxProps } from '../Box/Box'
import { Box } from '../Box/Box'
import clsx from 'clsx'
import * as styles from './Heading.css'
import type { Color } from '@/src/tokens/color'

interface HeadingContainerProps {
textAlign?: React.CSSProperties['textAlign']
textTransform: React.CSSProperties['textTransform']
$level: '1' | '2'
$color: NonNullable<WithColor['color']>
$color: NonNullable<Color>
}

const ContainerBox = React.forwardRef<
Expand Down Expand Up @@ -47,7 +46,8 @@ export type HeadingProps = {
/** CSS property of text-transform */
transform?: React.CSSProperties['textTransform']
level?: '1' | '2'
} & WithColor &
color: Color
} &
Omit<NativeDivAttributes, 'color'>

export const Heading = React.forwardRef<HTMLHeadingElement | HTMLLegendElement, HeadingProps>(
Expand Down
2 changes: 1 addition & 1 deletion components/src/components/atoms/Spinner/Spinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { VisuallyHidden } from '../VisuallyHidden/VisuallyHidden'
import * as styles from './styles.css'
import type { BoxProps } from '../Box/Box'
import { Box } from '../Box/Box'
import type { Color } from '@/src/interfaces/withColor'
import { clsx } from 'clsx'
import type { Color } from '@/src/tokens/color'

type Size = 'small' | 'medium' | 'large'

Expand Down
8 changes: 3 additions & 5 deletions components/src/components/atoms/Typography/Typography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ import * as React from 'react'

import type { Font, FontSize, FontWeight } from '@/src/tokens/typography'

import type { Color, WithColor } from '@/src/interfaces/withColor'

import { removeNullishProps } from '@/src/utils/removeNullishProps'

import { Box, type BoxProps } from '../Box/Box'
import type { FontVariant } from './utils/variant.css'
import { fontVariant } from './utils/variant.css'
import clsx from 'clsx'
import type { Color } from '@/src/tokens/color'

type ContainerProps = {
$ellipsis?: boolean
$fontVariant: FontVariant
$size?: FontSize
$color: Color
$color?: Color
$weight?: FontWeight
$font: Font
}
Expand Down Expand Up @@ -65,10 +64,9 @@ export type TypographyProps = {
font?: Font
/** A weight value that overrides existing weight property */
weight?: FontWeight

color?: Color
fontVariant?: FontVariant
} & Omit<NativeDivProps, 'color' | 'as' | 'translate'> &
WithColor &
Omit<BoxProps, 'color'> & { fontVariant?: FontVariant }

export const Typography = React.forwardRef<HTMLElement, TypographyProps>(
Expand Down
2 changes: 1 addition & 1 deletion components/src/components/molecules/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { DownChevronSVG } from '@/src/icons'
import { ScrollBox } from '../../atoms/ScrollBox/ScrollBox'
import * as styles from './styles.css'
import { clsx } from 'clsx'
import type { Color } from '@/src/interfaces/withColor'
import { assignInlineVars } from '@vanilla-extract/dynamic'
import type { Color } from '@/src/tokens/color'

type Align = 'left' | 'right'
type LabelAlign = 'flex-start' | 'flex-end' | 'center'
Expand Down
22 changes: 10 additions & 12 deletions components/src/css/sprinkles.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { createSprinkles, defineProperties } from '@vanilla-extract/sprinkles'

import { commonVars, modeVars } from './theme.css'

const colorPropertiesObject = { ...modeVars.color, inherit: 'inherit', initial: 'initial', unset: 'unset', transparent: 'transparent', currentColor: 'currentColor', none: 'none' }

const colorProperties = defineProperties({
conditions: {
base: {},
Expand All @@ -16,16 +14,16 @@ const colorProperties = defineProperties({
},
defaultCondition: 'base',
properties: {
color: colorPropertiesObject,
fill: colorPropertiesObject,
stroke: colorPropertiesObject,
background: colorPropertiesObject,
backgroundColor: colorPropertiesObject,
borderColor: colorPropertiesObject,
borderBottomColor: colorPropertiesObject,
borderTopColor: colorPropertiesObject,
borderLeftColor: colorPropertiesObject,
borderRightColor: colorPropertiesObject,
color: modeVars.color,
fill: modeVars.color,
stroke: modeVars.color,
background: modeVars.color,
backgroundColor: modeVars.color,
borderColor: modeVars.color,
borderBottomColor: modeVars.color,
borderTopColor: modeVars.color,
borderLeftColor: modeVars.color,
borderRightColor: modeVars.color,
opacity: ['0', '1', '0.5', '0.7', '0.9', '0.95', '1', 'inherit', 'initial'],

},
Expand Down
21 changes: 0 additions & 21 deletions components/src/interfaces/withColor.ts

This file was deleted.

15 changes: 14 additions & 1 deletion components/src/tokens/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,18 +347,31 @@ const GRADIENT_MAP: { [key in Gradient]: string } = {
'linear-gradient(330.4deg, #DFDFDF 4.54%, #959595 59.2%, #474747 148.85%)',
}

export type Color = PaletteColor | AdditionalColor | Gradient
const STATIC_VALUES = {
inherit: 'inherit',
initial: 'initial',
unset: 'unset',
transparent: 'transparent',
currentColor: 'currentColor',
none: 'none',
}

type StaticValue = keyof typeof STATIC_VALUES

export type Color = PaletteColor | AdditionalColor | Gradient | StaticValue

export const lightColors: { [key in Color]: string } = {
...RAW_PALETTE_COLORS_LIGHT,
...RAW_ADDITIONAL_COLORS_LIGHT,
...GRADIENT_MAP,
...STATIC_VALUES,
}

export const darkColors: { [key in Color]: string } = {
...RAW_PALETTE_COLORS_LIGHT,
...RAW_ADDITIONAL_COLORS_DARK,
...GRADIENT_MAP,
...STATIC_VALUES,
}

export const colors = {
Expand Down
2 changes: 1 addition & 1 deletion components/src/utils/removeNullishProps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BoxProps } from '../components/atoms/Box/Box'

export const removeNullishProps = (props: BoxProps): object => {
export const removeNullishProps = (props: BoxProps): BoxProps => {
const keys = Object.keys(props) as (keyof BoxProps)[]
return keys.reduce<BoxProps>(
(acc, cur) => (props[cur] ? { ...acc, [cur]: props[cur] } : acc),
Expand Down

0 comments on commit 56b3694

Please sign in to comment.