@hero-design/rn 8.97.0 → 8.98.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 +3 -3
- package/CHANGELOG.md +6 -0
- package/es/index.js +40 -10
- package/lib/index.js +40 -10
- package/package.json +1 -1
- package/src/components/Button/Button.tsx +16 -6
- package/src/components/Button/StyledButton.tsx +78 -29
- package/src/components/Button/__tests__/Button.spec.tsx +51 -36
- package/src/components/Button/__tests__/__snapshots__/Button.spec.tsx.snap +1873 -0
- package/src/components/DatePicker/__tests__/__snapshots__/DatePickerIOS.spec.tsx.snap +2 -0
- package/src/components/Select/MultiSelect/__tests__/__snapshots__/index.spec.tsx.snap +5 -0
- package/src/components/TimePicker/__tests__/__snapshots__/TimePickerIOS.spec.tsx.snap +1 -0
- package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +4 -1
- package/src/theme/components/button.ts +4 -1
- package/stats/8.98.0/rn-stats.html +4842 -0
- package/types/components/Button/Button.d.ts +2 -2
- package/types/components/Button/StyledButton.d.ts +1 -0
- package/types/theme/components/button.d.ts +4 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(node:
|
|
1
|
+
(node:3005) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
|
|
2
2
|
(Use `node --trace-warnings ...` to show where the warning was created)
|
|
3
3
|
[36m
|
|
4
4
|
[1msrc/index.ts[22m → [1mlib/index.js, es/index.js[22m...[39m
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
[7m [0m [91m ~~~~~~~~~~~~~~~~~~~[0m
|
|
11
11
|
[39m
|
|
12
12
|
[1m[33m(!) [plugin node-resolve] preferring built-in module 'events' over local alternative at '/home/runner/work/hero-design/hero-design/node_modules/events/events.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning.or passing a function to 'preferBuiltins' to provide more fine-grained control over which built-in modules to prefer.[39m[22m
|
|
13
|
-
[32mcreated [1mlib/index.js, es/index.js[22m in [
|
|
13
|
+
[32mcreated [1mlib/index.js, es/index.js[22m in [1m56.1s[22m[39m
|
|
14
14
|
[36m
|
|
15
15
|
[1m/home/runner/work/hero-design/hero-design/packages/rn/src/locales/en_AU.ts, /home/runner/work/hero-design/hero-design/packages/rn/src/locales/en_CA.ts, /home/runner/work/hero-design/hero-design/packages/rn/src/locales/index.ts, /home/runner/work/hero-design/hero-design/packages/rn/src/locales/types.ts[22m → [1m., .[22m...[39m
|
|
16
16
|
[1m[33m(!) Generated empty chunks[39m[22m
|
|
17
17
|
"locales/types" and "locales/types"
|
|
18
|
-
[32mcreated [1m., .[22m in [
|
|
18
|
+
[32mcreated [1m., .[22m in [1m22.9s[22m[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @hero-design/rn
|
|
2
2
|
|
|
3
|
+
## 8.98.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#3788](https://github.com/Thinkei/hero-design/pull/3788) [`1c42238a8c0b3651f621b04994bd812e14a30c8c`](https://github.com/Thinkei/hero-design/commit/1c42238a8c0b3651f621b04994bd812e14a30c8c) Thanks [@ttkien](https://github.com/ttkien)! - [Button] add compact text and compact inline text
|
|
8
|
+
|
|
3
9
|
## 8.97.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/es/index.js
CHANGED
|
@@ -2794,7 +2794,10 @@ var getButtonTheme = function getButtonTheme(theme) {
|
|
|
2794
2794
|
}
|
|
2795
2795
|
};
|
|
2796
2796
|
var lineHeights = {
|
|
2797
|
-
titleOfTextVariant:
|
|
2797
|
+
titleOfTextVariant: {
|
|
2798
|
+
"default": theme.lineHeights.medium,
|
|
2799
|
+
compact: theme.lineHeights.small
|
|
2800
|
+
},
|
|
2798
2801
|
buttonText: Platform.select({
|
|
2799
2802
|
android: theme.lineHeights.medium + theme.space.xxsmall
|
|
2800
2803
|
}),
|
|
@@ -10117,6 +10120,24 @@ var genOutlineContainerStyles = function genOutlineContainerStyles(theme, intent
|
|
|
10117
10120
|
backgroundColor: 'transparent'
|
|
10118
10121
|
}, borderColorStyling());
|
|
10119
10122
|
};
|
|
10123
|
+
var getTextButtonPaddingVertical = function getTextButtonPaddingVertical(theme, themeInlineText, themeIsCompact) {
|
|
10124
|
+
if (themeInlineText) {
|
|
10125
|
+
return 0;
|
|
10126
|
+
}
|
|
10127
|
+
if (themeIsCompact) {
|
|
10128
|
+
return theme.__hd__.button.space.compact.buttonPaddingVertical;
|
|
10129
|
+
}
|
|
10130
|
+
return theme.__hd__.button.space["default"].textButtonPadding;
|
|
10131
|
+
};
|
|
10132
|
+
var getTextButtonPaddingHorizontal = function getTextButtonPaddingHorizontal(theme, themeInlineText, themeIsCompact) {
|
|
10133
|
+
if (themeInlineText) {
|
|
10134
|
+
return 0;
|
|
10135
|
+
}
|
|
10136
|
+
if (themeIsCompact) {
|
|
10137
|
+
return theme.__hd__.button.space.compact.buttonPaddingHorizontal;
|
|
10138
|
+
}
|
|
10139
|
+
return theme.__hd__.button.space["default"].textButtonPadding;
|
|
10140
|
+
};
|
|
10120
10141
|
var genTextStyles = function genTextStyles(theme, intent, disabled, isPressed) {
|
|
10121
10142
|
if (disabled) {
|
|
10122
10143
|
return {
|
|
@@ -10164,16 +10185,22 @@ var StyledButtonContainer = index$b(TouchableHighlight)(function (_ref) {
|
|
|
10164
10185
|
case 'text-secondary':
|
|
10165
10186
|
case 'text-danger':
|
|
10166
10187
|
case 'text-white':
|
|
10167
|
-
return {
|
|
10188
|
+
return _objectSpread2(_objectSpread2({
|
|
10168
10189
|
height: themeInlineText ? undefined : getButtonHeight(themeIsCompact),
|
|
10169
10190
|
borderRadius: theme.__hd__.button.radii.text,
|
|
10170
10191
|
flexDirection: 'row',
|
|
10171
10192
|
justifyContent: 'center',
|
|
10172
|
-
alignItems: 'center'
|
|
10173
|
-
|
|
10193
|
+
alignItems: 'center'
|
|
10194
|
+
}, themeIsCompact ? {
|
|
10195
|
+
alignSelf: 'flex-start',
|
|
10196
|
+
paddingVertical: getTextButtonPaddingVertical(theme, themeInlineText, themeIsCompact),
|
|
10197
|
+
paddingHorizontal: getTextButtonPaddingHorizontal(theme, themeInlineText, themeIsCompact)
|
|
10198
|
+
} : {
|
|
10199
|
+
padding: themeInlineText ? 0 : theme.__hd__.button.space["default"].textButtonPadding
|
|
10200
|
+
}), {}, {
|
|
10174
10201
|
borderWidth: 0,
|
|
10175
10202
|
backgroundColor: loading && !themeInlineText && themeButtonVariant !== 'text-white' ? theme.__hd__.button.colors.textLoadingBackground : 'transparent'
|
|
10176
|
-
};
|
|
10203
|
+
});
|
|
10177
10204
|
}
|
|
10178
10205
|
});
|
|
10179
10206
|
var genWhiteTextStyles = function genWhiteTextStyles(_ref2) {
|
|
@@ -10264,7 +10291,8 @@ var StyledButtonTitleOfVariantText = index$b(Typography.Body)(function (_ref5) {
|
|
|
10264
10291
|
var disabled = _ref5.disabled,
|
|
10265
10292
|
themeButtonVariant = _ref5.themeButtonVariant,
|
|
10266
10293
|
themeIsPressed = _ref5.themeIsPressed,
|
|
10267
|
-
theme = _ref5.theme
|
|
10294
|
+
theme = _ref5.theme,
|
|
10295
|
+
themeIsCompact = _ref5.themeIsCompact;
|
|
10268
10296
|
var themeStyling = function themeStyling() {
|
|
10269
10297
|
switch (themeButtonVariant) {
|
|
10270
10298
|
case 'text-primary':
|
|
@@ -10283,7 +10311,7 @@ var StyledButtonTitleOfVariantText = index$b(Typography.Body)(function (_ref5) {
|
|
|
10283
10311
|
};
|
|
10284
10312
|
return _objectSpread2({
|
|
10285
10313
|
flexShrink: 1,
|
|
10286
|
-
lineHeight: theme.__hd__.button.lineHeights.titleOfTextVariant,
|
|
10314
|
+
lineHeight: theme.__hd__.button.lineHeights.titleOfTextVariant[themeIsCompact ? 'compact' : 'default'],
|
|
10287
10315
|
textAlign: 'center',
|
|
10288
10316
|
textAlignVertical: 'center'
|
|
10289
10317
|
}, themeStyling());
|
|
@@ -10374,6 +10402,7 @@ var getThemeVariant = function getThemeVariant(variant, intent) {
|
|
|
10374
10402
|
case 'outlined-compact':
|
|
10375
10403
|
return OUTLINED_VARIANTS[intent];
|
|
10376
10404
|
case 'text':
|
|
10405
|
+
case 'text-compact':
|
|
10377
10406
|
return TEXT_VARIANTS[intent];
|
|
10378
10407
|
}
|
|
10379
10408
|
};
|
|
@@ -10426,7 +10455,7 @@ var Button = function Button(_ref) {
|
|
|
10426
10455
|
text = _ref.text,
|
|
10427
10456
|
_ref$variant = _ref.variant,
|
|
10428
10457
|
variant = _ref$variant === void 0 ? 'filled' : _ref$variant;
|
|
10429
|
-
var isInlineText = variant === 'inline-text';
|
|
10458
|
+
var isInlineText = variant === 'inline-text' || variant === 'inline-text-compact';
|
|
10430
10459
|
var themeVariant = getThemeVariant(isInlineText ? 'text' : variant, intent);
|
|
10431
10460
|
var theme = useTheme();
|
|
10432
10461
|
var underlayColor = useMemo(function () {
|
|
@@ -10437,7 +10466,7 @@ var Button = function Button(_ref) {
|
|
|
10437
10466
|
isPressed = _useState2[0],
|
|
10438
10467
|
setIsPressed = _useState2[1];
|
|
10439
10468
|
useDeprecation("Button variant ".concat(deprecatedVariants.join(', '), " are deprecated."), deprecatedVariants.includes(themeVariant));
|
|
10440
|
-
var isCompactVariant = ['filled-compact', 'outlined-compact'].includes(variant);
|
|
10469
|
+
var isCompactVariant = ['filled-compact', 'outlined-compact', 'text-compact', 'inline-text-compact'].includes(variant);
|
|
10441
10470
|
var isRenderTextVariant = isTextVariant(themeVariant);
|
|
10442
10471
|
var renderTextVariantTitle = function renderTextVariantTitle() {
|
|
10443
10472
|
if (!isRenderTextVariant) return null;
|
|
@@ -10447,7 +10476,8 @@ var Button = function Button(_ref) {
|
|
|
10447
10476
|
numberOfLines: 1,
|
|
10448
10477
|
disabled: disabled,
|
|
10449
10478
|
themeButtonVariant: themeVariant,
|
|
10450
|
-
themeIsPressed: isPressed
|
|
10479
|
+
themeIsPressed: isPressed,
|
|
10480
|
+
themeIsCompact: isCompactVariant
|
|
10451
10481
|
}, text);
|
|
10452
10482
|
};
|
|
10453
10483
|
var renderTitle = function renderTitle() {
|
package/lib/index.js
CHANGED
|
@@ -2823,7 +2823,10 @@ var getButtonTheme = function getButtonTheme(theme) {
|
|
|
2823
2823
|
}
|
|
2824
2824
|
};
|
|
2825
2825
|
var lineHeights = {
|
|
2826
|
-
titleOfTextVariant:
|
|
2826
|
+
titleOfTextVariant: {
|
|
2827
|
+
"default": theme.lineHeights.medium,
|
|
2828
|
+
compact: theme.lineHeights.small
|
|
2829
|
+
},
|
|
2827
2830
|
buttonText: reactNative.Platform.select({
|
|
2828
2831
|
android: theme.lineHeights.medium + theme.space.xxsmall
|
|
2829
2832
|
}),
|
|
@@ -10146,6 +10149,24 @@ var genOutlineContainerStyles = function genOutlineContainerStyles(theme, intent
|
|
|
10146
10149
|
backgroundColor: 'transparent'
|
|
10147
10150
|
}, borderColorStyling());
|
|
10148
10151
|
};
|
|
10152
|
+
var getTextButtonPaddingVertical = function getTextButtonPaddingVertical(theme, themeInlineText, themeIsCompact) {
|
|
10153
|
+
if (themeInlineText) {
|
|
10154
|
+
return 0;
|
|
10155
|
+
}
|
|
10156
|
+
if (themeIsCompact) {
|
|
10157
|
+
return theme.__hd__.button.space.compact.buttonPaddingVertical;
|
|
10158
|
+
}
|
|
10159
|
+
return theme.__hd__.button.space["default"].textButtonPadding;
|
|
10160
|
+
};
|
|
10161
|
+
var getTextButtonPaddingHorizontal = function getTextButtonPaddingHorizontal(theme, themeInlineText, themeIsCompact) {
|
|
10162
|
+
if (themeInlineText) {
|
|
10163
|
+
return 0;
|
|
10164
|
+
}
|
|
10165
|
+
if (themeIsCompact) {
|
|
10166
|
+
return theme.__hd__.button.space.compact.buttonPaddingHorizontal;
|
|
10167
|
+
}
|
|
10168
|
+
return theme.__hd__.button.space["default"].textButtonPadding;
|
|
10169
|
+
};
|
|
10149
10170
|
var genTextStyles = function genTextStyles(theme, intent, disabled, isPressed) {
|
|
10150
10171
|
if (disabled) {
|
|
10151
10172
|
return {
|
|
@@ -10193,16 +10214,22 @@ var StyledButtonContainer = index$b(reactNative.TouchableHighlight)(function (_r
|
|
|
10193
10214
|
case 'text-secondary':
|
|
10194
10215
|
case 'text-danger':
|
|
10195
10216
|
case 'text-white':
|
|
10196
|
-
return {
|
|
10217
|
+
return _objectSpread2(_objectSpread2({
|
|
10197
10218
|
height: themeInlineText ? undefined : getButtonHeight(themeIsCompact),
|
|
10198
10219
|
borderRadius: theme.__hd__.button.radii.text,
|
|
10199
10220
|
flexDirection: 'row',
|
|
10200
10221
|
justifyContent: 'center',
|
|
10201
|
-
alignItems: 'center'
|
|
10202
|
-
|
|
10222
|
+
alignItems: 'center'
|
|
10223
|
+
}, themeIsCompact ? {
|
|
10224
|
+
alignSelf: 'flex-start',
|
|
10225
|
+
paddingVertical: getTextButtonPaddingVertical(theme, themeInlineText, themeIsCompact),
|
|
10226
|
+
paddingHorizontal: getTextButtonPaddingHorizontal(theme, themeInlineText, themeIsCompact)
|
|
10227
|
+
} : {
|
|
10228
|
+
padding: themeInlineText ? 0 : theme.__hd__.button.space["default"].textButtonPadding
|
|
10229
|
+
}), {}, {
|
|
10203
10230
|
borderWidth: 0,
|
|
10204
10231
|
backgroundColor: loading && !themeInlineText && themeButtonVariant !== 'text-white' ? theme.__hd__.button.colors.textLoadingBackground : 'transparent'
|
|
10205
|
-
};
|
|
10232
|
+
});
|
|
10206
10233
|
}
|
|
10207
10234
|
});
|
|
10208
10235
|
var genWhiteTextStyles = function genWhiteTextStyles(_ref2) {
|
|
@@ -10293,7 +10320,8 @@ var StyledButtonTitleOfVariantText = index$b(Typography.Body)(function (_ref5) {
|
|
|
10293
10320
|
var disabled = _ref5.disabled,
|
|
10294
10321
|
themeButtonVariant = _ref5.themeButtonVariant,
|
|
10295
10322
|
themeIsPressed = _ref5.themeIsPressed,
|
|
10296
|
-
theme = _ref5.theme
|
|
10323
|
+
theme = _ref5.theme,
|
|
10324
|
+
themeIsCompact = _ref5.themeIsCompact;
|
|
10297
10325
|
var themeStyling = function themeStyling() {
|
|
10298
10326
|
switch (themeButtonVariant) {
|
|
10299
10327
|
case 'text-primary':
|
|
@@ -10312,7 +10340,7 @@ var StyledButtonTitleOfVariantText = index$b(Typography.Body)(function (_ref5) {
|
|
|
10312
10340
|
};
|
|
10313
10341
|
return _objectSpread2({
|
|
10314
10342
|
flexShrink: 1,
|
|
10315
|
-
lineHeight: theme.__hd__.button.lineHeights.titleOfTextVariant,
|
|
10343
|
+
lineHeight: theme.__hd__.button.lineHeights.titleOfTextVariant[themeIsCompact ? 'compact' : 'default'],
|
|
10316
10344
|
textAlign: 'center',
|
|
10317
10345
|
textAlignVertical: 'center'
|
|
10318
10346
|
}, themeStyling());
|
|
@@ -10403,6 +10431,7 @@ var getThemeVariant = function getThemeVariant(variant, intent) {
|
|
|
10403
10431
|
case 'outlined-compact':
|
|
10404
10432
|
return OUTLINED_VARIANTS[intent];
|
|
10405
10433
|
case 'text':
|
|
10434
|
+
case 'text-compact':
|
|
10406
10435
|
return TEXT_VARIANTS[intent];
|
|
10407
10436
|
}
|
|
10408
10437
|
};
|
|
@@ -10455,7 +10484,7 @@ var Button = function Button(_ref) {
|
|
|
10455
10484
|
text = _ref.text,
|
|
10456
10485
|
_ref$variant = _ref.variant,
|
|
10457
10486
|
variant = _ref$variant === void 0 ? 'filled' : _ref$variant;
|
|
10458
|
-
var isInlineText = variant === 'inline-text';
|
|
10487
|
+
var isInlineText = variant === 'inline-text' || variant === 'inline-text-compact';
|
|
10459
10488
|
var themeVariant = getThemeVariant(isInlineText ? 'text' : variant, intent);
|
|
10460
10489
|
var theme = useTheme();
|
|
10461
10490
|
var underlayColor = React.useMemo(function () {
|
|
@@ -10466,7 +10495,7 @@ var Button = function Button(_ref) {
|
|
|
10466
10495
|
isPressed = _useState2[0],
|
|
10467
10496
|
setIsPressed = _useState2[1];
|
|
10468
10497
|
useDeprecation("Button variant ".concat(deprecatedVariants.join(', '), " are deprecated."), deprecatedVariants.includes(themeVariant));
|
|
10469
|
-
var isCompactVariant = ['filled-compact', 'outlined-compact'].includes(variant);
|
|
10498
|
+
var isCompactVariant = ['filled-compact', 'outlined-compact', 'text-compact', 'inline-text-compact'].includes(variant);
|
|
10470
10499
|
var isRenderTextVariant = isTextVariant(themeVariant);
|
|
10471
10500
|
var renderTextVariantTitle = function renderTextVariantTitle() {
|
|
10472
10501
|
if (!isRenderTextVariant) return null;
|
|
@@ -10476,7 +10505,8 @@ var Button = function Button(_ref) {
|
|
|
10476
10505
|
numberOfLines: 1,
|
|
10477
10506
|
disabled: disabled,
|
|
10478
10507
|
themeButtonVariant: themeVariant,
|
|
10479
|
-
themeIsPressed: isPressed
|
|
10508
|
+
themeIsPressed: isPressed,
|
|
10509
|
+
themeIsCompact: isCompactVariant
|
|
10480
10510
|
}, text);
|
|
10481
10511
|
};
|
|
10482
10512
|
var renderTitle = function renderTitle() {
|
package/package.json
CHANGED
|
@@ -68,7 +68,9 @@ export interface ButtonProps {
|
|
|
68
68
|
| 'text'
|
|
69
69
|
| 'inline-text'
|
|
70
70
|
| 'filled-compact'
|
|
71
|
-
| 'outlined-compact'
|
|
71
|
+
| 'outlined-compact'
|
|
72
|
+
| 'text-compact'
|
|
73
|
+
| 'inline-text-compact';
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
const isIconName = (icon: IconName | ReactNode): icon is IconName => {
|
|
@@ -102,7 +104,8 @@ export const getThemeVariant = (
|
|
|
102
104
|
| 'outlined'
|
|
103
105
|
| 'text'
|
|
104
106
|
| 'filled-compact'
|
|
105
|
-
| 'outlined-compact'
|
|
107
|
+
| 'outlined-compact'
|
|
108
|
+
| 'text-compact',
|
|
106
109
|
intent: Intent
|
|
107
110
|
): ThemeVariant => {
|
|
108
111
|
switch (variant) {
|
|
@@ -113,6 +116,7 @@ export const getThemeVariant = (
|
|
|
113
116
|
case 'outlined-compact':
|
|
114
117
|
return OUTLINED_VARIANTS[intent];
|
|
115
118
|
case 'text':
|
|
119
|
+
case 'text-compact':
|
|
116
120
|
return TEXT_VARIANTS[intent];
|
|
117
121
|
}
|
|
118
122
|
};
|
|
@@ -181,7 +185,9 @@ const Button = ({
|
|
|
181
185
|
text,
|
|
182
186
|
variant = 'filled',
|
|
183
187
|
}: ButtonProps): JSX.Element => {
|
|
184
|
-
const isInlineText =
|
|
188
|
+
const isInlineText =
|
|
189
|
+
variant === 'inline-text' || variant === 'inline-text-compact';
|
|
190
|
+
|
|
185
191
|
const themeVariant = getThemeVariant(isInlineText ? 'text' : variant, intent);
|
|
186
192
|
const theme = useTheme();
|
|
187
193
|
const underlayColor = useMemo(() => {
|
|
@@ -194,9 +200,12 @@ const Button = ({
|
|
|
194
200
|
deprecatedVariants.includes(themeVariant)
|
|
195
201
|
);
|
|
196
202
|
|
|
197
|
-
const isCompactVariant = [
|
|
198
|
-
|
|
199
|
-
|
|
203
|
+
const isCompactVariant = [
|
|
204
|
+
'filled-compact',
|
|
205
|
+
'outlined-compact',
|
|
206
|
+
'text-compact',
|
|
207
|
+
'inline-text-compact',
|
|
208
|
+
].includes(variant);
|
|
200
209
|
|
|
201
210
|
const isRenderTextVariant = isTextVariant(themeVariant);
|
|
202
211
|
|
|
@@ -210,6 +219,7 @@ const Button = ({
|
|
|
210
219
|
disabled={disabled}
|
|
211
220
|
themeButtonVariant={themeVariant}
|
|
212
221
|
themeIsPressed={isPressed}
|
|
222
|
+
themeIsCompact={isCompactVariant}
|
|
213
223
|
>
|
|
214
224
|
{text}
|
|
215
225
|
</StyledButtonTitleOfVariantText>
|
|
@@ -114,6 +114,34 @@ const genOutlineContainerStyles = (
|
|
|
114
114
|
};
|
|
115
115
|
};
|
|
116
116
|
|
|
117
|
+
const getTextButtonPaddingVertical = (
|
|
118
|
+
theme: Theme,
|
|
119
|
+
themeInlineText: boolean,
|
|
120
|
+
themeIsCompact: boolean
|
|
121
|
+
) => {
|
|
122
|
+
if (themeInlineText) {
|
|
123
|
+
return 0;
|
|
124
|
+
}
|
|
125
|
+
if (themeIsCompact) {
|
|
126
|
+
return theme.__hd__.button.space.compact.buttonPaddingVertical;
|
|
127
|
+
}
|
|
128
|
+
return theme.__hd__.button.space.default.textButtonPadding;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const getTextButtonPaddingHorizontal = (
|
|
132
|
+
theme: Theme,
|
|
133
|
+
themeInlineText: boolean,
|
|
134
|
+
themeIsCompact: boolean
|
|
135
|
+
) => {
|
|
136
|
+
if (themeInlineText) {
|
|
137
|
+
return 0;
|
|
138
|
+
}
|
|
139
|
+
if (themeIsCompact) {
|
|
140
|
+
return theme.__hd__.button.space.compact.buttonPaddingHorizontal;
|
|
141
|
+
}
|
|
142
|
+
return theme.__hd__.button.space.default.textButtonPadding;
|
|
143
|
+
};
|
|
144
|
+
|
|
117
145
|
const genTextStyles = (
|
|
118
146
|
theme: Theme,
|
|
119
147
|
intent: Intent,
|
|
@@ -225,10 +253,25 @@ const StyledButtonContainer = styled(TouchableHighlight)<{
|
|
|
225
253
|
flexDirection: 'row',
|
|
226
254
|
justifyContent: 'center',
|
|
227
255
|
alignItems: 'center',
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
256
|
+
...(themeIsCompact
|
|
257
|
+
? {
|
|
258
|
+
alignSelf: 'flex-start',
|
|
259
|
+
paddingVertical: getTextButtonPaddingVertical(
|
|
260
|
+
theme,
|
|
261
|
+
themeInlineText,
|
|
262
|
+
themeIsCompact
|
|
263
|
+
),
|
|
264
|
+
paddingHorizontal: getTextButtonPaddingHorizontal(
|
|
265
|
+
theme,
|
|
266
|
+
themeInlineText,
|
|
267
|
+
themeIsCompact
|
|
268
|
+
),
|
|
269
|
+
}
|
|
270
|
+
: {
|
|
271
|
+
padding: themeInlineText
|
|
272
|
+
? 0
|
|
273
|
+
: theme.__hd__.button.space.default.textButtonPadding,
|
|
274
|
+
}),
|
|
232
275
|
|
|
233
276
|
borderWidth: 0,
|
|
234
277
|
backgroundColor:
|
|
@@ -339,31 +382,37 @@ const StyledButtonTitleOfVariantText = styled(Typography.Body)<{
|
|
|
339
382
|
| 'text-danger'
|
|
340
383
|
| 'text-white';
|
|
341
384
|
themeIsPressed?: boolean;
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
385
|
+
themeIsCompact: boolean;
|
|
386
|
+
}>(
|
|
387
|
+
({ disabled, themeButtonVariant, themeIsPressed, theme, themeIsCompact }) => {
|
|
388
|
+
const themeStyling = () => {
|
|
389
|
+
switch (themeButtonVariant) {
|
|
390
|
+
case 'text-primary':
|
|
391
|
+
return genTextStyles(theme, 'primary', disabled, themeIsPressed);
|
|
392
|
+
case 'text-secondary':
|
|
393
|
+
return genTextStyles(theme, 'secondary', disabled, themeIsPressed);
|
|
394
|
+
case 'text-danger':
|
|
395
|
+
return genTextStyles(theme, 'danger', disabled, themeIsPressed);
|
|
396
|
+
case 'text-white':
|
|
397
|
+
return genWhiteTextStyles({
|
|
398
|
+
variant: 'text-white',
|
|
399
|
+
disabled,
|
|
400
|
+
theme,
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
return {
|
|
405
|
+
flexShrink: 1,
|
|
406
|
+
lineHeight:
|
|
407
|
+
theme.__hd__.button.lineHeights.titleOfTextVariant[
|
|
408
|
+
themeIsCompact ? 'compact' : 'default'
|
|
409
|
+
],
|
|
410
|
+
textAlign: 'center',
|
|
411
|
+
textAlignVertical: 'center',
|
|
412
|
+
...themeStyling(),
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
);
|
|
367
416
|
|
|
368
417
|
const StyledButtonIconWrapper = styled(View)<{
|
|
369
418
|
themePosition: 'left' | 'right';
|
|
@@ -108,42 +108,56 @@ describe('Button', () => {
|
|
|
108
108
|
});
|
|
109
109
|
|
|
110
110
|
it.each`
|
|
111
|
-
variant
|
|
112
|
-
${'filled'}
|
|
113
|
-
${'filled'}
|
|
114
|
-
${'filled'}
|
|
115
|
-
${'filled'}
|
|
116
|
-
${'filled'}
|
|
117
|
-
${'filled'}
|
|
118
|
-
${'outlined'}
|
|
119
|
-
${'outlined'}
|
|
120
|
-
${'outlined'}
|
|
121
|
-
${'outlined'}
|
|
122
|
-
${'outlined'}
|
|
123
|
-
${'outlined'}
|
|
124
|
-
${'text'}
|
|
125
|
-
${'text'}
|
|
126
|
-
${'text'}
|
|
127
|
-
${'text'}
|
|
128
|
-
${'text'}
|
|
129
|
-
${'text'}
|
|
130
|
-
${'text'}
|
|
131
|
-
${'text'}
|
|
132
|
-
${'text'}
|
|
133
|
-
${'text'}
|
|
134
|
-
${'text'}
|
|
135
|
-
${'text'}
|
|
136
|
-
${'inline-text'}
|
|
137
|
-
${'inline-text'}
|
|
138
|
-
${'inline-text'}
|
|
139
|
-
${'inline-text'}
|
|
140
|
-
${'inline-text'}
|
|
141
|
-
${'filled-compact'}
|
|
142
|
-
${'filled-compact'}
|
|
143
|
-
${'filled-compact'}
|
|
144
|
-
${'outlined-compact'}
|
|
145
|
-
${'outlined-compact'}
|
|
146
|
-
${'outlined-compact'}
|
|
111
|
+
variant | intent | loading | disabled
|
|
112
|
+
${'filled'} | ${'primary'} | ${false} | ${false}
|
|
113
|
+
${'filled'} | ${'primary'} | ${true} | ${false}
|
|
114
|
+
${'filled'} | ${'primary'} | ${false} | ${true}
|
|
115
|
+
${'filled'} | ${'white'} | ${false} | ${false}
|
|
116
|
+
${'filled'} | ${'white'} | ${true} | ${false}
|
|
117
|
+
${'filled'} | ${'white'} | ${false} | ${true}
|
|
118
|
+
${'outlined'} | ${'primary'} | ${false} | ${false}
|
|
119
|
+
${'outlined'} | ${'primary'} | ${true} | ${false}
|
|
120
|
+
${'outlined'} | ${'primary'} | ${false} | ${true}
|
|
121
|
+
${'outlined'} | ${'white'} | ${false} | ${false}
|
|
122
|
+
${'outlined'} | ${'white'} | ${true} | ${false}
|
|
123
|
+
${'outlined'} | ${'white'} | ${false} | ${true}
|
|
124
|
+
${'text'} | ${'primary'} | ${false} | ${false}
|
|
125
|
+
${'text'} | ${'primary'} | ${true} | ${false}
|
|
126
|
+
${'text'} | ${'primary'} | ${false} | ${true}
|
|
127
|
+
${'text'} | ${'secondary'} | ${false} | ${false}
|
|
128
|
+
${'text'} | ${'secondary'} | ${true} | ${false}
|
|
129
|
+
${'text'} | ${'secondary'} | ${false} | ${true}
|
|
130
|
+
${'text'} | ${'danger'} | ${false} | ${false}
|
|
131
|
+
${'text'} | ${'danger'} | ${true} | ${false}
|
|
132
|
+
${'text'} | ${'danger'} | ${false} | ${true}
|
|
133
|
+
${'text'} | ${'white'} | ${false} | ${false}
|
|
134
|
+
${'text'} | ${'white'} | ${true} | ${false}
|
|
135
|
+
${'text'} | ${'white'} | ${false} | ${true}
|
|
136
|
+
${'inline-text'} | ${'primary'} | ${false} | ${false}
|
|
137
|
+
${'inline-text'} | ${'secondary'} | ${true} | ${false}
|
|
138
|
+
${'inline-text'} | ${'danger'} | ${false} | ${false}
|
|
139
|
+
${'inline-text'} | ${'primary'} | ${true} | ${false}
|
|
140
|
+
${'inline-text'} | ${'primary'} | ${false} | ${true}
|
|
141
|
+
${'filled-compact'} | ${'primary'} | ${false} | ${false}
|
|
142
|
+
${'filled-compact'} | ${'primary'} | ${true} | ${false}
|
|
143
|
+
${'filled-compact'} | ${'primary'} | ${false} | ${true}
|
|
144
|
+
${'outlined-compact'} | ${'primary'} | ${false} | ${false}
|
|
145
|
+
${'outlined-compact'} | ${'primary'} | ${true} | ${false}
|
|
146
|
+
${'outlined-compact'} | ${'primary'} | ${false} | ${true}
|
|
147
|
+
${'text-compact'} | ${'primary'} | ${false} | ${false}
|
|
148
|
+
${'text-compact'} | ${'primary'} | ${true} | ${false}
|
|
149
|
+
${'text-compact'} | ${'primary'} | ${false} | ${true}
|
|
150
|
+
${'text-compact'} | ${'secondary'} | ${false} | ${false}
|
|
151
|
+
${'text-compact'} | ${'secondary'} | ${true} | ${false}
|
|
152
|
+
${'text-compact'} | ${'secondary'} | ${false} | ${true}
|
|
153
|
+
${'text-compact'} | ${'danger'} | ${false} | ${false}
|
|
154
|
+
${'text-compact'} | ${'danger'} | ${true} | ${false}
|
|
155
|
+
${'text-compact'} | ${'danger'} | ${false} | ${true}
|
|
156
|
+
${'inline-text-compact'} | ${'primary'} | ${false} | ${false}
|
|
157
|
+
${'inline-text-compact'} | ${'secondary'} | ${true} | ${false}
|
|
158
|
+
${'inline-text-compact'} | ${'danger'} | ${false} | ${false}
|
|
159
|
+
${'inline-text-compact'} | ${'primary'} | ${true} | ${false}
|
|
160
|
+
${'inline-text-compact'} | ${'primary'} | ${false} | ${true}
|
|
147
161
|
`('renders correctly', ({ variant, intent, loading, disabled }) => {
|
|
148
162
|
const { toJSON } = renderWithTheme(
|
|
149
163
|
<Button
|
|
@@ -177,6 +191,7 @@ describe('getThemeVariant', () => {
|
|
|
177
191
|
${'text'} | ${'secondary'} | ${'text-secondary'}
|
|
178
192
|
${'text'} | ${'danger'} | ${'text-danger'}
|
|
179
193
|
${'text'} | ${'white'} | ${'text-white'}
|
|
194
|
+
${'text-compact'} | ${'danger'} | ${'text-danger'}
|
|
180
195
|
`('returns $themeVariant', ({ variant, intent, themeVariant }) => {
|
|
181
196
|
expect(getThemeVariant(variant, intent)).toBe(themeVariant);
|
|
182
197
|
});
|