@hero-design/rn 8.80.1 → 8.81.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 +45 -17
- package/lib/index.js +45 -17
- package/package.json +1 -1
- package/src/components/Button/Button.tsx +13 -5
- package/src/components/Button/StyledButton.tsx +60 -39
- package/src/components/Button/__tests__/Button.spec.tsx +21 -16
- package/src/components/Button/__tests__/StyledButton.spec.tsx +19 -12
- package/src/components/Button/__tests__/__snapshots__/Button.spec.tsx.snap +670 -0
- package/src/components/Button/__tests__/__snapshots__/StyledButton.spec.tsx.snap +153 -0
- package/src/components/DatePicker/__tests__/__snapshots__/DatePickerIOS.spec.tsx.snap +1 -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 +5 -0
- package/src/theme/components/button.ts +5 -0
- package/stats/8.81.0/rn-stats.html +4842 -0
- package/types/components/Button/Button.d.ts +1 -1
- package/types/components/Button/StyledButton.d.ts +3 -0
- package/types/theme/components/button.d.ts +5 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
(node:
|
|
1
|
+
(node:2840) 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
|
|
5
5
|
[1m[33m(!) [plugin replace] @rollup/plugin-replace: 'preventAssignment' currently defaults to false. It is recommended to set this option to `true`, as the next major version will default this option to `true`.[39m[22m
|
|
6
6
|
[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
|
|
7
|
-
[32mcreated [1mlib/index.js, es/index.js[22m in [
|
|
7
|
+
[32mcreated [1mlib/index.js, es/index.js[22m in [1m50.9s[22m[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @hero-design/rn
|
|
2
2
|
|
|
3
|
+
## 8.81.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#3505](https://github.com/Thinkei/hero-design/pull/3505) [`6b9e214ee7e9fe63374a4ae7c11c8af4902437ac`](https://github.com/Thinkei/hero-design/commit/6b9e214ee7e9fe63374a4ae7c11c8af4902437ac) Thanks [@haudao-eh](https://github.com/haudao-eh)! - [Button] Support inline-text variant
|
|
8
|
+
|
|
3
9
|
## 8.80.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/es/index.js
CHANGED
|
@@ -2483,6 +2483,11 @@ var getButtonTheme = function getButtonTheme(theme) {
|
|
|
2483
2483
|
textPrimary: theme.colors.highlightedSurface,
|
|
2484
2484
|
textSecondary: theme.colors.neutralGlobalSurface,
|
|
2485
2485
|
textDanger: theme.colors.errorSurface
|
|
2486
|
+
},
|
|
2487
|
+
pressedText: {
|
|
2488
|
+
primary: theme.colors.pressedSurface,
|
|
2489
|
+
secondary: theme.colors.onDefaultGlobalSurface,
|
|
2490
|
+
danger: theme.colors.mutedError
|
|
2486
2491
|
}
|
|
2487
2492
|
};
|
|
2488
2493
|
var lineHeights = {
|
|
@@ -9286,12 +9291,17 @@ var genOutlineContainerStyles = function genOutlineContainerStyles(theme, intent
|
|
|
9286
9291
|
backgroundColor: 'transparent'
|
|
9287
9292
|
}, borderColorStyling());
|
|
9288
9293
|
};
|
|
9289
|
-
var genTextStyles = function genTextStyles(theme, intent, disabled) {
|
|
9294
|
+
var genTextStyles = function genTextStyles(theme, intent, disabled, isPressed) {
|
|
9290
9295
|
if (disabled) {
|
|
9291
9296
|
return {
|
|
9292
9297
|
color: theme.__hd__.button.colors.disabledText
|
|
9293
9298
|
};
|
|
9294
9299
|
}
|
|
9300
|
+
if (isPressed) {
|
|
9301
|
+
return {
|
|
9302
|
+
color: theme.__hd__.button.colors.pressedText[intent]
|
|
9303
|
+
};
|
|
9304
|
+
}
|
|
9295
9305
|
return {
|
|
9296
9306
|
color: theme.__hd__.button.colors[intent]
|
|
9297
9307
|
};
|
|
@@ -9302,6 +9312,7 @@ var StyledButtonContainer = index$a(TouchableHighlight)(function (_ref) {
|
|
|
9302
9312
|
_ref$loading = _ref.loading,
|
|
9303
9313
|
loading = _ref$loading === void 0 ? false : _ref$loading,
|
|
9304
9314
|
themeButtonVariant = _ref.themeButtonVariant,
|
|
9315
|
+
themeInlineText = _ref.themeInlineText,
|
|
9305
9316
|
theme = _ref.theme;
|
|
9306
9317
|
switch (themeButtonVariant) {
|
|
9307
9318
|
case 'filled-primary':
|
|
@@ -9320,14 +9331,14 @@ var StyledButtonContainer = index$a(TouchableHighlight)(function (_ref) {
|
|
|
9320
9331
|
case 'text-secondary':
|
|
9321
9332
|
case 'text-danger':
|
|
9322
9333
|
return {
|
|
9323
|
-
height: scale(60),
|
|
9334
|
+
height: themeInlineText ? undefined : scale(60),
|
|
9324
9335
|
borderRadius: theme.__hd__.button.radii.text,
|
|
9325
9336
|
flexDirection: 'row',
|
|
9326
9337
|
justifyContent: 'center',
|
|
9327
9338
|
alignItems: 'center',
|
|
9328
|
-
padding: theme.__hd__.button.space.textButtonPadding,
|
|
9339
|
+
padding: themeInlineText ? 0 : theme.__hd__.button.space.textButtonPadding,
|
|
9329
9340
|
borderWidth: 0,
|
|
9330
|
-
backgroundColor: loading ? theme.__hd__.button.colors.textLoadingBackground : 'transparent'
|
|
9341
|
+
backgroundColor: loading && !themeInlineText ? theme.__hd__.button.colors.textLoadingBackground : 'transparent'
|
|
9331
9342
|
};
|
|
9332
9343
|
}
|
|
9333
9344
|
});
|
|
@@ -9365,15 +9376,16 @@ var StyledButtonText = index$a(Typography.Title)(function (_ref2) {
|
|
|
9365
9376
|
var StyledButtonTitleOfVariantText = index$a(Typography.Body)(function (_ref3) {
|
|
9366
9377
|
var disabled = _ref3.disabled,
|
|
9367
9378
|
themeButtonVariant = _ref3.themeButtonVariant,
|
|
9379
|
+
themeIsPressed = _ref3.themeIsPressed,
|
|
9368
9380
|
theme = _ref3.theme;
|
|
9369
9381
|
var themeStyling = function themeStyling() {
|
|
9370
9382
|
switch (themeButtonVariant) {
|
|
9371
9383
|
case 'text-primary':
|
|
9372
|
-
return genTextStyles(theme, 'primary', disabled);
|
|
9384
|
+
return genTextStyles(theme, 'primary', disabled, themeIsPressed);
|
|
9373
9385
|
case 'text-secondary':
|
|
9374
|
-
return genTextStyles(theme, 'secondary', disabled);
|
|
9386
|
+
return genTextStyles(theme, 'secondary', disabled, themeIsPressed);
|
|
9375
9387
|
case 'text-danger':
|
|
9376
|
-
return genTextStyles(theme, 'danger', disabled);
|
|
9388
|
+
return genTextStyles(theme, 'danger', disabled, themeIsPressed);
|
|
9377
9389
|
}
|
|
9378
9390
|
};
|
|
9379
9391
|
return _objectSpread2({
|
|
@@ -9399,6 +9411,7 @@ var StyledButtonIconWrapper = index$a(View)(function (_ref4) {
|
|
|
9399
9411
|
var StyledButtonIcon = index$a(Icon)(function (_ref5) {
|
|
9400
9412
|
var disabled = _ref5.disabled,
|
|
9401
9413
|
themeButtonVariant = _ref5.themeButtonVariant,
|
|
9414
|
+
themeIsPressed = _ref5.themeIsPressed,
|
|
9402
9415
|
theme = _ref5.theme;
|
|
9403
9416
|
var themeStyling = function themeStyling() {
|
|
9404
9417
|
switch (themeButtonVariant) {
|
|
@@ -9415,11 +9428,11 @@ var StyledButtonIcon = index$a(Icon)(function (_ref5) {
|
|
|
9415
9428
|
case 'outlined-danger':
|
|
9416
9429
|
return genTextStyles(theme, 'danger', disabled);
|
|
9417
9430
|
case 'text-primary':
|
|
9418
|
-
return genTextStyles(theme, 'primary', disabled);
|
|
9431
|
+
return genTextStyles(theme, 'primary', disabled, themeIsPressed);
|
|
9419
9432
|
case 'text-secondary':
|
|
9420
|
-
return genTextStyles(theme, 'secondary', disabled);
|
|
9433
|
+
return genTextStyles(theme, 'secondary', disabled, themeIsPressed);
|
|
9421
9434
|
case 'text-danger':
|
|
9422
|
-
return genTextStyles(theme, 'danger', disabled);
|
|
9435
|
+
return genTextStyles(theme, 'danger', disabled, themeIsPressed);
|
|
9423
9436
|
}
|
|
9424
9437
|
};
|
|
9425
9438
|
return _objectSpread2({
|
|
@@ -9498,11 +9511,16 @@ var Button = function Button(_ref) {
|
|
|
9498
9511
|
text = _ref.text,
|
|
9499
9512
|
_ref$variant = _ref.variant,
|
|
9500
9513
|
variant = _ref$variant === void 0 ? 'filled' : _ref$variant;
|
|
9501
|
-
var
|
|
9514
|
+
var isInlineText = variant === 'inline-text';
|
|
9515
|
+
var themeVariant = getThemeVariant(isInlineText ? 'text' : variant, intent);
|
|
9502
9516
|
var theme = useTheme();
|
|
9503
9517
|
var underlayColor = useMemo(function () {
|
|
9504
|
-
return getUnderlayColor(theme, themeVariant);
|
|
9505
|
-
}, [theme, themeVariant]);
|
|
9518
|
+
return isInlineText ? 'transparent' : getUnderlayColor(theme, themeVariant);
|
|
9519
|
+
}, [theme, themeVariant, isInlineText]);
|
|
9520
|
+
var _useState = useState(false),
|
|
9521
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
9522
|
+
isPressed = _useState2[0],
|
|
9523
|
+
setIsPressed = _useState2[1];
|
|
9506
9524
|
useDeprecation("Button variant ".concat(deprecatedVariants.join(', '), " are deprecated."), deprecatedVariants.includes(themeVariant));
|
|
9507
9525
|
return /*#__PURE__*/React__default.createElement(StyledButtonContainer, {
|
|
9508
9526
|
accessibilityHint: accessibilityHint,
|
|
@@ -9513,7 +9531,14 @@ var Button = function Button(_ref) {
|
|
|
9513
9531
|
testID: testID,
|
|
9514
9532
|
themeButtonVariant: themeVariant,
|
|
9515
9533
|
style: style,
|
|
9516
|
-
underlayColor: underlayColor
|
|
9534
|
+
underlayColor: underlayColor,
|
|
9535
|
+
themeInlineText: isInlineText,
|
|
9536
|
+
onPressIn: function onPressIn() {
|
|
9537
|
+
return isInlineText && setIsPressed(true);
|
|
9538
|
+
},
|
|
9539
|
+
onPressOut: function onPressOut() {
|
|
9540
|
+
return isInlineText && setIsPressed(false);
|
|
9541
|
+
}
|
|
9517
9542
|
}, loading === true ? /*#__PURE__*/React__default.createElement(LoadingIndicator, {
|
|
9518
9543
|
testID: "".concat(testID, "-loading-indicator"),
|
|
9519
9544
|
themeVariant: themeVariant
|
|
@@ -9523,13 +9548,15 @@ var Button = function Button(_ref) {
|
|
|
9523
9548
|
disabled: disabled,
|
|
9524
9549
|
icon: icon,
|
|
9525
9550
|
testID: "".concat(testID, "-left-icon"),
|
|
9526
|
-
themeButtonVariant: themeVariant
|
|
9551
|
+
themeButtonVariant: themeVariant,
|
|
9552
|
+
themeIsPressed: isPressed
|
|
9527
9553
|
}) : icon), isTextVariant(themeVariant) ? /*#__PURE__*/React__default.createElement(StyledButtonTitleOfVariantText, {
|
|
9528
9554
|
variant: "regular-bold",
|
|
9529
9555
|
ellipsizeMode: "tail",
|
|
9530
9556
|
numberOfLines: 1,
|
|
9531
9557
|
disabled: disabled,
|
|
9532
|
-
themeButtonVariant: themeVariant
|
|
9558
|
+
themeButtonVariant: themeVariant,
|
|
9559
|
+
themeIsPressed: isPressed
|
|
9533
9560
|
}, text) : /*#__PURE__*/React__default.createElement(StyledButtonText, {
|
|
9534
9561
|
level: "h5",
|
|
9535
9562
|
ellipsizeMode: "tail",
|
|
@@ -9542,7 +9569,8 @@ var Button = function Button(_ref) {
|
|
|
9542
9569
|
disabled: disabled,
|
|
9543
9570
|
icon: rightIcon,
|
|
9544
9571
|
testID: "".concat(testID, "-right-icon"),
|
|
9545
|
-
themeButtonVariant: themeVariant
|
|
9572
|
+
themeButtonVariant: themeVariant,
|
|
9573
|
+
themeIsPressed: isPressed
|
|
9546
9574
|
}) : rightIcon)));
|
|
9547
9575
|
};
|
|
9548
9576
|
|
package/lib/index.js
CHANGED
|
@@ -2510,6 +2510,11 @@ var getButtonTheme = function getButtonTheme(theme) {
|
|
|
2510
2510
|
textPrimary: theme.colors.highlightedSurface,
|
|
2511
2511
|
textSecondary: theme.colors.neutralGlobalSurface,
|
|
2512
2512
|
textDanger: theme.colors.errorSurface
|
|
2513
|
+
},
|
|
2514
|
+
pressedText: {
|
|
2515
|
+
primary: theme.colors.pressedSurface,
|
|
2516
|
+
secondary: theme.colors.onDefaultGlobalSurface,
|
|
2517
|
+
danger: theme.colors.mutedError
|
|
2513
2518
|
}
|
|
2514
2519
|
};
|
|
2515
2520
|
var lineHeights = {
|
|
@@ -9313,12 +9318,17 @@ var genOutlineContainerStyles = function genOutlineContainerStyles(theme, intent
|
|
|
9313
9318
|
backgroundColor: 'transparent'
|
|
9314
9319
|
}, borderColorStyling());
|
|
9315
9320
|
};
|
|
9316
|
-
var genTextStyles = function genTextStyles(theme, intent, disabled) {
|
|
9321
|
+
var genTextStyles = function genTextStyles(theme, intent, disabled, isPressed) {
|
|
9317
9322
|
if (disabled) {
|
|
9318
9323
|
return {
|
|
9319
9324
|
color: theme.__hd__.button.colors.disabledText
|
|
9320
9325
|
};
|
|
9321
9326
|
}
|
|
9327
|
+
if (isPressed) {
|
|
9328
|
+
return {
|
|
9329
|
+
color: theme.__hd__.button.colors.pressedText[intent]
|
|
9330
|
+
};
|
|
9331
|
+
}
|
|
9322
9332
|
return {
|
|
9323
9333
|
color: theme.__hd__.button.colors[intent]
|
|
9324
9334
|
};
|
|
@@ -9329,6 +9339,7 @@ var StyledButtonContainer = index$a(reactNative.TouchableHighlight)(function (_r
|
|
|
9329
9339
|
_ref$loading = _ref.loading,
|
|
9330
9340
|
loading = _ref$loading === void 0 ? false : _ref$loading,
|
|
9331
9341
|
themeButtonVariant = _ref.themeButtonVariant,
|
|
9342
|
+
themeInlineText = _ref.themeInlineText,
|
|
9332
9343
|
theme = _ref.theme;
|
|
9333
9344
|
switch (themeButtonVariant) {
|
|
9334
9345
|
case 'filled-primary':
|
|
@@ -9347,14 +9358,14 @@ var StyledButtonContainer = index$a(reactNative.TouchableHighlight)(function (_r
|
|
|
9347
9358
|
case 'text-secondary':
|
|
9348
9359
|
case 'text-danger':
|
|
9349
9360
|
return {
|
|
9350
|
-
height: scale(60),
|
|
9361
|
+
height: themeInlineText ? undefined : scale(60),
|
|
9351
9362
|
borderRadius: theme.__hd__.button.radii.text,
|
|
9352
9363
|
flexDirection: 'row',
|
|
9353
9364
|
justifyContent: 'center',
|
|
9354
9365
|
alignItems: 'center',
|
|
9355
|
-
padding: theme.__hd__.button.space.textButtonPadding,
|
|
9366
|
+
padding: themeInlineText ? 0 : theme.__hd__.button.space.textButtonPadding,
|
|
9356
9367
|
borderWidth: 0,
|
|
9357
|
-
backgroundColor: loading ? theme.__hd__.button.colors.textLoadingBackground : 'transparent'
|
|
9368
|
+
backgroundColor: loading && !themeInlineText ? theme.__hd__.button.colors.textLoadingBackground : 'transparent'
|
|
9358
9369
|
};
|
|
9359
9370
|
}
|
|
9360
9371
|
});
|
|
@@ -9392,15 +9403,16 @@ var StyledButtonText = index$a(Typography.Title)(function (_ref2) {
|
|
|
9392
9403
|
var StyledButtonTitleOfVariantText = index$a(Typography.Body)(function (_ref3) {
|
|
9393
9404
|
var disabled = _ref3.disabled,
|
|
9394
9405
|
themeButtonVariant = _ref3.themeButtonVariant,
|
|
9406
|
+
themeIsPressed = _ref3.themeIsPressed,
|
|
9395
9407
|
theme = _ref3.theme;
|
|
9396
9408
|
var themeStyling = function themeStyling() {
|
|
9397
9409
|
switch (themeButtonVariant) {
|
|
9398
9410
|
case 'text-primary':
|
|
9399
|
-
return genTextStyles(theme, 'primary', disabled);
|
|
9411
|
+
return genTextStyles(theme, 'primary', disabled, themeIsPressed);
|
|
9400
9412
|
case 'text-secondary':
|
|
9401
|
-
return genTextStyles(theme, 'secondary', disabled);
|
|
9413
|
+
return genTextStyles(theme, 'secondary', disabled, themeIsPressed);
|
|
9402
9414
|
case 'text-danger':
|
|
9403
|
-
return genTextStyles(theme, 'danger', disabled);
|
|
9415
|
+
return genTextStyles(theme, 'danger', disabled, themeIsPressed);
|
|
9404
9416
|
}
|
|
9405
9417
|
};
|
|
9406
9418
|
return _objectSpread2({
|
|
@@ -9426,6 +9438,7 @@ var StyledButtonIconWrapper = index$a(reactNative.View)(function (_ref4) {
|
|
|
9426
9438
|
var StyledButtonIcon = index$a(Icon)(function (_ref5) {
|
|
9427
9439
|
var disabled = _ref5.disabled,
|
|
9428
9440
|
themeButtonVariant = _ref5.themeButtonVariant,
|
|
9441
|
+
themeIsPressed = _ref5.themeIsPressed,
|
|
9429
9442
|
theme = _ref5.theme;
|
|
9430
9443
|
var themeStyling = function themeStyling() {
|
|
9431
9444
|
switch (themeButtonVariant) {
|
|
@@ -9442,11 +9455,11 @@ var StyledButtonIcon = index$a(Icon)(function (_ref5) {
|
|
|
9442
9455
|
case 'outlined-danger':
|
|
9443
9456
|
return genTextStyles(theme, 'danger', disabled);
|
|
9444
9457
|
case 'text-primary':
|
|
9445
|
-
return genTextStyles(theme, 'primary', disabled);
|
|
9458
|
+
return genTextStyles(theme, 'primary', disabled, themeIsPressed);
|
|
9446
9459
|
case 'text-secondary':
|
|
9447
|
-
return genTextStyles(theme, 'secondary', disabled);
|
|
9460
|
+
return genTextStyles(theme, 'secondary', disabled, themeIsPressed);
|
|
9448
9461
|
case 'text-danger':
|
|
9449
|
-
return genTextStyles(theme, 'danger', disabled);
|
|
9462
|
+
return genTextStyles(theme, 'danger', disabled, themeIsPressed);
|
|
9450
9463
|
}
|
|
9451
9464
|
};
|
|
9452
9465
|
return _objectSpread2({
|
|
@@ -9525,11 +9538,16 @@ var Button = function Button(_ref) {
|
|
|
9525
9538
|
text = _ref.text,
|
|
9526
9539
|
_ref$variant = _ref.variant,
|
|
9527
9540
|
variant = _ref$variant === void 0 ? 'filled' : _ref$variant;
|
|
9528
|
-
var
|
|
9541
|
+
var isInlineText = variant === 'inline-text';
|
|
9542
|
+
var themeVariant = getThemeVariant(isInlineText ? 'text' : variant, intent);
|
|
9529
9543
|
var theme = useTheme();
|
|
9530
9544
|
var underlayColor = React.useMemo(function () {
|
|
9531
|
-
return getUnderlayColor(theme, themeVariant);
|
|
9532
|
-
}, [theme, themeVariant]);
|
|
9545
|
+
return isInlineText ? 'transparent' : getUnderlayColor(theme, themeVariant);
|
|
9546
|
+
}, [theme, themeVariant, isInlineText]);
|
|
9547
|
+
var _useState = React.useState(false),
|
|
9548
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
9549
|
+
isPressed = _useState2[0],
|
|
9550
|
+
setIsPressed = _useState2[1];
|
|
9533
9551
|
useDeprecation("Button variant ".concat(deprecatedVariants.join(', '), " are deprecated."), deprecatedVariants.includes(themeVariant));
|
|
9534
9552
|
return /*#__PURE__*/React__namespace.default.createElement(StyledButtonContainer, {
|
|
9535
9553
|
accessibilityHint: accessibilityHint,
|
|
@@ -9540,7 +9558,14 @@ var Button = function Button(_ref) {
|
|
|
9540
9558
|
testID: testID,
|
|
9541
9559
|
themeButtonVariant: themeVariant,
|
|
9542
9560
|
style: style,
|
|
9543
|
-
underlayColor: underlayColor
|
|
9561
|
+
underlayColor: underlayColor,
|
|
9562
|
+
themeInlineText: isInlineText,
|
|
9563
|
+
onPressIn: function onPressIn() {
|
|
9564
|
+
return isInlineText && setIsPressed(true);
|
|
9565
|
+
},
|
|
9566
|
+
onPressOut: function onPressOut() {
|
|
9567
|
+
return isInlineText && setIsPressed(false);
|
|
9568
|
+
}
|
|
9544
9569
|
}, loading === true ? /*#__PURE__*/React__namespace.default.createElement(LoadingIndicator, {
|
|
9545
9570
|
testID: "".concat(testID, "-loading-indicator"),
|
|
9546
9571
|
themeVariant: themeVariant
|
|
@@ -9550,13 +9575,15 @@ var Button = function Button(_ref) {
|
|
|
9550
9575
|
disabled: disabled,
|
|
9551
9576
|
icon: icon,
|
|
9552
9577
|
testID: "".concat(testID, "-left-icon"),
|
|
9553
|
-
themeButtonVariant: themeVariant
|
|
9578
|
+
themeButtonVariant: themeVariant,
|
|
9579
|
+
themeIsPressed: isPressed
|
|
9554
9580
|
}) : icon), isTextVariant(themeVariant) ? /*#__PURE__*/React__namespace.default.createElement(StyledButtonTitleOfVariantText, {
|
|
9555
9581
|
variant: "regular-bold",
|
|
9556
9582
|
ellipsizeMode: "tail",
|
|
9557
9583
|
numberOfLines: 1,
|
|
9558
9584
|
disabled: disabled,
|
|
9559
|
-
themeButtonVariant: themeVariant
|
|
9585
|
+
themeButtonVariant: themeVariant,
|
|
9586
|
+
themeIsPressed: isPressed
|
|
9560
9587
|
}, text) : /*#__PURE__*/React__namespace.default.createElement(StyledButtonText, {
|
|
9561
9588
|
level: "h5",
|
|
9562
9589
|
ellipsizeMode: "tail",
|
|
@@ -9569,7 +9596,8 @@ var Button = function Button(_ref) {
|
|
|
9569
9596
|
disabled: disabled,
|
|
9570
9597
|
icon: rightIcon,
|
|
9571
9598
|
testID: "".concat(testID, "-right-icon"),
|
|
9572
|
-
themeButtonVariant: themeVariant
|
|
9599
|
+
themeButtonVariant: themeVariant,
|
|
9600
|
+
themeIsPressed: isPressed
|
|
9573
9601
|
}) : rightIcon)));
|
|
9574
9602
|
};
|
|
9575
9603
|
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { ReactChild, ReactNode, useMemo } from 'react';
|
|
1
|
+
import React, { ReactChild, ReactNode, useMemo, useState } from 'react';
|
|
2
2
|
import type { StyleProp, ViewStyle } from 'react-native';
|
|
3
3
|
import { Theme, useTheme } from '../../theme';
|
|
4
4
|
import { useDeprecation } from '../../utils/hooks';
|
|
@@ -61,7 +61,7 @@ export interface ButtonProps {
|
|
|
61
61
|
/**
|
|
62
62
|
* Button type.
|
|
63
63
|
*/
|
|
64
|
-
variant?: 'filled' | 'outlined' | 'text';
|
|
64
|
+
variant?: 'filled' | 'outlined' | 'text' | 'inline-text';
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
const isIconName = (icon: IconName | ReactNode): icon is IconName => {
|
|
@@ -151,11 +151,13 @@ const Button = ({
|
|
|
151
151
|
text,
|
|
152
152
|
variant = 'filled',
|
|
153
153
|
}: ButtonProps): JSX.Element => {
|
|
154
|
-
const
|
|
154
|
+
const isInlineText = variant === 'inline-text';
|
|
155
|
+
const themeVariant = getThemeVariant(isInlineText ? 'text' : variant, intent);
|
|
155
156
|
const theme = useTheme();
|
|
156
157
|
const underlayColor = useMemo(() => {
|
|
157
|
-
return getUnderlayColor(theme, themeVariant);
|
|
158
|
-
}, [theme, themeVariant]);
|
|
158
|
+
return isInlineText ? 'transparent' : getUnderlayColor(theme, themeVariant);
|
|
159
|
+
}, [theme, themeVariant, isInlineText]);
|
|
160
|
+
const [isPressed, setIsPressed] = useState(false);
|
|
159
161
|
|
|
160
162
|
useDeprecation(
|
|
161
163
|
`Button variant ${deprecatedVariants.join(', ')} are deprecated.`,
|
|
@@ -173,6 +175,9 @@ const Button = ({
|
|
|
173
175
|
themeButtonVariant={themeVariant}
|
|
174
176
|
style={style}
|
|
175
177
|
underlayColor={underlayColor}
|
|
178
|
+
themeInlineText={isInlineText}
|
|
179
|
+
onPressIn={() => isInlineText && setIsPressed(true)}
|
|
180
|
+
onPressOut={() => isInlineText && setIsPressed(false)}
|
|
176
181
|
>
|
|
177
182
|
{loading === true ? (
|
|
178
183
|
<LoadingIndicator
|
|
@@ -189,6 +194,7 @@ const Button = ({
|
|
|
189
194
|
icon={icon}
|
|
190
195
|
testID={`${testID}-left-icon`}
|
|
191
196
|
themeButtonVariant={themeVariant}
|
|
197
|
+
themeIsPressed={isPressed}
|
|
192
198
|
/>
|
|
193
199
|
) : (
|
|
194
200
|
icon
|
|
@@ -202,6 +208,7 @@ const Button = ({
|
|
|
202
208
|
numberOfLines={1}
|
|
203
209
|
disabled={disabled}
|
|
204
210
|
themeButtonVariant={themeVariant}
|
|
211
|
+
themeIsPressed={isPressed}
|
|
205
212
|
>
|
|
206
213
|
{text}
|
|
207
214
|
</StyledButtonTitleOfVariantText>
|
|
@@ -224,6 +231,7 @@ const Button = ({
|
|
|
224
231
|
icon={rightIcon}
|
|
225
232
|
testID={`${testID}-right-icon`}
|
|
226
233
|
themeButtonVariant={themeVariant}
|
|
234
|
+
themeIsPressed={isPressed}
|
|
227
235
|
/>
|
|
228
236
|
) : (
|
|
229
237
|
rightIcon
|
|
@@ -82,7 +82,8 @@ const genOutlineContainerStyles = (
|
|
|
82
82
|
const genTextStyles = (
|
|
83
83
|
theme: Theme,
|
|
84
84
|
intent: Intent,
|
|
85
|
-
disabled?: boolean
|
|
85
|
+
disabled?: boolean,
|
|
86
|
+
isPressed?: boolean
|
|
86
87
|
): ReactNativeStyle => {
|
|
87
88
|
if (disabled) {
|
|
88
89
|
return {
|
|
@@ -90,6 +91,12 @@ const genTextStyles = (
|
|
|
90
91
|
};
|
|
91
92
|
}
|
|
92
93
|
|
|
94
|
+
if (isPressed) {
|
|
95
|
+
return {
|
|
96
|
+
color: theme.__hd__.button.colors.pressedText[intent],
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
93
100
|
return { color: theme.__hd__.button.colors[intent] };
|
|
94
101
|
};
|
|
95
102
|
|
|
@@ -97,37 +104,49 @@ const StyledButtonContainer = styled(TouchableHighlight)<{
|
|
|
97
104
|
disabled?: boolean;
|
|
98
105
|
themeButtonVariant: ThemeVariant;
|
|
99
106
|
loading?: boolean;
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
?
|
|
127
|
-
:
|
|
128
|
-
|
|
107
|
+
themeInlineText?: boolean;
|
|
108
|
+
}>(
|
|
109
|
+
({
|
|
110
|
+
disabled = false,
|
|
111
|
+
loading = false,
|
|
112
|
+
themeButtonVariant,
|
|
113
|
+
themeInlineText,
|
|
114
|
+
theme,
|
|
115
|
+
}) => {
|
|
116
|
+
switch (themeButtonVariant) {
|
|
117
|
+
case 'filled-primary':
|
|
118
|
+
return genFilledContainerStyles(theme, 'primary', disabled, loading);
|
|
119
|
+
case 'filled-secondary':
|
|
120
|
+
return genFilledContainerStyles(theme, 'secondary', disabled, loading);
|
|
121
|
+
case 'filled-danger':
|
|
122
|
+
return genFilledContainerStyles(theme, 'danger', disabled, loading);
|
|
123
|
+
case 'outlined-primary':
|
|
124
|
+
return genOutlineContainerStyles(theme, 'primary', disabled, loading);
|
|
125
|
+
case 'outlined-secondary':
|
|
126
|
+
return genOutlineContainerStyles(theme, 'secondary', disabled, loading);
|
|
127
|
+
case 'outlined-danger':
|
|
128
|
+
return genOutlineContainerStyles(theme, 'danger', disabled, loading);
|
|
129
|
+
case 'text-primary':
|
|
130
|
+
case 'text-secondary':
|
|
131
|
+
case 'text-danger':
|
|
132
|
+
return {
|
|
133
|
+
height: themeInlineText ? undefined : scale(60),
|
|
134
|
+
borderRadius: theme.__hd__.button.radii.text,
|
|
135
|
+
flexDirection: 'row',
|
|
136
|
+
justifyContent: 'center',
|
|
137
|
+
alignItems: 'center',
|
|
138
|
+
padding: themeInlineText
|
|
139
|
+
? 0
|
|
140
|
+
: theme.__hd__.button.space.textButtonPadding,
|
|
141
|
+
borderWidth: 0,
|
|
142
|
+
backgroundColor:
|
|
143
|
+
loading && !themeInlineText
|
|
144
|
+
? theme.__hd__.button.colors.textLoadingBackground
|
|
145
|
+
: 'transparent',
|
|
146
|
+
};
|
|
147
|
+
}
|
|
129
148
|
}
|
|
130
|
-
|
|
149
|
+
);
|
|
131
150
|
|
|
132
151
|
const StyledButtonText = styled(Typography.Title)<{
|
|
133
152
|
disabled?: boolean;
|
|
@@ -165,15 +184,16 @@ const StyledButtonText = styled(Typography.Title)<{
|
|
|
165
184
|
const StyledButtonTitleOfVariantText = styled(Typography.Body)<{
|
|
166
185
|
disabled?: boolean;
|
|
167
186
|
themeButtonVariant: 'text-primary' | 'text-secondary' | 'text-danger';
|
|
168
|
-
|
|
187
|
+
themeIsPressed?: boolean;
|
|
188
|
+
}>(({ disabled, themeButtonVariant, themeIsPressed, theme }) => {
|
|
169
189
|
const themeStyling = () => {
|
|
170
190
|
switch (themeButtonVariant) {
|
|
171
191
|
case 'text-primary':
|
|
172
|
-
return genTextStyles(theme, 'primary', disabled);
|
|
192
|
+
return genTextStyles(theme, 'primary', disabled, themeIsPressed);
|
|
173
193
|
case 'text-secondary':
|
|
174
|
-
return genTextStyles(theme, 'secondary', disabled);
|
|
194
|
+
return genTextStyles(theme, 'secondary', disabled, themeIsPressed);
|
|
175
195
|
case 'text-danger':
|
|
176
|
-
return genTextStyles(theme, 'danger', disabled);
|
|
196
|
+
return genTextStyles(theme, 'danger', disabled, themeIsPressed);
|
|
177
197
|
}
|
|
178
198
|
};
|
|
179
199
|
return {
|
|
@@ -198,7 +218,8 @@ const StyledButtonIconWrapper = styled(View)<{
|
|
|
198
218
|
const StyledButtonIcon = styled(Icon)<{
|
|
199
219
|
disabled?: boolean;
|
|
200
220
|
themeButtonVariant: ThemeVariant;
|
|
201
|
-
|
|
221
|
+
themeIsPressed?: boolean;
|
|
222
|
+
}>(({ disabled, themeButtonVariant, themeIsPressed, theme }) => {
|
|
202
223
|
const themeStyling = () => {
|
|
203
224
|
switch (themeButtonVariant) {
|
|
204
225
|
case 'filled-primary':
|
|
@@ -212,11 +233,11 @@ const StyledButtonIcon = styled(Icon)<{
|
|
|
212
233
|
case 'outlined-danger':
|
|
213
234
|
return genTextStyles(theme, 'danger', disabled);
|
|
214
235
|
case 'text-primary':
|
|
215
|
-
return genTextStyles(theme, 'primary', disabled);
|
|
236
|
+
return genTextStyles(theme, 'primary', disabled, themeIsPressed);
|
|
216
237
|
case 'text-secondary':
|
|
217
|
-
return genTextStyles(theme, 'secondary', disabled);
|
|
238
|
+
return genTextStyles(theme, 'secondary', disabled, themeIsPressed);
|
|
218
239
|
case 'text-danger':
|
|
219
|
-
return genTextStyles(theme, 'danger', disabled);
|
|
240
|
+
return genTextStyles(theme, 'danger', disabled, themeIsPressed);
|
|
220
241
|
}
|
|
221
242
|
};
|
|
222
243
|
|
|
@@ -108,22 +108,27 @@ 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'}
|
|
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}
|
|
127
132
|
`('renders correctly', ({ variant, intent, loading, disabled }) => {
|
|
128
133
|
const { toJSON } = renderWithTheme(
|
|
129
134
|
<Button
|
|
@@ -92,19 +92,26 @@ describe('StyledButtonIconWrapper', () => {
|
|
|
92
92
|
|
|
93
93
|
describe('StyledButtonIcon', () => {
|
|
94
94
|
it.each`
|
|
95
|
-
themeVariant
|
|
96
|
-
${'filled-primary'}
|
|
97
|
-
${'filled-secondary'}
|
|
98
|
-
${'filled-danger'}
|
|
99
|
-
${'outlined-primary'}
|
|
100
|
-
${'outlined-secondary'}
|
|
101
|
-
${'outlined-danger'}
|
|
102
|
-
${'text-primary'}
|
|
103
|
-
${'text-secondary'}
|
|
104
|
-
${'text-danger'}
|
|
105
|
-
|
|
95
|
+
themeVariant | themeIsPressed
|
|
96
|
+
${'filled-primary'} | ${undefined}
|
|
97
|
+
${'filled-secondary'} | ${undefined}
|
|
98
|
+
${'filled-danger'} | ${undefined}
|
|
99
|
+
${'outlined-primary'} | ${undefined}
|
|
100
|
+
${'outlined-secondary'} | ${undefined}
|
|
101
|
+
${'outlined-danger'} | ${undefined}
|
|
102
|
+
${'text-primary'} | ${false}
|
|
103
|
+
${'text-secondary'} | ${false}
|
|
104
|
+
${'text-danger'} | ${false}
|
|
105
|
+
${'text-primary'} | ${true}
|
|
106
|
+
${'text-secondary'} | ${true}
|
|
107
|
+
${'text-danger'} | ${true}
|
|
108
|
+
`('has $themeVariant style', ({ themeVariant, themeIsPressed }) => {
|
|
106
109
|
const { toJSON } = renderWithTheme(
|
|
107
|
-
<StyledButtonIcon
|
|
110
|
+
<StyledButtonIcon
|
|
111
|
+
icon="bell"
|
|
112
|
+
themeButtonVariant={themeVariant}
|
|
113
|
+
themeIsPressed={themeIsPressed}
|
|
114
|
+
/>
|
|
108
115
|
);
|
|
109
116
|
|
|
110
117
|
expect(toJSON()).toMatchSnapshot();
|