react-native-molecules 0.5.0-beta.3 → 0.5.0-beta.31

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 (227) hide show
  1. package/components/Accordion/Accordion.tsx +2 -6
  2. package/components/Accordion/AccordionItem.tsx +16 -12
  3. package/components/Accordion/AccordionItemContent.tsx +6 -1
  4. package/components/Accordion/AccordionItemHeader.tsx +1 -1
  5. package/components/Accordion/utils.ts +6 -0
  6. package/components/ActivityIndicator/ActivityIndicator.tsx +6 -15
  7. package/components/Appbar/AppbarBase.tsx +18 -13
  8. package/components/Button/Button.tsx +211 -264
  9. package/components/Button/index.tsx +9 -3
  10. package/components/Button/types.ts +16 -2
  11. package/components/Button/utils.ts +230 -208
  12. package/components/Card/Card.tsx +1 -1
  13. package/components/Checkbox/Checkbox.tsx +125 -88
  14. package/components/Checkbox/CheckboxBase.ios.tsx +14 -23
  15. package/components/Checkbox/CheckboxBase.tsx +21 -137
  16. package/components/Checkbox/context.tsx +14 -0
  17. package/components/Checkbox/index.tsx +11 -4
  18. package/components/Checkbox/types.ts +63 -29
  19. package/components/Checkbox/utils.ts +25 -108
  20. package/components/Chip/Chip.tsx +41 -52
  21. package/components/Chip/utils.ts +3 -7
  22. package/components/DateField/DateField.tsx +111 -0
  23. package/components/DateField/index.tsx +6 -0
  24. package/components/{DatePickerInput/inputUtils.ts → DateField/useDateFieldState.ts} +19 -51
  25. package/components/DatePicker/DateCalendar.tsx +83 -0
  26. package/components/DatePicker/DatePickerActions.tsx +73 -0
  27. package/components/DatePicker/DatePickerModal.tsx +246 -0
  28. package/components/DatePicker/DatePickerPopover.tsx +79 -0
  29. package/components/DatePicker/DatePickerProvider.tsx +158 -0
  30. package/components/DatePicker/DatePickerTrigger.tsx +23 -0
  31. package/components/DatePicker/context.tsx +83 -0
  32. package/components/DatePicker/index.tsx +45 -0
  33. package/components/DatePicker/utils.ts +295 -0
  34. package/components/DatePickerInline/DatePickerDockedHeader.tsx +117 -0
  35. package/components/DatePickerInline/DatePickerInline.tsx +17 -16
  36. package/components/DatePickerInline/DatePickerInlineBase.tsx +11 -5
  37. package/components/DatePickerInline/DatePickerInlineHeader.tsx +50 -20
  38. package/components/DatePickerInline/Day.tsx +25 -1
  39. package/components/DatePickerInline/DayNames.tsx +13 -10
  40. package/components/DatePickerInline/DayRange.tsx +2 -4
  41. package/components/DatePickerInline/HeaderItem.tsx +44 -29
  42. package/components/DatePickerInline/Month.tsx +48 -67
  43. package/components/DatePickerInline/MonthPicker.tsx +80 -92
  44. package/components/DatePickerInline/Swiper.native.tsx +21 -4
  45. package/components/DatePickerInline/Swiper.tsx +169 -14
  46. package/components/DatePickerInline/SwiperUtils.ts +1 -1
  47. package/components/DatePickerInline/Week.tsx +6 -1
  48. package/components/DatePickerInline/YearPicker.tsx +220 -78
  49. package/components/DatePickerInline/dateUtils.tsx +18 -13
  50. package/components/DatePickerInline/store.tsx +27 -0
  51. package/components/DatePickerInline/types.ts +6 -2
  52. package/components/DatePickerInline/utils.ts +66 -29
  53. package/components/Divider/Divider.tsx +192 -0
  54. package/components/Divider/index.tsx +10 -0
  55. package/components/Drawer/Drawer.tsx +17 -6
  56. package/components/Drawer/DrawerItemGroup.tsx +3 -7
  57. package/components/ElementGroup/ElementGroup.tsx +1 -1
  58. package/components/FilePicker/FilePicker.tsx +48 -78
  59. package/components/FilePicker/index.tsx +2 -1
  60. package/components/FilePicker/utils.ts +9 -0
  61. package/components/HelperText/HelperText.tsx +0 -35
  62. package/components/Icon/iconFactory.tsx +5 -4
  63. package/components/Icon/index.tsx +1 -1
  64. package/components/Icon/types.ts +17 -6
  65. package/components/IconButton/IconButton.tsx +84 -84
  66. package/components/IconButton/index.tsx +1 -0
  67. package/components/IconButton/types.ts +10 -0
  68. package/components/IconButton/utils.ts +167 -33
  69. package/components/List/List.tsx +276 -0
  70. package/components/List/context.tsx +27 -0
  71. package/components/List/index.ts +8 -0
  72. package/components/List/types.ts +117 -0
  73. package/components/List/utils.ts +79 -0
  74. package/components/LoadingIndicator/LoadingIndicator.tsx +253 -0
  75. package/components/LoadingIndicator/LoadingIndicator.web.tsx +136 -0
  76. package/components/LoadingIndicator/index.tsx +13 -0
  77. package/components/LoadingIndicator/utils.ts +117 -0
  78. package/components/Menu/Menu.tsx +162 -39
  79. package/components/Menu/index.tsx +10 -7
  80. package/components/Menu/utils.ts +21 -70
  81. package/components/NavigationRail/NavigationRail.tsx +15 -9
  82. package/components/Popover/Popover.tsx +119 -145
  83. package/components/Popover/PopoverRoot.tsx +60 -0
  84. package/components/Popover/common.ts +54 -34
  85. package/components/Popover/index.ts +12 -1
  86. package/components/Popover/usePlatformMeasure.native.ts +90 -0
  87. package/components/Popover/usePlatformMeasure.ts +120 -0
  88. package/components/Popover/utils.ts +34 -0
  89. package/components/Portal/Portal.tsx +1 -2
  90. package/components/Radio/Radio.tsx +188 -0
  91. package/components/Radio/RadioBase.ios.tsx +69 -0
  92. package/components/Radio/RadioBase.tsx +136 -0
  93. package/components/Radio/context.tsx +23 -0
  94. package/components/Radio/index.tsx +20 -0
  95. package/components/Radio/types.ts +101 -0
  96. package/components/Radio/utils.ts +115 -0
  97. package/components/Rating/Rating.tsx +1 -1
  98. package/components/Select/Select.tsx +521 -785
  99. package/components/Select/context.tsx +81 -0
  100. package/components/Select/index.ts +26 -14
  101. package/components/Select/types.ts +65 -58
  102. package/components/Select/utils.ts +126 -0
  103. package/components/Slot/Slot.tsx +224 -0
  104. package/components/Slot/compose-refs.tsx +62 -0
  105. package/components/Slot/index.tsx +8 -0
  106. package/components/Surface/Surface.android.tsx +32 -7
  107. package/components/Surface/Surface.ios.tsx +34 -29
  108. package/components/Surface/Surface.tsx +31 -4
  109. package/components/Surface/utils.ts +44 -6
  110. package/components/Switch/Switch.ios.tsx +1 -1
  111. package/components/Switch/Switch.tsx +10 -3
  112. package/components/Tabs/TabItem.tsx +35 -58
  113. package/components/Tabs/TabLabel.tsx +5 -9
  114. package/components/Tabs/Tabs.tsx +156 -150
  115. package/components/Tabs/utils.ts +15 -2
  116. package/components/Text/textFactory.tsx +17 -5
  117. package/components/TextInput/TextInput.tsx +663 -579
  118. package/components/TextInput/index.tsx +19 -3
  119. package/components/TextInput/types.ts +77 -28
  120. package/components/TextInput/utils.ts +235 -145
  121. package/components/TimeField/TimeField.tsx +75 -0
  122. package/components/TimeField/index.tsx +6 -0
  123. package/components/TimeField/useTimeFieldState.ts +70 -0
  124. package/components/{TimePickerField/sanitizeTime.ts → TimeField/utils.ts} +77 -10
  125. package/components/TimePicker/AnalogClock.tsx +1 -1
  126. package/components/TimePicker/TimeInput.tsx +87 -42
  127. package/components/TimePicker/TimeInputs.tsx +138 -50
  128. package/components/TimePicker/TimePicker.tsx +74 -11
  129. package/components/TimePicker/TimePickerModal.tsx +186 -0
  130. package/components/TimePicker/context.tsx +17 -0
  131. package/components/TimePicker/index.tsx +15 -3
  132. package/components/TimePicker/utils.ts +93 -4
  133. package/components/Tooltip/Tooltip.tsx +42 -67
  134. package/components/Tooltip/TooltipContent.tsx +32 -5
  135. package/components/Tooltip/TooltipTrigger.tsx +21 -24
  136. package/components/Tooltip/index.tsx +1 -1
  137. package/components/TouchableRipple/TouchableRipple.native.tsx +83 -16
  138. package/components/TouchableRipple/TouchableRipple.tsx +150 -102
  139. package/components/TouchableRipple/rippleFromForegroundColor.ts +21 -0
  140. package/hocs/index.tsx +1 -1
  141. package/hocs/withKeyboardAccessibility.tsx +2 -3
  142. package/hocs/withPortal.tsx +1 -1
  143. package/hooks/index.tsx +2 -12
  144. package/hooks/useActionState.tsx +19 -8
  145. package/hooks/useContrastColor.ts +1 -2
  146. package/hooks/useFilePicker.tsx +7 -17
  147. package/hooks/useHandleNumberFormat.tsx +2 -2
  148. package/hooks/useMediaQuery.tsx +1 -2
  149. package/package.json +95 -111
  150. package/shortcuts-manager/ShortcutsManager/ShortcutsManager.tsx +6 -3
  151. package/shortcuts-manager/ShortcutsManager/utils.tsx +1 -1
  152. package/shortcuts-manager/useSetScopes/useSetScopes.tsx +1 -1
  153. package/shortcuts-manager/useShortcut/useShortcut.tsx +1 -1
  154. package/styles/shadow.ts +2 -1
  155. package/styles/themes/LightTheme.tsx +1 -1
  156. package/utils/DocumentPicker/documentPicker.ts +78 -27
  157. package/utils/DocumentPicker/types.ts +0 -1
  158. package/utils/extractSubcomponents.ts +89 -0
  159. package/utils/extractTextStyles.ts +1 -2
  160. package/utils/formatNumberWithMask/formatNumberWithMask.ts +2 -1
  161. package/utils/index.ts +0 -3
  162. package/utils/normalizeToNumberString/normalizeToNumberString.ts +1 -1
  163. package/components/DatePickerDocked/DatePickerDocked.tsx +0 -30
  164. package/components/DatePickerDocked/DatePickerDockedHeader.tsx +0 -129
  165. package/components/DatePickerDocked/index.tsx +0 -17
  166. package/components/DatePickerDocked/types.ts +0 -11
  167. package/components/DatePickerDocked/utils.ts +0 -157
  168. package/components/DatePickerInline/DatePickerContext.tsx +0 -21
  169. package/components/DatePickerInput/DatePickerInput.tsx +0 -139
  170. package/components/DatePickerInput/DatePickerInputModal.tsx +0 -48
  171. package/components/DatePickerInput/DatePickerInputWithoutModal.tsx +0 -77
  172. package/components/DatePickerInput/DateRangeInput.tsx +0 -88
  173. package/components/DatePickerInput/index.tsx +0 -10
  174. package/components/DatePickerInput/types.ts +0 -28
  175. package/components/DatePickerInput/utils.ts +0 -15
  176. package/components/DatePickerModal/AnimatedCrossView.tsx +0 -94
  177. package/components/DatePickerModal/CalendarEdit.tsx +0 -139
  178. package/components/DatePickerModal/DatePickerModal.tsx +0 -85
  179. package/components/DatePickerModal/DatePickerModalContent.tsx +0 -155
  180. package/components/DatePickerModal/DatePickerModalContentHeader.tsx +0 -213
  181. package/components/DatePickerModal/DatePickerModalHeader.tsx +0 -74
  182. package/components/DatePickerModal/DatePickerModalHeaderBackground.tsx +0 -13
  183. package/components/DatePickerModal/index.tsx +0 -16
  184. package/components/DatePickerModal/types.ts +0 -92
  185. package/components/DatePickerModal/utils.ts +0 -122
  186. package/components/DateTimePicker/DateTimePicker.tsx +0 -172
  187. package/components/DateTimePicker/index.tsx +0 -10
  188. package/components/DateTimePicker/utils.ts +0 -12
  189. package/components/HorizontalDivider/HorizontalDivider.tsx +0 -103
  190. package/components/HorizontalDivider/index.tsx +0 -9
  191. package/components/ListItem/ListItem.tsx +0 -136
  192. package/components/ListItem/ListItemDescription.tsx +0 -25
  193. package/components/ListItem/ListItemTitle.tsx +0 -25
  194. package/components/ListItem/index.tsx +0 -14
  195. package/components/ListItem/utils.ts +0 -115
  196. package/components/Menu/MenuDivider.tsx +0 -13
  197. package/components/Menu/MenuItem.tsx +0 -128
  198. package/components/Popover/Popover.native.tsx +0 -185
  199. package/components/RadioButton/RadioButton.tsx +0 -138
  200. package/components/RadioButton/RadioButtonAndroid.tsx +0 -188
  201. package/components/RadioButton/RadioButtonGroup.tsx +0 -98
  202. package/components/RadioButton/RadioButtonIOS.tsx +0 -106
  203. package/components/RadioButton/RadioButtonItem.tsx +0 -232
  204. package/components/RadioButton/index.ts +0 -22
  205. package/components/RadioButton/utils.ts +0 -165
  206. package/components/TimePickerField/TimePickerField.tsx +0 -152
  207. package/components/TimePickerField/index.tsx +0 -10
  208. package/components/TimePickerField/utils.ts +0 -94
  209. package/components/TimePickerModal/TimePickerModal.tsx +0 -115
  210. package/components/TimePickerModal/index.tsx +0 -10
  211. package/components/TimePickerModal/utils.ts +0 -47
  212. package/components/VerticalDivider/VerticalDivider.tsx +0 -100
  213. package/components/VerticalDivider/index.tsx +0 -9
  214. package/context-bridge/index.tsx +0 -87
  215. package/fast-context/index.tsx +0 -190
  216. package/hocs/typedMemo.tsx +0 -5
  217. package/hooks/useControlledValue.tsx +0 -68
  218. package/hooks/useLatest.tsx +0 -9
  219. package/hooks/useMergedRefs.ts +0 -14
  220. package/hooks/usePrevious.ts +0 -13
  221. package/hooks/useSearchable.tsx +0 -74
  222. package/hooks/useSubcomponents.tsx +0 -59
  223. package/hooks/useToggle.tsx +0 -24
  224. package/utils/color.ts +0 -22
  225. package/utils/compare/index.ts +0 -54
  226. package/utils/lodash.ts +0 -49
  227. package/utils/repository.ts +0 -53
