Created
July 13, 2021 04:41
-
-
Save dpeek/079b8ac4268e7b818316d192da4f8794 to your computer and use it in GitHub Desktop.
Radix Color Scale Mapper
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
import { createCss } from '@stitches/react'; | |
import { mint } from '@radix-ui/colors'; | |
type ScaleNum = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12; | |
type ScaleKey<Name extends string> = `${Name}${ScaleNum}`; | |
type ColorScale<Name extends string> = { [K in ScaleKey<Name>]: string }; | |
function mapColorScale<FromName extends string, ToName extends string>( | |
fromScale: ColorScale<FromName>, | |
fromName: FromName, | |
toName: ToName | |
): ColorScale<ToName> { | |
const scale: Record<string, string> = {}; | |
for (let i = 1; i <= 12; i++) { | |
scale[`${toName}${i}`] = fromScale[`${fromName}${i}` as ScaleKey<FromName>]; | |
} | |
return scale as ColorScale<ToName>; | |
} | |
export const { styled, css, global, keyframes, getCssString, theme } = | |
createCss({ | |
theme: { | |
colors: { | |
...mapColorScale(mint, 'mint', 'brand') | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment