-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: seperated generate colors function
- Loading branch information
1 parent
da1b27d
commit d5d06f5
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |