Skip to content

Commit b2d78dc

Browse files
dominicdominic
authored andcommitted
pass along variant name to restyled component
1 parent 5fbb3f4 commit b2d78dc

File tree

2 files changed

+52
-30
lines changed

2 files changed

+52
-30
lines changed

src/hooks/useRestyle.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ const useRestyle = <
9393
]);
9494

9595
cleanProps.style = calculatedStyle;
96+
if (restyleProps.variant) {
97+
(cleanProps as TProps & {variant?: unknown}).variant = restyleProps.variant;
98+
}
9699
return cleanProps;
97100
};
98101

src/test/createRestyleComponent.test.tsx

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -179,36 +179,6 @@ describe('createRestyleComponent', () => {
179179
);
180180
});
181181

182-
it('passes styles from default variant when no variant prop is defined', () => {
183-
const {root} = render(
184-
<ThemeProvider theme={themeWithVariant}>
185-
<ComponentWithVariant margin="s" />
186-
</ThemeProvider>,
187-
);
188-
expect(root.findByType(View).props.style).toStrictEqual([
189-
{
190-
alignItems: 'flex-start',
191-
backgroundColor: '#FFB6C1',
192-
margin: 8,
193-
},
194-
]);
195-
});
196-
197-
it('passes styles from the defined variant', () => {
198-
const {root} = render(
199-
<ThemeProvider theme={themeWithVariant}>
200-
<ComponentWithVariant variant="regular" margin="s" />
201-
</ThemeProvider>,
202-
);
203-
expect(root.findByType(View).props.style).toStrictEqual([
204-
{
205-
alignItems: 'center',
206-
backgroundColor: '#E0FFFF',
207-
margin: 8,
208-
},
209-
]);
210-
});
211-
212182
it('uses gap values from the theme', () => {
213183
const {root} = render(
214184
<ThemeProvider theme={theme}>
@@ -230,5 +200,54 @@ describe('createRestyleComponent', () => {
230200
style: [{gap: 8, columnGap: 8, rowGap: 8}],
231201
});
232202
});
203+
204+
describe('variant', () => {
205+
it('does not pass variant prop if no variant is created', () => {
206+
const {root} = render(
207+
<ThemeProvider theme={theme}>
208+
<Component opacity={0.5} />
209+
</ThemeProvider>,
210+
);
211+
expect(root.findByType(View).props).toStrictEqual({
212+
style: [{opacity: 0.5}],
213+
});
214+
});
215+
216+
it('passes styles from default variant when no variant prop is defined', () => {
217+
const {root} = render(
218+
<ThemeProvider theme={themeWithVariant}>
219+
<ComponentWithVariant margin="s" />
220+
</ThemeProvider>,
221+
);
222+
expect(root.findByType(View).props).toStrictEqual({
223+
variant: 'defaults',
224+
style: [
225+
{
226+
alignItems: 'flex-start',
227+
backgroundColor: '#FFB6C1',
228+
margin: 8,
229+
},
230+
],
231+
});
232+
});
233+
234+
it('passes styles from the defined variant', () => {
235+
const {root} = render(
236+
<ThemeProvider theme={themeWithVariant}>
237+
<ComponentWithVariant variant="regular" margin="s" />
238+
</ThemeProvider>,
239+
);
240+
expect(root.findByType(View).props).toStrictEqual({
241+
variant: 'regular',
242+
style: [
243+
{
244+
alignItems: 'center',
245+
backgroundColor: '#E0FFFF',
246+
margin: 8,
247+
},
248+
],
249+
});
250+
});
251+
});
233252
});
234253
});

0 commit comments

Comments
 (0)