@ankhorage/zora 12.1.0 → 14.0.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/CHANGELOG.md +16 -0
- package/README.md +11 -5
- package/dist/features/accordion/accordionItemMeta.d.ts +53 -0
- package/dist/features/accordion/accordionItemMeta.d.ts.map +1 -0
- package/dist/features/accordion/accordionItemMeta.js +45 -0
- package/dist/features/accordion/accordionItemMeta.js.map +1 -0
- package/dist/features/accordion/accordionMeta.d.ts +36 -0
- package/dist/features/accordion/accordionMeta.d.ts.map +1 -0
- package/dist/features/accordion/accordionMeta.js +33 -0
- package/dist/features/accordion/accordionMeta.js.map +1 -0
- package/dist/features/accordion/adapters/inbound/Accordion.d.ts +5 -0
- package/dist/features/accordion/adapters/inbound/Accordion.d.ts.map +1 -0
- package/dist/features/accordion/adapters/inbound/Accordion.js +41 -0
- package/dist/features/accordion/adapters/inbound/Accordion.js.map +1 -0
- package/dist/features/accordion/adapters/inbound/AccordionItem.d.ts +5 -0
- package/dist/features/accordion/adapters/inbound/AccordionItem.d.ts.map +1 -0
- package/dist/features/accordion/adapters/inbound/AccordionItem.js +52 -0
- package/dist/features/accordion/adapters/inbound/AccordionItem.js.map +1 -0
- package/dist/features/accordion/composition/AccordionPresentationContext.d.ts +4 -0
- package/dist/features/accordion/composition/AccordionPresentationContext.d.ts.map +1 -0
- package/dist/features/accordion/composition/AccordionPresentationContext.js +3 -0
- package/dist/features/accordion/composition/AccordionPresentationContext.js.map +1 -0
- package/dist/features/accordion/public.d.ts +4 -0
- package/dist/features/accordion/public.d.ts.map +1 -0
- package/dist/features/accordion/public.js +3 -0
- package/dist/features/accordion/public.js.map +1 -0
- package/dist/features/bottom-sheet/bottomSheetMeta.d.ts +1 -1
- package/dist/features/card/cardMeta.d.ts +1 -1
- package/dist/features/card/mediaCardMeta.d.ts +1 -1
- package/dist/features/card/postCardMeta.d.ts +1 -1
- package/dist/features/date-picker/adapters/inbound/DatePicker.d.ts +1 -6
- package/dist/features/date-picker/adapters/inbound/DatePicker.d.ts.map +1 -1
- package/dist/features/date-picker/adapters/inbound/DatePicker.js +1 -175
- package/dist/features/date-picker/adapters/inbound/DatePicker.js.map +1 -1
- package/dist/features/date-picker/adapters/inbound/DatePicker.native.d.ts +5 -0
- package/dist/features/date-picker/adapters/inbound/DatePicker.native.d.ts.map +1 -0
- package/dist/features/date-picker/adapters/inbound/DatePicker.native.js +27 -0
- package/dist/features/date-picker/adapters/inbound/DatePicker.native.js.map +1 -0
- package/dist/features/date-picker/adapters/inbound/DatePicker.web.d.ts +5 -0
- package/dist/features/date-picker/adapters/inbound/DatePicker.web.d.ts.map +1 -0
- package/dist/features/date-picker/adapters/inbound/DatePicker.web.js +25 -0
- package/dist/features/date-picker/adapters/inbound/DatePicker.web.js.map +1 -0
- package/dist/features/date-picker/composition/DatePickerContent.d.ts +10 -0
- package/dist/features/date-picker/composition/DatePickerContent.d.ts.map +1 -0
- package/dist/features/date-picker/composition/DatePickerContent.js +129 -0
- package/dist/features/date-picker/composition/DatePickerContent.js.map +1 -0
- package/dist/features/date-picker/composition/DatePickerField.d.ts +9 -0
- package/dist/features/date-picker/composition/DatePickerField.d.ts.map +1 -0
- package/dist/features/date-picker/composition/DatePickerField.js +21 -0
- package/dist/features/date-picker/composition/DatePickerField.js.map +1 -0
- package/dist/features/date-picker/composition/DatePickerTrigger.d.ts +9 -0
- package/dist/features/date-picker/composition/DatePickerTrigger.d.ts.map +1 -0
- package/dist/features/date-picker/composition/DatePickerTrigger.js +18 -0
- package/dist/features/date-picker/composition/DatePickerTrigger.js.map +1 -0
- package/dist/features/gradient/gradientMeta.d.ts +1 -1
- package/dist/features/keyboard-avoiding-view/keyboardAvoidingViewMeta.d.ts +1 -1
- package/dist/features/layout/boxMeta.d.ts +1 -1
- package/dist/features/layout/containerMeta.d.ts +1 -1
- package/dist/features/layout/gridMeta.d.ts +1 -1
- package/dist/features/layout/stackMeta.d.ts +1 -1
- package/dist/features/list/flatListMeta.d.ts +1 -1
- package/dist/features/list/sectionListMeta.d.ts +1 -1
- package/dist/features/surface/surfaceMeta.d.ts +1 -1
- package/dist/features/time-picker/adapters/inbound/TimePicker.d.ts +1 -6
- package/dist/features/time-picker/adapters/inbound/TimePicker.d.ts.map +1 -1
- package/dist/features/time-picker/adapters/inbound/TimePicker.js +1 -116
- package/dist/features/time-picker/adapters/inbound/TimePicker.js.map +1 -1
- package/dist/features/time-picker/adapters/inbound/TimePicker.native.d.ts +5 -0
- package/dist/features/time-picker/adapters/inbound/TimePicker.native.d.ts.map +1 -0
- package/dist/features/time-picker/adapters/inbound/TimePicker.native.js +26 -0
- package/dist/features/time-picker/adapters/inbound/TimePicker.native.js.map +1 -0
- package/dist/features/time-picker/adapters/inbound/TimePicker.web.d.ts +5 -0
- package/dist/features/time-picker/adapters/inbound/TimePicker.web.d.ts.map +1 -0
- package/dist/features/time-picker/adapters/inbound/TimePicker.web.js +24 -0
- package/dist/features/time-picker/adapters/inbound/TimePicker.web.js.map +1 -0
- package/dist/features/time-picker/composition/TimePickerContent.d.ts +10 -0
- package/dist/features/time-picker/composition/TimePickerContent.d.ts.map +1 -0
- package/dist/features/time-picker/composition/TimePickerContent.js +78 -0
- package/dist/features/time-picker/composition/TimePickerContent.js.map +1 -0
- package/dist/features/time-picker/composition/TimePickerField.d.ts +9 -0
- package/dist/features/time-picker/composition/TimePickerField.d.ts.map +1 -0
- package/dist/features/time-picker/composition/TimePickerField.js +21 -0
- package/dist/features/time-picker/composition/TimePickerField.js.map +1 -0
- package/dist/features/time-picker/composition/TimePickerTrigger.d.ts +8 -0
- package/dist/features/time-picker/composition/TimePickerTrigger.d.ts.map +1 -0
- package/dist/features/time-picker/composition/TimePickerTrigger.js +9 -0
- package/dist/features/time-picker/composition/TimePickerTrigger.js.map +1 -0
- package/dist/features/toast/adapters/inbound/Toast.d.ts +5 -0
- package/dist/features/toast/adapters/inbound/Toast.d.ts.map +1 -0
- package/dist/features/toast/adapters/inbound/Toast.js +10 -0
- package/dist/features/toast/adapters/inbound/Toast.js.map +1 -0
- package/dist/features/toast/adapters/inbound/ToastProvider.d.ts +5 -0
- package/dist/features/toast/adapters/inbound/ToastProvider.d.ts.map +1 -0
- package/dist/features/toast/adapters/inbound/ToastProvider.js +7 -0
- package/dist/features/toast/adapters/inbound/ToastProvider.js.map +1 -0
- package/dist/features/toast/public.d.ts +5 -0
- package/dist/features/toast/public.d.ts.map +1 -0
- package/dist/features/toast/public.js +4 -0
- package/dist/features/toast/public.js.map +1 -0
- package/dist/features/toast/toastMeta.d.ts +9 -0
- package/dist/features/toast/toastMeta.d.ts.map +1 -0
- package/dist/features/toast/toastMeta.js +9 -0
- package/dist/features/toast/toastMeta.js.map +1 -0
- package/dist/features/toast/toastProviderMeta.d.ts +9 -0
- package/dist/features/toast/toastProviderMeta.d.ts.map +1 -0
- package/dist/features/toast/toastProviderMeta.js +9 -0
- package/dist/features/toast/toastProviderMeta.js.map +1 -0
- package/dist/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/layout/screen/meta.d.ts +1 -1
- package/dist/layout/screen-section/meta.d.ts +1 -1
- package/dist/metadata/allowedChildren.d.ts +3 -3
- package/dist/metadata/allowedChildren.d.ts.map +1 -1
- package/dist/metadata/allowedChildren.js +1 -0
- package/dist/metadata/allowedChildren.js.map +1 -1
- package/dist/metadata/bindableComponentMeta.d.ts +2 -2
- package/dist/metadata/componentMeta.d.ts.map +1 -1
- package/dist/metadata/componentMeta.js +6 -3
- package/dist/metadata/componentMeta.js.map +1 -1
- package/dist/patterns/message-bubble/meta.d.ts +1 -1
- package/dist/patterns/notice/meta.d.ts +1 -1
- package/dist/patterns/panel/meta.d.ts +1 -1
- package/dist/patterns/reader/meta.d.ts +2 -2
- package/dist/patterns/scanner/meta.d.ts +2 -2
- package/dist/patterns/selection/SelectionProvider.d.ts +0 -4
- package/dist/patterns/selection/SelectionProvider.d.ts.map +1 -1
- package/dist/patterns/selection/SelectionProvider.js +4 -6
- package/dist/patterns/selection/SelectionProvider.js.map +1 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +4 -3
- package/dist/registry.js.map +1 -1
- package/dist/theme/ZoraProvider.d.ts +4 -10
- package/dist/theme/ZoraProvider.d.ts.map +1 -1
- package/dist/theme/ZoraProvider.js +8 -6
- package/dist/theme/ZoraProvider.js.map +1 -1
- package/dist/theme/ZoraRuntimeCapabilities.d.ts +2 -0
- package/dist/theme/ZoraRuntimeCapabilities.d.ts.map +1 -0
- package/dist/theme/ZoraRuntimeCapabilities.js +2 -0
- package/dist/theme/ZoraRuntimeCapabilities.js.map +1 -0
- package/dist/theme/ZoraRuntimeCapabilities.native.d.ts +4 -0
- package/dist/theme/ZoraRuntimeCapabilities.native.d.ts.map +1 -0
- package/dist/theme/ZoraRuntimeCapabilities.native.js +8 -0
- package/dist/theme/ZoraRuntimeCapabilities.native.js.map +1 -0
- package/dist/theme/ZoraRuntimeCapabilities.web.d.ts +4 -0
- package/dist/theme/ZoraRuntimeCapabilities.web.d.ts.map +1 -0
- package/dist/theme/ZoraRuntimeCapabilities.web.js +8 -0
- package/dist/theme/ZoraRuntimeCapabilities.web.js.map +1 -0
- package/dist/theme/ZoraThemeRuntimeContext.d.ts +1 -0
- package/dist/theme/ZoraThemeRuntimeContext.d.ts.map +1 -1
- package/dist/theme/ZoraThemeRuntimeContext.js +3 -2
- package/dist/theme/ZoraThemeRuntimeContext.js.map +1 -1
- package/dist/theme/ZoraThemeScope.d.ts +1 -0
- package/dist/theme/ZoraThemeScope.d.ts.map +1 -1
- package/dist/theme/ZoraThemeScope.js +12 -10
- package/dist/theme/ZoraThemeScope.js.map +1 -1
- package/dist/theme/index.d.ts +1 -1
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js.map +1 -1
- package/dist/types/accordion.d.ts +23 -0
- package/dist/types/accordion.d.ts.map +1 -0
- package/dist/types/accordion.js +2 -0
- package/dist/types/accordion.js.map +1 -0
- package/dist/types/provider.d.ts +19 -0
- package/dist/types/provider.d.ts.map +1 -0
- package/dist/types/provider.js +2 -0
- package/dist/types/provider.js.map +1 -0
- package/dist/types/toast.d.ts +9 -0
- package/dist/types/toast.d.ts.map +1 -0
- package/dist/types/toast.js +2 -0
- package/dist/types/toast.js.map +1 -0
- package/package.json +2 -2
- package/src/features/accordion/accordionItemMeta.ts +46 -0
- package/src/features/accordion/accordionMeta.ts +34 -0
- package/src/features/accordion/adapters/inbound/Accordion.tsx +94 -0
- package/src/features/accordion/adapters/inbound/AccordionItem.tsx +86 -0
- package/src/features/accordion/composition/AccordionPresentationContext.ts +6 -0
- package/src/features/accordion/public.ts +9 -0
- package/src/features/bottom-sheet/public.test.ts +15 -12
- package/src/features/date-picker/adapters/inbound/DatePicker.native.tsx +46 -0
- package/src/features/date-picker/adapters/inbound/DatePicker.tsx +1 -356
- package/src/features/date-picker/adapters/inbound/DatePicker.web.tsx +48 -0
- package/src/features/date-picker/composition/DatePickerContent.tsx +256 -0
- package/src/features/date-picker/composition/DatePickerField.tsx +53 -0
- package/src/features/date-picker/composition/DatePickerTrigger.tsx +47 -0
- package/src/features/date-picker/public.test.ts +14 -4
- package/src/features/time-picker/adapters/inbound/TimePicker.native.tsx +47 -0
- package/src/features/time-picker/adapters/inbound/TimePicker.tsx +1 -258
- package/src/features/time-picker/adapters/inbound/TimePicker.web.tsx +49 -0
- package/src/features/time-picker/composition/TimePickerContent.tsx +164 -0
- package/src/features/time-picker/composition/TimePickerField.tsx +53 -0
- package/src/features/time-picker/composition/TimePickerTrigger.tsx +35 -0
- package/src/features/time-picker/public.test.ts +14 -3
- package/src/features/toast/adapters/inbound/Toast.tsx +13 -0
- package/src/features/toast/adapters/inbound/ToastProvider.tsx +9 -0
- package/src/features/toast/public.test.ts +19 -0
- package/src/features/toast/public.ts +10 -0
- package/src/features/toast/toastMeta.ts +10 -0
- package/src/features/toast/toastProviderMeta.ts +10 -0
- package/src/index.ts +17 -4
- package/src/metadata/allowedChildren.ts +1 -0
- package/src/metadata/componentMeta.test.ts +9 -0
- package/src/metadata/componentMeta.ts +6 -3
- package/src/patterns/selection/SelectionProvider.tsx +4 -6
- package/src/registry.ts +4 -3
- package/src/showcaseCoverage.test.ts +2 -1
- package/src/theme/ZoraProvider.tsx +11 -13
- package/src/theme/ZoraRuntimeCapabilities.native.tsx +19 -0
- package/src/theme/ZoraRuntimeCapabilities.tsx +1 -0
- package/src/theme/ZoraRuntimeCapabilities.web.tsx +10 -0
- package/src/theme/ZoraThemeRuntimeContext.tsx +3 -2
- package/src/theme/ZoraThemeScope.tsx +14 -12
- package/src/theme/index.ts +1 -1
- package/src/theme/themeConfigScope.test.ts +4 -1
- package/src/theme/themeScopeStructure.test.ts +27 -18
- package/src/types/accordion.ts +38 -0
- package/src/types/provider.ts +22 -0
- package/src/{components/toast/types.ts → types/toast.ts} +5 -7
- package/dist/components/toast/Toast.d.ts +0 -9
- package/dist/components/toast/Toast.d.ts.map +0 -1
- package/dist/components/toast/Toast.js +0 -13
- package/dist/components/toast/Toast.js.map +0 -1
- package/dist/components/toast/ToastProvider.d.ts +0 -9
- package/dist/components/toast/ToastProvider.d.ts.map +0 -1
- package/dist/components/toast/ToastProvider.js +0 -14
- package/dist/components/toast/ToastProvider.js.map +0 -1
- package/dist/components/toast/index.d.ts +0 -5
- package/dist/components/toast/index.d.ts.map +0 -1
- package/dist/components/toast/index.js +0 -4
- package/dist/components/toast/index.js.map +0 -1
- package/dist/components/toast/meta.d.ts +0 -17
- package/dist/components/toast/meta.d.ts.map +0 -1
- package/dist/components/toast/meta.js +0 -17
- package/dist/components/toast/meta.js.map +0 -1
- package/dist/components/toast/types.d.ts +0 -12
- package/dist/components/toast/types.d.ts.map +0 -1
- package/dist/components/toast/types.js +0 -2
- package/dist/components/toast/types.js.map +0 -1
- package/dist/patterns/disclosure-section/DisclosureSection.d.ts +0 -9
- package/dist/patterns/disclosure-section/DisclosureSection.d.ts.map +0 -1
- package/dist/patterns/disclosure-section/DisclosureSection.js +0 -86
- package/dist/patterns/disclosure-section/DisclosureSection.js.map +0 -1
- package/dist/patterns/disclosure-section/index.d.ts +0 -3
- package/dist/patterns/disclosure-section/index.d.ts.map +0 -1
- package/dist/patterns/disclosure-section/index.js +0 -3
- package/dist/patterns/disclosure-section/index.js.map +0 -1
- package/dist/patterns/disclosure-section/meta.d.ts +0 -9
- package/dist/patterns/disclosure-section/meta.d.ts.map +0 -1
- package/dist/patterns/disclosure-section/meta.js +0 -9
- package/dist/patterns/disclosure-section/meta.js.map +0 -1
- package/dist/patterns/disclosure-section/types.d.ts +0 -15
- package/dist/patterns/disclosure-section/types.d.ts.map +0 -1
- package/dist/patterns/disclosure-section/types.js +0 -2
- package/dist/patterns/disclosure-section/types.js.map +0 -1
- package/src/components/toast/Toast.tsx +0 -16
- package/src/components/toast/ToastProvider.tsx +0 -17
- package/src/components/toast/index.ts +0 -4
- package/src/components/toast/meta.ts +0 -19
- package/src/patterns/disclosure-section/DisclosureSection.tsx +0 -130
- package/src/patterns/disclosure-section/index.ts +0 -2
- package/src/patterns/disclosure-section/meta.ts +0 -10
- package/src/patterns/disclosure-section/types.ts +0 -16
|
@@ -1,356 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import React from 'react';
|
|
3
|
-
|
|
4
|
-
import { withZoraThemeScope } from '../../../../theme/withZoraThemeScope';
|
|
5
|
-
import type { DatePickerProps } from '../../../../types/date-picker';
|
|
6
|
-
import { useBottomSheet } from '../../../bottom-sheet/public';
|
|
7
|
-
import { Button } from '../../../button/public';
|
|
8
|
-
import { Box, Stack } from '../../../layout/public';
|
|
9
|
-
import { Text } from '../../../typography/public';
|
|
10
|
-
import { formatLocalDate, parseLocalDate } from '../../utils/localDate';
|
|
11
|
-
|
|
12
|
-
const WEEKDAY_LABELS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] as const;
|
|
13
|
-
const DAY_CELL_WIDTH = 42;
|
|
14
|
-
|
|
15
|
-
/*** Render the field label and optional supporting description. */
|
|
16
|
-
function renderLabel(label: React.ReactNode, description: React.ReactNode | undefined) {
|
|
17
|
-
return (
|
|
18
|
-
<Stack gap="xs">
|
|
19
|
-
<Text variant="label" weight="semiBold">
|
|
20
|
-
{label}
|
|
21
|
-
</Text>
|
|
22
|
-
{description ? (
|
|
23
|
-
<Text emphasis="muted" variant="bodySmall">
|
|
24
|
-
{description}
|
|
25
|
-
</Text>
|
|
26
|
-
) : null}
|
|
27
|
-
</Stack>
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/*** Compare two values by local calendar day. */
|
|
32
|
-
function isSameLocalDay(left: string | null, right: Date): boolean {
|
|
33
|
-
return left === formatLocalDate(right);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/*** Normalize a Date to the start of its local calendar day for range comparisons. */
|
|
37
|
-
function startOfLocalDay(value: Date): Date {
|
|
38
|
-
return new Date(value.getFullYear(), value.getMonth(), value.getDate());
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/*** Report whether one local calendar day precedes another. */
|
|
42
|
-
function isBeforeLocalDay(left: Date, right: Date): boolean {
|
|
43
|
-
return startOfLocalDay(left).getTime() < startOfLocalDay(right).getTime();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/*** Report whether one local calendar day follows another. */
|
|
47
|
-
function isAfterLocalDay(left: Date, right: Date): boolean {
|
|
48
|
-
return startOfLocalDay(left).getTime() > startOfLocalDay(right).getTime();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/*** Resolve whether a date falls outside the configured picker range. */
|
|
52
|
-
function isDateDisabled(
|
|
53
|
-
value: Date,
|
|
54
|
-
minDate: Date | undefined,
|
|
55
|
-
maxDate: Date | undefined,
|
|
56
|
-
): boolean {
|
|
57
|
-
if (minDate && isBeforeLocalDay(value, minDate)) return true;
|
|
58
|
-
if (maxDate && isAfterLocalDay(value, maxDate)) return true;
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/*** Format the current calendar month for the picker heading. */
|
|
63
|
-
function formatMonthLabel(value: Date): string {
|
|
64
|
-
return value.toLocaleDateString(undefined, { month: 'long', year: 'numeric' });
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/*** Format a selected date with the platform locale defaults. */
|
|
68
|
-
function formatDefaultDate(value: string): string {
|
|
69
|
-
return parseLocalDate(value)?.toLocaleDateString() ?? value;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/*** Build the padded calendar grid for one month. */
|
|
73
|
-
function createMonthDays(month: Date): (Date | null)[] {
|
|
74
|
-
const firstDay = new Date(month.getFullYear(), month.getMonth(), 1);
|
|
75
|
-
const dayCount = new Date(month.getFullYear(), month.getMonth() + 1, 0).getDate();
|
|
76
|
-
const populatedLength = firstDay.getDay() + dayCount;
|
|
77
|
-
const paddedLength = Math.ceil(populatedLength / 7) * 7;
|
|
78
|
-
|
|
79
|
-
return Array.from({ length: paddedLength }, (_, index) =>
|
|
80
|
-
index < firstDay.getDay()
|
|
81
|
-
? null
|
|
82
|
-
: new Date(month.getFullYear(), month.getMonth(), index - firstDay.getDay() + 1),
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/*** Resolve the month initially shown by the calendar sheet. */
|
|
87
|
-
function resolveInitialMonth(value: string | null, minDate: string | undefined): Date {
|
|
88
|
-
const base = parseLocalDate(value) ?? parseLocalDate(minDate) ?? new Date();
|
|
89
|
-
return new Date(base.getFullYear(), base.getMonth(), 1);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/*** Report whether the configured range intersects a candidate month. */
|
|
93
|
-
function canNavigateToMonth(
|
|
94
|
-
month: Date,
|
|
95
|
-
minDate: Date | undefined,
|
|
96
|
-
maxDate: Date | undefined,
|
|
97
|
-
): boolean {
|
|
98
|
-
const firstDay = new Date(month.getFullYear(), month.getMonth(), 1);
|
|
99
|
-
const lastDay = new Date(month.getFullYear(), month.getMonth() + 1, 0);
|
|
100
|
-
|
|
101
|
-
if (maxDate && isAfterLocalDay(firstDay, maxDate)) return false;
|
|
102
|
-
if (minDate && isBeforeLocalDay(lastDay, minDate)) return false;
|
|
103
|
-
return true;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function DatePickerInner({
|
|
107
|
-
themeId: _themeId,
|
|
108
|
-
mode: _mode,
|
|
109
|
-
value,
|
|
110
|
-
onValueChange,
|
|
111
|
-
label,
|
|
112
|
-
description,
|
|
113
|
-
error,
|
|
114
|
-
placeholder = 'Choose date',
|
|
115
|
-
minDate,
|
|
116
|
-
maxDate,
|
|
117
|
-
disabled = false,
|
|
118
|
-
required = false,
|
|
119
|
-
formatDate,
|
|
120
|
-
testID,
|
|
121
|
-
interactionPolicy,
|
|
122
|
-
}: DatePickerProps) {
|
|
123
|
-
const { dismiss, present } = useBottomSheet();
|
|
124
|
-
const passive = interactionPolicy === 'passive';
|
|
125
|
-
const displayValue = value
|
|
126
|
-
? formatDate
|
|
127
|
-
? formatDate(value)
|
|
128
|
-
: formatDefaultDate(value)
|
|
129
|
-
: placeholder;
|
|
130
|
-
|
|
131
|
-
/*** Present the calendar content through the shared BottomSheet controller. */
|
|
132
|
-
function openPicker() {
|
|
133
|
-
if (passive) return;
|
|
134
|
-
present({
|
|
135
|
-
content: (
|
|
136
|
-
<DatePickerSheet
|
|
137
|
-
description={description}
|
|
138
|
-
interactionPolicy={interactionPolicy}
|
|
139
|
-
label={label}
|
|
140
|
-
maxDate={maxDate}
|
|
141
|
-
minDate={minDate}
|
|
142
|
-
onDismiss={dismiss}
|
|
143
|
-
onSelect={(date) => {
|
|
144
|
-
onValueChange?.(formatLocalDate(date));
|
|
145
|
-
dismiss();
|
|
146
|
-
}}
|
|
147
|
-
testID={testID}
|
|
148
|
-
value={value}
|
|
149
|
-
/>
|
|
150
|
-
),
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return (
|
|
155
|
-
<Field
|
|
156
|
-
disabled={disabled}
|
|
157
|
-
errorText={error}
|
|
158
|
-
invalid={Boolean(error)}
|
|
159
|
-
label={label ? renderLabel(label, description) : undefined}
|
|
160
|
-
required={required}
|
|
161
|
-
testID={testID}
|
|
162
|
-
>
|
|
163
|
-
<Button
|
|
164
|
-
disabled={disabled}
|
|
165
|
-
interactionPolicy={interactionPolicy}
|
|
166
|
-
onPress={openPicker}
|
|
167
|
-
testID={testID ? `${testID}-trigger` : undefined}
|
|
168
|
-
trailingIcon={{ name: 'calendar-outline' }}
|
|
169
|
-
variant="outline"
|
|
170
|
-
>
|
|
171
|
-
{displayValue}
|
|
172
|
-
</Button>
|
|
173
|
-
</Field>
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
interface DatePickerSheetProps extends Pick<
|
|
178
|
-
DatePickerProps,
|
|
179
|
-
'description' | 'interactionPolicy' | 'label' | 'maxDate' | 'minDate' | 'testID' | 'value'
|
|
180
|
-
> {
|
|
181
|
-
onDismiss: () => void;
|
|
182
|
-
onSelect: (value: Date) => void;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/*** Render the calendar-specific content inside the shared BottomSheet host. */
|
|
186
|
-
function DatePickerSheet({
|
|
187
|
-
description,
|
|
188
|
-
interactionPolicy,
|
|
189
|
-
label,
|
|
190
|
-
maxDate,
|
|
191
|
-
minDate,
|
|
192
|
-
onDismiss,
|
|
193
|
-
onSelect,
|
|
194
|
-
testID,
|
|
195
|
-
value,
|
|
196
|
-
}: DatePickerSheetProps) {
|
|
197
|
-
const [displayMonth, setDisplayMonth] = React.useState(() => resolveInitialMonth(value, minDate));
|
|
198
|
-
const monthDays = React.useMemo(() => createMonthDays(displayMonth), [displayMonth]);
|
|
199
|
-
const resolvedMaxDate = React.useMemo(() => parseLocalDate(maxDate), [maxDate]);
|
|
200
|
-
const resolvedMinDate = React.useMemo(() => parseLocalDate(minDate), [minDate]);
|
|
201
|
-
|
|
202
|
-
return (
|
|
203
|
-
<Stack gap="m" p="m" testID={testID ? `${testID}-sheet` : undefined}>
|
|
204
|
-
<PickerSheetHeader description={description} title={label ?? 'Choose date'} />
|
|
205
|
-
<DatePickerMonthNavigation
|
|
206
|
-
displayMonth={displayMonth}
|
|
207
|
-
interactionPolicy={interactionPolicy}
|
|
208
|
-
maxDate={resolvedMaxDate}
|
|
209
|
-
minDate={resolvedMinDate}
|
|
210
|
-
onMonthChange={setDisplayMonth}
|
|
211
|
-
/>
|
|
212
|
-
<DatePickerWeekdays />
|
|
213
|
-
<DatePickerCalendar
|
|
214
|
-
interactionPolicy={interactionPolicy}
|
|
215
|
-
maxDate={resolvedMaxDate}
|
|
216
|
-
minDate={resolvedMinDate}
|
|
217
|
-
monthDays={monthDays}
|
|
218
|
-
onSelect={onSelect}
|
|
219
|
-
testID={testID}
|
|
220
|
-
value={value}
|
|
221
|
-
/>
|
|
222
|
-
<Button fullWidth interactionPolicy={interactionPolicy} onPress={onDismiss} variant="ghost">
|
|
223
|
-
Cancel
|
|
224
|
-
</Button>
|
|
225
|
-
</Stack>
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/*** Render the shared title block used by the calendar sheet. */
|
|
230
|
-
function PickerSheetHeader({
|
|
231
|
-
description,
|
|
232
|
-
title,
|
|
233
|
-
}: {
|
|
234
|
-
description: React.ReactNode | undefined;
|
|
235
|
-
title: React.ReactNode;
|
|
236
|
-
}) {
|
|
237
|
-
return (
|
|
238
|
-
<Stack gap="xxs">
|
|
239
|
-
<Text align="center" variant="label" weight="semiBold">
|
|
240
|
-
{title}
|
|
241
|
-
</Text>
|
|
242
|
-
{description ? (
|
|
243
|
-
<Text align="center" emphasis="muted" variant="bodySmall">
|
|
244
|
-
{description}
|
|
245
|
-
</Text>
|
|
246
|
-
) : null}
|
|
247
|
-
</Stack>
|
|
248
|
-
);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/*** Render previous/next month controls for the calendar sheet. */
|
|
252
|
-
function DatePickerMonthNavigation({
|
|
253
|
-
displayMonth,
|
|
254
|
-
interactionPolicy,
|
|
255
|
-
maxDate,
|
|
256
|
-
minDate,
|
|
257
|
-
onMonthChange,
|
|
258
|
-
}: {
|
|
259
|
-
displayMonth: Date;
|
|
260
|
-
interactionPolicy: DatePickerProps['interactionPolicy'];
|
|
261
|
-
maxDate: Date | undefined;
|
|
262
|
-
minDate: Date | undefined;
|
|
263
|
-
onMonthChange: (month: Date) => void;
|
|
264
|
-
}) {
|
|
265
|
-
const previousMonth = new Date(displayMonth.getFullYear(), displayMonth.getMonth() - 1, 1);
|
|
266
|
-
const nextMonth = new Date(displayMonth.getFullYear(), displayMonth.getMonth() + 1, 1);
|
|
267
|
-
|
|
268
|
-
return (
|
|
269
|
-
<Stack align="center" direction="row" justify="space-between">
|
|
270
|
-
<Button
|
|
271
|
-
disabled={!canNavigateToMonth(previousMonth, minDate, maxDate)}
|
|
272
|
-
interactionPolicy={interactionPolicy}
|
|
273
|
-
onPress={() => onMonthChange(previousMonth)}
|
|
274
|
-
size="s"
|
|
275
|
-
variant="ghost"
|
|
276
|
-
>
|
|
277
|
-
Previous
|
|
278
|
-
</Button>
|
|
279
|
-
<Text align="center" variant="label" weight="semiBold">
|
|
280
|
-
{formatMonthLabel(displayMonth)}
|
|
281
|
-
</Text>
|
|
282
|
-
<Button
|
|
283
|
-
disabled={!canNavigateToMonth(nextMonth, minDate, maxDate)}
|
|
284
|
-
interactionPolicy={interactionPolicy}
|
|
285
|
-
onPress={() => onMonthChange(nextMonth)}
|
|
286
|
-
size="s"
|
|
287
|
-
variant="ghost"
|
|
288
|
-
>
|
|
289
|
-
Next
|
|
290
|
-
</Button>
|
|
291
|
-
</Stack>
|
|
292
|
-
);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/*** Render weekday headings for the calendar grid. */
|
|
296
|
-
function DatePickerWeekdays() {
|
|
297
|
-
return (
|
|
298
|
-
<Stack direction="row" justify="space-between">
|
|
299
|
-
{WEEKDAY_LABELS.map((weekday) => (
|
|
300
|
-
<Box key={weekday} width={DAY_CELL_WIDTH}>
|
|
301
|
-
<Text align="center" emphasis="muted" variant="caption" weight="semiBold">
|
|
302
|
-
{weekday}
|
|
303
|
-
</Text>
|
|
304
|
-
</Box>
|
|
305
|
-
))}
|
|
306
|
-
</Stack>
|
|
307
|
-
);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/*** Render selectable day cells for the current calendar month. */
|
|
311
|
-
function DatePickerCalendar({
|
|
312
|
-
interactionPolicy,
|
|
313
|
-
maxDate,
|
|
314
|
-
minDate,
|
|
315
|
-
monthDays,
|
|
316
|
-
onSelect,
|
|
317
|
-
testID,
|
|
318
|
-
value,
|
|
319
|
-
}: {
|
|
320
|
-
interactionPolicy: DatePickerProps['interactionPolicy'];
|
|
321
|
-
maxDate: Date | undefined;
|
|
322
|
-
minDate: Date | undefined;
|
|
323
|
-
monthDays: readonly (Date | null)[];
|
|
324
|
-
onSelect: (value: Date) => void;
|
|
325
|
-
testID: string | undefined;
|
|
326
|
-
value: DatePickerProps['value'];
|
|
327
|
-
}) {
|
|
328
|
-
return (
|
|
329
|
-
<Stack direction="row" gap="xs" wrap="wrap">
|
|
330
|
-
{monthDays.map((day, index) => {
|
|
331
|
-
if (!day) return <Box key={`empty-${index}`} width={DAY_CELL_WIDTH} />;
|
|
332
|
-
const selected = isSameLocalDay(value, day);
|
|
333
|
-
return (
|
|
334
|
-
<Box key={day.toISOString()} width={DAY_CELL_WIDTH}>
|
|
335
|
-
<Button
|
|
336
|
-
color={selected ? 'primary' : 'neutral'}
|
|
337
|
-
disabled={isDateDisabled(day, minDate, maxDate)}
|
|
338
|
-
interactionPolicy={interactionPolicy}
|
|
339
|
-
onPress={() => onSelect(day)}
|
|
340
|
-
size="s"
|
|
341
|
-
testID={testID ? `${testID}-day-${day.getDate()}` : undefined}
|
|
342
|
-
variant={selected ? 'solid' : 'ghost'}
|
|
343
|
-
>
|
|
344
|
-
{day.getDate()}
|
|
345
|
-
</Button>
|
|
346
|
-
</Box>
|
|
347
|
-
);
|
|
348
|
-
})}
|
|
349
|
-
</Stack>
|
|
350
|
-
);
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
/***
|
|
354
|
-
* Date input control with calendar selection and formatted display value.
|
|
355
|
-
*/
|
|
356
|
-
export const DatePicker = withZoraThemeScope(DatePickerInner);
|
|
1
|
+
export { DatePicker } from './DatePicker.web';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Popover } from '@ankhorage/surface';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
import { withZoraThemeScope } from '../../../../theme/withZoraThemeScope';
|
|
5
|
+
import type { DatePickerProps } from '../../../../types/date-picker';
|
|
6
|
+
import { Surface } from '../../../surface/public';
|
|
7
|
+
import { DatePickerContent } from '../../composition/DatePickerContent';
|
|
8
|
+
import { DatePickerField } from '../../composition/DatePickerField';
|
|
9
|
+
import { DatePickerTrigger } from '../../composition/DatePickerTrigger';
|
|
10
|
+
import { formatLocalDate } from '../../utils/localDate';
|
|
11
|
+
|
|
12
|
+
/*** Renders DatePicker with anchored web Popover presentation. */
|
|
13
|
+
export const DatePicker = withZoraThemeScope(DatePickerInner);
|
|
14
|
+
|
|
15
|
+
/*** Connects the shared DatePicker field and content to the web Popover host. */
|
|
16
|
+
function DatePickerInner({ themeId: _themeId, mode: _mode, ...props }: DatePickerProps) {
|
|
17
|
+
const [open, setOpen] = React.useState(false);
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<DatePickerField {...props}>
|
|
21
|
+
<Popover
|
|
22
|
+
anchor={({ toggle }) => <DatePickerTrigger {...props} onPress={toggle} />}
|
|
23
|
+
interactionPolicy={props.interactionPolicy}
|
|
24
|
+
onOpenChange={setOpen}
|
|
25
|
+
open={open}
|
|
26
|
+
placement="bottom-start"
|
|
27
|
+
testID={props.testID ? `${props.testID}-popover` : undefined}
|
|
28
|
+
>
|
|
29
|
+
<Surface variant="raised">
|
|
30
|
+
<DatePickerContent
|
|
31
|
+
description={props.description}
|
|
32
|
+
interactionPolicy={props.interactionPolicy}
|
|
33
|
+
label={props.label}
|
|
34
|
+
maxDate={props.maxDate}
|
|
35
|
+
minDate={props.minDate}
|
|
36
|
+
onDismiss={() => setOpen(false)}
|
|
37
|
+
onSelect={(date) => {
|
|
38
|
+
props.onValueChange?.(formatLocalDate(date));
|
|
39
|
+
setOpen(false);
|
|
40
|
+
}}
|
|
41
|
+
testID={props.testID}
|
|
42
|
+
value={props.value}
|
|
43
|
+
/>
|
|
44
|
+
</Surface>
|
|
45
|
+
</Popover>
|
|
46
|
+
</DatePickerField>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import type { DatePickerProps } from '../../../types/date-picker';
|
|
4
|
+
import { Button } from '../../button/public';
|
|
5
|
+
import { Box, Stack } from '../../layout/public';
|
|
6
|
+
import { Text } from '../../typography/public';
|
|
7
|
+
import { formatLocalDate, parseLocalDate } from '../utils/localDate';
|
|
8
|
+
|
|
9
|
+
const WEEKDAY_LABELS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] as const;
|
|
10
|
+
const DAY_CELL_WIDTH = 42;
|
|
11
|
+
|
|
12
|
+
/*** Renders the shared calendar content used by native BottomSheet and web Popover hosts. */
|
|
13
|
+
export function DatePickerContent({
|
|
14
|
+
description,
|
|
15
|
+
interactionPolicy,
|
|
16
|
+
label,
|
|
17
|
+
maxDate,
|
|
18
|
+
minDate,
|
|
19
|
+
onDismiss,
|
|
20
|
+
onSelect,
|
|
21
|
+
testID,
|
|
22
|
+
value,
|
|
23
|
+
}: DatePickerContentProps) {
|
|
24
|
+
const [displayMonth, setDisplayMonth] = React.useState(() => resolveInitialMonth(value, minDate));
|
|
25
|
+
const monthDays = React.useMemo(() => createMonthDays(displayMonth), [displayMonth]);
|
|
26
|
+
const resolvedMaxDate = React.useMemo(() => parseLocalDate(maxDate), [maxDate]);
|
|
27
|
+
const resolvedMinDate = React.useMemo(() => parseLocalDate(minDate), [minDate]);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<Stack gap="m" p="m" testID={testID ? `${testID}-content` : undefined}>
|
|
31
|
+
<PickerHeader description={description} title={label ?? 'Choose date'} />
|
|
32
|
+
<DatePickerMonthNavigation
|
|
33
|
+
displayMonth={displayMonth}
|
|
34
|
+
interactionPolicy={interactionPolicy}
|
|
35
|
+
maxDate={resolvedMaxDate}
|
|
36
|
+
minDate={resolvedMinDate}
|
|
37
|
+
onMonthChange={setDisplayMonth}
|
|
38
|
+
/>
|
|
39
|
+
<DatePickerWeekdays />
|
|
40
|
+
<DatePickerCalendar
|
|
41
|
+
interactionPolicy={interactionPolicy}
|
|
42
|
+
maxDate={resolvedMaxDate}
|
|
43
|
+
minDate={resolvedMinDate}
|
|
44
|
+
monthDays={monthDays}
|
|
45
|
+
onSelect={onSelect}
|
|
46
|
+
testID={testID}
|
|
47
|
+
value={value}
|
|
48
|
+
/>
|
|
49
|
+
<Button fullWidth interactionPolicy={interactionPolicy} onPress={onDismiss} variant="ghost">
|
|
50
|
+
Cancel
|
|
51
|
+
</Button>
|
|
52
|
+
</Stack>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface DatePickerContentProps extends Pick<
|
|
57
|
+
DatePickerProps,
|
|
58
|
+
'description' | 'interactionPolicy' | 'label' | 'maxDate' | 'minDate' | 'testID' | 'value'
|
|
59
|
+
> {
|
|
60
|
+
onDismiss: () => void;
|
|
61
|
+
onSelect: (value: Date) => void;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/*** Renders the shared title block used by picker overlays. */
|
|
65
|
+
function PickerHeader({
|
|
66
|
+
description,
|
|
67
|
+
title,
|
|
68
|
+
}: {
|
|
69
|
+
description: React.ReactNode | undefined;
|
|
70
|
+
title: React.ReactNode;
|
|
71
|
+
}) {
|
|
72
|
+
return (
|
|
73
|
+
<Stack gap="xxs">
|
|
74
|
+
<Text align="center" variant="label" weight="semiBold">
|
|
75
|
+
{title}
|
|
76
|
+
</Text>
|
|
77
|
+
{description ? (
|
|
78
|
+
<Text align="center" emphasis="muted" variant="bodySmall">
|
|
79
|
+
{description}
|
|
80
|
+
</Text>
|
|
81
|
+
) : null}
|
|
82
|
+
</Stack>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/*** Renders previous and next month controls for the calendar. */
|
|
87
|
+
function DatePickerMonthNavigation({
|
|
88
|
+
displayMonth,
|
|
89
|
+
interactionPolicy,
|
|
90
|
+
maxDate,
|
|
91
|
+
minDate,
|
|
92
|
+
onMonthChange,
|
|
93
|
+
}: {
|
|
94
|
+
displayMonth: Date;
|
|
95
|
+
interactionPolicy: DatePickerProps['interactionPolicy'];
|
|
96
|
+
maxDate: Date | undefined;
|
|
97
|
+
minDate: Date | undefined;
|
|
98
|
+
onMonthChange: (month: Date) => void;
|
|
99
|
+
}) {
|
|
100
|
+
const previousMonth = new Date(displayMonth.getFullYear(), displayMonth.getMonth() - 1, 1);
|
|
101
|
+
const nextMonth = new Date(displayMonth.getFullYear(), displayMonth.getMonth() + 1, 1);
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<Stack align="center" direction="row" justify="space-between">
|
|
105
|
+
<Button
|
|
106
|
+
disabled={!canNavigateToMonth(previousMonth, minDate, maxDate)}
|
|
107
|
+
interactionPolicy={interactionPolicy}
|
|
108
|
+
onPress={() => onMonthChange(previousMonth)}
|
|
109
|
+
size="s"
|
|
110
|
+
variant="ghost"
|
|
111
|
+
>
|
|
112
|
+
Previous
|
|
113
|
+
</Button>
|
|
114
|
+
<Text align="center" variant="label" weight="semiBold">
|
|
115
|
+
{formatMonthLabel(displayMonth)}
|
|
116
|
+
</Text>
|
|
117
|
+
<Button
|
|
118
|
+
disabled={!canNavigateToMonth(nextMonth, minDate, maxDate)}
|
|
119
|
+
interactionPolicy={interactionPolicy}
|
|
120
|
+
onPress={() => onMonthChange(nextMonth)}
|
|
121
|
+
size="s"
|
|
122
|
+
variant="ghost"
|
|
123
|
+
>
|
|
124
|
+
Next
|
|
125
|
+
</Button>
|
|
126
|
+
</Stack>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/*** Renders weekday headings for the calendar grid. */
|
|
131
|
+
function DatePickerWeekdays() {
|
|
132
|
+
return (
|
|
133
|
+
<Stack direction="row" justify="space-between">
|
|
134
|
+
{WEEKDAY_LABELS.map((weekday) => (
|
|
135
|
+
<Box key={weekday} width={DAY_CELL_WIDTH}>
|
|
136
|
+
<Text align="center" emphasis="muted" variant="caption" weight="semiBold">
|
|
137
|
+
{weekday}
|
|
138
|
+
</Text>
|
|
139
|
+
</Box>
|
|
140
|
+
))}
|
|
141
|
+
</Stack>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/*** Renders selectable day cells for the current calendar month. */
|
|
146
|
+
function DatePickerCalendar({
|
|
147
|
+
interactionPolicy,
|
|
148
|
+
maxDate,
|
|
149
|
+
minDate,
|
|
150
|
+
monthDays,
|
|
151
|
+
onSelect,
|
|
152
|
+
testID,
|
|
153
|
+
value,
|
|
154
|
+
}: {
|
|
155
|
+
interactionPolicy: DatePickerProps['interactionPolicy'];
|
|
156
|
+
maxDate: Date | undefined;
|
|
157
|
+
minDate: Date | undefined;
|
|
158
|
+
monthDays: readonly (Date | null)[];
|
|
159
|
+
onSelect: (value: Date) => void;
|
|
160
|
+
testID: string | undefined;
|
|
161
|
+
value: DatePickerProps['value'];
|
|
162
|
+
}) {
|
|
163
|
+
return (
|
|
164
|
+
<Stack direction="row" gap="xs" wrap="wrap">
|
|
165
|
+
{monthDays.map((day, index) => {
|
|
166
|
+
if (!day) return <Box key={`empty-${index}`} width={DAY_CELL_WIDTH} />;
|
|
167
|
+
const selected = isSameLocalDay(value, day);
|
|
168
|
+
return (
|
|
169
|
+
<Box key={day.toISOString()} width={DAY_CELL_WIDTH}>
|
|
170
|
+
<Button
|
|
171
|
+
color={selected ? 'primary' : 'neutral'}
|
|
172
|
+
disabled={isDateDisabled(day, minDate, maxDate)}
|
|
173
|
+
interactionPolicy={interactionPolicy}
|
|
174
|
+
onPress={() => onSelect(day)}
|
|
175
|
+
size="s"
|
|
176
|
+
testID={testID ? `${testID}-day-${day.getDate()}` : undefined}
|
|
177
|
+
variant={selected ? 'solid' : 'ghost'}
|
|
178
|
+
>
|
|
179
|
+
{day.getDate()}
|
|
180
|
+
</Button>
|
|
181
|
+
</Box>
|
|
182
|
+
);
|
|
183
|
+
})}
|
|
184
|
+
</Stack>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/*** Compares a serialized date to one local calendar day. */
|
|
189
|
+
function isSameLocalDay(left: string | null, right: Date): boolean {
|
|
190
|
+
return left === formatLocalDate(right);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/*** Normalizes a Date to the start of its local calendar day. */
|
|
194
|
+
function startOfLocalDay(value: Date): Date {
|
|
195
|
+
return new Date(value.getFullYear(), value.getMonth(), value.getDate());
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/*** Reports whether one local calendar day precedes another. */
|
|
199
|
+
function isBeforeLocalDay(left: Date, right: Date): boolean {
|
|
200
|
+
return startOfLocalDay(left).getTime() < startOfLocalDay(right).getTime();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/*** Reports whether one local calendar day follows another. */
|
|
204
|
+
function isAfterLocalDay(left: Date, right: Date): boolean {
|
|
205
|
+
return startOfLocalDay(left).getTime() > startOfLocalDay(right).getTime();
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/*** Reports whether a date falls outside the configured picker range. */
|
|
209
|
+
function isDateDisabled(
|
|
210
|
+
value: Date,
|
|
211
|
+
minDate: Date | undefined,
|
|
212
|
+
maxDate: Date | undefined,
|
|
213
|
+
): boolean {
|
|
214
|
+
if (minDate && isBeforeLocalDay(value, minDate)) return true;
|
|
215
|
+
if (maxDate && isAfterLocalDay(value, maxDate)) return true;
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/*** Formats the current calendar month for the picker heading. */
|
|
220
|
+
function formatMonthLabel(value: Date): string {
|
|
221
|
+
return value.toLocaleDateString(undefined, { month: 'long', year: 'numeric' });
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/*** Builds the padded calendar grid for one month. */
|
|
225
|
+
function createMonthDays(month: Date): (Date | null)[] {
|
|
226
|
+
const firstDay = new Date(month.getFullYear(), month.getMonth(), 1);
|
|
227
|
+
const dayCount = new Date(month.getFullYear(), month.getMonth() + 1, 0).getDate();
|
|
228
|
+
const populatedLength = firstDay.getDay() + dayCount;
|
|
229
|
+
const paddedLength = Math.ceil(populatedLength / 7) * 7;
|
|
230
|
+
|
|
231
|
+
return Array.from({ length: paddedLength }, (_, index) =>
|
|
232
|
+
index < firstDay.getDay()
|
|
233
|
+
? null
|
|
234
|
+
: new Date(month.getFullYear(), month.getMonth(), index - firstDay.getDay() + 1),
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/*** Resolves the month initially shown by the calendar. */
|
|
239
|
+
function resolveInitialMonth(value: string | null, minDate: string | undefined): Date {
|
|
240
|
+
const base = parseLocalDate(value) ?? parseLocalDate(minDate) ?? new Date();
|
|
241
|
+
return new Date(base.getFullYear(), base.getMonth(), 1);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/*** Reports whether the configured range intersects a candidate month. */
|
|
245
|
+
function canNavigateToMonth(
|
|
246
|
+
month: Date,
|
|
247
|
+
minDate: Date | undefined,
|
|
248
|
+
maxDate: Date | undefined,
|
|
249
|
+
): boolean {
|
|
250
|
+
const firstDay = new Date(month.getFullYear(), month.getMonth(), 1);
|
|
251
|
+
const lastDay = new Date(month.getFullYear(), month.getMonth() + 1, 0);
|
|
252
|
+
|
|
253
|
+
if (maxDate && isAfterLocalDay(firstDay, maxDate)) return false;
|
|
254
|
+
if (minDate && isBeforeLocalDay(lastDay, minDate)) return false;
|
|
255
|
+
return true;
|
|
256
|
+
}
|