@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,212 @@
1
+ import dayjs from 'dayjs';
2
+ import type { CalendarDay, CalendarMonth, CalendarWeek, DateType, Numerals } from './DatePicker.props';
3
+ export declare const CALENDAR_FORMAT = "YYYY-MM-DD HH:mm";
4
+ export declare const DATE_FORMAT = "YYYY-MM-DD";
5
+ export declare const YEAR_PAGE_SIZE = 12;
6
+ export declare const getMonths: () => dayjs.MonthNames;
7
+ export declare const getMonthName: (month: number) => string;
8
+ /**
9
+ * Get months array
10
+ *
11
+ * @returns months array
12
+ */
13
+ export declare const getMonthsArray: () => CalendarMonth[];
14
+ /**
15
+ * Get weekdays
16
+ *
17
+ * @param locale - locale
18
+ * @param firstDayOfWeek - first day of week
19
+ * @param format - format short, min or full
20
+ *
21
+ * @returns weekdays
22
+ */
23
+ export declare const getWeekdays: (firstDayOfWeek: number) => CalendarWeek[];
24
+ export declare const getFormated: (date: DateType) => string;
25
+ export declare const getDateMonth: (date: DateType) => number;
26
+ export declare const getDateYear: (date: DateType) => number;
27
+ /**
28
+ * Check if two dates are on the same day
29
+ *
30
+ * @param a - date to check
31
+ * @param b - date to check
32
+ *
33
+ * @returns true if dates are on the same day, false otherwise
34
+ */
35
+ export declare function areDatesOnSameDay(a: DateType, b: DateType): boolean;
36
+ /**
37
+ * Check if date is between two dates
38
+ *
39
+ * @param date - date to check
40
+ * @param options - options
41
+ *
42
+ * @returns true if date is between two dates, false otherwise
43
+ */
44
+ export declare function isDateBetween(date: DateType, { startDate, endDate, }: {
45
+ startDate?: DateType;
46
+ endDate?: DateType;
47
+ }): boolean;
48
+ /**
49
+ * Check if date is disabled
50
+ *
51
+ * @param date - date to check
52
+ * @param options - options
53
+ *
54
+ * @returns true if date is disabled, false otherwise
55
+ */
56
+ export declare function isDateDisabled(date: dayjs.Dayjs, { minDate, maxDate, enabledDates, disabledDates, }: {
57
+ minDate?: DateType;
58
+ maxDate?: DateType;
59
+ enabledDates?: DateType[] | ((date: DateType) => boolean) | undefined;
60
+ disabledDates?: DateType[] | ((date: DateType) => boolean) | undefined;
61
+ }): boolean;
62
+ /**
63
+ * Check if year is disabled
64
+ *
65
+ * @param year - year to check
66
+ * @param options - options
67
+ *
68
+ * @returns true if year is disabled, false otherwise
69
+ */
70
+ export declare function isYearDisabled(year: number, { minDate, maxDate, }: {
71
+ minDate?: DateType;
72
+ maxDate?: DateType;
73
+ }): boolean;
74
+ /**
75
+ * Check if month is disabled
76
+ *
77
+ * @param month - month to check
78
+ * @param date - date to check
79
+ * @param options - options
80
+ *
81
+ * @returns true if month is disabled, false otherwise
82
+ */
83
+ export declare function isMonthDisabled(month: number, date: DateType, { minDate, maxDate, }: {
84
+ minDate?: DateType;
85
+ maxDate?: DateType;
86
+ }): boolean;
87
+ /**
88
+ * Get formated date
89
+ *
90
+ * @param date - date to get formated date from
91
+ * @param format - format to get formated date from
92
+ *
93
+ * @returns formated date
94
+ */
95
+ export declare const getFormatedDate: (date: DateType, format: string) => string;
96
+ /**
97
+ * Get date
98
+ *
99
+ * @param date - date to get
100
+ *
101
+ * @returns date
102
+ */
103
+ export declare const getDate: (date: DateType) => dayjs.Dayjs;
104
+ /**
105
+ * Get year range
106
+ *
107
+ * @param year - year to get year range from
108
+ *
109
+ * @returns year range
110
+ */
111
+ export declare const getYearRange: (year: number) => number[];
112
+ /**
113
+ * Get days in month
114
+ *
115
+ * @param date - date to get days in month from
116
+ * @param showOutsideDays - whether to show outside days
117
+ * @param firstDayOfWeek - first day of week, number 0-6, 0 – Sunday, 6 – Saturday
118
+ *
119
+ * @returns days in month
120
+ */
121
+ export declare function getDaysInMonth(date: DateType, showOutsideDays: boolean | undefined, firstDayOfWeek: number): {
122
+ prevMonthDays: number;
123
+ prevMonthOffset: number;
124
+ daysInCurrentMonth: number;
125
+ daysInNextMonth: number;
126
+ fullDaysInMonth: number;
127
+ };
128
+ /**
129
+ * Get first day of month
130
+ *
131
+ * @param date - date to get first day of month from
132
+ * @param firstDayOfWeek - first day of week, number 0-6, 0 – Sunday, 6 – Saturday
133
+ *
134
+ * @returns first day of month
135
+ */
136
+ export declare function getFirstDayOfMonth(date: DateType, firstDayOfWeek: number): number;
137
+ /**
138
+ * Get start of day
139
+ *
140
+ * @param date - date to get start of day from
141
+ *
142
+ * @returns start of day
143
+ */
144
+ export declare function getStartOfDay(date: DateType): DateType;
145
+ /**
146
+ * Get end of day
147
+ *
148
+ * @param date - date to get end of day from
149
+ *
150
+ * @returns end of day
151
+ */
152
+ export declare function getEndOfDay(date: DateType): DateType;
153
+ /**
154
+ * Convert date to unix timestamp
155
+ *
156
+ * @param date - date to convert
157
+ *
158
+ * @returns unix timestamp
159
+ */
160
+ export declare function dateToUnix(date: DateType): number;
161
+ /**
162
+ * Remove time from date
163
+ *
164
+ * @param date - date to remove time from
165
+ *
166
+ * @returns date with time removed
167
+ */
168
+ export declare function removeTime(date: DateType, timeZone: string | undefined): DateType;
169
+ /**
170
+ * Get detailed date object
171
+ *
172
+ * @param date Get detailed date object
173
+ *
174
+ * @returns parsed date object
175
+ */
176
+ export declare const getParsedDate: (date: DateType) => {
177
+ year: number;
178
+ month: number;
179
+ hour: number;
180
+ hour12: number;
181
+ minute: number;
182
+ period: string;
183
+ };
184
+ /**
185
+ * Calculate month days array based on current date
186
+ *
187
+ * @param datetime - The current date that selected
188
+ * @param showOutsideDays
189
+ * @param minDate - min selectable date
190
+ * @param maxDate - max selectable date
191
+ * @param firstDayOfWeek - first day of week, number 0-6, 0 – Sunday, 6 – Saturday
192
+ * @param enabledDates - array of enabled dates, or a function that returns true for a given date (takes precedence over disabledDates)
193
+ * @param disabledDates - array of disabled dates, or a function that returns true for a given date
194
+ * @param prevMonthDays - number of days in the previous month
195
+ * @param prevMonthOffset - number of days to offset the previous month
196
+ * @param daysInCurrentMonth - number of days in the current month
197
+ * @param daysInNextMonth - number of days in the next month
198
+ *
199
+ * @returns days array based on current date
200
+ */
201
+ export declare const getMonthDays: (datetime: DateType, showOutsideDays: boolean, minDate: DateType, maxDate: DateType, firstDayOfWeek: number, enabledDates: DateType[] | ((date: DateType) => boolean) | undefined, disabledDates: DateType[] | ((date: DateType) => boolean) | undefined, prevMonthDays: number, prevMonthOffset: number, daysInCurrentMonth: number, daysInNextMonth: number, numerals: Numerals) => CalendarDay[];
202
+ /**
203
+ * Deep compare memo
204
+ *
205
+ * @param value - value to compare
206
+ * @param deps - dependencies
207
+ *
208
+ * @returns memoized value
209
+ */
210
+ export declare function useDeepCompareMemo<T>(value: T, deps: any[]): T;
211
+ export declare const numeralSystems: Record<Numerals, readonly string[]>;
212
+ export declare function formatNumber(value: number, numerals: Numerals): string;
@@ -0,0 +1,391 @@
1
+ import dayjs from 'dayjs';
2
+ import { useRef } from 'react';
3
+ import { isEqual } from '../../utils';
4
+ export const CALENDAR_FORMAT = 'YYYY-MM-DD HH:mm';
5
+ export const DATE_FORMAT = 'YYYY-MM-DD';
6
+ export const YEAR_PAGE_SIZE = 12;
7
+ export const getMonths = () => dayjs.months();
8
+ export const getMonthName = (month) => dayjs.months()[month];
9
+ /**
10
+ * Get months array
11
+ *
12
+ * @returns months array
13
+ */
14
+ export const getMonthsArray = () => {
15
+ const monthNames = dayjs.months();
16
+ const monthShortNames = dayjs.monthsShort();
17
+ return monthNames.map((name, index) => ({
18
+ index,
19
+ name: {
20
+ full: name,
21
+ short: monthShortNames[index] || '',
22
+ },
23
+ isSelected: false,
24
+ }));
25
+ };
26
+ /**
27
+ * Get weekdays
28
+ *
29
+ * @param locale - locale
30
+ * @param firstDayOfWeek - first day of week
31
+ * @param format - format short, min or full
32
+ *
33
+ * @returns weekdays
34
+ */
35
+ export const getWeekdays = (firstDayOfWeek) => {
36
+ dayjs.locale('en');
37
+ const weekdayNames = dayjs.weekdays();
38
+ const weekdayShortNames = dayjs.weekdaysShort();
39
+ const weekdayMinNames = dayjs.weekdaysMin();
40
+ let weekdays = weekdayNames.map((name, index) => ({
41
+ index,
42
+ name: {
43
+ full: name,
44
+ short: weekdayShortNames[index] || '',
45
+ min: weekdayMinNames[index][0] || '',
46
+ },
47
+ }));
48
+ if (firstDayOfWeek > 0) {
49
+ weekdays = [
50
+ ...weekdays.slice(firstDayOfWeek, weekdays.length),
51
+ ...weekdays.slice(0, firstDayOfWeek),
52
+ ];
53
+ }
54
+ return weekdays;
55
+ };
56
+ export const getFormated = (date) => dayjs(date).format(CALENDAR_FORMAT);
57
+ export const getDateMonth = (date) => dayjs(date).month();
58
+ export const getDateYear = (date) => dayjs(date).year();
59
+ /**
60
+ * Check if two dates are on the same day
61
+ *
62
+ * @param a - date to check
63
+ * @param b - date to check
64
+ *
65
+ * @returns true if dates are on the same day, false otherwise
66
+ */
67
+ export function areDatesOnSameDay(a, b) {
68
+ if (!a || !b) {
69
+ return false;
70
+ }
71
+ const date_a = dayjs(a).format(DATE_FORMAT);
72
+ const date_b = dayjs(b).format(DATE_FORMAT);
73
+ return date_a === date_b;
74
+ }
75
+ /**
76
+ * Check if date is between two dates
77
+ *
78
+ * @param date - date to check
79
+ * @param options - options
80
+ *
81
+ * @returns true if date is between two dates, false otherwise
82
+ */
83
+ export function isDateBetween(date, { startDate, endDate, }) {
84
+ if (!startDate || !endDate) {
85
+ return false;
86
+ }
87
+ return dayjs(date) <= endDate && dayjs(date) >= startDate;
88
+ }
89
+ /**
90
+ * Check if date is disabled
91
+ *
92
+ * @param date - date to check
93
+ * @param options - options
94
+ *
95
+ * @returns true if date is disabled, false otherwise
96
+ */
97
+ export function isDateDisabled(date, { minDate, maxDate, enabledDates, disabledDates, }) {
98
+ if (minDate && date.isBefore(dayjs(minDate).startOf('day'))) {
99
+ return true;
100
+ }
101
+ if (maxDate && date.isAfter(dayjs(maxDate).endOf('day'))) {
102
+ return true;
103
+ }
104
+ if (enabledDates) {
105
+ if (Array.isArray(enabledDates)) {
106
+ const isEnabled = enabledDates.some(enabledDate => areDatesOnSameDay(date, enabledDate));
107
+ return !isEnabled;
108
+ }
109
+ else if (enabledDates instanceof Function) {
110
+ return !enabledDates(date);
111
+ }
112
+ }
113
+ else if (disabledDates) {
114
+ if (Array.isArray(disabledDates)) {
115
+ const isDisabled = disabledDates.some(disabledDate => areDatesOnSameDay(date, disabledDate));
116
+ return isDisabled;
117
+ }
118
+ else if (disabledDates instanceof Function) {
119
+ return disabledDates(date);
120
+ }
121
+ }
122
+ return false;
123
+ }
124
+ /**
125
+ * Check if year is disabled
126
+ *
127
+ * @param year - year to check
128
+ * @param options - options
129
+ *
130
+ * @returns true if year is disabled, false otherwise
131
+ */
132
+ export function isYearDisabled(year, { minDate, maxDate, }) {
133
+ if (minDate && year < getDateYear(minDate))
134
+ return true;
135
+ if (maxDate && year > getDateYear(maxDate))
136
+ return true;
137
+ return false;
138
+ }
139
+ /**
140
+ * Check if month is disabled
141
+ *
142
+ * @param month - month to check
143
+ * @param date - date to check
144
+ * @param options - options
145
+ *
146
+ * @returns true if month is disabled, false otherwise
147
+ */
148
+ export function isMonthDisabled(month, date, { minDate, maxDate, }) {
149
+ if (minDate && month < getDateMonth(minDate) && getDateYear(date) === getDateYear(minDate))
150
+ return true;
151
+ if (maxDate && month > getDateMonth(maxDate) && getDateYear(date) === getDateYear(maxDate))
152
+ return true;
153
+ return false;
154
+ }
155
+ /**
156
+ * Get formated date
157
+ *
158
+ * @param date - date to get formated date from
159
+ * @param format - format to get formated date from
160
+ *
161
+ * @returns formated date
162
+ */
163
+ export const getFormatedDate = (date, format) => dayjs(date).format(format);
164
+ /**
165
+ * Get date
166
+ *
167
+ * @param date - date to get
168
+ *
169
+ * @returns date
170
+ */
171
+ export const getDate = (date) => dayjs(date);
172
+ /**
173
+ * Get year range
174
+ *
175
+ * @param year - year to get year range from
176
+ *
177
+ * @returns year range
178
+ */
179
+ export const getYearRange = (year) => {
180
+ const endYear = YEAR_PAGE_SIZE * Math.ceil(year / YEAR_PAGE_SIZE);
181
+ let startYear = endYear === year ? endYear : endYear - YEAR_PAGE_SIZE;
182
+ if (startYear < 0) {
183
+ startYear = 0;
184
+ }
185
+ return Array.from({ length: YEAR_PAGE_SIZE }, (_, i) => startYear + i);
186
+ };
187
+ /**
188
+ * Get days in month
189
+ *
190
+ * @param date - date to get days in month from
191
+ * @param showOutsideDays - whether to show outside days
192
+ * @param firstDayOfWeek - first day of week, number 0-6, 0 – Sunday, 6 – Saturday
193
+ *
194
+ * @returns days in month
195
+ */
196
+ export function getDaysInMonth(date, showOutsideDays, firstDayOfWeek) {
197
+ const daysInCurrentMonth = dayjs(date).daysInMonth();
198
+ const prevMonthDays = dayjs(date).add(-1, 'month').daysInMonth();
199
+ const firstDay = dayjs(date).date(1 - firstDayOfWeek);
200
+ const prevMonthOffset = firstDay.day() % 7;
201
+ const daysInPrevMonth = showOutsideDays ? prevMonthOffset : 0;
202
+ const monthDaysOffset = prevMonthOffset + daysInCurrentMonth;
203
+ const daysInNextMonth = showOutsideDays
204
+ ? monthDaysOffset > 35
205
+ ? 42 - monthDaysOffset
206
+ : 35 - monthDaysOffset
207
+ : 0;
208
+ const fullDaysInMonth = daysInPrevMonth + daysInCurrentMonth + daysInNextMonth;
209
+ return {
210
+ prevMonthDays,
211
+ prevMonthOffset,
212
+ daysInCurrentMonth,
213
+ daysInNextMonth,
214
+ fullDaysInMonth,
215
+ };
216
+ }
217
+ /**
218
+ * Get first day of month
219
+ *
220
+ * @param date - date to get first day of month from
221
+ * @param firstDayOfWeek - first day of week, number 0-6, 0 – Sunday, 6 – Saturday
222
+ *
223
+ * @returns first day of month
224
+ */
225
+ export function getFirstDayOfMonth(date, firstDayOfWeek) {
226
+ const d = getDate(date);
227
+ return d.date(1 - firstDayOfWeek).day();
228
+ }
229
+ /**
230
+ * Get start of day
231
+ *
232
+ * @param date - date to get start of day from
233
+ *
234
+ * @returns start of day
235
+ */
236
+ export function getStartOfDay(date) {
237
+ return dayjs(date).startOf('day');
238
+ }
239
+ /**
240
+ * Get end of day
241
+ *
242
+ * @param date - date to get end of day from
243
+ *
244
+ * @returns end of day
245
+ */
246
+ export function getEndOfDay(date) {
247
+ return dayjs(date).endOf('day');
248
+ }
249
+ /**
250
+ * Convert date to unix timestamp
251
+ *
252
+ * @param date - date to convert
253
+ *
254
+ * @returns unix timestamp
255
+ */
256
+ export function dateToUnix(date) {
257
+ return dayjs(date).unix();
258
+ }
259
+ /**
260
+ * Remove time from date
261
+ *
262
+ * @param date - date to remove time from
263
+ *
264
+ * @returns date with time removed
265
+ */
266
+ export function removeTime(date, timeZone) {
267
+ return date ? dayjs.tz(date, timeZone).startOf('day') : undefined;
268
+ }
269
+ /**
270
+ * Get detailed date object
271
+ *
272
+ * @param date Get detailed date object
273
+ *
274
+ * @returns parsed date object
275
+ */
276
+ export const getParsedDate = (date) => {
277
+ return {
278
+ year: dayjs(date).year(),
279
+ month: dayjs(date).month(),
280
+ hour: dayjs(date).hour(),
281
+ hour12: parseInt(dayjs(date).format('hh')),
282
+ minute: dayjs(date).minute(),
283
+ period: dayjs(date).format('A'),
284
+ };
285
+ };
286
+ /**
287
+ * Calculate month days array based on current date
288
+ *
289
+ * @param datetime - The current date that selected
290
+ * @param showOutsideDays
291
+ * @param minDate - min selectable date
292
+ * @param maxDate - max selectable date
293
+ * @param firstDayOfWeek - first day of week, number 0-6, 0 – Sunday, 6 – Saturday
294
+ * @param enabledDates - array of enabled dates, or a function that returns true for a given date (takes precedence over disabledDates)
295
+ * @param disabledDates - array of disabled dates, or a function that returns true for a given date
296
+ * @param prevMonthDays - number of days in the previous month
297
+ * @param prevMonthOffset - number of days to offset the previous month
298
+ * @param daysInCurrentMonth - number of days in the current month
299
+ * @param daysInNextMonth - number of days in the next month
300
+ *
301
+ * @returns days array based on current date
302
+ */
303
+ export const getMonthDays = (datetime, showOutsideDays, minDate, maxDate, firstDayOfWeek, enabledDates, disabledDates, prevMonthDays, prevMonthOffset, daysInCurrentMonth, daysInNextMonth, numerals) => {
304
+ const date = dayjs(datetime);
305
+ const prevDays = showOutsideDays
306
+ ? Array.from({ length: prevMonthOffset }, (_, index) => {
307
+ const number = index + (prevMonthDays - prevMonthOffset + 1);
308
+ const thisDay = date.add(-1, 'month').date(number);
309
+ return generateCalendarDay(number, thisDay, minDate, maxDate, enabledDates, disabledDates, false, index + 1, firstDayOfWeek, numerals);
310
+ })
311
+ : Array(prevMonthOffset).fill(null);
312
+ const currentDays = Array.from({ length: daysInCurrentMonth }, (_, index) => {
313
+ const day = index + 1;
314
+ const thisDay = date.date(day);
315
+ return generateCalendarDay(day, thisDay, minDate, maxDate, enabledDates, disabledDates, true, prevMonthOffset + day, firstDayOfWeek, numerals);
316
+ });
317
+ const nextDays = Array.from({ length: daysInNextMonth }, (_, index) => {
318
+ const day = index + 1;
319
+ const thisDay = date.add(1, 'month').date(day);
320
+ return generateCalendarDay(day, thisDay, minDate, maxDate, enabledDates, disabledDates, false, daysInCurrentMonth + prevMonthOffset + day, firstDayOfWeek, numerals);
321
+ });
322
+ return [...prevDays, ...currentDays, ...nextDays];
323
+ };
324
+ /**
325
+ * Generate day object for displaying inside day cell
326
+ *
327
+ * @param number - number of day
328
+ * @param date - calculated date based on day, month, and year
329
+ * @param minDate - min selectable date
330
+ * @param maxDate - max selectable date
331
+ * @param enabledDates - array of enabled dates, or a function that returns true for a given date (takes precedence over disabledDates)
332
+ * @param disabledDates - array of disabled dates, or a function that returns true for a given date
333
+ * @param isCurrentMonth - define the day is in the current month
334
+ * @param dayOfMonth - number the day in the current month
335
+ * @param firstDayOfWeek - first day of week, number 0-6, 0 – Sunday, 6 – Saturday
336
+ *
337
+ * @returns days object based on current date
338
+ */
339
+ const generateCalendarDay = (number, date, minDate, maxDate, enabledDates, disabledDates, isCurrentMonth, dayOfMonth, firstDayOfWeek, numerals) => {
340
+ const startOfWeek = dayjs(date).startOf('week').add(firstDayOfWeek, 'day');
341
+ return {
342
+ text: formatNumber(number, numerals),
343
+ number,
344
+ date: date,
345
+ isDisabled: isDateDisabled(date, {
346
+ minDate,
347
+ maxDate,
348
+ enabledDates,
349
+ disabledDates,
350
+ }),
351
+ isCurrentMonth,
352
+ dayOfMonth,
353
+ isStartOfWeek: date.isSame(startOfWeek, 'day'),
354
+ isEndOfWeek: date.day() === (firstDayOfWeek + 6) % 7,
355
+ };
356
+ };
357
+ /**
358
+ * Deep compare memo
359
+ *
360
+ * @param value - value to compare
361
+ * @param deps - dependencies
362
+ *
363
+ * @returns memoized value
364
+ */
365
+ export function useDeepCompareMemo(value, deps) {
366
+ const ref = useRef(null);
367
+ const depsRef = useRef(null);
368
+ if (!depsRef.current || !deps.every((dep, i) => isEqual(dep, depsRef.current[i]))) {
369
+ ref.current = value;
370
+ depsRef.current = deps;
371
+ }
372
+ return ref.current;
373
+ }
374
+ export const numeralSystems = {
375
+ latn: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
376
+ };
377
+ function getDigitMap(numerals) {
378
+ const digitMap = {};
379
+ const numeralDigits = numeralSystems[numerals];
380
+ for (let i = 0; i < 10; i++) {
381
+ digitMap[i.toString()] = numeralDigits[i];
382
+ }
383
+ return digitMap;
384
+ }
385
+ function replaceDigits(input, numerals) {
386
+ const digitMap = getDigitMap(numerals);
387
+ return input.replace(/\d/g, digit => digitMap[digit] || digit);
388
+ }
389
+ export function formatNumber(value, numerals) {
390
+ return replaceDigits(value.toString(), numerals);
391
+ }
@@ -0,0 +1,6 @@
1
+ import type DatePickerInputProps from './DatePickerInput.props';
2
+ declare const DatePickerInput: {
3
+ ({ validationStatus, disabled, focused, readonly, placeholder, inBottomSheet, format, openButtonLabel, autoCloseOnSelect, onChange, onChangeText, onBlur, onFocus, value, datePickerProps, onClear, ...rest }: DatePickerInputProps): import("react/jsx-runtime").JSX.Element;
4
+ displayName: string;
5
+ };
6
+ export default DatePickerInput;