Last active
January 28, 2022 18:24
-
-
Save garand/17d61f715b5d646eebaec7b21604793d to your computer and use it in GitHub Desktop.
Stitches Token Variant
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
export function tokenVariant< | |
T extends keyof typeof theme, | |
V extends keyof typeof theme[T], | |
K extends (value: V) => ReturnType<K> | |
>(type: T, variantCss: K) { | |
return Object.keys(theme[type]).reduce( | |
(acc, key) => ({ | |
...acc, | |
[key]: variantCss(key as V), | |
}), | |
{} | |
) as Record<V, ReturnType<K>>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment