@utilitywarehouse/hearth-react-native 0.23.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.
Files changed (107) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.turbo/turbo-lint.log +13 -13
  3. package/CHANGELOG.md +77 -0
  4. package/build/components/DatePicker/DatePickerCalendar.js +4 -9
  5. package/build/components/Modal/Modal.js +5 -4
  6. package/build/components/Modal/Modal.props.d.ts +10 -4
  7. package/build/components/ProgressBar/ProgressBar.d.ts +6 -0
  8. package/build/components/ProgressBar/ProgressBar.js +35 -0
  9. package/build/components/ProgressBar/ProgressBar.props.d.ts +60 -0
  10. package/build/components/ProgressBar/ProgressBar.props.js +1 -0
  11. package/build/components/ProgressBar/ProgressBarCircular.d.ts +6 -0
  12. package/build/components/ProgressBar/ProgressBarCircular.js +115 -0
  13. package/build/components/ProgressBar/ProgressBarLinear.d.ts +6 -0
  14. package/build/components/ProgressBar/ProgressBarLinear.js +79 -0
  15. package/build/components/ProgressBar/index.d.ts +2 -0
  16. package/build/components/ProgressBar/index.js +1 -0
  17. package/build/components/TimePicker/TimePicker.d.ts +6 -0
  18. package/build/components/TimePicker/TimePicker.js +78 -0
  19. package/build/components/TimePicker/TimePicker.props.d.ts +45 -0
  20. package/build/components/TimePicker/TimePicker.props.js +1 -0
  21. package/build/components/TimePicker/TimePickerView.d.ts +12 -0
  22. package/build/components/TimePicker/TimePickerView.js +130 -0
  23. package/build/components/TimePicker/TimePickerWheel.d.ts +8 -0
  24. package/build/components/TimePicker/TimePickerWheel.js +78 -0
  25. package/build/components/{DatePicker/time-picker/wheel-web.d.ts → TimePicker/TimePickerWheel.web.d.ts} +4 -4
  26. package/build/components/TimePicker/TimePickerWheel.web.js +122 -0
  27. package/build/components/TimePicker/index.d.ts +6 -0
  28. package/build/components/TimePicker/index.js +3 -0
  29. package/build/components/TimePickerInput/TimePickerInput.d.ts +6 -0
  30. package/build/components/TimePickerInput/TimePickerInput.js +127 -0
  31. package/build/components/TimePickerInput/TimePickerInput.props.d.ts +52 -0
  32. package/build/components/TimePickerInput/TimePickerInput.props.js +1 -0
  33. package/build/components/TimePickerInput/TimePickerInputDoneButton.d.ts +8 -0
  34. package/build/components/TimePickerInput/TimePickerInputDoneButton.js +19 -0
  35. package/build/components/TimePickerInput/TimePickerInputDoneButton.web.d.ts +5 -0
  36. package/build/components/TimePickerInput/TimePickerInputDoneButton.web.js +5 -0
  37. package/build/components/TimePickerInput/index.d.ts +2 -0
  38. package/build/components/TimePickerInput/index.js +1 -0
  39. package/build/components/index.d.ts +3 -0
  40. package/build/components/index.js +3 -0
  41. package/docs/components/AllComponents.web.tsx +36 -0
  42. package/package.json +2 -1
  43. package/src/components/DatePicker/DatePickerCalendar.tsx +30 -13
  44. package/src/components/Modal/Modal.props.ts +13 -4
  45. package/src/components/Modal/Modal.stories.tsx +1 -1
  46. package/src/components/Modal/Modal.tsx +28 -11
  47. package/src/components/ProgressBar/ProgressBar.docs.mdx +90 -0
  48. package/src/components/ProgressBar/ProgressBar.figma.tsx +79 -0
  49. package/src/components/ProgressBar/ProgressBar.props.ts +60 -0
  50. package/src/components/ProgressBar/ProgressBar.stories.tsx +117 -0
  51. package/src/components/ProgressBar/ProgressBar.tsx +74 -0
  52. package/src/components/ProgressBar/ProgressBarCircular.tsx +181 -0
  53. package/src/components/ProgressBar/ProgressBarLinear.tsx +127 -0
  54. package/src/components/ProgressBar/index.ts +7 -0
  55. package/src/components/TimePicker/TimePicker.docs.mdx +84 -0
  56. package/src/components/TimePicker/TimePicker.figma.tsx +29 -0
  57. package/src/components/TimePicker/TimePicker.props.ts +45 -0
  58. package/src/components/TimePicker/TimePicker.stories.tsx +85 -0
  59. package/src/components/TimePicker/TimePicker.tsx +150 -0
  60. package/src/components/TimePicker/TimePickerView.tsx +216 -0
  61. package/src/components/TimePicker/TimePickerWheel.tsx +154 -0
  62. package/src/components/TimePicker/TimePickerWheel.web.tsx +217 -0
  63. package/src/components/TimePicker/index.ts +8 -0
  64. package/src/components/TimePickerInput/TimePickerInput.docs.mdx +135 -0
  65. package/src/components/TimePickerInput/TimePickerInput.figma.tsx +34 -0
  66. package/src/components/TimePickerInput/TimePickerInput.props.ts +55 -0
  67. package/src/components/TimePickerInput/TimePickerInput.stories.tsx +175 -0
  68. package/src/components/TimePickerInput/TimePickerInput.tsx +283 -0
  69. package/src/components/TimePickerInput/TimePickerInputDoneButton.tsx +42 -0
  70. package/src/components/TimePickerInput/TimePickerInputDoneButton.web.tsx +7 -0
  71. package/src/components/TimePickerInput/index.ts +2 -0
  72. package/src/components/index.ts +3 -0
  73. package/build/components/DatePicker/TimePicker.d.ts +0 -3
  74. package/build/components/DatePicker/TimePicker.js +0 -84
  75. package/build/components/DatePicker/time-picker/animated-math.d.ts +0 -4
  76. package/build/components/DatePicker/time-picker/animated-math.js +0 -19
  77. package/build/components/DatePicker/time-picker/period-native.d.ts +0 -6
  78. package/build/components/DatePicker/time-picker/period-native.js +0 -17
  79. package/build/components/DatePicker/time-picker/period-picker.d.ts +0 -6
  80. package/build/components/DatePicker/time-picker/period-picker.js +0 -10
  81. package/build/components/DatePicker/time-picker/period-web.d.ts +0 -6
  82. package/build/components/DatePicker/time-picker/period-web.js +0 -21
  83. package/build/components/DatePicker/time-picker/wheel-native.d.ts +0 -8
  84. package/build/components/DatePicker/time-picker/wheel-native.js +0 -19
  85. package/build/components/DatePicker/time-picker/wheel-picker/index.d.ts +0 -2
  86. package/build/components/DatePicker/time-picker/wheel-picker/index.js +0 -2
  87. package/build/components/DatePicker/time-picker/wheel-picker/wheel-picker-item.d.ts +0 -16
  88. package/build/components/DatePicker/time-picker/wheel-picker/wheel-picker-item.js +0 -97
  89. package/build/components/DatePicker/time-picker/wheel-picker/wheel-picker.d.ts +0 -21
  90. package/build/components/DatePicker/time-picker/wheel-picker/wheel-picker.js +0 -88
  91. package/build/components/DatePicker/time-picker/wheel-picker/wheel-picker.style.d.ts +0 -23
  92. package/build/components/DatePicker/time-picker/wheel-picker/wheel-picker.style.js +0 -21
  93. package/build/components/DatePicker/time-picker/wheel-web.js +0 -146
  94. package/build/components/DatePicker/time-picker/wheel.d.ts +0 -8
  95. package/build/components/DatePicker/time-picker/wheel.js +0 -10
  96. package/src/components/DatePicker/TimePicker.tsx +0 -141
  97. package/src/components/DatePicker/time-picker/animated-math.ts +0 -33
  98. package/src/components/DatePicker/time-picker/period-native.tsx +0 -34
  99. package/src/components/DatePicker/time-picker/period-picker.tsx +0 -16
  100. package/src/components/DatePicker/time-picker/period-web.tsx +0 -36
  101. package/src/components/DatePicker/time-picker/wheel-native.tsx +0 -37
  102. package/src/components/DatePicker/time-picker/wheel-picker/index.ts +0 -3
  103. package/src/components/DatePicker/time-picker/wheel-picker/wheel-picker-item.tsx +0 -132
  104. package/src/components/DatePicker/time-picker/wheel-picker/wheel-picker.style.ts +0 -22
  105. package/src/components/DatePicker/time-picker/wheel-picker/wheel-picker.tsx +0 -200
  106. package/src/components/DatePicker/time-picker/wheel-web.tsx +0 -180
  107. package/src/components/DatePicker/time-picker/wheel.tsx +0 -18
