@utilitywarehouse/hearth-react-native 0.3.1 → 0.4.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 (193) hide show
  1. package/.storybook/preview.tsx +3 -0
  2. package/.turbo/turbo-build.log +1 -1
  3. package/.turbo/turbo-lint.log +1 -1
  4. package/CHANGELOG.md +10 -0
  5. package/build/components/CurrencyInput/CurrencyInput.js +1 -1
  6. package/build/components/DatePicker/DatePicker.context.d.ts +19 -0
  7. package/build/components/DatePicker/DatePicker.context.js +3 -0
  8. package/build/components/DatePicker/DatePicker.d.ts +19 -0
  9. package/build/components/DatePicker/DatePicker.js +479 -0
  10. package/build/components/DatePicker/DatePicker.props.d.ts +125 -0
  11. package/build/components/DatePicker/DatePicker.props.js +1 -0
  12. package/build/components/DatePicker/DatePickerCalendar.d.ts +2 -0
  13. package/build/components/DatePicker/DatePickerCalendar.js +28 -0
  14. package/build/components/DatePicker/DatePickerDay.d.ts +11 -0
  15. package/build/components/DatePicker/DatePickerDay.js +242 -0
  16. package/build/components/DatePicker/DatePickerDays.d.ts +2 -0
  17. package/build/components/DatePicker/DatePickerDays.js +157 -0
  18. package/build/components/DatePicker/DatePickerFooter.d.ts +2 -0
  19. package/build/components/DatePicker/DatePickerFooter.js +23 -0
  20. package/build/components/DatePicker/DatePickerHeader/DatePickerHeader.props.d.ts +8 -0
  21. package/build/components/DatePicker/DatePickerHeader/DatePickerHeader.props.js +1 -0
  22. package/build/components/DatePicker/DatePickerHeader/DatePickerMonthButton.d.ts +2 -0
  23. package/build/components/DatePicker/DatePickerHeader/DatePickerMonthButton.js +14 -0
  24. package/build/components/DatePicker/DatePickerHeader/DatePickerNextButton.d.ts +2 -0
  25. package/build/components/DatePicker/DatePickerHeader/DatePickerNextButton.js +32 -0
  26. package/build/components/DatePicker/DatePickerHeader/DatePickerPrevButton.d.ts +2 -0
  27. package/build/components/DatePicker/DatePickerHeader/DatePickerPrevButton.js +32 -0
  28. package/build/components/DatePicker/DatePickerHeader/DatePickerSelectors.d.ts +6 -0
  29. package/build/components/DatePicker/DatePickerHeader/DatePickerSelectors.js +64 -0
  30. package/build/components/DatePicker/DatePickerHeader/DatePickerTimeButton.d.ts +1 -0
  31. package/build/components/DatePicker/DatePickerHeader/DatePickerTimeButton.js +22 -0
  32. package/build/components/DatePicker/DatePickerHeader/DatePickerYearButton.d.ts +2 -0
  33. package/build/components/DatePicker/DatePickerHeader/DatePickerYearButton.js +25 -0
  34. package/build/components/DatePicker/DatePickerHeader/index.d.ts +3 -0
  35. package/build/components/DatePicker/DatePickerHeader/index.js +30 -0
  36. package/build/components/DatePicker/DatePickerMonths.d.ts +2 -0
  37. package/build/components/DatePicker/DatePickerMonths.js +69 -0
  38. package/build/components/DatePicker/DatePickerWeekdays.d.ts +8 -0
  39. package/build/components/DatePicker/DatePickerWeekdays.js +26 -0
  40. package/build/components/DatePicker/DatePickerYears.d.ts +2 -0
  41. package/build/components/DatePicker/DatePickerYears.js +83 -0
  42. package/build/components/DatePicker/TimePicker.d.ts +3 -0
  43. package/build/components/DatePicker/TimePicker.js +84 -0
  44. package/build/components/DatePicker/enums.d.ts +12 -0
  45. package/build/components/DatePicker/enums.js +12 -0
  46. package/build/components/DatePicker/index.d.ts +4 -0
  47. package/build/components/DatePicker/index.js +3 -0
  48. package/build/components/DatePicker/polyfill.d.ts +0 -0
  49. package/build/components/DatePicker/polyfill.js +22 -0
  50. package/build/components/DatePicker/time-picker/animated-math.d.ts +4 -0
  51. package/build/components/DatePicker/time-picker/animated-math.js +19 -0
  52. package/build/components/DatePicker/time-picker/period-native.d.ts +6 -0
  53. package/build/components/DatePicker/time-picker/period-native.js +17 -0
  54. package/build/components/DatePicker/time-picker/period-picker.d.ts +6 -0
  55. package/build/components/DatePicker/time-picker/period-picker.js +10 -0
  56. package/build/components/DatePicker/time-picker/period-web.d.ts +6 -0
  57. package/build/components/DatePicker/time-picker/period-web.js +21 -0
  58. package/build/components/DatePicker/time-picker/wheel-native.d.ts +8 -0
  59. package/build/components/DatePicker/time-picker/wheel-native.js +19 -0
  60. package/build/components/DatePicker/time-picker/wheel-picker/index.d.ts +2 -0
  61. package/build/components/DatePicker/time-picker/wheel-picker/index.js +2 -0
  62. package/build/components/DatePicker/time-picker/wheel-picker/wheel-picker-item.d.ts +16 -0
  63. package/build/components/DatePicker/time-picker/wheel-picker/wheel-picker-item.js +97 -0
  64. package/build/components/DatePicker/time-picker/wheel-picker/wheel-picker.d.ts +21 -0
  65. package/build/components/DatePicker/time-picker/wheel-picker/wheel-picker.js +88 -0
  66. package/build/components/DatePicker/time-picker/wheel-picker/wheel-picker.style.d.ts +23 -0
  67. package/build/components/DatePicker/time-picker/wheel-picker/wheel-picker.style.js +21 -0
  68. package/build/components/DatePicker/time-picker/wheel-web.d.ts +8 -0
  69. package/build/components/DatePicker/time-picker/wheel-web.js +148 -0
  70. package/build/components/DatePicker/time-picker/wheel.d.ts +8 -0
  71. package/build/components/DatePicker/time-picker/wheel.js +10 -0
  72. package/build/components/DatePicker/utils.d.ts +212 -0
  73. package/build/components/DatePicker/utils.js +391 -0
  74. package/build/components/DatePickerInput/DatePickerInput.d.ts +6 -0
  75. package/build/components/DatePickerInput/DatePickerInput.js +126 -0
  76. package/build/components/DatePickerInput/DatePickerInput.props.d.ts +47 -0
  77. package/build/components/DatePickerInput/DatePickerInput.props.js +1 -0
  78. package/build/components/DatePickerInput/DatePickerInputDoneButton.d.ts +8 -0
  79. package/build/components/DatePickerInput/DatePickerInputDoneButton.js +19 -0
  80. package/build/components/DatePickerInput/DatePickerInputDoneButton.web.d.ts +5 -0
  81. package/build/components/DatePickerInput/DatePickerInputDoneButton.web.js +5 -0
  82. package/build/components/DatePickerInput/index.d.ts +2 -0
  83. package/build/components/DatePickerInput/index.js +1 -0
  84. package/build/components/Input/InputField.d.ts +1 -1
  85. package/build/components/Input/InputField.js +1 -1
  86. package/build/components/Input/InputSlot.d.ts +1 -1
  87. package/build/components/Input/InputSlot.js +3 -3
  88. package/build/components/UnstyledIconButton/UnstyledIconButton.js +2 -2
  89. package/build/components/UnstyledIconButton/UnstyledIconButtonRoot.js +1 -1
  90. package/build/components/index.d.ts +2 -0
  91. package/build/components/index.js +2 -0
  92. package/build/hooks/index.d.ts +4 -3
  93. package/build/hooks/index.js +4 -3
  94. package/build/hooks/usePrevious.d.ts +1 -0
  95. package/build/hooks/usePrevious.js +8 -0
  96. package/build/hooks/useTheme.d.ts +2 -1
  97. package/build/hooks/useTheme.js +2 -2
  98. package/build/tokens/components/dark/date-picker.d.ts +1 -0
  99. package/build/tokens/components/dark/date-picker.js +1 -0
  100. package/build/tokens/components/dark/illustrations.d.ts +7 -0
  101. package/build/tokens/components/dark/illustrations.js +6 -0
  102. package/build/tokens/components/dark/index.d.ts +1 -0
  103. package/build/tokens/components/dark/index.js +1 -0
  104. package/build/tokens/components/dark/segmented-control.d.ts +2 -2
  105. package/build/tokens/components/dark/segmented-control.js +2 -2
  106. package/build/tokens/components/dark/table.d.ts +3 -0
  107. package/build/tokens/components/dark/table.js +3 -0
  108. package/build/tokens/components/light/date-picker.d.ts +1 -0
  109. package/build/tokens/components/light/date-picker.js +1 -0
  110. package/build/tokens/components/light/illustrations.d.ts +7 -0
  111. package/build/tokens/components/light/illustrations.js +6 -0
  112. package/build/tokens/components/light/index.d.ts +1 -0
  113. package/build/tokens/components/light/index.js +1 -0
  114. package/build/tokens/components/light/segmented-control.d.ts +2 -2
  115. package/build/tokens/components/light/segmented-control.js +2 -2
  116. package/build/tokens/components/light/table.d.ts +3 -0
  117. package/build/tokens/components/light/table.js +3 -0
  118. package/build/utils/index.d.ts +1 -0
  119. package/build/utils/index.js +1 -0
  120. package/build/utils/isEqual.d.ts +2 -0
  121. package/build/utils/isEqual.js +29 -0
  122. package/chromatic.config.json +6 -0
  123. package/docs/components/AllComponents.web.tsx +43 -1
  124. package/docs/components/ViewWrap.tsx +32 -0
  125. package/docs/components/index.ts +1 -0
  126. package/docs/getting-started.mdx +6 -6
  127. package/package.json +10 -7
  128. package/src/components/CurrencyInput/CurrencyInput.tsx +2 -1
  129. package/src/components/DatePicker/DatePicker.context.ts +23 -0
  130. package/src/components/DatePicker/DatePicker.docs.mdx +239 -0
  131. package/src/components/DatePicker/DatePicker.props.ts +139 -0
  132. package/src/components/DatePicker/DatePicker.stories.tsx +98 -0
  133. package/src/components/DatePicker/DatePicker.tsx +669 -0
  134. package/src/components/DatePicker/DatePickerCalendar.tsx +41 -0
  135. package/src/components/DatePicker/DatePickerDay.tsx +302 -0
  136. package/src/components/DatePicker/DatePickerDays.tsx +241 -0
  137. package/src/components/DatePicker/DatePickerFooter.tsx +35 -0
  138. package/src/components/DatePicker/DatePickerHeader/DatePickerHeader.props.ts +10 -0
  139. package/src/components/DatePicker/DatePickerHeader/DatePickerMonthButton.tsx +29 -0
  140. package/src/components/DatePicker/DatePickerHeader/DatePickerNextButton.tsx +46 -0
  141. package/src/components/DatePicker/DatePickerHeader/DatePickerPrevButton.tsx +46 -0
  142. package/src/components/DatePicker/DatePickerHeader/DatePickerSelectors.tsx +96 -0
  143. package/src/components/DatePicker/DatePickerHeader/DatePickerTimeButton.tsx +48 -0
  144. package/src/components/DatePicker/DatePickerHeader/DatePickerYearButton.tsx +50 -0
  145. package/src/components/DatePicker/DatePickerHeader/index.tsx +64 -0
  146. package/src/components/DatePicker/DatePickerMonths.tsx +101 -0
  147. package/src/components/DatePicker/DatePickerWeekdays.tsx +49 -0
  148. package/src/components/DatePicker/DatePickerYears.tsx +119 -0
  149. package/src/components/DatePicker/TimePicker.tsx +141 -0
  150. package/src/components/DatePicker/enums.ts +14 -0
  151. package/src/components/DatePicker/index.ts +13 -0
  152. package/src/components/DatePicker/polyfill.ts +21 -0
  153. package/src/components/DatePicker/time-picker/animated-math.ts +33 -0
  154. package/src/components/DatePicker/time-picker/period-native.tsx +34 -0
  155. package/src/components/DatePicker/time-picker/period-picker.tsx +16 -0
  156. package/src/components/DatePicker/time-picker/period-web.tsx +36 -0
  157. package/src/components/DatePicker/time-picker/wheel-native.tsx +37 -0
  158. package/src/components/DatePicker/time-picker/wheel-picker/index.ts +3 -0
  159. package/src/components/DatePicker/time-picker/wheel-picker/wheel-picker-item.tsx +132 -0
  160. package/src/components/DatePicker/time-picker/wheel-picker/wheel-picker.style.ts +22 -0
  161. package/src/components/DatePicker/time-picker/wheel-picker/wheel-picker.tsx +200 -0
  162. package/src/components/DatePicker/time-picker/wheel-web.tsx +181 -0
  163. package/src/components/DatePicker/time-picker/wheel.tsx +18 -0
  164. package/src/components/DatePicker/utils.ts +549 -0
  165. package/src/components/DatePickerInput/DatePickerInput.docs.mdx +237 -0
  166. package/src/components/DatePickerInput/DatePickerInput.props.ts +50 -0
  167. package/src/components/DatePickerInput/DatePickerInput.stories.tsx +178 -0
  168. package/src/components/DatePickerInput/DatePickerInput.tsx +265 -0
  169. package/src/components/DatePickerInput/DatePickerInputDoneButton.tsx +42 -0
  170. package/src/components/DatePickerInput/DatePickerInputDoneButton.web.tsx +7 -0
  171. package/src/components/DatePickerInput/index.ts +2 -0
  172. package/src/components/Icon/Icon.stories.tsx +4 -3
  173. package/src/components/Input/InputField.tsx +0 -2
  174. package/src/components/Input/InputSlot.tsx +14 -3
  175. package/src/components/Modal/Modal.stories.tsx +2 -30
  176. package/src/components/UnstyledIconButton/UnstyledIconButton.tsx +14 -2
  177. package/src/components/UnstyledIconButton/UnstyledIconButtonRoot.tsx +7 -3
  178. package/src/components/index.ts +2 -0
  179. package/src/hooks/index.ts +4 -3
  180. package/src/hooks/usePrevious.ts +9 -0
  181. package/src/hooks/useTheme.ts +4 -3
  182. package/src/tokens/components/dark/date-picker.ts +1 -0
  183. package/src/tokens/components/dark/illustrations.ts +7 -0
  184. package/src/tokens/components/dark/index.ts +1 -0
  185. package/src/tokens/components/dark/segmented-control.ts +2 -2
  186. package/src/tokens/components/dark/table.ts +3 -0
  187. package/src/tokens/components/light/date-picker.ts +1 -0
  188. package/src/tokens/components/light/illustrations.ts +7 -0
  189. package/src/tokens/components/light/index.ts +1 -0
  190. package/src/tokens/components/light/segmented-control.ts +2 -2
  191. package/src/tokens/components/light/table.ts +3 -0
  192. package/src/utils/index.ts +1 -0
  193. package/src/utils/isEqual.ts +30 -0
