@hero-design/rn 8.103.5 → 8.103.7
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 +4 -4
- package/CHANGELOG.md +16 -0
- package/es/index.js +174 -73
- package/lib/index.js +174 -73
- package/package.json +1 -1
- package/src/components/DatePicker/DatePickerAndroid.tsx +18 -4
- package/src/components/DatePicker/DatePickerCalendar.tsx +18 -4
- package/src/components/DatePicker/DatePickerIOS.tsx +18 -4
- package/src/components/DatePicker/StyledDatePicker.tsx +19 -2
- package/src/components/DatePicker/__tests__/DatePicker.spec.tsx +102 -1
- package/src/components/DatePicker/__tests__/__snapshots__/DatePicker.spec.tsx.snap +6 -0
- package/src/components/DatePicker/__tests__/__snapshots__/DatePickerAndroid.spec.tsx.snap +2 -0
- package/src/components/DatePicker/__tests__/__snapshots__/DatePickerCalendar.spec.tsx.snap +2 -0
- package/src/components/DatePicker/__tests__/__snapshots__/DatePickerIOS.spec.tsx.snap +4 -0
- package/src/components/DatePicker/types.ts +11 -0
- package/src/components/RichTextEditor/RichTextEditor.tsx +6 -2
- package/src/components/RichTextEditor/StyledRichTextEditor.ts +1 -4
- package/src/components/RichTextEditor/__tests__/RichTextEditor.spec.tsx +4 -2
- package/src/components/RichTextEditor/__tests__/__snapshots__/RichTextEditor.spec.tsx.snap +8 -5
- package/src/components/Select/MultiSelect/__tests__/__snapshots__/index.spec.tsx.snap +7 -0
- package/src/components/Select/MultiSelect/__tests__/index.spec.tsx +53 -0
- package/src/components/Select/MultiSelect/index.tsx +18 -8
- package/src/components/Select/SingleSelect/__tests__/__snapshots__/index.spec.tsx.snap +6 -0
- package/src/components/Select/SingleSelect/__tests__/index.spec.tsx +50 -0
- package/src/components/Select/SingleSelect/index.tsx +19 -8
- package/src/components/Select/StyledSelect.tsx +25 -2
- package/src/components/Select/index.tsx +8 -2
- package/src/components/TextInput/__tests__/__snapshots__/index.spec.tsx.snap +14 -0
- package/src/components/TextInput/index.tsx +6 -1
- package/src/components/TimePicker/StyledTimePicker.tsx +19 -2
- package/src/components/TimePicker/TimePickerAndroid.tsx +18 -4
- package/src/components/TimePicker/TimePickerIOS.tsx +21 -5
- package/src/components/TimePicker/__tests__/TimePicker.spec.tsx +72 -1
- package/src/components/TimePicker/__tests__/__snapshots__/TimePickerAndroid.spec.tsx.snap +4 -0
- package/src/components/TimePicker/__tests__/__snapshots__/TimePickerIOS.spec.tsx.snap +4 -0
- package/src/components/TimePicker/types.ts +11 -0
- package/stats/8.103.5/rn-stats.html +0 -2
- package/stats/8.103.6/rn-stats.html +4842 -0
- package/stats/8.103.7/rn-stats.html +4844 -0
- package/types/components/DatePicker/DatePickerAndroid.d.ts +1 -1
- package/types/components/DatePicker/DatePickerCalendar.d.ts +1 -1
- package/types/components/DatePicker/DatePickerIOS.d.ts +1 -1
- package/types/components/DatePicker/StyledDatePicker.d.ts +8 -1
- package/types/components/DatePicker/types.d.ts +11 -0
- package/types/components/RichTextEditor/StyledRichTextEditor.d.ts +0 -2
- package/types/components/Select/MultiSelect/index.d.ts +2 -1
- package/types/components/Select/SingleSelect/index.d.ts +2 -1
- package/types/components/Select/StyledSelect.d.ts +8 -1
- package/types/components/Select/index.d.ts +2 -2
- package/types/components/Select/index.internal.d.ts +1 -1
- package/types/components/TimePicker/StyledTimePicker.d.ts +8 -1
- package/types/components/TimePicker/TimePickerAndroid.d.ts +1 -1
- package/types/components/TimePicker/TimePickerIOS.d.ts +1 -1
- package/types/components/TimePicker/types.d.ts +11 -0
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import React, { useRef, useState } from 'react';
|
|
1
|
+
import React, { useCallback, useRef, useState } from 'react';
|
|
2
2
|
import type {
|
|
3
|
-
SectionList,
|
|
4
3
|
TextInputProps as NativeTextInputProps,
|
|
4
|
+
SectionList,
|
|
5
5
|
} from 'react-native';
|
|
6
|
-
import {
|
|
6
|
+
import { View } from 'react-native';
|
|
7
|
+
import { deepCompareValue, useKeyboard } from '../../../utils/helpers';
|
|
7
8
|
import BottomSheet from '../../BottomSheet';
|
|
8
9
|
import TextInput, { TextInputProps } from '../../TextInput';
|
|
9
10
|
import { getScrollParams, toFlatOptions, toSections } from '../helpers';
|
|
10
|
-
import { StyledSearchBar } from '../StyledSelect';
|
|
11
|
-
import type {
|
|
11
|
+
import { StyledSearchBar, StyledTouchableOpacity } from '../StyledSelect';
|
|
12
|
+
import type { SectionType, SelectOptionType, SelectProps } from '../types';
|
|
12
13
|
import OptionList from './OptionList';
|
|
13
|
-
import { deepCompareValue, useKeyboard } from '../../../utils/helpers';
|
|
14
14
|
|
|
15
15
|
export interface SingleSelectProps<
|
|
16
16
|
V,
|
|
@@ -43,6 +43,7 @@ export interface InternalSingleSelectProps<
|
|
|
43
43
|
T extends SelectOptionType<V> = SelectOptionType<V>
|
|
44
44
|
> extends SingleSelectProps<V, T> {
|
|
45
45
|
TextInputComponent?: React.ComponentType<TextInputProps>;
|
|
46
|
+
groupStyleEnabled?: boolean;
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
const SingleSelect = <V, T extends SelectOptionType<V>>({
|
|
@@ -66,6 +67,7 @@ const SingleSelect = <V, T extends SelectOptionType<V>>({
|
|
|
66
67
|
value,
|
|
67
68
|
supportedOrientations = ['portrait'],
|
|
68
69
|
bottomSheetConfig = {},
|
|
70
|
+
groupStyleEnabled = false,
|
|
69
71
|
...rest
|
|
70
72
|
}: InternalSingleSelectProps<V, T>) => {
|
|
71
73
|
const { isKeyboardVisible, keyboardHeight } = useKeyboard();
|
|
@@ -83,6 +85,10 @@ const SingleSelect = <V, T extends SelectOptionType<V>>({
|
|
|
83
85
|
|
|
84
86
|
const TextInputComponent = rest.TextInputComponent || TextInput;
|
|
85
87
|
|
|
88
|
+
const onPress = useCallback(() => {
|
|
89
|
+
setOpen(true);
|
|
90
|
+
}, []);
|
|
91
|
+
|
|
86
92
|
return (
|
|
87
93
|
<>
|
|
88
94
|
<View
|
|
@@ -90,7 +96,12 @@ const SingleSelect = <V, T extends SelectOptionType<V>>({
|
|
|
90
96
|
!editable || disabled || inputProps?.loading ? 'none' : 'auto'
|
|
91
97
|
}
|
|
92
98
|
>
|
|
93
|
-
<
|
|
99
|
+
<StyledTouchableOpacity
|
|
100
|
+
onPress={onPress}
|
|
101
|
+
themeGroupStyleEnabled={groupStyleEnabled}
|
|
102
|
+
themeHasError={!!error}
|
|
103
|
+
testID="single-select-touchable-opacity"
|
|
104
|
+
>
|
|
94
105
|
{
|
|
95
106
|
// prevent users from focusing TextInput
|
|
96
107
|
}
|
|
@@ -115,7 +126,7 @@ const SingleSelect = <V, T extends SelectOptionType<V>>({
|
|
|
115
126
|
}
|
|
116
127
|
/>
|
|
117
128
|
</View>
|
|
118
|
-
</
|
|
129
|
+
</StyledTouchableOpacity>
|
|
119
130
|
</View>
|
|
120
131
|
<BottomSheet
|
|
121
132
|
variant={bottomSheetVariant || 'fixed'}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SectionList, View } from 'react-native';
|
|
1
|
+
import { SectionList, TouchableOpacity, View } from 'react-native';
|
|
2
2
|
import styled from '@emotion/native';
|
|
3
3
|
|
|
4
4
|
const SectionSpacer = styled(View)(({ theme }) => ({
|
|
@@ -19,4 +19,27 @@ const StyledSectionList = styled(SectionList)(({ theme }) => ({
|
|
|
19
19
|
paddingHorizontal: theme.__hd__.select.space.optionListHorizontalPadding,
|
|
20
20
|
})) as unknown as typeof SectionList;
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
const getZIndexByState = ({ themeHasError }: { themeHasError: boolean }) => {
|
|
23
|
+
if (themeHasError) {
|
|
24
|
+
return 1;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return 0;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const StyledTouchableOpacity = styled(TouchableOpacity)<{
|
|
31
|
+
themeGroupStyleEnabled: boolean;
|
|
32
|
+
themeHasError: boolean;
|
|
33
|
+
}>(({ themeGroupStyleEnabled, themeHasError }) => ({
|
|
34
|
+
...(themeGroupStyleEnabled && {
|
|
35
|
+
zIndex: getZIndexByState({ themeHasError }),
|
|
36
|
+
}),
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
export {
|
|
40
|
+
SectionSpacer,
|
|
41
|
+
OptionSpacer,
|
|
42
|
+
StyledSearchBar,
|
|
43
|
+
StyledSectionList,
|
|
44
|
+
StyledTouchableOpacity,
|
|
45
|
+
};
|
|
@@ -10,11 +10,17 @@ type SingleSelectType = <
|
|
|
10
10
|
V,
|
|
11
11
|
T extends SelectOptionType<V> = SelectOptionType<V>
|
|
12
12
|
>(
|
|
13
|
-
props: Omit<
|
|
13
|
+
props: Omit<
|
|
14
|
+
SingleSelectProps<V, T>,
|
|
15
|
+
'TextInputComponent' | 'groupStyleEnabled'
|
|
16
|
+
>
|
|
14
17
|
) => React.ReactElement;
|
|
15
18
|
|
|
16
19
|
type MultiSelectType = <V, T extends SelectOptionType<V> = SelectOptionType<V>>(
|
|
17
|
-
props: Omit<
|
|
20
|
+
props: Omit<
|
|
21
|
+
MultiSelectProps<V, T>,
|
|
22
|
+
'TextInputComponent' | 'groupStyleEnabled'
|
|
23
|
+
>
|
|
18
24
|
) => React.ReactElement;
|
|
19
25
|
|
|
20
26
|
export default Object.assign(SingleSelect as SingleSelectType, {
|
|
@@ -199,6 +199,7 @@ exports[`TextInput backgroundColor renders correctly 1`] = `
|
|
|
199
199
|
defaultValue="1000"
|
|
200
200
|
editable={true}
|
|
201
201
|
maxLength={255}
|
|
202
|
+
numberOfLines={1}
|
|
202
203
|
onBlur={[Function]}
|
|
203
204
|
onChangeText={[Function]}
|
|
204
205
|
onFocus={[Function]}
|
|
@@ -527,6 +528,7 @@ exports[`TextInput defaultValue TextInput is idle renders correctly 1`] = `
|
|
|
527
528
|
defaultValue="1000"
|
|
528
529
|
editable={true}
|
|
529
530
|
maxLength={255}
|
|
531
|
+
numberOfLines={1}
|
|
530
532
|
onBlur={[Function]}
|
|
531
533
|
onChangeText={[Function]}
|
|
532
534
|
onFocus={[Function]}
|
|
@@ -854,6 +856,7 @@ exports[`TextInput defaultValue default Value and Value renders correctly with 2
|
|
|
854
856
|
defaultValue="1000"
|
|
855
857
|
editable={true}
|
|
856
858
|
maxLength={255}
|
|
859
|
+
numberOfLines={1}
|
|
857
860
|
onBlur={[Function]}
|
|
858
861
|
onChangeText={[Function]}
|
|
859
862
|
onFocus={[Function]}
|
|
@@ -1165,6 +1168,7 @@ exports[`TextInput disabled renders correctly 1`] = `
|
|
|
1165
1168
|
}
|
|
1166
1169
|
allowFontScaling={false}
|
|
1167
1170
|
editable={true}
|
|
1171
|
+
numberOfLines={1}
|
|
1168
1172
|
onBlur={[Function]}
|
|
1169
1173
|
onChangeText={[Function]}
|
|
1170
1174
|
onFocus={[Function]}
|
|
@@ -1441,6 +1445,7 @@ exports[`TextInput error renders correctly 1`] = `
|
|
|
1441
1445
|
}
|
|
1442
1446
|
allowFontScaling={false}
|
|
1443
1447
|
editable={true}
|
|
1448
|
+
numberOfLines={1}
|
|
1444
1449
|
onBlur={[Function]}
|
|
1445
1450
|
onChangeText={[Function]}
|
|
1446
1451
|
onFocus={[Function]}
|
|
@@ -1744,6 +1749,7 @@ exports[`TextInput filled renders correctly 1`] = `
|
|
|
1744
1749
|
}
|
|
1745
1750
|
allowFontScaling={false}
|
|
1746
1751
|
editable={true}
|
|
1752
|
+
numberOfLines={1}
|
|
1747
1753
|
onBlur={[Function]}
|
|
1748
1754
|
onChangeText={[Function]}
|
|
1749
1755
|
onFocus={[Function]}
|
|
@@ -2035,6 +2041,7 @@ exports[`TextInput helper text renders correctly 1`] = `
|
|
|
2035
2041
|
}
|
|
2036
2042
|
allowFontScaling={false}
|
|
2037
2043
|
editable={true}
|
|
2044
|
+
numberOfLines={1}
|
|
2038
2045
|
onBlur={[Function]}
|
|
2039
2046
|
onChangeText={[Function]}
|
|
2040
2047
|
onFocus={[Function]}
|
|
@@ -2304,6 +2311,7 @@ exports[`TextInput idle renders correctly 1`] = `
|
|
|
2304
2311
|
}
|
|
2305
2312
|
allowFontScaling={false}
|
|
2306
2313
|
editable={true}
|
|
2314
|
+
numberOfLines={1}
|
|
2307
2315
|
onBlur={[Function]}
|
|
2308
2316
|
onChangeText={[Function]}
|
|
2309
2317
|
onFocus={[Function]}
|
|
@@ -2594,6 +2602,7 @@ exports[`TextInput idle with suffix and prefix are React Element renders correct
|
|
|
2594
2602
|
}
|
|
2595
2603
|
allowFontScaling={false}
|
|
2596
2604
|
editable={true}
|
|
2605
|
+
numberOfLines={1}
|
|
2597
2606
|
onBlur={[Function]}
|
|
2598
2607
|
onChangeText={[Function]}
|
|
2599
2608
|
onFocus={[Function]}
|
|
@@ -2796,6 +2805,7 @@ exports[`TextInput loading renders correctly 1`] = `
|
|
|
2796
2805
|
}
|
|
2797
2806
|
allowFontScaling={false}
|
|
2798
2807
|
editable={true}
|
|
2808
|
+
numberOfLines={1}
|
|
2799
2809
|
onBlur={[Function]}
|
|
2800
2810
|
onChangeText={[Function]}
|
|
2801
2811
|
onFocus={[Function]}
|
|
@@ -3766,6 +3776,7 @@ exports[`TextInput placeholder TextInput is idle renders correctly 1`] = `
|
|
|
3766
3776
|
}
|
|
3767
3777
|
allowFontScaling={false}
|
|
3768
3778
|
editable={true}
|
|
3779
|
+
numberOfLines={1}
|
|
3769
3780
|
onBlur={[Function]}
|
|
3770
3781
|
onChangeText={[Function]}
|
|
3771
3782
|
onFocus={[Function]}
|
|
@@ -4061,6 +4072,7 @@ exports[`TextInput readonly renders correctly 1`] = `
|
|
|
4061
4072
|
}
|
|
4062
4073
|
allowFontScaling={false}
|
|
4063
4074
|
editable={false}
|
|
4075
|
+
numberOfLines={1}
|
|
4064
4076
|
onBlur={[Function]}
|
|
4065
4077
|
onChangeText={[Function]}
|
|
4066
4078
|
onFocus={[Function]}
|
|
@@ -4307,6 +4319,7 @@ exports[`TextInput ref ref methods work correctly 1`] = `
|
|
|
4307
4319
|
}
|
|
4308
4320
|
allowFontScaling={false}
|
|
4309
4321
|
editable={true}
|
|
4322
|
+
numberOfLines={1}
|
|
4310
4323
|
onBlur={[Function]}
|
|
4311
4324
|
onChangeText={[Function]}
|
|
4312
4325
|
onFocus={[Function]}
|
|
@@ -4583,6 +4596,7 @@ exports[`TextInput required renders correctly 1`] = `
|
|
|
4583
4596
|
}
|
|
4584
4597
|
allowFontScaling={false}
|
|
4585
4598
|
editable={true}
|
|
4599
|
+
numberOfLines={1}
|
|
4586
4600
|
onBlur={[Function]}
|
|
4587
4601
|
onChangeText={[Function]}
|
|
4588
4602
|
onFocus={[Function]}
|
|
@@ -226,13 +226,18 @@ export const renderInput = ({
|
|
|
226
226
|
ref?: React.Ref<RNTextInput>;
|
|
227
227
|
theme: Theme;
|
|
228
228
|
}) => {
|
|
229
|
+
const multiline = variant === 'textarea' || nativeInputProps.multiline;
|
|
230
|
+
// `numberOfLines` must be `1` for single-line inputs to render properly on Android.
|
|
231
|
+
const numberOfLines = multiline ? nativeInputProps.numberOfLines : 1;
|
|
232
|
+
|
|
229
233
|
return renderInputValue ? (
|
|
230
234
|
renderInputValue(nativeInputProps, ref)
|
|
231
235
|
) : (
|
|
232
236
|
<StyledTextInput
|
|
233
237
|
{...nativeInputProps}
|
|
234
238
|
themeVariant={variant}
|
|
235
|
-
multiline={
|
|
239
|
+
multiline={multiline}
|
|
240
|
+
numberOfLines={numberOfLines}
|
|
236
241
|
ref={ref}
|
|
237
242
|
placeholderTextColor={theme.__hd__.textInput.colors.placeholder}
|
|
238
243
|
/>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import styled from '@emotion/native';
|
|
2
|
-
import { View } from 'react-native';
|
|
2
|
+
import { View, TouchableOpacity } from 'react-native';
|
|
3
3
|
import type { ViewProps } from 'react-native';
|
|
4
4
|
|
|
5
5
|
const StyledPickerWrapper = styled(View)<ViewProps>(({ theme }) => ({
|
|
@@ -7,4 +7,21 @@ const StyledPickerWrapper = styled(View)<ViewProps>(({ theme }) => ({
|
|
|
7
7
|
alignItems: 'center',
|
|
8
8
|
}));
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
const getZIndexByState = ({ themeHasError }: { themeHasError: boolean }) => {
|
|
11
|
+
if (themeHasError) {
|
|
12
|
+
return 1;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return 0;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const StyledTouchableOpacity = styled(TouchableOpacity)<{
|
|
19
|
+
themeGroupStyleEnabled: boolean;
|
|
20
|
+
themeHasError: boolean;
|
|
21
|
+
}>(({ themeGroupStyleEnabled, themeHasError }) => ({
|
|
22
|
+
...(themeGroupStyleEnabled && {
|
|
23
|
+
zIndex: getZIndexByState({ themeHasError }),
|
|
24
|
+
}),
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
export { StyledPickerWrapper, StyledTouchableOpacity };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import DateTimePicker from '@react-native-community/datetimepicker';
|
|
2
|
-
import React, { useState } from 'react';
|
|
3
|
-
import {
|
|
2
|
+
import React, { useState, useCallback } from 'react';
|
|
3
|
+
import { View } from 'react-native';
|
|
4
4
|
import formatTime from 'date-fns/fp/format';
|
|
5
5
|
|
|
6
6
|
import TextInput from '../TextInput';
|
|
7
|
+
import { StyledTouchableOpacity } from './StyledTimePicker';
|
|
7
8
|
import type { InternalTimePickerProps } from './types';
|
|
8
9
|
|
|
9
10
|
const TimePickerAndroid = ({
|
|
@@ -20,6 +21,8 @@ const TimePickerAndroid = ({
|
|
|
20
21
|
testID,
|
|
21
22
|
showSuffix = true,
|
|
22
23
|
TextInputComponent,
|
|
24
|
+
inputProps,
|
|
25
|
+
groupStyleEnabled = false,
|
|
23
26
|
}: InternalTimePickerProps) => {
|
|
24
27
|
const [open, setOpen] = useState(false);
|
|
25
28
|
|
|
@@ -29,10 +32,21 @@ const TimePickerAndroid = ({
|
|
|
29
32
|
|
|
30
33
|
const InputComponent = TextInputComponent || TextInput;
|
|
31
34
|
|
|
35
|
+
const onPress = useCallback(() => {
|
|
36
|
+
setOpen(true);
|
|
37
|
+
}, []);
|
|
38
|
+
|
|
32
39
|
return (
|
|
33
|
-
<
|
|
40
|
+
<StyledTouchableOpacity
|
|
41
|
+
onPress={onPress}
|
|
42
|
+
disabled={disabled}
|
|
43
|
+
themeGroupStyleEnabled={groupStyleEnabled}
|
|
44
|
+
themeHasError={!!error}
|
|
45
|
+
testID="time-picker-android-touchable-opacity"
|
|
46
|
+
>
|
|
34
47
|
<View pointerEvents="none" testID="timePickerInputAndroid">
|
|
35
48
|
<InputComponent
|
|
49
|
+
{...inputProps}
|
|
36
50
|
label={label}
|
|
37
51
|
value={displayValue}
|
|
38
52
|
suffix={showSuffix ? 'clock-3' : undefined}
|
|
@@ -60,7 +74,7 @@ const TimePickerAndroid = ({
|
|
|
60
74
|
is24Hour={!is12Hour}
|
|
61
75
|
/>
|
|
62
76
|
) : null}
|
|
63
|
-
</
|
|
77
|
+
</StyledTouchableOpacity>
|
|
64
78
|
);
|
|
65
79
|
};
|
|
66
80
|
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import DateTimePicker from '@react-native-community/datetimepicker';
|
|
2
|
-
import React, { useEffect, useState } from 'react';
|
|
3
|
-
import {
|
|
2
|
+
import React, { useEffect, useState, useCallback } from 'react';
|
|
3
|
+
import { View } from 'react-native';
|
|
4
4
|
import formatTime from 'date-fns/fp/format';
|
|
5
5
|
|
|
6
6
|
import BottomSheet from '../BottomSheet';
|
|
7
7
|
import TextInput from '../TextInput';
|
|
8
8
|
import Button from '../Button';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
StyledPickerWrapper,
|
|
11
|
+
StyledTouchableOpacity,
|
|
12
|
+
} from './StyledTimePicker';
|
|
10
13
|
import type { InternalTimePickerProps } from './types';
|
|
11
14
|
import { useTheme } from '../../theme';
|
|
12
15
|
|
|
@@ -26,6 +29,8 @@ const TimePickerIOS = ({
|
|
|
26
29
|
showSuffix = true,
|
|
27
30
|
supportedOrientations = ['portrait'],
|
|
28
31
|
TextInputComponent,
|
|
32
|
+
inputProps,
|
|
33
|
+
groupStyleEnabled = false,
|
|
29
34
|
}: InternalTimePickerProps) => {
|
|
30
35
|
const [selectingDate, setSelectingDate] = useState<Date>(value || new Date());
|
|
31
36
|
const [open, setOpen] = useState(false);
|
|
@@ -40,10 +45,21 @@ const TimePickerIOS = ({
|
|
|
40
45
|
setSelectingDate(value || new Date());
|
|
41
46
|
}, [value]);
|
|
42
47
|
|
|
48
|
+
const onPress = useCallback(() => {
|
|
49
|
+
setOpen(true);
|
|
50
|
+
}, []);
|
|
51
|
+
|
|
43
52
|
return (
|
|
44
|
-
<
|
|
53
|
+
<StyledTouchableOpacity
|
|
54
|
+
onPress={onPress}
|
|
55
|
+
disabled={disabled}
|
|
56
|
+
themeGroupStyleEnabled={groupStyleEnabled}
|
|
57
|
+
themeHasError={!!error}
|
|
58
|
+
testID="time-picker-ios-touchable-opacity"
|
|
59
|
+
>
|
|
45
60
|
<View pointerEvents="none" testID="timePickerInputIOS">
|
|
46
61
|
<InputComponent
|
|
62
|
+
{...inputProps}
|
|
47
63
|
label={label}
|
|
48
64
|
value={displayValue}
|
|
49
65
|
suffix={showSuffix ? 'clock-3' : undefined}
|
|
@@ -93,7 +109,7 @@ const TimePickerIOS = ({
|
|
|
93
109
|
/>
|
|
94
110
|
</StyledPickerWrapper>
|
|
95
111
|
</BottomSheet>
|
|
96
|
-
</
|
|
112
|
+
</StyledTouchableOpacity>
|
|
97
113
|
);
|
|
98
114
|
};
|
|
99
115
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Platform } from 'react-native';
|
|
3
|
-
import
|
|
3
|
+
// Use internal import for full prop support
|
|
4
|
+
import TimePicker from '../index.internal';
|
|
4
5
|
import renderWithTheme from '../../../testHelpers/renderWithTheme';
|
|
5
6
|
|
|
6
7
|
describe('TimePicker', () => {
|
|
@@ -31,4 +32,74 @@ describe('TimePicker', () => {
|
|
|
31
32
|
|
|
32
33
|
expect(getByTestId('timePickerInputAndroid')).toBeDefined();
|
|
33
34
|
});
|
|
35
|
+
|
|
36
|
+
it('renders correctly when inputProps loading is true', () => {
|
|
37
|
+
Platform.OS = 'ios';
|
|
38
|
+
const { getByTestId } = renderWithTheme(
|
|
39
|
+
<TimePicker
|
|
40
|
+
label="Start time"
|
|
41
|
+
value={new Date('December 17, 1995 03:24:00')}
|
|
42
|
+
confirmLabel="Confirm"
|
|
43
|
+
inputProps={{ loading: true }}
|
|
44
|
+
onChange={jest.fn()}
|
|
45
|
+
/>
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
expect(getByTestId('input-suffix')).toHaveProp('name', 'loading');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('renders correctly when groupStyleEnabled is true and no error', () => {
|
|
52
|
+
Platform.OS = 'ios';
|
|
53
|
+
const { getByTestId } = renderWithTheme(
|
|
54
|
+
<TimePicker
|
|
55
|
+
label="Start time"
|
|
56
|
+
value={new Date('December 17, 1995 03:24:00')}
|
|
57
|
+
confirmLabel="Confirm"
|
|
58
|
+
groupStyleEnabled
|
|
59
|
+
onChange={jest.fn()}
|
|
60
|
+
/>
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const touchableOpacity = getByTestId('time-picker-ios-touchable-opacity');
|
|
64
|
+
expect(touchableOpacity).toBeTruthy();
|
|
65
|
+
expect(touchableOpacity.props.style).toHaveProperty('zIndex', 0);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('renders correctly when groupStyleEnabled is true and has error', () => {
|
|
69
|
+
Platform.OS = 'ios';
|
|
70
|
+
const { getByTestId } = renderWithTheme(
|
|
71
|
+
<TimePicker
|
|
72
|
+
label="Start time"
|
|
73
|
+
value={new Date('December 17, 1995 03:24:00')}
|
|
74
|
+
confirmLabel="Confirm"
|
|
75
|
+
groupStyleEnabled
|
|
76
|
+
error="This field is required"
|
|
77
|
+
onChange={jest.fn()}
|
|
78
|
+
/>
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const touchableOpacity = getByTestId('time-picker-ios-touchable-opacity');
|
|
82
|
+
expect(touchableOpacity).toBeTruthy();
|
|
83
|
+
expect(touchableOpacity.props.style).toHaveProperty('zIndex', 1);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('renders correctly when groupStyleEnabled is true and has error for Android', () => {
|
|
87
|
+
Platform.OS = 'android';
|
|
88
|
+
const { getByTestId } = renderWithTheme(
|
|
89
|
+
<TimePicker
|
|
90
|
+
label="Start time"
|
|
91
|
+
value={new Date('December 17, 1995 03:24:00')}
|
|
92
|
+
confirmLabel="Confirm"
|
|
93
|
+
groupStyleEnabled
|
|
94
|
+
error="This field is required"
|
|
95
|
+
onChange={jest.fn()}
|
|
96
|
+
/>
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
const touchableOpacity = getByTestId(
|
|
100
|
+
'time-picker-android-touchable-opacity'
|
|
101
|
+
);
|
|
102
|
+
expect(touchableOpacity).toBeTruthy();
|
|
103
|
+
expect(touchableOpacity.props.style).toHaveProperty('zIndex', 1);
|
|
104
|
+
});
|
|
34
105
|
});
|
|
@@ -41,6 +41,7 @@ exports[`TimePickerAndroid renders correct with hide suffix 1`] = `
|
|
|
41
41
|
"opacity": 1,
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
+
testID="time-picker-android-touchable-opacity"
|
|
44
45
|
>
|
|
45
46
|
<View
|
|
46
47
|
pointerEvents="none"
|
|
@@ -190,6 +191,7 @@ exports[`TimePickerAndroid renders correct with hide suffix 1`] = `
|
|
|
190
191
|
}
|
|
191
192
|
allowFontScaling={false}
|
|
192
193
|
editable={true}
|
|
194
|
+
numberOfLines={1}
|
|
193
195
|
onBlur={[Function]}
|
|
194
196
|
onChangeText={[Function]}
|
|
195
197
|
onFocus={[Function]}
|
|
@@ -332,6 +334,7 @@ exports[`TimePickerAndroid renders correctly 1`] = `
|
|
|
332
334
|
"opacity": 1,
|
|
333
335
|
}
|
|
334
336
|
}
|
|
337
|
+
testID="time-picker-android-touchable-opacity"
|
|
335
338
|
>
|
|
336
339
|
<View
|
|
337
340
|
pointerEvents="none"
|
|
@@ -481,6 +484,7 @@ exports[`TimePickerAndroid renders correctly 1`] = `
|
|
|
481
484
|
}
|
|
482
485
|
allowFontScaling={false}
|
|
483
486
|
editable={true}
|
|
487
|
+
numberOfLines={1}
|
|
484
488
|
onBlur={[Function]}
|
|
485
489
|
onChangeText={[Function]}
|
|
486
490
|
onFocus={[Function]}
|
|
@@ -41,6 +41,7 @@ exports[`TimePickerIOS renders correct with hide suffix 1`] = `
|
|
|
41
41
|
"opacity": 1,
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
+
testID="time-picker-ios-touchable-opacity"
|
|
44
45
|
>
|
|
45
46
|
<View
|
|
46
47
|
pointerEvents="none"
|
|
@@ -190,6 +191,7 @@ exports[`TimePickerIOS renders correct with hide suffix 1`] = `
|
|
|
190
191
|
}
|
|
191
192
|
allowFontScaling={false}
|
|
192
193
|
editable={true}
|
|
194
|
+
numberOfLines={1}
|
|
193
195
|
onBlur={[Function]}
|
|
194
196
|
onChangeText={[Function]}
|
|
195
197
|
onFocus={[Function]}
|
|
@@ -332,6 +334,7 @@ exports[`TimePickerIOS renders correctly 1`] = `
|
|
|
332
334
|
"opacity": 1,
|
|
333
335
|
}
|
|
334
336
|
}
|
|
337
|
+
testID="time-picker-ios-touchable-opacity"
|
|
335
338
|
>
|
|
336
339
|
<View
|
|
337
340
|
pointerEvents="none"
|
|
@@ -481,6 +484,7 @@ exports[`TimePickerIOS renders correctly 1`] = `
|
|
|
481
484
|
}
|
|
482
485
|
allowFontScaling={false}
|
|
483
486
|
editable={true}
|
|
487
|
+
numberOfLines={1}
|
|
484
488
|
onBlur={[Function]}
|
|
485
489
|
onChangeText={[Function]}
|
|
486
490
|
onFocus={[Function]}
|
|
@@ -65,5 +65,16 @@ export interface TimePickerProps {
|
|
|
65
65
|
|
|
66
66
|
// Add an internal prop type for TextInputComponent, not exported
|
|
67
67
|
export interface InternalTimePickerProps extends TimePickerProps {
|
|
68
|
+
/**
|
|
69
|
+
* Props that are passed to TextInput.
|
|
70
|
+
*/
|
|
71
|
+
inputProps?: Pick<TextInputProps, 'loading' | 'numberOfLines'>;
|
|
72
|
+
/**
|
|
73
|
+
* Whether the component is used within a FormGroup for styling purposes.
|
|
74
|
+
*/
|
|
75
|
+
groupStyleEnabled?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Input component to use instead of the default TextInput.
|
|
78
|
+
*/
|
|
68
79
|
TextInputComponent?: React.ComponentType<TextInputProps>;
|
|
69
80
|
}
|