({
property = 'variant' as P,
themeKey,
defaults,
}: {
property?: P;
themeKey: K;
defaults?: AllProps<Theme>;
})
| 32 | defaults?: AllProps<Theme>; |
| 33 | }): RestyleFunctionContainer<VariantProps<Theme, K>, Theme, 'variant', K>; |
| 34 | function createVariant< |
| 35 | Theme extends BaseTheme, |
| 36 | K extends keyof SafeVariants<Theme>, |
| 37 | P extends keyof any, |
| 38 | TProps extends VariantProps<Theme, K, P>, |
| 39 | >({ |
| 40 | property = 'variant' as P, |
| 41 | themeKey, |
| 42 | defaults, |
| 43 | }: { |
| 44 | property?: P; |
| 45 | themeKey: K; |
| 46 | defaults?: AllProps<Theme>; |
| 47 | }) { |
| 48 | const styleFunction = createRestyleFunction<Theme, TProps, P, K>({ |
| 49 | property, |
| 50 | themeKey, |
| 51 | }); |
| 52 | const func: RestyleFunction<TProps, Theme> = (props, {theme, dimensions}) => { |
| 53 | const expandedProps = styleFunction.func(props, {theme, dimensions})[ |
| 54 | property |
| 55 | ]; |
| 56 | |
| 57 | const variantDefaults = theme[themeKey] |
| 58 | ? (theme[themeKey].defaults as Partial<AllProps<Theme>>) |
| 59 | : {}; |
| 60 | |
| 61 | if (!expandedProps && !defaults && !variantDefaults) return {}; |
| 62 | return StyleSheet.flatten( |
| 63 | allRestyleFunctions.buildStyle( |
| 64 | {...defaults, ...variantDefaults, ...expandedProps}, |
| 65 | { |
| 66 | theme, |
| 67 | dimensions, |
| 68 | }, |
| 69 | ), |
| 70 | ); |
| 71 | }; |
| 72 | return { |
| 73 | property, |
| 74 | themeKey, |
| 75 | variant: true, |
| 76 | func, |
| 77 | }; |
| 78 | } |
| 79 | |
| 80 | export type VariantProps< |
| 81 | Theme extends BaseTheme, |
no test coverage detected
searching dependent graphs…