react-native-molecules 0.5.0-beta.15 → 0.5.0-beta.17
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/AccordionItem.tsx +1 -7
- package/components/DateField/DateField.tsx +110 -0
- package/components/DateField/index.tsx +6 -0
- package/components/{DatePickerInput/inputUtils.ts → DateField/useDateFieldState.ts} +17 -49
- package/components/DatePicker/DateCalendar.tsx +83 -0
- package/components/DatePicker/DatePickerActions.tsx +73 -0
- package/components/DatePicker/DatePickerModal.tsx +234 -0
- package/components/DatePicker/DatePickerPopover.tsx +79 -0
- package/components/DatePicker/DatePickerProvider.tsx +152 -0
- package/components/DatePicker/DatePickerTrigger.tsx +23 -0
- package/components/DatePicker/context.tsx +82 -0
- package/components/DatePicker/index.tsx +44 -0
- package/components/DatePicker/utils.ts +292 -0
- package/components/DatePickerInline/DatePickerContext.tsx +1 -0
- package/components/DatePickerInline/DatePickerDockedHeader.tsx +113 -0
- package/components/DatePickerInline/DatePickerInline.tsx +16 -15
- package/components/DatePickerInline/DatePickerInlineBase.tsx +7 -1
- package/components/DatePickerInline/Day.tsx +25 -1
- package/components/DatePickerInline/DayRange.tsx +2 -4
- package/components/DatePickerInline/HeaderItem.tsx +42 -27
- package/components/DatePickerInline/Month.tsx +45 -65
- package/components/DatePickerInline/MonthPicker.tsx +25 -41
- package/components/DatePickerInline/Swiper.native.tsx +21 -4
- package/components/DatePickerInline/Swiper.tsx +168 -13
- package/components/DatePickerInline/Week.tsx +6 -1
- package/components/DatePickerInline/YearPicker.tsx +206 -53
- package/components/DatePickerInline/dateUtils.tsx +17 -12
- package/components/DatePickerInline/types.ts +3 -0
- package/components/DatePickerInline/utils.ts +66 -29
- package/components/FilePicker/index.tsx +1 -1
- package/components/ListItem/ListItem.tsx +3 -1
- package/components/ListItem/utils.ts +1 -1
- package/components/LoadingIndicator/index.tsx +1 -1
- package/components/Popover/Popover.native.tsx +4 -25
- package/components/Popover/Popover.tsx +4 -26
- package/components/Popover/utils.ts +41 -0
- package/components/Select/Select.tsx +7 -8
- package/components/Select/context.tsx +72 -0
- package/components/Select/index.ts +1 -0
- package/components/Select/utils.ts +0 -71
- package/components/Slot/compose-refs.tsx +2 -0
- 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/TimePicker.tsx +53 -9
- 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 +50 -0
- package/hooks/useActionState.tsx +19 -8
- package/package.json +6 -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/DatePickerInput/DatePickerInput.tsx +0 -130
- package/components/DatePickerInput/DatePickerInputModal.tsx +0 -48
- package/components/DatePickerInput/DatePickerInputWithoutModal.tsx +0 -73
- package/components/DatePickerInput/DateRangeInput.tsx +0 -88
- package/components/DatePickerInput/index.tsx +0 -11
- package/components/DatePickerInput/types.ts +0 -26
- package/components/DatePickerInput/utils.ts +0 -24
- package/components/DatePickerModal/AnimatedCrossView.tsx +0 -94
- package/components/DatePickerModal/CalendarEdit.tsx +0 -140
- 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/TimePickerField/TimePickerField.tsx +0 -154
- package/components/TimePickerField/index.tsx +0 -10
- package/components/TimePickerField/utils.ts +0 -94
- package/components/TimePickerModal/TimePickerModal.tsx +0 -119
- package/components/TimePickerModal/index.tsx +0 -10
- package/components/TimePickerModal/utils.ts +0 -47
|
@@ -1,48 +1,70 @@
|
|
|
1
1
|
import { setYear } from 'date-fns';
|
|
2
|
-
import { memo, useCallback,
|
|
3
|
-
import { FlatList, StyleSheet, View } from 'react-native';
|
|
2
|
+
import { memo, useCallback, useLayoutEffect, useMemo, useRef } from 'react';
|
|
3
|
+
import { FlatList, ScrollView, StyleSheet, View } from 'react-native';
|
|
4
4
|
|
|
5
5
|
import { getYearRange, resolveStateVariant } from '../../utils';
|
|
6
|
+
import { datePickerMonthItemStyles, datePickerMonthPickerStyles } from '../DatePicker/utils';
|
|
6
7
|
import { HorizontalDivider } from '../HorizontalDivider';
|
|
8
|
+
import { Icon } from '../Icon';
|
|
7
9
|
import { ListItem } from '../ListItem';
|
|
10
|
+
import { Text } from '../Text';
|
|
8
11
|
import { useDatePickerStore } from './DatePickerContext';
|
|
9
12
|
import { datePickerYearItemStyles, datePickerYearPickerStyles } from './utils';
|
|
10
13
|
|
|
11
|
-
const
|
|
14
|
+
const GRID_ITEM_HEIGHT = 62;
|
|
15
|
+
const NUM_COLUMNS = 3;
|
|
16
|
+
const LIST_ITEM_HEIGHT = 46;
|
|
12
17
|
|
|
13
|
-
|
|
18
|
+
type YearPickerProps = {
|
|
19
|
+
layout?: 'grid' | 'list';
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default function YearPicker({ layout = 'grid' }: YearPickerProps) {
|
|
23
|
+
if (layout === 'list') return <YearPickerList />;
|
|
24
|
+
return <YearPickerGrid />;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function YearPickerGrid() {
|
|
14
28
|
const [{ startDateYear, endDateYear, localDate, pickerType }, setStore] = useDatePickerStore(
|
|
15
29
|
state => state,
|
|
16
30
|
);
|
|
17
|
-
const flatList = useRef<FlatList<number> | null>(null);
|
|
18
31
|
const years = useMemo(
|
|
19
32
|
() => getYearRange(startDateYear, endDateYear),
|
|
20
33
|
[startDateYear, endDateYear],
|
|
21
34
|
);
|
|
35
|
+
const rows = useMemo(() => {
|
|
36
|
+
const chunks: number[][] = [];
|
|
37
|
+
for (let i = 0; i < years.length; i += NUM_COLUMNS) {
|
|
38
|
+
chunks.push(years.slice(i, i + NUM_COLUMNS));
|
|
39
|
+
}
|
|
40
|
+
return chunks;
|
|
41
|
+
}, [years]);
|
|
22
42
|
const selectingYear = pickerType === 'year';
|
|
23
43
|
const selectedYear = localDate.getFullYear();
|
|
44
|
+
const scrollRef = useRef<ScrollView | null>(null);
|
|
24
45
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
46
|
+
const initialScrollOffset = useMemo(() => {
|
|
47
|
+
if (years.length === 0) return 0;
|
|
48
|
+
const totalRows = Math.ceil(years.length / NUM_COLUMNS);
|
|
49
|
+
const unclampedRow = Math.floor((selectedYear - years[0]) / NUM_COLUMNS);
|
|
50
|
+
const rowIndex = Math.min(Math.max(0, unclampedRow), Math.max(0, totalRows - 1));
|
|
51
|
+
return rowIndex * GRID_ITEM_HEIGHT;
|
|
52
|
+
}, [selectedYear, years]);
|
|
53
|
+
|
|
54
|
+
useLayoutEffect(() => {
|
|
55
|
+
if (!selectingYear) return;
|
|
56
|
+
scrollRef.current?.scrollTo({ y: initialScrollOffset, animated: false });
|
|
57
|
+
}, [selectingYear, initialScrollOffset]);
|
|
35
58
|
|
|
36
59
|
const { containerStyle, yearStyle } = useMemo(() => {
|
|
37
60
|
const { backgroundColor, ...rest } = datePickerYearPickerStyles.root;
|
|
38
|
-
|
|
39
61
|
return {
|
|
40
62
|
containerStyle: [
|
|
41
63
|
StyleSheet.absoluteFill,
|
|
42
|
-
|
|
64
|
+
gridStyles.root,
|
|
43
65
|
{ backgroundColor },
|
|
44
66
|
datePickerYearPickerStyles.yearContainer,
|
|
45
|
-
selectingYear ?
|
|
67
|
+
selectingYear ? gridStyles.opacity1 : gridStyles.opacity0,
|
|
46
68
|
],
|
|
47
69
|
yearStyle: rest,
|
|
48
70
|
};
|
|
@@ -59,32 +81,39 @@ export default function YearPicker() {
|
|
|
59
81
|
);
|
|
60
82
|
|
|
61
83
|
return (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
84
|
+
<View style={containerStyle} pointerEvents={selectingYear ? 'auto' : 'none'}>
|
|
85
|
+
<HorizontalDivider />
|
|
86
|
+
<ScrollView
|
|
87
|
+
ref={scrollRef}
|
|
88
|
+
style={gridStyles.list}
|
|
89
|
+
contentOffset={{ x: 0, y: initialScrollOffset }}
|
|
90
|
+
removeClippedSubviews>
|
|
91
|
+
<View style={gridStyles.grid}>
|
|
92
|
+
{rows.map((row, rowIdx) => (
|
|
93
|
+
<View key={rowIdx} style={gridStyles.row}>
|
|
94
|
+
{row.map(year => (
|
|
95
|
+
<View key={year} style={gridStyles.cell}>
|
|
96
|
+
<YearPill
|
|
97
|
+
year={year}
|
|
98
|
+
selected={selectedYear === year}
|
|
99
|
+
onPressYear={handleOnChange}
|
|
100
|
+
yearStyles={yearStyle}
|
|
101
|
+
/>
|
|
102
|
+
</View>
|
|
103
|
+
))}
|
|
104
|
+
{row.length < NUM_COLUMNS &&
|
|
105
|
+
Array.from({ length: NUM_COLUMNS - row.length }).map((_, i) => (
|
|
106
|
+
<View key={`pad-${i}`} style={gridStyles.cell} />
|
|
107
|
+
))}
|
|
108
|
+
</View>
|
|
109
|
+
))}
|
|
81
110
|
</View>
|
|
82
|
-
|
|
83
|
-
|
|
111
|
+
</ScrollView>
|
|
112
|
+
</View>
|
|
84
113
|
);
|
|
85
114
|
}
|
|
86
115
|
|
|
87
|
-
function
|
|
116
|
+
function YearPillPure({
|
|
88
117
|
year,
|
|
89
118
|
selected,
|
|
90
119
|
onPressYear,
|
|
@@ -96,9 +125,7 @@ function YearPure({
|
|
|
96
125
|
yearStyles: Record<string, any>;
|
|
97
126
|
}) {
|
|
98
127
|
datePickerYearItemStyles.useVariants({
|
|
99
|
-
state: resolveStateVariant({
|
|
100
|
-
selected,
|
|
101
|
-
}) as any,
|
|
128
|
+
state: resolveStateVariant({ selected }) as any,
|
|
102
129
|
});
|
|
103
130
|
|
|
104
131
|
const handlePressYear = useCallback(() => {
|
|
@@ -107,10 +134,11 @@ function YearPure({
|
|
|
107
134
|
|
|
108
135
|
return (
|
|
109
136
|
<ListItem
|
|
137
|
+
contentStyle={datePickerYearItemStyles.content}
|
|
110
138
|
onPress={handlePressYear}
|
|
111
139
|
accessibilityRole="button"
|
|
112
140
|
accessibilityLabel={String(year)}
|
|
113
|
-
style={[datePickerYearItemStyles.yearButton
|
|
141
|
+
style={[yearStyles, datePickerYearItemStyles.yearButton]}
|
|
114
142
|
testID={`pick-year-${year}`}>
|
|
115
143
|
<ListItem.Title style={datePickerYearItemStyles.yearLabel} selectable={false}>
|
|
116
144
|
{year}
|
|
@@ -118,22 +146,147 @@ function YearPure({
|
|
|
118
146
|
</ListItem>
|
|
119
147
|
);
|
|
120
148
|
}
|
|
121
|
-
const
|
|
149
|
+
const YearPill = memo(YearPillPure);
|
|
150
|
+
|
|
151
|
+
function YearPickerList() {
|
|
152
|
+
const [{ startDateYear, endDateYear, localDate, pickerType }, setStore] = useDatePickerStore(
|
|
153
|
+
state => state,
|
|
154
|
+
);
|
|
155
|
+
const flatList = useRef<FlatList<number> | null>(null);
|
|
156
|
+
const years = useMemo(
|
|
157
|
+
() => getYearRange(startDateYear, endDateYear),
|
|
158
|
+
[startDateYear, endDateYear],
|
|
159
|
+
);
|
|
160
|
+
const selectingYear = pickerType === 'year';
|
|
161
|
+
const selectedYear = localDate.getFullYear();
|
|
162
|
+
|
|
163
|
+
const initialScrollIndex = useMemo(() => {
|
|
164
|
+
if (years.length === 0) return 0;
|
|
165
|
+
const idx = years.indexOf(selectedYear);
|
|
166
|
+
return Math.max(0, idx);
|
|
167
|
+
}, [selectedYear, years]);
|
|
168
|
+
|
|
169
|
+
const handleOnChange = useCallback(
|
|
170
|
+
(year: number) => {
|
|
171
|
+
setStore(prev => ({
|
|
172
|
+
localDate: setYear(prev.localDate, year),
|
|
173
|
+
pickerType: undefined,
|
|
174
|
+
}));
|
|
175
|
+
},
|
|
176
|
+
[setStore],
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
const renderItem = useCallback(
|
|
180
|
+
({ item }: { item: number }) => (
|
|
181
|
+
<YearRow year={item} selected={selectedYear === item} onPressYear={handleOnChange} />
|
|
182
|
+
),
|
|
183
|
+
[selectedYear, handleOnChange],
|
|
184
|
+
);
|
|
122
185
|
|
|
123
|
-
const
|
|
186
|
+
const getItemLayout = useCallback(
|
|
187
|
+
(_data: any, index: number) => ({
|
|
188
|
+
length: LIST_ITEM_HEIGHT,
|
|
189
|
+
offset: LIST_ITEM_HEIGHT * index,
|
|
190
|
+
index,
|
|
191
|
+
}),
|
|
192
|
+
[],
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
if (!selectingYear) return null;
|
|
196
|
+
|
|
197
|
+
return (
|
|
198
|
+
<View style={[StyleSheet.absoluteFill, listStyles.root]} pointerEvents="auto">
|
|
199
|
+
<HorizontalDivider />
|
|
200
|
+
<FlatList<number>
|
|
201
|
+
ref={flatList}
|
|
202
|
+
style={listStyles.list}
|
|
203
|
+
data={years}
|
|
204
|
+
renderItem={renderItem}
|
|
205
|
+
keyExtractor={item => `${item}`}
|
|
206
|
+
initialScrollIndex={initialScrollIndex}
|
|
207
|
+
getItemLayout={getItemLayout}
|
|
208
|
+
/>
|
|
209
|
+
</View>
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function YearRowPure({
|
|
214
|
+
year,
|
|
215
|
+
selected,
|
|
216
|
+
onPressYear,
|
|
217
|
+
}: {
|
|
218
|
+
year: number;
|
|
219
|
+
selected: boolean;
|
|
220
|
+
onPressYear: (newYear: number) => any;
|
|
221
|
+
}) {
|
|
222
|
+
datePickerMonthItemStyles.useVariants({
|
|
223
|
+
state: resolveStateVariant({ selected }) as any,
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
const handlePressYear = useCallback(() => {
|
|
227
|
+
onPressYear(year);
|
|
228
|
+
}, [year, onPressYear]);
|
|
229
|
+
|
|
230
|
+
return (
|
|
231
|
+
<ListItem
|
|
232
|
+
onPress={handlePressYear}
|
|
233
|
+
accessibilityRole="button"
|
|
234
|
+
accessibilityLabel={String(year)}
|
|
235
|
+
accessibilityState={{ selected }}
|
|
236
|
+
style={datePickerMonthItemStyles.monthButton}
|
|
237
|
+
testID={`pick-year-${year}`}
|
|
238
|
+
left={
|
|
239
|
+
selected ? (
|
|
240
|
+
<View style={listStyles.checkIconView}>
|
|
241
|
+
<Icon name="check" size={24} />
|
|
242
|
+
</View>
|
|
243
|
+
) : (
|
|
244
|
+
<View style={listStyles.spacer} />
|
|
245
|
+
)
|
|
246
|
+
}>
|
|
247
|
+
<View style={datePickerMonthItemStyles.monthInner}>
|
|
248
|
+
<Text style={datePickerMonthItemStyles.monthLabel} selectable={false}>
|
|
249
|
+
{year}
|
|
250
|
+
</Text>
|
|
251
|
+
</View>
|
|
252
|
+
</ListItem>
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
const YearRow = memo(YearRowPure);
|
|
256
|
+
|
|
257
|
+
const gridStyles = StyleSheet.create({
|
|
124
258
|
root: {
|
|
125
259
|
flex: 1,
|
|
126
260
|
top: 56,
|
|
127
261
|
zIndex: 100,
|
|
128
262
|
},
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
263
|
+
list: { flex: 1 },
|
|
264
|
+
grid: { alignItems: 'center' },
|
|
265
|
+
row: {
|
|
266
|
+
flexDirection: 'row',
|
|
267
|
+
justifyContent: 'center',
|
|
268
|
+
alignSelf: 'stretch',
|
|
269
|
+
gap: 12,
|
|
132
270
|
},
|
|
133
|
-
|
|
134
|
-
|
|
271
|
+
cell: {
|
|
272
|
+
flex: 1,
|
|
273
|
+
maxWidth: 110,
|
|
274
|
+
minWidth: 90,
|
|
275
|
+
height: GRID_ITEM_HEIGHT,
|
|
276
|
+
justifyContent: 'center',
|
|
135
277
|
},
|
|
136
|
-
|
|
137
|
-
|
|
278
|
+
opacity0: { opacity: 0 },
|
|
279
|
+
opacity1: { opacity: 1 },
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
const listStyles = StyleSheet.create({
|
|
283
|
+
root: {
|
|
284
|
+
flex: 1,
|
|
285
|
+
top: 56,
|
|
286
|
+
zIndex: 100,
|
|
287
|
+
backgroundColor: datePickerMonthPickerStyles.root.backgroundColor,
|
|
138
288
|
},
|
|
289
|
+
list: { flex: 1 },
|
|
290
|
+
checkIconView: { marginLeft: 16 },
|
|
291
|
+
spacer: { width: 44 },
|
|
139
292
|
});
|
|
@@ -219,21 +219,25 @@ export const generateCalendarGrid = ({
|
|
|
219
219
|
const isFirstWeek = weekGrid === 0;
|
|
220
220
|
const realDayIndex = emptyDays - dayIndex;
|
|
221
221
|
const beforeWeekDay = isFirstWeek && realDayIndex > 0;
|
|
222
|
-
const
|
|
223
|
-
const afterWeekDay =
|
|
224
|
-
|
|
225
|
-
|
|
222
|
+
const rawDayOfMonth = weekGrid * 7 + dayIndex - emptyDays + 1;
|
|
223
|
+
const afterWeekDay = rawDayOfMonth > daysInMonth;
|
|
224
|
+
const outside = beforeWeekDay || afterWeekDay;
|
|
225
|
+
|
|
226
|
+
const day = new Date(year, month, rawDayOfMonth);
|
|
227
|
+
const dayOfMonth = day.getDate();
|
|
228
|
+
const displayYear = day.getFullYear();
|
|
229
|
+
const displayMonth = day.getMonth();
|
|
226
230
|
const isToday = areDatesOnSameDay(day, today);
|
|
227
231
|
|
|
228
232
|
let inRange = false;
|
|
229
233
|
let disabled = isDisabled(day);
|
|
230
234
|
let selected = false;
|
|
231
235
|
|
|
232
|
-
let leftCrop =
|
|
233
|
-
let rightCrop =
|
|
236
|
+
let leftCrop = rawDayOfMonth === 1;
|
|
237
|
+
let rightCrop = rawDayOfMonth === daysInMonth;
|
|
234
238
|
|
|
235
|
-
const isFirstDayOfMonth =
|
|
236
|
-
const isLastDayOfMonth =
|
|
239
|
+
const isFirstDayOfMonth = rawDayOfMonth === 1;
|
|
240
|
+
const isLastDayOfMonth = rawDayOfMonth === daysInMonth;
|
|
237
241
|
|
|
238
242
|
if (mode === 'range') {
|
|
239
243
|
const selectedStartDay = areDatesOnSameDay(day, startDate);
|
|
@@ -267,8 +271,8 @@ export const generateCalendarGrid = ({
|
|
|
267
271
|
const safeDates = dates || [];
|
|
268
272
|
selected = safeDates.some(d => areDatesOnSameDay(day, d));
|
|
269
273
|
|
|
270
|
-
const yesterday = new Date(year, month,
|
|
271
|
-
const tomorrow = new Date(year, month,
|
|
274
|
+
const yesterday = new Date(year, month, rawDayOfMonth - 1);
|
|
275
|
+
const tomorrow = new Date(year, month, rawDayOfMonth + 1);
|
|
272
276
|
|
|
273
277
|
const yesterdaySelected = safeDates.some(d => areDatesOnSameDay(d, yesterday));
|
|
274
278
|
const tomorrowSelected = safeDates.some(d => areDatesOnSameDay(d, tomorrow));
|
|
@@ -316,8 +320,9 @@ export const generateCalendarGrid = ({
|
|
|
316
320
|
return {
|
|
317
321
|
beforeWeekDay,
|
|
318
322
|
afterWeekDay,
|
|
319
|
-
|
|
320
|
-
|
|
323
|
+
outside,
|
|
324
|
+
year: displayYear,
|
|
325
|
+
month: displayMonth,
|
|
321
326
|
dayOfMonth,
|
|
322
327
|
dayIndex,
|
|
323
328
|
mode,
|
|
@@ -13,6 +13,7 @@ export interface BaseMonthProps {
|
|
|
13
13
|
onPressDate: (date: Date) => any;
|
|
14
14
|
validRange?: ValidRangeType;
|
|
15
15
|
customMonthStyles?: Record<string, any>;
|
|
16
|
+
showOutsideDays?: boolean;
|
|
16
17
|
|
|
17
18
|
// some of these should be required in final implementation
|
|
18
19
|
date?: CalendarDate;
|
|
@@ -52,7 +53,9 @@ export type BaseDatePickerProps = {
|
|
|
52
53
|
startYear?: number;
|
|
53
54
|
endYear?: number;
|
|
54
55
|
HeaderComponent?: MemoExoticComponent<CalendarHeaderProps | any>;
|
|
56
|
+
headerLayout?: 'inline' | 'docked';
|
|
55
57
|
monthStyle?: Record<string, any>;
|
|
58
|
+
showOutsideDays?: boolean;
|
|
56
59
|
|
|
57
60
|
// here they are optional but in final implemenation they are required
|
|
58
61
|
date?: CalendarDate;
|
|
@@ -3,11 +3,13 @@ import { StyleSheet } from 'react-native-unistyles';
|
|
|
3
3
|
import { getRegisteredComponentStylesWithFallback } from '../../core';
|
|
4
4
|
import { daySize } from './dateUtils';
|
|
5
5
|
|
|
6
|
-
export const dayNamesHeight =
|
|
6
|
+
export const dayNamesHeight = 48;
|
|
7
7
|
|
|
8
8
|
// TODO make it flexible
|
|
9
|
-
export const
|
|
10
|
-
export const
|
|
9
|
+
export const cellSize = 48;
|
|
10
|
+
export const cellVerticalPadding = (cellSize - daySize) / 2;
|
|
11
|
+
export const weekMargin = 0;
|
|
12
|
+
export const weekSize = cellSize + weekMargin;
|
|
11
13
|
export const montHeaderHeight = 56;
|
|
12
14
|
export const monthHeaderSingleMarginTop = 4;
|
|
13
15
|
export const monthHeaderSingleMarginBottom = 8 + 22 + 12;
|
|
@@ -33,8 +35,7 @@ const datePickerMonthStylesDefault = StyleSheet.create(theme => ({
|
|
|
33
35
|
backgroundColor: theme.colors.surface,
|
|
34
36
|
},
|
|
35
37
|
monthLabel: {
|
|
36
|
-
...theme.typescale.
|
|
37
|
-
opacity: 0.7,
|
|
38
|
+
...theme.typescale.labelLarge,
|
|
38
39
|
},
|
|
39
40
|
yearButton: {
|
|
40
41
|
alignSelf: 'flex-start',
|
|
@@ -89,6 +90,30 @@ const datePickerYearPickerStylesDefault = StyleSheet.create(theme => ({
|
|
|
89
90
|
},
|
|
90
91
|
}));
|
|
91
92
|
|
|
93
|
+
export const datePickerDayStateLayerStyles = StyleSheet.create(theme => ({
|
|
94
|
+
stateLayer: {
|
|
95
|
+
variants: {
|
|
96
|
+
state: {
|
|
97
|
+
hovered: {
|
|
98
|
+
backgroundColor: theme.colors.stateLayer.hover.onSurface,
|
|
99
|
+
},
|
|
100
|
+
todayAndHovered: {
|
|
101
|
+
backgroundColor: theme.colors.stateLayer.hover.primary,
|
|
102
|
+
},
|
|
103
|
+
outsideAndHovered: {
|
|
104
|
+
backgroundColor: theme.colors.stateLayer.hover.onSurface,
|
|
105
|
+
},
|
|
106
|
+
selectedAndHovered: {
|
|
107
|
+
backgroundColor: theme.colors.stateLayer.hover.onPrimary,
|
|
108
|
+
},
|
|
109
|
+
inRangeAndHovered: {
|
|
110
|
+
backgroundColor: theme.colors.stateLayer.hover.onSurface,
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
}));
|
|
116
|
+
|
|
92
117
|
const datePickerDayStylesDefault = StyleSheet.create(theme => ({
|
|
93
118
|
containerStyle: {
|
|
94
119
|
flex: 1,
|
|
@@ -102,6 +127,9 @@ const datePickerDayStylesDefault = StyleSheet.create(theme => ({
|
|
|
102
127
|
disabled: {
|
|
103
128
|
opacity: 0.3,
|
|
104
129
|
},
|
|
130
|
+
outside: {
|
|
131
|
+
opacity: 0.38,
|
|
132
|
+
},
|
|
105
133
|
},
|
|
106
134
|
},
|
|
107
135
|
},
|
|
@@ -117,7 +145,7 @@ const datePickerDayStylesDefault = StyleSheet.create(theme => ({
|
|
|
117
145
|
variants: {
|
|
118
146
|
state: {
|
|
119
147
|
inRange: {
|
|
120
|
-
backgroundColor:
|
|
148
|
+
backgroundColor: 'transparent',
|
|
121
149
|
},
|
|
122
150
|
},
|
|
123
151
|
},
|
|
@@ -140,12 +168,13 @@ const datePickerDayStylesDefault = StyleSheet.create(theme => ({
|
|
|
140
168
|
},
|
|
141
169
|
|
|
142
170
|
inRange: {
|
|
143
|
-
|
|
171
|
+
borderWidth: 0,
|
|
172
|
+
borderColor: 'transparent',
|
|
144
173
|
button: {
|
|
145
|
-
backgroundColor:
|
|
174
|
+
backgroundColor: 'transparent',
|
|
146
175
|
},
|
|
147
176
|
today: {
|
|
148
|
-
borderColor:
|
|
177
|
+
borderColor: 'transparent',
|
|
149
178
|
},
|
|
150
179
|
},
|
|
151
180
|
},
|
|
@@ -156,15 +185,17 @@ const datePickerDayStylesDefault = StyleSheet.create(theme => ({
|
|
|
156
185
|
variants: {
|
|
157
186
|
state: {
|
|
158
187
|
inRange: {
|
|
159
|
-
|
|
188
|
+
borderWidth: 0,
|
|
189
|
+
borderColor: 'transparent',
|
|
160
190
|
button: {
|
|
161
|
-
backgroundColor:
|
|
191
|
+
backgroundColor: 'transparent',
|
|
162
192
|
},
|
|
163
193
|
},
|
|
164
194
|
},
|
|
165
195
|
},
|
|
166
196
|
},
|
|
167
197
|
text: {
|
|
198
|
+
...theme.typescale.bodyLarge,
|
|
168
199
|
variants: {
|
|
169
200
|
state: {
|
|
170
201
|
selected: {
|
|
@@ -175,16 +206,16 @@ const datePickerDayStylesDefault = StyleSheet.create(theme => ({
|
|
|
175
206
|
},
|
|
176
207
|
|
|
177
208
|
inRange: {
|
|
178
|
-
color: theme.colors.
|
|
209
|
+
color: theme.colors.onSecondaryContainer,
|
|
179
210
|
|
|
180
211
|
day: {
|
|
181
|
-
borderColor:
|
|
212
|
+
borderColor: 'transparent',
|
|
182
213
|
},
|
|
183
214
|
button: {
|
|
184
|
-
backgroundColor:
|
|
215
|
+
backgroundColor: 'transparent',
|
|
185
216
|
},
|
|
186
217
|
today: {
|
|
187
|
-
borderColor:
|
|
218
|
+
borderColor: 'transparent',
|
|
188
219
|
},
|
|
189
220
|
},
|
|
190
221
|
},
|
|
@@ -205,7 +236,7 @@ const datePickerDayEmptyStylesDefault = StyleSheet.create({
|
|
|
205
236
|
const datePickerWeekStylesDefault = StyleSheet.create({
|
|
206
237
|
root: {
|
|
207
238
|
flexDirection: 'row',
|
|
208
|
-
height:
|
|
239
|
+
height: cellSize,
|
|
209
240
|
},
|
|
210
241
|
});
|
|
211
242
|
|
|
@@ -214,7 +245,7 @@ const datePickerHeaderStylesDefault = StyleSheet.create(theme => ({
|
|
|
214
245
|
flexDirection: 'row',
|
|
215
246
|
alignItems: 'center',
|
|
216
247
|
justifyContent: 'space-between',
|
|
217
|
-
|
|
248
|
+
padding: theme.spacings['2'],
|
|
218
249
|
},
|
|
219
250
|
buttonContainer: {
|
|
220
251
|
height: 56,
|
|
@@ -226,8 +257,7 @@ const datePickerHeaderStylesDefault = StyleSheet.create(theme => ({
|
|
|
226
257
|
buttonWrapper: {},
|
|
227
258
|
spacer: { flex: 1 },
|
|
228
259
|
yearLabelStyle: {
|
|
229
|
-
...theme.typescale.
|
|
230
|
-
opacity: 0.7,
|
|
260
|
+
...theme.typescale.labelLarge,
|
|
231
261
|
},
|
|
232
262
|
yearButtonStyle: {
|
|
233
263
|
alignSelf: 'flex-start',
|
|
@@ -249,24 +279,25 @@ const dateDayNameStylesDefault = StyleSheet.create(theme => ({
|
|
|
249
279
|
alignItems: 'center',
|
|
250
280
|
backgroundColor: theme.colors.surface,
|
|
251
281
|
},
|
|
252
|
-
dayName: { flex: 1, alignItems: 'center' },
|
|
282
|
+
dayName: { flex: 1, alignItems: 'center', ...theme.typescale.bodyLarge },
|
|
253
283
|
dayNameLabel: {
|
|
254
|
-
|
|
255
|
-
...theme.typescale.bodyMedium,
|
|
284
|
+
...theme.typescale.bodyLarge,
|
|
256
285
|
},
|
|
257
286
|
}));
|
|
258
287
|
|
|
259
288
|
const datePickerDayRangeStylesDefault = StyleSheet.create(theme => ({
|
|
260
289
|
container: {
|
|
290
|
+
position: 'absolute',
|
|
291
|
+
top: cellVerticalPadding,
|
|
292
|
+
bottom: cellVerticalPadding,
|
|
293
|
+
left: 0,
|
|
294
|
+
right: 0,
|
|
261
295
|
flexDirection: 'row',
|
|
262
296
|
|
|
263
297
|
variants: {
|
|
264
298
|
state: {
|
|
265
|
-
bothWays: {
|
|
266
|
-
borderRadius: daySize / 2,
|
|
267
|
-
},
|
|
268
299
|
inRange: {
|
|
269
|
-
backgroundColor: theme.colors.
|
|
300
|
+
backgroundColor: theme.colors.secondaryContainer,
|
|
270
301
|
},
|
|
271
302
|
isCrop: {
|
|
272
303
|
backgroundColor: undefined,
|
|
@@ -280,7 +311,7 @@ const datePickerDayRangeStylesDefault = StyleSheet.create(theme => ({
|
|
|
280
311
|
variants: {
|
|
281
312
|
state: {
|
|
282
313
|
isRightCrop: {
|
|
283
|
-
backgroundColor: theme.colors.
|
|
314
|
+
backgroundColor: theme.colors.secondaryContainer,
|
|
284
315
|
},
|
|
285
316
|
},
|
|
286
317
|
},
|
|
@@ -291,13 +322,13 @@ const datePickerDayRangeStylesDefault = StyleSheet.create(theme => ({
|
|
|
291
322
|
variants: {
|
|
292
323
|
state: {
|
|
293
324
|
isLeftCrop: {
|
|
294
|
-
backgroundColor: theme.colors.
|
|
325
|
+
backgroundColor: theme.colors.secondaryContainer,
|
|
295
326
|
},
|
|
296
327
|
},
|
|
297
328
|
},
|
|
298
329
|
},
|
|
299
330
|
centerCrop: {
|
|
300
|
-
backgroundColor: theme.colors.
|
|
331
|
+
backgroundColor: theme.colors.secondaryContainer,
|
|
301
332
|
minWidth: daySize,
|
|
302
333
|
minHeight: daySize,
|
|
303
334
|
|
|
@@ -317,7 +348,13 @@ const datePickerDayRangeStylesDefault = StyleSheet.create(theme => ({
|
|
|
317
348
|
}));
|
|
318
349
|
|
|
319
350
|
const datePickerYearItemStylesDefault = StyleSheet.create(theme => ({
|
|
351
|
+
content: {
|
|
352
|
+
alignItems: 'center',
|
|
353
|
+
},
|
|
320
354
|
yearButton: {
|
|
355
|
+
borderRadius: theme.shapes.corner.full,
|
|
356
|
+
paddingHorizontal: 0,
|
|
357
|
+
overflow: 'hidden',
|
|
321
358
|
variants: {
|
|
322
359
|
state: {
|
|
323
360
|
selected: {
|
|
@@ -4,5 +4,5 @@ import FilePickerDefault from './FilePicker';
|
|
|
4
4
|
export const FilePicker = getRegisteredComponentWithFallback('FilePicker', FilePickerDefault);
|
|
5
5
|
|
|
6
6
|
export type { Props as FilePickerProps } from './FilePicker';
|
|
7
|
-
export { FilePickerContext, defaultStyles } from './utils';
|
|
8
7
|
export type { FilePickerContextType } from './utils';
|
|
8
|
+
export { defaultStyles, FilePickerContext } from './utils';
|
|
@@ -37,6 +37,7 @@ export type Props = Omit<TouchableRippleProps, 'children'> &
|
|
|
37
37
|
* @default true if onPress is passed
|
|
38
38
|
*/
|
|
39
39
|
hoverable?: boolean;
|
|
40
|
+
contentStyle?: StyleProp<ViewStyle>;
|
|
40
41
|
};
|
|
41
42
|
|
|
42
43
|
const ListItem = (
|
|
@@ -52,6 +53,7 @@ const ListItem = (
|
|
|
52
53
|
onPress,
|
|
53
54
|
hoverable: hoverableProp = false,
|
|
54
55
|
hovered: hoveredProp = false,
|
|
56
|
+
contentStyle: contentStyleProp,
|
|
55
57
|
...props
|
|
56
58
|
}: Props,
|
|
57
59
|
ref: any,
|
|
@@ -108,7 +110,7 @@ const ListItem = (
|
|
|
108
110
|
{typeof left === 'function' ? left({ hovered }) : left}
|
|
109
111
|
</View>
|
|
110
112
|
) : null}
|
|
111
|
-
<View style={contentStyle}>
|
|
113
|
+
<View style={[contentStyle, contentStyleProp]}>
|
|
112
114
|
<ListItemContext.Provider value={contextValue}>
|
|
113
115
|
<>{children}</>
|
|
114
116
|
</ListItemContext.Provider>
|