@yamatozhen/design_system 1.0.1 → 1.2.1

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.
Files changed (156) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +101 -101
  3. package/package.json +50 -50
  4. package/scripts/postinstall.js +91 -91
  5. package/template/app/ClientNav.tsx +258 -310
  6. package/template/app/globals.css +2 -167
  7. package/template/app/layout.tsx +94 -82
  8. package/template/app/themes/dark-mc.css +51 -51
  9. package/template/app/themes/dark.css +51 -51
  10. package/template/app/themes/light-mc.css +51 -51
  11. package/template/app/themes/light.css +51 -51
  12. package/template/app/themes/theme.css +272 -82
  13. package/template/components/{layout/button → (buttons)}/Button.module.css +351 -305
  14. package/template/components/{layout/button → (buttons)}/ButtonGroup.tsx +414 -503
  15. package/template/components/{layout/button → (buttons)}/FAB.tsx +119 -118
  16. package/template/components/(buttons)/button.tsx +164 -0
  17. package/template/components/(controls)/slider/Slider.module.css +250 -0
  18. package/template/components/(controls)/slider/Slider.tsx +386 -0
  19. package/template/components/{layout → (controls)}/switch/Switch.module.css +108 -102
  20. package/template/components/{layout → (controls)}/switch/Switch.tsx +69 -48
  21. package/template/components/(date & time)/calendar/Calendar.module.css +125 -0
  22. package/template/components/(date & time)/calendar/Calendar.tsx +206 -0
  23. package/template/components/(date & time)/dateField/DateField.module.css +25 -0
  24. package/template/components/(date & time)/dateField/DateField.tsx +193 -0
  25. package/template/components/(date & time)/datePicker/DatePicker.tsx +118 -0
  26. package/template/components/(date & time)/dateRangePicker/DateRangePicker.tsx +144 -0
  27. package/template/components/(date & time)/rangeCalendar/RangeCalendar.module.css +203 -0
  28. package/template/components/(date & time)/rangeCalendar/RangeCalendar.tsx +263 -0
  29. package/template/components/(date & time)/shared/dateUtils.ts +107 -0
  30. package/template/components/(date & time)/timeField/TimeField.module.css +39 -0
  31. package/template/components/(date & time)/timeField/TimeField.tsx +158 -0
  32. package/template/components/(feedback)/circularProgress/CircularProgress.tsx +646 -0
  33. package/template/components/(feedback)/linearProgress/LinearProgress.tsx +337 -0
  34. package/template/components/(feedback)/meter/Meter.tsx +111 -0
  35. package/template/components/(feedback)/skeleton/Skeleton.module.css +49 -0
  36. package/template/components/(feedback)/skeleton/Skeleton.tsx +32 -0
  37. package/template/components/(feedback)/spinner/Spinner.module.css +27 -0
  38. package/template/components/(feedback)/spinner/Spinner.tsx +60 -0
  39. package/template/components/(forms)/checkbox/Checkbox.tsx +121 -0
  40. package/template/components/(forms)/checkboxGroup/CheckboxGroup.tsx +83 -0
  41. package/template/components/(forms)/description/Description.tsx +34 -0
  42. package/template/components/(forms)/errorMessage/ErrorMessage.tsx +31 -0
  43. package/template/components/(forms)/fieldError/FieldError.tsx +39 -0
  44. package/template/components/(forms)/fieldset/Fieldset.tsx +51 -0
  45. package/template/components/(forms)/form/Form.tsx +54 -0
  46. package/template/components/(forms)/input/Input.tsx +50 -0
  47. package/template/components/(forms)/inputGroup/InputGroup.tsx +65 -0
  48. package/template/components/(forms)/inputOtp/InputOtp.tsx +139 -0
  49. package/template/components/(forms)/label/Label.tsx +46 -0
  50. package/template/components/(forms)/numberField/NumberField.tsx +292 -0
  51. package/template/components/(forms)/radioGroup/RadioGroup.tsx +175 -0
  52. package/template/components/(forms)/searchField/SearchField.tsx +139 -0
  53. package/template/components/(forms)/shared/field.module.css +75 -0
  54. package/template/components/(forms)/shared/fieldContext.ts +28 -0
  55. package/template/components/(forms)/textArea/TextArea.tsx +55 -0
  56. package/template/components/(forms)/textField/TextField.tsx +91 -0
  57. package/template/components/{layout → (layout)}/Lightbox/LightboxCard.tsx +100 -100
  58. package/template/components/{layout → (layout)}/Lightbox/LightboxGallery.module.css +249 -249
  59. package/template/components/{layout → (layout)}/Lightbox/LightboxGallery.tsx +72 -72
  60. package/template/components/{layout → (layout)}/Lightbox/LightboxGrid.tsx +185 -186
  61. package/template/components/{layout → (layout)}/Lightbox/LightboxModal.module.css +395 -395
  62. package/template/components/{layout → (layout)}/Lightbox/LightboxModal.tsx +498 -500
  63. package/template/components/{layout → (layout)}/Lightbox/demo.tsx +396 -412
  64. package/template/components/{layout → (layout)}/Lightbox/index.ts +30 -30
  65. package/template/components/{layout → (layout)}/Lightbox/types.ts +101 -113
  66. package/template/components/{layout → (layout)}/Lightbox/useLightboxFilters.ts +140 -140
  67. package/template/components/(layout)/accordion/Accordion.module.css +108 -0
  68. package/template/components/(layout)/accordion/Accordion.tsx +251 -0
  69. package/template/components/(layout)/card/Card.module.css +136 -0
  70. package/template/components/(layout)/card/Card.tsx +371 -0
  71. package/template/components/(layout)/list/List.module.css +83 -0
  72. package/template/components/(layout)/list/List.tsx +332 -0
  73. package/template/components/{layout → (layout)}/navigation/Wrap.tsx +41 -41
  74. package/template/components/(layout)/navigation/breadcrumbs/Breadcrumbs.tsx +145 -0
  75. package/template/components/{layout/navigation/nav/Nav.module.css → (layout)/navigation/nav/Nav.module.css.old} +474 -508
  76. package/template/components/{layout → (layout)}/navigation/nav/Nav.tsx +186 -167
  77. package/template/components/{layout → (layout)}/navigation/nav/NavBar.tsx +396 -419
  78. package/template/components/{layout → (layout)}/navigation/nav/NavContext.tsx +259 -259
  79. package/template/components/{layout → (layout)}/navigation/nav/NavItem.tsx +195 -173
  80. package/template/components/{layout → (layout)}/navigation/nav/NavNew.module.css +406 -373
  81. package/template/components/{layout → (layout)}/navigation/nav/NavRail.tsx +317 -315
  82. package/template/components/{layout → (layout)}/navigation/nav/NavSection.tsx +101 -102
  83. package/template/components/{layout → (layout)}/navigation/nav/NavTab.tsx +25 -25
  84. package/template/components/{layout → (layout)}/navigation/nav/navftb/NavFTB.module.css +253 -252
  85. package/template/components/{layout → (layout)}/navigation/nav/navftb/NavFTB.tsx +448 -399
  86. package/template/components/{layout → (layout)}/navigation/nav/navftb/useTabIndicator.ts +498 -484
  87. package/template/components/{layout → (layout)}/navigation/nav/navheader/NavHeader.module.css +59 -59
  88. package/template/components/{layout → (layout)}/navigation/nav/navheader/NavHeader.tsx +465 -473
  89. package/template/components/(layout)/navigation/pagination/Pagination.tsx +261 -0
  90. package/template/components/{layout → (layout)}/pages/loadingScreen.tsx +117 -102
  91. package/template/components/{layout → (layout)}/pages/maintenance/Maintenance.tsx +52 -52
  92. package/template/components/{layout → (layout)}/pages/maintenance/maintenance.module.css +162 -162
  93. package/template/components/(layout)/scrollShadow/ScrollShadow.module.css +81 -0
  94. package/template/components/(layout)/scrollShadow/ScrollShadow.tsx +161 -0
  95. package/template/components/(layout)/scrollShadow/useScrollShadow.ts +130 -0
  96. package/template/components/(layout)/separator/Separator.tsx +112 -0
  97. package/template/components/(overlays)/accessibilityModal/AccessibilityModal.tsx +307 -0
  98. package/template/components/(overlays)/drawer/Drawer.tsx +953 -0
  99. package/template/components/(overlays)/modal/Modal.tsx +654 -0
  100. package/template/components/(overlays)/popover/Popover.tsx +420 -0
  101. package/template/components/(overlays)/toast/Toast.tsx +692 -0
  102. package/template/components/(pickers)/autocomplete/Autocomplete.tsx +24 -0
  103. package/template/components/(pickers)/comboBox/ComboBox.tsx +21 -0
  104. package/template/components/(pickers)/select/Select.tsx +188 -0
  105. package/template/components/(pickers)/shared/FilterableField.tsx +223 -0
  106. package/template/components/(pickers)/shared/PickerItem.ts +13 -0
  107. package/template/components/tools/CustomScrollbar.tsx +107 -0
  108. package/template/components/tools/Divider.tsx +11 -11
  109. package/template/components/tools/ReduceMotionContext.tsx +5 -5
  110. package/template/components/tools/Sinewave.tsx +396 -199
  111. package/template/components/tools/SinewaveProgress.tsx +140 -135
  112. package/template/components/tools/badge/Badge.tsx +28 -28
  113. package/template/components/tools/dropdown/drop.module.css +196 -0
  114. package/template/components/tools/dropdown/drop.tsx +568 -0
  115. package/template/components/tools/easing.ts +118 -0
  116. package/template/components/tools/flubber.d.ts +6 -6
  117. package/template/components/tools/footer/Footer.tsx +20 -0
  118. package/template/components/tools/input/Input.module.css +45 -0
  119. package/template/components/tools/input/Input.tsx +99 -0
  120. package/template/components/tools/label/Icon.tsx +39 -0
  121. package/template/components/tools/label/Label.tsx +156 -0
  122. package/template/components/tools/mobileViewProvider.tsx +53 -58
  123. package/template/components/tools/ripple/ripple.css +38 -41
  124. package/template/components/tools/ripple/ripple.tsx +78 -53
  125. package/template/components/tools/shape/Shape.module.css +25 -0
  126. package/template/components/tools/shape/{ShapeMorph.tsx → Shape.tsx} +316 -190
  127. package/template/components/tools/shape/ShapeLoader.tsx +104 -101
  128. package/template/components/tools/shape/ShapePaths.ts +116 -116
  129. package/template/components/tools/switch/Switch.module.css +102 -102
  130. package/template/components/tools/switch/Switch.tsx +48 -48
  131. package/template/components/tools/useBodyScrollLock.tsx +27 -27
  132. package/template/components/tools/useImageColor.ts +47 -47
  133. package/template/components/tools/useNavSheetDrag.tsx +196 -196
  134. package/template/components/layout/accordion/Accordion.module.css +0 -149
  135. package/template/components/layout/accordion/Accordion.tsx +0 -114
  136. package/template/components/layout/button/button.tsx +0 -128
  137. package/template/components/layout/button/drop.module.css +0 -229
  138. package/template/components/layout/button/drop.tsx +0 -516
  139. package/template/components/layout/hero/v1/heroSlideshow.module.css +0 -107
  140. package/template/components/layout/hero/v1/heroSlideshow.tsx +0 -233
  141. package/template/components/layout/modals/accessibilityModal/AccessibilityModal.module.css +0 -126
  142. package/template/components/layout/modals/accessibilityModal/AccessibilityModal.tsx +0 -290
  143. package/template/components/layout/modals/alert/Alert.tsx +0 -188
  144. package/template/components/layout/navigation/MioCard.module.css +0 -88
  145. package/template/components/layout/navigation/MioCard.tsx +0 -266
  146. package/template/components/tools/ProgressiveBlur.tsx +0 -73
  147. package/template/components/tools/icon/icon.module.css +0 -0
  148. package/template/components/tools/icon/icon.tsx +0 -125
  149. package/template/components/tools/react-bits/ClickSpark.tsx +0 -177
  150. package/template/components/tools/react-bits/FadeContent.tsx +0 -90
  151. package/template/components/tools/react-bits/GlareHover.tsx +0 -73
  152. package/template/components/tools/react-bits/GradientText/GradientText.css +0 -70
  153. package/template/components/tools/react-bits/GradientText/GradientText.tsx +0 -44
  154. package/template/components/tools/react-bits/Magnet.tsx +0 -118
  155. package/template/components/tools/react-bits/Stepper/Stepper.css +0 -134
  156. package/template/components/tools/react-bits/Stepper/Stepper.tsx +0 -412
