react-native-molecules 0.5.0-beta.3 → 0.5.0-beta.30
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.
- package/components/Accordion/Accordion.tsx +2 -6
- package/components/Accordion/AccordionItem.tsx +16 -12
- package/components/Accordion/AccordionItemContent.tsx +6 -1
- package/components/Accordion/AccordionItemHeader.tsx +1 -1
- package/components/Accordion/utils.ts +6 -0
- package/components/ActivityIndicator/ActivityIndicator.tsx +6 -15
- package/components/Appbar/AppbarBase.tsx +18 -13
- package/components/Button/Button.tsx +211 -264
- package/components/Button/index.tsx +9 -3
- package/components/Button/types.ts +16 -2
- package/components/Button/utils.ts +230 -208
- package/components/Card/Card.tsx +1 -1
- package/components/Checkbox/Checkbox.tsx +125 -88
- package/components/Checkbox/CheckboxBase.ios.tsx +14 -23
- package/components/Checkbox/CheckboxBase.tsx +21 -137
- package/components/Checkbox/context.tsx +14 -0
- package/components/Checkbox/index.tsx +11 -4
- package/components/Checkbox/types.ts +63 -29
- package/components/Checkbox/utils.ts +25 -108
- package/components/Chip/Chip.tsx +41 -52
- package/components/Chip/utils.ts +3 -7
- package/components/DateField/DateField.tsx +111 -0
- package/components/DateField/index.tsx +6 -0
- package/components/{DatePickerInput/inputUtils.ts → DateField/useDateFieldState.ts} +19 -51
- package/components/DatePicker/DateCalendar.tsx +83 -0
- package/components/DatePicker/DatePickerActions.tsx +73 -0
- package/components/DatePicker/DatePickerModal.tsx +246 -0
- package/components/DatePicker/DatePickerPopover.tsx +79 -0
- package/components/DatePicker/DatePickerProvider.tsx +158 -0
- package/components/DatePicker/DatePickerTrigger.tsx +23 -0
- package/components/DatePicker/context.tsx +83 -0
- package/components/DatePicker/index.tsx +45 -0
- package/components/DatePicker/utils.ts +295 -0
- package/components/DatePickerInline/DatePickerDockedHeader.tsx +117 -0
- package/components/DatePickerInline/DatePickerInline.tsx +17 -16
- package/components/DatePickerInline/DatePickerInlineBase.tsx +11 -5
- package/components/DatePickerInline/DatePickerInlineHeader.tsx +50 -20
- package/components/DatePickerInline/Day.tsx +25 -1
- package/components/DatePickerInline/DayNames.tsx +13 -10
- package/components/DatePickerInline/DayRange.tsx +2 -4
- package/components/DatePickerInline/HeaderItem.tsx +44 -29
- package/components/DatePickerInline/Month.tsx +48 -67
- package/components/DatePickerInline/MonthPicker.tsx +80 -92
- package/components/DatePickerInline/Swiper.native.tsx +21 -4
- package/components/DatePickerInline/Swiper.tsx +169 -14
- package/components/DatePickerInline/SwiperUtils.ts +1 -1
- package/components/DatePickerInline/Week.tsx +6 -1
- package/components/DatePickerInline/YearPicker.tsx +220 -78
- package/components/DatePickerInline/dateUtils.tsx +18 -13
- package/components/DatePickerInline/store.tsx +27 -0
- package/components/DatePickerInline/types.ts +6 -2
- package/components/DatePickerInline/utils.ts +66 -29
- package/components/Divider/Divider.tsx +192 -0
- package/components/Divider/index.tsx +10 -0
- package/components/Drawer/Drawer.tsx +17 -6
- package/components/Drawer/DrawerItemGroup.tsx +3 -7
- package/components/ElementGroup/ElementGroup.tsx +1 -1
- package/components/FilePicker/FilePicker.tsx +48 -78
- package/components/FilePicker/index.tsx +2 -1
- package/components/FilePicker/utils.ts +9 -0
- package/components/HelperText/HelperText.tsx +0 -35
- package/components/Icon/iconFactory.tsx +5 -4
- package/components/Icon/index.tsx +1 -1
- package/components/Icon/types.ts +17 -6
- package/components/IconButton/IconButton.tsx +84 -84
- package/components/IconButton/index.tsx +1 -0
- package/components/IconButton/types.ts +10 -0
- package/components/IconButton/utils.ts +167 -33
- package/components/List/List.tsx +276 -0
- package/components/List/context.tsx +27 -0
- package/components/List/index.ts +8 -0
- package/components/List/types.ts +117 -0
- package/components/List/utils.ts +79 -0
- package/components/LoadingIndicator/LoadingIndicator.tsx +253 -0
- package/components/LoadingIndicator/LoadingIndicator.web.tsx +136 -0
- package/components/LoadingIndicator/index.tsx +13 -0
- package/components/LoadingIndicator/utils.ts +117 -0
- package/components/Menu/Menu.tsx +162 -39
- package/components/Menu/index.tsx +10 -7
- package/components/Menu/utils.ts +21 -70
- package/components/NavigationRail/NavigationRail.tsx +15 -9
- package/components/Popover/Popover.tsx +119 -145
- package/components/Popover/PopoverRoot.tsx +60 -0
- package/components/Popover/common.ts +54 -34
- package/components/Popover/index.ts +12 -1
- package/components/Popover/usePlatformMeasure.native.ts +90 -0
- package/components/Popover/usePlatformMeasure.ts +120 -0
- package/components/Popover/utils.ts +34 -0
- package/components/Portal/Portal.tsx +1 -2
- package/components/Radio/Radio.tsx +188 -0
- package/components/Radio/RadioBase.ios.tsx +69 -0
- package/components/Radio/RadioBase.tsx +136 -0
- package/components/Radio/context.tsx +23 -0
- package/components/Radio/index.tsx +20 -0
- package/components/Radio/types.ts +101 -0
- package/components/Radio/utils.ts +115 -0
- package/components/Rating/Rating.tsx +1 -1
- package/components/Select/Select.tsx +521 -785
- package/components/Select/context.tsx +81 -0
- package/components/Select/index.ts +26 -14
- package/components/Select/types.ts +65 -58
- package/components/Select/utils.ts +126 -0
- package/components/Slot/Slot.tsx +244 -0
- package/components/Slot/compose-refs.tsx +62 -0
- package/components/Slot/index.tsx +8 -0
- package/components/Surface/Surface.android.tsx +32 -7
- package/components/Surface/Surface.ios.tsx +34 -29
- package/components/Surface/Surface.tsx +31 -4
- package/components/Surface/utils.ts +44 -6
- package/components/Switch/Switch.ios.tsx +1 -1
- package/components/Switch/Switch.tsx +10 -3
- package/components/Tabs/TabItem.tsx +35 -58
- package/components/Tabs/TabLabel.tsx +5 -9
- package/components/Tabs/Tabs.tsx +156 -150
- package/components/Tabs/utils.ts +15 -2
- package/components/Text/textFactory.tsx +17 -5
- package/components/TextInput/TextInput.tsx +663 -579
- package/components/TextInput/index.tsx +19 -3
- package/components/TextInput/types.ts +77 -28
- package/components/TextInput/utils.ts +235 -145
- package/components/TimeField/TimeField.tsx +75 -0
- package/components/TimeField/index.tsx +6 -0
- package/components/TimeField/useTimeFieldState.ts +70 -0
- package/components/{TimePickerField/sanitizeTime.ts → TimeField/utils.ts} +77 -10
- package/components/TimePicker/AnalogClock.tsx +1 -1
- package/components/TimePicker/TimeInput.tsx +87 -42
- package/components/TimePicker/TimeInputs.tsx +138 -50
- package/components/TimePicker/TimePicker.tsx +74 -11
- package/components/TimePicker/TimePickerModal.tsx +186 -0
- package/components/TimePicker/context.tsx +17 -0
- package/components/TimePicker/index.tsx +15 -3
- package/components/TimePicker/utils.ts +93 -4
- package/components/Tooltip/Tooltip.tsx +42 -67
- package/components/Tooltip/TooltipContent.tsx +32 -5
- package/components/Tooltip/TooltipTrigger.tsx +20 -20
- package/components/Tooltip/index.tsx +1 -1
- package/components/TouchableRipple/TouchableRipple.native.tsx +83 -16
- package/components/TouchableRipple/TouchableRipple.tsx +150 -102
- package/components/TouchableRipple/rippleFromForegroundColor.ts +21 -0
- package/hocs/index.tsx +1 -1
- package/hocs/withKeyboardAccessibility.tsx +2 -3
- package/hocs/withPortal.tsx +1 -1
- package/hooks/index.tsx +2 -12
- package/hooks/useActionState.tsx +19 -8
- package/hooks/useContrastColor.ts +1 -2
- package/hooks/useFilePicker.tsx +7 -17
- package/hooks/useHandleNumberFormat.tsx +2 -2
- package/hooks/useMediaQuery.tsx +1 -2
- package/package.json +95 -111
- package/shortcuts-manager/ShortcutsManager/ShortcutsManager.tsx +6 -3
- package/shortcuts-manager/ShortcutsManager/utils.tsx +1 -1
- package/shortcuts-manager/useSetScopes/useSetScopes.tsx +1 -1
- package/shortcuts-manager/useShortcut/useShortcut.tsx +1 -1
- package/styles/shadow.ts +2 -1
- package/styles/themes/LightTheme.tsx +1 -1
- package/utils/DocumentPicker/documentPicker.ts +78 -27
- package/utils/DocumentPicker/types.ts +0 -1
- package/utils/extractSubcomponents.ts +89 -0
- package/utils/extractTextStyles.ts +1 -2
- package/utils/formatNumberWithMask/formatNumberWithMask.ts +2 -1
- package/utils/index.ts +0 -3
- package/utils/normalizeToNumberString/normalizeToNumberString.ts +1 -1
- package/components/DatePickerDocked/DatePickerDocked.tsx +0 -30
- package/components/DatePickerDocked/DatePickerDockedHeader.tsx +0 -129
- package/components/DatePickerDocked/index.tsx +0 -17
- package/components/DatePickerDocked/types.ts +0 -11
- package/components/DatePickerDocked/utils.ts +0 -157
- package/components/DatePickerInline/DatePickerContext.tsx +0 -21
- package/components/DatePickerInput/DatePickerInput.tsx +0 -139
- package/components/DatePickerInput/DatePickerInputModal.tsx +0 -48
- package/components/DatePickerInput/DatePickerInputWithoutModal.tsx +0 -77
- package/components/DatePickerInput/DateRangeInput.tsx +0 -88
- package/components/DatePickerInput/index.tsx +0 -10
- package/components/DatePickerInput/types.ts +0 -28
- package/components/DatePickerInput/utils.ts +0 -15
- package/components/DatePickerModal/AnimatedCrossView.tsx +0 -94
- package/components/DatePickerModal/CalendarEdit.tsx +0 -139
- package/components/DatePickerModal/DatePickerModal.tsx +0 -85
- package/components/DatePickerModal/DatePickerModalContent.tsx +0 -155
- package/components/DatePickerModal/DatePickerModalContentHeader.tsx +0 -213
- package/components/DatePickerModal/DatePickerModalHeader.tsx +0 -74
- package/components/DatePickerModal/DatePickerModalHeaderBackground.tsx +0 -13
- package/components/DatePickerModal/index.tsx +0 -16
- package/components/DatePickerModal/types.ts +0 -92
- package/components/DatePickerModal/utils.ts +0 -122
- package/components/DateTimePicker/DateTimePicker.tsx +0 -172
- package/components/DateTimePicker/index.tsx +0 -10
- package/components/DateTimePicker/utils.ts +0 -12
- package/components/HorizontalDivider/HorizontalDivider.tsx +0 -103
- package/components/HorizontalDivider/index.tsx +0 -9
- package/components/ListItem/ListItem.tsx +0 -136
- package/components/ListItem/ListItemDescription.tsx +0 -25
- package/components/ListItem/ListItemTitle.tsx +0 -25
- package/components/ListItem/index.tsx +0 -14
- package/components/ListItem/utils.ts +0 -115
- package/components/Menu/MenuDivider.tsx +0 -13
- package/components/Menu/MenuItem.tsx +0 -128
- package/components/Popover/Popover.native.tsx +0 -185
- package/components/RadioButton/RadioButton.tsx +0 -138
- package/components/RadioButton/RadioButtonAndroid.tsx +0 -188
- package/components/RadioButton/RadioButtonGroup.tsx +0 -98
- package/components/RadioButton/RadioButtonIOS.tsx +0 -106
- package/components/RadioButton/RadioButtonItem.tsx +0 -232
- package/components/RadioButton/index.ts +0 -22
- package/components/RadioButton/utils.ts +0 -165
- package/components/TimePickerField/TimePickerField.tsx +0 -152
- package/components/TimePickerField/index.tsx +0 -10
- package/components/TimePickerField/utils.ts +0 -94
- package/components/TimePickerModal/TimePickerModal.tsx +0 -115
- package/components/TimePickerModal/index.tsx +0 -10
- package/components/TimePickerModal/utils.ts +0 -47
- package/components/VerticalDivider/VerticalDivider.tsx +0 -100
- package/components/VerticalDivider/index.tsx +0 -9
- package/context-bridge/index.tsx +0 -87
- package/fast-context/index.tsx +0 -190
- package/hocs/typedMemo.tsx +0 -5
- package/hooks/useControlledValue.tsx +0 -68
- package/hooks/useLatest.tsx +0 -9
- package/hooks/useMergedRefs.ts +0 -14
- package/hooks/usePrevious.ts +0 -13
- package/hooks/useSearchable.tsx +0 -74
- package/hooks/useSubcomponents.tsx +0 -59
- package/hooks/useToggle.tsx +0 -24
- package/utils/color.ts +0 -22
- package/utils/compare/index.ts +0 -54
- package/utils/lodash.ts +0 -49
- package/utils/repository.ts +0 -53
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { memo,
|
|
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 =
|
|
58
|
-
const m =
|
|
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:
|
|
61
|
-
}, [index,
|
|
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
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
2
|
-
import { memo, useCallback, useMemo
|
|
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
|
-
|
|
10
|
-
|
|
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 {
|
|
12
|
+
import { List, type ListItemId, useListContextValue } from '../List';
|
|
15
13
|
import { Text } from '../Text';
|
|
16
|
-
import {
|
|
14
|
+
import { useDatePickerInlineStore, useDatePickerInlineStoreValue } from './store';
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
29
|
-
|
|
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
|
-
(
|
|
31
|
+
(value: ListItemId | null) => {
|
|
32
|
+
if (typeof value !== 'number') return;
|
|
44
33
|
setStore(prev => ({
|
|
45
|
-
localDate: setMonth(prev.localDate,
|
|
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
|
-
<
|
|
72
|
-
<
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
89
|
+
|
|
90
|
+
datePickerMonthItemStyles.useVariants({
|
|
99
91
|
state: state as any,
|
|
100
92
|
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
<
|
|
125
|
-
|
|
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
|
-
|
|
132
|
-
|
|
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={
|
|
141
|
-
<Text style={
|
|
142
|
-
{
|
|
123
|
+
)}
|
|
124
|
+
</View>
|
|
125
|
+
<View style={datePickerMonthItemStyles.monthInner}>
|
|
126
|
+
<Text style={datePickerMonthItemStyles.monthLabel} selectable={false}>
|
|
127
|
+
{monthLabel}
|
|
143
128
|
</Text>
|
|
144
129
|
</View>
|
|
145
|
-
</
|
|
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(() => {
|