@yamatozhen/design_system 1.0.0 → 1.1.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/LICENSE +201 -201
- package/README.md +101 -101
- package/package.json +50 -49
- package/scripts/postinstall.js +91 -105
- package/template/app/ClientNav.tsx +258 -310
- package/template/app/globals.css +2 -167
- package/template/app/layout.tsx +94 -128
- package/template/app/themes/dark-mc 2.css +51 -0
- package/template/app/themes/dark-mc.css +51 -51
- package/template/app/themes/dark.css +51 -51
- package/template/app/themes/light 2.css +51 -0
- package/template/app/themes/light-mc 2.css +51 -0
- package/template/app/themes/light-mc.css +51 -51
- package/template/app/themes/light.css +51 -51
- package/template/app/themes/theme 2.css +272 -0
- package/template/app/themes/theme.css +272 -82
- package/template/components/{layout/button → (buttons)}/Button.module.css +351 -305
- package/template/components/{layout/button → (buttons)}/ButtonGroup.tsx +414 -503
- package/template/components/{layout/button → (buttons)}/FAB.tsx +119 -118
- package/template/components/(buttons)/button.tsx +164 -0
- package/template/components/(controls)/slider/Slider.module.css +250 -0
- package/template/components/(controls)/slider/Slider.tsx +386 -0
- package/template/components/(controls)/switch/Switch.module.css +108 -0
- package/template/components/(controls)/switch/Switch.tsx +69 -0
- package/template/components/(date & time)/calendar/Calendar.module.css +125 -0
- package/template/components/(date & time)/calendar/Calendar.tsx +206 -0
- package/template/components/(date & time)/dateField/DateField.module.css +25 -0
- package/template/components/(date & time)/dateField/DateField.tsx +193 -0
- package/template/components/(date & time)/datePicker/DatePicker.tsx +118 -0
- package/template/components/(date & time)/dateRangePicker/DateRangePicker.tsx +144 -0
- package/template/components/(date & time)/rangeCalendar/RangeCalendar.module.css +203 -0
- package/template/components/(date & time)/rangeCalendar/RangeCalendar.tsx +263 -0
- package/template/components/(date & time)/shared/dateUtils.ts +107 -0
- package/template/components/(date & time)/timeField/TimeField.module.css +39 -0
- package/template/components/(date & time)/timeField/TimeField.tsx +158 -0
- package/template/components/(feedback)/circularProgress/CircularProgress.tsx +646 -0
- package/template/components/(feedback)/linearProgress/LinearProgress.tsx +337 -0
- package/template/components/(feedback)/meter/Meter.tsx +111 -0
- package/template/components/(feedback)/skeleton/Skeleton.module.css +49 -0
- package/template/components/(feedback)/skeleton/Skeleton.tsx +32 -0
- package/template/components/(feedback)/spinner/Spinner.module.css +27 -0
- package/template/components/(feedback)/spinner/Spinner.tsx +60 -0
- package/template/components/(forms)/checkbox/Checkbox.tsx +121 -0
- package/template/components/(forms)/checkboxGroup/CheckboxGroup.tsx +83 -0
- package/template/components/(forms)/description/Description.tsx +34 -0
- package/template/components/(forms)/errorMessage/ErrorMessage.tsx +31 -0
- package/template/components/(forms)/fieldError/FieldError.tsx +39 -0
- package/template/components/(forms)/fieldset/Fieldset.tsx +51 -0
- package/template/components/(forms)/form/Form.tsx +54 -0
- package/template/components/(forms)/input/Input.tsx +50 -0
- package/template/components/(forms)/inputGroup/InputGroup.tsx +65 -0
- package/template/components/(forms)/inputOtp/InputOtp.tsx +139 -0
- package/template/components/(forms)/label/Label.tsx +46 -0
- package/template/components/(forms)/numberField/NumberField.tsx +292 -0
- package/template/components/(forms)/radioGroup/RadioGroup.tsx +175 -0
- package/template/components/(forms)/searchField/SearchField.tsx +139 -0
- package/template/components/(forms)/shared/field.module.css +75 -0
- package/template/components/(forms)/shared/fieldContext.ts +28 -0
- package/template/components/(forms)/textArea/TextArea.tsx +55 -0
- package/template/components/(forms)/textField/TextField.tsx +91 -0
- package/template/components/{layout → (layout)}/Lightbox/LightboxCard.tsx +100 -100
- package/template/components/{layout → (layout)}/Lightbox/LightboxGallery.module.css +249 -249
- package/template/components/{layout → (layout)}/Lightbox/LightboxGallery.tsx +72 -72
- package/template/components/{layout → (layout)}/Lightbox/LightboxGrid.tsx +185 -186
- package/template/components/{layout → (layout)}/Lightbox/LightboxModal.module.css +395 -395
- package/template/components/{layout → (layout)}/Lightbox/LightboxModal.tsx +498 -500
- package/template/components/{layout → (layout)}/Lightbox/demo.tsx +396 -412
- package/template/components/{layout → (layout)}/Lightbox/index.ts +30 -30
- package/template/components/{layout → (layout)}/Lightbox/types.ts +101 -113
- package/template/components/{layout → (layout)}/Lightbox/useLightboxFilters.ts +140 -140
- package/template/components/(layout)/accordion/Accordion.module.css +108 -0
- package/template/components/(layout)/accordion/Accordion.tsx +251 -0
- package/template/components/(layout)/card/Card.module.css +136 -0
- package/template/components/(layout)/card/Card.tsx +371 -0
- package/template/components/(layout)/list/List.module.css +83 -0
- package/template/components/(layout)/list/List.tsx +332 -0
- package/template/components/{layout → (layout)}/navigation/Wrap.tsx +41 -41
- package/template/components/(layout)/navigation/breadcrumbs/Breadcrumbs.tsx +145 -0
- package/template/components/{layout/navigation/nav/Nav.module.css → (layout)/navigation/nav/Nav.module.css.old} +474 -508
- package/template/components/{layout → (layout)}/navigation/nav/Nav.tsx +186 -167
- package/template/components/{layout → (layout)}/navigation/nav/NavBar.tsx +396 -419
- package/template/components/{layout → (layout)}/navigation/nav/NavContext.tsx +259 -259
- package/template/components/{layout → (layout)}/navigation/nav/NavItem.tsx +195 -173
- package/template/components/{layout → (layout)}/navigation/nav/NavNew.module.css +406 -373
- package/template/components/{layout → (layout)}/navigation/nav/NavRail.tsx +317 -315
- package/template/components/{layout → (layout)}/navigation/nav/NavSection.tsx +101 -102
- package/template/components/{layout → (layout)}/navigation/nav/NavTab.tsx +25 -25
- package/template/components/{layout → (layout)}/navigation/nav/navftb/NavFTB.module.css +253 -252
- package/template/components/{layout → (layout)}/navigation/nav/navftb/NavFTB.tsx +448 -399
- package/template/components/{layout → (layout)}/navigation/nav/navftb/useTabIndicator.ts +498 -484
- package/template/components/{layout → (layout)}/navigation/nav/navheader/NavHeader.module.css +59 -59
- package/template/components/{layout → (layout)}/navigation/nav/navheader/NavHeader.tsx +465 -478
- package/template/components/(layout)/navigation/pagination/Pagination.tsx +261 -0
- package/template/components/{layout → (layout)}/pages/loadingScreen.tsx +117 -102
- package/template/components/{layout → (layout)}/pages/maintenance/Maintenance.tsx +52 -52
- package/template/components/{layout → (layout)}/pages/maintenance/maintenance.module.css +162 -162
- package/template/components/(layout)/scrollShadow/ScrollShadow.module.css +81 -0
- package/template/components/(layout)/scrollShadow/ScrollShadow.tsx +161 -0
- package/template/components/(layout)/scrollShadow/useScrollShadow.ts +130 -0
- package/template/components/(layout)/separator/Separator.tsx +112 -0
- package/template/components/(overlays)/accessibilityModal/AccessibilityModal.tsx +307 -0
- package/template/components/(overlays)/drawer/Drawer.tsx +953 -0
- package/template/components/(overlays)/modal/Modal.tsx +654 -0
- package/template/components/(overlays)/popover/Popover.tsx +420 -0
- package/template/components/(overlays)/toast/Toast.tsx +692 -0
- package/template/components/(pickers)/autocomplete/Autocomplete.tsx +24 -0
- package/template/components/(pickers)/comboBox/ComboBox.tsx +21 -0
- package/template/components/(pickers)/select/Select.tsx +188 -0
- package/template/components/(pickers)/shared/FilterableField.tsx +223 -0
- package/template/components/(pickers)/shared/PickerItem.ts +13 -0
- package/template/components/tools/CustomScrollbar 2.tsx +107 -0
- package/template/components/tools/CustomScrollbar.tsx +107 -0
- package/template/components/tools/Divider 2.tsx +11 -0
- package/template/components/tools/Divider.tsx +11 -11
- package/template/components/tools/ReduceMotionContext 2.tsx +5 -0
- package/template/components/tools/ReduceMotionContext.tsx +5 -5
- package/template/components/tools/Sinewave 2.tsx +206 -0
- package/template/components/tools/Sinewave.tsx +396 -199
- package/template/components/tools/SinewaveProgress 2.tsx +140 -0
- package/template/components/tools/SinewaveProgress.tsx +140 -135
- package/template/components/tools/badge/Badge 2.tsx +28 -0
- package/template/components/tools/badge/Badge.tsx +28 -28
- package/template/components/tools/dropdown/drop.module.css +196 -0
- package/template/components/tools/dropdown/drop.tsx +568 -0
- package/template/components/tools/easing.ts +118 -0
- package/template/components/tools/flubber.d 2.ts +7 -0
- package/template/components/tools/flubber.d.ts +6 -6
- package/template/components/tools/footer/Footer.tsx +20 -0
- package/template/components/tools/input/Input 2.tsx +99 -0
- package/template/components/tools/input/Input.module 2.css +45 -0
- package/template/components/tools/input/Input.module.css +45 -0
- package/template/components/tools/input/Input.tsx +99 -0
- package/template/components/tools/label/Icon 2.tsx +39 -0
- package/template/components/tools/label/Icon.tsx +39 -0
- package/template/components/tools/label/Label 2.tsx +150 -0
- package/template/components/tools/label/Label.tsx +156 -0
- package/template/components/tools/mobileViewProvider 2.tsx +53 -0
- package/template/components/tools/mobileViewProvider.tsx +53 -58
- package/template/components/tools/ripple/ripple 2.css +38 -0
- package/template/components/tools/ripple/ripple 2.tsx +78 -0
- package/template/components/tools/ripple/ripple.css +38 -41
- package/template/components/tools/ripple/ripple.tsx +78 -53
- package/template/components/tools/shape/{ShapeMorph.tsx → Shape 2.tsx } +313 -190
- package/template/components/tools/shape/Shape.module 2.css +21 -0
- package/template/components/tools/shape/Shape.module.css +25 -0
- package/template/components/tools/shape/Shape.tsx +316 -0
- package/template/components/tools/shape/ShapeLoader 2.tsx +104 -0
- package/template/components/tools/shape/ShapeLoader.tsx +104 -101
- package/template/components/tools/shape/ShapePaths 2.ts +116 -0
- package/template/components/tools/shape/ShapePaths.ts +116 -116
- package/template/components/{layout/switch/Switch.tsx → tools/switch/Switch 2.tsx } +48 -48
- package/template/components/{layout/switch/Switch.module.css → tools/switch/Switch.module 2.css } +102 -102
- package/template/components/tools/switch/Switch.module.css +102 -102
- package/template/components/tools/switch/Switch.tsx +48 -48
- package/template/components/tools/useBodyScrollLock 2.tsx +27 -0
- package/template/components/tools/useBodyScrollLock.tsx +27 -27
- package/template/components/tools/useImageColor 2.ts +47 -0
- package/template/components/tools/useImageColor.ts +47 -47
- package/template/components/tools/useNavSheetDrag 2.tsx +196 -0
- package/template/components/tools/useNavSheetDrag.tsx +196 -196
- package/template/public/fonts/material-symbols/MaterialSymbolsRounded-VariableFont_FILL,GRAD,opsz,wght 2.woff2 +0 -0
- package/template/components/layout/accordion/Accordion.module.css +0 -149
- package/template/components/layout/accordion/Accordion.tsx +0 -114
- package/template/components/layout/button/button.tsx +0 -128
- package/template/components/layout/button/drop.module.css +0 -229
- package/template/components/layout/button/drop.tsx +0 -516
- package/template/components/layout/hero/v1/heroSlideshow.module.css +0 -107
- package/template/components/layout/hero/v1/heroSlideshow.tsx +0 -233
- package/template/components/layout/modals/accessibilityModal/AccessibilityModal.module.css +0 -126
- package/template/components/layout/modals/accessibilityModal/AccessibilityModal.tsx +0 -290
- package/template/components/layout/modals/alert/Alert.tsx +0 -188
- package/template/components/layout/navigation/MioCard.module.css +0 -88
- package/template/components/layout/navigation/MioCard.tsx +0 -266
- package/template/components/tools/ProgressiveBlur.tsx +0 -73
- package/template/components/tools/icon/SocialIcons.tsx +0 -88
- package/template/components/tools/icon/icon.module.css +0 -0
- package/template/components/tools/icon/icon.tsx +0 -125
- package/template/components/tools/react-bits/ClickSpark.tsx +0 -177
- package/template/components/tools/react-bits/FadeContent.tsx +0 -90
- package/template/components/tools/react-bits/GlareHover.tsx +0 -73
- package/template/components/tools/react-bits/GradientText/GradientText.css +0 -70
- package/template/components/tools/react-bits/GradientText/GradientText.tsx +0 -44
- package/template/components/tools/react-bits/Magnet.tsx +0 -118
- package/template/components/tools/react-bits/Stepper/Stepper.css +0 -134
- package/template/components/tools/react-bits/Stepper/Stepper.tsx +0 -412
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import React, { useMemo, useRef, useState } from "react";
|
|
3
|
+
import Icon from "@/components/tools/label/Icon";
|
|
4
|
+
import {
|
|
5
|
+
addDays,
|
|
6
|
+
addMonths,
|
|
7
|
+
getMonthGrid,
|
|
8
|
+
getWeekdayLabels,
|
|
9
|
+
formatMonthYear,
|
|
10
|
+
isSameDay,
|
|
11
|
+
isSameMonth,
|
|
12
|
+
isWithinRange,
|
|
13
|
+
stripTime,
|
|
14
|
+
type WeekDay,
|
|
15
|
+
} from "@/components/(date & time)/shared/dateUtils";
|
|
16
|
+
import styles from "./Calendar.module.css";
|
|
17
|
+
|
|
18
|
+
export type CalendarSelectionMode = "single" | "multiple";
|
|
19
|
+
|
|
20
|
+
export interface CalendarProps {
|
|
21
|
+
selectionMode?: CalendarSelectionMode;
|
|
22
|
+
value?: Date | Date[] | null;
|
|
23
|
+
defaultValue?: Date | Date[] | null;
|
|
24
|
+
onChange?: (value: Date | Date[] | null) => void;
|
|
25
|
+
minValue?: Date;
|
|
26
|
+
maxValue?: Date;
|
|
27
|
+
isDateUnavailable?: (date: Date) => boolean;
|
|
28
|
+
firstDayOfWeek?: WeekDay;
|
|
29
|
+
isDisabled?: boolean;
|
|
30
|
+
isReadOnly?: boolean;
|
|
31
|
+
"aria-label"?: string;
|
|
32
|
+
className?: string;
|
|
33
|
+
style?: React.CSSProperties;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function toArray(value: Date | Date[] | null | undefined): Date[] {
|
|
37
|
+
if (!value) return [];
|
|
38
|
+
return Array.isArray(value) ? value : [value];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default function Calendar({
|
|
42
|
+
selectionMode = "single",
|
|
43
|
+
value: controlledValue,
|
|
44
|
+
defaultValue = null,
|
|
45
|
+
onChange,
|
|
46
|
+
minValue,
|
|
47
|
+
maxValue,
|
|
48
|
+
isDateUnavailable,
|
|
49
|
+
firstDayOfWeek = "sun",
|
|
50
|
+
isDisabled = false,
|
|
51
|
+
isReadOnly = false,
|
|
52
|
+
"aria-label": ariaLabel = "Calendar",
|
|
53
|
+
className,
|
|
54
|
+
style,
|
|
55
|
+
}: CalendarProps) {
|
|
56
|
+
const isControlled = controlledValue !== undefined;
|
|
57
|
+
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
58
|
+
const value = isControlled ? controlledValue : internalValue;
|
|
59
|
+
const selectedDates = toArray(value);
|
|
60
|
+
|
|
61
|
+
const today = useMemo(() => stripTime(new Date()), []);
|
|
62
|
+
const [visibleMonth, setVisibleMonth] = useState(
|
|
63
|
+
() => selectedDates[0] ?? today,
|
|
64
|
+
);
|
|
65
|
+
const [focusedDate, setFocusedDate] = useState(
|
|
66
|
+
() => selectedDates[0] ?? today,
|
|
67
|
+
);
|
|
68
|
+
const gridRef = useRef<HTMLDivElement>(null);
|
|
69
|
+
|
|
70
|
+
const cells = useMemo(
|
|
71
|
+
() => getMonthGrid(visibleMonth, firstDayOfWeek),
|
|
72
|
+
[visibleMonth, firstDayOfWeek],
|
|
73
|
+
);
|
|
74
|
+
const weekdayLabels = useMemo(
|
|
75
|
+
() => getWeekdayLabels(firstDayOfWeek, "short"),
|
|
76
|
+
[firstDayOfWeek],
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const isUnavailable = (date: Date) =>
|
|
80
|
+
!isWithinRange(date, minValue, maxValue) ||
|
|
81
|
+
(isDateUnavailable?.(date) ?? false);
|
|
82
|
+
|
|
83
|
+
const commit = (next: Date | Date[] | null) => {
|
|
84
|
+
if (!isControlled) setInternalValue(next);
|
|
85
|
+
onChange?.(next);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const selectDate = (date: Date) => {
|
|
89
|
+
if (isDisabled || isReadOnly || isUnavailable(date)) return;
|
|
90
|
+
if (selectionMode === "single") {
|
|
91
|
+
commit(date);
|
|
92
|
+
} else {
|
|
93
|
+
const exists = selectedDates.some((d) => isSameDay(d, date));
|
|
94
|
+
commit(
|
|
95
|
+
exists
|
|
96
|
+
? selectedDates.filter((d) => !isSameDay(d, date))
|
|
97
|
+
: [...selectedDates, date],
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const moveFocus = (next: Date) => {
|
|
103
|
+
setFocusedDate(next);
|
|
104
|
+
if (!isSameMonth(next, visibleMonth)) setVisibleMonth(next);
|
|
105
|
+
requestAnimationFrame(() => {
|
|
106
|
+
gridRef.current
|
|
107
|
+
?.querySelector<HTMLButtonElement>('[tabindex="0"]')
|
|
108
|
+
?.focus();
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const handleKeyDown = (e: React.KeyboardEvent, date: Date) => {
|
|
113
|
+
const keyMoves: Record<string, number> = {
|
|
114
|
+
ArrowLeft: -1,
|
|
115
|
+
ArrowRight: 1,
|
|
116
|
+
ArrowUp: -7,
|
|
117
|
+
ArrowDown: 7,
|
|
118
|
+
};
|
|
119
|
+
if (e.key in keyMoves) {
|
|
120
|
+
e.preventDefault();
|
|
121
|
+
moveFocus(addDays(date, keyMoves[e.key]));
|
|
122
|
+
} else if (e.key === "Enter" || e.key === " ") {
|
|
123
|
+
e.preventDefault();
|
|
124
|
+
selectDate(date);
|
|
125
|
+
} else if (e.key === "PageUp") {
|
|
126
|
+
e.preventDefault();
|
|
127
|
+
moveFocus(addMonths(date, e.shiftKey ? -12 : -1));
|
|
128
|
+
} else if (e.key === "PageDown") {
|
|
129
|
+
e.preventDefault();
|
|
130
|
+
moveFocus(addMonths(date, e.shiftKey ? 12 : 1));
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
return (
|
|
135
|
+
<div
|
|
136
|
+
role="application"
|
|
137
|
+
aria-label={ariaLabel}
|
|
138
|
+
className={[styles.calendar, className].filter(Boolean).join(" ")}
|
|
139
|
+
style={style}
|
|
140
|
+
>
|
|
141
|
+
<div className={styles.header}>
|
|
142
|
+
<button
|
|
143
|
+
type="button"
|
|
144
|
+
aria-label="Previous month"
|
|
145
|
+
disabled={isDisabled}
|
|
146
|
+
onClick={() => setVisibleMonth((m) => addMonths(m, -1))}
|
|
147
|
+
className={styles.navButton}
|
|
148
|
+
>
|
|
149
|
+
<Icon systemName="chevron_left" />
|
|
150
|
+
</button>
|
|
151
|
+
<span className={styles.heading}>{formatMonthYear(visibleMonth)}</span>
|
|
152
|
+
<button
|
|
153
|
+
type="button"
|
|
154
|
+
aria-label="Next month"
|
|
155
|
+
disabled={isDisabled}
|
|
156
|
+
onClick={() => setVisibleMonth((m) => addMonths(m, 1))}
|
|
157
|
+
className={styles.navButton}
|
|
158
|
+
>
|
|
159
|
+
<Icon systemName="chevron_right" />
|
|
160
|
+
</button>
|
|
161
|
+
</div>
|
|
162
|
+
|
|
163
|
+
<div ref={gridRef} role="grid" className={styles.grid}>
|
|
164
|
+
<div role="row" className={styles.gridHeaderRow}>
|
|
165
|
+
{weekdayLabels.map((label, i) => (
|
|
166
|
+
<span key={i} role="columnheader" className={styles.headerCell}>
|
|
167
|
+
{label}
|
|
168
|
+
</span>
|
|
169
|
+
))}
|
|
170
|
+
</div>
|
|
171
|
+
<div className={styles.gridBody}>
|
|
172
|
+
{cells.map((date) => {
|
|
173
|
+
const selected = selectedDates.some((d) => isSameDay(d, date));
|
|
174
|
+
const outsideMonth = !isSameMonth(date, visibleMonth);
|
|
175
|
+
const unavailable = isUnavailable(date);
|
|
176
|
+
const isTodayCell = isSameDay(date, today);
|
|
177
|
+
const isFocusTarget = isSameDay(date, focusedDate);
|
|
178
|
+
return (
|
|
179
|
+
<button
|
|
180
|
+
key={date.toISOString()}
|
|
181
|
+
type="button"
|
|
182
|
+
role="gridcell"
|
|
183
|
+
tabIndex={isFocusTarget ? 0 : -1}
|
|
184
|
+
aria-selected={selected}
|
|
185
|
+
aria-disabled={unavailable || undefined}
|
|
186
|
+
data-selected={selected || undefined}
|
|
187
|
+
data-today={isTodayCell || undefined}
|
|
188
|
+
data-outside-month={outsideMonth || undefined}
|
|
189
|
+
data-unavailable={unavailable || undefined}
|
|
190
|
+
disabled={isDisabled || unavailable}
|
|
191
|
+
onClick={() => {
|
|
192
|
+
setFocusedDate(date);
|
|
193
|
+
selectDate(date);
|
|
194
|
+
}}
|
|
195
|
+
onKeyDown={(e) => handleKeyDown(e, date)}
|
|
196
|
+
className={styles.cell}
|
|
197
|
+
>
|
|
198
|
+
{date.getDate()}
|
|
199
|
+
</button>
|
|
200
|
+
);
|
|
201
|
+
})}
|
|
202
|
+
</div>
|
|
203
|
+
</div>
|
|
204
|
+
</div>
|
|
205
|
+
);
|
|
206
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
.field {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
gap: 2px;
|
|
5
|
+
width: auto;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.segment {
|
|
9
|
+
width: 2.2ch;
|
|
10
|
+
border: none;
|
|
11
|
+
background: transparent;
|
|
12
|
+
color: inherit;
|
|
13
|
+
font-size: 14px;
|
|
14
|
+
font-variant-numeric: tabular-nums;
|
|
15
|
+
text-align: center;
|
|
16
|
+
outline: none;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.segment[aria-label="year"] {
|
|
20
|
+
width: 4ch;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.literal {
|
|
24
|
+
color: var(--md-sys-color-on-surface-variant);
|
|
25
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import React, { useId, useMemo, useRef, useState } from "react";
|
|
3
|
+
import {
|
|
4
|
+
clampToRange,
|
|
5
|
+
isWithinRange,
|
|
6
|
+
} from "@/components/(date & time)/shared/dateUtils";
|
|
7
|
+
import fieldStyles from "@/components/(forms)/shared/field.module.css";
|
|
8
|
+
import styles from "./DateField.module.css";
|
|
9
|
+
|
|
10
|
+
type SegmentType = "month" | "day" | "year";
|
|
11
|
+
type Segment = { type: SegmentType; literal?: string };
|
|
12
|
+
|
|
13
|
+
// Locale-aware segment order + literal separators (the "/" or "." between
|
|
14
|
+
// numbers), read from Intl itself rather than hardcoding MM/DD/YYYY —
|
|
15
|
+
// this is the one piece of real i18n this port's date components get for
|
|
16
|
+
// free without a date library.
|
|
17
|
+
function getSegmentOrder(locale: string): Segment[] {
|
|
18
|
+
const parts = new Intl.DateTimeFormat(locale, {
|
|
19
|
+
year: "numeric",
|
|
20
|
+
month: "2-digit",
|
|
21
|
+
day: "2-digit",
|
|
22
|
+
}).formatToParts(new Date(2000, 0, 1));
|
|
23
|
+
return parts
|
|
24
|
+
.filter(
|
|
25
|
+
(p) =>
|
|
26
|
+
p.type === "month" ||
|
|
27
|
+
p.type === "day" ||
|
|
28
|
+
p.type === "year" ||
|
|
29
|
+
p.type === "literal",
|
|
30
|
+
)
|
|
31
|
+
.map((p) =>
|
|
32
|
+
p.type === "literal"
|
|
33
|
+
? { type: "month" as SegmentType, literal: p.value }
|
|
34
|
+
: { type: p.type as SegmentType },
|
|
35
|
+
)
|
|
36
|
+
.filter((s, i, arr) => !(s.literal !== undefined && i === arr.length - 1));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface DateFieldProps {
|
|
40
|
+
value?: Date | null;
|
|
41
|
+
defaultValue?: Date | null;
|
|
42
|
+
onChange?: (value: Date | null) => void;
|
|
43
|
+
minValue?: Date;
|
|
44
|
+
maxValue?: Date;
|
|
45
|
+
locale?: string;
|
|
46
|
+
isDisabled?: boolean;
|
|
47
|
+
isReadOnly?: boolean;
|
|
48
|
+
isRequired?: boolean;
|
|
49
|
+
isInvalid?: boolean;
|
|
50
|
+
"aria-label"?: string;
|
|
51
|
+
id?: string;
|
|
52
|
+
className?: string;
|
|
53
|
+
style?: React.CSSProperties;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const SEGMENT_BOUNDS: Record<SegmentType, [number, number]> = {
|
|
57
|
+
month: [1, 12],
|
|
58
|
+
day: [1, 31],
|
|
59
|
+
year: [1, 9999],
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default function DateField({
|
|
63
|
+
value: controlledValue,
|
|
64
|
+
defaultValue = null,
|
|
65
|
+
onChange,
|
|
66
|
+
minValue,
|
|
67
|
+
maxValue,
|
|
68
|
+
locale = "en-US",
|
|
69
|
+
isDisabled = false,
|
|
70
|
+
isReadOnly = false,
|
|
71
|
+
isRequired = false,
|
|
72
|
+
isInvalid = false,
|
|
73
|
+
"aria-label": ariaLabel = "Date",
|
|
74
|
+
id,
|
|
75
|
+
className,
|
|
76
|
+
style,
|
|
77
|
+
}: DateFieldProps) {
|
|
78
|
+
const generatedId = useId();
|
|
79
|
+
const fieldId = id ?? generatedId;
|
|
80
|
+
const isControlled = controlledValue !== undefined;
|
|
81
|
+
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
82
|
+
const value = isControlled ? controlledValue : internalValue;
|
|
83
|
+
|
|
84
|
+
const [parts, setParts] = useState<Record<SegmentType, string>>({
|
|
85
|
+
month: value ? String(value.getMonth() + 1).padStart(2, "0") : "",
|
|
86
|
+
day: value ? String(value.getDate()).padStart(2, "0") : "",
|
|
87
|
+
year: value ? String(value.getFullYear()) : "",
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const segments = useMemo(() => getSegmentOrder(locale), [locale]);
|
|
91
|
+
const refs = useRef<Record<SegmentType, HTMLInputElement | null>>({
|
|
92
|
+
month: null,
|
|
93
|
+
day: null,
|
|
94
|
+
year: null,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const commitIfComplete = (next: Record<SegmentType, string>) => {
|
|
98
|
+
if (next.month && next.day && next.year && next.year.length === 4) {
|
|
99
|
+
const candidate = new Date(
|
|
100
|
+
Number(next.year),
|
|
101
|
+
Number(next.month) - 1,
|
|
102
|
+
Number(next.day),
|
|
103
|
+
);
|
|
104
|
+
if (!Number.isNaN(candidate.getTime())) {
|
|
105
|
+
const clamped = clampToRange(candidate, minValue, maxValue);
|
|
106
|
+
if (!isControlled) setInternalValue(clamped);
|
|
107
|
+
onChange?.(clamped);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (!isControlled) setInternalValue(null);
|
|
112
|
+
onChange?.(null);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const setSegment = (type: SegmentType, raw: string) => {
|
|
116
|
+
const maxLen = type === "year" ? 4 : 2;
|
|
117
|
+
const digits = raw.replace(/\D/g, "").slice(-maxLen);
|
|
118
|
+
const next = { ...parts, [type]: digits };
|
|
119
|
+
setParts(next);
|
|
120
|
+
commitIfComplete(next);
|
|
121
|
+
if (digits.length >= maxLen) {
|
|
122
|
+
const order: SegmentType[] = segments
|
|
123
|
+
.filter((s) => !s.literal)
|
|
124
|
+
.map((s) => s.type);
|
|
125
|
+
const currentIndex = order.indexOf(type);
|
|
126
|
+
const nextType = order[currentIndex + 1];
|
|
127
|
+
if (nextType) refs.current[nextType]?.focus();
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const step = (type: SegmentType, delta: number) => {
|
|
132
|
+
const [min, max] = SEGMENT_BOUNDS[type];
|
|
133
|
+
const current = Number(parts[type]) || min - delta;
|
|
134
|
+
const next = Math.min(max, Math.max(min, current + delta));
|
|
135
|
+
const padded =
|
|
136
|
+
type === "year" ? String(next) : String(next).padStart(2, "0");
|
|
137
|
+
const nextParts = { ...parts, [type]: padded };
|
|
138
|
+
setParts(nextParts);
|
|
139
|
+
commitIfComplete(nextParts);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const isUnavailable = value
|
|
143
|
+
? !isWithinRange(value, minValue, maxValue)
|
|
144
|
+
: false;
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<div
|
|
148
|
+
role="group"
|
|
149
|
+
aria-label={ariaLabel}
|
|
150
|
+
id={fieldId}
|
|
151
|
+
data-invalid={isInvalid || isUnavailable || undefined}
|
|
152
|
+
className={[fieldStyles.field, styles.field, className]
|
|
153
|
+
.filter(Boolean)
|
|
154
|
+
.join(" ")}
|
|
155
|
+
style={style}
|
|
156
|
+
>
|
|
157
|
+
{segments.map((seg, i) =>
|
|
158
|
+
seg.literal ? (
|
|
159
|
+
<span key={i} className={styles.literal}>
|
|
160
|
+
{seg.literal}
|
|
161
|
+
</span>
|
|
162
|
+
) : (
|
|
163
|
+
<input
|
|
164
|
+
key={seg.type}
|
|
165
|
+
ref={(el) => {
|
|
166
|
+
refs.current[seg.type] = el;
|
|
167
|
+
}}
|
|
168
|
+
type="text"
|
|
169
|
+
inputMode="numeric"
|
|
170
|
+
aria-label={seg.type}
|
|
171
|
+
disabled={isDisabled}
|
|
172
|
+
readOnly={isReadOnly}
|
|
173
|
+
required={isRequired}
|
|
174
|
+
placeholder={seg.type[0].toUpperCase()}
|
|
175
|
+
value={parts[seg.type]}
|
|
176
|
+
maxLength={seg.type === "year" ? 4 : 2}
|
|
177
|
+
onChange={(e) => setSegment(seg.type, e.target.value)}
|
|
178
|
+
onKeyDown={(e) => {
|
|
179
|
+
if (e.key === "ArrowUp") {
|
|
180
|
+
e.preventDefault();
|
|
181
|
+
step(seg.type, 1);
|
|
182
|
+
} else if (e.key === "ArrowDown") {
|
|
183
|
+
e.preventDefault();
|
|
184
|
+
step(seg.type, -1);
|
|
185
|
+
}
|
|
186
|
+
}}
|
|
187
|
+
className={styles.segment}
|
|
188
|
+
/>
|
|
189
|
+
),
|
|
190
|
+
)}
|
|
191
|
+
</div>
|
|
192
|
+
);
|
|
193
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import React, { useState } from "react";
|
|
3
|
+
import Icon from "@/components/tools/label/Icon";
|
|
4
|
+
import Popover from "@/components/(overlays)/popover/Popover";
|
|
5
|
+
import DateField from "@/components/(date & time)/dateField/DateField";
|
|
6
|
+
import Calendar from "@/components/(date & time)/calendar/Calendar";
|
|
7
|
+
import { isSameDay } from "@/components/(date & time)/shared/dateUtils";
|
|
8
|
+
import fieldStyles from "@/components/(forms)/shared/field.module.css";
|
|
9
|
+
import Button from "@/components/(buttons)/button";
|
|
10
|
+
import InputGroup from "@/components/(forms)/inputGroup/InputGroup";
|
|
11
|
+
|
|
12
|
+
export interface DatePickerProps {
|
|
13
|
+
value?: Date | null;
|
|
14
|
+
defaultValue?: Date | null;
|
|
15
|
+
onChange?: (value: Date | null) => void;
|
|
16
|
+
minValue?: Date;
|
|
17
|
+
maxValue?: Date;
|
|
18
|
+
isDateUnavailable?: (date: Date) => boolean;
|
|
19
|
+
isDisabled?: boolean;
|
|
20
|
+
isReadOnly?: boolean;
|
|
21
|
+
isRequired?: boolean;
|
|
22
|
+
isInvalid?: boolean;
|
|
23
|
+
"aria-label"?: string;
|
|
24
|
+
className?: string;
|
|
25
|
+
style?: React.CSSProperties;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// DateField for typed entry + a Calendar in a Popover for picking — the
|
|
29
|
+
// two stay in sync either direction, same as HeroUI's own composition.
|
|
30
|
+
export default function DatePicker({
|
|
31
|
+
value: controlledValue,
|
|
32
|
+
defaultValue = null,
|
|
33
|
+
onChange,
|
|
34
|
+
minValue,
|
|
35
|
+
maxValue,
|
|
36
|
+
isDateUnavailable,
|
|
37
|
+
isDisabled = false,
|
|
38
|
+
isReadOnly = false,
|
|
39
|
+
isRequired = false,
|
|
40
|
+
isInvalid = false,
|
|
41
|
+
"aria-label": ariaLabel = "Date",
|
|
42
|
+
className,
|
|
43
|
+
style,
|
|
44
|
+
}: DatePickerProps) {
|
|
45
|
+
const isControlled = controlledValue !== undefined;
|
|
46
|
+
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
47
|
+
const value = isControlled ? controlledValue : internalValue;
|
|
48
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
49
|
+
|
|
50
|
+
const commit = (next: Date | null) => {
|
|
51
|
+
if (!isControlled) setInternalValue(next);
|
|
52
|
+
onChange?.(next);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<Popover isOpen={isOpen} onOpenChange={setIsOpen}>
|
|
57
|
+
<InputGroup
|
|
58
|
+
className={[fieldStyles.field, className].filter(Boolean).join(" ")}
|
|
59
|
+
style={{
|
|
60
|
+
paddingRight: 0,
|
|
61
|
+
paddingLeft: 18,
|
|
62
|
+
width: "fit-content",
|
|
63
|
+
...style,
|
|
64
|
+
}}
|
|
65
|
+
data-invalid={isInvalid || undefined}
|
|
66
|
+
>
|
|
67
|
+
<div style={{ display: "flex" }}>
|
|
68
|
+
<DateField
|
|
69
|
+
value={value}
|
|
70
|
+
onChange={commit}
|
|
71
|
+
minValue={minValue}
|
|
72
|
+
maxValue={maxValue}
|
|
73
|
+
isDisabled={isDisabled}
|
|
74
|
+
isReadOnly={isReadOnly}
|
|
75
|
+
isRequired={isRequired}
|
|
76
|
+
isInvalid={isInvalid}
|
|
77
|
+
aria-label={ariaLabel}
|
|
78
|
+
data-in-group={true}
|
|
79
|
+
style={{ width: "fit-content" }}
|
|
80
|
+
/>
|
|
81
|
+
<Popover.Trigger>
|
|
82
|
+
<Button
|
|
83
|
+
type="button"
|
|
84
|
+
aria-label="Open calendar"
|
|
85
|
+
disabled={isDisabled || isReadOnly}
|
|
86
|
+
variant="primary-bold"
|
|
87
|
+
elevated
|
|
88
|
+
style={{
|
|
89
|
+
borderRadius: 60,
|
|
90
|
+
minWidth: 60,
|
|
91
|
+
minHeight: 36,
|
|
92
|
+
maxHeight: 36,
|
|
93
|
+
margin: 4,
|
|
94
|
+
marginLeft: 12,
|
|
95
|
+
}}
|
|
96
|
+
>
|
|
97
|
+
<Icon systemName="calendar_month" />
|
|
98
|
+
</Button>
|
|
99
|
+
</Popover.Trigger>
|
|
100
|
+
</div>
|
|
101
|
+
</InputGroup>
|
|
102
|
+
<Popover.Content placement="bottom-start" offset={4}>
|
|
103
|
+
<Calendar
|
|
104
|
+
value={value}
|
|
105
|
+
onChange={(next) => {
|
|
106
|
+
const date = Array.isArray(next) ? (next[0] ?? null) : next;
|
|
107
|
+
commit(date);
|
|
108
|
+
if (date && !isSameDay(date, value)) setIsOpen(false);
|
|
109
|
+
}}
|
|
110
|
+
minValue={minValue}
|
|
111
|
+
maxValue={maxValue}
|
|
112
|
+
isDateUnavailable={isDateUnavailable}
|
|
113
|
+
aria-label={ariaLabel}
|
|
114
|
+
/>
|
|
115
|
+
</Popover.Content>
|
|
116
|
+
</Popover>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import React, { useState } from "react";
|
|
3
|
+
import Icon from "@/components/tools/label/Icon";
|
|
4
|
+
import Popover from "@/components/(overlays)/popover/Popover";
|
|
5
|
+
import DateField from "@/components/(date & time)/dateField/DateField";
|
|
6
|
+
import RangeCalendar, {
|
|
7
|
+
type DateRange,
|
|
8
|
+
} from "@/components/(date & time)/rangeCalendar/RangeCalendar";
|
|
9
|
+
import fieldStyles from "@/components/(forms)/shared/field.module.css";
|
|
10
|
+
import Drop from "@/components/tools/dropdown/drop";
|
|
11
|
+
import Button from "@/components/(buttons)/button";
|
|
12
|
+
import InputGroup from "@/components/(forms)/inputGroup/InputGroup";
|
|
13
|
+
|
|
14
|
+
export interface DateRangePickerProps {
|
|
15
|
+
value?: DateRange | null;
|
|
16
|
+
defaultValue?: DateRange | null;
|
|
17
|
+
onChange?: (value: DateRange | null) => void;
|
|
18
|
+
minValue?: Date;
|
|
19
|
+
maxValue?: Date;
|
|
20
|
+
isDateUnavailable?: (date: Date) => boolean;
|
|
21
|
+
isDisabled?: boolean;
|
|
22
|
+
isReadOnly?: boolean;
|
|
23
|
+
isRequired?: boolean;
|
|
24
|
+
isInvalid?: boolean;
|
|
25
|
+
"aria-label"?: string;
|
|
26
|
+
className?: string;
|
|
27
|
+
style?: React.CSSProperties;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default function DateRangePicker({
|
|
31
|
+
value: controlledValue,
|
|
32
|
+
defaultValue = null,
|
|
33
|
+
onChange,
|
|
34
|
+
minValue,
|
|
35
|
+
maxValue,
|
|
36
|
+
isDateUnavailable,
|
|
37
|
+
isDisabled = false,
|
|
38
|
+
isReadOnly = false,
|
|
39
|
+
isRequired = false,
|
|
40
|
+
isInvalid = false,
|
|
41
|
+
"aria-label": ariaLabel = "Date range",
|
|
42
|
+
className,
|
|
43
|
+
style,
|
|
44
|
+
}: DateRangePickerProps) {
|
|
45
|
+
const isControlled = controlledValue !== undefined;
|
|
46
|
+
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
47
|
+
const value = isControlled ? controlledValue : internalValue;
|
|
48
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
49
|
+
|
|
50
|
+
const commit = (next: DateRange | null) => {
|
|
51
|
+
if (!isControlled) setInternalValue(next);
|
|
52
|
+
onChange?.(next);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<Popover isOpen={isOpen} onOpenChange={setIsOpen}>
|
|
57
|
+
<InputGroup
|
|
58
|
+
className={[fieldStyles.field, className].filter(Boolean).join(" ")}
|
|
59
|
+
style={{
|
|
60
|
+
paddingRight: 0,
|
|
61
|
+
paddingLeft: 18,
|
|
62
|
+
width: "fit-content",
|
|
63
|
+
...style,
|
|
64
|
+
}}
|
|
65
|
+
data-invalid={isInvalid || undefined}
|
|
66
|
+
>
|
|
67
|
+
<div
|
|
68
|
+
style={{
|
|
69
|
+
display: "flex",
|
|
70
|
+
alignItems: "center",
|
|
71
|
+
}}
|
|
72
|
+
>
|
|
73
|
+
<DateField
|
|
74
|
+
value={value?.start ?? null}
|
|
75
|
+
onChange={(start) =>
|
|
76
|
+
commit(start ? { start, end: value?.end ?? start } : null)
|
|
77
|
+
}
|
|
78
|
+
minValue={minValue}
|
|
79
|
+
maxValue={maxValue}
|
|
80
|
+
isDisabled={isDisabled}
|
|
81
|
+
isReadOnly={isReadOnly}
|
|
82
|
+
isRequired={isRequired}
|
|
83
|
+
aria-label={`${ariaLabel} start`}
|
|
84
|
+
style={{ width: "fit-content" }}
|
|
85
|
+
/>
|
|
86
|
+
<span
|
|
87
|
+
style={{
|
|
88
|
+
color: "var(--md-sys-color-on-surface-variant)",
|
|
89
|
+
marginInline: 8,
|
|
90
|
+
}}
|
|
91
|
+
>
|
|
92
|
+
–
|
|
93
|
+
</span>
|
|
94
|
+
<DateField
|
|
95
|
+
value={value?.end ?? null}
|
|
96
|
+
onChange={(end) =>
|
|
97
|
+
commit(end ? { start: value?.start ?? end, end } : null)
|
|
98
|
+
}
|
|
99
|
+
minValue={minValue}
|
|
100
|
+
maxValue={maxValue}
|
|
101
|
+
isDisabled={isDisabled}
|
|
102
|
+
isReadOnly={isReadOnly}
|
|
103
|
+
isRequired={isRequired}
|
|
104
|
+
aria-label={`${ariaLabel} end`}
|
|
105
|
+
style={{ width: "fit-content" }}
|
|
106
|
+
/>
|
|
107
|
+
<Popover.Trigger>
|
|
108
|
+
<Button
|
|
109
|
+
type="button"
|
|
110
|
+
aria-label="Open calendar"
|
|
111
|
+
disabled={isDisabled || isReadOnly}
|
|
112
|
+
variant="primary-bold"
|
|
113
|
+
elevated
|
|
114
|
+
style={{
|
|
115
|
+
borderRadius: 60,
|
|
116
|
+
minWidth: 60,
|
|
117
|
+
minHeight: 36,
|
|
118
|
+
maxHeight: 36,
|
|
119
|
+
margin: 4,
|
|
120
|
+
marginLeft: 12,
|
|
121
|
+
}}
|
|
122
|
+
>
|
|
123
|
+
<Icon systemName="calendar_month" />
|
|
124
|
+
</Button>
|
|
125
|
+
</Popover.Trigger>
|
|
126
|
+
</div>
|
|
127
|
+
</InputGroup>
|
|
128
|
+
|
|
129
|
+
<Popover.Content placement="bottom-start" offset={4}>
|
|
130
|
+
<RangeCalendar
|
|
131
|
+
value={value}
|
|
132
|
+
onChange={(next) => {
|
|
133
|
+
commit(next);
|
|
134
|
+
if (next) setIsOpen(false);
|
|
135
|
+
}}
|
|
136
|
+
minValue={minValue}
|
|
137
|
+
maxValue={maxValue}
|
|
138
|
+
isDateUnavailable={isDateUnavailable}
|
|
139
|
+
aria-label={ariaLabel}
|
|
140
|
+
/>
|
|
141
|
+
</Popover.Content>
|
|
142
|
+
</Popover>
|
|
143
|
+
);
|
|
144
|
+
}
|