@hero-design/rn 7.20.1 → 7.22.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/.eslintrc.js +11 -0
- package/.turbo/turbo-build.log +9 -9
- package/babel.config.js +1 -1
- package/es/index.js +714 -471
- package/lib/index.js +720 -474
- package/package.json +9 -15
- package/rollup.config.js +1 -0
- package/src/components/BottomNavigation/__tests__/index.spec.tsx +1 -1
- package/src/components/BottomNavigation/index.tsx +3 -3
- package/src/components/BottomSheet/index.tsx +6 -1
- package/src/components/Box/helpers.ts +1 -1
- package/src/components/Calendar/index.tsx +9 -9
- package/src/components/Checkbox/__tests__/__snapshots__/StyledCheckbox.spec.tsx.snap +4 -4
- package/src/components/Checkbox/__tests__/__snapshots__/index.spec.tsx.snap +13 -13
- package/src/components/Collapse/index.tsx +1 -1
- package/src/components/Drawer/DragableDrawer/helpers.ts +7 -3
- package/src/components/Empty/StyledEmpty.tsx +1 -9
- package/src/components/Empty/__tests__/__snapshots__/index.spec.tsx.snap +58 -5
- package/src/components/Empty/__tests__/index.spec.tsx +13 -0
- package/src/components/Empty/index.tsx +38 -18
- package/src/components/FAB/ActionGroup/index.tsx +1 -1
- package/src/components/Icon/HeroIcon/selection.json +7029 -1
- package/src/components/Image/__tests__/__snapshots__/index.spec.tsx.snap +81 -0
- package/src/components/Image/__tests__/index.spec.tsx +29 -0
- package/src/components/Image/index.tsx +46 -0
- package/src/components/List/__tests__/__snapshots__/ListItem.spec.tsx.snap +5 -5
- package/src/components/PinInput/index.tsx +1 -1
- package/src/components/Progress/__tests__/__snapshots__/index.spec.js.snap +60 -60
- package/src/components/RichTextEditor/EditorToolbar.tsx +3 -3
- package/src/components/RichTextEditor/RichTextEditor.tsx +5 -5
- package/src/components/RichTextEditor/__tests__/EditorToolbar.spec.tsx +2 -2
- package/src/components/RichTextEditor/__tests__/MentionList.spec.tsx +1 -1
- package/src/components/RichTextEditor/__tests__/__snapshots__/EditorToolbar.spec.tsx.snap +2 -2
- package/src/components/RichTextEditor/__tests__/__snapshots__/RichTextEditor.spec.tsx.snap +2 -2
- package/src/components/Select/MultiSelect/OptionList.tsx +5 -7
- package/src/components/Select/MultiSelect/__tests__/index.spec.tsx +21 -0
- package/src/components/Select/MultiSelect/index.tsx +35 -5
- package/src/components/Select/SingleSelect/OptionList.tsx +4 -5
- package/src/components/Select/SingleSelect/__tests__/index.spec.tsx +16 -0
- package/src/components/Select/SingleSelect/index.tsx +36 -6
- package/src/components/Select/StyledOptionList.tsx +3 -9
- package/src/components/Select/helpers.tsx +4 -4
- package/src/components/Slider/__tests__/__snapshots__/index.spec.tsx.snap +43 -0
- package/src/components/Slider/__tests__/index.spec.tsx +33 -0
- package/src/components/Slider/index.tsx +89 -0
- package/src/components/Switch/SelectorSwitch/Option.tsx +67 -0
- package/src/components/Switch/SelectorSwitch/StyledSelectorSwitch.tsx +25 -0
- package/src/components/Switch/SelectorSwitch/__tests__/Option.spec.tsx +61 -0
- package/src/components/Switch/SelectorSwitch/__tests__/__snapshots__/Option.spec.tsx.snap +195 -0
- package/src/components/Switch/SelectorSwitch/__tests__/__snapshots__/index.spec.tsx.snap +121 -0
- package/src/components/Switch/SelectorSwitch/__tests__/index.spec.tsx +62 -0
- package/src/components/Switch/SelectorSwitch/index.tsx +60 -0
- package/src/components/Switch/StyledSwitch.tsx +4 -4
- package/src/components/Switch/__tests__/__snapshots__/StyledSwitch.spec.tsx.snap +10 -10
- package/src/components/Switch/__tests__/__snapshots__/index.spec.tsx.snap +8 -8
- package/src/components/Switch/index.tsx +9 -5
- package/src/components/Tabs/ScrollableTabs.tsx +12 -5
- package/src/components/Tabs/__tests__/ScrollableTabs.spec.tsx +1 -1
- package/src/components/Tabs/__tests__/index.spec.tsx +1 -1
- package/src/components/Tabs/index.tsx +13 -6
- package/src/components/TextInput/__tests__/__snapshots__/index.spec.tsx.snap +3 -1
- package/src/components/TextInput/__tests__/index.spec.tsx +114 -112
- package/src/components/TextInput/index.tsx +64 -59
- package/src/components/Toast/ToastContainer.tsx +6 -6
- package/src/index.ts +4 -0
- package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +70 -23
- package/src/theme/components/alert.ts +1 -2
- package/src/theme/components/avatar.ts +8 -8
- package/src/theme/components/badge.ts +4 -4
- package/src/theme/components/bottomNavigation.ts +1 -1
- package/src/theme/components/bottomSheet.ts +2 -3
- package/src/theme/components/calendar.ts +9 -7
- package/src/theme/components/card.ts +1 -1
- package/src/theme/components/checkbox.ts +2 -5
- package/src/theme/components/datePicker.ts +3 -3
- package/src/theme/components/drawer.ts +2 -3
- package/src/theme/components/empty.ts +3 -8
- package/src/theme/components/fab.ts +2 -2
- package/src/theme/components/image.ts +12 -0
- package/src/theme/components/pinInput.ts +3 -3
- package/src/theme/components/progress.ts +2 -3
- package/src/theme/components/radio.ts +7 -3
- package/src/theme/components/richTextEditor.ts +4 -4
- package/src/theme/components/slider.ts +13 -0
- package/src/theme/components/switch.ts +28 -17
- package/src/theme/components/tabs.ts +1 -1
- package/src/theme/components/timePicker.ts +3 -3
- package/src/theme/components/toast.ts +1 -2
- package/src/theme/getTheme.ts +9 -2
- package/src/theme/global/colors/swag.ts +2 -0
- package/src/theme/global/colors/types.ts +2 -0
- package/src/theme/global/index.ts +3 -0
- package/src/theme/global/scale.ts +3 -0
- package/src/theme/global/sizes.ts +29 -0
- package/testUtils/setup.tsx +15 -1
- package/tsconfig.json +1 -1
- package/types/components/BottomSheet/index.d.ts +5 -1
- package/types/components/Empty/StyledEmpty.d.ts +1 -7
- package/types/components/Empty/index.d.ts +8 -2
- package/types/components/Image/__tests__/index.spec.d.ts +1 -0
- package/types/components/Image/index.d.ts +17 -0
- package/types/components/Select/MultiSelect/OptionList.d.ts +5 -2
- package/types/components/Select/MultiSelect/index.d.ts +7 -1
- package/types/components/Select/SingleSelect/OptionList.d.ts +5 -2
- package/types/components/Select/SingleSelect/index.d.ts +8 -2
- package/types/components/Select/StyledOptionList.d.ts +4 -3
- package/types/components/Select/index.d.ts +1 -1
- package/types/components/Slider/__tests__/index.spec.d.ts +1 -0
- package/types/components/Slider/index.d.ts +52 -0
- package/types/components/Switch/SelectorSwitch/Option.d.ts +10 -0
- package/types/components/Switch/SelectorSwitch/StyledSelectorSwitch.d.ts +19 -0
- package/types/components/Switch/SelectorSwitch/__tests__/Option.spec.d.ts +1 -0
- package/types/components/Switch/SelectorSwitch/__tests__/index.spec.d.ts +1 -0
- package/types/components/Switch/SelectorSwitch/index.d.ts +37 -0
- package/types/components/Switch/index.d.ts +5 -3
- package/types/components/Tabs/ScrollableTabs.d.ts +1 -1
- package/types/components/Tabs/index.d.ts +2 -2
- package/types/components/TextInput/index.d.ts +6 -5
- package/types/index.d.ts +3 -1
- package/types/theme/components/datePicker.d.ts +2 -1
- package/types/theme/components/empty.d.ts +2 -5
- package/types/theme/components/image.d.ts +8 -0
- package/types/theme/components/slider.d.ts +9 -0
- package/types/theme/components/switch.d.ts +27 -12
- package/types/theme/components/timePicker.d.ts +2 -1
- package/types/theme/getTheme.d.ts +4 -0
- package/types/theme/global/colors/types.d.ts +2 -0
- package/types/theme/global/index.d.ts +3 -0
- package/types/theme/global/scale.d.ts +1 -0
- package/types/theme/global/sizes.d.ts +14 -0
- package/.eslintrc.json +0 -61
- package/.prettierrc.json +0 -8
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import renderWithTheme from '../../../../testHelpers/renderWithTheme';
|
|
3
|
+
import Icon from '../../../Icon';
|
|
4
|
+
import Option, { OptionContent } from '../Option';
|
|
5
|
+
|
|
6
|
+
describe('Option', () => {
|
|
7
|
+
it('renders correctly when selected', () => {
|
|
8
|
+
const wrapper = renderWithTheme(
|
|
9
|
+
<Option
|
|
10
|
+
text="My Dashboard"
|
|
11
|
+
icon="user"
|
|
12
|
+
badge={{ type: 'status' }}
|
|
13
|
+
selected
|
|
14
|
+
/>
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
expect(wrapper.queryAllByText('My Dashboard')).toHaveLength(1);
|
|
18
|
+
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('renders correctly when not selected', () => {
|
|
22
|
+
const wrapper = renderWithTheme(
|
|
23
|
+
<Option
|
|
24
|
+
text="My Dashboard"
|
|
25
|
+
icon="user"
|
|
26
|
+
badge={{ type: 'status' }}
|
|
27
|
+
selected={false}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
expect(wrapper.queryAllByText('My Dashboard')).toHaveLength(0);
|
|
32
|
+
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('OptionContent', () => {
|
|
37
|
+
it('renders correctly there is no badge', () => {
|
|
38
|
+
const wrapper = renderWithTheme(
|
|
39
|
+
<OptionContent content={<Icon icon="user" />} />
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
expect(
|
|
43
|
+
wrapper.queryAllByTestId('selector-switch-status-badge')
|
|
44
|
+
).toHaveLength(0);
|
|
45
|
+
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('renders correctly when there is a badge', () => {
|
|
49
|
+
const wrapper = renderWithTheme(
|
|
50
|
+
<OptionContent
|
|
51
|
+
content={<Icon icon="user" />}
|
|
52
|
+
badge={{ type: 'status' }}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
expect(
|
|
57
|
+
wrapper.queryAllByTestId('selector-switch-status-badge')
|
|
58
|
+
).toHaveLength(1);
|
|
59
|
+
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Option renders correctly when not selected 1`] = `
|
|
4
|
+
<View
|
|
5
|
+
style={
|
|
6
|
+
Array [
|
|
7
|
+
Object {
|
|
8
|
+
"alignItems": "center",
|
|
9
|
+
"justifyContent": "center",
|
|
10
|
+
"paddingHorizontal": 16,
|
|
11
|
+
},
|
|
12
|
+
undefined,
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
>
|
|
16
|
+
<View
|
|
17
|
+
style={
|
|
18
|
+
Object {
|
|
19
|
+
"paddingHorizontal": 8,
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
testID="selector-switch-status-badge"
|
|
23
|
+
>
|
|
24
|
+
<HeroIcon
|
|
25
|
+
name="user"
|
|
26
|
+
style={
|
|
27
|
+
Array [
|
|
28
|
+
Object {
|
|
29
|
+
"color": "#001f23",
|
|
30
|
+
"fontSize": 24,
|
|
31
|
+
},
|
|
32
|
+
undefined,
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
themeIntent="text"
|
|
36
|
+
themeSize="medium"
|
|
37
|
+
/>
|
|
38
|
+
<View
|
|
39
|
+
collapsable={false}
|
|
40
|
+
nativeID="animatedComponent"
|
|
41
|
+
style={
|
|
42
|
+
Object {
|
|
43
|
+
"backgroundColor": "#de350b",
|
|
44
|
+
"borderRadius": 999,
|
|
45
|
+
"height": 8,
|
|
46
|
+
"opacity": 1,
|
|
47
|
+
"position": "absolute",
|
|
48
|
+
"right": -2,
|
|
49
|
+
"top": -2,
|
|
50
|
+
"transform": Array [
|
|
51
|
+
Object {
|
|
52
|
+
"scale": 1,
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
"width": 8,
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
themeIntent="danger"
|
|
59
|
+
/>
|
|
60
|
+
</View>
|
|
61
|
+
</View>
|
|
62
|
+
`;
|
|
63
|
+
|
|
64
|
+
exports[`Option renders correctly when selected 1`] = `
|
|
65
|
+
<View
|
|
66
|
+
style={
|
|
67
|
+
Array [
|
|
68
|
+
Object {
|
|
69
|
+
"alignItems": "center",
|
|
70
|
+
"backgroundColor": "#401960",
|
|
71
|
+
"borderRadius": 999,
|
|
72
|
+
"flex": 1,
|
|
73
|
+
"justifyContent": "center",
|
|
74
|
+
},
|
|
75
|
+
undefined,
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
>
|
|
79
|
+
<View
|
|
80
|
+
style={
|
|
81
|
+
Object {
|
|
82
|
+
"paddingHorizontal": 8,
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
testID="selector-switch-status-badge"
|
|
86
|
+
>
|
|
87
|
+
<Text
|
|
88
|
+
style={
|
|
89
|
+
Array [
|
|
90
|
+
Object {
|
|
91
|
+
"color": "#ffffff",
|
|
92
|
+
"fontFamily": "BeVietnamPro-Regular",
|
|
93
|
+
"fontSize": 16,
|
|
94
|
+
"letterSpacing": 0.48,
|
|
95
|
+
"lineHeight": 24,
|
|
96
|
+
},
|
|
97
|
+
undefined,
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
themeFontSize="large"
|
|
101
|
+
themeFontWeight="regular"
|
|
102
|
+
themeIntent="inverted"
|
|
103
|
+
>
|
|
104
|
+
My Dashboard
|
|
105
|
+
</Text>
|
|
106
|
+
<View
|
|
107
|
+
collapsable={false}
|
|
108
|
+
nativeID="animatedComponent"
|
|
109
|
+
style={
|
|
110
|
+
Object {
|
|
111
|
+
"backgroundColor": "#de350b",
|
|
112
|
+
"borderRadius": 999,
|
|
113
|
+
"height": 8,
|
|
114
|
+
"opacity": 1,
|
|
115
|
+
"position": "absolute",
|
|
116
|
+
"right": -2,
|
|
117
|
+
"top": -2,
|
|
118
|
+
"transform": Array [
|
|
119
|
+
Object {
|
|
120
|
+
"scale": 1,
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
"width": 8,
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
themeIntent="danger"
|
|
127
|
+
/>
|
|
128
|
+
</View>
|
|
129
|
+
</View>
|
|
130
|
+
`;
|
|
131
|
+
|
|
132
|
+
exports[`OptionContent renders correctly there is no badge 1`] = `
|
|
133
|
+
<HeroIcon
|
|
134
|
+
name="user"
|
|
135
|
+
style={
|
|
136
|
+
Array [
|
|
137
|
+
Object {
|
|
138
|
+
"color": "#001f23",
|
|
139
|
+
"fontSize": 24,
|
|
140
|
+
},
|
|
141
|
+
undefined,
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
themeIntent="text"
|
|
145
|
+
themeSize="medium"
|
|
146
|
+
/>
|
|
147
|
+
`;
|
|
148
|
+
|
|
149
|
+
exports[`OptionContent renders correctly when there is a badge 1`] = `
|
|
150
|
+
<View
|
|
151
|
+
style={
|
|
152
|
+
Object {
|
|
153
|
+
"paddingHorizontal": 8,
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
testID="selector-switch-status-badge"
|
|
157
|
+
>
|
|
158
|
+
<HeroIcon
|
|
159
|
+
name="user"
|
|
160
|
+
style={
|
|
161
|
+
Array [
|
|
162
|
+
Object {
|
|
163
|
+
"color": "#001f23",
|
|
164
|
+
"fontSize": 24,
|
|
165
|
+
},
|
|
166
|
+
undefined,
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
themeIntent="text"
|
|
170
|
+
themeSize="medium"
|
|
171
|
+
/>
|
|
172
|
+
<View
|
|
173
|
+
collapsable={false}
|
|
174
|
+
nativeID="animatedComponent"
|
|
175
|
+
style={
|
|
176
|
+
Object {
|
|
177
|
+
"backgroundColor": "#de350b",
|
|
178
|
+
"borderRadius": 999,
|
|
179
|
+
"height": 8,
|
|
180
|
+
"opacity": 1,
|
|
181
|
+
"position": "absolute",
|
|
182
|
+
"right": -2,
|
|
183
|
+
"top": -2,
|
|
184
|
+
"transform": Array [
|
|
185
|
+
Object {
|
|
186
|
+
"scale": 1,
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
"width": 8,
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
themeIntent="danger"
|
|
193
|
+
/>
|
|
194
|
+
</View>
|
|
195
|
+
`;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`SelectorSwitch renders correctly 1`] = `
|
|
4
|
+
<View
|
|
5
|
+
accessible={true}
|
|
6
|
+
focusable={true}
|
|
7
|
+
onClick={[Function]}
|
|
8
|
+
onResponderGrant={[Function]}
|
|
9
|
+
onResponderMove={[Function]}
|
|
10
|
+
onResponderRelease={[Function]}
|
|
11
|
+
onResponderTerminate={[Function]}
|
|
12
|
+
onResponderTerminationRequest={[Function]}
|
|
13
|
+
onStartShouldSetResponder={[Function]}
|
|
14
|
+
style={
|
|
15
|
+
Array [
|
|
16
|
+
Object {
|
|
17
|
+
"backgroundColor": "#f6f6f7",
|
|
18
|
+
"borderRadius": 999,
|
|
19
|
+
"flexDirection": "row",
|
|
20
|
+
"height": 56,
|
|
21
|
+
"padding": 4,
|
|
22
|
+
"width": "100%",
|
|
23
|
+
},
|
|
24
|
+
undefined,
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
>
|
|
28
|
+
<View
|
|
29
|
+
style={
|
|
30
|
+
Array [
|
|
31
|
+
Object {
|
|
32
|
+
"alignItems": "center",
|
|
33
|
+
"backgroundColor": "#401960",
|
|
34
|
+
"borderRadius": 999,
|
|
35
|
+
"flex": 1,
|
|
36
|
+
"justifyContent": "center",
|
|
37
|
+
},
|
|
38
|
+
undefined,
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
>
|
|
42
|
+
<Text
|
|
43
|
+
style={
|
|
44
|
+
Array [
|
|
45
|
+
Object {
|
|
46
|
+
"color": "#ffffff",
|
|
47
|
+
"fontFamily": "BeVietnamPro-Regular",
|
|
48
|
+
"fontSize": 16,
|
|
49
|
+
"letterSpacing": 0.48,
|
|
50
|
+
"lineHeight": 24,
|
|
51
|
+
},
|
|
52
|
+
undefined,
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
themeFontSize="large"
|
|
56
|
+
themeFontWeight="regular"
|
|
57
|
+
themeIntent="inverted"
|
|
58
|
+
>
|
|
59
|
+
My Dashboard
|
|
60
|
+
</Text>
|
|
61
|
+
</View>
|
|
62
|
+
<View
|
|
63
|
+
style={
|
|
64
|
+
Array [
|
|
65
|
+
Object {
|
|
66
|
+
"alignItems": "center",
|
|
67
|
+
"justifyContent": "center",
|
|
68
|
+
"paddingHorizontal": 16,
|
|
69
|
+
},
|
|
70
|
+
undefined,
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
>
|
|
74
|
+
<View
|
|
75
|
+
style={
|
|
76
|
+
Object {
|
|
77
|
+
"paddingHorizontal": 8,
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
testID="selector-switch-status-badge"
|
|
81
|
+
>
|
|
82
|
+
<HeroIcon
|
|
83
|
+
name="multiple-users"
|
|
84
|
+
style={
|
|
85
|
+
Array [
|
|
86
|
+
Object {
|
|
87
|
+
"color": "#001f23",
|
|
88
|
+
"fontSize": 24,
|
|
89
|
+
},
|
|
90
|
+
undefined,
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
themeIntent="text"
|
|
94
|
+
themeSize="medium"
|
|
95
|
+
/>
|
|
96
|
+
<View
|
|
97
|
+
collapsable={false}
|
|
98
|
+
nativeID="animatedComponent"
|
|
99
|
+
style={
|
|
100
|
+
Object {
|
|
101
|
+
"backgroundColor": "#de350b",
|
|
102
|
+
"borderRadius": 999,
|
|
103
|
+
"height": 8,
|
|
104
|
+
"opacity": 1,
|
|
105
|
+
"position": "absolute",
|
|
106
|
+
"right": -2,
|
|
107
|
+
"top": -2,
|
|
108
|
+
"transform": Array [
|
|
109
|
+
Object {
|
|
110
|
+
"scale": 1,
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
"width": 8,
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
themeIntent="danger"
|
|
117
|
+
/>
|
|
118
|
+
</View>
|
|
119
|
+
</View>
|
|
120
|
+
</View>
|
|
121
|
+
`;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { fireEvent } from '@testing-library/react-native';
|
|
3
|
+
import renderWithTheme from '../../../../testHelpers/renderWithTheme';
|
|
4
|
+
import SelectorSwitch from '..';
|
|
5
|
+
|
|
6
|
+
type PermissionType = 'employee' | 'manager';
|
|
7
|
+
|
|
8
|
+
describe('SelectorSwitch', () => {
|
|
9
|
+
it('renders correctly', () => {
|
|
10
|
+
const wrapper = renderWithTheme(
|
|
11
|
+
<SelectorSwitch<PermissionType>
|
|
12
|
+
options={[
|
|
13
|
+
{
|
|
14
|
+
value: 'employee',
|
|
15
|
+
text: 'My Dashboard',
|
|
16
|
+
icon: 'user',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
value: 'manager',
|
|
20
|
+
text: 'Manager Dashboard',
|
|
21
|
+
icon: 'multiple-users',
|
|
22
|
+
badge: { type: 'status' },
|
|
23
|
+
},
|
|
24
|
+
]}
|
|
25
|
+
value="employee"
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
expect(wrapper.queryAllByText('My Dashboard')).toHaveLength(1);
|
|
30
|
+
expect(wrapper.queryAllByText('Manager Dashboard')).toHaveLength(0);
|
|
31
|
+
expect(
|
|
32
|
+
wrapper.queryAllByTestId('selector-switch-status-badge')
|
|
33
|
+
).toHaveLength(1);
|
|
34
|
+
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('triggers onPress correctly', () => {
|
|
38
|
+
const onPress = jest.fn();
|
|
39
|
+
const wrapper = renderWithTheme(
|
|
40
|
+
<SelectorSwitch<PermissionType>
|
|
41
|
+
options={[
|
|
42
|
+
{
|
|
43
|
+
value: 'employee',
|
|
44
|
+
text: 'My Dashboard',
|
|
45
|
+
icon: 'user',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
value: 'manager',
|
|
49
|
+
text: 'Manager Dashboard',
|
|
50
|
+
icon: 'multiple-users',
|
|
51
|
+
badge: { type: 'status' },
|
|
52
|
+
},
|
|
53
|
+
]}
|
|
54
|
+
value="manager"
|
|
55
|
+
onPress={onPress}
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
fireEvent.press(wrapper.getByText('Manager Dashboard'));
|
|
60
|
+
expect(onPress).toBeCalledTimes(1);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
import { StyleProp, TouchableWithoutFeedback, ViewStyle } from 'react-native';
|
|
4
|
+
import { StyledWrapper } from './StyledSelectorSwitch';
|
|
5
|
+
import type { IconName } from '../../Icon';
|
|
6
|
+
import Option from './Option';
|
|
7
|
+
|
|
8
|
+
type StatusBadgeType = {
|
|
9
|
+
type: 'status';
|
|
10
|
+
};
|
|
11
|
+
export type BadgeConfigType = StatusBadgeType;
|
|
12
|
+
|
|
13
|
+
export type OptionType<T> = {
|
|
14
|
+
value: T;
|
|
15
|
+
text: string;
|
|
16
|
+
icon: IconName;
|
|
17
|
+
badge?: BadgeConfigType;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export interface SelectorSwitchProps<T> {
|
|
21
|
+
/**
|
|
22
|
+
* Array of exactly TWO options to switch between.
|
|
23
|
+
*/
|
|
24
|
+
options: [OptionType<T>, OptionType<T>];
|
|
25
|
+
/**
|
|
26
|
+
* Current selected value.
|
|
27
|
+
*/
|
|
28
|
+
value: T;
|
|
29
|
+
/**
|
|
30
|
+
* Callback called when an option is pressed.
|
|
31
|
+
*/
|
|
32
|
+
onPress?: (value: T) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Additional style.
|
|
35
|
+
*/
|
|
36
|
+
style?: StyleProp<ViewStyle>;
|
|
37
|
+
/**
|
|
38
|
+
* Testing id of the component.
|
|
39
|
+
*/
|
|
40
|
+
testID?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const SelectorSwitch = <T,>({
|
|
44
|
+
options,
|
|
45
|
+
value,
|
|
46
|
+
onPress,
|
|
47
|
+
style,
|
|
48
|
+
testID,
|
|
49
|
+
}: SelectorSwitchProps<T>): ReactElement => (
|
|
50
|
+
<TouchableWithoutFeedback onPress={() => onPress(value)} testID={testID}>
|
|
51
|
+
<StyledWrapper style={style}>
|
|
52
|
+
{options.map((opt, index) => (
|
|
53
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
54
|
+
<Option {...opt} selected={opt.value === value} key={index} />
|
|
55
|
+
))}
|
|
56
|
+
</StyledWrapper>
|
|
57
|
+
</TouchableWithoutFeedback>
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
export default SelectorSwitch;
|
|
@@ -13,8 +13,8 @@ const StyledWrapper = styled(View)<{
|
|
|
13
13
|
themeVariant: Variant;
|
|
14
14
|
themeSize: ThemeSize;
|
|
15
15
|
}>(({ theme, themeVariant, themeSize }) => ({
|
|
16
|
-
height: theme.__hd__.switch.heights[themeSize],
|
|
17
|
-
width: theme.__hd__.switch.widths[themeSize],
|
|
16
|
+
height: theme.__hd__.switch.sizes.heights[themeSize],
|
|
17
|
+
width: theme.__hd__.switch.sizes.widths[themeSize],
|
|
18
18
|
paddingHorizontal: theme.__hd__.switch.spaces[themeSize],
|
|
19
19
|
borderRadius: theme.__hd__.switch.radii.rounded,
|
|
20
20
|
backgroundColor: theme.__hd__.switch.colors.backgroundColors[themeVariant],
|
|
@@ -25,8 +25,8 @@ const StyledWrapper = styled(View)<{
|
|
|
25
25
|
const StyledKnot = styled(Animated.View)<{
|
|
26
26
|
themeSize: ThemeSize;
|
|
27
27
|
}>(({ theme, themeSize }) => ({
|
|
28
|
-
width: theme.__hd__.switch.
|
|
29
|
-
height: theme.__hd__.switch.
|
|
28
|
+
width: theme.__hd__.switch.sizes.thumbs[themeSize],
|
|
29
|
+
height: theme.__hd__.switch.sizes.thumbs[themeSize],
|
|
30
30
|
backgroundColor: theme.__hd__.switch.colors.thumb,
|
|
31
31
|
borderRadius: theme.__hd__.switch.radii.rounded,
|
|
32
32
|
}));
|
|
@@ -8,8 +8,8 @@ exports[`StyledKnot renders correct style 1`] = `
|
|
|
8
8
|
Object {
|
|
9
9
|
"backgroundColor": "#ffffff",
|
|
10
10
|
"borderRadius": 999,
|
|
11
|
-
"height":
|
|
12
|
-
"width":
|
|
11
|
+
"height": 24,
|
|
12
|
+
"width": 24,
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
themeSize="medium"
|
|
@@ -24,10 +24,10 @@ exports[`StyledWrapper renders correct style with variant checked 1`] = `
|
|
|
24
24
|
"backgroundColor": "#8505a2",
|
|
25
25
|
"borderRadius": 999,
|
|
26
26
|
"display": "flex",
|
|
27
|
-
"height":
|
|
27
|
+
"height": 32,
|
|
28
28
|
"justifyContent": "center",
|
|
29
29
|
"paddingHorizontal": 4,
|
|
30
|
-
"width":
|
|
30
|
+
"width": 64,
|
|
31
31
|
},
|
|
32
32
|
undefined,
|
|
33
33
|
]
|
|
@@ -45,10 +45,10 @@ exports[`StyledWrapper renders correct style with variant disabled-checked 1`] =
|
|
|
45
45
|
"backgroundColor": "#c282d1",
|
|
46
46
|
"borderRadius": 999,
|
|
47
47
|
"display": "flex",
|
|
48
|
-
"height":
|
|
48
|
+
"height": 32,
|
|
49
49
|
"justifyContent": "center",
|
|
50
50
|
"paddingHorizontal": 4,
|
|
51
|
-
"width":
|
|
51
|
+
"width": 64,
|
|
52
52
|
},
|
|
53
53
|
undefined,
|
|
54
54
|
]
|
|
@@ -66,10 +66,10 @@ exports[`StyledWrapper renders correct style with variant disabled-unchecked 1`]
|
|
|
66
66
|
"backgroundColor": "#ccced1",
|
|
67
67
|
"borderRadius": 999,
|
|
68
68
|
"display": "flex",
|
|
69
|
-
"height":
|
|
69
|
+
"height": 32,
|
|
70
70
|
"justifyContent": "center",
|
|
71
71
|
"paddingHorizontal": 4,
|
|
72
|
-
"width":
|
|
72
|
+
"width": 64,
|
|
73
73
|
},
|
|
74
74
|
undefined,
|
|
75
75
|
]
|
|
@@ -87,10 +87,10 @@ exports[`StyledWrapper renders correct style with variant unchecked 1`] = `
|
|
|
87
87
|
"backgroundColor": "#808f91",
|
|
88
88
|
"borderRadius": 999,
|
|
89
89
|
"display": "flex",
|
|
90
|
-
"height":
|
|
90
|
+
"height": 32,
|
|
91
91
|
"justifyContent": "center",
|
|
92
92
|
"paddingHorizontal": 4,
|
|
93
|
-
"width":
|
|
93
|
+
"width": 64,
|
|
94
94
|
},
|
|
95
95
|
undefined,
|
|
96
96
|
]
|
|
@@ -22,10 +22,10 @@ exports[`Switch renders correctly 1`] = `
|
|
|
22
22
|
"backgroundColor": "#808f91",
|
|
23
23
|
"borderRadius": 999,
|
|
24
24
|
"display": "flex",
|
|
25
|
-
"height":
|
|
25
|
+
"height": 32,
|
|
26
26
|
"justifyContent": "center",
|
|
27
27
|
"paddingHorizontal": 4,
|
|
28
|
-
"width":
|
|
28
|
+
"width": 64,
|
|
29
29
|
},
|
|
30
30
|
undefined,
|
|
31
31
|
]
|
|
@@ -41,9 +41,9 @@ exports[`Switch renders correctly 1`] = `
|
|
|
41
41
|
Object {
|
|
42
42
|
"backgroundColor": "#ffffff",
|
|
43
43
|
"borderRadius": 999,
|
|
44
|
-
"height":
|
|
44
|
+
"height": 24,
|
|
45
45
|
"left": 0,
|
|
46
|
-
"width":
|
|
46
|
+
"width": 24,
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
themeSize="medium"
|
|
@@ -73,10 +73,10 @@ exports[`Switch trigger press function correctly 1`] = `
|
|
|
73
73
|
"backgroundColor": "#808f91",
|
|
74
74
|
"borderRadius": 999,
|
|
75
75
|
"display": "flex",
|
|
76
|
-
"height":
|
|
76
|
+
"height": 32,
|
|
77
77
|
"justifyContent": "center",
|
|
78
78
|
"paddingHorizontal": 4,
|
|
79
|
-
"width":
|
|
79
|
+
"width": 64,
|
|
80
80
|
},
|
|
81
81
|
undefined,
|
|
82
82
|
]
|
|
@@ -92,9 +92,9 @@ exports[`Switch trigger press function correctly 1`] = `
|
|
|
92
92
|
Object {
|
|
93
93
|
"backgroundColor": "#ffffff",
|
|
94
94
|
"borderRadius": 999,
|
|
95
|
-
"height":
|
|
95
|
+
"height": 24,
|
|
96
96
|
"left": 0,
|
|
97
|
-
"width":
|
|
97
|
+
"width": 24,
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
themeSize="medium"
|
|
@@ -6,6 +6,7 @@ import { Animated, Easing, TouchableWithoutFeedback } from 'react-native';
|
|
|
6
6
|
import type { ReactElement } from 'react';
|
|
7
7
|
import type { StyleProp, ViewStyle } from 'react-native';
|
|
8
8
|
import { StyledKnot, StyledWrapper, Variant } from './StyledSwitch';
|
|
9
|
+
import SelectorSwitch from './SelectorSwitch';
|
|
9
10
|
|
|
10
11
|
export interface SwitchProps {
|
|
11
12
|
/**
|
|
@@ -60,10 +61,11 @@ const Switch = ({
|
|
|
60
61
|
const variant = getVariant({ disabled, checked });
|
|
61
62
|
|
|
62
63
|
const offset = checked
|
|
63
|
-
? theme.__hd__.switch.widths[size] -
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
? (theme.__hd__.switch.sizes.widths[size] -
|
|
65
|
+
theme.__hd__.switch.sizes.thumbs[size]) /
|
|
66
|
+
2 +
|
|
67
|
+
theme.__hd__.switch.sizes.thumbs[size] / 2
|
|
68
|
+
: 0;
|
|
67
69
|
|
|
68
70
|
const [animatedOffset] = useState(() => new Animated.Value(offset));
|
|
69
71
|
|
|
@@ -87,4 +89,6 @@ const Switch = ({
|
|
|
87
89
|
);
|
|
88
90
|
};
|
|
89
91
|
|
|
90
|
-
export default Switch
|
|
92
|
+
export default Object.assign(Switch, {
|
|
93
|
+
Selector: SelectorSwitch,
|
|
94
|
+
});
|