@@ -1,48 +1,69 @@
1
- "use client";
2
- import styles from "./Switch.module.css";
3
- import { useState } from "react";
4
- import Icon from "../../tools/icon/icon";
5
-
6
- export default function Switch({
7
- id,
8
- onClick,
9
- systemIcon = false,
10
- checked: controlledChecked,
11
- onChange,
12
- }: {
13
- id?: string;
14
- onClick?: () => void;
15
- systemIcon?: boolean;
16
- /** If provided the Switch runs in controlled mode */
17
- checked?: boolean;
18
- onChange?: (checked: boolean) => void;
19
- }) {
20
- const [internalChecked, setInternalChecked] = useState(false);
21
- const isControlled = controlledChecked !== undefined;
22
- const isChecked = isControlled ? controlledChecked : internalChecked;
23
-
24
- const handleChange = () => {
25
- const next = !isChecked;
26
- if (!isControlled) setInternalChecked(next);
27
- onChange?.(next);
28
- onClick?.();
29
- };
30
- return (
31
- <>
32
- <label
33
- className={`${styles.switchContainer} ${isChecked ? styles.checked : ""}`}
34
- >
35
- <input type="checkbox" checked={isChecked} onChange={handleChange} />
36
- <span className={styles.switchBg}>
37
- <Icon
38
- id={`switch-icon md-18${id}`}
39
- label=""
40
- className={styles.switchIcon}
41
- systemName={isChecked ? "check" : "close"}
42
- iconStyle={systemIcon == false ? { opacity: 0 } : {}}
43
- />
44
- </span>
45
- </label>
46
- </>
47
- );
48
- }
1
+ "use client";
2
+ import styles from "./Switch.module.css";
3
+ import { useState, type CSSProperties } from "react";
4
+ import Icon from "../../tools/label/Icon";
5
+
6
+ export type SwitchVariant = "primary" | "secondary" | "tertiary";
7
+
8
+ export default function Switch({
9
+ id,
10
+ onClick,
11
+ systemIcon = false,
12
+ checked: controlledChecked,
13
+ onChange,
14
+ onToggleOn,
15
+ onToggleOff,
16
+ variant = "primary",
17
+ }: {
18
+ id?: string;
19
+ onClick?: () => void;
20
+ systemIcon?: boolean;
21
+ /** If provided the Switch runs in controlled mode */
22
+ checked?: boolean;
23
+ onChange?: (checked: boolean) => void;
24
+ /** Fired instead of/alongside onChange when the switch turns on or off —
25
+ * split out since consumers often only care about one direction. */
26
+ onToggleOn?: () => void;
27
+ onToggleOff?: () => void;
28
+ /** Checked-state color. No "default"/neutral option — a checked switch is
29
+ * always tinted, there's no neutral "on" look. */
30
+ variant?: SwitchVariant;
31
+ }) {
32
+ const [internalChecked, setInternalChecked] = useState(false);
33
+ const isControlled = controlledChecked !== undefined;
34
+ const isChecked = isControlled ? controlledChecked : internalChecked;
35
+
36
+ const handleChange = () => {
37
+ const next = !isChecked;
38
+ if (!isControlled) setInternalChecked(next);
39
+ onChange?.(next);
40
+ if (next) onToggleOn?.();
41
+ else onToggleOff?.();
42
+ onClick?.();
43
+ };
44
+
45
+ const variantStyle = {
46
+ "--switch-on-bg": `var(--md-sys-color-${variant})`,
47
+ "--switch-on-thumb": `var(--md-sys-color-on-${variant})`,
48
+ } as CSSProperties;
49
+
50
+ return (
51
+ <>
52
+ <label
53
+ className={`${styles.switchContainer} ${isChecked ? styles.checked : ""}`}
54
+ style={variantStyle}
55
+ >
56
+ <input type="checkbox" checked={isChecked} onChange={handleChange} />
57
+ <span className={styles.switchBg}>
58
+ <span
59
+ id={`switch-icon md-18${id}`}
60
+ className={styles.switchIcon}
61
+ style={systemIcon == false ? { opacity: 0 } : {}}
62
+ >
63
+ <Icon systemName={isChecked ? "check" : "close"} />
64
+ </span>
65
+ </span>
66
+ </label>
67
+ </>
68
+ );
69
+ }
@@ -0,0 +1,125 @@
1
+ .calendar {
2
+ display: inline-flex;
3
+ flex-direction: column;
4
+ gap: 8px;
5
+ width: fit-content;
6
+ padding: 12px;
7
+ border-radius: var(--borderRadius-md);
8
+ background: transparent;
9
+ }
10
+
11
+ .header {
12
+ display: flex;
13
+ align-items: center;
14
+ justify-content: space-between;
15
+ }
16
+
17
+ .heading {
18
+ font-size: 14px;
19
+ font-weight: 600;
20
+ color: var(--md-sys-color-on-surface);
21
+ }
22
+
23
+ .navButton {
24
+ display: flex;
25
+ align-items: center;
26
+ justify-content: center;
27
+ width: 32px;
28
+ height: 32px;
29
+ border: none;
30
+ border-radius: var(--borderRadius-sm);
31
+ background: transparent;
32
+ color: var(--md-sys-color-on-surface);
33
+ cursor: pointer;
34
+ transition: background-color var(--transition-expressive-color);
35
+ }
36
+ .navButton:hover:not(:disabled) {
37
+ background: var(--md-sys-color-surface-container-highest);
38
+ }
39
+ .navButton:disabled {
40
+ opacity: 0.4;
41
+ cursor: not-allowed;
42
+ }
43
+
44
+ .grid {
45
+ display: flex;
46
+ flex-direction: column;
47
+ gap: 2px;
48
+ }
49
+
50
+ .gridHeaderRow,
51
+ .gridBody {
52
+ display: grid;
53
+ grid-template-columns: repeat(7, 1fr);
54
+ }
55
+
56
+ .headerCell {
57
+ display: flex;
58
+ align-items: center;
59
+ justify-content: center;
60
+ height: 32px;
61
+ font-size: 14px;
62
+ font-weight: 600;
63
+ color: var(--md-sys-color-on-surface-variant);
64
+ }
65
+
66
+ .cell {
67
+ position: relative;
68
+ z-index: 0;
69
+ display: flex;
70
+ align-items: center;
71
+ justify-content: center;
72
+ margin: 2px 0;
73
+ height: 38px;
74
+ min-width: 38px;
75
+ border-radius: var(--borderRadius-xs);
76
+ border: none;
77
+ background: transparent;
78
+ color: var(--md-sys-color-on-surface);
79
+ font-size: 14px;
80
+ cursor: pointer;
81
+ filter: none;
82
+ transition:
83
+ background-color var(--transition-expressive-color),
84
+ border-radius var(--transition-expressive-fast);
85
+ }
86
+
87
+ .cell[data-outside-month="true"] {
88
+ color: var(--md-sys-color-on-surface-variant);
89
+ opacity: 0.4;
90
+ }
91
+
92
+ .cell[data-today="true"] {
93
+ font-weight: 700;
94
+ border-radius: var(--borderRadius-md);
95
+ box-shadow: inset 0 0 0 2px var(--md-sys-color-primary);
96
+ }
97
+
98
+ .cell:hover:not(:disabled) {
99
+ background: var(--md-sys-color-surface-container-low);
100
+ filter: var(--filterBrightness);
101
+ }
102
+
103
+ .cell[data-selected="true"] {
104
+ background: var(--md-sys-color-primary) !important;
105
+ color: var(--md-sys-color-on-primary) !important;
106
+ font-weight: 600;
107
+ border-radius: var(--borderRadius-md) !important;
108
+ box-shadow:
109
+ 0 0 0 1px var(--globalUIBorder),
110
+ 0 1px 1px rgba(0, 0, 0, 0.1),
111
+ 0 1px 3px rgba(0, 0, 0, 0.1),
112
+ 0 2px 6px rgba(0, 0, 0, 0.1);
113
+ }
114
+
115
+ .cell[data-unavailable="true"],
116
+ .cell:disabled {
117
+ opacity: 0.35;
118
+ cursor: not-allowed;
119
+ text-decoration: line-through;
120
+ }
121
+
122
+ .cell:focus-visible {
123
+ outline: 2px solid var(--md-sys-color-primary);
124
+ outline-offset: 1px;
125
+ }
@@ -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
+ }