@musecat/uikit 0.1.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.
- package/LICENSE +9 -0
- package/README.md +51 -0
- package/index.ts +78 -0
- package/package.json +103 -0
- package/packages/Components/Box/Box.tsx +173 -0
- package/packages/Components/Box/Box.types.ts +48 -0
- package/packages/Components/Button/Button.tsx +275 -0
- package/packages/Components/Button/Button.types.ts +44 -0
- package/packages/Components/Card/Card.default.tsx +180 -0
- package/packages/Components/Card/Card.foldable.tsx +383 -0
- package/packages/Components/Card/Card.module.scss +23 -0
- package/packages/Components/Card/Card.tsx +8 -0
- package/packages/Components/Card/Card.types.ts +91 -0
- package/packages/Components/Card/Card.utils.ts +66 -0
- package/packages/Components/Checkbox/Checkbox.module.scss +11 -0
- package/packages/Components/Checkbox/Checkbox.tsx +104 -0
- package/packages/Components/Checkbox/Checkbox.types.ts +24 -0
- package/packages/Components/CodeBox/CodeBox.copy.tsx +43 -0
- package/packages/Components/CodeBox/CodeBox.module.scss +72 -0
- package/packages/Components/CodeBox/CodeBox.tsx +91 -0
- package/packages/Components/CodeBox/CodeBox.types.ts +17 -0
- package/packages/Components/ContextMenu/ContextMenu.module.scss +8 -0
- package/packages/Components/ContextMenu/ContextMenu.options.tsx +126 -0
- package/packages/Components/ContextMenu/ContextMenu.tsx +381 -0
- package/packages/Components/ContextMenu/ContextMenu.types.ts +46 -0
- package/packages/Components/ContributionGraph/ContributionGraph.module.scss +42 -0
- package/packages/Components/ContributionGraph/ContributionGraph.tsx +454 -0
- package/packages/Components/ContributionGraph/ContributionGraph.types.ts +27 -0
- package/packages/Components/DatePicker/DatePicker.calendar.tsx +161 -0
- package/packages/Components/DatePicker/DatePicker.core.tsx +582 -0
- package/packages/Components/DatePicker/DatePicker.module.scss +26 -0
- package/packages/Components/DatePicker/DatePicker.tsx +786 -0
- package/packages/Components/DatePicker/DatePicker.types.ts +36 -0
- package/packages/Components/DatePicker/DatePicker.utils.ts +80 -0
- package/packages/Components/DatePicker/hooks/useCalendar.ts +61 -0
- package/packages/Components/DatePicker/hooks/useSelection.ts +208 -0
- package/packages/Components/Divider/Divider.tsx +46 -0
- package/packages/Components/Divider/Divider.types.ts +12 -0
- package/packages/Components/Header/Header.module.scss +74 -0
- package/packages/Components/Header/Header.tsx +47 -0
- package/packages/Components/Header/Header.types.ts +8 -0
- package/packages/Components/Icon/Icon.group.tsx +122 -0
- package/packages/Components/Icon/Icon.group.types.ts +20 -0
- package/packages/Components/Icon/Icon.tsx +341 -0
- package/packages/Components/Icon/Icon.types.ts +59 -0
- package/packages/Components/Icon/SVG/data.tsx +232 -0
- package/packages/Components/Input/Input.module.scss +5 -0
- package/packages/Components/Input/Input.tsx +87 -0
- package/packages/Components/Input/Input.types.ts +14 -0
- package/packages/Components/Label/Label.module.scss +19 -0
- package/packages/Components/Label/Label.tsx +115 -0
- package/packages/Components/Label/Label.types.ts +28 -0
- package/packages/Components/Layout/Layout.docs.module.scss +42 -0
- package/packages/Components/Layout/Layout.docs.tsx +150 -0
- package/packages/Components/Layout/Layout.docs.types.ts +18 -0
- package/packages/Components/Layout/Layout.module.scss +91 -0
- package/packages/Components/Layout/Layout.tsx +306 -0
- package/packages/Components/Layout/Layout.types.ts +71 -0
- package/packages/Components/Maps/OSM/MapOSM.module.scss +11 -0
- package/packages/Components/Maps/OSM/MapOSM.shared.ts +121 -0
- package/packages/Components/Maps/OSM/MapOSM.tsx +279 -0
- package/packages/Components/Maps/OSM/MapOSM.types.ts +18 -0
- package/packages/Components/Nav/Nav.module.scss +137 -0
- package/packages/Components/Nav/Nav.tsx +304 -0
- package/packages/Components/Nav/Nav.types.ts +32 -0
- package/packages/Components/Nav/hooks/useNavDrag.ts +374 -0
- package/packages/Components/Nav/hooks/useNavIndicator.ts +137 -0
- package/packages/Components/Pagination/Pagination.tsx +254 -0
- package/packages/Components/Pagination/Pagination.types.ts +18 -0
- package/packages/Components/Pill/Pill.tsx +127 -0
- package/packages/Components/Pill/Pill.types.ts +33 -0
- package/packages/Components/Profile/Profile.shared.ts +74 -0
- package/packages/Components/Profile/Profile.tsx +382 -0
- package/packages/Components/Profile/Profile.types.ts +55 -0
- package/packages/Components/Progress/Progress.module.scss +15 -0
- package/packages/Components/Progress/Progress.tsx +88 -0
- package/packages/Components/Progress/Progress.types.ts +22 -0
- package/packages/Components/Radio/Radio.module.scss +11 -0
- package/packages/Components/Radio/Radio.tsx +121 -0
- package/packages/Components/Radio/Radio.types.ts +20 -0
- package/packages/Components/Select/Select.keyboard.tsx +76 -0
- package/packages/Components/Select/Select.trigger.tsx +88 -0
- package/packages/Components/Select/Select.tsx +11 -0
- package/packages/Components/Select/Select.types.ts +38 -0
- package/packages/Components/Select/Select.utils.ts +84 -0
- package/packages/Components/Select/hooks/useSelectNavigation.ts +461 -0
- package/packages/Components/Select/hooks/useSelectSelection.ts +142 -0
- package/packages/Components/Select/hooks/useSelectState.ts +314 -0
- package/packages/Components/Select/select.control.tsx +228 -0
- package/packages/Components/Select/select.inner.tsx +312 -0
- package/packages/Components/Skeleton/Skeleton.tsx +30 -0
- package/packages/Components/Skeleton/Skeleton.types.ts +12 -0
- package/packages/Components/Spinner/Spinner.module.scss +78 -0
- package/packages/Components/Spinner/Spinner.tsx +125 -0
- package/packages/Components/Spinner/Spinner.types.ts +19 -0
- package/packages/Components/Text/Text.module.scss +7 -0
- package/packages/Components/Text/Text.tsx +49 -0
- package/packages/Components/Text/Text.types.ts +33 -0
- package/packages/Components/TimePicker/TimePicker.core.tsx +448 -0
- package/packages/Components/TimePicker/TimePicker.module.scss +30 -0
- package/packages/Components/TimePicker/TimePicker.tsx +511 -0
- package/packages/Components/TimePicker/TimePicker.types.ts +22 -0
- package/packages/Components/Timeline/Timeline.tsx +111 -0
- package/packages/Components/Timeline/Timeline.types.ts +23 -0
- package/packages/Components/Title/Title.tsx +305 -0
- package/packages/Components/Title/Title.types.ts +64 -0
- package/packages/Components/Toggle/Toggle.module.scss +32 -0
- package/packages/Components/Toggle/Toggle.tsx +272 -0
- package/packages/Components/Toggle/Toggle.types.ts +17 -0
- package/packages/Components/Tooltip/Tooltip.module.scss +44 -0
- package/packages/Components/Tooltip/Tooltip.tsx +340 -0
- package/packages/Components/Tooltip/Tooltip.types.ts +38 -0
- package/packages/Frameworks/Dialog/Dialog.background.tsx +88 -0
- package/packages/Frameworks/Dialog/Dialog.boot.tsx +32 -0
- package/packages/Frameworks/Dialog/Dialog.store.ts +199 -0
- package/packages/Frameworks/Dialog/Dialog.tsx +185 -0
- package/packages/Frameworks/Dialog/Dialog.types.ts +264 -0
- package/packages/Frameworks/Dialog/Dialog.utils.ts +22 -0
- package/packages/Frameworks/Dialog/contents/Dialog.footer.tsx +79 -0
- package/packages/Frameworks/Dialog/contents/Dialog.funnel.tsx +260 -0
- package/packages/Frameworks/Dialog/contents/Dialog.header.tsx +137 -0
- package/packages/Frameworks/Dialog/hooks/useDialogPosition.ts +298 -0
- package/packages/Frameworks/Dialog/hooks/useSheetDrag.ts +325 -0
- package/packages/Frameworks/Dialog/hooks/useSheetGeometry.ts +201 -0
- package/packages/Frameworks/Dialog/hooks/useSheetProgressive.ts +98 -0
- package/packages/Frameworks/Dialog/renderers/renderModal.tsx +228 -0
- package/packages/Frameworks/Dialog/renderers/renderPopover.tsx +220 -0
- package/packages/Frameworks/Dialog/renderers/renderSheet.tsx +571 -0
- package/packages/Frameworks/EdgeEffect/EdgeEffect.tsx +52 -0
- package/packages/Frameworks/EdgeEffect/EdgeEffect.types.ts +5 -0
- package/packages/Frameworks/Motion/Motion.presets.ts +49 -0
- package/packages/Frameworks/Pressable/Pressable.module.scss +19 -0
- package/packages/Frameworks/Pressable/Pressable.tsx +651 -0
- package/packages/Frameworks/Pressable/Pressable.types.ts +73 -0
- package/packages/Frameworks/Squircle/Squircle.tsx +263 -0
- package/packages/Frameworks/Squircle/Squircle.types.ts +15 -0
- package/packages/Frameworks/Theme/Radius.types.ts +55 -0
- package/packages/Frameworks/Theme/Theme.types.ts +325 -0
- package/packages/Frameworks/Toaster/Toaster.boot.tsx +47 -0
- package/packages/Frameworks/Toaster/Toaster.module.scss +168 -0
- package/packages/Frameworks/Toaster/Toaster.types.ts +13 -0
- package/packages/Frameworks/View/DNDView/DNDView.module.scss +8 -0
- package/packages/Frameworks/View/DNDView/DNDView.tsx +470 -0
- package/packages/Frameworks/View/DNDView/DNDView.types.ts +61 -0
- package/packages/Frameworks/View/HScrollView/HScrollView.module.scss +59 -0
- package/packages/Frameworks/View/HScrollView/HScrollView.tsx +386 -0
- package/packages/Frameworks/View/HScrollView/HScrollView.types.ts +46 -0
- package/packages/Frameworks/View/ImageView/Dialog/ImageDialog.counter.tsx +27 -0
- package/packages/Frameworks/View/ImageView/Dialog/ImageDialog.footer.tsx +76 -0
- package/packages/Frameworks/View/ImageView/Dialog/ImageDialog.header.tsx +49 -0
- package/packages/Frameworks/View/ImageView/Dialog/ImageDialog.list.tsx +74 -0
- package/packages/Frameworks/View/ImageView/Dialog/ImageDialog.slide.tsx +71 -0
- package/packages/Frameworks/View/ImageView/Dialog/ImageDialog.tsx +175 -0
- package/packages/Frameworks/View/ImageView/Image.controls.tsx +39 -0
- package/packages/Frameworks/View/ImageView/Image.hooks.ts +82 -0
- package/packages/Frameworks/View/ImageView/Image.module.scss +7 -0
- package/packages/Frameworks/View/ImageView/Image.tsx +375 -0
- package/packages/Frameworks/View/ImageView/Image.types.ts +71 -0
- package/packages/Frameworks/View/ImageView/Image.utils.ts +79 -0
- package/packages/Frameworks/View/View.module.scss +34 -0
- package/packages/Frameworks/View/View.tsx +200 -0
- package/packages/Frameworks/View/View.types.ts +36 -0
- package/packages/Frameworks/_shared/Padding.types.ts +52 -0
- package/packages/Frameworks/_shared/StopParentInteraction.tsx +45 -0
- package/packages/Frameworks/_shared/Wind.types.ts +17 -0
- package/packages/Frameworks/_shared/bodyScrollLock.ts +127 -0
- package/packages/Frameworks/_shared/layer.constants.ts +8 -0
- package/packages/Frameworks/_shared/normalize.ts +39 -0
- package/packages/Frameworks/_shared/sizing.ts +55 -0
- package/packages/Frameworks/_shared/useControllableState.ts +29 -0
- package/packages/Styles/_animation.scss +42 -0
- package/packages/Styles/_color.scss +131 -0
- package/packages/Styles/_font.scss +30 -0
- package/packages/Styles/_icon.scss +782 -0
- package/packages/Styles/_importer.scss +9 -0
- package/packages/Styles/_system.scss +69 -0
- package/packages/Styles/_textstyle.scss +111 -0
- package/packages/Styles/_theme.scss +452 -0
- package/packages/Styles/_viewport-global.scss +99 -0
- package/packages/Styles/_viewport.scss +108 -0
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import {
|
|
5
|
+
forwardRef,
|
|
6
|
+
type KeyboardEvent,
|
|
7
|
+
useCallback,
|
|
8
|
+
useImperativeHandle,
|
|
9
|
+
useMemo,
|
|
10
|
+
useRef,
|
|
11
|
+
} from "react";
|
|
12
|
+
import styles from "@/packages/Components/DatePicker/DatePicker.module.scss";
|
|
13
|
+
import Text from "@/packages/Components/Text/Text";
|
|
14
|
+
|
|
15
|
+
type SingleSegment = "year" | "month" | "day";
|
|
16
|
+
type RangeSegment =
|
|
17
|
+
| "startYear"
|
|
18
|
+
| "startMonth"
|
|
19
|
+
| "startDay"
|
|
20
|
+
| "endYear"
|
|
21
|
+
| "endMonth"
|
|
22
|
+
| "endDay";
|
|
23
|
+
type Segment = SingleSegment | RangeSegment;
|
|
24
|
+
|
|
25
|
+
function padYear(n: number | null): string {
|
|
26
|
+
if (n === null) return "";
|
|
27
|
+
return String(n);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function padMonthDay(n: number | null): string {
|
|
31
|
+
if (n === null) return "";
|
|
32
|
+
return String(n);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getWidth(val: string, placeholder: string): string {
|
|
36
|
+
return `${(val || placeholder).length + 0.8}ch`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface DatePickerCoreRef {
|
|
40
|
+
focusFirst: () => void;
|
|
41
|
+
focusLast: () => void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface DatePickerCoreProps {
|
|
45
|
+
mode: "single" | "range";
|
|
46
|
+
year: number | null;
|
|
47
|
+
month: number | null;
|
|
48
|
+
day: number | null;
|
|
49
|
+
startYear: number | null;
|
|
50
|
+
startMonth: number | null;
|
|
51
|
+
startDay: number | null;
|
|
52
|
+
endYear: number | null;
|
|
53
|
+
endMonth: number | null;
|
|
54
|
+
endDay: number | null;
|
|
55
|
+
today: Date;
|
|
56
|
+
disabled?: boolean;
|
|
57
|
+
readOnly?: boolean;
|
|
58
|
+
onDateChange: (seg: Segment, val: number | null) => void;
|
|
59
|
+
onFocusPrev?: () => void;
|
|
60
|
+
onFocusNext?: () => void;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const DatePickerCore = forwardRef<DatePickerCoreRef, DatePickerCoreProps>(
|
|
64
|
+
(
|
|
65
|
+
{
|
|
66
|
+
mode,
|
|
67
|
+
year,
|
|
68
|
+
month,
|
|
69
|
+
day,
|
|
70
|
+
startYear,
|
|
71
|
+
startMonth,
|
|
72
|
+
startDay,
|
|
73
|
+
endYear,
|
|
74
|
+
endMonth,
|
|
75
|
+
endDay,
|
|
76
|
+
today,
|
|
77
|
+
disabled,
|
|
78
|
+
readOnly,
|
|
79
|
+
onDateChange,
|
|
80
|
+
onFocusPrev,
|
|
81
|
+
onFocusNext,
|
|
82
|
+
},
|
|
83
|
+
ref,
|
|
84
|
+
) => {
|
|
85
|
+
const bufRef = useRef("");
|
|
86
|
+
|
|
87
|
+
const yearRef = useRef<HTMLInputElement>(null);
|
|
88
|
+
const monthRef = useRef<HTMLInputElement>(null);
|
|
89
|
+
const dayRef = useRef<HTMLInputElement>(null);
|
|
90
|
+
const startYearRef = useRef<HTMLInputElement>(null);
|
|
91
|
+
const startMonthRef = useRef<HTMLInputElement>(null);
|
|
92
|
+
const startDayRef = useRef<HTMLInputElement>(null);
|
|
93
|
+
const endYearRef = useRef<HTMLInputElement>(null);
|
|
94
|
+
const endMonthRef = useRef<HTMLInputElement>(null);
|
|
95
|
+
const endDayRef = useRef<HTMLInputElement>(null);
|
|
96
|
+
|
|
97
|
+
const getSegmentRef = useCallback((seg: Segment) => {
|
|
98
|
+
switch (seg) {
|
|
99
|
+
case "year":
|
|
100
|
+
return yearRef;
|
|
101
|
+
case "month":
|
|
102
|
+
return monthRef;
|
|
103
|
+
case "day":
|
|
104
|
+
return dayRef;
|
|
105
|
+
case "startYear":
|
|
106
|
+
return startYearRef;
|
|
107
|
+
case "startMonth":
|
|
108
|
+
return startMonthRef;
|
|
109
|
+
case "startDay":
|
|
110
|
+
return startDayRef;
|
|
111
|
+
case "endYear":
|
|
112
|
+
return endYearRef;
|
|
113
|
+
case "endMonth":
|
|
114
|
+
return endMonthRef;
|
|
115
|
+
case "endDay":
|
|
116
|
+
return endDayRef;
|
|
117
|
+
}
|
|
118
|
+
}, []);
|
|
119
|
+
|
|
120
|
+
const order = useMemo<Segment[]>(() => {
|
|
121
|
+
return mode === "single"
|
|
122
|
+
? ["year", "month", "day"]
|
|
123
|
+
: [
|
|
124
|
+
"startYear",
|
|
125
|
+
"startMonth",
|
|
126
|
+
"startDay",
|
|
127
|
+
"endYear",
|
|
128
|
+
"endMonth",
|
|
129
|
+
"endDay",
|
|
130
|
+
];
|
|
131
|
+
}, [mode]);
|
|
132
|
+
|
|
133
|
+
useImperativeHandle(ref, () => ({
|
|
134
|
+
focusFirst: () => getSegmentRef(order[0]).current?.focus(),
|
|
135
|
+
focusLast: () => getSegmentRef(order[order.length - 1]).current?.focus(),
|
|
136
|
+
}));
|
|
137
|
+
|
|
138
|
+
const moveNext = useCallback(
|
|
139
|
+
(current: Segment) => {
|
|
140
|
+
const idx = order.indexOf(current);
|
|
141
|
+
if (idx < order.length - 1)
|
|
142
|
+
getSegmentRef(order[idx + 1]).current?.focus();
|
|
143
|
+
else onFocusNext?.();
|
|
144
|
+
},
|
|
145
|
+
[getSegmentRef, order, onFocusNext],
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
const movePrev = useCallback(
|
|
149
|
+
(current: Segment) => {
|
|
150
|
+
const idx = order.indexOf(current);
|
|
151
|
+
if (idx > 0) getSegmentRef(order[idx - 1]).current?.focus();
|
|
152
|
+
else onFocusPrev?.();
|
|
153
|
+
},
|
|
154
|
+
[getSegmentRef, order, onFocusPrev],
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
const focusAndSelect = useCallback(
|
|
158
|
+
(segment: Segment) => {
|
|
159
|
+
const target = getSegmentRef(segment).current;
|
|
160
|
+
if (!target) return;
|
|
161
|
+
requestAnimationFrame(() => {
|
|
162
|
+
target.focus();
|
|
163
|
+
if ("select" in target && typeof target.select === "function")
|
|
164
|
+
target.select();
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
[getSegmentRef],
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
const commitSegment = useCallback(
|
|
171
|
+
(seg: Segment, rawValue: string) => {
|
|
172
|
+
const isYear = seg.toLowerCase().includes("year");
|
|
173
|
+
const isMonth = seg.toLowerCase().includes("month");
|
|
174
|
+
const isDay = seg.toLowerCase().includes("day");
|
|
175
|
+
|
|
176
|
+
const maxLen = isYear ? 4 : 2;
|
|
177
|
+
const digits = rawValue.replace(/\D/g, "").slice(-maxLen);
|
|
178
|
+
|
|
179
|
+
let max = 9999;
|
|
180
|
+
let min = 1000;
|
|
181
|
+
if (isMonth) {
|
|
182
|
+
max = 12;
|
|
183
|
+
min = 1;
|
|
184
|
+
} else if (isDay) {
|
|
185
|
+
let y = today.getFullYear();
|
|
186
|
+
let m = today.getMonth() + 1;
|
|
187
|
+
if (seg === "day") {
|
|
188
|
+
y = year ?? y;
|
|
189
|
+
m = month ?? m;
|
|
190
|
+
} else if (seg === "startDay") {
|
|
191
|
+
y = startYear ?? y;
|
|
192
|
+
m = startMonth ?? m;
|
|
193
|
+
} else if (seg === "endDay") {
|
|
194
|
+
y = endYear ?? y;
|
|
195
|
+
m = endMonth ?? m;
|
|
196
|
+
}
|
|
197
|
+
max = new Date(y, m, 0).getDate();
|
|
198
|
+
min = 1;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (!digits) {
|
|
202
|
+
onDateChange(seg, null);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const parsed = Number(digits);
|
|
207
|
+
let next = parsed;
|
|
208
|
+
if (isYear) {
|
|
209
|
+
if (digits.length === 4)
|
|
210
|
+
next = Math.max(1000, Math.min(9999, parsed));
|
|
211
|
+
} else {
|
|
212
|
+
next = Math.max(min, Math.min(max, parsed));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
onDateChange(seg, next);
|
|
216
|
+
|
|
217
|
+
if (digits.length >= maxLen || (!isYear && parsed * 10 > max)) {
|
|
218
|
+
moveNext(seg);
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
[
|
|
222
|
+
year,
|
|
223
|
+
month,
|
|
224
|
+
startYear,
|
|
225
|
+
startMonth,
|
|
226
|
+
endYear,
|
|
227
|
+
endMonth,
|
|
228
|
+
today,
|
|
229
|
+
onDateChange,
|
|
230
|
+
moveNext,
|
|
231
|
+
],
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
const handleBlur = (seg: Segment) => {
|
|
235
|
+
if (bufRef.current) {
|
|
236
|
+
const val = bufRef.current;
|
|
237
|
+
bufRef.current = "";
|
|
238
|
+
commitSegment(seg, val);
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const handleKeyDown = (
|
|
243
|
+
e: KeyboardEvent<HTMLInputElement>,
|
|
244
|
+
seg: Segment,
|
|
245
|
+
) => {
|
|
246
|
+
if (e.key === "Tab") return;
|
|
247
|
+
|
|
248
|
+
const isYear = seg.toLowerCase().includes("year");
|
|
249
|
+
const isMonth = seg.toLowerCase().includes("month");
|
|
250
|
+
const isDay = seg.toLowerCase().includes("day");
|
|
251
|
+
|
|
252
|
+
let max = 9999;
|
|
253
|
+
let min = 1000;
|
|
254
|
+
if (isMonth) {
|
|
255
|
+
max = 12;
|
|
256
|
+
min = 1;
|
|
257
|
+
} else if (isDay) {
|
|
258
|
+
let y = today.getFullYear(),
|
|
259
|
+
m = today.getMonth() + 1;
|
|
260
|
+
if (seg === "day") {
|
|
261
|
+
y = year ?? y;
|
|
262
|
+
m = month ?? m;
|
|
263
|
+
} else if (seg === "startDay") {
|
|
264
|
+
y = startYear ?? y;
|
|
265
|
+
m = startMonth ?? m;
|
|
266
|
+
} else if (seg === "endDay") {
|
|
267
|
+
y = endYear ?? y;
|
|
268
|
+
m = endMonth ?? m;
|
|
269
|
+
}
|
|
270
|
+
max = new Date(y, m, 0).getDate();
|
|
271
|
+
min = 1;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const current = (() => {
|
|
275
|
+
switch (seg) {
|
|
276
|
+
case "year":
|
|
277
|
+
return year;
|
|
278
|
+
case "month":
|
|
279
|
+
return month;
|
|
280
|
+
case "day":
|
|
281
|
+
return day;
|
|
282
|
+
case "startYear":
|
|
283
|
+
return startYear;
|
|
284
|
+
case "startMonth":
|
|
285
|
+
return startMonth;
|
|
286
|
+
case "startDay":
|
|
287
|
+
return startDay;
|
|
288
|
+
case "endYear":
|
|
289
|
+
return endYear;
|
|
290
|
+
case "endMonth":
|
|
291
|
+
return endMonth;
|
|
292
|
+
case "endDay":
|
|
293
|
+
return endDay;
|
|
294
|
+
}
|
|
295
|
+
})();
|
|
296
|
+
const base = current ?? (isYear ? today.getFullYear() : min);
|
|
297
|
+
|
|
298
|
+
if (e.key === "ArrowUp") {
|
|
299
|
+
e.preventDefault();
|
|
300
|
+
onDateChange(seg, base + 1 > max ? min : base + 1);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (e.key === "ArrowDown") {
|
|
305
|
+
e.preventDefault();
|
|
306
|
+
onDateChange(seg, base - 1 < min ? max : base - 1);
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (e.key === "ArrowRight") {
|
|
311
|
+
e.preventDefault();
|
|
312
|
+
moveNext(seg);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (e.key === "ArrowLeft") {
|
|
317
|
+
e.preventDefault();
|
|
318
|
+
movePrev(seg);
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (e.key === "Backspace") {
|
|
323
|
+
if (!e.currentTarget.value) {
|
|
324
|
+
e.preventDefault();
|
|
325
|
+
movePrev(seg);
|
|
326
|
+
}
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (!/^\d$/.test(e.key)) return;
|
|
331
|
+
|
|
332
|
+
e.preventDefault();
|
|
333
|
+
bufRef.current += e.key;
|
|
334
|
+
const attempt = Number(bufRef.current);
|
|
335
|
+
const maxLen = isYear ? 4 : 2;
|
|
336
|
+
|
|
337
|
+
if (bufRef.current.length >= maxLen || (!isYear && attempt * 10 > max)) {
|
|
338
|
+
const val = bufRef.current;
|
|
339
|
+
bufRef.current = "";
|
|
340
|
+
commitSegment(seg, val);
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
onDateChange(seg, attempt);
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
const isDisabledOrReadOnly = !!(disabled || readOnly);
|
|
348
|
+
|
|
349
|
+
if (mode === "single") {
|
|
350
|
+
return (
|
|
351
|
+
<>
|
|
352
|
+
<input
|
|
353
|
+
ref={yearRef}
|
|
354
|
+
type="text"
|
|
355
|
+
inputMode="numeric"
|
|
356
|
+
pattern="[0-9]*"
|
|
357
|
+
autoComplete="off"
|
|
358
|
+
maxLength={4}
|
|
359
|
+
placeholder="YYYY"
|
|
360
|
+
className={clsx(styles.Field, styles.FieldYear, "Subheadline")}
|
|
361
|
+
style={{ width: getWidth(padYear(year), "YYYY") }}
|
|
362
|
+
value={padYear(year)}
|
|
363
|
+
readOnly={isDisabledOrReadOnly}
|
|
364
|
+
disabled={isDisabledOrReadOnly}
|
|
365
|
+
onFocus={() => {
|
|
366
|
+
bufRef.current = "";
|
|
367
|
+
focusAndSelect("year");
|
|
368
|
+
}}
|
|
369
|
+
onClick={() => focusAndSelect("year")}
|
|
370
|
+
onChange={(e) => commitSegment("year", e.target.value)}
|
|
371
|
+
onKeyDown={(e) => handleKeyDown(e, "year")}
|
|
372
|
+
onBlur={() => handleBlur("year")}
|
|
373
|
+
/>
|
|
374
|
+
<Text type="Subheadline" verticalTrim className={styles.Sep}>
|
|
375
|
+
.
|
|
376
|
+
</Text>
|
|
377
|
+
<input
|
|
378
|
+
ref={monthRef}
|
|
379
|
+
type="text"
|
|
380
|
+
inputMode="numeric"
|
|
381
|
+
pattern="[0-9]*"
|
|
382
|
+
autoComplete="off"
|
|
383
|
+
maxLength={2}
|
|
384
|
+
placeholder="MM"
|
|
385
|
+
className={clsx(styles.Field, styles.FieldMonth, "Subheadline")}
|
|
386
|
+
style={{ width: getWidth(padMonthDay(month), "MM") }}
|
|
387
|
+
value={padMonthDay(month)}
|
|
388
|
+
readOnly={isDisabledOrReadOnly}
|
|
389
|
+
disabled={isDisabledOrReadOnly}
|
|
390
|
+
onFocus={() => {
|
|
391
|
+
bufRef.current = "";
|
|
392
|
+
focusAndSelect("month");
|
|
393
|
+
}}
|
|
394
|
+
onClick={() => focusAndSelect("month")}
|
|
395
|
+
onChange={(e) => commitSegment("month", e.target.value)}
|
|
396
|
+
onKeyDown={(e) => handleKeyDown(e, "month")}
|
|
397
|
+
onBlur={() => handleBlur("month")}
|
|
398
|
+
/>
|
|
399
|
+
<Text type="Subheadline" verticalTrim className={styles.Sep}>
|
|
400
|
+
.
|
|
401
|
+
</Text>
|
|
402
|
+
<input
|
|
403
|
+
ref={dayRef}
|
|
404
|
+
type="text"
|
|
405
|
+
inputMode="numeric"
|
|
406
|
+
pattern="[0-9]*"
|
|
407
|
+
autoComplete="off"
|
|
408
|
+
maxLength={2}
|
|
409
|
+
placeholder="DD"
|
|
410
|
+
className={clsx(styles.Field, styles.FieldDay, "Subheadline")}
|
|
411
|
+
style={{ width: getWidth(padMonthDay(day), "DD") }}
|
|
412
|
+
value={padMonthDay(day)}
|
|
413
|
+
readOnly={isDisabledOrReadOnly}
|
|
414
|
+
disabled={isDisabledOrReadOnly}
|
|
415
|
+
onFocus={() => {
|
|
416
|
+
bufRef.current = "";
|
|
417
|
+
focusAndSelect("day");
|
|
418
|
+
}}
|
|
419
|
+
onClick={() => focusAndSelect("day")}
|
|
420
|
+
onChange={(e) => commitSegment("day", e.target.value)}
|
|
421
|
+
onKeyDown={(e) => handleKeyDown(e, "day")}
|
|
422
|
+
onBlur={() => handleBlur("day")}
|
|
423
|
+
/>
|
|
424
|
+
</>
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
return (
|
|
429
|
+
<>
|
|
430
|
+
<input
|
|
431
|
+
ref={startYearRef}
|
|
432
|
+
type="text"
|
|
433
|
+
inputMode="numeric"
|
|
434
|
+
pattern="[0-9]*"
|
|
435
|
+
autoComplete="off"
|
|
436
|
+
maxLength={4}
|
|
437
|
+
placeholder="YYYY"
|
|
438
|
+
className={clsx(styles.Field, styles.FieldYear, "Subheadline")}
|
|
439
|
+
style={{ width: getWidth(padYear(startYear), "YYYY") }}
|
|
440
|
+
value={padYear(startYear)}
|
|
441
|
+
readOnly={isDisabledOrReadOnly}
|
|
442
|
+
disabled={isDisabledOrReadOnly}
|
|
443
|
+
onFocus={() => {
|
|
444
|
+
bufRef.current = "";
|
|
445
|
+
focusAndSelect("startYear");
|
|
446
|
+
}}
|
|
447
|
+
onClick={() => focusAndSelect("startYear")}
|
|
448
|
+
onChange={(e) => commitSegment("startYear", e.target.value)}
|
|
449
|
+
onKeyDown={(e) => handleKeyDown(e, "startYear")}
|
|
450
|
+
onBlur={() => handleBlur("startYear")}
|
|
451
|
+
/>
|
|
452
|
+
<Text type="Subheadline" verticalTrim className={styles.Sep}>
|
|
453
|
+
.
|
|
454
|
+
</Text>
|
|
455
|
+
<input
|
|
456
|
+
ref={startMonthRef}
|
|
457
|
+
type="text"
|
|
458
|
+
inputMode="numeric"
|
|
459
|
+
pattern="[0-9]*"
|
|
460
|
+
autoComplete="off"
|
|
461
|
+
maxLength={2}
|
|
462
|
+
placeholder="MM"
|
|
463
|
+
className={clsx(styles.Field, styles.FieldMonth, "Subheadline")}
|
|
464
|
+
style={{ width: getWidth(padMonthDay(startMonth), "MM") }}
|
|
465
|
+
value={padMonthDay(startMonth)}
|
|
466
|
+
readOnly={isDisabledOrReadOnly}
|
|
467
|
+
disabled={isDisabledOrReadOnly}
|
|
468
|
+
onFocus={() => {
|
|
469
|
+
bufRef.current = "";
|
|
470
|
+
focusAndSelect("startMonth");
|
|
471
|
+
}}
|
|
472
|
+
onClick={() => focusAndSelect("startMonth")}
|
|
473
|
+
onChange={(e) => commitSegment("startMonth", e.target.value)}
|
|
474
|
+
onKeyDown={(e) => handleKeyDown(e, "startMonth")}
|
|
475
|
+
onBlur={() => handleBlur("startMonth")}
|
|
476
|
+
/>
|
|
477
|
+
<Text type="Subheadline" verticalTrim className={styles.Sep}>
|
|
478
|
+
.
|
|
479
|
+
</Text>
|
|
480
|
+
<input
|
|
481
|
+
ref={startDayRef}
|
|
482
|
+
type="text"
|
|
483
|
+
inputMode="numeric"
|
|
484
|
+
pattern="[0-9]*"
|
|
485
|
+
autoComplete="off"
|
|
486
|
+
maxLength={2}
|
|
487
|
+
placeholder="DD"
|
|
488
|
+
className={clsx(styles.Field, styles.FieldDay, "Subheadline")}
|
|
489
|
+
style={{ width: getWidth(padMonthDay(startDay), "DD") }}
|
|
490
|
+
value={padMonthDay(startDay)}
|
|
491
|
+
readOnly={isDisabledOrReadOnly}
|
|
492
|
+
disabled={isDisabledOrReadOnly}
|
|
493
|
+
onFocus={() => {
|
|
494
|
+
bufRef.current = "";
|
|
495
|
+
focusAndSelect("startDay");
|
|
496
|
+
}}
|
|
497
|
+
onClick={() => focusAndSelect("startDay")}
|
|
498
|
+
onChange={(e) => commitSegment("startDay", e.target.value)}
|
|
499
|
+
onKeyDown={(e) => handleKeyDown(e, "startDay")}
|
|
500
|
+
onBlur={() => handleBlur("startDay")}
|
|
501
|
+
/>
|
|
502
|
+
<Text type="Subheadline" verticalTrim className={styles.RangeSep}>
|
|
503
|
+
–
|
|
504
|
+
</Text>
|
|
505
|
+
<input
|
|
506
|
+
ref={endYearRef}
|
|
507
|
+
type="text"
|
|
508
|
+
inputMode="numeric"
|
|
509
|
+
pattern="[0-9]*"
|
|
510
|
+
autoComplete="off"
|
|
511
|
+
maxLength={4}
|
|
512
|
+
placeholder="YYYY"
|
|
513
|
+
className={clsx(styles.Field, styles.FieldYear, "Subheadline")}
|
|
514
|
+
style={{ width: getWidth(padYear(endYear), "YYYY") }}
|
|
515
|
+
value={padYear(endYear)}
|
|
516
|
+
readOnly={isDisabledOrReadOnly}
|
|
517
|
+
disabled={isDisabledOrReadOnly}
|
|
518
|
+
onFocus={() => {
|
|
519
|
+
bufRef.current = "";
|
|
520
|
+
focusAndSelect("endYear");
|
|
521
|
+
}}
|
|
522
|
+
onClick={() => focusAndSelect("endYear")}
|
|
523
|
+
onChange={(e) => commitSegment("endYear", e.target.value)}
|
|
524
|
+
onKeyDown={(e) => handleKeyDown(e, "endYear")}
|
|
525
|
+
onBlur={() => handleBlur("endYear")}
|
|
526
|
+
/>
|
|
527
|
+
<Text type="Subheadline" verticalTrim className={styles.Sep}>
|
|
528
|
+
.
|
|
529
|
+
</Text>
|
|
530
|
+
<input
|
|
531
|
+
ref={endMonthRef}
|
|
532
|
+
type="text"
|
|
533
|
+
inputMode="numeric"
|
|
534
|
+
pattern="[0-9]*"
|
|
535
|
+
autoComplete="off"
|
|
536
|
+
maxLength={2}
|
|
537
|
+
placeholder="MM"
|
|
538
|
+
className={clsx(styles.Field, styles.FieldMonth, "Subheadline")}
|
|
539
|
+
style={{ width: getWidth(padMonthDay(endMonth), "MM") }}
|
|
540
|
+
value={padMonthDay(endMonth)}
|
|
541
|
+
readOnly={isDisabledOrReadOnly}
|
|
542
|
+
disabled={isDisabledOrReadOnly}
|
|
543
|
+
onFocus={() => {
|
|
544
|
+
bufRef.current = "";
|
|
545
|
+
focusAndSelect("endMonth");
|
|
546
|
+
}}
|
|
547
|
+
onClick={() => focusAndSelect("endMonth")}
|
|
548
|
+
onChange={(e) => commitSegment("endMonth", e.target.value)}
|
|
549
|
+
onKeyDown={(e) => handleKeyDown(e, "endMonth")}
|
|
550
|
+
onBlur={() => handleBlur("endMonth")}
|
|
551
|
+
/>
|
|
552
|
+
<Text type="Subheadline" verticalTrim className={styles.Sep}>
|
|
553
|
+
.
|
|
554
|
+
</Text>
|
|
555
|
+
<input
|
|
556
|
+
ref={endDayRef}
|
|
557
|
+
type="text"
|
|
558
|
+
inputMode="numeric"
|
|
559
|
+
pattern="[0-9]*"
|
|
560
|
+
autoComplete="off"
|
|
561
|
+
maxLength={2}
|
|
562
|
+
placeholder="DD"
|
|
563
|
+
className={clsx(styles.Field, styles.FieldDay, "Subheadline")}
|
|
564
|
+
style={{ width: getWidth(padMonthDay(endDay), "DD") }}
|
|
565
|
+
value={padMonthDay(endDay)}
|
|
566
|
+
readOnly={isDisabledOrReadOnly}
|
|
567
|
+
disabled={isDisabledOrReadOnly}
|
|
568
|
+
onFocus={() => {
|
|
569
|
+
bufRef.current = "";
|
|
570
|
+
focusAndSelect("endDay");
|
|
571
|
+
}}
|
|
572
|
+
onClick={() => focusAndSelect("endDay")}
|
|
573
|
+
onChange={(e) => commitSegment("endDay", e.target.value)}
|
|
574
|
+
onKeyDown={(e) => handleKeyDown(e, "endDay")}
|
|
575
|
+
onBlur={() => handleBlur("endDay")}
|
|
576
|
+
/>
|
|
577
|
+
</>
|
|
578
|
+
);
|
|
579
|
+
},
|
|
580
|
+
);
|
|
581
|
+
|
|
582
|
+
export default DatePickerCore;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
.Field {
|
|
2
|
+
background: transparent;
|
|
3
|
+
border: 0;
|
|
4
|
+
outline: 0 !important;
|
|
5
|
+
padding: 0;
|
|
6
|
+
caret-color: transparent;
|
|
7
|
+
cursor: default;
|
|
8
|
+
|
|
9
|
+
&:focus {
|
|
10
|
+
background: var(--color-base-3);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.Sep {
|
|
15
|
+
opacity: 0.4;
|
|
16
|
+
user-select: none;
|
|
17
|
+
pointer-events: none;
|
|
18
|
+
margin: 0 0.1rem;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.RangeSep {
|
|
22
|
+
margin: 0 0.4rem;
|
|
23
|
+
opacity: 0.6;
|
|
24
|
+
user-select: none;
|
|
25
|
+
pointer-events: none;
|
|
26
|
+
}
|