@hero-design/rn 8.83.0 → 8.84.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +2 -2
- package/CHANGELOG.md +6 -0
- package/es/index.js +107 -49
- package/lib/index.js +107 -49
- package/package.json +1 -1
- package/src/components/Button/Button.tsx +73 -26
- package/src/components/Button/StyledButton.tsx +137 -48
- package/src/components/Button/UtilityButton/StyledUtilityButton.tsx +1 -1
- package/src/components/Button/__tests__/Button.spec.tsx +39 -31
- package/src/components/Button/__tests__/StyledButton.spec.tsx +52 -0
- package/src/components/Button/__tests__/__snapshots__/Button.spec.tsx.snap +774 -0
- package/src/components/Button/__tests__/__snapshots__/StyledButton.spec.tsx.snap +489 -0
- package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +14 -4
- package/src/theme/components/button.ts +14 -4
- package/stats/8.84.0/rn-stats.html +4842 -0
- package/types/components/Button/Button.d.ts +2 -2
- package/types/components/Button/StyledButton.d.ts +11 -1
- package/types/theme/components/button.d.ts +14 -4
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
StyledButtonIconWrapper,
|
|
12
12
|
StyledButtonText,
|
|
13
13
|
StyledButtonTitleOfVariantText,
|
|
14
|
+
StyledSmallButtonText,
|
|
14
15
|
} from './StyledButton';
|
|
15
16
|
|
|
16
17
|
export interface ButtonProps {
|
|
@@ -61,7 +62,13 @@ export interface ButtonProps {
|
|
|
61
62
|
/**
|
|
62
63
|
* Button type.
|
|
63
64
|
*/
|
|
64
|
-
variant?:
|
|
65
|
+
variant?:
|
|
66
|
+
| 'filled'
|
|
67
|
+
| 'outlined'
|
|
68
|
+
| 'text'
|
|
69
|
+
| 'inline-text'
|
|
70
|
+
| 'filled-compact'
|
|
71
|
+
| 'outlined-compact';
|
|
65
72
|
}
|
|
66
73
|
|
|
67
74
|
const isIconName = (icon: IconName | ReactNode): icon is IconName => {
|
|
@@ -87,13 +94,20 @@ const TEXT_VARIANTS = {
|
|
|
87
94
|
} as const;
|
|
88
95
|
|
|
89
96
|
export const getThemeVariant = (
|
|
90
|
-
variant:
|
|
97
|
+
variant:
|
|
98
|
+
| 'filled'
|
|
99
|
+
| 'outlined'
|
|
100
|
+
| 'text'
|
|
101
|
+
| 'filled-compact'
|
|
102
|
+
| 'outlined-compact',
|
|
91
103
|
intent: Intent
|
|
92
104
|
): ThemeVariant => {
|
|
93
105
|
switch (variant) {
|
|
94
106
|
case 'filled':
|
|
107
|
+
case 'filled-compact':
|
|
95
108
|
return FILLED_VARIANTS[intent];
|
|
96
109
|
case 'outlined':
|
|
110
|
+
case 'outlined-compact':
|
|
97
111
|
return OUTLINED_VARIANTS[intent];
|
|
98
112
|
case 'text':
|
|
99
113
|
return TEXT_VARIANTS[intent];
|
|
@@ -164,6 +178,51 @@ const Button = ({
|
|
|
164
178
|
deprecatedVariants.includes(themeVariant)
|
|
165
179
|
);
|
|
166
180
|
|
|
181
|
+
const isCompactVariant = ['filled-compact', 'outlined-compact'].includes(
|
|
182
|
+
variant
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
const isRenderTextVariant = isTextVariant(themeVariant);
|
|
186
|
+
|
|
187
|
+
const renderTextVariantTitle = () => {
|
|
188
|
+
if (!isRenderTextVariant) return null;
|
|
189
|
+
return (
|
|
190
|
+
<StyledButtonTitleOfVariantText
|
|
191
|
+
variant={isCompactVariant ? 'small-bold' : 'regular-bold'}
|
|
192
|
+
ellipsizeMode="tail"
|
|
193
|
+
numberOfLines={1}
|
|
194
|
+
disabled={disabled}
|
|
195
|
+
themeButtonVariant={themeVariant}
|
|
196
|
+
themeIsPressed={isPressed}
|
|
197
|
+
>
|
|
198
|
+
{text}
|
|
199
|
+
</StyledButtonTitleOfVariantText>
|
|
200
|
+
);
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const renderTitle = () =>
|
|
204
|
+
isCompactVariant ? (
|
|
205
|
+
<StyledSmallButtonText
|
|
206
|
+
variant="small"
|
|
207
|
+
ellipsizeMode="tail"
|
|
208
|
+
numberOfLines={1}
|
|
209
|
+
disabled={disabled}
|
|
210
|
+
themeButtonVariant={themeVariant}
|
|
211
|
+
>
|
|
212
|
+
{text}
|
|
213
|
+
</StyledSmallButtonText>
|
|
214
|
+
) : (
|
|
215
|
+
<StyledButtonText
|
|
216
|
+
level="h5"
|
|
217
|
+
ellipsizeMode="tail"
|
|
218
|
+
numberOfLines={1}
|
|
219
|
+
disabled={disabled}
|
|
220
|
+
themeButtonVariant={themeVariant}
|
|
221
|
+
>
|
|
222
|
+
{text}
|
|
223
|
+
</StyledButtonText>
|
|
224
|
+
);
|
|
225
|
+
|
|
167
226
|
return (
|
|
168
227
|
<StyledButtonContainer
|
|
169
228
|
accessibilityHint={accessibilityHint}
|
|
@@ -178,6 +237,7 @@ const Button = ({
|
|
|
178
237
|
themeInlineText={isInlineText}
|
|
179
238
|
onPressIn={() => isInlineText && setIsPressed(true)}
|
|
180
239
|
onPressOut={() => isInlineText && setIsPressed(false)}
|
|
240
|
+
themeIsCompact={isCompactVariant}
|
|
181
241
|
>
|
|
182
242
|
{loading === true ? (
|
|
183
243
|
<LoadingIndicator
|
|
@@ -187,7 +247,10 @@ const Button = ({
|
|
|
187
247
|
) : (
|
|
188
248
|
<>
|
|
189
249
|
{icon !== undefined && (
|
|
190
|
-
<StyledButtonIconWrapper
|
|
250
|
+
<StyledButtonIconWrapper
|
|
251
|
+
themePosition="left"
|
|
252
|
+
themeIsCompact={isCompactVariant}
|
|
253
|
+
>
|
|
191
254
|
{isIconName(icon) ? (
|
|
192
255
|
<StyledButtonIcon
|
|
193
256
|
disabled={disabled}
|
|
@@ -195,36 +258,19 @@ const Button = ({
|
|
|
195
258
|
testID={`${testID}-left-icon`}
|
|
196
259
|
themeButtonVariant={themeVariant}
|
|
197
260
|
themeIsPressed={isPressed}
|
|
261
|
+
themeIsCompact={isCompactVariant}
|
|
198
262
|
/>
|
|
199
263
|
) : (
|
|
200
264
|
icon
|
|
201
265
|
)}
|
|
202
266
|
</StyledButtonIconWrapper>
|
|
203
267
|
)}
|
|
204
|
-
{
|
|
205
|
-
<StyledButtonTitleOfVariantText
|
|
206
|
-
variant="regular-bold"
|
|
207
|
-
ellipsizeMode="tail"
|
|
208
|
-
numberOfLines={1}
|
|
209
|
-
disabled={disabled}
|
|
210
|
-
themeButtonVariant={themeVariant}
|
|
211
|
-
themeIsPressed={isPressed}
|
|
212
|
-
>
|
|
213
|
-
{text}
|
|
214
|
-
</StyledButtonTitleOfVariantText>
|
|
215
|
-
) : (
|
|
216
|
-
<StyledButtonText
|
|
217
|
-
level="h5"
|
|
218
|
-
ellipsizeMode="tail"
|
|
219
|
-
numberOfLines={1}
|
|
220
|
-
disabled={disabled}
|
|
221
|
-
themeButtonVariant={themeVariant}
|
|
222
|
-
>
|
|
223
|
-
{text}
|
|
224
|
-
</StyledButtonText>
|
|
225
|
-
)}
|
|
268
|
+
{isRenderTextVariant ? renderTextVariantTitle() : renderTitle()}
|
|
226
269
|
{rightIcon !== undefined && (
|
|
227
|
-
<StyledButtonIconWrapper
|
|
270
|
+
<StyledButtonIconWrapper
|
|
271
|
+
themePosition="right"
|
|
272
|
+
themeIsCompact={isCompactVariant}
|
|
273
|
+
>
|
|
228
274
|
{isIconName(rightIcon) ? (
|
|
229
275
|
<StyledButtonIcon
|
|
230
276
|
disabled={disabled}
|
|
@@ -232,6 +278,7 @@ const Button = ({
|
|
|
232
278
|
testID={`${testID}-right-icon`}
|
|
233
279
|
themeButtonVariant={themeVariant}
|
|
234
280
|
themeIsPressed={isPressed}
|
|
281
|
+
themeIsCompact={isCompactVariant}
|
|
235
282
|
/>
|
|
236
283
|
) : (
|
|
237
284
|
rightIcon
|
|
@@ -19,11 +19,21 @@ type ThemeVariant =
|
|
|
19
19
|
| 'text-secondary'
|
|
20
20
|
| 'text-danger';
|
|
21
21
|
|
|
22
|
+
const getButtonHeight = (themeIsCompact: boolean) => {
|
|
23
|
+
switch (themeIsCompact) {
|
|
24
|
+
case true:
|
|
25
|
+
return scale(36);
|
|
26
|
+
default:
|
|
27
|
+
return scale(60);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
22
31
|
const genFilledContainerStyles = (
|
|
23
32
|
theme: Theme,
|
|
24
33
|
intent: Intent,
|
|
25
34
|
disabled: boolean,
|
|
26
|
-
loading: boolean
|
|
35
|
+
loading: boolean,
|
|
36
|
+
compact: boolean
|
|
27
37
|
): ReactNativeStyle => {
|
|
28
38
|
const backgroundColorStyling = () => {
|
|
29
39
|
if (!loading && disabled) {
|
|
@@ -36,12 +46,21 @@ const genFilledContainerStyles = (
|
|
|
36
46
|
};
|
|
37
47
|
|
|
38
48
|
return {
|
|
39
|
-
height:
|
|
49
|
+
height: getButtonHeight(compact),
|
|
40
50
|
flexDirection: 'row',
|
|
41
51
|
justifyContent: 'center',
|
|
42
52
|
alignItems: 'center',
|
|
43
|
-
|
|
44
|
-
|
|
53
|
+
...(compact
|
|
54
|
+
? {
|
|
55
|
+
alignSelf: 'flex-start',
|
|
56
|
+
paddingVertical:
|
|
57
|
+
theme.__hd__.button.space.compact.buttonPaddingVertical,
|
|
58
|
+
paddingHorizontal: theme.__hd__.button.space.default.buttonPadding,
|
|
59
|
+
}
|
|
60
|
+
: {
|
|
61
|
+
alignSelf: 'stretch',
|
|
62
|
+
padding: theme.__hd__.button.space.default.buttonPadding,
|
|
63
|
+
}),
|
|
45
64
|
borderRadius: theme.__hd__.button.radii.default,
|
|
46
65
|
...backgroundColorStyling(),
|
|
47
66
|
};
|
|
@@ -51,7 +70,8 @@ const genOutlineContainerStyles = (
|
|
|
51
70
|
theme: Theme,
|
|
52
71
|
intent: Intent,
|
|
53
72
|
disabled: boolean,
|
|
54
|
-
loading: boolean
|
|
73
|
+
loading: boolean,
|
|
74
|
+
compact: boolean
|
|
55
75
|
): ReactNativeStyle => {
|
|
56
76
|
const borderColorStyling = () => {
|
|
57
77
|
if (!loading && disabled) {
|
|
@@ -64,14 +84,26 @@ const genOutlineContainerStyles = (
|
|
|
64
84
|
};
|
|
65
85
|
|
|
66
86
|
return {
|
|
67
|
-
height:
|
|
87
|
+
height: getButtonHeight(compact),
|
|
68
88
|
flexDirection: 'row',
|
|
69
89
|
justifyContent: 'center',
|
|
70
90
|
alignItems: 'center',
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
91
|
+
...(compact
|
|
92
|
+
? {
|
|
93
|
+
alignSelf: 'flex-start',
|
|
94
|
+
paddingVertical:
|
|
95
|
+
theme.__hd__.button.space.compact.buttonPaddingVertical -
|
|
96
|
+
theme.__hd__.button.borderWidth.default,
|
|
97
|
+
paddingHorizontal:
|
|
98
|
+
theme.__hd__.button.space.default.buttonPadding -
|
|
99
|
+
theme.__hd__.button.borderWidth.default,
|
|
100
|
+
}
|
|
101
|
+
: {
|
|
102
|
+
alignSelf: 'stretch',
|
|
103
|
+
padding:
|
|
104
|
+
theme.__hd__.button.space.default.buttonPadding -
|
|
105
|
+
theme.__hd__.button.borderWidth.default,
|
|
106
|
+
}),
|
|
75
107
|
borderWidth: theme.__hd__.button.borderWidth.default,
|
|
76
108
|
borderRadius: theme.__hd__.button.radii.default,
|
|
77
109
|
backgroundColor: 'transparent',
|
|
@@ -105,39 +137,79 @@ const StyledButtonContainer = styled(TouchableHighlight)<{
|
|
|
105
137
|
themeButtonVariant: ThemeVariant;
|
|
106
138
|
loading?: boolean;
|
|
107
139
|
themeInlineText?: boolean;
|
|
140
|
+
themeIsCompact?: boolean;
|
|
108
141
|
}>(
|
|
109
142
|
({
|
|
110
143
|
disabled = false,
|
|
111
144
|
loading = false,
|
|
112
145
|
themeButtonVariant,
|
|
113
|
-
themeInlineText,
|
|
146
|
+
themeInlineText = false,
|
|
114
147
|
theme,
|
|
148
|
+
themeIsCompact = false,
|
|
115
149
|
}) => {
|
|
116
150
|
switch (themeButtonVariant) {
|
|
117
151
|
case 'filled-primary':
|
|
118
|
-
return genFilledContainerStyles(
|
|
152
|
+
return genFilledContainerStyles(
|
|
153
|
+
theme,
|
|
154
|
+
'primary',
|
|
155
|
+
disabled,
|
|
156
|
+
loading,
|
|
157
|
+
themeIsCompact
|
|
158
|
+
);
|
|
119
159
|
case 'filled-secondary':
|
|
120
|
-
return genFilledContainerStyles(
|
|
160
|
+
return genFilledContainerStyles(
|
|
161
|
+
theme,
|
|
162
|
+
'secondary',
|
|
163
|
+
disabled,
|
|
164
|
+
loading,
|
|
165
|
+
themeIsCompact
|
|
166
|
+
);
|
|
121
167
|
case 'filled-danger':
|
|
122
|
-
return genFilledContainerStyles(
|
|
168
|
+
return genFilledContainerStyles(
|
|
169
|
+
theme,
|
|
170
|
+
'danger',
|
|
171
|
+
disabled,
|
|
172
|
+
loading,
|
|
173
|
+
themeIsCompact
|
|
174
|
+
);
|
|
123
175
|
case 'outlined-primary':
|
|
124
|
-
return genOutlineContainerStyles(
|
|
176
|
+
return genOutlineContainerStyles(
|
|
177
|
+
theme,
|
|
178
|
+
'primary',
|
|
179
|
+
disabled,
|
|
180
|
+
loading,
|
|
181
|
+
themeIsCompact
|
|
182
|
+
);
|
|
125
183
|
case 'outlined-secondary':
|
|
126
|
-
return genOutlineContainerStyles(
|
|
184
|
+
return genOutlineContainerStyles(
|
|
185
|
+
theme,
|
|
186
|
+
'secondary',
|
|
187
|
+
disabled,
|
|
188
|
+
loading,
|
|
189
|
+
themeIsCompact
|
|
190
|
+
);
|
|
127
191
|
case 'outlined-danger':
|
|
128
|
-
return genOutlineContainerStyles(
|
|
192
|
+
return genOutlineContainerStyles(
|
|
193
|
+
theme,
|
|
194
|
+
'danger',
|
|
195
|
+
disabled,
|
|
196
|
+
loading,
|
|
197
|
+
themeIsCompact
|
|
198
|
+
);
|
|
129
199
|
case 'text-primary':
|
|
130
200
|
case 'text-secondary':
|
|
131
201
|
case 'text-danger':
|
|
132
202
|
return {
|
|
133
|
-
height: themeInlineText ? undefined :
|
|
203
|
+
height: themeInlineText ? undefined : getButtonHeight(themeIsCompact),
|
|
134
204
|
borderRadius: theme.__hd__.button.radii.text,
|
|
135
205
|
flexDirection: 'row',
|
|
136
206
|
justifyContent: 'center',
|
|
137
207
|
alignItems: 'center',
|
|
208
|
+
|
|
138
209
|
padding: themeInlineText
|
|
139
210
|
? 0
|
|
140
|
-
: theme.__hd__.button.space.textButtonPadding,
|
|
211
|
+
: theme.__hd__.button.space.default.textButtonPadding,
|
|
212
|
+
|
|
141
213
|
borderWidth: 0,
|
|
142
214
|
backgroundColor:
|
|
143
215
|
loading && !themeInlineText
|
|
@@ -181,6 +253,8 @@ const StyledButtonText = styled(Typography.Title)<{
|
|
|
181
253
|
};
|
|
182
254
|
});
|
|
183
255
|
|
|
256
|
+
const StyledSmallButtonText = StyledButtonText.withComponent(Typography.Body);
|
|
257
|
+
|
|
184
258
|
const StyledButtonTitleOfVariantText = styled(Typography.Body)<{
|
|
185
259
|
disabled?: boolean;
|
|
186
260
|
themeButtonVariant: 'text-primary' | 'text-secondary' | 'text-danger';
|
|
@@ -206,12 +280,21 @@ const StyledButtonTitleOfVariantText = styled(Typography.Body)<{
|
|
|
206
280
|
|
|
207
281
|
const StyledButtonIconWrapper = styled(View)<{
|
|
208
282
|
themePosition: 'left' | 'right';
|
|
209
|
-
|
|
283
|
+
themeIsCompact?: boolean;
|
|
284
|
+
}>(({ themePosition, theme, themeIsCompact }) => {
|
|
210
285
|
switch (themePosition) {
|
|
211
286
|
case 'left':
|
|
212
|
-
return {
|
|
287
|
+
return {
|
|
288
|
+
paddingRight: themeIsCompact
|
|
289
|
+
? theme.__hd__.button.space.compact.iconPadding
|
|
290
|
+
: theme.__hd__.button.space.default.iconPadding,
|
|
291
|
+
};
|
|
213
292
|
case 'right':
|
|
214
|
-
return {
|
|
293
|
+
return {
|
|
294
|
+
paddingLeft: themeIsCompact
|
|
295
|
+
? theme.__hd__.button.space.compact.iconPadding
|
|
296
|
+
: theme.__hd__.button.space.default.iconPadding,
|
|
297
|
+
};
|
|
215
298
|
}
|
|
216
299
|
});
|
|
217
300
|
|
|
@@ -219,37 +302,43 @@ const StyledButtonIcon = styled(Icon)<{
|
|
|
219
302
|
disabled?: boolean;
|
|
220
303
|
themeButtonVariant: ThemeVariant;
|
|
221
304
|
themeIsPressed?: boolean;
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
305
|
+
themeIsCompact?: boolean;
|
|
306
|
+
}>(
|
|
307
|
+
({ disabled, themeButtonVariant, themeIsPressed, theme, themeIsCompact }) => {
|
|
308
|
+
const themeStyling = () => {
|
|
309
|
+
switch (themeButtonVariant) {
|
|
310
|
+
case 'filled-primary':
|
|
311
|
+
case 'filled-secondary':
|
|
312
|
+
case 'filled-danger':
|
|
313
|
+
return { color: theme.__hd__.button.colors.invertedText };
|
|
314
|
+
case 'outlined-primary':
|
|
315
|
+
return genTextStyles(theme, 'primary', disabled);
|
|
316
|
+
case 'outlined-secondary':
|
|
317
|
+
return genTextStyles(theme, 'secondary', disabled);
|
|
318
|
+
case 'outlined-danger':
|
|
319
|
+
return genTextStyles(theme, 'danger', disabled);
|
|
320
|
+
case 'text-primary':
|
|
321
|
+
return genTextStyles(theme, 'primary', disabled, themeIsPressed);
|
|
322
|
+
case 'text-secondary':
|
|
323
|
+
return genTextStyles(theme, 'secondary', disabled, themeIsPressed);
|
|
324
|
+
case 'text-danger':
|
|
325
|
+
return genTextStyles(theme, 'danger', disabled, themeIsPressed);
|
|
326
|
+
}
|
|
327
|
+
};
|
|
243
328
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
329
|
+
return {
|
|
330
|
+
fontSize: themeIsCompact
|
|
331
|
+
? theme.__hd__.button.sizes.iconSize.compact
|
|
332
|
+
: theme.__hd__.button.sizes.iconSize.default,
|
|
333
|
+
...themeStyling(),
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
);
|
|
249
337
|
|
|
250
338
|
export {
|
|
251
339
|
StyledButtonContainer,
|
|
252
340
|
StyledButtonText,
|
|
341
|
+
StyledSmallButtonText,
|
|
253
342
|
StyledButtonIconWrapper,
|
|
254
343
|
StyledButtonIcon,
|
|
255
344
|
StyledButtonTitleOfVariantText,
|
|
@@ -14,7 +14,7 @@ export const ButtonContainer = styled(TouchableOpacity)(({ theme }) => ({
|
|
|
14
14
|
}));
|
|
15
15
|
|
|
16
16
|
export const IconWrapper = styled(View)(({ theme }) => ({
|
|
17
|
-
paddingRight: theme.__hd__.button.space.iconPadding,
|
|
17
|
+
paddingRight: theme.__hd__.button.space.default.iconPadding,
|
|
18
18
|
}));
|
|
19
19
|
|
|
20
20
|
export const ButtonText = styled(Typography.Body)({
|
|
@@ -108,27 +108,33 @@ describe('Button', () => {
|
|
|
108
108
|
});
|
|
109
109
|
|
|
110
110
|
it.each`
|
|
111
|
-
variant
|
|
112
|
-
${'filled'}
|
|
113
|
-
${'filled'}
|
|
114
|
-
${'filled'}
|
|
115
|
-
${'outlined'}
|
|
116
|
-
${'outlined'}
|
|
117
|
-
${'outlined'}
|
|
118
|
-
${'text'}
|
|
119
|
-
${'text'}
|
|
120
|
-
${'text'}
|
|
121
|
-
${'text'}
|
|
122
|
-
${'text'}
|
|
123
|
-
${'text'}
|
|
124
|
-
${'text'}
|
|
125
|
-
${'text'}
|
|
126
|
-
${'text'}
|
|
127
|
-
${'inline-text'}
|
|
128
|
-
${'inline-text'}
|
|
129
|
-
${'inline-text'}
|
|
130
|
-
${'inline-text'}
|
|
131
|
-
${'inline-text'}
|
|
111
|
+
variant | intent | loading | disabled
|
|
112
|
+
${'filled'} | ${'primary'} | ${false} | ${false}
|
|
113
|
+
${'filled'} | ${'primary'} | ${true} | ${false}
|
|
114
|
+
${'filled'} | ${'primary'} | ${false} | ${true}
|
|
115
|
+
${'outlined'} | ${'primary'} | ${false} | ${false}
|
|
116
|
+
${'outlined'} | ${'primary'} | ${true} | ${false}
|
|
117
|
+
${'outlined'} | ${'primary'} | ${false} | ${true}
|
|
118
|
+
${'text'} | ${'primary'} | ${false} | ${false}
|
|
119
|
+
${'text'} | ${'primary'} | ${true} | ${false}
|
|
120
|
+
${'text'} | ${'primary'} | ${false} | ${true}
|
|
121
|
+
${'text'} | ${'secondary'} | ${false} | ${false}
|
|
122
|
+
${'text'} | ${'secondary'} | ${true} | ${false}
|
|
123
|
+
${'text'} | ${'secondary'} | ${false} | ${true}
|
|
124
|
+
${'text'} | ${'danger'} | ${false} | ${false}
|
|
125
|
+
${'text'} | ${'danger'} | ${true} | ${false}
|
|
126
|
+
${'text'} | ${'danger'} | ${false} | ${true}
|
|
127
|
+
${'inline-text'} | ${'primary'} | ${false} | ${false}
|
|
128
|
+
${'inline-text'} | ${'secondary'} | ${true} | ${false}
|
|
129
|
+
${'inline-text'} | ${'danger'} | ${false} | ${false}
|
|
130
|
+
${'inline-text'} | ${'primary'} | ${true} | ${false}
|
|
131
|
+
${'inline-text'} | ${'primary'} | ${false} | ${true}
|
|
132
|
+
${'filled-compact'} | ${'primary'} | ${false} | ${false}
|
|
133
|
+
${'filled-compact'} | ${'primary'} | ${true} | ${false}
|
|
134
|
+
${'filled-compact'} | ${'primary'} | ${false} | ${true}
|
|
135
|
+
${'outlined-compact'} | ${'primary'} | ${false} | ${false}
|
|
136
|
+
${'outlined-compact'} | ${'primary'} | ${true} | ${false}
|
|
137
|
+
${'outlined-compact'} | ${'primary'} | ${false} | ${true}
|
|
132
138
|
`('renders correctly', ({ variant, intent, loading, disabled }) => {
|
|
133
139
|
const { toJSON } = renderWithTheme(
|
|
134
140
|
<Button
|
|
@@ -147,16 +153,18 @@ describe('Button', () => {
|
|
|
147
153
|
|
|
148
154
|
describe('getThemeVariant', () => {
|
|
149
155
|
it.each`
|
|
150
|
-
variant
|
|
151
|
-
${'filled'}
|
|
152
|
-
${'filled'}
|
|
153
|
-
${'filled'}
|
|
154
|
-
${'
|
|
155
|
-
${'outlined'}
|
|
156
|
-
${'outlined'}
|
|
157
|
-
${'
|
|
158
|
-
${'
|
|
159
|
-
${'text'}
|
|
156
|
+
variant | intent | themeVariant
|
|
157
|
+
${'filled'} | ${'primary'} | ${'filled-primary'}
|
|
158
|
+
${'filled'} | ${'secondary'} | ${'filled-secondary'}
|
|
159
|
+
${'filled'} | ${'danger'} | ${'filled-danger'}
|
|
160
|
+
${'filled-compact'} | ${'danger'} | ${'filled-danger'}
|
|
161
|
+
${'outlined'} | ${'primary'} | ${'outlined-primary'}
|
|
162
|
+
${'outlined'} | ${'secondary'} | ${'outlined-secondary'}
|
|
163
|
+
${'outlined'} | ${'danger'} | ${'outlined-danger'}
|
|
164
|
+
${'outlined-compact'} | ${'danger'} | ${'outlined-danger'}
|
|
165
|
+
${'text'} | ${'primary'} | ${'text-primary'}
|
|
166
|
+
${'text'} | ${'secondary'} | ${'text-secondary'}
|
|
167
|
+
${'text'} | ${'danger'} | ${'text-danger'}
|
|
160
168
|
`('returns $themeVariant', ({ variant, intent, themeVariant }) => {
|
|
161
169
|
expect(getThemeVariant(variant, intent)).toBe(themeVariant);
|
|
162
170
|
});
|
|
@@ -32,6 +32,24 @@ describe('StyledButtonContainer', () => {
|
|
|
32
32
|
expect(toJSON()).toMatchSnapshot();
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
+
it.each`
|
|
36
|
+
themeIsCompact
|
|
37
|
+
${true}
|
|
38
|
+
${false}
|
|
39
|
+
${undefined}
|
|
40
|
+
`('has $themeIsCompact style', ({ themeIsCompact }): void => {
|
|
41
|
+
const { toJSON } = renderWithTheme(
|
|
42
|
+
<StyledButtonContainer
|
|
43
|
+
themeIsCompact={themeIsCompact}
|
|
44
|
+
themeButtonVariant="filled-primary"
|
|
45
|
+
>
|
|
46
|
+
<Text>Title</Text>
|
|
47
|
+
</StyledButtonContainer>
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
expect(toJSON()).toMatchSnapshot();
|
|
51
|
+
});
|
|
52
|
+
|
|
35
53
|
it('renders disabled correctly', () => {
|
|
36
54
|
const { toJSON } = renderWithTheme(
|
|
37
55
|
<StyledButtonContainer themeButtonVariant="filled-primary" disabled>
|
|
@@ -88,6 +106,22 @@ describe('StyledButtonIconWrapper', () => {
|
|
|
88
106
|
|
|
89
107
|
expect(toJSON()).toMatchSnapshot();
|
|
90
108
|
});
|
|
109
|
+
|
|
110
|
+
it.each`
|
|
111
|
+
themeIsCompact
|
|
112
|
+
${true}
|
|
113
|
+
${false}
|
|
114
|
+
${undefined}
|
|
115
|
+
`('has $themeIsCompact style', ({ themeIsCompact }) => {
|
|
116
|
+
const { toJSON } = renderWithTheme(
|
|
117
|
+
<StyledButtonIconWrapper
|
|
118
|
+
themeIsCompact={themeIsCompact}
|
|
119
|
+
themePosition="left"
|
|
120
|
+
/>
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
expect(toJSON()).toMatchSnapshot();
|
|
124
|
+
});
|
|
91
125
|
});
|
|
92
126
|
|
|
93
127
|
describe('StyledButtonIcon', () => {
|
|
@@ -117,6 +151,24 @@ describe('StyledButtonIcon', () => {
|
|
|
117
151
|
expect(toJSON()).toMatchSnapshot();
|
|
118
152
|
});
|
|
119
153
|
|
|
154
|
+
it.each`
|
|
155
|
+
themeIsCompact
|
|
156
|
+
${true}
|
|
157
|
+
${false}
|
|
158
|
+
${undefined}
|
|
159
|
+
`('has $themeIsCompact style', ({ themeIsCompact }) => {
|
|
160
|
+
const { toJSON } = renderWithTheme(
|
|
161
|
+
<StyledButtonIcon
|
|
162
|
+
icon="bell"
|
|
163
|
+
themeButtonVariant="filled-primary"
|
|
164
|
+
themeIsPressed={false}
|
|
165
|
+
themeIsCompact={themeIsCompact}
|
|
166
|
+
/>
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
expect(toJSON()).toMatchSnapshot();
|
|
170
|
+
});
|
|
171
|
+
|
|
120
172
|
it('renders disabled correctly', () => {
|
|
121
173
|
const { toJSON } = renderWithTheme(
|
|
122
174
|
<StyledButtonIcon
|