MCPcopy Index your code
hub / github.com/Shopify/restyle / createVariant

Function createVariant

src/createVariant.ts:34–78  ·  view source on GitHub ↗
({
  property = 'variant' as P,
  themeKey,
  defaults,
}: {
  property?: P;
  themeKey: K;
  defaults?: AllProps<Theme>;
})

Source from the content-addressed store, hash-verified

32 defaults?: AllProps<Theme>;
33}): RestyleFunctionContainer<VariantProps<Theme, K>, Theme, 'variant', K>;
34function 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
80export type VariantProps<
81 Theme extends BaseTheme,

Callers 6

App.tsxFile · 0.85
createText.tsFile · 0.85
TestButton.tsxFile · 0.85
TestContainer.tsxFile · 0.85

Calls 1

createRestyleFunctionFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…