@hero-design/rn 8.105.4 → 8.106.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 +18 -0
- package/es/index.js +2797 -2453
- package/lib/index.js +2800 -2456
- package/package.json +2 -2
- package/src/components/Button/Button.tsx +70 -44
- package/src/components/Button/LoadingIndicator/StyledLoadingIndicator.tsx +12 -33
- package/src/components/Button/LoadingIndicator/__tests__/__snapshots__/StyledLoadingIndicator.spec.tsx.snap +4 -4
- package/src/components/Button/LoadingIndicator/__tests__/__snapshots__/index.spec.tsx.snap +12 -12
- package/src/components/Button/LoadingIndicator/index.tsx +4 -1
- package/src/components/Button/StyledButton.tsx +461 -313
- package/src/components/Button/__tests__/__snapshots__/Button.spec.tsx.snap +102 -86
- package/src/components/Button/__tests__/__snapshots__/StyledButton.spec.tsx.snap +19 -18
- package/src/components/Chart/Line/__tests__/__snapshots__/index.spec.tsx.snap +2 -2
- package/src/components/Checkbox/{index.tsx → DefaultCheckBox.tsx} +6 -31
- package/src/components/Checkbox/InlineCheckBox.tsx +97 -0
- package/src/components/Checkbox/{StyledCheckbox.tsx → StyledDefaultCheckBox.tsx} +1 -0
- package/src/components/Checkbox/StyledInlineCheckBox.tsx +49 -0
- package/src/components/Checkbox/__tests__/{index.spec.tsx → DefaultCheckBox.spec.tsx} +21 -20
- package/src/components/Checkbox/__tests__/InlineCheckBox.spec.tsx +93 -0
- package/src/components/Checkbox/__tests__/{StyledCheckbox.spec.tsx → StyledDefaultCheckbox.spec.tsx} +2 -2
- package/src/components/Checkbox/__tests__/__snapshots__/{index.spec.tsx.snap → DefaultCheckBox.spec.tsx.snap} +6 -0
- package/src/components/Checkbox/__tests__/__snapshots__/InlineCheckBox.spec.tsx.snap +988 -0
- package/src/components/Checkbox/__tests__/__snapshots__/{StyledCheckbox.spec.tsx.snap → StyledDefaultCheckbox.spec.tsx.snap} +4 -0
- package/src/components/Checkbox/__tests__/utils.spec.ts +20 -0
- package/src/components/Checkbox/index.ts +9 -0
- package/src/components/Checkbox/utils.ts +25 -0
- package/src/components/DatePicker/__tests__/__snapshots__/DatePickerIOS.spec.tsx.snap +2 -2
- package/src/components/Drawer/__tests__/__snapshots__/index.spec.tsx.snap +11 -8
- package/src/components/Drawer/__tests__/index.spec.tsx +15 -1
- package/src/components/Drawer/index.tsx +5 -2
- package/src/components/Select/MultiSelect/__tests__/__snapshots__/index.spec.tsx.snap +5 -5
- package/src/components/TimePicker/__tests__/__snapshots__/TimePickerIOS.spec.tsx.snap +1 -1
- package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +59 -19
- package/src/theme/components/button.ts +52 -19
- package/src/theme/components/checkbox.ts +7 -0
- package/src/theme/components/drawer.ts +1 -1
- package/src/utils/__tests__/helpers.spec.ts +37 -1
- package/src/utils/helpers.ts +14 -0
- package/stats/8.106.0/rn-stats.html +4844 -0
- package/types/components/Button/Button.d.ts +5 -4
- package/types/components/Button/LoadingIndicator/StyledLoadingIndicator.d.ts +3 -4
- package/types/components/Button/LoadingIndicator/index.d.ts +1 -1
- package/types/components/Button/StyledButton.d.ts +8 -4
- package/types/components/Checkbox/DefaultCheckBox.d.ts +40 -0
- package/types/components/Checkbox/InlineCheckBox.d.ts +38 -0
- package/types/components/Checkbox/StyledInlineCheckBox.d.ts +45 -0
- package/types/components/Checkbox/index.d.ts +5 -45
- package/types/components/Checkbox/utils.d.ts +6 -0
- package/types/theme/components/button.d.ts +49 -15
- package/types/theme/components/checkbox.d.ts +6 -0
- package/types/theme/components/drawer.d.ts +1 -1
- package/types/utils/helpers.d.ts +2 -0
- /package/types/components/Checkbox/{StyledCheckbox.d.ts → StyledDefaultCheckBox.d.ts} +0 -0
|
@@ -100,7 +100,7 @@ exports[`StyledButtonContainer has filled-danger style 1`] = `
|
|
|
100
100
|
{
|
|
101
101
|
"alignItems": "center",
|
|
102
102
|
"alignSelf": "stretch",
|
|
103
|
-
"backgroundColor": "#
|
|
103
|
+
"backgroundColor": "#f46363",
|
|
104
104
|
"borderRadius": 32,
|
|
105
105
|
"flexDirection": "row",
|
|
106
106
|
"height": 60,
|
|
@@ -238,7 +238,7 @@ exports[`StyledButtonContainer has filled-secondary style 1`] = `
|
|
|
238
238
|
{
|
|
239
239
|
"alignItems": "center",
|
|
240
240
|
"alignSelf": "stretch",
|
|
241
|
-
"backgroundColor": "#
|
|
241
|
+
"backgroundColor": "#f6f6f7",
|
|
242
242
|
"borderRadius": 32,
|
|
243
243
|
"flexDirection": "row",
|
|
244
244
|
"height": 60,
|
|
@@ -519,7 +519,7 @@ exports[`StyledButtonContainer has outlined-secondary style 1`] = `
|
|
|
519
519
|
"alignItems": "center",
|
|
520
520
|
"alignSelf": "stretch",
|
|
521
521
|
"backgroundColor": "transparent",
|
|
522
|
-
"borderColor": "#
|
|
522
|
+
"borderColor": "#e8e9ea",
|
|
523
523
|
"borderRadius": 32,
|
|
524
524
|
"borderWidth": 2,
|
|
525
525
|
"flexDirection": "row",
|
|
@@ -660,7 +660,7 @@ exports[`StyledButtonContainer has text-danger style 1`] = `
|
|
|
660
660
|
{
|
|
661
661
|
"alignItems": "center",
|
|
662
662
|
"backgroundColor": "transparent",
|
|
663
|
-
"borderRadius":
|
|
663
|
+
"borderRadius": 999,
|
|
664
664
|
"borderWidth": 0,
|
|
665
665
|
"flexDirection": "row",
|
|
666
666
|
"height": 60,
|
|
@@ -729,7 +729,7 @@ exports[`StyledButtonContainer has text-primary style 1`] = `
|
|
|
729
729
|
{
|
|
730
730
|
"alignItems": "center",
|
|
731
731
|
"backgroundColor": "transparent",
|
|
732
|
-
"borderRadius":
|
|
732
|
+
"borderRadius": 999,
|
|
733
733
|
"borderWidth": 0,
|
|
734
734
|
"flexDirection": "row",
|
|
735
735
|
"height": 60,
|
|
@@ -798,7 +798,7 @@ exports[`StyledButtonContainer has text-secondary style 1`] = `
|
|
|
798
798
|
{
|
|
799
799
|
"alignItems": "center",
|
|
800
800
|
"backgroundColor": "transparent",
|
|
801
|
-
"borderRadius":
|
|
801
|
+
"borderRadius": 999,
|
|
802
802
|
"borderWidth": 0,
|
|
803
803
|
"flexDirection": "row",
|
|
804
804
|
"height": 60,
|
|
@@ -867,7 +867,7 @@ exports[`StyledButtonContainer has text-white style 1`] = `
|
|
|
867
867
|
{
|
|
868
868
|
"alignItems": "center",
|
|
869
869
|
"backgroundColor": "transparent",
|
|
870
|
-
"borderRadius":
|
|
870
|
+
"borderRadius": 999,
|
|
871
871
|
"borderWidth": 0,
|
|
872
872
|
"flexDirection": "row",
|
|
873
873
|
"height": 60,
|
|
@@ -1080,11 +1080,12 @@ exports[`StyledButtonContainer renders disabled correctly 1`] = `
|
|
|
1080
1080
|
{
|
|
1081
1081
|
"alignItems": "center",
|
|
1082
1082
|
"alignSelf": "stretch",
|
|
1083
|
-
"backgroundColor": "#
|
|
1083
|
+
"backgroundColor": "#401960",
|
|
1084
1084
|
"borderRadius": 32,
|
|
1085
1085
|
"flexDirection": "row",
|
|
1086
1086
|
"height": 60,
|
|
1087
1087
|
"justifyContent": "center",
|
|
1088
|
+
"opacity": 0.25,
|
|
1088
1089
|
"padding": 16,
|
|
1089
1090
|
},
|
|
1090
1091
|
undefined,
|
|
@@ -1289,7 +1290,7 @@ exports[`StyledButtonIcon has filled-secondary style 1`] = `
|
|
|
1289
1290
|
},
|
|
1290
1291
|
[
|
|
1291
1292
|
{
|
|
1292
|
-
"color": "#
|
|
1293
|
+
"color": "#001f23",
|
|
1293
1294
|
"fontSize": 20,
|
|
1294
1295
|
},
|
|
1295
1296
|
undefined,
|
|
@@ -1493,7 +1494,7 @@ exports[`StyledButtonIcon has outlined-secondary style 1`] = `
|
|
|
1493
1494
|
},
|
|
1494
1495
|
[
|
|
1495
1496
|
{
|
|
1496
|
-
"color": "#
|
|
1497
|
+
"color": "#001f23",
|
|
1497
1498
|
"fontSize": 20,
|
|
1498
1499
|
},
|
|
1499
1500
|
undefined,
|
|
@@ -1646,7 +1647,7 @@ exports[`StyledButtonIcon has text-danger style 2`] = `
|
|
|
1646
1647
|
},
|
|
1647
1648
|
[
|
|
1648
1649
|
{
|
|
1649
|
-
"color": "#
|
|
1650
|
+
"color": "#f46363",
|
|
1650
1651
|
"fontSize": 20,
|
|
1651
1652
|
},
|
|
1652
1653
|
undefined,
|
|
@@ -1748,7 +1749,7 @@ exports[`StyledButtonIcon has text-primary style 2`] = `
|
|
|
1748
1749
|
},
|
|
1749
1750
|
[
|
|
1750
1751
|
{
|
|
1751
|
-
"color": "#
|
|
1752
|
+
"color": "#795e90",
|
|
1752
1753
|
"fontSize": 20,
|
|
1753
1754
|
},
|
|
1754
1755
|
undefined,
|
|
@@ -1799,7 +1800,7 @@ exports[`StyledButtonIcon has text-secondary style 1`] = `
|
|
|
1799
1800
|
},
|
|
1800
1801
|
[
|
|
1801
1802
|
{
|
|
1802
|
-
"color": "#
|
|
1803
|
+
"color": "#001f23",
|
|
1803
1804
|
"fontSize": 20,
|
|
1804
1805
|
},
|
|
1805
1806
|
undefined,
|
|
@@ -1850,7 +1851,7 @@ exports[`StyledButtonIcon has text-secondary style 2`] = `
|
|
|
1850
1851
|
},
|
|
1851
1852
|
[
|
|
1852
1853
|
{
|
|
1853
|
-
"color": "#
|
|
1854
|
+
"color": "#606065",
|
|
1854
1855
|
"fontSize": 20,
|
|
1855
1856
|
},
|
|
1856
1857
|
undefined,
|
|
@@ -1952,7 +1953,7 @@ exports[`StyledButtonIcon has text-white style 2`] = `
|
|
|
1952
1953
|
},
|
|
1953
1954
|
[
|
|
1954
1955
|
{
|
|
1955
|
-
"color": "#
|
|
1956
|
+
"color": "#795e90",
|
|
1956
1957
|
"fontSize": 20,
|
|
1957
1958
|
},
|
|
1958
1959
|
undefined,
|
|
@@ -2493,7 +2494,7 @@ exports[`StyledButtonText has filled-secondary style 1`] = `
|
|
|
2493
2494
|
},
|
|
2494
2495
|
[
|
|
2495
2496
|
{
|
|
2496
|
-
"color": "#
|
|
2497
|
+
"color": "#001f23",
|
|
2497
2498
|
"flexShrink": 1,
|
|
2498
2499
|
"lineHeight": undefined,
|
|
2499
2500
|
"textAlign": "center",
|
|
@@ -2737,7 +2738,7 @@ exports[`StyledButtonText has outlined-secondary style 1`] = `
|
|
|
2737
2738
|
},
|
|
2738
2739
|
[
|
|
2739
2740
|
{
|
|
2740
|
-
"color": "#
|
|
2741
|
+
"color": "#001f23",
|
|
2741
2742
|
"flexShrink": 1,
|
|
2742
2743
|
"lineHeight": undefined,
|
|
2743
2744
|
"textAlign": "center",
|
|
@@ -2981,7 +2982,7 @@ exports[`StyledButtonText has text-secondary style 1`] = `
|
|
|
2981
2982
|
},
|
|
2982
2983
|
[
|
|
2983
2984
|
{
|
|
2984
|
-
"color": "#
|
|
2985
|
+
"color": "#001f23",
|
|
2985
2986
|
"flexShrink": 1,
|
|
2986
2987
|
"lineHeight": undefined,
|
|
2987
2988
|
"textAlign": "center",
|
|
@@ -117,7 +117,7 @@ exports[`LineChart renders chart with custom colors 1`] = `
|
|
|
117
117
|
"alignItems": "center",
|
|
118
118
|
"alignSelf": "flex-start",
|
|
119
119
|
"backgroundColor": "transparent",
|
|
120
|
-
"borderRadius":
|
|
120
|
+
"borderRadius": 999,
|
|
121
121
|
"borderWidth": 0,
|
|
122
122
|
"flexDirection": "row",
|
|
123
123
|
"height": undefined,
|
|
@@ -1577,7 +1577,7 @@ exports[`LineChart should render 1`] = `
|
|
|
1577
1577
|
"alignItems": "center",
|
|
1578
1578
|
"alignSelf": "flex-start",
|
|
1579
1579
|
"backgroundColor": "transparent",
|
|
1580
|
-
"borderRadius":
|
|
1580
|
+
"borderRadius": 999,
|
|
1581
1581
|
"borderWidth": 0,
|
|
1582
1582
|
"flexDirection": "row",
|
|
1583
1583
|
"height": undefined,
|
|
@@ -6,10 +6,11 @@ import {
|
|
|
6
6
|
StyledCheckMark,
|
|
7
7
|
StyledDescription,
|
|
8
8
|
StyledWrapper,
|
|
9
|
-
} from './
|
|
9
|
+
} from './StyledDefaultCheckBox';
|
|
10
10
|
import { useDeprecation } from '../../utils/hooks';
|
|
11
|
+
import { getThemeState } from './utils';
|
|
11
12
|
|
|
12
|
-
export interface
|
|
13
|
+
export interface DefaultCheckboxProps {
|
|
13
14
|
/**
|
|
14
15
|
* Control whether the switch is checked
|
|
15
16
|
*/
|
|
@@ -46,33 +47,7 @@ export interface CheckboxProps {
|
|
|
46
47
|
readonly?: boolean;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
disabled: boolean;
|
|
51
|
-
readonly: boolean;
|
|
52
|
-
checked?: boolean;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const getThemeState = ({
|
|
56
|
-
disabled,
|
|
57
|
-
readonly,
|
|
58
|
-
checked,
|
|
59
|
-
}: getStateType) => {
|
|
60
|
-
if (disabled) {
|
|
61
|
-
return 'disabled';
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (readonly) {
|
|
65
|
-
return 'readonly';
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (checked) {
|
|
69
|
-
return 'checked';
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return 'default';
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const Checkbox = ({
|
|
50
|
+
const DefaultCheckbox = ({
|
|
76
51
|
checked,
|
|
77
52
|
description,
|
|
78
53
|
withBorder = false,
|
|
@@ -81,7 +56,7 @@ const Checkbox = ({
|
|
|
81
56
|
style,
|
|
82
57
|
testID,
|
|
83
58
|
readonly = false,
|
|
84
|
-
}:
|
|
59
|
+
}: DefaultCheckboxProps) => {
|
|
85
60
|
useDeprecation(
|
|
86
61
|
`Checkbox's withBorder prop will be removed in the next major release, all checkboxes will have border by default. Please remove it.`,
|
|
87
62
|
withBorder === true
|
|
@@ -119,4 +94,4 @@ const Checkbox = ({
|
|
|
119
94
|
);
|
|
120
95
|
};
|
|
121
96
|
|
|
122
|
-
export default
|
|
97
|
+
export default DefaultCheckbox;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type StyleProp, type ViewStyle } from 'react-native';
|
|
3
|
+
import {
|
|
4
|
+
StyledCheckbox,
|
|
5
|
+
StyledCheckboxContainer,
|
|
6
|
+
StyledCheckMark,
|
|
7
|
+
StyledDescription,
|
|
8
|
+
StyledWrapper,
|
|
9
|
+
} from './StyledInlineCheckBox';
|
|
10
|
+
import { getThemeState } from './utils';
|
|
11
|
+
|
|
12
|
+
export interface InlineCheckboxProps {
|
|
13
|
+
/**
|
|
14
|
+
* Control whether the checkbox is checked
|
|
15
|
+
*/
|
|
16
|
+
checked?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Checkbox's description.
|
|
19
|
+
*/
|
|
20
|
+
description?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Whether the checkbox is disabled
|
|
23
|
+
*/
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Event handler.
|
|
27
|
+
*/
|
|
28
|
+
onPress?: () => void;
|
|
29
|
+
/**
|
|
30
|
+
* Additional style.
|
|
31
|
+
*/
|
|
32
|
+
style?: StyleProp<ViewStyle>;
|
|
33
|
+
/**
|
|
34
|
+
* Testing id of the component.
|
|
35
|
+
*/
|
|
36
|
+
testID?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Readonly of the checkbox.
|
|
39
|
+
*/
|
|
40
|
+
readonly?: boolean;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Size of the checkbox. Can be 'medium' or 'large'.
|
|
44
|
+
*/
|
|
45
|
+
size?: 'medium' | 'large';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const InlineCheckbox = ({
|
|
49
|
+
checked = false,
|
|
50
|
+
description,
|
|
51
|
+
disabled = false,
|
|
52
|
+
onPress,
|
|
53
|
+
style,
|
|
54
|
+
testID,
|
|
55
|
+
readonly = false,
|
|
56
|
+
size = 'medium',
|
|
57
|
+
}: InlineCheckboxProps) => {
|
|
58
|
+
const themeState = getThemeState({ disabled, readonly, checked });
|
|
59
|
+
return (
|
|
60
|
+
<StyledWrapper
|
|
61
|
+
onPress={onPress}
|
|
62
|
+
disabled={disabled || readonly}
|
|
63
|
+
themeState={themeState}
|
|
64
|
+
style={style}
|
|
65
|
+
testID={testID}
|
|
66
|
+
accessibilityRole="checkbox"
|
|
67
|
+
accessibilityState={{
|
|
68
|
+
checked,
|
|
69
|
+
disabled: disabled || readonly,
|
|
70
|
+
}}
|
|
71
|
+
accessibilityLabel={description}
|
|
72
|
+
>
|
|
73
|
+
<StyledCheckboxContainer themeSize={size}>
|
|
74
|
+
{checked && (
|
|
75
|
+
<StyledCheckMark
|
|
76
|
+
themeIntent="primary"
|
|
77
|
+
name="box-check"
|
|
78
|
+
testID="check-mark"
|
|
79
|
+
themeState={themeState}
|
|
80
|
+
themeSize={size}
|
|
81
|
+
/>
|
|
82
|
+
)}
|
|
83
|
+
<StyledCheckbox themeState={themeState} themeSize={size} />
|
|
84
|
+
</StyledCheckboxContainer>
|
|
85
|
+
{!!description && (
|
|
86
|
+
<StyledDescription
|
|
87
|
+
intent={disabled ? 'subdued' : 'body'}
|
|
88
|
+
variant={size === 'large' ? 'regular' : 'small'}
|
|
89
|
+
>
|
|
90
|
+
{description}
|
|
91
|
+
</StyledDescription>
|
|
92
|
+
)}
|
|
93
|
+
</StyledWrapper>
|
|
94
|
+
);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export default InlineCheckbox;
|
|
@@ -13,6 +13,7 @@ export const StyledWrapper = styled(TouchableOpacity)<{
|
|
|
13
13
|
borderWidth: theme.__hd__.checkbox.borderWidths.wrapper,
|
|
14
14
|
padding: theme.__hd__.checkbox.space.wrapperPadding,
|
|
15
15
|
borderColor: theme.__hd__.checkbox.colors.borders[themeState],
|
|
16
|
+
gap: theme.__hd__.checkbox.space.inlineCheckboxGap,
|
|
16
17
|
}));
|
|
17
18
|
|
|
18
19
|
export const StyledDescription = styled(Typography.Body)(({ theme }) => ({
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import styled from '@emotion/native';
|
|
2
|
+
import { TouchableOpacity, View } from 'react-native';
|
|
3
|
+
import Typography from '../Typography';
|
|
4
|
+
import HeroIcon from '../Icon/HeroIcon';
|
|
5
|
+
|
|
6
|
+
type CheckboxThemeState = 'default' | 'checked' | 'disabled' | 'readonly';
|
|
7
|
+
|
|
8
|
+
export const StyledWrapper = styled(TouchableOpacity)<{
|
|
9
|
+
themeState: CheckboxThemeState;
|
|
10
|
+
}>(({ theme }) => ({
|
|
11
|
+
flexDirection: 'row',
|
|
12
|
+
gap: theme.__hd__.checkbox.space.inlineCheckboxGap,
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
export const StyledDescription = styled(Typography.Body)({
|
|
16
|
+
flex: 1,
|
|
17
|
+
alignSelf: 'center',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const StyledCheckboxContainer = styled(View)<{
|
|
21
|
+
themeSize?: 'medium' | 'large';
|
|
22
|
+
}>(({ theme, themeSize = 'medium' }) => ({
|
|
23
|
+
height: theme.__hd__.checkbox.sizes.inlineCheckbox[themeSize],
|
|
24
|
+
width: theme.__hd__.checkbox.sizes.inlineCheckbox[themeSize],
|
|
25
|
+
overflow: 'hidden',
|
|
26
|
+
margin: theme.__hd__.checkbox.space.inlineCheckboxMargin,
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
export const StyledCheckbox = styled(View)<{
|
|
30
|
+
themeState: CheckboxThemeState;
|
|
31
|
+
themeSize?: 'medium' | 'large';
|
|
32
|
+
}>(({ theme, themeState }) => ({
|
|
33
|
+
flex: 1,
|
|
34
|
+
borderRadius: theme.__hd__.checkbox.radii.icon,
|
|
35
|
+
borderWidth: theme.__hd__.checkbox.borderWidths.icon,
|
|
36
|
+
borderColor: theme.__hd__.checkbox.colors.checkboxBorder[themeState],
|
|
37
|
+
overflow: 'hidden',
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
export const StyledCheckMark = styled(HeroIcon)<{
|
|
41
|
+
themeState: CheckboxThemeState;
|
|
42
|
+
themeSize?: 'medium' | 'large';
|
|
43
|
+
}>(({ theme, themeState, themeSize = 'medium' }) => ({
|
|
44
|
+
position: 'absolute',
|
|
45
|
+
overflow: 'hidden',
|
|
46
|
+
borderRadius: theme.__hd__.checkbox.radii.icon,
|
|
47
|
+
color: theme.__hd__.checkbox.colors.checkboxBorder[themeState],
|
|
48
|
+
fontSize: theme.__hd__.checkbox.sizes.inlineCheckbox[themeSize],
|
|
49
|
+
}));
|
|
@@ -2,26 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { fireEvent } from '@testing-library/react-native';
|
|
3
3
|
|
|
4
4
|
import renderWithTheme from '../../../testHelpers/renderWithTheme';
|
|
5
|
-
import Checkbox
|
|
6
|
-
|
|
7
|
-
describe('getThemeState', () => {
|
|
8
|
-
it.each`
|
|
9
|
-
disabled | readonly | checked | expected
|
|
10
|
-
${false} | ${false} | ${false} | ${'default'}
|
|
11
|
-
${false} | ${false} | ${true} | ${'checked'}
|
|
12
|
-
${false} | ${true} | ${false} | ${'readonly'}
|
|
13
|
-
${false} | ${true} | ${true} | ${'readonly'}
|
|
14
|
-
${true} | ${false} | ${false} | ${'disabled'}
|
|
15
|
-
${true} | ${false} | ${true} | ${'disabled'}
|
|
16
|
-
${true} | ${true} | ${false} | ${'disabled'}
|
|
17
|
-
${true} | ${true} | ${true} | ${'disabled'}
|
|
18
|
-
`(
|
|
19
|
-
`should return correctly if disabled is $disabled and readonly is $readonly`,
|
|
20
|
-
({ disabled, readonly, checked, expected }) => {
|
|
21
|
-
expect(getThemeState({ disabled, readonly, checked })).toBe(expected);
|
|
22
|
-
}
|
|
23
|
-
);
|
|
24
|
-
});
|
|
5
|
+
import Checkbox from '../DefaultCheckBox';
|
|
25
6
|
|
|
26
7
|
describe('Checkbox', () => {
|
|
27
8
|
it.each`
|
|
@@ -71,4 +52,24 @@ describe('Checkbox', () => {
|
|
|
71
52
|
fireEvent.press(wrapper.getByTestId('checkbox'));
|
|
72
53
|
expect(pressFn).toBeCalled();
|
|
73
54
|
});
|
|
55
|
+
|
|
56
|
+
it('does not trigger press function when disabled', () => {
|
|
57
|
+
const pressFn = jest.fn();
|
|
58
|
+
const wrapper = renderWithTheme(
|
|
59
|
+
<Checkbox testID="checkbox" onPress={pressFn} disabled />
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
fireEvent.press(wrapper.getByTestId('checkbox'));
|
|
63
|
+
expect(pressFn).not.toBeCalled();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('does not trigger press function when readonly', () => {
|
|
67
|
+
const pressFn = jest.fn();
|
|
68
|
+
const wrapper = renderWithTheme(
|
|
69
|
+
<Checkbox testID="checkbox" onPress={pressFn} readonly />
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
fireEvent.press(wrapper.getByTestId('checkbox'));
|
|
73
|
+
expect(pressFn).not.toBeCalled();
|
|
74
|
+
});
|
|
74
75
|
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { fireEvent } from '@testing-library/react-native';
|
|
3
|
+
|
|
4
|
+
import renderWithTheme from '../../../testHelpers/renderWithTheme';
|
|
5
|
+
import InlineCheckbox from '../InlineCheckBox';
|
|
6
|
+
|
|
7
|
+
describe('InlineCheckbox', () => {
|
|
8
|
+
it.each`
|
|
9
|
+
disabled | readonly
|
|
10
|
+
${false} | ${false}
|
|
11
|
+
${true} | ${false}
|
|
12
|
+
${false} | ${true}
|
|
13
|
+
${true} | ${true}
|
|
14
|
+
`(
|
|
15
|
+
'renders correctly when disabled is $disabled and readonly is $readonly',
|
|
16
|
+
({ disabled, readonly }) => {
|
|
17
|
+
const wrapper = renderWithTheme(
|
|
18
|
+
<InlineCheckbox
|
|
19
|
+
disabled={disabled}
|
|
20
|
+
readonly={readonly}
|
|
21
|
+
description="Please agree to our privacy policy"
|
|
22
|
+
/>
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
expect(
|
|
26
|
+
wrapper.getByText('Please agree to our privacy policy')
|
|
27
|
+
).toBeTruthy();
|
|
28
|
+
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
it.each`
|
|
33
|
+
checked | length
|
|
34
|
+
${false} | ${0}
|
|
35
|
+
${true} | ${1}
|
|
36
|
+
`(
|
|
37
|
+
'renders correctly when checked is $checked and there is no description',
|
|
38
|
+
({ checked, length }) => {
|
|
39
|
+
const wrapper = renderWithTheme(<InlineCheckbox checked={checked} />);
|
|
40
|
+
|
|
41
|
+
expect(wrapper.queryAllByTestId('check-mark')).toHaveLength(length);
|
|
42
|
+
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
it('trigger press function correctly', () => {
|
|
47
|
+
const pressFn = jest.fn();
|
|
48
|
+
const wrapper = renderWithTheme(
|
|
49
|
+
<InlineCheckbox testID="checkbox" onPress={pressFn} />
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
fireEvent.press(wrapper.getByTestId('checkbox'));
|
|
53
|
+
expect(pressFn).toBeCalled();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('does not trigger press function when disabled', () => {
|
|
57
|
+
const pressFn = jest.fn();
|
|
58
|
+
const wrapper = renderWithTheme(
|
|
59
|
+
<InlineCheckbox testID="checkbox" onPress={pressFn} disabled />
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
fireEvent.press(wrapper.getByTestId('checkbox'));
|
|
63
|
+
expect(pressFn).not.toBeCalled();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('does not trigger press function when readonly', () => {
|
|
67
|
+
const pressFn = jest.fn();
|
|
68
|
+
const wrapper = renderWithTheme(
|
|
69
|
+
<InlineCheckbox testID="checkbox" onPress={pressFn} readonly />
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
fireEvent.press(wrapper.getByTestId('checkbox'));
|
|
73
|
+
expect(pressFn).not.toBeCalled();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it.each`
|
|
77
|
+
size
|
|
78
|
+
${'medium'}
|
|
79
|
+
${'large'}
|
|
80
|
+
`('renders correctly when size is $size', ({ size }) => {
|
|
81
|
+
const wrapper = renderWithTheme(
|
|
82
|
+
<InlineCheckbox
|
|
83
|
+
size={size}
|
|
84
|
+
description="Please agree to our privacy policy"
|
|
85
|
+
/>
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
expect(
|
|
89
|
+
wrapper.getByText('Please agree to our privacy policy')
|
|
90
|
+
).toBeTruthy();
|
|
91
|
+
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
92
|
+
});
|
|
93
|
+
});
|
package/src/components/Checkbox/__tests__/{StyledCheckbox.spec.tsx → StyledDefaultCheckbox.spec.tsx}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import renderWithTheme from '../../../testHelpers/renderWithTheme';
|
|
3
|
-
import { StyledWrapper, StyledCheckbox } from '../
|
|
4
|
-
import { getThemeState } from '
|
|
3
|
+
import { StyledWrapper, StyledCheckbox } from '../StyledDefaultCheckBox';
|
|
4
|
+
import { getThemeState } from '../utils';
|
|
5
5
|
|
|
6
6
|
describe('StyledWrapper', () => {
|
|
7
7
|
it.each`
|
|
@@ -42,6 +42,7 @@ exports[`Checkbox renders correctly when checked is false and there is no descri
|
|
|
42
42
|
"borderRadius": 8,
|
|
43
43
|
"borderWidth": 1,
|
|
44
44
|
"flexDirection": "row",
|
|
45
|
+
"gap": 8,
|
|
45
46
|
"opacity": 1,
|
|
46
47
|
"padding": 16,
|
|
47
48
|
}
|
|
@@ -140,6 +141,7 @@ exports[`Checkbox renders correctly when checked is true and there is no descrip
|
|
|
140
141
|
"borderRadius": 8,
|
|
141
142
|
"borderWidth": 1,
|
|
142
143
|
"flexDirection": "row",
|
|
144
|
+
"gap": 8,
|
|
143
145
|
"opacity": 1,
|
|
144
146
|
"padding": 16,
|
|
145
147
|
}
|
|
@@ -260,6 +262,7 @@ exports[`Checkbox renders correctly when disabled is false and readonly is false
|
|
|
260
262
|
"borderRadius": 8,
|
|
261
263
|
"borderWidth": 1,
|
|
262
264
|
"flexDirection": "row",
|
|
265
|
+
"gap": 8,
|
|
263
266
|
"opacity": 1,
|
|
264
267
|
"padding": 16,
|
|
265
268
|
}
|
|
@@ -384,6 +387,7 @@ exports[`Checkbox renders correctly when disabled is false and readonly is true
|
|
|
384
387
|
"borderRadius": 8,
|
|
385
388
|
"borderWidth": 1,
|
|
386
389
|
"flexDirection": "row",
|
|
390
|
+
"gap": 8,
|
|
387
391
|
"opacity": 1,
|
|
388
392
|
"padding": 16,
|
|
389
393
|
}
|
|
@@ -508,6 +512,7 @@ exports[`Checkbox renders correctly when disabled is true and readonly is false
|
|
|
508
512
|
"borderRadius": 8,
|
|
509
513
|
"borderWidth": 1,
|
|
510
514
|
"flexDirection": "row",
|
|
515
|
+
"gap": 8,
|
|
511
516
|
"opacity": 1,
|
|
512
517
|
"padding": 16,
|
|
513
518
|
}
|
|
@@ -632,6 +637,7 @@ exports[`Checkbox renders correctly when disabled is true and readonly is true 1
|
|
|
632
637
|
"borderRadius": 8,
|
|
633
638
|
"borderWidth": 1,
|
|
634
639
|
"flexDirection": "row",
|
|
640
|
+
"gap": 8,
|
|
635
641
|
"opacity": 1,
|
|
636
642
|
"padding": 16,
|
|
637
643
|
}
|