@tide-design/components 0.25.0 → 0.26.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/dist/DatePicker/DatePicker.d.ts +43 -0
- package/dist/DatePicker/DatePicker.js +20 -0
- package/dist/DatePicker/components/Calendar.js +152 -0
- package/dist/DatePicker/components/CalendarCell.js +33 -0
- package/dist/DatePicker/components/CalendarGrid.js +28 -0
- package/dist/DatePicker/components/CalendarMonthView.js +82 -0
- package/dist/DatePicker/components/CalendarNavButton.js +24 -0
- package/dist/DatePicker/components/CalendarPickerCell.js +39 -0
- package/dist/DatePicker/components/CalendarPickerGrid.js +46 -0
- package/dist/DatePicker/components/CalendarTitle.js +33 -0
- package/dist/DatePicker/components/CalendarYearView.js +64 -0
- package/dist/DatePicker/components/DatePickerGroup.js +121 -0
- package/dist/DatePicker/components/DatePickerPopover.js +18 -0
- package/dist/DatePicker/components/DatePickerPopoverInner.js +57 -0
- package/dist/DatePicker/components/DateSegment.js +26 -0
- package/dist/DatePicker/components/DateSegments.js +62 -0
- package/dist/DatePicker/constants/calendarClass.js +41 -0
- package/dist/DatePicker/constants/calendarPicker.js +4 -0
- package/dist/DatePicker/constants/dateFormat.js +5 -0
- package/dist/DatePicker/constants/datePickerClass.js +27 -0
- package/dist/DatePicker/hooks/useOpenOnFocus.js +69 -0
- package/dist/DatePicker/hooks/useSegmentEntry.js +53 -0
- package/dist/DatePicker/index.d.ts +2 -0
- package/dist/DatePicker/libs/calendarPicker.js +64 -0
- package/dist/DatePicker/libs/dateFormat.js +45 -0
- package/dist/DatePicker/libs/isoDate.js +23 -0
- package/dist/DatePicker/libs/segmentEntry.js +19 -0
- package/dist/DatePicker/libs/warnOnce.js +17 -0
- package/dist/Field/Field.d.ts +1 -1
- package/dist/Field/Field.js +4 -12
- package/dist/Field/components/FieldLabelledControl.js +40 -0
- package/dist/_internal/components/OverlayPortal.js +2 -1
- package/dist/_internal/constants/inputClass.js +6 -1
- package/dist/_internal/hooks/useFieldGroupControl.js +30 -0
- package/dist/_internal/hooks/usePopoverOverlay.js +3 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -1
- package/package.json +4 -3
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { InputSize } from "../_internal/constants/inputClass.js";
|
|
2
|
+
import { ComponentProps, ReactElement } from "react";
|
|
3
|
+
export interface DatePickerOwnProps {
|
|
4
|
+
/** 고른 날(제어). ISO `"YYYY-MM-DD"`. `null`이면 빈 값이다. 주면 `onValueChange`로 바꾼다. */
|
|
5
|
+
value?: string | null;
|
|
6
|
+
/** 처음 날(비제어). ISO `"YYYY-MM-DD"`. 폼을 reset하면 이 값으로 돌아간다. */
|
|
7
|
+
defaultValue?: string;
|
|
8
|
+
/** 연·월·일이 모두 차거나 달력에서 고르면 ISO 문자열로, 모두 지우면 `null`로 부른다. */
|
|
9
|
+
onValueChange?: (value: string | null) => void;
|
|
10
|
+
/** 달력이 열리거나 닫힐 때 새 상태로 부른다. */
|
|
11
|
+
onOpenChange?: (open: boolean) => void;
|
|
12
|
+
/** 폼 제출 이름. 숨은 input에 붙어 `format`과 무관하게 ISO `"YYYY-MM-DD"`로 제출된다. */
|
|
13
|
+
name?: string;
|
|
14
|
+
/** 숨은 input이 속할 `<form>`의 id. 폼 밖에 둘 때 쓴다. */
|
|
15
|
+
form?: string;
|
|
16
|
+
/** 높이 `sm` 32px, `md` 40px, `lg` 48px. 같은 size의 Input·Select와 같다. 기본값은 `md`다. */
|
|
17
|
+
size?: InputSize;
|
|
18
|
+
/** 오류 상태. 입력 칸에 `data-invalid`, 각 칸에 `aria-invalid`가 붙는다. Field 값보다 여기 준 값이 이긴다. */
|
|
19
|
+
invalid?: boolean;
|
|
20
|
+
/** 입력을 막고 달력을 열지 않는다. 폼에 제출되지 않는다. Field 값보다 여기 준 값이 이긴다. */
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
/** 값을 바꿀 수 없다. 칸에 포커스는 가고 폼에 제출된다. 달력은 열지 않는다. */
|
|
23
|
+
readOnly?: boolean;
|
|
24
|
+
/** 필수. 비운 채 제출하면 막고 첫 칸으로 포커스를 옮긴다(브라우저 말풍선 없음, 메시지는 Field `error`). */
|
|
25
|
+
required?: boolean;
|
|
26
|
+
/** 고를 수 있는 첫날(ISO). 밖의 날은 달력에서 막히고 입력하면 오류 상태가 된다. */
|
|
27
|
+
min?: string;
|
|
28
|
+
/** 고를 수 있는 마지막 날(ISO). */
|
|
29
|
+
max?: string;
|
|
30
|
+
/** `true`를 돌려준 날은 달력에서 고를 수 없다(포커스는 간다). 인자는 ISO 문자열이다. */
|
|
31
|
+
isDateUnavailable?: (date: string) => boolean;
|
|
32
|
+
/** 달력 제목·요일·주 시작과 스크린리더 문구의 언어. 기본값 `"ko-KR"`. 입력 칸 순서는 `format`이 정한다. */
|
|
33
|
+
locale?: string;
|
|
34
|
+
/** 표시 형식. 토큰 `yyyy`·`MM`·`dd`(대소문자 구분)와 구분자. 기본값 `"yyyy-MM-dd"`. 값과 제출 형식은 바꾸지 않는다. */
|
|
35
|
+
format?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface DatePickerProps extends DatePickerOwnProps, Omit<ComponentProps<"div">, keyof DatePickerOwnProps | "onChange" | "children"> {}
|
|
38
|
+
/**
|
|
39
|
+
* 날짜 하나를 고르는 입력. 연·월·일 칸에 치거나, 칸에 포커스하면 함께 열리는 Popover 달력에서 고른다.
|
|
40
|
+
* 값은 ISO `"YYYY-MM-DD"` 문자열이다. Field 안에 두면 label·설명·오류가 연결된다(`group` 불필요).
|
|
41
|
+
* Tide props: `value`, `defaultValue`, `onValueChange`, `onOpenChange`, `name`, `form`, `size`, `invalid`, `disabled`, `readOnly`, `required`, `min`, `max`, `isDateUnavailable`, `locale`, `format` ({@link DatePickerOwnProps}). 나머지는 루트 group `<div>` 속성.
|
|
42
|
+
*/
|
|
43
|
+
export declare function DatePicker({ locale, ...props }: DatePickerProps): ReactElement;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { DatePickerGroup } from "./components/DatePickerGroup.js";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
import { I18nProvider } from "react-aria";
|
|
6
|
+
|
|
7
|
+
// src/DatePicker/DatePicker.tsx
|
|
8
|
+
/**
|
|
9
|
+
* 날짜 하나를 고르는 입력. 연·월·일 칸에 치거나, 칸에 포커스하면 함께 열리는 Popover 달력에서 고른다.
|
|
10
|
+
* 값은 ISO `"YYYY-MM-DD"` 문자열이다. Field 안에 두면 label·설명·오류가 연결된다(`group` 불필요).
|
|
11
|
+
* Tide props: `value`, `defaultValue`, `onValueChange`, `onOpenChange`, `name`, `form`, `size`, `invalid`, `disabled`, `readOnly`, `required`, `min`, `max`, `isDateUnavailable`, `locale`, `format` ({@link DatePickerOwnProps}). 나머지는 루트 group `<div>` 속성.
|
|
12
|
+
*/
|
|
13
|
+
function DatePicker({ locale = "ko-KR", ...props }) {
|
|
14
|
+
return /* @__PURE__ */ jsx(I18nProvider, {
|
|
15
|
+
locale,
|
|
16
|
+
children: /* @__PURE__ */ jsx(DatePickerGroup, { ...props })
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { DatePicker };
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { maxYear } from "../constants/calendarPicker.js";
|
|
4
|
+
import { calendarClass, calendarHeaderClass } from "../constants/calendarClass.js";
|
|
5
|
+
import { clampKey, fromMonthKey, monthKey, shiftYearMonth } from "../libs/calendarPicker.js";
|
|
6
|
+
import { parseIsoDate, toIsoDate } from "../libs/isoDate.js";
|
|
7
|
+
import { CalendarGrid } from "./CalendarGrid.js";
|
|
8
|
+
import { CalendarMonthView } from "./CalendarMonthView.js";
|
|
9
|
+
import { CalendarNavButton } from "./CalendarNavButton.js";
|
|
10
|
+
import { CalendarTitle } from "./CalendarTitle.js";
|
|
11
|
+
import { CalendarYearView } from "./CalendarYearView.js";
|
|
12
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { useMemo, useState } from "react";
|
|
14
|
+
import { ChevronLeftIcon, ChevronRightIcon } from "@tide-design/icons";
|
|
15
|
+
import { mergeProps, useCalendar, useLocale } from "react-aria";
|
|
16
|
+
import { useCalendarState } from "react-stately";
|
|
17
|
+
import { GregorianCalendar, toCalendarDate } from "@internationalized/date";
|
|
18
|
+
|
|
19
|
+
// src/DatePicker/components/Calendar.tsx
|
|
20
|
+
const createCalendar = () => new GregorianCalendar();
|
|
21
|
+
/** DatePicker Popover 안의 달력. 날짜 화면에서 제목의 연도·월을 누르면 연도·월 화면으로 바꾼다. */
|
|
22
|
+
function Calendar({ value, onValueChange, onPickerValueChange = onValueChange, min, max, isDateUnavailable, referenceDate, autoFocus = false, readOnly = false, disabled = false }) {
|
|
23
|
+
const { locale } = useLocale();
|
|
24
|
+
const selected = useMemo(() => parseIsoDate(value), [value]);
|
|
25
|
+
const minValue = useMemo(() => parseIsoDate(min), [min]);
|
|
26
|
+
const maxValue = useMemo(() => parseIsoDate(max), [max]);
|
|
27
|
+
const reference = useMemo(() => parseIsoDate(referenceDate), [referenceDate]);
|
|
28
|
+
const calendarProps = {
|
|
29
|
+
value: selected,
|
|
30
|
+
onChange: (date) => onValueChange(toIsoDate(toCalendarDate(date))),
|
|
31
|
+
minValue,
|
|
32
|
+
maxValue,
|
|
33
|
+
isDateUnavailable: isDateUnavailable ? (date) => isDateUnavailable(toIsoDate(toCalendarDate(date))) : void 0,
|
|
34
|
+
defaultFocusedValue: selected ? void 0 : reference,
|
|
35
|
+
autoFocus,
|
|
36
|
+
isReadOnly: readOnly,
|
|
37
|
+
isDisabled: disabled
|
|
38
|
+
};
|
|
39
|
+
const state = useCalendarState({
|
|
40
|
+
...calendarProps,
|
|
41
|
+
locale,
|
|
42
|
+
createCalendar
|
|
43
|
+
});
|
|
44
|
+
const [view, setView] = useState("day");
|
|
45
|
+
const [pickerKey, setPickerKey] = useState(0);
|
|
46
|
+
const [shownValue, setShownValue] = useState(value);
|
|
47
|
+
const [pickedValue, setPickedValue] = useState(null);
|
|
48
|
+
if (value !== shownValue) {
|
|
49
|
+
setShownValue(value);
|
|
50
|
+
setPickedValue(null);
|
|
51
|
+
if (value !== pickedValue) {
|
|
52
|
+
setView("day");
|
|
53
|
+
if (selected) state.setFocusedDate(selected);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const { calendarProps: rootProps, prevButtonProps, nextButtonProps } = useCalendar(calendarProps, state);
|
|
57
|
+
const yearMin = minValue?.year ?? 1;
|
|
58
|
+
const yearMax = maxValue?.year ?? 9999;
|
|
59
|
+
const monthMin = monthKey(minValue ?? {
|
|
60
|
+
year: 1,
|
|
61
|
+
month: 1
|
|
62
|
+
});
|
|
63
|
+
const monthMax = monthKey(maxValue ?? {
|
|
64
|
+
year: 9999,
|
|
65
|
+
month: 12
|
|
66
|
+
});
|
|
67
|
+
const openYearView = (year) => {
|
|
68
|
+
setPickerKey(clampKey(year, yearMin, yearMax));
|
|
69
|
+
setView("year");
|
|
70
|
+
};
|
|
71
|
+
const openMonthView = (shown) => {
|
|
72
|
+
setPickerKey(clampKey(monthKey(shown), monthMin, monthMax));
|
|
73
|
+
setView("month");
|
|
74
|
+
};
|
|
75
|
+
const showDays = () => {
|
|
76
|
+
state.setFocused(true);
|
|
77
|
+
setView("day");
|
|
78
|
+
};
|
|
79
|
+
/** 값이 있으면 해·달만 바꿔 반영하고 그 날을 돌려준다. 막힌 날이면 값은 그대로 둔다. */
|
|
80
|
+
const pickValue = (fields) => {
|
|
81
|
+
if (!selected || readOnly || disabled) return null;
|
|
82
|
+
const next = shiftYearMonth(selected, fields, {
|
|
83
|
+
min: minValue,
|
|
84
|
+
max: maxValue,
|
|
85
|
+
isUnavailable: calendarProps.isDateUnavailable
|
|
86
|
+
});
|
|
87
|
+
if (!next) return null;
|
|
88
|
+
state.setFocusedDate(next);
|
|
89
|
+
const iso = toIsoDate(next);
|
|
90
|
+
if (iso !== value) {
|
|
91
|
+
setPickedValue(iso);
|
|
92
|
+
onPickerValueChange(iso);
|
|
93
|
+
}
|
|
94
|
+
return next;
|
|
95
|
+
};
|
|
96
|
+
const showYear = (year) => {
|
|
97
|
+
openMonthView(pickValue({ year }) ?? {
|
|
98
|
+
year,
|
|
99
|
+
month: state.focusedDate.month
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
const showMonth = (key) => {
|
|
103
|
+
if (!pickValue(fromMonthKey(key))) state.setFocusedDate(state.focusedDate.set(fromMonthKey(key)));
|
|
104
|
+
showDays();
|
|
105
|
+
};
|
|
106
|
+
const onKeyDown = (event) => {
|
|
107
|
+
if (view === "day" || event.key !== "Escape") return;
|
|
108
|
+
event.preventDefault();
|
|
109
|
+
event.stopPropagation();
|
|
110
|
+
showDays();
|
|
111
|
+
};
|
|
112
|
+
return /* @__PURE__ */ jsx("div", {
|
|
113
|
+
...mergeProps(rootProps, { onKeyDown }),
|
|
114
|
+
className: calendarClass,
|
|
115
|
+
children: view === "year" ? /* @__PURE__ */ jsx(CalendarYearView, {
|
|
116
|
+
focusedYear: pickerKey,
|
|
117
|
+
onFocusedYearChange: setPickerKey,
|
|
118
|
+
selectedYear: selected?.year ?? null,
|
|
119
|
+
minYear: yearMin,
|
|
120
|
+
maxYear: yearMax,
|
|
121
|
+
onSelect: showYear
|
|
122
|
+
}) : view === "month" ? /* @__PURE__ */ jsx(CalendarMonthView, {
|
|
123
|
+
focusedKey: pickerKey,
|
|
124
|
+
onFocusedKeyChange: setPickerKey,
|
|
125
|
+
selectedKey: selected ? monthKey(selected) : null,
|
|
126
|
+
minKey: monthMin,
|
|
127
|
+
maxKey: monthMax,
|
|
128
|
+
timeZone: state.timeZone,
|
|
129
|
+
onSelect: showMonth,
|
|
130
|
+
onYearPress: () => openYearView(fromMonthKey(pickerKey).year)
|
|
131
|
+
}) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
|
|
132
|
+
className: calendarHeaderClass,
|
|
133
|
+
children: [
|
|
134
|
+
/* @__PURE__ */ jsx(CalendarNavButton, {
|
|
135
|
+
...prevButtonProps,
|
|
136
|
+
children: /* @__PURE__ */ jsx(ChevronLeftIcon, {})
|
|
137
|
+
}),
|
|
138
|
+
/* @__PURE__ */ jsx(CalendarTitle, {
|
|
139
|
+
state,
|
|
140
|
+
onYearPress: () => openYearView(state.focusedDate.year),
|
|
141
|
+
onMonthPress: () => openMonthView(state.focusedDate)
|
|
142
|
+
}),
|
|
143
|
+
/* @__PURE__ */ jsx(CalendarNavButton, {
|
|
144
|
+
...nextButtonProps,
|
|
145
|
+
children: /* @__PURE__ */ jsx(ChevronRightIcon, {})
|
|
146
|
+
})
|
|
147
|
+
]
|
|
148
|
+
}), /* @__PURE__ */ jsx(CalendarGrid, { state })] })
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export { Calendar };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { calendarCellClass, calendarDayClass } from "../constants/calendarClass.js";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
import { useRef } from "react";
|
|
6
|
+
import { useCalendarCell } from "react-aria";
|
|
7
|
+
import { isToday } from "@internationalized/date";
|
|
8
|
+
|
|
9
|
+
// src/DatePicker/components/CalendarCell.tsx
|
|
10
|
+
const withVisibleDate = (label, visible) => label === void 0 || label.split(/[\s,]+/).includes(visible) ? label : `${visible}, ${label}`;
|
|
11
|
+
/** 달력 grid의 칸 하나. 보이는 달 밖의 날짜는 숨긴다. */
|
|
12
|
+
function CalendarCell({ state, date }) {
|
|
13
|
+
const ref = useRef(null);
|
|
14
|
+
const { cellProps, buttonProps, isSelected, isDisabled, isUnavailable, isOutsideVisibleRange, formattedDate } = useCalendarCell({ date }, state, ref);
|
|
15
|
+
return /* @__PURE__ */ jsx("td", {
|
|
16
|
+
...cellProps,
|
|
17
|
+
className: calendarCellClass,
|
|
18
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
19
|
+
...buttonProps,
|
|
20
|
+
"aria-label": withVisibleDate(buttonProps["aria-label"], formattedDate),
|
|
21
|
+
ref,
|
|
22
|
+
hidden: isOutsideVisibleRange,
|
|
23
|
+
"data-selected": isSelected || void 0,
|
|
24
|
+
"data-today": isToday(date, state.timeZone) || void 0,
|
|
25
|
+
"data-unavailable": isUnavailable || void 0,
|
|
26
|
+
"data-disabled": isDisabled || void 0,
|
|
27
|
+
className: calendarDayClass,
|
|
28
|
+
children: formattedDate
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { CalendarCell };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { calendarCellClass, calendarGridClass, calendarWeekdayClass } from "../constants/calendarClass.js";
|
|
4
|
+
import { CalendarCell } from "./CalendarCell.js";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { useCalendarGrid } from "react-aria";
|
|
7
|
+
|
|
8
|
+
// src/DatePicker/components/CalendarGrid.tsx
|
|
9
|
+
/** 한 달 날짜 표. 주 시작 요일은 locale이 정한다(`ko-KR-u-fw-mon`이면 월요일). */
|
|
10
|
+
function CalendarGrid({ state }) {
|
|
11
|
+
const { gridProps, headerProps, weekDays, weeksInMonth } = useCalendarGrid({}, state);
|
|
12
|
+
return /* @__PURE__ */ jsxs("table", {
|
|
13
|
+
...gridProps,
|
|
14
|
+
className: calendarGridClass,
|
|
15
|
+
children: [/* @__PURE__ */ jsx("thead", {
|
|
16
|
+
...headerProps,
|
|
17
|
+
children: /* @__PURE__ */ jsx("tr", { children: weekDays.map((day, index) => /* @__PURE__ */ jsx("th", {
|
|
18
|
+
className: calendarWeekdayClass,
|
|
19
|
+
children: day
|
|
20
|
+
}, index)) })
|
|
21
|
+
}), /* @__PURE__ */ jsx("tbody", { children: Array.from({ length: weeksInMonth }, (_, weekIndex) => /* @__PURE__ */ jsx("tr", { children: state.getDatesInWeek(weekIndex).map((date, index) => date ? /* @__PURE__ */ jsx(CalendarCell, {
|
|
22
|
+
state,
|
|
23
|
+
date
|
|
24
|
+
}, index) : /* @__PURE__ */ jsx("td", { className: calendarCellClass }, index)) }, weekIndex)) })]
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { CalendarGrid };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Button } from "../../Button/Button.js";
|
|
4
|
+
import { calendarHeaderClass, calendarTitleButtonClass } from "../constants/calendarClass.js";
|
|
5
|
+
import { clampKey, fromMonthKey, monthKey } from "../libs/calendarPicker.js";
|
|
6
|
+
import { CalendarNavButton } from "./CalendarNavButton.js";
|
|
7
|
+
import { CalendarPickerGrid } from "./CalendarPickerGrid.js";
|
|
8
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { ChevronsLeftIcon, ChevronsRightIcon } from "@tide-design/icons";
|
|
10
|
+
import { useDateFormatter } from "react-aria";
|
|
11
|
+
import { CalendarDate } from "@internationalized/date";
|
|
12
|
+
|
|
13
|
+
// src/DatePicker/components/CalendarMonthView.tsx
|
|
14
|
+
/** 월 화면. 한 해의 12달을 3열 4줄로 보인다. 제목(해)을 누르면 연도 화면으로 간다. */
|
|
15
|
+
function CalendarMonthView({ focusedKey, onFocusedKeyChange, selectedKey, minKey, maxKey, timeZone, onSelect, onYearPress }) {
|
|
16
|
+
const monthFormatter = useDateFormatter({
|
|
17
|
+
month: "short",
|
|
18
|
+
timeZone
|
|
19
|
+
});
|
|
20
|
+
const yearFormatter = useDateFormatter({
|
|
21
|
+
year: "numeric",
|
|
22
|
+
timeZone
|
|
23
|
+
});
|
|
24
|
+
const { year } = fromMonthKey(focusedKey);
|
|
25
|
+
const start = monthKey({
|
|
26
|
+
year,
|
|
27
|
+
month: 1
|
|
28
|
+
});
|
|
29
|
+
const title = yearFormatter.format(new CalendarDate(year, 1, 1).toDate(timeZone));
|
|
30
|
+
const items = Array.from({ length: 12 }, (_, index) => ({
|
|
31
|
+
key: start + index,
|
|
32
|
+
label: monthFormatter.format(new CalendarDate(year, index + 1, 1).toDate(timeZone)),
|
|
33
|
+
isOutside: false,
|
|
34
|
+
isDisabled: start + index < minKey || start + index > maxKey,
|
|
35
|
+
isSelected: start + index === selectedKey
|
|
36
|
+
}));
|
|
37
|
+
const moveYear = (offset) => onFocusedKeyChange(clampKey(focusedKey + offset, minKey, maxKey));
|
|
38
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
|
|
39
|
+
className: calendarHeaderClass,
|
|
40
|
+
children: [
|
|
41
|
+
/* @__PURE__ */ jsx(CalendarNavButton, {
|
|
42
|
+
"aria-label": "이전 해",
|
|
43
|
+
isDisabled: start - 1 < minKey,
|
|
44
|
+
onPress: () => moveYear(-12),
|
|
45
|
+
children: /* @__PURE__ */ jsx(ChevronsLeftIcon, {})
|
|
46
|
+
}),
|
|
47
|
+
/* @__PURE__ */ jsx("h2", {
|
|
48
|
+
"aria-live": "polite",
|
|
49
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
50
|
+
variant: "ghost",
|
|
51
|
+
color: "neutral",
|
|
52
|
+
size: "sm",
|
|
53
|
+
noPressScale: true,
|
|
54
|
+
className: calendarTitleButtonClass,
|
|
55
|
+
"aria-label": `${title}, 연도 고르기`,
|
|
56
|
+
onClick: onYearPress,
|
|
57
|
+
children: title
|
|
58
|
+
})
|
|
59
|
+
}),
|
|
60
|
+
/* @__PURE__ */ jsx(CalendarNavButton, {
|
|
61
|
+
"aria-label": "다음 해",
|
|
62
|
+
isDisabled: start + 12 > maxKey,
|
|
63
|
+
onPress: () => moveYear(12),
|
|
64
|
+
children: /* @__PURE__ */ jsx(ChevronsRightIcon, {})
|
|
65
|
+
})
|
|
66
|
+
]
|
|
67
|
+
}), /* @__PURE__ */ jsx(CalendarPickerGrid, {
|
|
68
|
+
"aria-label": `월, ${title}`,
|
|
69
|
+
items,
|
|
70
|
+
focusedKey,
|
|
71
|
+
onFocusedKeyChange,
|
|
72
|
+
onSelect,
|
|
73
|
+
range: {
|
|
74
|
+
blockStart: start,
|
|
75
|
+
page: 12,
|
|
76
|
+
min: minKey,
|
|
77
|
+
max: maxKey
|
|
78
|
+
}
|
|
79
|
+
})] });
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { CalendarMonthView };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { IconButton } from "../../IconButton/IconButton.js";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
import { useRef } from "react";
|
|
6
|
+
import { useButton } from "react-aria";
|
|
7
|
+
|
|
8
|
+
// src/DatePicker/components/CalendarNavButton.tsx
|
|
9
|
+
/** 달력 머리의 이전·다음 버튼 */
|
|
10
|
+
function CalendarNavButton({ children, ...props }) {
|
|
11
|
+
const ref = useRef(null);
|
|
12
|
+
const { buttonProps } = useButton(props, ref);
|
|
13
|
+
return /* @__PURE__ */ jsx(IconButton, {
|
|
14
|
+
...buttonProps,
|
|
15
|
+
ref,
|
|
16
|
+
"aria-label": props["aria-label"] ?? "",
|
|
17
|
+
variant: "ghost",
|
|
18
|
+
color: "neutral",
|
|
19
|
+
size: "sm",
|
|
20
|
+
children
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { CalendarNavButton };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { calendarCellClass, calendarPickerItemClass } from "../constants/calendarClass.js";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
import { useEffect, useRef } from "react";
|
|
6
|
+
|
|
7
|
+
// src/DatePicker/components/CalendarPickerCell.tsx
|
|
8
|
+
/** 연도·월 grid의 칸 하나. 날짜 칸처럼 `gridcell` 안에 `button` 역할 요소를 둔다. */
|
|
9
|
+
function CalendarPickerCell({ item, isFocused, shouldFocus, onFocusItem, onSelect }) {
|
|
10
|
+
const ref = useRef(null);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (shouldFocus) ref.current?.focus({ preventScroll: true });
|
|
13
|
+
}, [shouldFocus]);
|
|
14
|
+
return /* @__PURE__ */ jsx("td", {
|
|
15
|
+
role: "gridcell",
|
|
16
|
+
"aria-selected": item.isSelected || void 0,
|
|
17
|
+
"aria-disabled": item.isDisabled || void 0,
|
|
18
|
+
className: calendarCellClass,
|
|
19
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
20
|
+
ref,
|
|
21
|
+
role: "button",
|
|
22
|
+
tabIndex: item.isDisabled ? void 0 : isFocused ? 0 : -1,
|
|
23
|
+
"aria-disabled": item.isDisabled || void 0,
|
|
24
|
+
"data-selected": item.isSelected || void 0,
|
|
25
|
+
"data-outside": item.isOutside || void 0,
|
|
26
|
+
"data-disabled": item.isDisabled || void 0,
|
|
27
|
+
className: calendarPickerItemClass,
|
|
28
|
+
onFocus: () => {
|
|
29
|
+
if (!item.isOutside && !item.isDisabled) onFocusItem(item.key);
|
|
30
|
+
},
|
|
31
|
+
onClick: () => {
|
|
32
|
+
if (!item.isDisabled) onSelect(item.key);
|
|
33
|
+
},
|
|
34
|
+
children: item.label
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { CalendarPickerCell };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { calendarPickerGridClass } from "../constants/calendarClass.js";
|
|
4
|
+
import { nextPickerKey } from "../libs/calendarPicker.js";
|
|
5
|
+
import { CalendarPickerCell } from "./CalendarPickerCell.js";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
import { useState } from "react";
|
|
8
|
+
import { useLocale } from "react-aria";
|
|
9
|
+
|
|
10
|
+
// src/DatePicker/components/CalendarPickerGrid.tsx
|
|
11
|
+
/** 연도·월 화면의 grid(APG grid 패턴). 화면에 들어오면 포커스 칸으로 포커스를 옮긴다. */
|
|
12
|
+
function CalendarPickerGrid({ "aria-label": ariaLabel, items, focusedKey, onFocusedKeyChange, onSelect, range }) {
|
|
13
|
+
const { direction } = useLocale();
|
|
14
|
+
const [isFocusWithin, setFocusWithin] = useState(true);
|
|
15
|
+
const rows = Array.from({ length: Math.ceil(items.length / 3) }, (_, row) => items.slice(row * 3, (row + 1) * 3));
|
|
16
|
+
const onKeyDown = (event) => {
|
|
17
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
18
|
+
event.preventDefault();
|
|
19
|
+
onSelect(focusedKey);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const next = nextPickerKey(event.key, focusedKey, range, direction === "rtl");
|
|
23
|
+
if (next === null) return;
|
|
24
|
+
event.preventDefault();
|
|
25
|
+
onFocusedKeyChange(next);
|
|
26
|
+
};
|
|
27
|
+
return /* @__PURE__ */ jsx("table", {
|
|
28
|
+
role: "grid",
|
|
29
|
+
"aria-label": ariaLabel,
|
|
30
|
+
className: calendarPickerGridClass,
|
|
31
|
+
onKeyDown,
|
|
32
|
+
onFocus: () => setFocusWithin(true),
|
|
33
|
+
onBlur: (event) => {
|
|
34
|
+
if (!event.currentTarget.contains(event.relatedTarget)) setFocusWithin(false);
|
|
35
|
+
},
|
|
36
|
+
children: /* @__PURE__ */ jsx("tbody", { children: rows.map((row, index) => /* @__PURE__ */ jsx("tr", { children: row.map((item) => /* @__PURE__ */ jsx(CalendarPickerCell, {
|
|
37
|
+
item,
|
|
38
|
+
isFocused: item.key === focusedKey,
|
|
39
|
+
shouldFocus: isFocusWithin && item.key === focusedKey,
|
|
40
|
+
onFocusItem: onFocusedKeyChange,
|
|
41
|
+
onSelect
|
|
42
|
+
}, item.key)) }, index)) })
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { CalendarPickerGrid };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Button } from "../../Button/Button.js";
|
|
4
|
+
import { calendarTitleButtonClass, calendarTitleButtonsClass } from "../constants/calendarClass.js";
|
|
5
|
+
import { splitYearMonthTitle } from "../libs/calendarPicker.js";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
import { useDateFormatter } from "react-aria";
|
|
8
|
+
|
|
9
|
+
// src/DatePicker/components/CalendarTitle.tsx
|
|
10
|
+
/** 날짜 화면 제목. 연도·월 부분이 각각 연도·월 화면을 여는 버튼이다. 순서는 locale을 따른다. */
|
|
11
|
+
function CalendarTitle({ state, onYearPress, onMonthPress }) {
|
|
12
|
+
const formatter = useDateFormatter({
|
|
13
|
+
year: "numeric",
|
|
14
|
+
month: "long",
|
|
15
|
+
timeZone: state.timeZone
|
|
16
|
+
});
|
|
17
|
+
const parts = splitYearMonthTitle(formatter.formatToParts(state.visibleRange.start.toDate(state.timeZone)));
|
|
18
|
+
return /* @__PURE__ */ jsx("h2", {
|
|
19
|
+
className: calendarTitleButtonsClass,
|
|
20
|
+
children: parts.map((part, index) => part.type === "literal" ? /* @__PURE__ */ jsx("span", { children: part.text }, index) : /* @__PURE__ */ jsx(Button, {
|
|
21
|
+
variant: "ghost",
|
|
22
|
+
color: "neutral",
|
|
23
|
+
size: "sm",
|
|
24
|
+
noPressScale: true,
|
|
25
|
+
className: calendarTitleButtonClass,
|
|
26
|
+
"aria-label": `${part.text}, ${part.type === "year" ? "연도" : "월"} 고르기`,
|
|
27
|
+
onClick: part.type === "year" ? onYearPress : onMonthPress,
|
|
28
|
+
children: part.text
|
|
29
|
+
}, part.type))
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { CalendarTitle };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { calendarHeaderClass, calendarTitleClass } from "../constants/calendarClass.js";
|
|
4
|
+
import { clampKey, decadeStart } from "../libs/calendarPicker.js";
|
|
5
|
+
import { CalendarNavButton } from "./CalendarNavButton.js";
|
|
6
|
+
import { CalendarPickerGrid } from "./CalendarPickerGrid.js";
|
|
7
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { ChevronsLeftIcon, ChevronsRightIcon } from "@tide-design/icons";
|
|
9
|
+
import { useNumberFormatter } from "react-aria";
|
|
10
|
+
|
|
11
|
+
// src/DatePicker/components/CalendarYearView.tsx
|
|
12
|
+
/** 연도 화면. 10년 묶음에 앞뒤 해를 하나씩 더해 3열 4줄로 보인다. */
|
|
13
|
+
function CalendarYearView({ focusedYear, onFocusedYearChange, selectedYear, minYear, maxYear, onSelect }) {
|
|
14
|
+
const formatter = useNumberFormatter({ useGrouping: false });
|
|
15
|
+
const start = decadeStart(focusedYear);
|
|
16
|
+
const title = `${formatter.format(start)}-${formatter.format(start + 9)}`;
|
|
17
|
+
const items = Array.from({ length: 12 }, (_, index) => {
|
|
18
|
+
const year = start - 1 + index;
|
|
19
|
+
return {
|
|
20
|
+
key: year,
|
|
21
|
+
label: formatter.format(year),
|
|
22
|
+
isOutside: year < start || year > start + 9,
|
|
23
|
+
isDisabled: year < minYear || year > maxYear,
|
|
24
|
+
isSelected: year === selectedYear
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
const moveDecade = (offset) => onFocusedYearChange(clampKey(focusedYear + offset, minYear, maxYear));
|
|
28
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
|
|
29
|
+
className: calendarHeaderClass,
|
|
30
|
+
children: [
|
|
31
|
+
/* @__PURE__ */ jsx(CalendarNavButton, {
|
|
32
|
+
"aria-label": "이전 10년",
|
|
33
|
+
isDisabled: start - 1 < minYear,
|
|
34
|
+
onPress: () => moveDecade(-10),
|
|
35
|
+
children: /* @__PURE__ */ jsx(ChevronsLeftIcon, {})
|
|
36
|
+
}),
|
|
37
|
+
/* @__PURE__ */ jsx("h2", {
|
|
38
|
+
"aria-live": "polite",
|
|
39
|
+
className: calendarTitleClass,
|
|
40
|
+
children: title
|
|
41
|
+
}),
|
|
42
|
+
/* @__PURE__ */ jsx(CalendarNavButton, {
|
|
43
|
+
"aria-label": "다음 10년",
|
|
44
|
+
isDisabled: start + 10 > maxYear,
|
|
45
|
+
onPress: () => moveDecade(10),
|
|
46
|
+
children: /* @__PURE__ */ jsx(ChevronsRightIcon, {})
|
|
47
|
+
})
|
|
48
|
+
]
|
|
49
|
+
}), /* @__PURE__ */ jsx(CalendarPickerGrid, {
|
|
50
|
+
"aria-label": `연도, ${title}`,
|
|
51
|
+
items,
|
|
52
|
+
focusedKey: focusedYear,
|
|
53
|
+
onFocusedKeyChange: onFocusedYearChange,
|
|
54
|
+
onSelect,
|
|
55
|
+
range: {
|
|
56
|
+
blockStart: start,
|
|
57
|
+
page: 10,
|
|
58
|
+
min: minYear,
|
|
59
|
+
max: maxYear
|
|
60
|
+
}
|
|
61
|
+
})] });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { CalendarYearView };
|