@@ -1,9 +1,7 @@
1
- import { memo, useCallback, useMemo } from 'react';
1
+ import { memo, useMemo } from 'react';
2
2
  import { View } from 'react-native';
3
3
 
4
- import { format } from '../../utils/date-fns';
5
4
  import { Text } from '../Text';
6
- import { useDatePickerStoreValue } from './DatePickerContext';
7
5
  import { getCalendarHeaderHeight } from './DatePickerInlineHeader';
8
6
  import {
9
7
  addMonths,
@@ -14,6 +12,7 @@ import {
14
12
  getRealIndex,
15
13
  gridCounts,
16
14
  startAtIndex,
15
+ totalMonths,
17
16
  useRangeChecker,
18
17
  } from './dateUtils';
19
18
  import type { MonthMultiProps, MonthRangeProps, MonthSingleProps } from './types';
@@ -42,11 +41,10 @@ function Month(props: MonthSingleProps | MonthRangeProps | MonthMultiProps) {
42
41
  scrollMode,
43
42
  disableWeekDays,
44
43
  validRange,
44
+ showOutsideDays,
45
+ locale,
45
46
  // customMonthStyles,
46
47
  } = props;
47
- const { localDate } = useDatePickerStoreValue(state => ({ localDate: state.localDate }));
48
- // const monthStyles = useComponentStyles('DatePicker_Month', customMonthStyles);
49
-
50
48
  const isHorizontal = scrollMode === 'horizontal';
51
49
  const { isDisabled, isWithinValidRange } = useRangeChecker(validRange);
52
50
 
@@ -54,11 +52,12 @@ function Month(props: MonthSingleProps | MonthRangeProps | MonthMultiProps) {
54
52
  const realIndex = getRealIndex(index);
55
53
 
56
54
  const md = addMonths(new Date(), realIndex);
57
- const y = mode === 'single' ? localDate.getFullYear() : md.getFullYear();
58
- const m = mode === 'single' ? localDate.getMonth() : md.getMonth();
55
+ const y = md.getFullYear();
56
+ const m = md.getMonth();
57
+ const name = new Intl.DateTimeFormat(locale, { month: 'long' }).format(md);
59
58
 
60
- return { monthName: format(md, 'LLLL'), month: m, year: y };
61
- }, [index, localDate, mode]);
59
+ return { monthName: name, month: m, year: y };
60
+ }, [index, locale]);
62
61
 
