@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
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { SectionListRenderItemInfo } from 'react-native';
|
|
3
|
-
import { getScrollParams } from '../helpers';
|
|
2
|
+
import type { SectionListRenderItemInfo, SectionList } from 'react-native';
|
|
4
3
|
import StyledOptionList from '../StyledOptionList';
|
|
5
4
|
import Option from './Option';
|
|
6
5
|
import type { MultiSelectProps } from '.';
|
|
@@ -17,6 +16,7 @@ type OptionListProps<V, T extends OptionType<V>> = Pick<
|
|
|
17
16
|
> & {
|
|
18
17
|
onPress: (value: V[]) => void;
|
|
19
18
|
sections: SectionData<V, T>[];
|
|
19
|
+
sectionListRef?: React.RefObject<SectionList<T, SectionType>>;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
const OptionList = <V, T extends OptionType<V>>({
|
|
@@ -28,16 +28,14 @@ const OptionList = <V, T extends OptionType<V>>({
|
|
|
28
28
|
sections,
|
|
29
29
|
renderOption,
|
|
30
30
|
value,
|
|
31
|
+
sectionListRef,
|
|
31
32
|
}: OptionListProps<V, T>) => {
|
|
32
|
-
const firstValue = value?.[0];
|
|
33
|
-
const scrollParams = getScrollParams(firstValue, sections);
|
|
34
|
-
|
|
35
33
|
const renderItem = (info: SectionListRenderItemInfo<T, SectionType>) => {
|
|
36
34
|
const { item } = info;
|
|
37
35
|
const selected = value.includes(info.item.value);
|
|
38
36
|
const onItemPress = () => {
|
|
39
37
|
if (value.includes(info.item.value)) {
|
|
40
|
-
onPress(value.filter(val => val !== info.item.value));
|
|
38
|
+
onPress(value.filter((val) => val !== info.item.value));
|
|
41
39
|
} else {
|
|
42
40
|
onPress([...value, info.item.value]);
|
|
43
41
|
}
|
|
@@ -63,7 +61,7 @@ const OptionList = <V, T extends OptionType<V>>({
|
|
|
63
61
|
onQueryChange={onQueryChange}
|
|
64
62
|
sections={sections}
|
|
65
63
|
renderItem={renderItem}
|
|
66
|
-
|
|
64
|
+
sectionListRef={sectionListRef}
|
|
67
65
|
/>
|
|
68
66
|
);
|
|
69
67
|
};
|
|
@@ -174,6 +174,27 @@ describe('rendering', () => {
|
|
|
174
174
|
expect(getByText('Josh')).toBeTruthy();
|
|
175
175
|
expect(getByText('Junior Developer')).toBeTruthy();
|
|
176
176
|
});
|
|
177
|
+
|
|
178
|
+
it('allows custom selected value', () => {
|
|
179
|
+
const { getByText } = renderWithTheme(
|
|
180
|
+
<MultiSelect<string, CustomOptionType>
|
|
181
|
+
label="Choose collaborators"
|
|
182
|
+
footerLabel="Confirm"
|
|
183
|
+
options={collaboratorSections}
|
|
184
|
+
value={['daniel', 'daemon']}
|
|
185
|
+
onConfirm={jest.fn()}
|
|
186
|
+
renderSelectedValue={(selectedValue, _inputProps) => (
|
|
187
|
+
<>
|
|
188
|
+
{selectedValue.map((value) => (
|
|
189
|
+
<Typography.Text>Custom {value}</Typography.Text>
|
|
190
|
+
))}
|
|
191
|
+
</>
|
|
192
|
+
)}
|
|
193
|
+
/>
|
|
194
|
+
);
|
|
195
|
+
expect(getByText('Custom daniel')).toBeTruthy();
|
|
196
|
+
expect(getByText('Custom daemon')).toBeTruthy();
|
|
197
|
+
});
|
|
177
198
|
});
|
|
178
199
|
|
|
179
200
|
describe('behavior', () => {
|
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
1
|
+
import React, { useState, useRef } from 'react';
|
|
2
2
|
import { TouchableOpacity, View } from 'react-native';
|
|
3
|
+
import type {
|
|
4
|
+
SectionList,
|
|
5
|
+
TextInputProps as NativeTextInputProps,
|
|
6
|
+
} from 'react-native';
|
|
3
7
|
import BottomSheet from '../../BottomSheet';
|
|
4
8
|
import Footer from '../Footer';
|
|
5
9
|
import OptionList from './OptionList';
|
|
6
10
|
import TextInput from '../../TextInput';
|
|
7
11
|
import { StyledSearchBar } from '../StyledSelect';
|
|
8
|
-
import {
|
|
9
|
-
|
|
12
|
+
import {
|
|
13
|
+
getScrollParams,
|
|
14
|
+
toFlatOptions,
|
|
15
|
+
toSections,
|
|
16
|
+
useKeyboard,
|
|
17
|
+
} from '../helpers';
|
|
18
|
+
import type { OptionType, SectionType, SelectProps } from '../types';
|
|
10
19
|
|
|
11
20
|
export interface MultiSelectProps<V, T extends OptionType<V> = OptionType<V>>
|
|
12
21
|
extends SelectProps<V, T> {
|
|
@@ -22,6 +31,13 @@ export interface MultiSelectProps<V, T extends OptionType<V> = OptionType<V>>
|
|
|
22
31
|
* Footer label.
|
|
23
32
|
*/
|
|
24
33
|
footerLabel: string;
|
|
34
|
+
/**
|
|
35
|
+
* Customise the selected value rendering.
|
|
36
|
+
*/
|
|
37
|
+
renderSelectedValue?: (
|
|
38
|
+
selectedValue: V[],
|
|
39
|
+
inputProps: NativeTextInputProps
|
|
40
|
+
) => React.ReactNode;
|
|
25
41
|
}
|
|
26
42
|
|
|
27
43
|
function MultiSelect<V, T extends OptionType<V>>({
|
|
@@ -35,6 +51,7 @@ function MultiSelect<V, T extends OptionType<V>>({
|
|
|
35
51
|
onQueryChange,
|
|
36
52
|
options,
|
|
37
53
|
renderOption,
|
|
54
|
+
renderSelectedValue,
|
|
38
55
|
query,
|
|
39
56
|
error,
|
|
40
57
|
editable = true,
|
|
@@ -47,11 +64,12 @@ function MultiSelect<V, T extends OptionType<V>>({
|
|
|
47
64
|
const { isKeyboardVisible, keyboardHeight } = useKeyboard();
|
|
48
65
|
const [open, setOpen] = useState(false);
|
|
49
66
|
const [selectingValue, setSelectingValue] = useState(value);
|
|
67
|
+
const sectionListRef = useRef<SectionList<T, SectionType>>(null);
|
|
50
68
|
const sections = toSections(options);
|
|
51
69
|
const flatOptions = toFlatOptions(options);
|
|
52
70
|
const displayedValue = flatOptions
|
|
53
|
-
.filter(opt => value.includes(opt.value))
|
|
54
|
-
.map(opt => opt.text)
|
|
71
|
+
.filter((opt) => value.includes(opt.value))
|
|
72
|
+
.map((opt) => opt.text)
|
|
55
73
|
.join(', ');
|
|
56
74
|
|
|
57
75
|
return (
|
|
@@ -79,6 +97,11 @@ function MultiSelect<V, T extends OptionType<V>>({
|
|
|
79
97
|
pointerEvents="none"
|
|
80
98
|
style={style}
|
|
81
99
|
testID={testID}
|
|
100
|
+
renderInputValue={
|
|
101
|
+
renderSelectedValue !== undefined
|
|
102
|
+
? (props) => renderSelectedValue(value, props)
|
|
103
|
+
: undefined
|
|
104
|
+
}
|
|
82
105
|
/>
|
|
83
106
|
</View>
|
|
84
107
|
</TouchableOpacity>
|
|
@@ -100,6 +123,12 @@ function MultiSelect<V, T extends OptionType<V>>({
|
|
|
100
123
|
}}
|
|
101
124
|
/>
|
|
102
125
|
}
|
|
126
|
+
onAnimationEnd={() => {
|
|
127
|
+
if (open === true) {
|
|
128
|
+
const scrollParams = getScrollParams(value?.[0], sections);
|
|
129
|
+
sectionListRef.current?.scrollToLocation(scrollParams);
|
|
130
|
+
}
|
|
131
|
+
}}
|
|
103
132
|
>
|
|
104
133
|
{onQueryChange && (
|
|
105
134
|
<StyledSearchBar>
|
|
@@ -120,6 +149,7 @@ function MultiSelect<V, T extends OptionType<V>>({
|
|
|
120
149
|
renderOption={renderOption}
|
|
121
150
|
value={selectingValue}
|
|
122
151
|
onPress={setSelectingValue}
|
|
152
|
+
sectionListRef={sectionListRef}
|
|
123
153
|
/>
|
|
124
154
|
</BottomSheet>
|
|
125
155
|
</>
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { SectionListRenderItemInfo } from 'react-native';
|
|
3
|
-
import { getScrollParams } from '../helpers';
|
|
2
|
+
import type { SectionListRenderItemInfo, SectionList } from 'react-native';
|
|
4
3
|
import StyledOptionList from '../StyledOptionList';
|
|
5
4
|
import Option from './Option';
|
|
6
5
|
import type { SingleSelectProps } from '.';
|
|
@@ -17,6 +16,7 @@ type OptionListProps<V, T extends OptionType<V>> = Pick<
|
|
|
17
16
|
> & {
|
|
18
17
|
onPress: (value: V | null) => void;
|
|
19
18
|
sections: SectionData<V, T>[];
|
|
19
|
+
sectionListRef?: React.RefObject<SectionList<T, SectionType>>;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
const OptionList = <V, T extends OptionType<V>>({
|
|
@@ -28,9 +28,8 @@ const OptionList = <V, T extends OptionType<V>>({
|
|
|
28
28
|
sections,
|
|
29
29
|
renderOption,
|
|
30
30
|
value,
|
|
31
|
+
sectionListRef,
|
|
31
32
|
}: OptionListProps<V, T>) => {
|
|
32
|
-
const scrollParams = getScrollParams(value, sections);
|
|
33
|
-
|
|
34
33
|
const renderItem = (info: SectionListRenderItemInfo<T, SectionType>) => {
|
|
35
34
|
const { item } = info;
|
|
36
35
|
const selected = item.value === value;
|
|
@@ -62,7 +61,7 @@ const OptionList = <V, T extends OptionType<V>>({
|
|
|
62
61
|
onQueryChange={onQueryChange}
|
|
63
62
|
sections={sections}
|
|
64
63
|
renderItem={renderItem}
|
|
65
|
-
|
|
64
|
+
sectionListRef={sectionListRef}
|
|
66
65
|
/>
|
|
67
66
|
);
|
|
68
67
|
};
|
|
@@ -166,6 +166,22 @@ describe('rendering', () => {
|
|
|
166
166
|
expect(getByText('Josh')).toBeTruthy();
|
|
167
167
|
expect(getByText('Junior Developer')).toBeTruthy();
|
|
168
168
|
});
|
|
169
|
+
|
|
170
|
+
it('allows custom selected value', () => {
|
|
171
|
+
const { getByText } = renderWithTheme(
|
|
172
|
+
<SingleSelect<string, CustomOptionType>
|
|
173
|
+
label="Choose collaborators"
|
|
174
|
+
options={collaboratorSections}
|
|
175
|
+
renderOption={renderSingleOption}
|
|
176
|
+
value="daniel"
|
|
177
|
+
onConfirm={jest.fn()}
|
|
178
|
+
renderSelectedValue={(selectedValue, _inputProps) => (
|
|
179
|
+
<Typography.Text>Custom {selectedValue}</Typography.Text>
|
|
180
|
+
)}
|
|
181
|
+
/>
|
|
182
|
+
);
|
|
183
|
+
expect(getByText('Custom daniel')).toBeTruthy();
|
|
184
|
+
});
|
|
169
185
|
});
|
|
170
186
|
|
|
171
187
|
describe('behavior', () => {
|
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
1
|
+
import React, { useState, useRef } from 'react';
|
|
2
2
|
import { TouchableOpacity, View } from 'react-native';
|
|
3
|
+
import type {
|
|
4
|
+
SectionList,
|
|
5
|
+
TextInputProps as NativeTextInputProps,
|
|
6
|
+
} from 'react-native';
|
|
3
7
|
import BottomSheet from '../../BottomSheet';
|
|
4
8
|
import OptionList from './OptionList';
|
|
5
9
|
import TextInput from '../../TextInput';
|
|
6
10
|
import { StyledSearchBar } from '../StyledSelect';
|
|
7
|
-
import {
|
|
8
|
-
|
|
11
|
+
import {
|
|
12
|
+
getScrollParams,
|
|
13
|
+
toFlatOptions,
|
|
14
|
+
toSections,
|
|
15
|
+
useKeyboard,
|
|
16
|
+
} from '../helpers';
|
|
17
|
+
import type { OptionType, SectionType, SelectProps } from '../types';
|
|
9
18
|
|
|
10
19
|
export interface SingleSelectProps<V, T extends OptionType<V> = OptionType<V>>
|
|
11
20
|
extends SelectProps<V, T> {
|
|
@@ -14,9 +23,16 @@ export interface SingleSelectProps<V, T extends OptionType<V> = OptionType<V>>
|
|
|
14
23
|
*/
|
|
15
24
|
value: V | null;
|
|
16
25
|
/**
|
|
17
|
-
*
|
|
26
|
+
* On select event handler
|
|
18
27
|
*/
|
|
19
28
|
onConfirm: (value: V | null) => void;
|
|
29
|
+
/**
|
|
30
|
+
* Customise the selected value rendering.
|
|
31
|
+
*/
|
|
32
|
+
renderSelectedValue?: (
|
|
33
|
+
selectedValue: V | null,
|
|
34
|
+
inputProps: NativeTextInputProps
|
|
35
|
+
) => React.ReactNode;
|
|
20
36
|
}
|
|
21
37
|
|
|
22
38
|
const SingleSelect = <V, T extends OptionType<V>>({
|
|
@@ -29,6 +45,7 @@ const SingleSelect = <V, T extends OptionType<V>>({
|
|
|
29
45
|
onQueryChange,
|
|
30
46
|
options,
|
|
31
47
|
renderOption,
|
|
48
|
+
renderSelectedValue,
|
|
32
49
|
query,
|
|
33
50
|
error,
|
|
34
51
|
editable = true,
|
|
@@ -40,9 +57,10 @@ const SingleSelect = <V, T extends OptionType<V>>({
|
|
|
40
57
|
}: SingleSelectProps<V, T>) => {
|
|
41
58
|
const { isKeyboardVisible, keyboardHeight } = useKeyboard();
|
|
42
59
|
const [open, setOpen] = useState(false);
|
|
60
|
+
const sectionListRef = useRef<SectionList<T, SectionType>>(null);
|
|
43
61
|
const sections = toSections(options);
|
|
44
62
|
const flatOptions = toFlatOptions(options);
|
|
45
|
-
const displayedValue = flatOptions.find(opt => value === opt.value)?.text;
|
|
63
|
+
const displayedValue = flatOptions.find((opt) => value === opt.value)?.text;
|
|
46
64
|
|
|
47
65
|
return (
|
|
48
66
|
<>
|
|
@@ -69,6 +87,11 @@ const SingleSelect = <V, T extends OptionType<V>>({
|
|
|
69
87
|
pointerEvents="none"
|
|
70
88
|
style={style}
|
|
71
89
|
testID={testID}
|
|
90
|
+
renderInputValue={
|
|
91
|
+
renderSelectedValue !== undefined
|
|
92
|
+
? (props) => renderSelectedValue(value, props)
|
|
93
|
+
: undefined
|
|
94
|
+
}
|
|
72
95
|
/>
|
|
73
96
|
</View>
|
|
74
97
|
</TouchableOpacity>
|
|
@@ -81,6 +104,12 @@ const SingleSelect = <V, T extends OptionType<V>>({
|
|
|
81
104
|
style={{
|
|
82
105
|
paddingBottom: isKeyboardVisible ? keyboardHeight : 0,
|
|
83
106
|
}}
|
|
107
|
+
onAnimationEnd={() => {
|
|
108
|
+
if (open === true) {
|
|
109
|
+
const scrollParams = getScrollParams(value, sections);
|
|
110
|
+
sectionListRef.current?.scrollToLocation(scrollParams);
|
|
111
|
+
}
|
|
112
|
+
}}
|
|
84
113
|
>
|
|
85
114
|
{onQueryChange && (
|
|
86
115
|
<StyledSearchBar>
|
|
@@ -100,10 +129,11 @@ const SingleSelect = <V, T extends OptionType<V>>({
|
|
|
100
129
|
sections={sections}
|
|
101
130
|
renderOption={renderOption}
|
|
102
131
|
value={value}
|
|
103
|
-
onPress={selectedValue => {
|
|
132
|
+
onPress={(selectedValue) => {
|
|
104
133
|
setOpen(false);
|
|
105
134
|
onConfirm(selectedValue);
|
|
106
135
|
}}
|
|
136
|
+
sectionListRef={sectionListRef}
|
|
107
137
|
/>
|
|
108
138
|
</BottomSheet>
|
|
109
139
|
</>
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { useTheme } from '@emotion/react';
|
|
2
|
-
import React, {
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
3
|
import { Dimensions, SectionList, View } from 'react-native';
|
|
4
4
|
import type { ReactElement } from 'react';
|
|
5
5
|
import type { SectionListRenderItemInfo } from 'react-native';
|
|
6
6
|
import SectionHeading from '../SectionHeading';
|
|
7
7
|
import Spinner from '../Spinner';
|
|
8
8
|
import { OptionSpacer, SectionSpacer } from './StyledSelect';
|
|
9
|
-
import type { ScrollParams } from './helpers';
|
|
10
9
|
import type {
|
|
11
10
|
SectionData,
|
|
12
11
|
OptionType,
|
|
@@ -18,9 +17,9 @@ export type StyledOptionListProps<V, T extends OptionType<V>> = Pick<
|
|
|
18
17
|
SelectProps<V, T>,
|
|
19
18
|
'keyExtractor' | 'loading' | 'onEndReached' | 'onQueryChange'
|
|
20
19
|
> & {
|
|
21
|
-
scrollParams: ScrollParams;
|
|
22
20
|
sections: SectionData<V, T>[];
|
|
23
21
|
renderItem: (info: SectionListRenderItemInfo<T, SectionType>) => ReactElement;
|
|
22
|
+
sectionListRef?: React.RefObject<SectionList<T, SectionType>>;
|
|
24
23
|
};
|
|
25
24
|
|
|
26
25
|
const StyledOptionList = <V, T extends OptionType<V>>({
|
|
@@ -30,10 +29,9 @@ const StyledOptionList = <V, T extends OptionType<V>>({
|
|
|
30
29
|
onQueryChange,
|
|
31
30
|
sections,
|
|
32
31
|
renderItem,
|
|
33
|
-
|
|
32
|
+
sectionListRef,
|
|
34
33
|
}: StyledOptionListProps<V, T>) => {
|
|
35
34
|
const theme = useTheme();
|
|
36
|
-
const sectionListRef = useRef<SectionList<T, SectionType>>(null);
|
|
37
35
|
|
|
38
36
|
const [onEndReachedCalled, setOnEndReachedCalled] = useState(false);
|
|
39
37
|
|
|
@@ -48,10 +46,6 @@ const StyledOptionList = <V, T extends OptionType<V>>({
|
|
|
48
46
|
onEndReachedThreshold={0.1}
|
|
49
47
|
onEndReached={() => setOnEndReachedCalled(true)}
|
|
50
48
|
onScrollToIndexFailed={() => {}}
|
|
51
|
-
onContentSizeChange={() =>
|
|
52
|
-
sections.length &&
|
|
53
|
-
sectionListRef.current?.scrollToLocation(scrollParams)
|
|
54
|
-
}
|
|
55
49
|
onMomentumScrollBegin={() => {
|
|
56
50
|
if (onEndReached && onEndReachedCalled && !loading) onEndReached();
|
|
57
51
|
setOnEndReachedCalled(false);
|
|
@@ -44,7 +44,7 @@ export const toFlatOptions = <V, T extends OptionType<V>>(
|
|
|
44
44
|
options: CombinedOptionsType<V, T>
|
|
45
45
|
): OptionType<V>[] => {
|
|
46
46
|
if (isSections(options)) {
|
|
47
|
-
return options.flatMap(opt => opt.data);
|
|
47
|
+
return options.flatMap((opt) => opt.data);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
return options;
|
|
@@ -61,8 +61,8 @@ export const getScrollParams = <V, T extends OptionType<V>>(
|
|
|
61
61
|
): ScrollParams => {
|
|
62
62
|
let itemIndex = -1;
|
|
63
63
|
|
|
64
|
-
const sectionIndex = sections.findIndex(section => {
|
|
65
|
-
itemIndex = section.data.findIndex(opt => opt.value === value);
|
|
64
|
+
const sectionIndex = sections.findIndex((section) => {
|
|
65
|
+
itemIndex = section.data.findIndex((opt) => opt.value === value);
|
|
66
66
|
return itemIndex !== -1;
|
|
67
67
|
});
|
|
68
68
|
|
|
@@ -79,7 +79,7 @@ export const useKeyboard = () => {
|
|
|
79
79
|
useEffect(() => {
|
|
80
80
|
const keyboardWillShowListener = Keyboard.addListener(
|
|
81
81
|
'keyboardWillShow',
|
|
82
|
-
e => {
|
|
82
|
+
(e) => {
|
|
83
83
|
setKeyboardVisible(true);
|
|
84
84
|
setKeyboardHeight(e.endCoordinates.height);
|
|
85
85
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Slider renders correctly by default 1`] = `
|
|
4
|
+
<Slider
|
|
5
|
+
disabled={false}
|
|
6
|
+
maximumTrackTintColor="#ece8ef"
|
|
7
|
+
maximumValue={1}
|
|
8
|
+
minimumTrackTintColor="#401960"
|
|
9
|
+
minimumValue={0}
|
|
10
|
+
step={0}
|
|
11
|
+
thumbTintColor="#e6e9e9"
|
|
12
|
+
value={0}
|
|
13
|
+
/>
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
exports[`Slider renders correctly when disabled 1`] = `
|
|
17
|
+
<Slider
|
|
18
|
+
disabled={true}
|
|
19
|
+
maximumTrackTintColor="#ece8ef"
|
|
20
|
+
maximumValue={1}
|
|
21
|
+
minimumTrackTintColor="#401960"
|
|
22
|
+
minimumValue={0}
|
|
23
|
+
step={0}
|
|
24
|
+
thumbTintColor="#e6e9e9"
|
|
25
|
+
value={0}
|
|
26
|
+
/>
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
exports[`Slider renders correctly with props 1`] = `
|
|
30
|
+
<Slider
|
|
31
|
+
disabled={false}
|
|
32
|
+
maximumTrackTintColor="#ece8ef"
|
|
33
|
+
maximumValue={2}
|
|
34
|
+
minimumTrackTintColor="#401960"
|
|
35
|
+
minimumValue={-1}
|
|
36
|
+
onSlidingComplete={[MockFunction]}
|
|
37
|
+
onSlidingStart={[MockFunction]}
|
|
38
|
+
onValueChange={[MockFunction]}
|
|
39
|
+
step={0.25}
|
|
40
|
+
thumbTintColor="#e6e9e9"
|
|
41
|
+
value={0.5}
|
|
42
|
+
/>
|
|
43
|
+
`;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import renderWithTheme from '../../../testHelpers/renderWithTheme';
|
|
3
|
+
import Slider from '..';
|
|
4
|
+
|
|
5
|
+
describe('Slider', () => {
|
|
6
|
+
it('renders correctly by default', () => {
|
|
7
|
+
const { toJSON } = renderWithTheme(<Slider />);
|
|
8
|
+
|
|
9
|
+
expect(toJSON()).toMatchSnapshot();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('renders correctly when disabled', () => {
|
|
13
|
+
const { toJSON } = renderWithTheme(<Slider disabled />);
|
|
14
|
+
|
|
15
|
+
expect(toJSON()).toMatchSnapshot();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('renders correctly with props', () => {
|
|
19
|
+
const { toJSON } = renderWithTheme(
|
|
20
|
+
<Slider
|
|
21
|
+
value={0.5}
|
|
22
|
+
minimumValue={-1}
|
|
23
|
+
maximumValue={2}
|
|
24
|
+
step={0.25}
|
|
25
|
+
onValueChange={jest.fn()}
|
|
26
|
+
onSlidingStart={jest.fn()}
|
|
27
|
+
onSlidingComplete={jest.fn()}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
expect(toJSON()).toMatchSnapshot();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import RnSlider from '@react-native-community/slider';
|
|
3
|
+
import { StyleProp, ViewStyle } from 'react-native';
|
|
4
|
+
import { useTheme } from '../../theme';
|
|
5
|
+
|
|
6
|
+
export interface SliderProps {
|
|
7
|
+
/**
|
|
8
|
+
* Minimum value of the slider.
|
|
9
|
+
* Defaults to 0.
|
|
10
|
+
*/
|
|
11
|
+
minimumValue?: number;
|
|
12
|
+
/**
|
|
13
|
+
* Maximum value of the slider.
|
|
14
|
+
* Defaults to 1.
|
|
15
|
+
*/
|
|
16
|
+
maximumValue?: number;
|
|
17
|
+
/**
|
|
18
|
+
* Step value of the slider.
|
|
19
|
+
* The value should be between 0 and (maximumValue - minimumValue).
|
|
20
|
+
* Defaults to 0.
|
|
21
|
+
*/
|
|
22
|
+
step?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Value of the slider.
|
|
25
|
+
* Defaults to 0.
|
|
26
|
+
*/
|
|
27
|
+
value?: number;
|
|
28
|
+
/**
|
|
29
|
+
* Callback continuously called while the user is dragging the slider.
|
|
30
|
+
*/
|
|
31
|
+
onValueChange?: (value: number) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Callback that is called when the user picks up the slider.
|
|
34
|
+
* The initial value is passed as an argument to the callback handler.
|
|
35
|
+
*/
|
|
36
|
+
onSlidingStart?: (value: number) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Callback that is called when the user releases the slider, regardless if the value has changed.
|
|
39
|
+
* The current value is passed as an argument to the callback handler.
|
|
40
|
+
*/
|
|
41
|
+
onSlidingComplete?: (value: number) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Whether the slider is disabled.
|
|
44
|
+
*/
|
|
45
|
+
disabled?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Additional style.
|
|
48
|
+
*/
|
|
49
|
+
style?: StyleProp<ViewStyle>;
|
|
50
|
+
/**
|
|
51
|
+
* Testing id of the component.
|
|
52
|
+
*/
|
|
53
|
+
testID?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const Slider = ({
|
|
57
|
+
minimumValue = 0,
|
|
58
|
+
maximumValue = 1,
|
|
59
|
+
step = 0,
|
|
60
|
+
value = 0,
|
|
61
|
+
onValueChange,
|
|
62
|
+
onSlidingStart,
|
|
63
|
+
onSlidingComplete,
|
|
64
|
+
disabled = false,
|
|
65
|
+
style,
|
|
66
|
+
testID,
|
|
67
|
+
}: SliderProps) => {
|
|
68
|
+
const theme = useTheme();
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<RnSlider
|
|
72
|
+
minimumValue={minimumValue}
|
|
73
|
+
maximumValue={maximumValue}
|
|
74
|
+
step={step}
|
|
75
|
+
value={value}
|
|
76
|
+
onValueChange={onValueChange}
|
|
77
|
+
onSlidingStart={onSlidingStart}
|
|
78
|
+
onSlidingComplete={onSlidingComplete}
|
|
79
|
+
disabled={disabled}
|
|
80
|
+
minimumTrackTintColor={theme.__hd__.slider.colors.minimumTrackTint}
|
|
81
|
+
thumbTintColor={theme.__hd__.slider.colors.thumbTint}
|
|
82
|
+
maximumTrackTintColor={theme.__hd__.slider.colors.maximumTrackTint}
|
|
83
|
+
style={style}
|
|
84
|
+
testID={testID}
|
|
85
|
+
/>
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export default Slider;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
import type { BadgeConfigType, OptionType } from '.';
|
|
4
|
+
import { useTheme } from '../../../theme';
|
|
5
|
+
import { StyledIconWrapper, StyledTextWrapper } from './StyledSelectorSwitch';
|
|
6
|
+
import Typography from '../../Typography';
|
|
7
|
+
import Badge from '../../Badge';
|
|
8
|
+
import Icon from '../../Icon';
|
|
9
|
+
|
|
10
|
+
export const OptionContent = ({
|
|
11
|
+
content,
|
|
12
|
+
badge,
|
|
13
|
+
}: {
|
|
14
|
+
content: ReactElement;
|
|
15
|
+
badge?: BadgeConfigType;
|
|
16
|
+
}) => {
|
|
17
|
+
const theme = useTheme();
|
|
18
|
+
if (!badge) {
|
|
19
|
+
return content;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (badge.type === 'status') {
|
|
23
|
+
return (
|
|
24
|
+
<Badge.Status
|
|
25
|
+
visible
|
|
26
|
+
style={{ paddingHorizontal: theme.space.small }}
|
|
27
|
+
testID="selector-switch-status-badge"
|
|
28
|
+
>
|
|
29
|
+
{content}
|
|
30
|
+
</Badge.Status>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return content;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const Option = <T,>({
|
|
38
|
+
text,
|
|
39
|
+
icon,
|
|
40
|
+
badge,
|
|
41
|
+
selected,
|
|
42
|
+
}: Pick<OptionType<T>, 'text' | 'icon' | 'badge'> & {
|
|
43
|
+
selected: boolean;
|
|
44
|
+
}): ReactElement => {
|
|
45
|
+
if (selected) {
|
|
46
|
+
return (
|
|
47
|
+
<StyledTextWrapper>
|
|
48
|
+
<OptionContent
|
|
49
|
+
content={
|
|
50
|
+
<Typography.Text fontSize="large" intent="inverted">
|
|
51
|
+
{text}
|
|
52
|
+
</Typography.Text>
|
|
53
|
+
}
|
|
54
|
+
badge={badge}
|
|
55
|
+
/>
|
|
56
|
+
</StyledTextWrapper>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<StyledIconWrapper>
|
|
62
|
+
<OptionContent content={<Icon icon={icon} />} badge={badge} />
|
|
63
|
+
</StyledIconWrapper>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export default Option;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import styled from '@emotion/native';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export const StyledWrapper = styled(View)(({ theme }) => ({
|
|
5
|
+
flexDirection: 'row',
|
|
6
|
+
width: '100%',
|
|
7
|
+
height: theme.__hd__.switch.sizes.selector.height,
|
|
8
|
+
borderRadius: theme.__hd__.switch.radii.selector.default,
|
|
9
|
+
backgroundColor: theme.__hd__.switch.colors.selector.background,
|
|
10
|
+
padding: theme.__hd__.switch.spaces.selector.wrapperPadding,
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
export const StyledTextWrapper = styled(View)(({ theme }) => ({
|
|
14
|
+
flex: 1,
|
|
15
|
+
borderRadius: theme.__hd__.switch.radii.selector.default,
|
|
16
|
+
backgroundColor: theme.__hd__.switch.colors.selector.textBackground,
|
|
17
|
+
justifyContent: 'center',
|
|
18
|
+
alignItems: 'center',
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
export const StyledIconWrapper = styled(View)(({ theme }) => ({
|
|
22
|
+
paddingHorizontal: theme.__hd__.switch.spaces.selector.iconPadding,
|
|
23
|
+
justifyContent: 'center',
|
|
24
|
+
alignItems: 'center',
|
|
25
|
+
}));
|