@utilitywarehouse/hearth-react-native 0.3.1 → 0.4.1

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 (274) 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 +16 -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/core/themes.d.ts +482 -0
  93. package/build/core/themes.js +31 -0
  94. package/build/hooks/index.d.ts +4 -3
  95. package/build/hooks/index.js +4 -3
  96. package/build/hooks/usePrevious.d.ts +1 -0
  97. package/build/hooks/usePrevious.js +8 -0
  98. package/build/hooks/useTheme.d.ts +2 -1
  99. package/build/hooks/useTheme.js +2 -2
  100. package/build/legacyTokens/common/brand.d.ts +16 -0
  101. package/build/legacyTokens/common/brand.js +17 -0
  102. package/build/legacyTokens/common/index.d.ts +8 -0
  103. package/build/legacyTokens/common/index.js +9 -0
  104. package/build/legacyTokens/common/service.d.ts +20 -0
  105. package/build/legacyTokens/common/service.js +21 -0
  106. package/build/legacyTokens/dark/apple.d.ts +28 -0
  107. package/build/legacyTokens/dark/apple.js +29 -0
  108. package/build/legacyTokens/dark/cyan.d.ts +48 -0
  109. package/build/legacyTokens/dark/cyan.js +49 -0
  110. package/build/legacyTokens/dark/gold.d.ts +44 -0
  111. package/build/legacyTokens/dark/gold.js +45 -0
  112. package/build/legacyTokens/dark/grape.d.ts +28 -0
  113. package/build/legacyTokens/dark/grape.js +29 -0
  114. package/build/legacyTokens/dark/green.d.ts +40 -0
  115. package/build/legacyTokens/dark/green.js +41 -0
  116. package/build/legacyTokens/dark/grey.d.ts +60 -0
  117. package/build/legacyTokens/dark/grey.js +61 -0
  118. package/build/legacyTokens/dark/index.d.ts +40 -0
  119. package/build/legacyTokens/dark/index.js +41 -0
  120. package/build/legacyTokens/dark/pink.d.ts +28 -0
  121. package/build/legacyTokens/dark/pink.js +29 -0
  122. package/build/legacyTokens/dark/purple.d.ts +48 -0
  123. package/build/legacyTokens/dark/purple.js +49 -0
  124. package/build/legacyTokens/dark/red.d.ts +40 -0
  125. package/build/legacyTokens/dark/red.js +41 -0
  126. package/build/legacyTokens/dark/rose.d.ts +28 -0
  127. package/build/legacyTokens/dark/rose.js +29 -0
  128. package/build/legacyTokens/index.d.ts +12 -0
  129. package/build/legacyTokens/index.js +13 -0
  130. package/build/legacyTokens/light/apple.d.ts +28 -0
  131. package/build/legacyTokens/light/apple.js +29 -0
  132. package/build/legacyTokens/light/cyan.d.ts +48 -0
  133. package/build/legacyTokens/light/cyan.js +49 -0
  134. package/build/legacyTokens/light/gold.d.ts +44 -0
  135. package/build/legacyTokens/light/gold.js +45 -0
  136. package/build/legacyTokens/light/grape.d.ts +28 -0
  137. package/build/legacyTokens/light/grape.js +29 -0
  138. package/build/legacyTokens/light/green.d.ts +40 -0
  139. package/build/legacyTokens/light/green.js +41 -0
  140. package/build/legacyTokens/light/grey.d.ts +60 -0
  141. package/build/legacyTokens/light/grey.js +61 -0
  142. package/build/legacyTokens/light/index.d.ts +40 -0
  143. package/build/legacyTokens/light/index.js +41 -0
  144. package/build/legacyTokens/light/pink.d.ts +28 -0
  145. package/build/legacyTokens/light/pink.js +29 -0
  146. package/build/legacyTokens/light/purple.d.ts +48 -0
  147. package/build/legacyTokens/light/purple.js +49 -0
  148. package/build/legacyTokens/light/red.d.ts +40 -0
  149. package/build/legacyTokens/light/red.js +41 -0
  150. package/build/legacyTokens/light/rose.d.ts +32 -0
  151. package/build/legacyTokens/light/rose.js +33 -0
  152. package/build/tokens/components/dark/date-picker.d.ts +1 -0
  153. package/build/tokens/components/dark/date-picker.js +1 -0
  154. package/build/tokens/components/dark/illustrations.d.ts +7 -0
  155. package/build/tokens/components/dark/illustrations.js +6 -0
  156. package/build/tokens/components/dark/index.d.ts +1 -0
  157. package/build/tokens/components/dark/index.js +1 -0
  158. package/build/tokens/components/dark/segmented-control.d.ts +2 -2
  159. package/build/tokens/components/dark/segmented-control.js +2 -2
  160. package/build/tokens/components/dark/table.d.ts +3 -0
  161. package/build/tokens/components/dark/table.js +3 -0
  162. package/build/tokens/components/light/date-picker.d.ts +1 -0
  163. package/build/tokens/components/light/date-picker.js +1 -0
  164. package/build/tokens/components/light/illustrations.d.ts +7 -0
  165. package/build/tokens/components/light/illustrations.js +6 -0
  166. package/build/tokens/components/light/index.d.ts +1 -0
  167. package/build/tokens/components/light/index.js +1 -0
  168. package/build/tokens/components/light/segmented-control.d.ts +2 -2
  169. package/build/tokens/components/light/segmented-control.js +2 -2
  170. package/build/tokens/components/light/table.d.ts +3 -0
  171. package/build/tokens/components/light/table.js +3 -0
  172. package/build/utils/index.d.ts +1 -0
  173. package/build/utils/index.js +1 -0
  174. package/build/utils/isEqual.d.ts +2 -0
  175. package/build/utils/isEqual.js +29 -0
  176. package/chromatic.config.json +6 -0
  177. package/docs/components/AllComponents.web.tsx +43 -1
  178. package/docs/components/ViewWrap.tsx +32 -0
  179. package/docs/components/index.ts +1 -0
  180. package/docs/getting-started.mdx +6 -6
  181. package/package.json +11 -8
  182. package/src/components/CurrencyInput/CurrencyInput.tsx +2 -1
  183. package/src/components/DatePicker/DatePicker.context.ts +23 -0
  184. package/src/components/DatePicker/DatePicker.docs.mdx +239 -0
  185. package/src/components/DatePicker/DatePicker.props.ts +139 -0
  186. package/src/components/DatePicker/DatePicker.stories.tsx +98 -0
  187. package/src/components/DatePicker/DatePicker.tsx +669 -0
  188. package/src/components/DatePicker/DatePickerCalendar.tsx +41 -0
  189. package/src/components/DatePicker/DatePickerDay.tsx +302 -0
  190. package/src/components/DatePicker/DatePickerDays.tsx +241 -0
  191. package/src/components/DatePicker/DatePickerFooter.tsx +35 -0
  192. package/src/components/DatePicker/DatePickerHeader/DatePickerHeader.props.ts +10 -0
  193. package/src/components/DatePicker/DatePickerHeader/DatePickerMonthButton.tsx +29 -0
  194. package/src/components/DatePicker/DatePickerHeader/DatePickerNextButton.tsx +46 -0
  195. package/src/components/DatePicker/DatePickerHeader/DatePickerPrevButton.tsx +46 -0
  196. package/src/components/DatePicker/DatePickerHeader/DatePickerSelectors.tsx +96 -0
  197. package/src/components/DatePicker/DatePickerHeader/DatePickerTimeButton.tsx +48 -0
  198. package/src/components/DatePicker/DatePickerHeader/DatePickerYearButton.tsx +50 -0
  199. package/src/components/DatePicker/DatePickerHeader/index.tsx +64 -0
  200. package/src/components/DatePicker/DatePickerMonths.tsx +101 -0
  201. package/src/components/DatePicker/DatePickerWeekdays.tsx +49 -0
  202. package/src/components/DatePicker/DatePickerYears.tsx +119 -0
  203. package/src/components/DatePicker/TimePicker.tsx +141 -0
  204. package/src/components/DatePicker/enums.ts +14 -0
  205. package/src/components/DatePicker/index.ts +13 -0
  206. package/src/components/DatePicker/polyfill.ts +21 -0
  207. package/src/components/DatePicker/time-picker/animated-math.ts +33 -0
  208. package/src/components/DatePicker/time-picker/period-native.tsx +34 -0
  209. package/src/components/DatePicker/time-picker/period-picker.tsx +16 -0
  210. package/src/components/DatePicker/time-picker/period-web.tsx +36 -0
  211. package/src/components/DatePicker/time-picker/wheel-native.tsx +37 -0
  212. package/src/components/DatePicker/time-picker/wheel-picker/index.ts +3 -0
  213. package/src/components/DatePicker/time-picker/wheel-picker/wheel-picker-item.tsx +132 -0
  214. package/src/components/DatePicker/time-picker/wheel-picker/wheel-picker.style.ts +22 -0
  215. package/src/components/DatePicker/time-picker/wheel-picker/wheel-picker.tsx +200 -0
  216. package/src/components/DatePicker/time-picker/wheel-web.tsx +181 -0
  217. package/src/components/DatePicker/time-picker/wheel.tsx +18 -0
  218. package/src/components/DatePicker/utils.ts +549 -0
  219. package/src/components/DatePickerInput/DatePickerInput.docs.mdx +237 -0
  220. package/src/components/DatePickerInput/DatePickerInput.props.ts +50 -0
  221. package/src/components/DatePickerInput/DatePickerInput.stories.tsx +178 -0
  222. package/src/components/DatePickerInput/DatePickerInput.tsx +265 -0
  223. package/src/components/DatePickerInput/DatePickerInputDoneButton.tsx +42 -0
  224. package/src/components/DatePickerInput/DatePickerInputDoneButton.web.tsx +7 -0
  225. package/src/components/DatePickerInput/index.ts +2 -0
  226. package/src/components/Icon/Icon.stories.tsx +4 -3
  227. package/src/components/Input/InputField.tsx +0 -2
  228. package/src/components/Input/InputSlot.tsx +14 -3
  229. package/src/components/Modal/Modal.stories.tsx +2 -30
  230. package/src/components/UnstyledIconButton/UnstyledIconButton.tsx +14 -2
  231. package/src/components/UnstyledIconButton/UnstyledIconButtonRoot.tsx +7 -3
  232. package/src/components/index.ts +2 -0
  233. package/src/core/themes.ts +31 -0
  234. package/src/hooks/index.ts +4 -3
  235. package/src/hooks/usePrevious.ts +9 -0
  236. package/src/hooks/useTheme.ts +4 -3
  237. package/src/legacyTokens/common/brand.ts +18 -0
  238. package/src/legacyTokens/common/index.ts +10 -0
  239. package/src/legacyTokens/common/service.ts +22 -0
  240. package/src/legacyTokens/dark/apple.ts +30 -0
  241. package/src/legacyTokens/dark/cyan.ts +50 -0
  242. package/src/legacyTokens/dark/gold.ts +46 -0
  243. package/src/legacyTokens/dark/grape.ts +30 -0
  244. package/src/legacyTokens/dark/green.ts +42 -0
  245. package/src/legacyTokens/dark/grey.ts +62 -0
  246. package/src/legacyTokens/dark/index.ts +42 -0
  247. package/src/legacyTokens/dark/pink.ts +30 -0
  248. package/src/legacyTokens/dark/purple.ts +50 -0
  249. package/src/legacyTokens/dark/red.ts +42 -0
  250. package/src/legacyTokens/dark/rose.ts +30 -0
  251. package/src/legacyTokens/index.ts +14 -0
  252. package/src/legacyTokens/light/apple.ts +30 -0
  253. package/src/legacyTokens/light/cyan.ts +50 -0
  254. package/src/legacyTokens/light/gold.ts +46 -0
  255. package/src/legacyTokens/light/grape.ts +30 -0
  256. package/src/legacyTokens/light/green.ts +42 -0
  257. package/src/legacyTokens/light/grey.ts +62 -0
  258. package/src/legacyTokens/light/index.ts +42 -0
  259. package/src/legacyTokens/light/pink.ts +30 -0
  260. package/src/legacyTokens/light/purple.ts +50 -0
  261. package/src/legacyTokens/light/red.ts +42 -0
  262. package/src/legacyTokens/light/rose.ts +34 -0
  263. package/src/tokens/components/dark/date-picker.ts +1 -0
  264. package/src/tokens/components/dark/illustrations.ts +7 -0
  265. package/src/tokens/components/dark/index.ts +1 -0
  266. package/src/tokens/components/dark/segmented-control.ts +2 -2
  267. package/src/tokens/components/dark/table.ts +3 -0
  268. package/src/tokens/components/light/date-picker.ts +1 -0
  269. package/src/tokens/components/light/illustrations.ts +7 -0
  270. package/src/tokens/components/light/index.ts +1 -0
  271. package/src/tokens/components/light/segmented-control.ts +2 -2
  272. package/src/tokens/components/light/table.ts +3 -0
  273. package/src/utils/index.ts +1 -0
  274. package/src/utils/isEqual.ts +30 -0
