Skip to content

Commit

Permalink
feat: seperated generate colors function
Browse files Browse the repository at this point in the history
  • Loading branch information
fluid-design-io committed Jun 24, 2024
1 parent da1b27d commit d5d06f5
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions apps/web/data/generate-colors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { generateColorPalette } from '@/lib/colorCalculator'
import { colorHelper } from '@/lib/colorHelper'
import { generateReadability } from '@/lib/generateReadability'

import { BaseColorTypes, ColorOptions } from '@/types/app'

export const generateColors = (colors: ColorOptions) => {
const newBaseColors = {
primary: colorHelper.toRaw(colors.primary),
secondary: colorHelper.toRaw(colors.secondary),
accent: colorHelper.toRaw(colors.accent),
}
const baseColors: BaseColorTypes[] = ['primary', 'secondary', 'accent', 'gray']
// short-hand
const [primaryPalette, secondaryPalette, accentPalette, grayPalette] = baseColors.map((type) =>
generateColorPalette({
color: type === 'gray' ? newBaseColors.primary : newBaseColors[type],
type,
})
)
/* Calculate WCAG 2.0 */
const palettesWithReadability = generateReadability({
primaryPalette,
secondaryPalette,
accentPalette,
grayPalette,
})
return {
baseColors: newBaseColors,
colorPalettes: palettesWithReadability,
}
}

0 comments on commit d5d06f5

Please sign in to comment.