@hero-design/rn 7.10.2 → 7.12.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 +8 -8
- package/assets/fonts/hero-icons.ttf +0 -0
- package/es/index.js +3778 -728
- package/global-setup.js +3 -0
- package/jest.config.js +1 -0
- package/lib/assets/fonts/hero-icons.ttf +0 -0
- package/lib/index.js +3779 -726
- package/package.json +7 -3
- package/rollup.config.js +8 -1
- package/src/components/ContentNavigator/__tests__/__snapshots__/index.spec.tsx.snap +2 -0
- package/src/components/ContentNavigator/__tests__/index.spec.tsx +19 -2
- package/src/components/ContentNavigator/index.tsx +12 -1
- package/src/components/FAB/ActionGroup/__tests__/__snapshots__/index.spec.tsx.snap +4 -0
- package/src/components/FAB/ActionGroup/index.tsx +16 -5
- package/src/components/Icon/HeroIcon/selection.json +1 -1
- package/src/components/Icon/IconList.ts +1 -0
- package/src/components/PinInput/PinCell.tsx +34 -0
- package/src/components/PinInput/StyledPinInput.tsx +88 -0
- package/src/components/PinInput/__tests__/PinCell.spec.tsx +48 -0
- package/src/components/PinInput/__tests__/StyledPinInput.spec.tsx +22 -0
- package/src/components/PinInput/__tests__/__snapshots__/PinCell.spec.tsx.snap +186 -0
- package/src/components/PinInput/__tests__/__snapshots__/StyledPinInput.spec.tsx.snap +58 -0
- package/src/components/PinInput/__tests__/__snapshots__/index.spec.tsx.snap +1028 -0
- package/src/components/PinInput/__tests__/index.spec.tsx +91 -0
- package/src/components/PinInput/index.tsx +173 -0
- package/src/components/Select/MultiSelect/Option.tsx +1 -1
- package/src/components/Select/MultiSelect/OptionList.tsx +48 -26
- package/src/components/Select/MultiSelect/__tests__/OptionList.spec.tsx +13 -0
- package/src/components/Select/MultiSelect/__tests__/__snapshots__/OptionList.spec.tsx.snap +1062 -556
- package/src/components/Select/MultiSelect/__tests__/__snapshots__/index.spec.tsx.snap +983 -889
- package/src/components/Select/MultiSelect/index.tsx +59 -31
- package/src/components/Select/SingleSelect/OptionList.tsx +45 -26
- package/src/components/Select/SingleSelect/__tests__/OptionList.spec.tsx +8 -0
- package/src/components/Select/SingleSelect/__tests__/__snapshots__/OptionList.spec.tsx.snap +992 -500
- package/src/components/Select/SingleSelect/__tests__/__snapshots__/index.spec.tsx.snap +880 -786
- package/src/components/Select/SingleSelect/index.tsx +60 -31
- package/src/components/Select/StyledOptionList.tsx +88 -0
- package/src/components/Select/StyledSelect.tsx +18 -16
- package/src/components/Select/__tests__/StyledSelect.spec.tsx +1 -14
- package/src/components/Select/__tests__/__snapshots__/StyledSelect.spec.tsx.snap +0 -13
- package/src/components/Select/types.tsx +47 -0
- package/src/components/TextInput/__tests__/index.spec.tsx +15 -0
- package/src/components/TextInput/index.tsx +20 -16
- package/src/components/TimePicker/StyledTimePicker.tsx +8 -0
- package/src/components/TimePicker/TimePickerAndroid.tsx +61 -0
- package/src/components/TimePicker/TimePickerIOS.tsx +91 -0
- package/src/components/TimePicker/__tests__/TimePicker.spec.tsx +34 -0
- package/src/components/TimePicker/__tests__/TimePickerAndroid.spec.tsx +39 -0
- package/src/components/TimePicker/__tests__/TimePickerIOS.spec.tsx +46 -0
- package/src/components/TimePicker/__tests__/__snapshots__/TimePickerAndroid.spec.tsx.snap +200 -0
- package/src/components/TimePicker/__tests__/__snapshots__/TimePickerIOS.spec.tsx.snap +513 -0
- package/src/components/TimePicker/index.tsx +15 -0
- package/src/components/TimePicker/types.ts +50 -0
- package/src/components/Typography/Text/StyledText.tsx +1 -1
- package/src/components/Typography/Text/__tests__/StyledText.spec.tsx +1 -0
- package/src/components/Typography/Text/__tests__/__snapshots__/StyledText.spec.tsx.snap +22 -0
- package/src/components/Typography/Text/index.tsx +1 -1
- package/src/index.ts +4 -0
- package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +44 -0
- package/src/theme/components/pinInput.ts +45 -0
- package/src/theme/components/select.ts +4 -0
- package/src/theme/components/timePicker.ts +11 -0
- package/src/theme/components/typography.ts +2 -0
- package/src/theme/global/colors.ts +1 -1
- package/src/theme/global/space.ts +10 -10
- package/src/theme/index.ts +9 -3
- package/testUtils/setup.tsx +10 -0
- package/types/components/ContentNavigator/index.d.ts +5 -1
- package/types/components/Icon/IconList.d.ts +1 -1
- package/types/components/Icon/utils.d.ts +1 -1
- package/types/components/PinInput/PinCell.d.ts +8 -0
- package/types/components/PinInput/StyledPinInput.d.ts +73 -0
- package/types/components/PinInput/__tests__/PinCell.spec.d.ts +1 -0
- package/types/components/PinInput/__tests__/StyledPinInput.spec.d.ts +1 -0
- package/types/components/PinInput/__tests__/index.spec.d.ts +1 -0
- package/types/components/PinInput/index.d.ts +48 -0
- package/types/components/Select/MultiSelect/OptionList.d.ts +1 -1
- package/types/components/Select/MultiSelect/index.d.ts +3 -25
- package/types/components/Select/SingleSelect/OptionList.d.ts +1 -1
- package/types/components/Select/SingleSelect/index.d.ts +4 -26
- package/types/components/Select/StyledOptionList.d.ts +17 -0
- package/types/components/Select/StyledSelect.d.ts +7 -7
- package/types/components/Select/index.d.ts +1 -1
- package/types/components/Select/types.d.ts +44 -0
- package/types/components/TimePicker/StyledTimePicker.d.ts +8 -0
- package/types/components/TimePicker/TimePickerAndroid.d.ts +3 -0
- package/types/components/TimePicker/TimePickerIOS.d.ts +3 -0
- package/types/components/TimePicker/__tests__/TimePicker.spec.d.ts +1 -0
- package/types/components/TimePicker/__tests__/TimePickerAndroid.spec.d.ts +1 -0
- package/types/components/TimePicker/__tests__/TimePickerIOS.spec.d.ts +1 -0
- package/types/components/TimePicker/index.d.ts +3 -0
- package/types/components/TimePicker/types.d.ts +49 -0
- package/types/components/Typography/Text/StyledText.d.ts +1 -1
- package/types/components/Typography/Text/index.d.ts +1 -1
- package/types/index.d.ts +3 -1
- package/types/theme/components/pinInput.d.ts +35 -0
- package/types/theme/components/select.d.ts +4 -0
- package/types/theme/components/timePicker.d.ts +6 -0
- package/types/theme/components/typography.d.ts +2 -0
- package/types/theme/index.d.ts +6 -2
- package/src/components/Select/types.ts +0 -1
- package/src/components/TextInput/__tests__/.log/ti-10343.log +0 -62
- package/src/components/TextInput/__tests__/.log/tsserver.log +0 -15584
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { TouchableOpacity, Keyboard, KeyboardEvent, View } from 'react-native';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { SelectProps } from '../types';
|
|
5
5
|
import BottomSheet from '../../BottomSheet';
|
|
6
6
|
import Footer from '../Footer';
|
|
7
7
|
import OptionList from './OptionList';
|
|
8
8
|
import TextInput from '../../TextInput';
|
|
9
|
+
import { StyledSearchBar } from '../StyledSelect';
|
|
9
10
|
|
|
10
|
-
export interface MultiSelectProps<T> {
|
|
11
|
-
/**
|
|
12
|
-
* An array of options to be selected.
|
|
13
|
-
*/
|
|
14
|
-
options: OptionType<T>[];
|
|
11
|
+
export interface MultiSelectProps<T> extends SelectProps<T> {
|
|
15
12
|
/**
|
|
16
13
|
* Current selected value.
|
|
17
14
|
*/
|
|
@@ -20,37 +17,25 @@ export interface MultiSelectProps<T> {
|
|
|
20
17
|
* event handler for footer button.
|
|
21
18
|
*/
|
|
22
19
|
onConfirm: (value: T[]) => void;
|
|
23
|
-
/**
|
|
24
|
-
* Field label.
|
|
25
|
-
*/
|
|
26
|
-
label: string;
|
|
27
20
|
/**
|
|
28
21
|
* Footer label.
|
|
29
22
|
*/
|
|
30
23
|
footerLabel: string;
|
|
31
|
-
/**
|
|
32
|
-
* Used to extract a unique key for a given option at the specified index. Key is used for caching and as the react key to track item re-ordering.
|
|
33
|
-
* The default extractor checks option.key, and then falls back to using the index, like React does.
|
|
34
|
-
*/
|
|
35
|
-
keyExtractor?: (option: OptionType<T>, index?: number) => string;
|
|
36
|
-
/**
|
|
37
|
-
* Additional style.
|
|
38
|
-
*/
|
|
39
|
-
style?: StyleProp<ViewStyle>;
|
|
40
|
-
/**
|
|
41
|
-
* Testing id of the component.
|
|
42
|
-
*/
|
|
43
|
-
testID?: string;
|
|
44
24
|
}
|
|
45
25
|
|
|
46
26
|
function MultiSelect<T>({
|
|
47
|
-
options,
|
|
48
|
-
value,
|
|
49
|
-
testID,
|
|
50
|
-
style,
|
|
51
|
-
label,
|
|
52
27
|
footerLabel,
|
|
28
|
+
label,
|
|
29
|
+
loading,
|
|
53
30
|
onConfirm,
|
|
31
|
+
onDimiss,
|
|
32
|
+
onEndReached,
|
|
33
|
+
onQueryChange,
|
|
34
|
+
options,
|
|
35
|
+
query,
|
|
36
|
+
style,
|
|
37
|
+
testID,
|
|
38
|
+
value,
|
|
54
39
|
}: MultiSelectProps<T>) {
|
|
55
40
|
const [open, setOpen] = useState(false);
|
|
56
41
|
const [selectingValue, setSelectingValue] = useState(value);
|
|
@@ -59,6 +44,30 @@ function MultiSelect<T>({
|
|
|
59
44
|
.map(opt => opt.text)
|
|
60
45
|
.join(', ');
|
|
61
46
|
|
|
47
|
+
const [isKeyboardVisible, setKeyboardVisible] = useState(false);
|
|
48
|
+
const [keyboardHeight, setKeyboardHeight] = useState(0);
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
const keyboardDidShowListener = Keyboard.addListener(
|
|
52
|
+
'keyboardDidShow',
|
|
53
|
+
(e: KeyboardEvent) => {
|
|
54
|
+
setKeyboardVisible(true);
|
|
55
|
+
setKeyboardHeight(e.endCoordinates.height);
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
const keyboardDidHideListener = Keyboard.addListener(
|
|
59
|
+
'keyboardDidHide',
|
|
60
|
+
() => {
|
|
61
|
+
setKeyboardVisible(false);
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
return () => {
|
|
66
|
+
keyboardDidHideListener.remove();
|
|
67
|
+
keyboardDidShowListener.remove();
|
|
68
|
+
};
|
|
69
|
+
}, []);
|
|
70
|
+
|
|
62
71
|
return (
|
|
63
72
|
<TouchableOpacity onPress={() => setOpen(true)}>
|
|
64
73
|
<View pointerEvents="none">
|
|
@@ -74,8 +83,14 @@ function MultiSelect<T>({
|
|
|
74
83
|
<BottomSheet
|
|
75
84
|
open={open}
|
|
76
85
|
onRequestClose={() => setOpen(false)}
|
|
77
|
-
onDismiss={() =>
|
|
86
|
+
onDismiss={() => {
|
|
87
|
+
setSelectingValue(value);
|
|
88
|
+
if (onDimiss) onDimiss();
|
|
89
|
+
}}
|
|
78
90
|
header={label}
|
|
91
|
+
style={{
|
|
92
|
+
paddingBottom: isKeyboardVisible ? keyboardHeight : 0,
|
|
93
|
+
}}
|
|
79
94
|
footer={
|
|
80
95
|
<Footer
|
|
81
96
|
label={footerLabel}
|
|
@@ -86,7 +101,20 @@ function MultiSelect<T>({
|
|
|
86
101
|
/>
|
|
87
102
|
}
|
|
88
103
|
>
|
|
104
|
+
{onQueryChange && (
|
|
105
|
+
<StyledSearchBar>
|
|
106
|
+
<TextInput
|
|
107
|
+
editable
|
|
108
|
+
placeholder="Search"
|
|
109
|
+
suffix="search-outlined"
|
|
110
|
+
onChangeText={onQueryChange}
|
|
111
|
+
value={query}
|
|
112
|
+
/>
|
|
113
|
+
</StyledSearchBar>
|
|
114
|
+
)}
|
|
89
115
|
<OptionList
|
|
116
|
+
onEndReached={onEndReached}
|
|
117
|
+
loading={loading}
|
|
90
118
|
options={options}
|
|
91
119
|
value={selectingValue}
|
|
92
120
|
onPress={setSelectingValue}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { SingleSelectProps } from '.';
|
|
3
|
-
|
|
4
|
-
import {
|
|
3
|
+
|
|
4
|
+
import StyledOptionList, { RenderItemProps } from '../StyledOptionList';
|
|
5
5
|
import Option from './Option';
|
|
6
6
|
|
|
7
7
|
interface OptionListProps<T> extends SingleSelectProps<T> {
|
|
@@ -12,32 +12,51 @@ interface OptionListProps<T> extends SingleSelectProps<T> {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
const OptionList = <T,>({
|
|
15
|
-
value,
|
|
16
|
-
options,
|
|
17
|
-
onPress,
|
|
18
15
|
keyExtractor,
|
|
16
|
+
loading,
|
|
17
|
+
onEndReached,
|
|
18
|
+
onPress,
|
|
19
|
+
onQueryChange,
|
|
20
|
+
options,
|
|
21
|
+
value,
|
|
19
22
|
}: Pick<
|
|
20
23
|
OptionListProps<T>,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
24
|
+
| 'keyExtractor'
|
|
25
|
+
| 'loading'
|
|
26
|
+
| 'onEndReached'
|
|
27
|
+
| 'onPress'
|
|
28
|
+
| 'onQueryChange'
|
|
29
|
+
| 'options'
|
|
30
|
+
| 'value'
|
|
31
|
+
>) => {
|
|
32
|
+
const rawScrollIndex = options.findIndex(option => option.value === value);
|
|
33
|
+
const scrollIndex = rawScrollIndex - 2 >= 0 ? rawScrollIndex - 2 : 0;
|
|
34
|
+
|
|
35
|
+
const RenderItem = React.memo(({ item }: RenderItemProps<T>) => (
|
|
36
|
+
<Option
|
|
37
|
+
selected={value === item.value}
|
|
38
|
+
text={item.text}
|
|
39
|
+
onPress={() => {
|
|
40
|
+
if (value === item.value) {
|
|
41
|
+
onPress(null);
|
|
42
|
+
} else {
|
|
43
|
+
onPress(item.value);
|
|
44
|
+
}
|
|
45
|
+
}}
|
|
46
|
+
/>
|
|
47
|
+
));
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<StyledOptionList<T>
|
|
51
|
+
keyExtractor={keyExtractor}
|
|
52
|
+
loading={loading}
|
|
53
|
+
onEndReached={onEndReached}
|
|
54
|
+
onQueryChange={onQueryChange}
|
|
55
|
+
options={options}
|
|
56
|
+
RenderItem={RenderItem}
|
|
57
|
+
scrollIndex={scrollIndex}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
42
61
|
|
|
43
62
|
export default OptionList;
|
|
@@ -39,4 +39,12 @@ describe('OptionList', () => {
|
|
|
39
39
|
expect(pressFn).toBeCalledTimes(1);
|
|
40
40
|
expect(pressFn).toHaveBeenCalledWith(null);
|
|
41
41
|
});
|
|
42
|
+
|
|
43
|
+
it('render isLoading correctly', () => {
|
|
44
|
+
const pressFn = jest.fn();
|
|
45
|
+
const { toJSON } = renderWithTheme(
|
|
46
|
+
<OptionList value="a" options={mockOptions} onPress={pressFn} loading />
|
|
47
|
+
);
|
|
48
|
+
expect(toJSON()).toMatchSnapshot();
|
|
49
|
+
});
|
|
42
50
|
});
|