@@ -0,0 +1,181 @@
1
+ import { memo, useMemo, useRef } from 'react';
2
+ import { Animated, PanResponder, Platform, View } from 'react-native';
3
+ import { StyleSheet } from 'react-native-unistyles';
4
+ import { isEqual } from '../../../utils';
5
+ import { BodyText } from '../../BodyText';
6
+ import { PickerOption } from '../DatePicker.props';
7
+ import { CONTAINER_HEIGHT } from '../enums';
8
+ import { sin } from './animated-math';
9
+
10
+ interface WheelProps {
11
+ value: number | string;
12
+ setValue?: (value: any) => void;
13
+ items: PickerOption[];
14
+ }
15
+
16
+ const ITEM_HEIGHT = 44;
17
+
18
+ const WheelWeb = ({ value, setValue = () => {}, items }: WheelProps) => {
19
+ const displayCount = 5;
20
+ const translateY = useRef(new Animated.Value(0)).current;
21
+ const renderCount = displayCount * 2 < items.length ? displayCount * 8 : displayCount * 2 - 1;
22
+ const circular = items.length >= displayCount;
23
+ const height = 140;
24
+ const radius = height / 2;
25
+
26
+ const valueIndex = useMemo(() => {
27
+ return Math.max(
28
+ 0,
29
+ items.findIndex(item => item.value === value)
30
+ );
31
+ }, [items, value]);
32
+
33
+ const panResponder = useMemo(() => {
34
+ return PanResponder.create({
35
+ onMoveShouldSetPanResponder: () => true,
36
+ onStartShouldSetPanResponderCapture: () => true,
37
+ onPanResponderGrant: () => {
38
+ translateY.setValue(0);
39
+ },
40
+ onPanResponderMove: (evt, gestureState) => {
41
+ translateY.setValue(gestureState.dy);
42
+ evt.stopPropagation();
43
+ },
44
+ onPanResponderRelease: (_, gestureState) => {
45
+ translateY.extractOffset();
46
+ let newValueIndex =
47
+ valueIndex - Math.round(gestureState.dy / ((radius * 2) / displayCount));
48
+ if (circular) {
49
+ newValueIndex = (newValueIndex + items.length) % items.length;
50
+ } else {
51
+ if (newValueIndex < 0) {
52
+ newValueIndex = 0;
53
+ } else if (newValueIndex >= items.length) {
54
+ newValueIndex = items.length - 1;
55
+ }
56
+ }
57
+ const newValue = items[newValueIndex];
58
+ if (newValue?.value === value) {
59
+ translateY.setOffset(0);
60
+ translateY.setValue(0);
61
+ } else if (newValue?.value) {
62
+ setValue(newValue.value);
63
+ } else if (items[0]?.value) {
64
+ setValue(items[0].value);
65
+ }
66
+ },
67
+ });
68
+ }, [circular, displayCount, radius, setValue, value, valueIndex, items, translateY]);
69
+
70
+ const displayValues = useMemo(() => {
71
+ const centerIndex = Math.floor(renderCount / 2);
72
+
73
+ return Array.from({ length: renderCount }, (_, index) => {
74
+ let targetIndex = valueIndex + index - centerIndex;
75
+ if (circular) {
76
+ targetIndex = ((targetIndex % items.length) + items.length) % items.length;
77
+ } else {
78
+ targetIndex = Math.max(0, Math.min(targetIndex, items.length - 1));
79
+ }
80
+ return items[targetIndex] || items[0];
81
+ });
82
+ }, [renderCount, valueIndex, items, circular]);
83
+
84
+ const animatedAngles = useMemo(() => {
85
+ //translateY.setValue(0);
86
+ translateY.setOffset(0);
87
+ const currentIndex = displayValues.findIndex(item => item?.value === value);
88
+ return displayValues && displayValues.length > 0
89
+ ? displayValues.map((_, index) =>
90
+ translateY
91
+ .interpolate({
92
+ inputRange: [-radius, radius],
93
+ outputRange: [
94
+ -radius + ((radius * 2) / displayCount) * (index - currentIndex),
95
+ radius + ((radius * 2) / displayCount) * (index - currentIndex),
96
+ ],
97
+ extrapolate: 'extend',
98
+ })
99
+ .interpolate({
100
+ inputRange: [-radius, radius],
101
+ outputRange: [-Math.PI / 2, Math.PI / 2],
102
+ extrapolate: 'clamp',
103
+ })
104
+ )
105
+ : [];
106
+ }, [displayValues, radius, value, displayCount, translateY]);
107
+
108
+ return (
109
+ <View style={[styles.container]} {...panResponder.panHandlers}>
110
+ <View
111
+ style={[
112
+ styles.selectedIndicator,
113
+ {
114
+ transform: [{ translateY: -ITEM_HEIGHT / 2 }],
115
+ height: ITEM_HEIGHT,
116
+ },
117
+ ]}
118
+ />
119
+ {displayValues?.map((displayValue, index) => {
120
+ const animatedAngle = animatedAngles[index];
121
+ return (
122
+ <Animated.View
123
+ key={`${displayValue?.text}-${index}`}
124
+ // eslint-disable-next-line react-native/no-inline-styles
125
+ style={{
126
+ position: 'absolute',
127
+ height: ITEM_HEIGHT - 10,
128
+ transform: animatedAngle
129
+ ? [
130
+ {
131
+ translateY: Animated.multiply(radius, sin(animatedAngle)),
132
+ },
133
+ {
134
+ rotateX: animatedAngle.interpolate({
135
+ inputRange: [-Math.PI / 2, Math.PI / 2],
136
+ outputRange: ['-89deg', '89deg'],
137
+ extrapolate: 'clamp',
138
+ }),
139
+ },
140
+ ]
141
+ : [],
142
+ opacity: displayValue?.value !== value ? 0.3 : 1,
143
+ }}
144
+ >
145
+ <BodyText>{displayValue?.text}</BodyText>
146
+ </Animated.View>
147
+ );
148
+ })}
149
+ </View>
150
+ );
151
+ };
152
+
153
+ const styles = StyleSheet.create({
154
+ container: {
155
+ minWidth: 30,
156
+ overflow: 'hidden',
157
+ alignItems: 'center',
158
+ justifyContent: 'center',
159
+ height: CONTAINER_HEIGHT / 2,
160
+ ...Platform.select({
161
+ web: {
162
+ cursor: 'pointer',
163
+ userSelect: 'none',
164
+ },
165
+ }),
166
+ },
167
+ selectedIndicator: {
168
+ position: 'absolute',
169
+ width: '100%',
170
+ top: '50%',
171
+ },
172
+ });
173
+
174
+ const customComparator = (prev: Readonly<WheelProps>, next: Readonly<WheelProps>) => {
175
+ const areEqual =
176
+ prev.value === next.value && prev.setValue === next.setValue && isEqual(prev.items, next.items);
177
+
178
+ return areEqual;
179
+ };
180
+
181
+ export default memo(WheelWeb, customComparator);
@@ -0,0 +1,18 @@
1
+ import { memo } from 'react';
2
+ import { Platform } from 'react-native';
3
+ import { PickerOption } from '../DatePicker.props';
4
+ import WheelNative from './wheel-native';
5
+ import WheelWeb from './wheel-web';
6
+
7
+ type WheelProps = {
8
+ value: number | string;
9
+ setValue?: (value: any) => void;
10
+ items: PickerOption[];
11
+ };
12
+
13
+ const Wheel = (props: WheelProps) => {
14
+ const Component = Platform.OS === 'web' ? WheelWeb : WheelNative;
15
+ return <Component {...props} />;
16
+ };
17
+
18
+ export default memo(Wheel);