@@ -1,97 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import React from 'react';
3
- import { Animated } from 'react-native';
4
- import { BodyText } from '../../../BodyText';
5
- import styles from './wheel-picker.style';
6
- const WheelPickerItem = ({ style, height, option, index, visibleRest, currentScrollIndex, opacityFunction, rotationFunction, scaleFunction, }) => {
7
- const relativeScrollIndex = Animated.subtract(index, currentScrollIndex);
8
- const translateY = relativeScrollIndex.interpolate({
9
- inputRange: (() => {
10
- const range = [0];
11
- for (let i = 1; i <= visibleRest + 1; i++) {
12
- range.unshift(-i);
13
- range.push(i);
14
- }
15
- return range;
16
- })(),
17
- outputRange: (() => {
18
- const range = [0];
19
- for (let i = 1; i <= visibleRest + 1; i++) {
20
- let y = (height / 2) * (1 - Math.sin(Math.PI / 2 - rotationFunction(i)));
21
- for (let j = 1; j < i; j++) {
22
- y += height * (1 - Math.sin(Math.PI / 2 - rotationFunction(j)));
23
- }
24
- range.unshift(y);
25
- range.push(-y);
26
- }
27
- return range;
28
- })(),
29
- });
30
- const opacity = relativeScrollIndex.interpolate({
31
- inputRange: (() => {
32
- const range = [0];
33
- for (let i = 1; i <= visibleRest + 1; i++) {
34
- range.unshift(-i);
35
- range.push(i);
36
- }
37
- return range;
38
- })(),
39
- outputRange: (() => {
40
- const range = [1];
41
- for (let x = 1; x <= visibleRest + 1; x++) {
42
- const y = opacityFunction(x);
43
- range.unshift(y);
44
- range.push(y);
45
- }
46
- return range;
47
- })(),
48
- });
49
- const scale = relativeScrollIndex.interpolate({
50
- inputRange: (() => {
51
- const range = [0];
52
- for (let i = 1; i <= visibleRest + 1; i++) {
53
- range.unshift(-i);
54
- range.push(i);
55
- }
56
- return range;
57
- })(),
58
- outputRange: (() => {
59
- const range = [1.0];
60
- for (let x = 1; x <= visibleRest + 1; x++) {
61
- const y = scaleFunction(x);
62
- range.unshift(y);
63
- range.push(y);
64
- }
65
- return range;
66
- })(),
67
- });
68
- const rotateX = relativeScrollIndex.interpolate({
69
- inputRange: (() => {
70
- const range = [0];
71
- for (let i = 1; i <= visibleRest + 1; i++) {
72
- range.unshift(-i);
73
- range.push(i);
74
- }
75
- return range;
76
- })(),
77
- outputRange: (() => {
78
- const range = ['0deg'];
79
- for (let x = 1; x <= visibleRest + 1; x++) {
80
- const y = rotationFunction(x);
81
- range.unshift(`${y}deg`);
82
- range.push(`${y}deg`);
83
- }
84
- return range;
85
- })(),
86
- });
87
- return (_jsx(Animated.View, { style: [
88
- styles.option,
89
- style,
90
- {
91
- height,
92
- opacity,
93
- transform: [{ translateY }, { rotateX }, { scale }],
94
- },
95
- ], children: _jsx(BodyText, { children: option?.text }) }));
96
- };
97
- export default React.memo(WheelPickerItem);
@@ -1,21 +0,0 @@
1
- import React from 'react';
2
- import { FlatListProps, StyleProp, ViewProps, ViewStyle } from 'react-native';
3
- import { PickerOption } from '../../DatePicker.props';
4
- interface Props {
5
- value: number | string;
6
- options: PickerOption[];
7
- onChange: (index: number | string) => void;
8
- selectedIndicatorStyle?: StyleProp<ViewStyle>;
9
- itemStyle?: ViewStyle;
10
- itemHeight?: number;
11
- containerStyle?: ViewStyle;
12
- containerProps?: Omit<ViewProps, 'style'>;
13
- scaleFunction?: (x: number) => number;
14
- rotationFunction?: (x: number) => number;
15
- opacityFunction?: (x: number) => number;
16
- visibleRest?: number;
17
- decelerationRate?: 'normal' | 'fast' | number;
18
- flatListProps?: Omit<FlatListProps<PickerOption | null>, 'data' | 'renderItem'>;
19
- }
20
- declare const _default: React.NamedExoticComponent<Props>;
21
- export default _default;
@@ -1,88 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { memo, useEffect, useMemo, useRef, useState } from 'react';
3
- import { Animated, Platform, View, } from 'react-native';
4
- import WheelPickerItem from './wheel-picker-item';
5
- import styles from './wheel-picker.style';
6
- const WheelPicker = ({ value, options, onChange, selectedIndicatorStyle = {}, containerStyle = {}, itemStyle = {}, itemHeight = 40, scaleFunction = (x) => 1.0 ** x, rotationFunction = (x) => 1 - Math.pow(1 / 2, x), opacityFunction = (x) => Math.pow(1 / 3, x), visibleRest = 2, decelerationRate = 'normal', containerProps = {}, flatListProps = {}, }) => {
7
- const momentumStarted = useRef(false);
8
- const selectedIndex = options.findIndex(item => item.value === value);
9
- const flatListRef = useRef(null);
10
- const [scrollY] = useState(new Animated.Value(selectedIndex * itemHeight));
11
- const containerHeight = (1 + visibleRest * 2) * itemHeight;
12
- const paddedOptions = useMemo(() => {
13
- const array = [...options];
14
- for (let i = 0; i < visibleRest; i++) {
15
- array.unshift(null);
16
- array.push(null);
17
- }
18
- return array;
19
- }, [options, visibleRest]);
20
- const offsets = useMemo(() => [...Array(paddedOptions.length)].map((_, i) => i * itemHeight), [paddedOptions, itemHeight]);
21
- const currentScrollIndex = useMemo(() => Animated.add(Animated.divide(scrollY, itemHeight), visibleRest), [visibleRest, scrollY, itemHeight]);
22
- const handleScrollEnd = (event) => {
23
- const offsetY = Math.min(itemHeight * (options.length - 1), Math.max(event.nativeEvent.contentOffset.y, 0));
24
- let index = Math.floor(offsetY / itemHeight);
25
- const remainder = offsetY % itemHeight;
26
- if (remainder > itemHeight / 2) {
27
- index++;
28
- }
29
- if (index !== selectedIndex) {
30
- onChange(options[index]?.value || 0);
31
- }
32
- };
33
- const handleMomentumScrollBegin = () => {
34
- momentumStarted.current = true;
35
- };
36
- const handleMomentumScrollEnd = (event) => {
37
- momentumStarted.current = false;
38
- handleScrollEnd(event);
39
- };
40
- const handleScrollEndDrag = (event) => {
41
- // Capture the offset value immediately
42
- const offsetY = event.nativeEvent.contentOffset?.y;
43
- // We'll start a short timer to see if momentum scroll begins
44
- setTimeout(() => {
45
- // If momentum scroll hasn't started within the timeout,
46
- // then it was a slow scroll that won't trigger momentum
47
- if (!momentumStarted.current && offsetY !== undefined) {
48
- // Create a synthetic event with just the data we need
49
- const syntheticEvent = {
50
- nativeEvent: {
51
- contentOffset: { y: offsetY },
52
- },
53
- };
54
- handleScrollEnd(syntheticEvent);
55
- }
56
- }, 50);
57
- };
58
- useEffect(() => {
59
- if (selectedIndex < 0 || selectedIndex >= options.length) {
60
- throw new Error(`Selected index ${selectedIndex} is out of bounds [0, ${options.length - 1}]`);
61
- }
62
- }, [selectedIndex, options]);
63
- /**
64
- * If selectedIndex is changed from outside (not via onChange) we need to scroll to the specified index.
65
- * This ensures that what the user sees as selected in the picker always corresponds to the value state.
66
- */
67
- useEffect(() => {
68
- flatListRef.current?.scrollToIndex({
69
- index: selectedIndex,
70
- animated: Platform.OS === 'ios',
71
- });
72
- }, [selectedIndex, itemHeight]);
73
- return (_jsxs(View, { style: [styles.container, { height: containerHeight }, containerStyle], ...containerProps, children: [_jsx(View, { style: [
74
- styles.selectedIndicator,
75
- selectedIndicatorStyle,
76
- {
77
- transform: [{ translateY: -itemHeight / 2 }],
78
- height: itemHeight,
79
- },
80
- ] }), _jsx(Animated.FlatList, { ...flatListProps, ref: flatListRef, nestedScrollEnabled: true, style: styles.scrollView, showsVerticalScrollIndicator: false, onScroll: Animated.event([{ nativeEvent: { contentOffset: { y: scrollY } } }], {
81
- useNativeDriver: true,
82
- }), onScrollEndDrag: handleScrollEndDrag, onMomentumScrollBegin: handleMomentumScrollBegin, onMomentumScrollEnd: handleMomentumScrollEnd, snapToOffsets: offsets, decelerationRate: decelerationRate, initialScrollIndex: selectedIndex, getItemLayout: (_, index) => ({
83
- length: itemHeight,
84
- offset: itemHeight * index,
85
- index,
86
- }), data: paddedOptions, keyExtractor: (item, index) => item ? `${item.value}-${item.text}-${index}` : `null-${index}`, renderItem: ({ item: option, index }) => (_jsx(WheelPickerItem, { index: index, option: option, style: itemStyle, height: itemHeight, currentScrollIndex: currentScrollIndex, scaleFunction: scaleFunction, rotationFunction: rotationFunction, opacityFunction: opacityFunction, visibleRest: visibleRest }, `option-${index}`)) })] }));
87
- };
88
- export default memo(WheelPicker);
@@ -1,23 +0,0 @@
1
- declare const _default: {
2
- container: {
3
- position: "relative";
4
- };
5
- selectedIndicator: {
6
- position: "absolute";
7
- width: "100%";
8
- top: "50%";
9
- };
10
- scrollView: {
11
- overflow: "hidden";
12
- flex: number;
13
- };
14
- option: {
15
- alignItems: "center";
16
- justifyContent: "center";
17
- paddingHorizontal: number;
18
- zIndex: number;
19
- };
20
- } & {
21
- useVariants: (variants: never) => void;
22
- };
23
- export default _default;
@@ -1,21 +0,0 @@
1
- import { StyleSheet } from 'react-native-unistyles';
2
- export default StyleSheet.create({
3
- container: {
4
- position: 'relative',
5
- },
6
- selectedIndicator: {
7
- position: 'absolute',
8
- width: '100%',
9
- top: '50%',
10
- },
11
- scrollView: {
12
- overflow: 'hidden',
13
- flex: 1,
14
- },
15
- option: {
16
- alignItems: 'center',
17
- justifyContent: 'center',
18
- paddingHorizontal: 16,
19
- zIndex: 100,
20
- },
21
- });
@@ -1,146 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { memo, useMemo, useRef } from 'react';
3
- import { Animated, PanResponder, Platform, View } from 'react-native';
4
- import { StyleSheet } from 'react-native-unistyles';
5
- import { isEqual } from '../../../utils';
6
- import { BodyText } from '../../BodyText';
7
- import { CONTAINER_HEIGHT } from '../enums';
8
- import { sin } from './animated-math';
9
- const ITEM_HEIGHT = 44;
10
- const WheelWeb = ({ value, setValue = () => { }, items }) => {
11
- const displayCount = 5;
12
- const translateY = useRef(new Animated.Value(0)).current;
13
- const renderCount = displayCount * 2 < items.length ? displayCount * 8 : displayCount * 2 - 1;
14
- const circular = items.length >= displayCount;
15
- const height = 140;
16
- const radius = height / 2;
17
- const valueIndex = useMemo(() => {
18
- return Math.max(0, items.findIndex(item => item.value === value));
19
- }, [items, value]);
20
- const panResponder = useMemo(() => {
21
- return PanResponder.create({
22
- onMoveShouldSetPanResponder: () => true,
23
- onStartShouldSetPanResponderCapture: () => true,
24
- onPanResponderGrant: () => {
25
- translateY.setValue(0);
26
- },
27
- onPanResponderMove: (evt, gestureState) => {
28
- translateY.setValue(gestureState.dy);
29
- evt.stopPropagation();
30
- },
31
- onPanResponderRelease: (_, gestureState) => {
32
- translateY.extractOffset();
33
- let newValueIndex = valueIndex - Math.round(gestureState.dy / ((radius * 2) / displayCount));
34
- if (circular) {
35
- newValueIndex = (newValueIndex + items.length) % items.length;
36
- }
37
- else {
38
- if (newValueIndex < 0) {
39
- newValueIndex = 0;
40
- }
41
- else if (newValueIndex >= items.length) {
42
- newValueIndex = items.length - 1;
43
- }
44
- }
45
- const newValue = items[newValueIndex];
46
- if (newValue?.value === value) {
47
- translateY.setOffset(0);
48
- translateY.setValue(0);
49
- }
50
- else if (newValue?.value) {
51
- setValue(newValue.value);
52
- }
53
- else if (items[0]?.value) {
54
- setValue(items[0].value);
55
- }
56
- },
57
- });
58
- }, [circular, displayCount, radius, setValue, value, valueIndex, items, translateY]);
59
- const displayValues = useMemo(() => {
60
- const centerIndex = Math.floor(renderCount / 2);
61
- return Array.from({ length: renderCount }, (_, index) => {
62
- let targetIndex = valueIndex + index - centerIndex;
63
- if (circular) {
64
- targetIndex = ((targetIndex % items.length) + items.length) % items.length;
65
- }
66
- else {
67
- targetIndex = Math.max(0, Math.min(targetIndex, items.length - 1));
68
- }
69
- return items[targetIndex] || items[0];
70
- });
71
- }, [renderCount, valueIndex, items, circular]);
72
- const animatedAngles = useMemo(() => {
73
- //translateY.setValue(0);
74
- translateY.setOffset(0);
75
- const currentIndex = displayValues.findIndex(item => item?.value === value);
76
- return displayValues && displayValues.length > 0
77
- ? displayValues.map((_, index) => translateY
78
- .interpolate({
79
- inputRange: [-radius, radius],
80
- outputRange: [
81
- -radius + ((radius * 2) / displayCount) * (index - currentIndex),
82
- radius + ((radius * 2) / displayCount) * (index - currentIndex),
83
- ],
84
- extrapolate: 'extend',
85
- })
86
- .interpolate({
87
- inputRange: [-radius, radius],
88
- outputRange: [-Math.PI / 2, Math.PI / 2],
89
- extrapolate: 'clamp',
90
- }))
91
- : [];
92
- }, [displayValues, radius, value, displayCount, translateY]);
93
- return (_jsxs(View, { style: [styles.container], ...panResponder.panHandlers, children: [_jsx(View, { style: [
94
- styles.selectedIndicator,
95
- {
96
- transform: [{ translateY: -ITEM_HEIGHT / 2 }],
97
- height: ITEM_HEIGHT,
98
- },
99
- ] }), displayValues?.map((displayValue, index) => {
100
- const animatedAngle = animatedAngles[index];
101
- return (_jsx(Animated.View, { style: {
102
- position: 'absolute',
103
- height: ITEM_HEIGHT - 10,
104
- transform: animatedAngle
105
- ? [
106
- {
107
- translateY: Animated.multiply(radius, sin(animatedAngle)),
108
- },
109
- {
110
- rotateX: animatedAngle.interpolate({
111
- inputRange: [-Math.PI / 2, Math.PI / 2],
112
- outputRange: ['-89deg', '89deg'],
113
- extrapolate: 'clamp',
114
- }),
115
- },
116
- ]
117
- : [],
118
- opacity: displayValue?.value !== value ? 0.3 : 1,
119
- }, children: _jsx(BodyText, { children: displayValue?.text }) }, `${displayValue?.text}-${index}`));
120
- })] }));
121
- };
122
- const styles = StyleSheet.create({
123
- container: {
124
- minWidth: 30,
125
- overflow: 'hidden',
126
- alignItems: 'center',
127
- justifyContent: 'center',
128
- height: CONTAINER_HEIGHT / 2,
129
- ...Platform.select({
130
- web: {
131
- cursor: 'pointer',
132
- userSelect: 'none',
133
- },
134
- }),
135
- },
136
- selectedIndicator: {
137
- position: 'absolute',
138
- width: '100%',
139
- top: '50%',
140
- },
141
- });
142
- const customComparator = (prev, next) => {
143
- const areEqual = prev.value === next.value && prev.setValue === next.setValue && isEqual(prev.items, next.items);
144
- return areEqual;
145
- };
146
- export default memo(WheelWeb, customComparator);
@@ -1,8 +0,0 @@
1
- import { PickerOption } from '../DatePicker.props';
2
- type WheelProps = {
3
- value: number | string;
4
- setValue?: (value: any) => void;
5
- items: PickerOption[];
6
- };
7
- declare const _default: import("react").MemoExoticComponent<(props: WheelProps) => import("react/jsx-runtime").JSX.Element>;
8
- export default _default;
@@ -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 WheelNative from './wheel-native';
5
- import WheelWeb from './wheel-web';
6
- const Wheel = (props) => {
7
- const Component = Platform.OS === 'web' ? WheelWeb : WheelNative;
8
- return _jsx(Component, { ...props });
9
- };
10
- export default memo(Wheel);
@@ -1,141 +0,0 @@
1
- import dayjs from 'dayjs';
2
- import { useCallback, useMemo } from 'react';
3
- import { ScrollView, View } from 'react-native';
4
- import { StyleSheet } from 'react-native-unistyles';
5
- import { BodyText } from '../BodyText';
6
- import { useDatePickerContext } from './DatePicker.context';
7
- import { Numerals, PickerOption } from './DatePicker.props';
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
-
13
- export type Period = 'AM' | 'PM';
14
-
15
- const createNumberList = (
16
- num: number,
17
- numerals: Numerals,
18
- startFrom: number = 0
19
- ): PickerOption[] => {
20
- return Array.from({ length: num }, (_, i) => ({
21
- value: i + startFrom,
22
- text:
23
- i + startFrom < 10
24
- ? `${formatNumber(0, numerals)}${formatNumber(i + startFrom, numerals)}`
25
- : `${formatNumber(i + startFrom, numerals)}`,
26
- }));
27
- };
28
-
29
- const TimePicker = () => {
30
- const {
31
- currentDate,
32
- date,
33
- onSelectDate,
34
- timeZone,
35
- numerals = 'latn',
36
- use12Hours,
37
- } = useDatePickerContext();
38
-
39
- const hours = useMemo(
40
- () => createNumberList(use12Hours ? 12 : 24, numerals, use12Hours ? 1 : 0),
41
- [numerals, use12Hours]
42
- );
43
-
44
- const minutes = useMemo(() => createNumberList(60, numerals), [numerals]);
45
-
46
- const { hour, hour12, minute, period } = getParsedDate(date || currentDate);
47
-
48
- const handleChangeHour = useCallback(
49
- (value: number) => {
50
- let hour24 = value;
51
-
52
- if (use12Hours) {
53
- if (period === 'AM' && value === 12) {
54
- hour24 = 0;
55
- } else if (period === 'PM' && value < 12) {
56
- hour24 = value + 12;
57
- } else {
58
- hour24 = value;
59
- }
60
- }
61
- const newDate = dayjs.tz(date, timeZone).hour(hour24).minute(minute);
62
- onSelectDate(newDate);
63
- },
64
- [date, onSelectDate, timeZone, use12Hours, period, minute]
65
- );
66
-
67
- const handleChangeMinute = useCallback(
68
- (value: number) => {
69
- const newDate = dayjs.tz(date, timeZone).minute(value);
70
- onSelectDate(newDate);
71
- },
72
- [date, onSelectDate, timeZone]
73
- );
74
-
75
- const handlePeriodChange = useCallback(
76
- (newPeriod: Period) => {
77
- let newHour = hour12;
78
- if (newPeriod === 'PM' && hour12 < 12) {
79
- newHour = hour12 + 12;
80
- } else if (newPeriod === 'AM' && hour12 === 12) {
81
- newHour = 0;
82
- } else if (newPeriod === 'AM' && hour >= 12) {
83
- newHour = hour12;
84
- }
85
-
86
- const newDate = dayjs.tz(date || currentDate, timeZone).hour(newHour);
87
- onSelectDate(newDate);
88
- },
89
- [date, currentDate, onSelectDate, timeZone, hour, hour12]
90
- );
91
-
92
- return (
93
- <ScrollView
94
- horizontal={true}
95
- scrollEnabled={false}
96
- contentContainerStyle={styles.container}
97
- testID="time-selector"
98
- >
99
- <View style={styles.timePickerContainer}>
100
- <View style={styles.wheelContainer}>
101
- <Wheel value={use12Hours ? hour12 : hour} items={hours} setValue={handleChangeHour} />
102
- </View>
103
- <BodyText style={styles.timeSeparator}>:</BodyText>
104
- <View style={styles.wheelContainer}>
105
- <Wheel value={minute} items={minutes} setValue={handleChangeMinute} />
106
- </View>
107
- </View>
108
- {use12Hours && period ? (
109
- <View style={styles.periodContainer}>
110
- <PeriodPicker value={period} setValue={handlePeriodChange} />
111
- </View>
112
- ) : null}
113
- </ScrollView>
114
- );
115
- };
116
-
117
- const styles = StyleSheet.create({
118
- container: {
119
- flex: 1,
120
- alignItems: 'center',
121
- justifyContent: 'center',
122
- },
123
- wheelContainer: {
124
- flex: 1,
125
- },
126
- timePickerContainer: {
127
- alignItems: 'center',
128
- justifyContent: 'center',
129
- width: CONTAINER_HEIGHT / 2,
130
- height: CONTAINER_HEIGHT / 2,
131
- flexDirection: 'row',
132
- },
133
- timeSeparator: {
134
- marginHorizontal: 5,
135
- },
136
- periodContainer: {
137
- marginLeft: 10,
138
- },
139
- });
140
-
141
- export default TimePicker;
@@ -1,33 +0,0 @@
1
- import { Animated } from 'react-native';
2
-
3
- const FACTORIAL_3 = 3 * 2;
4
- const FACTORIAL_5 = 5 * 4 * FACTORIAL_3;
5
- const FACTORIAL_7 = 7 * 6 * FACTORIAL_5;
6
-
7
- function sin(animated: Animated.Animated) {
8
- const normalized = normalize(animated);
9
- const square = Animated.multiply(normalized, normalized);
10
- const pow3 = Animated.multiply(normalized, square);
11
- const pow5 = Animated.multiply(pow3, square);
12
- const pow7 = Animated.multiply(pow5, square);
13
-
14
- return Animated.add(
15
- Animated.add(normalized, Animated.multiply(pow3, -1 / FACTORIAL_3)),
16
- Animated.add(
17
- Animated.multiply(pow5, 1 / FACTORIAL_5),
18
- Animated.multiply(pow7, -1 / FACTORIAL_7)
19
- )
20
- );
21
- }
22
-
23
- function normalize(animated: Animated.Animated): Animated.Animated {
24
- return Animated.add(
25
- Animated.modulo(Animated.add(animated, Math.PI), Math.PI * 2),
26
- -Math.PI
27
- ).interpolate({
28
- inputRange: [-Math.PI, -Math.PI / 2, Math.PI / 2, Math.PI],
29
- outputRange: [0, -Math.PI / 2, Math.PI / 2, 0],
30
- });
31
- }
32
-
33
- export { sin, normalize };
@@ -1,34 +0,0 @@
1
- import { memo } from 'react';
2
- import { PickerOption } from '../DatePicker.props';
3
- import WheelPicker from './wheel-picker';
4
-
5
- interface PeriodProps {
6
- value: string;
7
- setValue?: (value: any) => void;
8
- }
9
-
10
- const options: PickerOption[] = [
11
- { value: 'AM', text: 'AM' },
12
- { value: 'PM', text: 'PM' },
13
- ];
14
-
15
- const PeriodNative = ({ value, setValue = () => {} }: PeriodProps) => {
16
- return (
17
- <WheelPicker
18
- value={value}
19
- options={options}
20
- onChange={setValue}
21
- //containerStyle={defaultStyles.container}
22
- itemHeight={44}
23
- decelerationRate="fast"
24
- />
25
- );
26
- };
27
-
28
- const customComparator = (prev: Readonly<PeriodProps>, next: Readonly<PeriodProps>) => {
29
- const areEqual = prev.value === next.value && prev.setValue === next.setValue;
30
-
31
- return areEqual;
32
- };
33
-
34
- export default memo(PeriodNative, customComparator);
@@ -1,16 +0,0 @@
1
- import { memo } from 'react';
2
- import { Platform } from 'react-native';
3
- import PeriodNative from './period-native';
4
- import PeriodWeb from './period-web';
5
-
6
- type PeriodProps = {
7
- value: string;
8
- setValue?: (value: any) => void;
9
- };
10
-
11
- const PeriodPicker = (props: PeriodProps) => {
12
- const Component = Platform.OS === 'web' ? PeriodWeb : PeriodNative;
13
- return <Component {...props} />;
14
- };
15
-
16
- export default memo(PeriodPicker);
@@ -1,36 +0,0 @@
1
- import { memo } from 'react';
2
- import { Pressable, View } from 'react-native';
3
- import { StyleSheet } from 'react-native-unistyles';
4
- import { BodyText } from '../../BodyText';
5
-
6
- interface PeriodProps {
7
- value: string;
8
- setValue?: (value: any) => void;
9
- }
10
-
11
- const PeriodWeb = ({ value, setValue = () => {} }: PeriodProps) => {
12
- return (
13
- <Pressable onPress={() => setValue(value == 'AM' ? 'PM' : 'AM')}>
14
- <View style={[styles.period]}>
15
- <BodyText>{value}</BodyText>
16
- </View>
17
- </Pressable>
18
- );
19
- };
20
-
21
- const styles = StyleSheet.create({
22
- period: {
23
- width: 65,
24
- height: 44,
25
- alignItems: 'center',
26
- justifyContent: 'center',
27
- },
28
- });
29
-
30
- const customComparator = (prev: Readonly<PeriodProps>, next: Readonly<PeriodProps>) => {
31
- const areEqual = prev.value === next.value && prev.setValue === next.setValue;
32
-
33
- return areEqual;
34
- };
35
-
36
- export default memo(PeriodWeb, customComparator);