@utilitywarehouse/hearth-react-native 0.24.0 → 0.25.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 +1 -1
- package/.turbo/turbo-lint.log +11 -11
- package/CHANGELOG.md +41 -0
- package/build/components/DatePicker/DatePickerCalendar.js +4 -9
- package/build/components/TimePicker/TimePicker.d.ts +6 -0
- package/build/components/TimePicker/TimePicker.js +78 -0
- package/build/components/TimePicker/TimePicker.props.d.ts +45 -0
- package/build/components/TimePicker/TimePicker.props.js +1 -0
- package/build/components/TimePicker/TimePickerView.d.ts +12 -0
- package/build/components/TimePicker/TimePickerView.js +130 -0
- package/build/components/TimePicker/TimePickerWheel.d.ts +8 -0
- package/build/components/TimePicker/TimePickerWheel.js +78 -0
- package/build/components/{DatePicker/time-picker/wheel-web.d.ts → TimePicker/TimePickerWheel.web.d.ts} +4 -4
- package/build/components/TimePicker/TimePickerWheel.web.js +122 -0
- package/build/components/TimePicker/index.d.ts +6 -0
- package/build/components/TimePicker/index.js +3 -0
- package/build/components/TimePickerInput/TimePickerInput.d.ts +6 -0
- package/build/components/TimePickerInput/TimePickerInput.js +127 -0
- package/build/components/TimePickerInput/TimePickerInput.props.d.ts +52 -0
- package/build/components/TimePickerInput/TimePickerInput.props.js +1 -0
- package/build/components/TimePickerInput/TimePickerInputDoneButton.d.ts +8 -0
- package/build/components/TimePickerInput/TimePickerInputDoneButton.js +19 -0
- package/build/components/TimePickerInput/TimePickerInputDoneButton.web.d.ts +5 -0
- package/build/components/TimePickerInput/TimePickerInputDoneButton.web.js +5 -0
- package/build/components/TimePickerInput/index.d.ts +2 -0
- package/build/components/TimePickerInput/index.js +1 -0
- package/build/components/index.d.ts +2 -0
- package/build/components/index.js +2 -0
- package/docs/components/AllComponents.web.tsx +30 -0
- package/package.json +2 -1
- package/src/components/DatePicker/DatePickerCalendar.tsx +30 -13
- package/src/components/TimePicker/TimePicker.docs.mdx +84 -0
- package/src/components/TimePicker/TimePicker.figma.tsx +29 -0
- package/src/components/TimePicker/TimePicker.props.ts +45 -0
- package/src/components/TimePicker/TimePicker.stories.tsx +85 -0
- package/src/components/TimePicker/TimePicker.tsx +150 -0
- package/src/components/TimePicker/TimePickerView.tsx +216 -0
- package/src/components/TimePicker/TimePickerWheel.tsx +154 -0
- package/src/components/TimePicker/TimePickerWheel.web.tsx +217 -0
- package/src/components/TimePicker/index.ts +8 -0
- package/src/components/TimePickerInput/TimePickerInput.docs.mdx +135 -0
- package/src/components/TimePickerInput/TimePickerInput.figma.tsx +34 -0
- package/src/components/TimePickerInput/TimePickerInput.props.ts +55 -0
- package/src/components/TimePickerInput/TimePickerInput.stories.tsx +175 -0
- package/src/components/TimePickerInput/TimePickerInput.tsx +283 -0
- package/src/components/TimePickerInput/TimePickerInputDoneButton.tsx +42 -0
- package/src/components/TimePickerInput/TimePickerInputDoneButton.web.tsx +7 -0
- package/src/components/TimePickerInput/index.ts +2 -0
- package/src/components/index.ts +2 -0
- package/build/components/DatePicker/TimePicker.d.ts +0 -3
- package/build/components/DatePicker/TimePicker.js +0 -84
- package/build/components/DatePicker/time-picker/animated-math.d.ts +0 -4
- package/build/components/DatePicker/time-picker/animated-math.js +0 -19
- package/build/components/DatePicker/time-picker/period-native.d.ts +0 -6
- package/build/components/DatePicker/time-picker/period-native.js +0 -17
- package/build/components/DatePicker/time-picker/period-picker.d.ts +0 -6
- package/build/components/DatePicker/time-picker/period-picker.js +0 -10
- package/build/components/DatePicker/time-picker/period-web.d.ts +0 -6
- package/build/components/DatePicker/time-picker/period-web.js +0 -21
- package/build/components/DatePicker/time-picker/wheel-native.d.ts +0 -8
- package/build/components/DatePicker/time-picker/wheel-native.js +0 -19
- package/build/components/DatePicker/time-picker/wheel-picker/index.d.ts +0 -2
- package/build/components/DatePicker/time-picker/wheel-picker/index.js +0 -2
- package/build/components/DatePicker/time-picker/wheel-picker/wheel-picker-item.d.ts +0 -16
- package/build/components/DatePicker/time-picker/wheel-picker/wheel-picker-item.js +0 -97
- package/build/components/DatePicker/time-picker/wheel-picker/wheel-picker.d.ts +0 -21
- package/build/components/DatePicker/time-picker/wheel-picker/wheel-picker.js +0 -88
- package/build/components/DatePicker/time-picker/wheel-picker/wheel-picker.style.d.ts +0 -23
- package/build/components/DatePicker/time-picker/wheel-picker/wheel-picker.style.js +0 -21
- package/build/components/DatePicker/time-picker/wheel-web.js +0 -146
- package/build/components/DatePicker/time-picker/wheel.d.ts +0 -8
- package/build/components/DatePicker/time-picker/wheel.js +0 -10
- package/src/components/DatePicker/TimePicker.tsx +0 -141
- package/src/components/DatePicker/time-picker/animated-math.ts +0 -33
- package/src/components/DatePicker/time-picker/period-native.tsx +0 -34
- package/src/components/DatePicker/time-picker/period-picker.tsx +0 -16
- package/src/components/DatePicker/time-picker/period-web.tsx +0 -36
- package/src/components/DatePicker/time-picker/wheel-native.tsx +0 -37
- package/src/components/DatePicker/time-picker/wheel-picker/index.ts +0 -3
- package/src/components/DatePicker/time-picker/wheel-picker/wheel-picker-item.tsx +0 -132
- package/src/components/DatePicker/time-picker/wheel-picker/wheel-picker.style.ts +0 -22
- package/src/components/DatePicker/time-picker/wheel-picker/wheel-picker.tsx +0 -200
- package/src/components/DatePicker/time-picker/wheel-web.tsx +0 -180
- package/src/components/DatePicker/time-picker/wheel.tsx +0 -18
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import type { BottomSheetModalMethods } from '@gorhom/bottom-sheet/lib/typescript/types';
|
|
2
|
+
import { CloseSmallIcon, TimeSmallIcon } from '@utilitywarehouse/hearth-react-native-icons';
|
|
3
|
+
import dayjs from 'dayjs';
|
|
4
|
+
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
5
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
6
|
+
import { Keyboard, Platform, TextInputFocusEvent } from 'react-native';
|
|
7
|
+
import { StyleSheet } from 'react-native-unistyles';
|
|
8
|
+
import type { DateType } from '../DatePicker/DatePicker.props';
|
|
9
|
+
import { useFormFieldContext } from '../FormField';
|
|
10
|
+
import { Input, InputField, InputSlot } from '../Input';
|
|
11
|
+
import { TimePicker } from '../TimePicker';
|
|
12
|
+
import { UnstyledIconButton } from '../UnstyledIconButton';
|
|
13
|
+
import type TimePickerInputProps from './TimePickerInput.props';
|
|
14
|
+
import TimePickerInputDoneButton from './TimePickerInputDoneButton';
|
|
15
|
+
|
|
16
|
+
dayjs.extend(customParseFormat);
|
|
17
|
+
|
|
18
|
+
const DEFAULT_FORMAT_24 = 'HH:mm';
|
|
19
|
+
const DEFAULT_FORMAT_12 = 'hh:mm A';
|
|
20
|
+
|
|
21
|
+
const maskDefaultFormat = (value: string) => {
|
|
22
|
+
const digitsOnly = value.replace(/\D/g, '').slice(0, 4);
|
|
23
|
+
const hours = digitsOnly.slice(0, 2);
|
|
24
|
+
const minutes = digitsOnly.slice(2, 4);
|
|
25
|
+
|
|
26
|
+
return [hours, minutes].filter(Boolean).join(':');
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const TimePickerInput = ({
|
|
30
|
+
validationStatus = 'initial',
|
|
31
|
+
disabled,
|
|
32
|
+
focused,
|
|
33
|
+
readonly,
|
|
34
|
+
placeholder = '--:--',
|
|
35
|
+
inBottomSheet = false,
|
|
36
|
+
format,
|
|
37
|
+
openButtonLabel = 'Open time picker',
|
|
38
|
+
autoCloseOnSelect = true,
|
|
39
|
+
label,
|
|
40
|
+
labelVariant,
|
|
41
|
+
helperText,
|
|
42
|
+
helperIcon,
|
|
43
|
+
validText,
|
|
44
|
+
invalidText,
|
|
45
|
+
required = true,
|
|
46
|
+
onChange,
|
|
47
|
+
onChangeText,
|
|
48
|
+
onBlur,
|
|
49
|
+
onFocus,
|
|
50
|
+
value,
|
|
51
|
+
timePickerProps,
|
|
52
|
+
onClear,
|
|
53
|
+
...rest
|
|
54
|
+
}: TimePickerInputProps) => {
|
|
55
|
+
const formFieldContext = useFormFieldContext();
|
|
56
|
+
const isDisabled = formFieldContext?.disabled ?? disabled;
|
|
57
|
+
const isReadonly = formFieldContext?.readonly ?? readonly;
|
|
58
|
+
|
|
59
|
+
const pickerRef = useRef<BottomSheetModalMethods | null>(null);
|
|
60
|
+
const accessoryViewID = useMemo(() => {
|
|
61
|
+
if (Platform.OS !== 'ios') return undefined;
|
|
62
|
+
return `timepicker-input-${Math.random().toString(36).slice(2)}`;
|
|
63
|
+
}, []);
|
|
64
|
+
|
|
65
|
+
const use12Hours = timePickerProps?.use12Hours ?? false;
|
|
66
|
+
const resolvedFormat = useMemo(
|
|
67
|
+
() => format ?? (use12Hours ? DEFAULT_FORMAT_12 : DEFAULT_FORMAT_24),
|
|
68
|
+
[format, use12Hours]
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const formatTime = useCallback(
|
|
72
|
+
(dateValue?: DateType) => {
|
|
73
|
+
if (!dateValue) return '';
|
|
74
|
+
const parsed = dayjs(dateValue);
|
|
75
|
+
return parsed.isValid() ? parsed.format(resolvedFormat) : '';
|
|
76
|
+
},
|
|
77
|
+
[resolvedFormat]
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const isDefaultFormat = resolvedFormat === DEFAULT_FORMAT_24;
|
|
81
|
+
|
|
82
|
+
const [inputValue, setInputValue] = useState(() => formatTime(value));
|
|
83
|
+
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
setInputValue(formatTime(value));
|
|
86
|
+
}, [value, formatTime]);
|
|
87
|
+
|
|
88
|
+
const handleTextChange = useCallback(
|
|
89
|
+
(text: string) => {
|
|
90
|
+
const nextValue = isDefaultFormat ? maskDefaultFormat(text) : text;
|
|
91
|
+
|
|
92
|
+
setInputValue(nextValue);
|
|
93
|
+
onChangeText?.(nextValue);
|
|
94
|
+
|
|
95
|
+
if (!nextValue) {
|
|
96
|
+
onChange?.({ date: undefined });
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const parsed = dayjs(nextValue, resolvedFormat, true);
|
|
101
|
+
|
|
102
|
+
if (parsed.isValid()) {
|
|
103
|
+
onChange?.({ date: parsed.toDate() });
|
|
104
|
+
} else {
|
|
105
|
+
onChange?.({ date: undefined });
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
[isDefaultFormat, onChange, onChangeText, resolvedFormat]
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const handleClear = useCallback(() => {
|
|
112
|
+
setInputValue('');
|
|
113
|
+
onChange?.({ date: undefined });
|
|
114
|
+
onClear?.();
|
|
115
|
+
}, [onChange, onClear]);
|
|
116
|
+
|
|
117
|
+
const closeKeyboard = useCallback(() => {
|
|
118
|
+
Keyboard.dismiss();
|
|
119
|
+
}, []);
|
|
120
|
+
|
|
121
|
+
const openPicker = useCallback(() => {
|
|
122
|
+
if (isDisabled || isReadonly) return;
|
|
123
|
+
closeKeyboard();
|
|
124
|
+
pickerRef.current?.present();
|
|
125
|
+
}, [closeKeyboard, isDisabled, isReadonly]);
|
|
126
|
+
|
|
127
|
+
const selectedDate = useMemo(() => {
|
|
128
|
+
if (value) {
|
|
129
|
+
return value;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const parsed = dayjs(inputValue, resolvedFormat, true);
|
|
133
|
+
return parsed.isValid() ? parsed.toDate() : undefined;
|
|
134
|
+
}, [value, inputValue, resolvedFormat]);
|
|
135
|
+
|
|
136
|
+
const handlePickerChange = useCallback(
|
|
137
|
+
({ date }: { date: DateType }) => {
|
|
138
|
+
if (!date) {
|
|
139
|
+
handleClear();
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const formatted = formatTime(date);
|
|
144
|
+
setInputValue(formatted);
|
|
145
|
+
onChange?.({ date });
|
|
146
|
+
|
|
147
|
+
if (autoCloseOnSelect) {
|
|
148
|
+
pickerRef.current?.close?.();
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
[autoCloseOnSelect, formatTime, handleClear, onChange]
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
const handleBlur = useCallback(
|
|
155
|
+
(event: TextInputFocusEvent) => {
|
|
156
|
+
onBlur?.(event);
|
|
157
|
+
},
|
|
158
|
+
[onBlur]
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
const handleFocus = useCallback(
|
|
162
|
+
(event: TextInputFocusEvent) => {
|
|
163
|
+
onFocus?.(event);
|
|
164
|
+
},
|
|
165
|
+
[onFocus]
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
const { onCancel: pickerOnCancel, ...restTimePickerProps } = timePickerProps ?? {};
|
|
169
|
+
const {
|
|
170
|
+
style: inputStyle,
|
|
171
|
+
keyboardType: keyboardTypeProp,
|
|
172
|
+
inputMode: inputModeProp,
|
|
173
|
+
accessibilityHint: accessibilityHintProp,
|
|
174
|
+
accessibilityLabel: accessibilityLabelProp,
|
|
175
|
+
accessible: accessibleProp,
|
|
176
|
+
importantForAccessibility: importantForAccessibilityProp,
|
|
177
|
+
...textInputProps
|
|
178
|
+
} = rest;
|
|
179
|
+
|
|
180
|
+
const resolvedKeyboardType = keyboardTypeProp ?? (isDefaultFormat ? 'number-pad' : undefined);
|
|
181
|
+
const resolvedInputMode = inputModeProp ?? (isDefaultFormat ? 'numeric' : undefined);
|
|
182
|
+
const resolvedAccessibilityHint =
|
|
183
|
+
accessibilityHintProp ?? `Enter the time in ${resolvedFormat} format`;
|
|
184
|
+
const resolvedAccessibilityLabel = accessibilityLabelProp ?? 'Time input';
|
|
185
|
+
const resolvedAccessible = accessibleProp ?? true;
|
|
186
|
+
const resolvedImportantForAccessibility = importantForAccessibilityProp ?? 'yes';
|
|
187
|
+
|
|
188
|
+
const handleCancel = useCallback(() => {
|
|
189
|
+
pickerOnCancel?.();
|
|
190
|
+
pickerRef.current?.close?.();
|
|
191
|
+
}, [pickerOnCancel]);
|
|
192
|
+
|
|
193
|
+
const placeholderValue = placeholder;
|
|
194
|
+
|
|
195
|
+
return (
|
|
196
|
+
<>
|
|
197
|
+
<Input
|
|
198
|
+
validationStatus={validationStatus}
|
|
199
|
+
disabled={disabled}
|
|
200
|
+
readonly={readonly}
|
|
201
|
+
focused={focused}
|
|
202
|
+
label={label}
|
|
203
|
+
labelVariant={labelVariant}
|
|
204
|
+
helperText={helperText}
|
|
205
|
+
helperIcon={helperIcon}
|
|
206
|
+
validText={validText}
|
|
207
|
+
invalidText={invalidText}
|
|
208
|
+
required={required}
|
|
209
|
+
style={styles.wrap}
|
|
210
|
+
accessible={false}
|
|
211
|
+
>
|
|
212
|
+
<InputField
|
|
213
|
+
editable={!isReadonly && !isDisabled}
|
|
214
|
+
value={inputValue}
|
|
215
|
+
placeholder={placeholderValue}
|
|
216
|
+
onChangeText={handleTextChange}
|
|
217
|
+
onBlur={handleBlur}
|
|
218
|
+
onFocus={handleFocus}
|
|
219
|
+
inBottomSheet={inBottomSheet}
|
|
220
|
+
keyboardType={resolvedKeyboardType}
|
|
221
|
+
inputMode={resolvedInputMode}
|
|
222
|
+
accessibilityHint={resolvedAccessibilityHint}
|
|
223
|
+
aria-label="Time input"
|
|
224
|
+
accessibilityLabel={resolvedAccessibilityLabel}
|
|
225
|
+
accessible={resolvedAccessible}
|
|
226
|
+
accessibilityState={{
|
|
227
|
+
disabled: isDisabled || isReadonly,
|
|
228
|
+
}}
|
|
229
|
+
importantForAccessibility={resolvedImportantForAccessibility}
|
|
230
|
+
inputAccessoryViewID={Platform.OS === 'ios' ? accessoryViewID : undefined}
|
|
231
|
+
{...textInputProps}
|
|
232
|
+
style={[styles.input, inputStyle]}
|
|
233
|
+
/>
|
|
234
|
+
{!!inputValue && onClear && !isReadonly && !isDisabled && (
|
|
235
|
+
<InputSlot accessibilityElementsHidden={false}>
|
|
236
|
+
<UnstyledIconButton
|
|
237
|
+
accessibilityLabel="Clear time"
|
|
238
|
+
accessibilityHint="Removes the current time"
|
|
239
|
+
icon={CloseSmallIcon}
|
|
240
|
+
onPress={handleClear}
|
|
241
|
+
/>
|
|
242
|
+
</InputSlot>
|
|
243
|
+
)}
|
|
244
|
+
<InputSlot accessibilityElementsHidden={false}>
|
|
245
|
+
<UnstyledIconButton
|
|
246
|
+
accessibilityLabel={openButtonLabel}
|
|
247
|
+
accessibilityHint="Opens the time picker"
|
|
248
|
+
icon={TimeSmallIcon}
|
|
249
|
+
onPress={openPicker}
|
|
250
|
+
disabled={isDisabled || isReadonly}
|
|
251
|
+
/>
|
|
252
|
+
</InputSlot>
|
|
253
|
+
</Input>
|
|
254
|
+
<TimePicker
|
|
255
|
+
ref={pickerRef}
|
|
256
|
+
date={selectedDate}
|
|
257
|
+
onChange={handlePickerChange}
|
|
258
|
+
onCancel={handleCancel}
|
|
259
|
+
{...restTimePickerProps}
|
|
260
|
+
/>
|
|
261
|
+
{Platform.OS === 'ios' && accessoryViewID && (
|
|
262
|
+
<TimePickerInputDoneButton
|
|
263
|
+
accessoryViewID={accessoryViewID}
|
|
264
|
+
closeKeyboard={closeKeyboard}
|
|
265
|
+
/>
|
|
266
|
+
)}
|
|
267
|
+
</>
|
|
268
|
+
);
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
TimePickerInput.displayName = 'TimePickerInput';
|
|
272
|
+
|
|
273
|
+
const styles = StyleSheet.create(theme => ({
|
|
274
|
+
wrap: {
|
|
275
|
+
gap: theme.components.input.date.gap,
|
|
276
|
+
},
|
|
277
|
+
input: {
|
|
278
|
+
paddingLeft: 0,
|
|
279
|
+
paddingRight: 0,
|
|
280
|
+
},
|
|
281
|
+
}));
|
|
282
|
+
|
|
283
|
+
export default TimePickerInput;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { InputAccessoryView, View } from 'react-native';
|
|
2
|
+
import { StyleSheet } from 'react-native-unistyles';
|
|
3
|
+
import { Button } from '../Button';
|
|
4
|
+
|
|
5
|
+
const TimePickerInputDoneButton = ({
|
|
6
|
+
accessoryViewID,
|
|
7
|
+
closeKeyboard,
|
|
8
|
+
}: {
|
|
9
|
+
accessoryViewID: string;
|
|
10
|
+
closeKeyboard: () => void;
|
|
11
|
+
}) => {
|
|
12
|
+
return (
|
|
13
|
+
<InputAccessoryView nativeID={accessoryViewID}>
|
|
14
|
+
<View style={styles.accessory}>
|
|
15
|
+
<Button
|
|
16
|
+
accessibilityRole="button"
|
|
17
|
+
accessibilityLabel="Done"
|
|
18
|
+
onPress={closeKeyboard}
|
|
19
|
+
variant="ghost"
|
|
20
|
+
colorScheme="functional"
|
|
21
|
+
>
|
|
22
|
+
Done
|
|
23
|
+
</Button>
|
|
24
|
+
</View>
|
|
25
|
+
</InputAccessoryView>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const styles = StyleSheet.create(theme => ({
|
|
30
|
+
accessory: {
|
|
31
|
+
paddingHorizontal: 16,
|
|
32
|
+
paddingVertical: 2,
|
|
33
|
+
alignItems: 'flex-end',
|
|
34
|
+
backgroundColor: theme.color.surface.neutral.strong,
|
|
35
|
+
borderTopWidth: theme.borderWidth[1],
|
|
36
|
+
borderTopColor: theme.color.border.subtle,
|
|
37
|
+
},
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
TimePickerInputDoneButton.DisplayName = 'TimePickerInputDoneButton';
|
|
41
|
+
|
|
42
|
+
export default TimePickerInputDoneButton;
|
package/src/components/index.ts
CHANGED
|
@@ -53,6 +53,8 @@ export * from './Switch';
|
|
|
53
53
|
export * from './Tabs';
|
|
54
54
|
export * from './Textarea';
|
|
55
55
|
export * from './ThemedImage';
|
|
56
|
+
export * from './TimePicker';
|
|
57
|
+
export * from './TimePickerInput';
|
|
56
58
|
export * from './Toast';
|
|
57
59
|
export * from './ToggleButtonCard';
|
|
58
60
|
export * from './VerificationInput';
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import dayjs from 'dayjs';
|
|
3
|
-
import { useCallback, useMemo } from 'react';
|
|
4
|
-
import { ScrollView, View } from 'react-native';
|
|
5
|
-
import { StyleSheet } from 'react-native-unistyles';
|
|
6
|
-
import { BodyText } from '../BodyText';
|
|
7
|
-
import { useDatePickerContext } from './DatePicker.context';
|
|
8
|
-
import { CONTAINER_HEIGHT } from './enums';
|
|
9
|
-
import PeriodPicker from './time-picker/period-picker';
|
|
10
|
-
import Wheel from './time-picker/wheel';
|
|
11
|
-
import { formatNumber, getParsedDate } from './utils';
|
|
12
|
-
const createNumberList = (num, numerals, startFrom = 0) => {
|
|
13
|
-
return Array.from({ length: num }, (_, i) => ({
|
|
14
|
-
value: i + startFrom,
|
|
15
|
-
text: i + startFrom < 10
|
|
16
|
-
? `${formatNumber(0, numerals)}${formatNumber(i + startFrom, numerals)}`
|
|
17
|
-
: `${formatNumber(i + startFrom, numerals)}`,
|
|
18
|
-
}));
|
|
19
|
-
};
|
|
20
|
-
const TimePicker = () => {
|
|
21
|
-
const { currentDate, date, onSelectDate, timeZone, numerals = 'latn', use12Hours, } = useDatePickerContext();
|
|
22
|
-
const hours = useMemo(() => createNumberList(use12Hours ? 12 : 24, numerals, use12Hours ? 1 : 0), [numerals, use12Hours]);
|
|
23
|
-
const minutes = useMemo(() => createNumberList(60, numerals), [numerals]);
|
|
24
|
-
const { hour, hour12, minute, period } = getParsedDate(date || currentDate);
|
|
25
|
-
const handleChangeHour = useCallback((value) => {
|
|
26
|
-
let hour24 = value;
|
|
27
|
-
if (use12Hours) {
|
|
28
|
-
if (period === 'AM' && value === 12) {
|
|
29
|
-
hour24 = 0;
|
|
30
|
-
}
|
|
31
|
-
else if (period === 'PM' && value < 12) {
|
|
32
|
-
hour24 = value + 12;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
hour24 = value;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
const newDate = dayjs.tz(date, timeZone).hour(hour24).minute(minute);
|
|
39
|
-
onSelectDate(newDate);
|
|
40
|
-
}, [date, onSelectDate, timeZone, use12Hours, period, minute]);
|
|
41
|
-
const handleChangeMinute = useCallback((value) => {
|
|
42
|
-
const newDate = dayjs.tz(date, timeZone).minute(value);
|
|
43
|
-
onSelectDate(newDate);
|
|
44
|
-
}, [date, onSelectDate, timeZone]);
|
|
45
|
-
const handlePeriodChange = useCallback((newPeriod) => {
|
|
46
|
-
let newHour = hour12;
|
|
47
|
-
if (newPeriod === 'PM' && hour12 < 12) {
|
|
48
|
-
newHour = hour12 + 12;
|
|
49
|
-
}
|
|
50
|
-
else if (newPeriod === 'AM' && hour12 === 12) {
|
|
51
|
-
newHour = 0;
|
|
52
|
-
}
|
|
53
|
-
else if (newPeriod === 'AM' && hour >= 12) {
|
|
54
|
-
newHour = hour12;
|
|
55
|
-
}
|
|
56
|
-
const newDate = dayjs.tz(date || currentDate, timeZone).hour(newHour);
|
|
57
|
-
onSelectDate(newDate);
|
|
58
|
-
}, [date, currentDate, onSelectDate, timeZone, hour, hour12]);
|
|
59
|
-
return (_jsxs(ScrollView, { horizontal: true, scrollEnabled: false, contentContainerStyle: styles.container, testID: "time-selector", children: [_jsxs(View, { style: styles.timePickerContainer, children: [_jsx(View, { style: styles.wheelContainer, children: _jsx(Wheel, { value: use12Hours ? hour12 : hour, items: hours, setValue: handleChangeHour }) }), _jsx(BodyText, { style: styles.timeSeparator, children: ":" }), _jsx(View, { style: styles.wheelContainer, children: _jsx(Wheel, { value: minute, items: minutes, setValue: handleChangeMinute }) })] }), use12Hours && period ? (_jsx(View, { style: styles.periodContainer, children: _jsx(PeriodPicker, { value: period, setValue: handlePeriodChange }) })) : null] }));
|
|
60
|
-
};
|
|
61
|
-
const styles = StyleSheet.create({
|
|
62
|
-
container: {
|
|
63
|
-
flex: 1,
|
|
64
|
-
alignItems: 'center',
|
|
65
|
-
justifyContent: 'center',
|
|
66
|
-
},
|
|
67
|
-
wheelContainer: {
|
|
68
|
-
flex: 1,
|
|
69
|
-
},
|
|
70
|
-
timePickerContainer: {
|
|
71
|
-
alignItems: 'center',
|
|
72
|
-
justifyContent: 'center',
|
|
73
|
-
width: CONTAINER_HEIGHT / 2,
|
|
74
|
-
height: CONTAINER_HEIGHT / 2,
|
|
75
|
-
flexDirection: 'row',
|
|
76
|
-
},
|
|
77
|
-
timeSeparator: {
|
|
78
|
-
marginHorizontal: 5,
|
|
79
|
-
},
|
|
80
|
-
periodContainer: {
|
|
81
|
-
marginLeft: 10,
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
|
-
export default TimePicker;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Animated } from 'react-native';
|
|
2
|
-
const FACTORIAL_3 = 3 * 2;
|
|
3
|
-
const FACTORIAL_5 = 5 * 4 * FACTORIAL_3;
|
|
4
|
-
const FACTORIAL_7 = 7 * 6 * FACTORIAL_5;
|
|
5
|
-
function sin(animated) {
|
|
6
|
-
const normalized = normalize(animated);
|
|
7
|
-
const square = Animated.multiply(normalized, normalized);
|
|
8
|
-
const pow3 = Animated.multiply(normalized, square);
|
|
9
|
-
const pow5 = Animated.multiply(pow3, square);
|
|
10
|
-
const pow7 = Animated.multiply(pow5, square);
|
|
11
|
-
return Animated.add(Animated.add(normalized, Animated.multiply(pow3, -1 / FACTORIAL_3)), Animated.add(Animated.multiply(pow5, 1 / FACTORIAL_5), Animated.multiply(pow7, -1 / FACTORIAL_7)));
|
|
12
|
-
}
|
|
13
|
-
function normalize(animated) {
|
|
14
|
-
return Animated.add(Animated.modulo(Animated.add(animated, Math.PI), Math.PI * 2), -Math.PI).interpolate({
|
|
15
|
-
inputRange: [-Math.PI, -Math.PI / 2, Math.PI / 2, Math.PI],
|
|
16
|
-
outputRange: [0, -Math.PI / 2, Math.PI / 2, 0],
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
export { sin, normalize };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { memo } from 'react';
|
|
3
|
-
import WheelPicker from './wheel-picker';
|
|
4
|
-
const options = [
|
|
5
|
-
{ value: 'AM', text: 'AM' },
|
|
6
|
-
{ value: 'PM', text: 'PM' },
|
|
7
|
-
];
|
|
8
|
-
const PeriodNative = ({ value, setValue = () => { } }) => {
|
|
9
|
-
return (_jsx(WheelPicker, { value: value, options: options, onChange: setValue,
|
|
10
|
-
//containerStyle={defaultStyles.container}
|
|
11
|
-
itemHeight: 44, decelerationRate: "fast" }));
|
|
12
|
-
};
|
|
13
|
-
const customComparator = (prev, next) => {
|
|
14
|
-
const areEqual = prev.value === next.value && prev.setValue === next.setValue;
|
|
15
|
-
return areEqual;
|
|
16
|
-
};
|
|
17
|
-
export default memo(PeriodNative, customComparator);
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { memo } from 'react';
|
|
3
|
-
import { Platform } from 'react-native';
|
|
4
|
-
import PeriodNative from './period-native';
|
|
5
|
-
import PeriodWeb from './period-web';
|
|
6
|
-
const PeriodPicker = (props) => {
|
|
7
|
-
const Component = Platform.OS === 'web' ? PeriodWeb : PeriodNative;
|
|
8
|
-
return _jsx(Component, { ...props });
|
|
9
|
-
};
|
|
10
|
-
export default memo(PeriodPicker);
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { memo } from 'react';
|
|
3
|
-
import { Pressable, View } from 'react-native';
|
|
4
|
-
import { StyleSheet } from 'react-native-unistyles';
|
|
5
|
-
import { BodyText } from '../../BodyText';
|
|
6
|
-
const PeriodWeb = ({ value, setValue = () => { } }) => {
|
|
7
|
-
return (_jsx(Pressable, { onPress: () => setValue(value == 'AM' ? 'PM' : 'AM'), children: _jsx(View, { style: [styles.period], children: _jsx(BodyText, { children: value }) }) }));
|
|
8
|
-
};
|
|
9
|
-
const styles = StyleSheet.create({
|
|
10
|
-
period: {
|
|
11
|
-
width: 65,
|
|
12
|
-
height: 44,
|
|
13
|
-
alignItems: 'center',
|
|
14
|
-
justifyContent: 'center',
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
const customComparator = (prev, next) => {
|
|
18
|
-
const areEqual = prev.value === next.value && prev.setValue === next.setValue;
|
|
19
|
-
return areEqual;
|
|
20
|
-
};
|
|
21
|
-
export default memo(PeriodWeb, customComparator);
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { PickerOption } from '../DatePicker.props';
|
|
2
|
-
interface WheelProps {
|
|
3
|
-
value: number | string;
|
|
4
|
-
setValue?: (value: any) => void;
|
|
5
|
-
items: PickerOption[];
|
|
6
|
-
}
|
|
7
|
-
declare const _default: import("react").MemoExoticComponent<({ value, setValue, items }: WheelProps) => import("react/jsx-runtime").JSX.Element>;
|
|
8
|
-
export default _default;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { memo } from 'react';
|
|
3
|
-
import { Platform } from 'react-native';
|
|
4
|
-
import { StyleSheet } from 'react-native-unistyles';
|
|
5
|
-
import WheelPicker from './wheel-picker';
|
|
6
|
-
const WheelNative = ({ value, setValue = () => { }, items }) => {
|
|
7
|
-
return (_jsx(WheelPicker, { value: value, options: items, onChange: setValue, containerStyle: styles.container, itemHeight: 44, decelerationRate: "fast" }));
|
|
8
|
-
};
|
|
9
|
-
const styles = StyleSheet.create({
|
|
10
|
-
container: {
|
|
11
|
-
display: 'flex',
|
|
12
|
-
...Platform.select({
|
|
13
|
-
web: {
|
|
14
|
-
userSelect: 'none',
|
|
15
|
-
},
|
|
16
|
-
}),
|
|
17
|
-
},
|
|
18
|
-
});
|
|
19
|
-
export default memo(WheelNative);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Animated, StyleProp, ViewStyle } from 'react-native';
|
|
3
|
-
import { PickerOption } from '../../DatePicker.props';
|
|
4
|
-
interface ItemProps {
|
|
5
|
-
style: StyleProp<ViewStyle>;
|
|
6
|
-
option: PickerOption | null;
|
|
7
|
-
height: number;
|
|
8
|
-
index: number;
|
|
9
|
-
currentScrollIndex: Animated.AnimatedAddition<number>;
|
|
10
|
-
visibleRest: number;
|
|
11
|
-
rotationFunction: (x: number) => number;
|
|
12
|
-
opacityFunction: (x: number) => number;
|
|
13
|
-
scaleFunction: (x: number) => number;
|
|
14
|
-
}
|
|
15
|
-
declare const _default: React.NamedExoticComponent<ItemProps>;
|
|
16
|
-
export default _default;
|