63
62
  const grid = useMemo(
64
63
  () =>
@@ -78,67 +77,34 @@ function Month(props: MonthSingleProps | MonthRangeProps | MonthMultiProps) {
78
77
  [year, month, index, isDisabled, mode, isWithinValidRange, startDate, endDate, dates, date],
79
78
  );
80
79
 
81
- const { headerStyle, yearButtonStyle, yearInnerStyle, monthLabelStyle, weekContainerStyle } =
82
- useMemo(() => {
83
- // const {
84
- // monthLabel: _monthLabel,
85
- // yearButton,
86
- // yearButtonInner,
87
- // month: _monthStyle,
88
- // monthHeader,
89
- // dockedHeaderStyle,
90
- // weekContainerStyle: weekContainer,
91
- // } = monthStyles;
92
- // const { typescale, ...monthLabel } = _monthLabel;
93
-
94
- return {
95
- headerStyle: [
96
- datePickerMonthStyles.monthHeader,
97
- isHorizontal
98
- ? [
99
- datePickerMonthStyles.dockedHeaderStyle,
100
- {
101
- marginTop: monthHeaderSingleMarginTop,
102
- marginBottom: monthHeaderSingleMarginBottom,
103
- },
104
- ]
105
- : null,
106
- ],
107
- yearButtonStyle: datePickerMonthStyles.yearButton,
108
- yearInnerStyle: datePickerMonthStyles.yearButtonInner,
109
- monthLabelStyle: [datePickerMonthStyles.monthLabel],
110
- weekContainerStyle: datePickerMonthStyles.weekContainerStyle,
111
- };
112
- }, [isHorizontal]);
113
-
114
- const renderHeader = useCallback(() => {
115
- if (!isHorizontal) {
116
- return (
80
+ const headerStyle = [
81
+ datePickerMonthStyles.monthHeader,
82
+ isHorizontal
83
+ ? [
84
+ datePickerMonthStyles.dockedHeaderStyle,
85
+ {
86
+ marginTop: monthHeaderSingleMarginTop,
87
+ marginBottom: monthHeaderSingleMarginBottom,
88
+ },
89
+ ]
90
+ : null,
91
+ ];
92
+
93
+ return (
94
+ <View>
95
+ {!isHorizontal ? (
117
96
  <View style={headerStyle}>
118
- <View accessibilityLabel={`${monthName} ${year}`} style={yearButtonStyle}>
119
- <View style={yearInnerStyle}>
120
- <Text style={monthLabelStyle} selectable={false}>
97
+ <View
98
+ accessibilityLabel={`${monthName} ${year}`}
99
+ style={[datePickerMonthStyles.yearButton]}>
100
+ <View style={[datePickerMonthStyles.yearButtonInner]}>
101
+ <Text style={datePickerMonthStyles.monthLabel} selectable={false}>
121
102
  {monthName} {year}
122
103
  </Text>
123
104
  </View>
124
105
  </View>
125
106
  </View>
126
- );
127
- }
128
- return null;
129
- }, [
130
- headerStyle,
131
- isHorizontal,
132
- monthLabelStyle,
133
- monthName,
134
- year,
135
- yearButtonStyle,
136
- yearInnerStyle,
137
- ]);
138
-
139
- return (
140
- <View>
141
- {renderHeader()}
107
+ ) : null}
142
108
  {grid.map(({ weekIndex, generatedDays }) => (
143
109
  <Week
144
110
  key={weekIndex}
@@ -146,7 +112,8 @@ function Month(props: MonthSingleProps | MonthRangeProps | MonthMultiProps) {
146
112
  generatedDays={generatedDays}
147
113
  disableWeekDays={disableWeekDays}
148
114
  onPressDate={onPressDate}
149
- style={weekContainerStyle}
115
+ showOutsideDays={showOutsideDays}
116
+ style={datePickerMonthStyles.weekContainerStyle}
150
117
  />
151
118
  ))}
152
119
  </View>
@@ -190,7 +157,21 @@ function weeksOffset(index: number): number {
190
157
  }
191
158
 
192
159
  export function getIndexFromHorizontalOffset(offset: number, width: number): number {
193
- return startAtIndex + Math.floor(offset / width);
160
+ if (!Number.isFinite(offset) || !Number.isFinite(width) || width <= 1) {
161
+ return startAtIndex;
162
+ }
163
+
164
+ const rawIndex = startAtIndex + Math.floor(offset / width);
165
+
166
+ if (rawIndex < 0) {
167
+ return 0;
168
+ }
169
+
170
+ if (rawIndex >= totalMonths) {
171
+ return totalMonths - 1;
172
+ }
173
+
174
+ return rawIndex;
194
175
  }
195
176
 
196
177
  export function getIndexFromVerticalOffset(offset: number): number {
@@ -1,148 +1,133 @@
1
- import { format, setMonth } from 'date-fns';
2
- import { memo, useCallback, useMemo, useRef } from 'react';
1
+ import { setMonth } from 'date-fns';
2
+ import { memo, useCallback, useMemo } from 'react';
3
3
  import { FlatList, View, type ViewStyle } from 'react-native';
4
4
  import { StyleSheet } from 'react-native-unistyles';
5
5
 
6
6
  import { resolveStateVariant } from '../../utils';
7
7
  import { range } from '../../utils/dateTimePicker';
8
- import {
9
- datePickerDockedMonthItemStyles,
10
- datePickerMonthPickerStyles,
11
- } from '../DatePickerDocked/utils';
12
- import { HorizontalDivider } from '../HorizontalDivider';
8
+ import type { DatePickerLocale } from '../DatePicker/context';
9
+ import { datePickerMonthItemStyles, datePickerMonthPickerStyles } from '../DatePicker/utils';
10
+ import { Divider } from '../Divider';
13
11
  import { Icon } from '../Icon';
14
- import { ListItem } from '../ListItem/';
12
+ import { List, type ListItemId, useListContextValue } from '../List';
15
13
  import { Text } from '../Text';
16
- import { useDatePickerStore, useDatePickerStoreValue } from './DatePickerContext';
14
+ import { useDatePickerInlineStore, useDatePickerInlineStoreValue } from './store';
17
15
 
18
- export default function MonthPicker() {
19
- const [_, setStore] = useDatePickerStore(state => state);
20
- const { localDate, selectingMonth } = useDatePickerStoreValue(state => ({
16
+ type MonthListItem = { id: number; label: string };
17
+
18
+ export default function MonthPicker({ locale }: { locale?: DatePickerLocale }) {
19
+ const [_, setStore] = useDatePickerInlineStore(state => state);
20
+ const { localDate, selectingMonth } = useDatePickerInlineStoreValue(state => ({
21
21
  localDate: state.localDate,
22
22
  selectingMonth: state.pickerType === 'month',
23
23
  }));
24
- // const monthPickerStyles = useComponentStyles('DatePickerDocked_MonthPicker');
25
- const flatList = useRef<FlatList<number> | null>(null);
26
24
  const months = range(0, 11);
27
-
28
- const { containerStyle, monthStyle } = useMemo(() => {
29
- const { backgroundColor, ...rest } = datePickerMonthPickerStyles.root;
30
-
31
- return {
32
- containerStyle: [
33
- StyleSheet.absoluteFill,
34
- styles.root,
35
- { backgroundColor },
36
- selectingMonth ? styles.opacity1 : styles.opacity0,
37
- ],
38
- monthStyle: rest,
39
- };
40
- }, [selectingMonth]);
25
+ const monthItems = useMemo<MonthListItem[]>(
26
+ () => months.map(month => ({ id: month, label: String(month) })),
27
+ [months],
28
+ );
41
29
 
42
30
  const handleOnChange = useCallback(
43
- (month: number) => {
31
+ (value: ListItemId | null) => {
32
+ if (typeof value !== 'number') return;
44
33
  setStore(prev => ({
45
- localDate: setMonth(prev.localDate, month),
34
+ localDate: setMonth(prev.localDate, value),
46
35
  pickerType: undefined,
47
36
  }));
48
37
  },
49
38
  [setStore],
50
39
  );
51
40
 
52
- const renderItem = useCallback(
53
- ({ item }: { item: number }) => {
54
- return (
55
- <Month
56
- month={item}
57
- selected={localDate.getMonth() === item}
58
- onPressMonth={handleOnChange}
59
- monthStyles={monthStyle}
60
- />
61
- );
62
- },
63
- [localDate, handleOnChange, monthStyle],
64
- );
65
-
66
41
  if (!selectingMonth) {
67
42
  return null;
68
43
  }
69
44
 
70
45
  return (
71
- <View style={containerStyle} pointerEvents={selectingMonth ? 'auto' : 'none'}>
72
- <HorizontalDivider />
73
- <FlatList<number>
74
- ref={flatList}
75
- style={styles.list}
76
- data={months}
77
- renderItem={renderItem}
78
- keyExtractor={item => `${item}`}
79
- />
80
- </View>
46
+ <List multiple={false} value={localDate.getMonth()} onChange={handleOnChange}>
47
+ <View
48
+ style={[
49
+ StyleSheet.absoluteFill,
50
+ styles.root,
51
+ selectingMonth ? styles.opacity1 : styles.opacity0,
52
+ ]}
53
+ pointerEvents={selectingMonth ? 'auto' : 'none'}>
54
+ <Divider />
55
+ <FlatList<MonthListItem>
56
+ style={styles.list}
57
+ data={monthItems}
58
+ renderItem={({ item }) => (
59
+ <Month
60
+ month={item.id}
61
+ monthStyles={datePickerMonthPickerStyles.root}
62
+ locale={locale}
63
+ />
64
+ )}
65
+ keyExtractor={item => `${item.id}`}
66
+ />
67
+ </View>
68
+ </List>
81
69
  );
82
70
  }
83
71
 
84
72
  function MonthPure({
85
73
  month,
86
- selected,
87
- onPressMonth,
88
74
  monthStyles,
75
+ locale,
89
76
  }: {
90
77
  month: number;
91
- selected: boolean;
92
- onPressMonth: (newMonth: number) => any;
93
78
  monthStyles: ViewStyle;
79
+ locale?: DatePickerLocale;
94
80
  }) {
81
+ const isSelected = useListContextValue(state => {
82
+ const selectedValue = state.value as any;
83
+ return (selectedValue?.id ?? selectedValue) === month;
84
+ });
85
+
95
86
  const state = resolveStateVariant({
96
- selected,
87
+ selected: isSelected,
97
88
  });
98
- datePickerDockedMonthItemStyles.useVariants({
89
+
90
+ datePickerMonthItemStyles.useVariants({
99
91
  state: state as any,
100
92
  });
101
- // const montLocalStyles = useComponentStyles('DatePickerDocked_MonthItem', monthStyles, {
102
- // state: resolveStateVariant({
103
- // selected,
104
- // }),
105
- // });
106
- const { monthInnerStyle, monthLabelStyle, monthButtonStyle, accessibilityState } =
107
- useMemo(() => {
108
- const { monthInner, monthLabel, monthButton } = datePickerDockedMonthItemStyles;
109
-
110
- return {
111
- monthInnerStyle: monthInner,
112
- monthLabelStyle: monthLabel,
113
- monthButtonStyle: [monthButton, monthStyles],
114
- accessibilityState: { selected },
115
- };
116
- // eslint-disable-next-line react-hooks/exhaustive-deps
117
- }, [selected, monthStyles, state]);
118
-
119
- const handleMonthPress = useCallback(() => {
120
- onPressMonth(month);
121
- }, [onPressMonth, month]);
93
+
94
+ const { monthButtonStyle, accessibilityState } = useMemo(() => {
95
+ const { monthButton } = datePickerMonthItemStyles;
96
+
97
+ return {
98
+ monthButtonStyle: [monthButton, monthStyles],
99
+ accessibilityState: { selected: isSelected },
100
+ };
101
+ }, [isSelected, monthStyles]);
102
+
103
+ const monthLabel = useMemo(
104
+ () => new Intl.DateTimeFormat(locale, { month: 'long' }).format(new Date(2000, month, 1)),
105
+ [locale, month],
106
+ );
122
107
 
123
108
  return (
124
- <ListItem
125
- onPress={handleMonthPress}
109
+ <List.Item
110
+ value={month}
126
111
  accessibilityRole="button"
127
112
  accessibilityLabel={String(month)}
128
113
  accessibilityState={accessibilityState}
129
114
  style={monthButtonStyle}
130
- testID={`pick-month-${month}`}
131
- left={
132
- selected ? (
115
+ testID={`pick-month-${month}`}>
116
+ <View style={styles.left}>
117
+ {isSelected ? (
133
118
  <View style={styles.checkIconView}>
134
119
  <Icon name="check" size={24} />
135
120
  </View>
136
121
  ) : (
137
122
  <View style={styles.spacer} />
138
- )
139
- }>
140
- <View style={monthInnerStyle}>
141
- <Text style={monthLabelStyle} selectable={false}>
142
- {format(new Date(2000, month, 1), 'MMMM')}
123
+ )}
124
+ </View>
125
+ <View style={datePickerMonthItemStyles.monthInner}>
126
+ <Text style={datePickerMonthItemStyles.monthLabel} selectable={false}>
127
+ {monthLabel}
143
128
  </Text>
144
129
  </View>
145
- </ListItem>
130
+ </List.Item>
146
131
  );
147
132
  }
148
133
  const Month = memo(MonthPure);
@@ -161,6 +146,9 @@ const styles = StyleSheet.create(theme => ({
161
146
  spacer: {
162
147
  width: 44,
163
148
  },
149
+ left: {
150
+ marginRight: theme.spacings['2'],
151
+ },
164
152
 
165
153
  list: {
166
154
  flex: 1,
@@ -1,4 +1,4 @@
1
- import { memo, useCallback, useMemo, useRef, useState } from 'react';
1
+ import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
2
  import {
3
3
  type NativeScrollEvent,
4
4
  type NativeSyntheticEvent,
@@ -9,13 +9,15 @@ import {
9
9
  } from 'react-native';
10
10
 
11
11
  import AutoSizer from './AutoSizer';
12
- import { beginOffset, estimatedMonthHeight, totalMonths } from './dateUtils';
12
+ import { beginOffset, estimatedMonthHeight, getInitialIndex, totalMonths } from './dateUtils';
13
+ import { addMonths, getRealIndex } from './dateUtils';
13
14
  import {
14
15
  getHorizontalMonthOffset,
15
16
  getIndexFromVerticalOffset,
16
17
  getMonthHeight,
17
18
  getVerticalMonthsOffset,
18
19
  } from './Month';
20
+ import { useDatePickerInlineStore } from './store';
19
21
  import type { SwiperProps } from './SwiperUtils';
20
22
  import { montHeaderHeight } from './utils';
21
23
 
@@ -54,11 +56,16 @@ function SwiperInner({
54
56
  );
55
57
 
56
58
  const parentRef = useRef<ScrollView | null>(null);
59
+ const [{ localDate }, setStore] = useDatePickerInlineStore(state => state);
57
60
 
58
61
  const scrollTo = useCallback(
59
62
  (index: number, animated: boolean) => {
60
63
  idx.current = index;
61
64
  setVisibleIndexes(getVisibleArray(index, { isHorizontal, height }));
65
+ setStore(prev => ({
66
+ ...prev,
67
+ localDate: addMonths(new Date(), getRealIndex(index)),
68
+ }));
62
69
 
63
70
  if (!parentRef.current) {
64
71
  return;
@@ -81,13 +88,19 @@ function SwiperInner({
81
88
  });
82
89
  }
83
90
  },
84
- [parentRef, isHorizontal, width, height],
91
+ [parentRef, isHorizontal, width, height, setStore],
85
92
  );
86
93
 
87
94
  const scrollToInitial = useCallback(() => {
88
95
  scrollTo(idx.current, false);
89
96
  }, [scrollTo]);
90
97
 
98
+ useEffect(() => {
99
+ const targetIndex = getInitialIndex(localDate);
100
+ if (targetIndex === idx.current) return;
101
+ scrollTo(targetIndex, false);
102
+ }, [localDate, scrollTo]);
103
+
91
104
  const onMomentumScrollEnd = useCallback(
92
105
  (e: NativeSyntheticEvent<NativeScrollEvent>) => {
93
106
  const contentOffset = e.nativeEvent.contentOffset;
@@ -103,9 +116,13 @@ function SwiperInner({
103
116
  if (idx.current !== newIndex) {
104
117
  idx.current = newIndex;
105
118
  setVisibleIndexes(getVisibleArray(newIndex, { isHorizontal, height }));
119
+ setStore(prev => ({
120
+ ...prev,
121
+ localDate: addMonths(new Date(), getRealIndex(newIndex)),
122
+ }));
106
123
  }
107
124
  },
108
- [idx, height, isHorizontal],
125
+ [idx, height, isHorizontal, setStore],
109
126
  );
110
127
 
111
128
  const { innerContainerStyle, itemContainerStyle } = useMemo(() => {