Created
September 22, 2020 12:21
-
-
Save luistak/2a72940d528518e9a33c27af47158f7c to your computer and use it in GitHub Desktop.
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
type ThemedCss = FlattenInterpolation<ThemeProps<DefaultTheme>>; | |
type VariantOptions<T extends string> = { | |
variant: T | undefined; | |
variants: Record<T, ThemedCss>; | |
defaultStyle: ThemedCss; | |
}; | |
type VariantCallback<T, K extends string> = (props: T) => VariantOptions<K>; | |
function pickVariantStyleV2<T, K extends string>( | |
fn: VariantCallback<T, K> | |
): (props: T) => ThemedCss { | |
return function themedVariant(props: T): ThemedCss { | |
const { variant, variants, defaultStyle } = fn(props); | |
if (!variant) { | |
return defaultStyle; | |
} | |
return variants[variant] || defaultStyle; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage: