@cdx-ui/components 0.2.5 → 0.3.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.
- package/docs/components/bottom-sheet/content.md +2 -0
- package/docs/components/calendar/content.md +25 -1
- package/docs/components/month-calendar/content.md +2 -0
- package/docs/components/range-calendar/content.md +3 -1
- package/docs/llms.txt +1 -0
- package/docs/resources/release-notes/0.2.5/content.md +25 -0
- package/docs/resources/release-notes/content.md +1 -0
- package/lib/commonjs/components/BottomSheet/index.js +25 -1
- package/lib/commonjs/components/BottomSheet/index.js.map +1 -1
- package/lib/commonjs/components/BottomSheet/styles.js +8 -2
- package/lib/commonjs/components/BottomSheet/styles.js.map +1 -1
- package/lib/commonjs/components/Calendar/CalendarMonthHeader.js +15 -5
- package/lib/commonjs/components/Calendar/CalendarMonthHeader.js.map +1 -1
- package/lib/commonjs/components/Calendar/CalendarYearList.js +116 -0
- package/lib/commonjs/components/Calendar/CalendarYearList.js.map +1 -0
- package/lib/commonjs/components/Calendar/CalendarYearPickerGrid.js +58 -31
- package/lib/commonjs/components/Calendar/CalendarYearPickerGrid.js.map +1 -1
- package/lib/commonjs/components/Calendar/flashCalendarAdapter.js +22 -3
- package/lib/commonjs/components/Calendar/flashCalendarAdapter.js.map +1 -1
- package/lib/commonjs/components/Calendar/index.js +6 -2
- package/lib/commonjs/components/Calendar/index.js.map +1 -1
- package/lib/commonjs/components/Calendar/styles.js +16 -2
- package/lib/commonjs/components/Calendar/styles.js.map +1 -1
- package/lib/commonjs/components/MonthCalendar/index.js +39 -13
- package/lib/commonjs/components/MonthCalendar/index.js.map +1 -1
- package/lib/commonjs/components/RangeCalendar/index.js +6 -2
- package/lib/commonjs/components/RangeCalendar/index.js.map +1 -1
- package/lib/module/components/BottomSheet/index.js +27 -3
- package/lib/module/components/BottomSheet/index.js.map +1 -1
- package/lib/module/components/BottomSheet/styles.js +8 -2
- package/lib/module/components/BottomSheet/styles.js.map +1 -1
- package/lib/module/components/Calendar/CalendarMonthHeader.js +15 -5
- package/lib/module/components/Calendar/CalendarMonthHeader.js.map +1 -1
- package/lib/module/components/Calendar/CalendarYearList.js +112 -0
- package/lib/module/components/Calendar/CalendarYearList.js.map +1 -0
- package/lib/module/components/Calendar/CalendarYearPickerGrid.js +61 -34
- package/lib/module/components/Calendar/CalendarYearPickerGrid.js.map +1 -1
- package/lib/module/components/Calendar/flashCalendarAdapter.js +20 -2
- package/lib/module/components/Calendar/flashCalendarAdapter.js.map +1 -1
- package/lib/module/components/Calendar/index.js +7 -3
- package/lib/module/components/Calendar/index.js.map +1 -1
- package/lib/module/components/Calendar/styles.js +15 -1
- package/lib/module/components/Calendar/styles.js.map +1 -1
- package/lib/module/components/MonthCalendar/index.js +42 -15
- package/lib/module/components/MonthCalendar/index.js.map +1 -1
- package/lib/module/components/RangeCalendar/index.js +7 -3
- package/lib/module/components/RangeCalendar/index.js.map +1 -1
- package/lib/typescript/components/BottomSheet/index.d.ts +8 -0
- package/lib/typescript/components/BottomSheet/index.d.ts.map +1 -1
- package/lib/typescript/components/BottomSheet/styles.d.ts +5 -1
- package/lib/typescript/components/BottomSheet/styles.d.ts.map +1 -1
- package/lib/typescript/components/Calendar/CalendarMonthHeader.d.ts.map +1 -1
- package/lib/typescript/components/Calendar/CalendarYearList.d.ts +23 -0
- package/lib/typescript/components/Calendar/CalendarYearList.d.ts.map +1 -0
- package/lib/typescript/components/Calendar/CalendarYearPickerGrid.d.ts +5 -1
- package/lib/typescript/components/Calendar/CalendarYearPickerGrid.d.ts.map +1 -1
- package/lib/typescript/components/Calendar/flashCalendarAdapter.d.ts +8 -0
- package/lib/typescript/components/Calendar/flashCalendarAdapter.d.ts.map +1 -1
- package/lib/typescript/components/Calendar/index.d.ts.map +1 -1
- package/lib/typescript/components/Calendar/styles.d.ts +7 -1
- package/lib/typescript/components/Calendar/styles.d.ts.map +1 -1
- package/lib/typescript/components/MonthCalendar/index.d.ts.map +1 -1
- package/lib/typescript/components/RangeCalendar/index.d.ts.map +1 -1
- package/lib/typescript/components/ToggleButton/styles.d.ts +1 -1
- package/package.json +5 -5
- package/src/components/BottomSheet/index.tsx +174 -138
- package/src/components/BottomSheet/styles.ts +11 -3
- package/src/components/Calendar/CalendarMonthHeader.tsx +29 -22
- package/src/components/Calendar/CalendarYearList.tsx +136 -0
- package/src/components/Calendar/CalendarYearPickerGrid.tsx +60 -33
- package/src/components/Calendar/flashCalendarAdapter.ts +27 -2
- package/src/components/Calendar/index.tsx +8 -3
- package/src/components/Calendar/styles.ts +17 -1
- package/src/components/MonthCalendar/index.tsx +55 -33
- package/src/components/RangeCalendar/index.tsx +8 -3
|
@@ -1,27 +1,32 @@
|
|
|
1
|
-
import { forwardRef, useCallback, useMemo, type ComponentRef } from 'react';
|
|
1
|
+
import { forwardRef, useCallback, useMemo, useState, type ComponentRef } from 'react';
|
|
2
2
|
import { Pressable, Text, View, type ViewProps } from 'react-native';
|
|
3
3
|
import {
|
|
4
4
|
formatMonthId,
|
|
5
5
|
formatSelectYear,
|
|
6
|
+
parseDateId,
|
|
6
7
|
parseMonthId,
|
|
7
8
|
resolveDateComponentLabels,
|
|
8
9
|
type DateComponentLabels,
|
|
10
|
+
type DateId,
|
|
9
11
|
type MonthId,
|
|
10
12
|
} from '@cdx-ui/formatters';
|
|
11
13
|
import { cn } from '@cdx-ui/utils';
|
|
14
|
+
import { CalendarYearList, getYearRange } from './CalendarYearList';
|
|
12
15
|
import type { CalendarNavigationView } from './CalendarMonthHeader';
|
|
16
|
+
import { getFlashCalendarGridHeight } from './flashCalendarAdapter';
|
|
13
17
|
import {
|
|
14
18
|
calendarPillCellTextVariants,
|
|
15
19
|
calendarPillCellVariants,
|
|
16
|
-
|
|
20
|
+
calendarYearPickerListVariants,
|
|
17
21
|
} from './styles';
|
|
18
22
|
|
|
19
|
-
const YEAR_RANGE_BEFORE = 9;
|
|
20
|
-
const YEAR_RANGE_AFTER = 11;
|
|
21
|
-
|
|
22
23
|
export interface CalendarYearPickerGridProps extends ViewProps {
|
|
23
24
|
monthId: MonthId;
|
|
24
25
|
onMonthIdChange: (monthId: MonthId) => void;
|
|
26
|
+
/** Earliest selectable date; its year is the first year listed. */
|
|
27
|
+
minValue?: DateId;
|
|
28
|
+
/** Latest selectable date; its year is the last year listed. */
|
|
29
|
+
maxValue?: DateId;
|
|
25
30
|
disabled?: boolean;
|
|
26
31
|
onViewChange: (view: CalendarNavigationView) => void;
|
|
27
32
|
labels?: Partial<DateComponentLabels>;
|
|
@@ -35,6 +40,8 @@ export const CalendarYearPickerGrid = forwardRef<
|
|
|
35
40
|
{
|
|
36
41
|
monthId,
|
|
37
42
|
onMonthIdChange,
|
|
43
|
+
minValue,
|
|
44
|
+
maxValue,
|
|
38
45
|
disabled = false,
|
|
39
46
|
onViewChange,
|
|
40
47
|
labels: labelsProp,
|
|
@@ -45,54 +52,74 @@ export const CalendarYearPickerGrid = forwardRef<
|
|
|
45
52
|
ref,
|
|
46
53
|
) => {
|
|
47
54
|
const labels = useMemo(() => resolveDateComponentLabels(labelsProp), [labelsProp]);
|
|
55
|
+
const [todayYear] = useState(() => new Date().getFullYear());
|
|
48
56
|
const parts = parseMonthId(monthId);
|
|
49
|
-
const currentYear = parts?.year ??
|
|
57
|
+
const currentYear = parts?.year ?? todayYear;
|
|
50
58
|
const currentMonth = parts?.month ?? 1;
|
|
59
|
+
const minParts = minValue ? parseDateId(minValue) : null;
|
|
60
|
+
const maxParts = maxValue ? parseDateId(maxValue) : null;
|
|
61
|
+
const minYear = minParts?.year;
|
|
62
|
+
const minMonth = minParts?.month;
|
|
63
|
+
const maxYear = maxParts?.year;
|
|
64
|
+
const maxMonth = maxParts?.month;
|
|
51
65
|
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
(_, i) => currentYear - YEAR_RANGE_BEFORE + i,
|
|
57
|
-
),
|
|
58
|
-
[currentYear],
|
|
59
|
-
);
|
|
66
|
+
const { first, last } = getYearRange(minYear, maxYear, currentYear, todayYear);
|
|
67
|
+
|
|
68
|
+
// Matches the day grid so switching views does not change the Calendar's height.
|
|
69
|
+
const height = getFlashCalendarGridHeight(monthId);
|
|
60
70
|
|
|
61
71
|
const selectYear = useCallback(
|
|
62
72
|
(year: number) => {
|
|
63
73
|
if (disabled) {
|
|
64
74
|
return;
|
|
65
75
|
}
|
|
66
|
-
|
|
76
|
+
let month = currentMonth;
|
|
77
|
+
if (minYear === year && minMonth !== undefined) {
|
|
78
|
+
month = Math.max(month, minMonth);
|
|
79
|
+
}
|
|
80
|
+
if (maxYear === year && maxMonth !== undefined) {
|
|
81
|
+
month = Math.min(month, maxMonth);
|
|
82
|
+
}
|
|
83
|
+
onMonthIdChange(formatMonthId({ year, month }));
|
|
67
84
|
onViewChange('month');
|
|
68
85
|
},
|
|
69
|
-
[currentMonth, disabled, onMonthIdChange, onViewChange],
|
|
86
|
+
[currentMonth, disabled, maxMonth, maxYear, minMonth, minYear, onMonthIdChange, onViewChange],
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const renderYear = useCallback(
|
|
90
|
+
(year: number) => {
|
|
91
|
+
const selected = year === currentYear;
|
|
92
|
+
return (
|
|
93
|
+
<Pressable
|
|
94
|
+
accessibilityRole="button"
|
|
95
|
+
accessibilityState={{ selected, disabled }}
|
|
96
|
+
accessibilityLabel={formatSelectYear(labels, year)}
|
|
97
|
+
disabled={disabled}
|
|
98
|
+
onPress={() => selectYear(year)}
|
|
99
|
+
className={calendarPillCellVariants({ selected, disabled })}
|
|
100
|
+
>
|
|
101
|
+
<Text className={calendarPillCellTextVariants({ selected })}>{String(year)}</Text>
|
|
102
|
+
</Pressable>
|
|
103
|
+
);
|
|
104
|
+
},
|
|
105
|
+
[currentYear, disabled, labels, selectYear],
|
|
70
106
|
);
|
|
71
107
|
|
|
72
108
|
return (
|
|
73
109
|
<View
|
|
74
110
|
ref={ref}
|
|
75
|
-
className={cn(
|
|
111
|
+
className={cn(calendarYearPickerListVariants(), className)}
|
|
76
112
|
style={style}
|
|
77
113
|
accessibilityRole="none"
|
|
78
114
|
{...props}
|
|
79
115
|
>
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
accessibilityLabel={formatSelectYear(labels, year)}
|
|
88
|
-
disabled={disabled}
|
|
89
|
-
onPress={() => selectYear(year)}
|
|
90
|
-
className={calendarPillCellVariants({ selected, disabled })}
|
|
91
|
-
>
|
|
92
|
-
<Text className={calendarPillCellTextVariants({ selected })}>{String(year)}</Text>
|
|
93
|
-
</Pressable>
|
|
94
|
-
);
|
|
95
|
-
})}
|
|
116
|
+
<CalendarYearList
|
|
117
|
+
first={first}
|
|
118
|
+
last={last}
|
|
119
|
+
selectedYear={currentYear}
|
|
120
|
+
height={height}
|
|
121
|
+
renderYear={renderYear}
|
|
122
|
+
/>
|
|
96
123
|
</View>
|
|
97
124
|
);
|
|
98
125
|
},
|
|
@@ -6,6 +6,9 @@ import { formatDateId, parseMonthId, type DateId, type MonthId } from '@cdx-ui/f
|
|
|
6
6
|
const DAY_SIZE = 36;
|
|
7
7
|
const DAY_RADIUS = DAY_SIZE / 2;
|
|
8
8
|
|
|
9
|
+
/** Bottom padding the theme adds under the weekday header row (`rowWeek.container`). */
|
|
10
|
+
const WEEK_HEADER_PADDING_BOTTOM = 4;
|
|
11
|
+
|
|
9
12
|
const CALENDAR_COLOR_VARS = [
|
|
10
13
|
'--color-surface-action-strong',
|
|
11
14
|
'--color-content-action-on-strong',
|
|
@@ -159,7 +162,7 @@ export function useFlashCalendarTheme(selectedDateId?: DateId): CalendarTheme {
|
|
|
159
162
|
},
|
|
160
163
|
rowWeek: {
|
|
161
164
|
container: {
|
|
162
|
-
paddingBottom:
|
|
165
|
+
paddingBottom: WEEK_HEADER_PADDING_BOTTOM,
|
|
163
166
|
},
|
|
164
167
|
},
|
|
165
168
|
itemWeekName: {
|
|
@@ -249,7 +252,7 @@ export function useFlashCalendarRangeTheme(range?: {
|
|
|
249
252
|
},
|
|
250
253
|
rowWeek: {
|
|
251
254
|
container: {
|
|
252
|
-
paddingBottom:
|
|
255
|
+
paddingBottom: WEEK_HEADER_PADDING_BOTTOM,
|
|
253
256
|
},
|
|
254
257
|
},
|
|
255
258
|
itemWeekName: {
|
|
@@ -348,6 +351,28 @@ export const FLASH_CALENDAR_RANGE_DAY_SPACING = 0;
|
|
|
348
351
|
|
|
349
352
|
export const FLASH_CALENDAR_DAY_HEIGHT = DAY_SIZE;
|
|
350
353
|
|
|
354
|
+
export const FLASH_CALENDAR_WEEK_HEADER_HEIGHT = 28;
|
|
355
|
+
|
|
356
|
+
export const FLASH_CALENDAR_ROW_VERTICAL_SPACING = 4;
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Rendered height of the Flash Calendar month grid for `monthId`, derived from the same layout
|
|
360
|
+
* values passed to Flash Calendar (zero-height month row, weekday header, one row per week with
|
|
361
|
+
* Sunday as the first day). Lets the year view match the day view without measuring.
|
|
362
|
+
*/
|
|
363
|
+
export function getFlashCalendarGridHeight(monthId: MonthId): number {
|
|
364
|
+
const parts = parseMonthId(monthId);
|
|
365
|
+
const firstWeekday = parts ? new Date(parts.year, parts.month - 1, 1).getDay() : 0;
|
|
366
|
+
const daysInMonth = parts ? new Date(parts.year, parts.month, 0).getDate() : 31;
|
|
367
|
+
const weekCount = Math.ceil((firstWeekday + daysInMonth) / 7);
|
|
368
|
+
return (
|
|
369
|
+
FLASH_CALENDAR_WEEK_HEADER_HEIGHT +
|
|
370
|
+
WEEK_HEADER_PADDING_BOTTOM +
|
|
371
|
+
weekCount * FLASH_CALENDAR_DAY_HEIGHT +
|
|
372
|
+
(weekCount + 1) * FLASH_CALENDAR_ROW_VERTICAL_SPACING
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
|
|
351
376
|
export function formatFlashCalendarWeekdayShort(date: Date, locale: string): string {
|
|
352
377
|
return new Intl.DateTimeFormat(locale, { weekday: 'short' }).format(date);
|
|
353
378
|
}
|
|
@@ -15,6 +15,8 @@ import { CalendarMonthHeader } from './CalendarMonthHeader';
|
|
|
15
15
|
import { CalendarYearPickerGrid } from './CalendarYearPickerGrid';
|
|
16
16
|
import {
|
|
17
17
|
FLASH_CALENDAR_DAY_HEIGHT,
|
|
18
|
+
FLASH_CALENDAR_ROW_VERTICAL_SPACING,
|
|
19
|
+
FLASH_CALENDAR_WEEK_HEADER_HEIGHT,
|
|
18
20
|
formatFlashCalendarWeekdayShort,
|
|
19
21
|
getMonthDateIds,
|
|
20
22
|
toCalendarDateId,
|
|
@@ -143,8 +145,8 @@ const CalendarGrid = forwardRef<View, ViewProps>(({ className, style, ...props }
|
|
|
143
145
|
calendarDisabledDateIds={unavailableDateIds}
|
|
144
146
|
calendarMonthHeaderHeight={0}
|
|
145
147
|
calendarDayHeight={FLASH_CALENDAR_DAY_HEIGHT}
|
|
146
|
-
calendarWeekHeaderHeight={
|
|
147
|
-
calendarRowVerticalSpacing={
|
|
148
|
+
calendarWeekHeaderHeight={FLASH_CALENDAR_WEEK_HEADER_HEIGHT}
|
|
149
|
+
calendarRowVerticalSpacing={FLASH_CALENDAR_ROW_VERTICAL_SPACING}
|
|
148
150
|
calendarRowHorizontalSpacing={4}
|
|
149
151
|
getCalendarMonthFormat={() => ''}
|
|
150
152
|
getCalendarWeekDayFormat={formatWeekday}
|
|
@@ -158,12 +160,15 @@ const CalendarGrid = forwardRef<View, ViewProps>(({ className, style, ...props }
|
|
|
158
160
|
CalendarGrid.displayName = 'Calendar.Grid';
|
|
159
161
|
|
|
160
162
|
const CalendarYearPicker = forwardRef<View, ViewProps>(({ className, style, ...props }, ref) => {
|
|
161
|
-
const { monthId, onMonthIdChange, disabled, setView, labels } =
|
|
163
|
+
const { monthId, onMonthIdChange, minValue, maxValue, disabled, setView, labels } =
|
|
164
|
+
useCalendarContext();
|
|
162
165
|
return (
|
|
163
166
|
<CalendarYearPickerGrid
|
|
164
167
|
ref={ref}
|
|
165
168
|
monthId={monthId}
|
|
166
169
|
onMonthIdChange={onMonthIdChange}
|
|
170
|
+
minValue={minValue}
|
|
171
|
+
maxValue={maxValue}
|
|
167
172
|
disabled={disabled}
|
|
168
173
|
onViewChange={setView}
|
|
169
174
|
labels={labels}
|
|
@@ -31,12 +31,28 @@ export const calendarMonthHeaderIconVariants = cva('size-5 shrink-0', {
|
|
|
31
31
|
defaultVariants: { isYearView: false },
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
export const calendarMonthHeaderNavVariants = cva('flex-row items-center gap-1'
|
|
34
|
+
export const calendarMonthHeaderNavVariants = cva('flex-row items-center gap-1', {
|
|
35
|
+
variants: {
|
|
36
|
+
hidden: {
|
|
37
|
+
true: 'opacity-0',
|
|
38
|
+
false: '',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
defaultVariants: { hidden: false },
|
|
42
|
+
});
|
|
35
43
|
|
|
36
44
|
export const calendarYearPickerGridVariants = cva(
|
|
37
45
|
'flex-row flex-wrap justify-between gap-y-2 px-1 py-1',
|
|
38
46
|
);
|
|
39
47
|
|
|
48
|
+
export const calendarYearPickerListVariants = cva('w-full');
|
|
49
|
+
|
|
50
|
+
export const calendarYearPickerListContentVariants = cva('px-1');
|
|
51
|
+
|
|
52
|
+
export const calendarYearPickerRowVariants = cva('flex-row items-center justify-between');
|
|
53
|
+
|
|
54
|
+
export const calendarYearPickerPlaceholderVariants = cva('w-[31%]');
|
|
55
|
+
|
|
40
56
|
export const calendarPillCellVariants = cva(
|
|
41
57
|
'my-0.5 w-[31%] items-center justify-center rounded-[var(--border-radius-round)] py-2.5',
|
|
42
58
|
{
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { forwardRef, useCallback,
|
|
1
|
+
import { forwardRef, useCallback, useState, type ReactNode } from 'react';
|
|
2
2
|
import { Pressable, Text, View, type ViewProps } from 'react-native';
|
|
3
3
|
import {
|
|
4
4
|
dataAttributes,
|
|
@@ -21,6 +21,7 @@ import { cn } from '@cdx-ui/utils';
|
|
|
21
21
|
import { ChevronLeft, ChevronRight, KeyboardArrowDown } from '@cdx-ui/icons';
|
|
22
22
|
import { Icon } from '../Icon';
|
|
23
23
|
import { IconButton } from '../IconButton';
|
|
24
|
+
import { CalendarYearList, getYearRange, YEAR_ROW_HEIGHT } from '../Calendar/CalendarYearList';
|
|
24
25
|
import {
|
|
25
26
|
calendarMonthHeaderIconVariants,
|
|
26
27
|
calendarMonthHeaderLabelVariants,
|
|
@@ -31,8 +32,16 @@ import {
|
|
|
31
32
|
calendarPillCellVariants,
|
|
32
33
|
calendarRootVariants,
|
|
33
34
|
calendarYearPickerGridVariants,
|
|
35
|
+
calendarYearPickerListVariants,
|
|
34
36
|
} from '../Calendar/styles';
|
|
35
37
|
|
|
38
|
+
// The month grid's four rows of pill cells, so the year view matches its height.
|
|
39
|
+
const MONTH_GRID_HEIGHT = 4 * YEAR_ROW_HEIGHT;
|
|
40
|
+
|
|
41
|
+
function renderYearCell(year: number) {
|
|
42
|
+
return <MonthCalendarYearCell year={year} />;
|
|
43
|
+
}
|
|
44
|
+
|
|
36
45
|
export interface MonthCalendarProps
|
|
37
46
|
extends Omit<MonthCalendarRootProps, 'children'>, Omit<ViewProps, 'children'> {
|
|
38
47
|
className?: string;
|
|
@@ -109,28 +118,35 @@ const MonthCalendarHeader = forwardRef<View, ViewProps>(({ className, style, ...
|
|
|
109
118
|
/>
|
|
110
119
|
</Pressable>
|
|
111
120
|
|
|
112
|
-
{
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
121
|
+
{/* Stays mounted in the year view so the header keeps its height and the label does not move. */}
|
|
122
|
+
<View
|
|
123
|
+
className={calendarMonthHeaderNavVariants({ hidden: isYearView })}
|
|
124
|
+
pointerEvents={isYearView ? 'none' : 'auto'}
|
|
125
|
+
accessibilityElementsHidden={isYearView}
|
|
126
|
+
importantForAccessibility={isYearView ? 'no-hide-descendants' : 'auto'}
|
|
127
|
+
{...(isYearView ? { 'aria-hidden': true } : {})}
|
|
128
|
+
>
|
|
129
|
+
<IconButton
|
|
130
|
+
as={ChevronLeft}
|
|
131
|
+
variant="ghost"
|
|
132
|
+
color="neutral"
|
|
133
|
+
size="small"
|
|
134
|
+
accessibilityLabel={labels.previousYear}
|
|
135
|
+
isDisabled={disabled || isYearView}
|
|
136
|
+
focusable={!isYearView}
|
|
137
|
+
onPress={() => shiftYear(-1)}
|
|
138
|
+
/>
|
|
139
|
+
<IconButton
|
|
140
|
+
as={ChevronRight}
|
|
141
|
+
variant="ghost"
|
|
142
|
+
color="neutral"
|
|
143
|
+
size="small"
|
|
144
|
+
accessibilityLabel={labels.nextYear}
|
|
145
|
+
isDisabled={disabled || isYearView}
|
|
146
|
+
focusable={!isYearView}
|
|
147
|
+
onPress={() => shiftYear(1)}
|
|
148
|
+
/>
|
|
149
|
+
</View>
|
|
134
150
|
</View>
|
|
135
151
|
);
|
|
136
152
|
});
|
|
@@ -138,25 +154,31 @@ const MonthCalendarHeader = forwardRef<View, ViewProps>(({ className, style, ...
|
|
|
138
154
|
MonthCalendarHeader.displayName = 'MonthCalendar.Header';
|
|
139
155
|
|
|
140
156
|
const MonthCalendarGrid = forwardRef<View, ViewProps>(({ className, style, ...props }, ref) => {
|
|
141
|
-
const { view, visibleYear } = useMonthCalendarContext();
|
|
142
|
-
|
|
143
|
-
const years = useMemo(
|
|
144
|
-
() => Array.from({ length: 12 }, (_, i) => visibleYear - 5 + i),
|
|
145
|
-
[visibleYear],
|
|
146
|
-
);
|
|
157
|
+
const { view, visibleYear, minValue, maxValue } = useMonthCalendarContext();
|
|
158
|
+
const [todayYear] = useState(() => new Date().getFullYear());
|
|
147
159
|
|
|
148
160
|
if (view === 'year') {
|
|
161
|
+
const { first, last } = getYearRange(
|
|
162
|
+
minValue ? parseMonthId(minValue)?.year : undefined,
|
|
163
|
+
maxValue ? parseMonthId(maxValue)?.year : undefined,
|
|
164
|
+
visibleYear,
|
|
165
|
+
todayYear,
|
|
166
|
+
);
|
|
149
167
|
return (
|
|
150
168
|
<View
|
|
151
169
|
ref={ref}
|
|
152
|
-
className={cn(
|
|
170
|
+
className={cn(calendarYearPickerListVariants(), className)}
|
|
153
171
|
style={style}
|
|
154
172
|
accessibilityRole="none"
|
|
155
173
|
{...props}
|
|
156
174
|
>
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
175
|
+
<CalendarYearList
|
|
176
|
+
first={first}
|
|
177
|
+
last={last}
|
|
178
|
+
selectedYear={visibleYear}
|
|
179
|
+
height={MONTH_GRID_HEIGHT}
|
|
180
|
+
renderYear={renderYearCell}
|
|
181
|
+
/>
|
|
160
182
|
</View>
|
|
161
183
|
);
|
|
162
184
|
}
|
|
@@ -14,6 +14,8 @@ import { CalendarYearPickerGrid } from '../Calendar/CalendarYearPickerGrid';
|
|
|
14
14
|
import {
|
|
15
15
|
FLASH_CALENDAR_DAY_HEIGHT,
|
|
16
16
|
FLASH_CALENDAR_RANGE_DAY_SPACING,
|
|
17
|
+
FLASH_CALENDAR_ROW_VERTICAL_SPACING,
|
|
18
|
+
FLASH_CALENDAR_WEEK_HEADER_HEIGHT,
|
|
17
19
|
formatFlashCalendarWeekdayShort,
|
|
18
20
|
toCalendarDateId,
|
|
19
21
|
useFlashCalendarRangeTheme,
|
|
@@ -78,12 +80,15 @@ RangeCalendarHeader.displayName = 'RangeCalendar.Header';
|
|
|
78
80
|
|
|
79
81
|
const RangeCalendarYearPicker = forwardRef<View, ViewProps>(
|
|
80
82
|
({ className, style, ...props }, ref) => {
|
|
81
|
-
const { monthId, onMonthIdChange, disabled, setView, labels } =
|
|
83
|
+
const { monthId, onMonthIdChange, minValue, maxValue, disabled, setView, labels } =
|
|
84
|
+
useRangeCalendarContext();
|
|
82
85
|
return (
|
|
83
86
|
<CalendarYearPickerGrid
|
|
84
87
|
ref={ref}
|
|
85
88
|
monthId={monthId}
|
|
86
89
|
onMonthIdChange={onMonthIdChange}
|
|
90
|
+
minValue={minValue}
|
|
91
|
+
maxValue={maxValue}
|
|
87
92
|
disabled={disabled}
|
|
88
93
|
onViewChange={setView}
|
|
89
94
|
labels={labels}
|
|
@@ -137,8 +142,8 @@ const RangeCalendarGrid = forwardRef<View, ViewProps>(({ className, style, ...pr
|
|
|
137
142
|
calendarMaxDateId={maxValue}
|
|
138
143
|
calendarMonthHeaderHeight={0}
|
|
139
144
|
calendarDayHeight={FLASH_CALENDAR_DAY_HEIGHT}
|
|
140
|
-
calendarWeekHeaderHeight={
|
|
141
|
-
calendarRowVerticalSpacing={
|
|
145
|
+
calendarWeekHeaderHeight={FLASH_CALENDAR_WEEK_HEADER_HEIGHT}
|
|
146
|
+
calendarRowVerticalSpacing={FLASH_CALENDAR_ROW_VERTICAL_SPACING}
|
|
142
147
|
calendarRowHorizontalSpacing={FLASH_CALENDAR_RANGE_DAY_SPACING}
|
|
143
148
|
getCalendarMonthFormat={() => ''}
|
|
144
149
|
getCalendarWeekDayFormat={formatWeekday}
|