@hero-design/rn 7.16.2 → 7.17.1
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/es/index.js +331 -259
- package/lib/index.js +330 -258
- package/package.json +2 -2
- package/src/components/Accordion/__tests__/__snapshots__/AccordionItem.spec.tsx.snap +12 -12
- package/src/components/Accordion/__tests__/__snapshots__/index.spec.tsx.snap +18 -18
- package/src/components/Alert/__tests__/__snapshots__/index.spec.tsx.snap +26 -26
- package/src/components/Avatar/__tests__/__snapshots__/StyledAvatar.spec.tsx.snap +3 -3
- package/src/components/Avatar/__tests__/__snapshots__/index.spec.tsx.snap +2 -2
- package/src/components/Badge/__tests__/__snapshots__/Badge.spec.tsx.snap +1 -1
- package/src/components/Badge/__tests__/__snapshots__/Status.spec.tsx.snap +2 -2
- package/src/components/BottomNavigation/__tests__/__snapshots__/index.spec.tsx.snap +9 -9
- package/src/components/BottomSheet/__tests__/__snapshots__/index.spec.tsx.snap +12 -12
- package/src/components/Button/LoadingIndicator/__tests__/__snapshots__/StyledLoadingIndicator.spec.tsx.snap +2 -2
- package/src/components/Button/LoadingIndicator/__tests__/__snapshots__/index.spec.tsx.snap +6 -6
- package/src/components/Button/UtilityButton/__tests__/__snapshots__/index.spec.tsx.snap +6 -6
- package/src/components/Button/__tests__/__snapshots__/IconButton.spec.tsx.snap +1 -1
- package/src/components/Button/__tests__/__snapshots__/StyledButton.spec.tsx.snap +67 -67
- package/src/components/Calendar/__tests__/__snapshots__/CalendarRowItem.spec.tsx.snap +12 -12
- package/src/components/Card/__tests__/__snapshots__/StyledCard.spec.tsx.snap +1 -1
- package/src/components/Checkbox/__tests__/__snapshots__/StyledCheckbox.spec.tsx.snap +1 -1
- package/src/components/Checkbox/__tests__/__snapshots__/index.spec.tsx.snap +2 -2
- package/src/components/ContentNavigator/__tests__/__snapshots__/StyledContentNavigator.spec.tsx.snap +1 -1
- package/src/components/ContentNavigator/__tests__/__snapshots__/index.spec.tsx.snap +6 -6
- package/src/components/DatePicker/__tests__/__snapshots__/DatePickerAndroid.spec.tsx.snap +5 -5
- package/src/components/DatePicker/__tests__/__snapshots__/DatePickerIOS.spec.tsx.snap +12 -12
- package/src/components/Divider/__tests__/__snapshots__/StyledDivider.spec.tsx.snap +12 -12
- package/src/components/Drawer/__tests__/__snapshots__/index.spec.tsx.snap +3 -3
- package/src/components/Empty/__tests__/__snapshots__/index.spec.tsx.snap +3 -3
- package/src/components/FAB/ActionGroup/__tests__/__snapshots__/index.spec.tsx.snap +28 -28
- package/src/components/FAB/__tests__/__snapshots__/AnimatedFABIcon.spec.tsx.snap +2 -2
- package/src/components/FAB/__tests__/__snapshots__/StyledFAB.spec.tsx.snap +3 -3
- package/src/components/FAB/__tests__/__snapshots__/index.spec.tsx.snap +9 -9
- package/src/components/Icon/__tests__/__snapshots__/index.spec.tsx.snap +3 -3
- package/src/components/List/BasicListItem.tsx +8 -4
- package/src/components/List/__tests__/__snapshots__/BasicListItem.spec.tsx.snap +3 -3
- package/src/components/List/__tests__/__snapshots__/ListItem.spec.tsx.snap +20 -20
- package/src/components/List/__tests__/__snapshots__/StyledBasicListItem.spec.tsx.snap +6 -6
- package/src/components/List/__tests__/__snapshots__/StyledListItem.spec.tsx.snap +12 -12
- package/src/components/PinInput/__tests__/__snapshots__/PinCell.spec.tsx.snap +4 -4
- package/src/components/PinInput/__tests__/__snapshots__/index.spec.tsx.snap +22 -22
- package/src/components/Progress/ProgressCircle.tsx +25 -22
- package/src/components/Progress/StyledProgressCircle.tsx +33 -28
- package/src/components/Progress/__tests__/__snapshots__/index.spec.js.snap +102 -92
- package/src/components/Radio/__tests__/__snapshots__/Radio.spec.tsx.snap +5 -5
- package/src/components/Radio/__tests__/__snapshots__/RadioGroup.spec.tsx.snap +6 -6
- package/src/components/Radio/__tests__/__snapshots__/StyledRadio.spec.tsx.snap +3 -3
- package/src/components/RichTextEditor/__tests__/__snapshots__/EditorToolbar.spec.tsx.snap +11 -11
- package/src/components/RichTextEditor/__tests__/__snapshots__/RichTextEditor.spec.tsx.snap +6 -6
- package/src/components/SectionHeading/__tests__/__snapshots__/StyledHeading.spec.tsx.snap +1 -1
- package/src/components/SectionHeading/__tests__/__snapshots__/index.spec.tsx.snap +9 -9
- package/src/components/Select/MultiSelect/Option.tsx +20 -11
- package/src/components/Select/MultiSelect/OptionList.tsx +47 -41
- package/src/components/Select/MultiSelect/__tests__/OptionList.spec.tsx +25 -14
- package/src/components/Select/MultiSelect/__tests__/__snapshots__/Option.spec.tsx.snap +6 -4
- package/src/components/Select/MultiSelect/__tests__/__snapshots__/OptionList.spec.tsx.snap +1638 -134
- package/src/components/Select/MultiSelect/__tests__/__snapshots__/index.spec.tsx.snap +5312 -366
- package/src/components/Select/MultiSelect/__tests__/index.spec.tsx +122 -1
- package/src/components/Select/MultiSelect/index.tsx +26 -36
- package/src/components/Select/SingleSelect/Option.tsx +19 -3
- package/src/components/Select/SingleSelect/OptionList.tsx +47 -39
- package/src/components/Select/SingleSelect/__tests__/OptionList.spec.tsx +23 -12
- package/src/components/Select/SingleSelect/__tests__/__snapshots__/Option.spec.tsx.snap +5 -3
- package/src/components/Select/SingleSelect/__tests__/__snapshots__/OptionList.spec.tsx.snap +1632 -128
- package/src/components/Select/SingleSelect/__tests__/__snapshots__/index.spec.tsx.snap +4932 -302
- package/src/components/Select/SingleSelect/__tests__/index.spec.tsx +117 -1
- package/src/components/Select/SingleSelect/index.tsx +26 -37
- package/src/components/Select/StyledOptionList.tsx +43 -44
- package/src/components/Select/StyledSelect.tsx +7 -3
- package/src/components/Select/__tests__/StyledSelect.spec.tsx +1 -9
- package/src/components/Select/__tests__/__snapshots__/StyledSelect.spec.tsx.snap +2 -15
- package/src/components/Select/__tests__/helpers.spec.tsx +74 -0
- package/src/components/Select/helpers.tsx +87 -4
- package/src/components/Select/types.ts +99 -0
- package/src/components/Spinner/__tests__/__snapshots__/AnimatedSpinner.spec.tsx.snap +4 -4
- package/src/components/Spinner/__tests__/__snapshots__/StyledSpinner.spec.tsx.snap +8 -8
- package/src/components/Spinner/__tests__/__snapshots__/index.spec.tsx.snap +4 -4
- package/src/components/Switch/__tests__/__snapshots__/StyledHeading.spec.tsx.snap +1 -1
- package/src/components/Switch/__tests__/__snapshots__/index.spec.tsx.snap +2 -2
- package/src/components/Tabs/__tests__/__snapshots__/ScrollableTabs.spec.tsx.snap +6 -6
- package/src/components/Tabs/__tests__/__snapshots__/index.spec.tsx.snap +8 -8
- package/src/components/Tag/__tests__/__snapshots__/Tag.spec.tsx.snap +8 -8
- package/src/components/TextInput/__tests__/__snapshots__/StyledTextInput.spec.tsx.snap +50 -50
- package/src/components/TextInput/__tests__/__snapshots__/index.spec.tsx.snap +241 -85
- package/src/components/TextInput/__tests__/index.spec.tsx +29 -8
- package/src/components/TextInput/index.tsx +18 -7
- package/src/components/TimePicker/__tests__/__snapshots__/TimePickerAndroid.spec.tsx.snap +5 -5
- package/src/components/TimePicker/__tests__/__snapshots__/TimePickerIOS.spec.tsx.snap +12 -12
- package/src/components/Toast/__tests__/__snapshots__/Toast.spec.tsx.snap +22 -22
- package/src/components/Toolbar/__tests__/__snapshots__/ToolbarGroup.spec.tsx.snap +12 -12
- package/src/components/Toolbar/__tests__/__snapshots__/ToolbarItem.spec.tsx.snap +8 -8
- package/src/components/Typography/Text/__tests__/__snapshots__/StyledText.spec.tsx.snap +13 -13
- package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +145 -146
- package/src/theme/components/alert.ts +3 -3
- package/src/theme/components/badge.ts +1 -1
- package/src/theme/components/card.ts +4 -4
- package/src/theme/components/list.ts +4 -4
- package/src/theme/components/pinInput.ts +2 -2
- package/src/theme/components/progress.ts +5 -5
- package/src/theme/components/select.ts +3 -3
- package/src/theme/components/toast.ts +3 -3
- package/src/theme/global/colors.ts +40 -39
- package/src/types.ts +7 -1
- package/types/components/List/BasicListItem.d.ts +1 -1
- package/types/components/Progress/StyledProgressCircle.d.ts +12 -6
- package/types/components/Select/MultiSelect/Option.d.ts +4 -2
- package/types/components/Select/MultiSelect/OptionList.d.ts +6 -7
- package/types/components/Select/MultiSelect/index.d.ts +5 -5
- package/types/components/Select/SingleSelect/Option.d.ts +4 -2
- package/types/components/Select/SingleSelect/OptionList.d.ts +6 -7
- package/types/components/Select/SingleSelect/index.d.ts +5 -5
- package/types/components/Select/StyledOptionList.d.ts +10 -16
- package/types/components/Select/StyledSelect.d.ts +8 -2
- package/types/components/Select/__tests__/helpers.spec.d.ts +1 -0
- package/types/components/Select/helpers.d.ts +14 -2
- package/types/components/Select/index.d.ts +1 -1
- package/types/components/Select/types.d.ts +32 -7
- package/types/components/TextInput/index.d.ts +4 -2
- package/types/theme/components/progress.d.ts +1 -2
- package/types/theme/components/select.d.ts +3 -3
- package/types/types.d.ts +2 -1
- package/src/components/Select/types.tsx +0 -52
|
@@ -6,8 +6,8 @@ exports[`EditorToolbar when the editor is focused should render toolbar 1`] = `
|
|
|
6
6
|
Array [
|
|
7
7
|
Object {
|
|
8
8
|
"alignItems": "center",
|
|
9
|
-
"backgroundColor": "#
|
|
10
|
-
"borderTopColor": "#
|
|
9
|
+
"backgroundColor": "#f6f6f7",
|
|
10
|
+
"borderTopColor": "#e8e9ea",
|
|
11
11
|
"borderTopWidth": 0.5,
|
|
12
12
|
"flexDirection": "row",
|
|
13
13
|
"paddingHorizontal": 8,
|
|
@@ -46,7 +46,7 @@ exports[`EditorToolbar when the editor is focused should render toolbar 1`] = `
|
|
|
46
46
|
style={
|
|
47
47
|
Array [
|
|
48
48
|
Object {
|
|
49
|
-
"color": "#
|
|
49
|
+
"color": "#001f23",
|
|
50
50
|
"fontSize": 20,
|
|
51
51
|
},
|
|
52
52
|
undefined,
|
|
@@ -85,7 +85,7 @@ exports[`EditorToolbar when the editor is focused should render toolbar 1`] = `
|
|
|
85
85
|
style={
|
|
86
86
|
Array [
|
|
87
87
|
Object {
|
|
88
|
-
"color": "#
|
|
88
|
+
"color": "#001f23",
|
|
89
89
|
"fontSize": 20,
|
|
90
90
|
},
|
|
91
91
|
undefined,
|
|
@@ -124,7 +124,7 @@ exports[`EditorToolbar when the editor is focused should render toolbar 1`] = `
|
|
|
124
124
|
style={
|
|
125
125
|
Array [
|
|
126
126
|
Object {
|
|
127
|
-
"color": "#
|
|
127
|
+
"color": "#001f23",
|
|
128
128
|
"fontSize": 20,
|
|
129
129
|
},
|
|
130
130
|
undefined,
|
|
@@ -139,7 +139,7 @@ exports[`EditorToolbar when the editor is focused should render toolbar 1`] = `
|
|
|
139
139
|
Array [
|
|
140
140
|
Object {
|
|
141
141
|
"alignItems": "center",
|
|
142
|
-
"backgroundColor": "#
|
|
142
|
+
"backgroundColor": "#e8e9ea",
|
|
143
143
|
"flexDirection": "row",
|
|
144
144
|
"height": 16,
|
|
145
145
|
"marginHorizontal": 8,
|
|
@@ -178,7 +178,7 @@ exports[`EditorToolbar when the editor is focused should render toolbar 1`] = `
|
|
|
178
178
|
style={
|
|
179
179
|
Array [
|
|
180
180
|
Object {
|
|
181
|
-
"color": "#
|
|
181
|
+
"color": "#001f23",
|
|
182
182
|
"fontSize": 20,
|
|
183
183
|
},
|
|
184
184
|
undefined,
|
|
@@ -217,7 +217,7 @@ exports[`EditorToolbar when the editor is focused should render toolbar 1`] = `
|
|
|
217
217
|
style={
|
|
218
218
|
Array [
|
|
219
219
|
Object {
|
|
220
|
-
"color": "#
|
|
220
|
+
"color": "#001f23",
|
|
221
221
|
"fontSize": 20,
|
|
222
222
|
},
|
|
223
223
|
undefined,
|
|
@@ -232,7 +232,7 @@ exports[`EditorToolbar when the editor is focused should render toolbar 1`] = `
|
|
|
232
232
|
Array [
|
|
233
233
|
Object {
|
|
234
234
|
"alignItems": "center",
|
|
235
|
-
"backgroundColor": "#
|
|
235
|
+
"backgroundColor": "#e8e9ea",
|
|
236
236
|
"flexDirection": "row",
|
|
237
237
|
"height": 16,
|
|
238
238
|
"marginHorizontal": 8,
|
|
@@ -271,7 +271,7 @@ exports[`EditorToolbar when the editor is focused should render toolbar 1`] = `
|
|
|
271
271
|
style={
|
|
272
272
|
Array [
|
|
273
273
|
Object {
|
|
274
|
-
"color": "#
|
|
274
|
+
"color": "#001f23",
|
|
275
275
|
"fontSize": 20,
|
|
276
276
|
},
|
|
277
277
|
undefined,
|
|
@@ -310,7 +310,7 @@ exports[`EditorToolbar when the editor is focused should render toolbar 1`] = `
|
|
|
310
310
|
style={
|
|
311
311
|
Array [
|
|
312
312
|
Object {
|
|
313
|
-
"color": "#
|
|
313
|
+
"color": "#001f23",
|
|
314
314
|
"fontSize": 20,
|
|
315
315
|
},
|
|
316
316
|
undefined,
|
|
@@ -79,7 +79,7 @@ exports[`RichTextEditor onMessage recevied event editor-layout should update hei
|
|
|
79
79
|
style={
|
|
80
80
|
Array [
|
|
81
81
|
Object {
|
|
82
|
-
"color": "#
|
|
82
|
+
"color": "#001f23",
|
|
83
83
|
"fontFamily": "BeVietnamPro-Regular",
|
|
84
84
|
"fontSize": 14,
|
|
85
85
|
"letterSpacing": 0.42,
|
|
@@ -89,7 +89,7 @@ exports[`RichTextEditor onMessage recevied event editor-layout should update hei
|
|
|
89
89
|
Object {
|
|
90
90
|
"alignContent": "center",
|
|
91
91
|
"alignItems": "center",
|
|
92
|
-
"color": "#
|
|
92
|
+
"color": "#001f23",
|
|
93
93
|
"fontSize": 14,
|
|
94
94
|
"textAlignVertical": "center",
|
|
95
95
|
},
|
|
@@ -234,7 +234,7 @@ exports[`RichTextEditor onMessage recevied event editor-layout should update hei
|
|
|
234
234
|
style={
|
|
235
235
|
Array [
|
|
236
236
|
Object {
|
|
237
|
-
"color": "#
|
|
237
|
+
"color": "#001f23",
|
|
238
238
|
"fontFamily": "BeVietnamPro-Regular",
|
|
239
239
|
"fontSize": 14,
|
|
240
240
|
"letterSpacing": 0.42,
|
|
@@ -342,7 +342,7 @@ exports[`RichTextEditor should render correctly 1`] = `
|
|
|
342
342
|
style={
|
|
343
343
|
Array [
|
|
344
344
|
Object {
|
|
345
|
-
"color": "#
|
|
345
|
+
"color": "#001f23",
|
|
346
346
|
"fontFamily": "BeVietnamPro-Regular",
|
|
347
347
|
"fontSize": 14,
|
|
348
348
|
"letterSpacing": 0.42,
|
|
@@ -352,7 +352,7 @@ exports[`RichTextEditor should render correctly 1`] = `
|
|
|
352
352
|
Object {
|
|
353
353
|
"alignContent": "center",
|
|
354
354
|
"alignItems": "center",
|
|
355
|
-
"color": "#
|
|
355
|
+
"color": "#001f23",
|
|
356
356
|
"fontSize": 14,
|
|
357
357
|
"textAlignVertical": "center",
|
|
358
358
|
},
|
|
@@ -496,7 +496,7 @@ exports[`RichTextEditor should render correctly 1`] = `
|
|
|
496
496
|
style={
|
|
497
497
|
Array [
|
|
498
498
|
Object {
|
|
499
|
-
"color": "#
|
|
499
|
+
"color": "#001f23",
|
|
500
500
|
"fontFamily": "BeVietnamPro-Regular",
|
|
501
501
|
"fontSize": 14,
|
|
502
502
|
"letterSpacing": 0.42,
|
|
@@ -6,7 +6,7 @@ exports[`SectionHeading allows to customise the icon 1`] = `
|
|
|
6
6
|
Array [
|
|
7
7
|
Object {
|
|
8
8
|
"alignContent": "center",
|
|
9
|
-
"backgroundColor": "#
|
|
9
|
+
"backgroundColor": "#e8e9ea",
|
|
10
10
|
"display": "flex",
|
|
11
11
|
"flexDirection": "row",
|
|
12
12
|
"justifyContent": "space-between",
|
|
@@ -58,7 +58,7 @@ exports[`SectionHeading allows to customise the icon 1`] = `
|
|
|
58
58
|
style={
|
|
59
59
|
Array [
|
|
60
60
|
Object {
|
|
61
|
-
"color": "#
|
|
61
|
+
"color": "#8505a2",
|
|
62
62
|
"fontFamily": "BeVietnamPro-Regular",
|
|
63
63
|
"fontSize": 16,
|
|
64
64
|
"letterSpacing": 0.48,
|
|
@@ -83,7 +83,7 @@ exports[`SectionHeading render icon correctly 1`] = `
|
|
|
83
83
|
Array [
|
|
84
84
|
Object {
|
|
85
85
|
"alignContent": "center",
|
|
86
|
-
"backgroundColor": "#
|
|
86
|
+
"backgroundColor": "#e8e9ea",
|
|
87
87
|
"display": "flex",
|
|
88
88
|
"flexDirection": "row",
|
|
89
89
|
"justifyContent": "space-between",
|
|
@@ -122,7 +122,7 @@ exports[`SectionHeading render icon correctly 1`] = `
|
|
|
122
122
|
style={
|
|
123
123
|
Array [
|
|
124
124
|
Object {
|
|
125
|
-
"color": "#
|
|
125
|
+
"color": "#001f23",
|
|
126
126
|
"fontSize": 24,
|
|
127
127
|
},
|
|
128
128
|
undefined,
|
|
@@ -136,7 +136,7 @@ exports[`SectionHeading render icon correctly 1`] = `
|
|
|
136
136
|
style={
|
|
137
137
|
Array [
|
|
138
138
|
Object {
|
|
139
|
-
"color": "#
|
|
139
|
+
"color": "#001f23",
|
|
140
140
|
"fontFamily": "BeVietnamPro-Regular",
|
|
141
141
|
"fontSize": 16,
|
|
142
142
|
"letterSpacing": 0.48,
|
|
@@ -161,7 +161,7 @@ exports[`SectionHeading render right children correctly 1`] = `
|
|
|
161
161
|
Array [
|
|
162
162
|
Object {
|
|
163
163
|
"alignContent": "center",
|
|
164
|
-
"backgroundColor": "#
|
|
164
|
+
"backgroundColor": "#e8e9ea",
|
|
165
165
|
"display": "flex",
|
|
166
166
|
"flexDirection": "row",
|
|
167
167
|
"justifyContent": "space-between",
|
|
@@ -199,7 +199,7 @@ exports[`SectionHeading render right children correctly 1`] = `
|
|
|
199
199
|
style={
|
|
200
200
|
Array [
|
|
201
201
|
Object {
|
|
202
|
-
"color": "#
|
|
202
|
+
"color": "#001f23",
|
|
203
203
|
"fontFamily": "BeVietnamPro-Regular",
|
|
204
204
|
"fontSize": 16,
|
|
205
205
|
"letterSpacing": 0.48,
|
|
@@ -227,7 +227,7 @@ exports[`SectionHeading renders correctly 1`] = `
|
|
|
227
227
|
Array [
|
|
228
228
|
Object {
|
|
229
229
|
"alignContent": "center",
|
|
230
|
-
"backgroundColor": "#
|
|
230
|
+
"backgroundColor": "#e8e9ea",
|
|
231
231
|
"display": "flex",
|
|
232
232
|
"flexDirection": "row",
|
|
233
233
|
"justifyContent": "space-between",
|
|
@@ -265,7 +265,7 @@ exports[`SectionHeading renders correctly 1`] = `
|
|
|
265
265
|
style={
|
|
266
266
|
Array [
|
|
267
267
|
Object {
|
|
268
|
-
"color": "#
|
|
268
|
+
"color": "#001f23",
|
|
269
269
|
"fontFamily": "BeVietnamPro-Regular",
|
|
270
270
|
"fontSize": 16,
|
|
271
271
|
"letterSpacing": 0.48,
|
|
@@ -1,22 +1,31 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import
|
|
1
|
+
import React, { ReactElement } from 'react';
|
|
2
|
+
import { useTheme } from '../../../theme';
|
|
3
3
|
import List from '../../List';
|
|
4
4
|
|
|
5
5
|
const Option = ({
|
|
6
6
|
text,
|
|
7
|
+
disabled = false,
|
|
7
8
|
selected,
|
|
8
9
|
onPress,
|
|
9
10
|
}: {
|
|
10
|
-
text: string;
|
|
11
|
+
text: string | ReactElement;
|
|
12
|
+
disabled?: boolean;
|
|
11
13
|
selected: boolean;
|
|
12
14
|
onPress: () => void;
|
|
13
|
-
}) =>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
}) => {
|
|
16
|
+
const theme = useTheme();
|
|
17
|
+
return (
|
|
18
|
+
<List.BasicItem
|
|
19
|
+
selected={selected}
|
|
20
|
+
disabled={disabled}
|
|
21
|
+
onPress={onPress}
|
|
22
|
+
title={text}
|
|
23
|
+
suffix={selected ? 'checkmark' : undefined}
|
|
24
|
+
style={{
|
|
25
|
+
marginHorizontal: theme.__hd__.select.space.optionHorizontalMargin,
|
|
26
|
+
}}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
21
30
|
|
|
22
31
|
export default Option;
|
|
@@ -1,63 +1,69 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { SectionListRenderItemInfo } from 'react-native';
|
|
2
3
|
import { MultiSelectProps } from '.';
|
|
3
|
-
|
|
4
|
-
import StyledOptionList
|
|
4
|
+
import { getScrollParams } from '../helpers';
|
|
5
|
+
import StyledOptionList from '../StyledOptionList';
|
|
6
|
+
import { OptionType, SectionData, SectionType } from '../types';
|
|
5
7
|
import Option from './Option';
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
type OptionListProps<V, T extends OptionType<V>> = Pick<
|
|
10
|
+
MultiSelectProps<V, T>,
|
|
11
|
+
| 'keyExtractor'
|
|
12
|
+
| 'loading'
|
|
13
|
+
| 'onEndReached'
|
|
14
|
+
| 'onQueryChange'
|
|
15
|
+
| 'value'
|
|
16
|
+
| 'renderOption'
|
|
17
|
+
> & {
|
|
18
|
+
onPress: (value: V[]) => void;
|
|
19
|
+
sections: SectionData<V, T>[];
|
|
20
|
+
};
|
|
13
21
|
|
|
14
|
-
const OptionList = <T
|
|
22
|
+
const OptionList = <V, T extends OptionType<V>>({
|
|
15
23
|
keyExtractor,
|
|
16
24
|
loading,
|
|
17
25
|
onEndReached,
|
|
18
26
|
onPress,
|
|
19
27
|
onQueryChange,
|
|
20
|
-
|
|
28
|
+
sections,
|
|
29
|
+
renderOption,
|
|
21
30
|
value,
|
|
22
|
-
}:
|
|
23
|
-
OptionListProps<T>,
|
|
24
|
-
| 'keyExtractor'
|
|
25
|
-
| 'loading'
|
|
26
|
-
| 'onEndReached'
|
|
27
|
-
| 'onPress'
|
|
28
|
-
| 'onQueryChange'
|
|
29
|
-
| 'options'
|
|
30
|
-
| 'value'
|
|
31
|
-
>) => {
|
|
31
|
+
}: OptionListProps<V, T>) => {
|
|
32
32
|
const firstValue = value?.[0];
|
|
33
|
-
const
|
|
34
|
-
? options.findIndex(option => option.value === firstValue)
|
|
35
|
-
: 0;
|
|
36
|
-
const scrollIndex = rawScrollIndex - 2 >= 0 ? rawScrollIndex - 2 : 0;
|
|
33
|
+
const scrollParams = getScrollParams(firstValue, sections);
|
|
37
34
|
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
const renderItem = (info: SectionListRenderItemInfo<T, SectionType>) => {
|
|
36
|
+
const { item } = info;
|
|
37
|
+
const selected = value.includes(info.item.value);
|
|
38
|
+
const onItemPress = () => {
|
|
39
|
+
if (value.includes(info.item.value)) {
|
|
40
|
+
onPress(value.filter(val => val !== info.item.value));
|
|
41
|
+
} else {
|
|
42
|
+
onPress([...value, info.item.value]);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return renderOption ? (
|
|
47
|
+
renderOption({ ...info, selected, onPress: onItemPress })
|
|
48
|
+
) : (
|
|
49
|
+
<Option
|
|
50
|
+
selected={selected}
|
|
51
|
+
text={item.text}
|
|
52
|
+
disabled={item.disabled}
|
|
53
|
+
onPress={onItemPress}
|
|
54
|
+
/>
|
|
55
|
+
);
|
|
56
|
+
};
|
|
51
57
|
|
|
52
58
|
return (
|
|
53
|
-
<StyledOptionList
|
|
59
|
+
<StyledOptionList
|
|
54
60
|
keyExtractor={keyExtractor}
|
|
55
61
|
loading={loading}
|
|
56
62
|
onEndReached={onEndReached}
|
|
57
63
|
onQueryChange={onQueryChange}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
64
|
+
sections={sections}
|
|
65
|
+
renderItem={renderItem}
|
|
66
|
+
scrollParams={scrollParams}
|
|
61
67
|
/>
|
|
62
68
|
);
|
|
63
69
|
};
|
|
@@ -3,49 +3,60 @@ import { fireEvent } from '@testing-library/react-native';
|
|
|
3
3
|
import OptionList from '../OptionList';
|
|
4
4
|
import renderWithTheme from '../../../../testHelpers/renderWithTheme';
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
{
|
|
8
|
-
{
|
|
9
|
-
|
|
6
|
+
const sections = [
|
|
7
|
+
{ category: 'A', data: [{ text: 'A1', value: 'a1' }] },
|
|
8
|
+
{
|
|
9
|
+
category: 'B',
|
|
10
|
+
data: [
|
|
11
|
+
{ text: 'B1', value: 'b1' },
|
|
12
|
+
{ text: 'B2', value: 'b2' },
|
|
13
|
+
],
|
|
14
|
+
},
|
|
10
15
|
];
|
|
11
16
|
|
|
12
17
|
describe('OptionList', () => {
|
|
13
18
|
it('renders correctly', () => {
|
|
14
19
|
const pressFn = jest.fn();
|
|
15
|
-
const { toJSON } = renderWithTheme(
|
|
16
|
-
<OptionList value={['
|
|
20
|
+
const { toJSON, getByText } = renderWithTheme(
|
|
21
|
+
<OptionList value={['a1']} sections={sections} onPress={pressFn} />
|
|
17
22
|
);
|
|
23
|
+
|
|
24
|
+
expect(getByText('A')).toBeTruthy();
|
|
25
|
+
expect(getByText('A1')).toBeTruthy();
|
|
26
|
+
expect(getByText('B')).toBeTruthy();
|
|
27
|
+
expect(getByText('B1')).toBeTruthy();
|
|
28
|
+
expect(getByText('B2')).toBeTruthy();
|
|
18
29
|
expect(toJSON()).toMatchSnapshot();
|
|
19
30
|
});
|
|
20
31
|
|
|
21
32
|
it('trigger onPress correctly on select additional value', () => {
|
|
22
33
|
const pressFn = jest.fn();
|
|
23
34
|
const { toJSON, getByText } = renderWithTheme(
|
|
24
|
-
<OptionList value={['
|
|
35
|
+
<OptionList value={['a1']} sections={sections} onPress={pressFn} />
|
|
25
36
|
);
|
|
26
37
|
expect(toJSON()).toMatchSnapshot();
|
|
27
|
-
fireEvent.press(getByText('
|
|
38
|
+
fireEvent.press(getByText('B1'));
|
|
28
39
|
expect(pressFn).toBeCalledTimes(1);
|
|
29
|
-
expect(pressFn).toHaveBeenCalledWith(['
|
|
40
|
+
expect(pressFn).toHaveBeenCalledWith(['a1', 'b1']);
|
|
30
41
|
});
|
|
31
42
|
|
|
32
43
|
it('trigger onPress correctly on changing selection', () => {
|
|
33
44
|
const pressFn = jest.fn();
|
|
34
45
|
const { toJSON, getByText } = renderWithTheme(
|
|
35
|
-
<OptionList value={['
|
|
46
|
+
<OptionList value={['a1', 'b1']} sections={sections} onPress={pressFn} />
|
|
36
47
|
);
|
|
37
48
|
expect(toJSON()).toMatchSnapshot();
|
|
38
|
-
fireEvent.press(getByText('
|
|
49
|
+
fireEvent.press(getByText('A1'));
|
|
39
50
|
expect(pressFn).toBeCalledTimes(1);
|
|
40
|
-
expect(pressFn).toHaveBeenCalledWith(['
|
|
51
|
+
expect(pressFn).toHaveBeenCalledWith(['b1']);
|
|
41
52
|
});
|
|
42
53
|
|
|
43
54
|
it('render isLoading correctly', () => {
|
|
44
55
|
const pressFn = jest.fn();
|
|
45
56
|
const { toJSON } = renderWithTheme(
|
|
46
57
|
<OptionList
|
|
47
|
-
value={['
|
|
48
|
-
|
|
58
|
+
value={['a1']}
|
|
59
|
+
sections={sections}
|
|
49
60
|
onPress={pressFn}
|
|
50
61
|
loading
|
|
51
62
|
/>
|
|
@@ -20,12 +20,14 @@ exports[`Option renders correctly 1`] = `
|
|
|
20
20
|
Array [
|
|
21
21
|
Object {
|
|
22
22
|
"alignItems": "center",
|
|
23
|
-
"backgroundColor": "#
|
|
23
|
+
"backgroundColor": "#f3e6f6",
|
|
24
24
|
"flexDirection": "row",
|
|
25
25
|
"opacity": 1,
|
|
26
26
|
"padding": 16,
|
|
27
27
|
},
|
|
28
|
-
|
|
28
|
+
Object {
|
|
29
|
+
"marginHorizontal": 12,
|
|
30
|
+
},
|
|
29
31
|
]
|
|
30
32
|
}
|
|
31
33
|
>
|
|
@@ -43,7 +45,7 @@ exports[`Option renders correctly 1`] = `
|
|
|
43
45
|
style={
|
|
44
46
|
Array [
|
|
45
47
|
Object {
|
|
46
|
-
"color": "#
|
|
48
|
+
"color": "#001f23",
|
|
47
49
|
"fontFamily": "BeVietnamPro-Regular",
|
|
48
50
|
"fontSize": 16,
|
|
49
51
|
"letterSpacing": 0.48,
|
|
@@ -74,7 +76,7 @@ exports[`Option renders correctly 1`] = `
|
|
|
74
76
|
style={
|
|
75
77
|
Array [
|
|
76
78
|
Object {
|
|
77
|
-
"color": "#
|
|
79
|
+
"color": "#001f23",
|
|
78
80
|
"fontSize": 20,
|
|
79
81
|
},
|
|
80
82
|
undefined,
|