@@ -0,0 +1,21 @@
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);
@@ -0,0 +1,8 @@
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;
@@ -0,0 +1,19 @@
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);
@@ -0,0 +1,2 @@
1
+ import WheelPicker from './wheel-picker';
2
+ export default WheelPicker;
@@ -0,0 +1,2 @@
1
+ import WheelPicker from './wheel-picker';
2
+ export default WheelPicker;
@@ -0,0 +1,16 @@
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;
@@ -0,0 +1,97 @@
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);
@@ -0,0 +1,21 @@
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;
@@ -0,0 +1,88 @@
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);
@@ -0,0 +1,23 @@
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;
@@ -0,0 +1,21 @@
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
+ });
@@ -0,0 +1,8 @@
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;
@@ -0,0 +1,148 @@
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, {
102
+ // eslint-disable-next-line react-native/no-inline-styles
103
+ style: {
104
+ position: 'absolute',
105
+ height: ITEM_HEIGHT - 10,
106
+ transform: animatedAngle
107
+ ? [
108
+ {
109
+ translateY: Animated.multiply(radius, sin(animatedAngle)),
110
+ },
111
+ {
112
+ rotateX: animatedAngle.interpolate({
113
+ inputRange: [-Math.PI / 2, Math.PI / 2],
114
+ outputRange: ['-89deg', '89deg'],
115
+ extrapolate: 'clamp',
116
+ }),
117
+ },
118
+ ]
119
+ : [],
120
+ opacity: displayValue?.value !== value ? 0.3 : 1,
121
+ }, children: _jsx(BodyText, { children: displayValue?.text }) }, `${displayValue?.text}-${index}`));
122
+ })] }));
123
+ };
124
+ const styles = StyleSheet.create({
125
+ container: {
126
+ minWidth: 30,
127
+ overflow: 'hidden',
128
+ alignItems: 'center',
129
+ justifyContent: 'center',
130
+ height: CONTAINER_HEIGHT / 2,
131
+ ...Platform.select({
132
+ web: {
133
+ cursor: 'pointer',
134
+ userSelect: 'none',
135
+ },
136
+ }),
137
+ },
138
+ selectedIndicator: {
139
+ position: 'absolute',
140
+ width: '100%',
141
+ top: '50%',
142
+ },
143
+ });
144
+ const customComparator = (prev, next) => {
145
+ const areEqual = prev.value === next.value && prev.setValue === next.setValue && isEqual(prev.items, next.items);
146
+ return areEqual;
147
+ };
148
+ export default memo(WheelWeb, customComparator);
@@ -0,0 +1,8 @@
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;
@@ -0,0 +1,10 @@
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);