Skip to content

Instantly share code, notes, and snippets.

@garand
Last active January 28, 2022 18:24
Show Gist options
  • Save garand/17d61f715b5d646eebaec7b21604793d to your computer and use it in GitHub Desktop.
Save garand/17d61f715b5d646eebaec7b21604793d to your computer and use it in GitHub Desktop.
Stitches Token Variant
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