@cocso-ui/react 1.10.0 → 1.11.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.
@@ -9,11 +9,11 @@ var DatePicker = require('react-datepicker');
9
9
  var cn = require('../../cn.js');
10
10
  require('../picker/picker-chrome.module.css.js');
11
11
  require('../picker/picker-day-grid.module.css.js');
12
+ var yearMonthView = require('../picker/year-month-view.js');
12
13
  var dateTimePicker_module = require('./date-time-picker.module.css.js');
13
14
  var jsxRuntime = require('react/jsx-runtime');
14
15
  var popover = require('../popover/popover.js');
15
16
  var button = require('../button/button.js');
16
- var typography = require('../typography/typography.js');
17
17
 
18
18
  const isSameDay = (a, b) => a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
19
19
  const atTime = (day, hours, minutes) => {
@@ -61,14 +61,24 @@ function DateTimePicker({
61
61
  const [draft, setDraft] = react.useState(null);
62
62
  const selected = value ?? draft;
63
63
 
64
- // The month to open on: `minDate`'s, if it is still ahead of today.
65
- const openToDate = react.useMemo(() => {
64
+ // The month to open on: the selection's, else `minDate`'s if it is still
65
+ // ahead of today, else today's.
66
+ const openingMonth = () => {
66
67
  if (selected) {
67
- return undefined;
68
+ return selected;
68
69
  }
69
70
  const now = new Date();
70
- return minDate && minDate.getTime() > now.getTime() ? minDate : undefined;
71
- }, [selected, minDate]);
71
+ return minDate && minDate.getTime() > now.getTime() ? minDate : now;
72
+ };
73
+ // The header opens a year-and-month grid, as in DayPicker — a date years
74
+ // away is a few clicks instead of one per month.
75
+ const calendar = yearMonthView.useYearMonthView(openingMonth);
76
+ const handleOpenChange = next => {
77
+ setOpen(next);
78
+ if (next) {
79
+ calendar.reset(openingMonth());
80
+ }
81
+ };
72
82
 
73
83
  // A bound that only applies on the day it falls on: on any other day the
74
84
  // whole day is open. Without this a `minDate` of 3pm today would also cut
@@ -109,7 +119,7 @@ function DateTimePicker({
109
119
  ref: ref,
110
120
  ...props,
111
121
  children: /*#__PURE__*/jsxRuntime.jsxs(popover.Popover, {
112
- onOpenChange: setOpen,
122
+ onOpenChange: handleOpenChange,
113
123
  open: open,
114
124
  children: [/*#__PURE__*/jsxRuntime.jsx(popover.Popover.Trigger, {
115
125
  render: trigger ?? /*#__PURE__*/jsxRuntime.jsx(button.Button, {
@@ -120,81 +130,94 @@ function DateTimePicker({
120
130
  locale: locale$1
121
131
  }) : "Select date and time"
122
132
  })
123
- }), /*#__PURE__*/jsxRuntime.jsx(popover.Popover.Content, {
133
+ }), /*#__PURE__*/jsxRuntime.jsxs(popover.Popover.Content, {
124
134
  "aria-label": "Select date and time",
125
135
  className: dateTimePicker_module.content,
126
- children: /*#__PURE__*/jsxRuntime.jsx(DatePicker, {
127
- dateFormat: dateFormat,
128
- dayClassName: date => {
129
- const day = date.getDay();
130
- if (day === 0) {
131
- return dateTimePicker_module.sunday;
132
- }
133
- if (day === 6) {
134
- return dateTimePicker_module.saturday;
135
- }
136
- return "";
137
- },
138
- disabled: disabled,
139
- filterTime: filterTime
140
- // Six weeks always, for the same reason as DayPicker: a five-week month made
141
- // the panel shorter, and paging into a six-week one could flip it above the trigger.
142
- ,
143
- fixedHeight: true,
144
- inline: true,
136
+ children: [/*#__PURE__*/jsxRuntime.jsx(yearMonthView.YearMonthView, {
137
+ currentMonthRef: calendar.currentMonthRef,
138
+ hidden: calendar.view !== "month",
145
139
  locale: locale$1,
146
140
  maxDate: maxDate,
147
- maxTime: bounds.maxTime,
148
141
  minDate: minDate,
149
- minTime: bounds.minTime,
150
- onChange: handleChange,
151
- openToDate: openToDate,
152
- renderCustomHeader: ({
153
- date,
154
- decreaseMonth,
155
- increaseMonth,
156
- prevMonthButtonDisabled,
157
- nextMonthButtonDisabled
158
- }) => /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
159
- children: [/*#__PURE__*/jsxRuntime.jsx(typography.Typography, {
160
- size: "small",
161
- type: "body",
162
- weight: "semibold",
163
- children: date.toLocaleDateString(locale$1.code ?? "ko-KR", {
164
- year: "numeric",
165
- month: "long"
166
- })
167
- }), /*#__PURE__*/jsxRuntime.jsxs("div", {
168
- className: dateTimePicker_module.menu,
169
- children: [/*#__PURE__*/jsxRuntime.jsx(button.Button, {
170
- "aria-label": "Previous month",
171
- className: dateTimePicker_module.arrow,
172
- disabled: prevMonthButtonDisabled,
173
- onClick: decreaseMonth,
174
- size: "x-small",
175
- svgOnly: true,
176
- type: "button",
177
- variant: "outline",
178
- children: /*#__PURE__*/jsxRuntime.jsx(reactIcons.ArrowIOSBackwardIcon, {})
179
- }), /*#__PURE__*/jsxRuntime.jsx(button.Button, {
180
- "aria-label": "Next month",
181
- className: dateTimePicker_module.arrow,
182
- disabled: nextMonthButtonDisabled,
183
- onClick: increaseMonth,
184
- size: "x-small",
185
- svgOnly: true,
186
- type: "button",
187
- variant: "outline",
188
- children: /*#__PURE__*/jsxRuntime.jsx(reactIcons.ArrowIOSForwardIcon, {})
142
+ minHeight: calendar.dayViewHeight,
143
+ onBack: () => calendar.changeView("day"),
144
+ onPick: calendar.jumpTo,
145
+ onYearChange: calendar.setViewDate,
146
+ selected: selected,
147
+ viewDate: calendar.viewDate
148
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
149
+ hidden: calendar.view !== "day",
150
+ children: /*#__PURE__*/jsxRuntime.jsx(DatePicker, {
151
+ dateFormat: dateFormat,
152
+ dayClassName: date => {
153
+ const day = date.getDay();
154
+ if (day === 0) {
155
+ return dateTimePicker_module.sunday;
156
+ }
157
+ if (day === 6) {
158
+ return dateTimePicker_module.saturday;
159
+ }
160
+ return "";
161
+ },
162
+ disabled: disabled,
163
+ filterTime: filterTime
164
+ // Six weeks always, for the same reason as DayPicker: a five-week month made
165
+ // the panel shorter, and paging into a six-week one could flip it above the trigger.
166
+ ,
167
+ fixedHeight: true,
168
+ inline: true,
169
+ locale: locale$1,
170
+ maxDate: maxDate,
171
+ maxTime: bounds.maxTime,
172
+ minDate: minDate,
173
+ minTime: bounds.minTime,
174
+ onChange: handleChange,
175
+ onMonthChange: calendar.setViewDate,
176
+ openToDate: calendar.viewDate,
177
+ renderCustomHeader: ({
178
+ date,
179
+ decreaseMonth,
180
+ increaseMonth,
181
+ prevMonthButtonDisabled,
182
+ nextMonthButtonDisabled
183
+ }) => /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
184
+ children: [/*#__PURE__*/jsxRuntime.jsx(yearMonthView.CalendarTitle, {
185
+ date: date,
186
+ locale: locale$1,
187
+ onPress: panel => calendar.openMonths(date, panel),
188
+ ref: calendar.titleRef
189
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
190
+ className: dateTimePicker_module.menu,
191
+ children: [/*#__PURE__*/jsxRuntime.jsx(button.Button, {
192
+ "aria-label": "Previous month",
193
+ className: dateTimePicker_module.arrow,
194
+ disabled: prevMonthButtonDisabled,
195
+ onClick: decreaseMonth,
196
+ size: "x-small",
197
+ svgOnly: true,
198
+ type: "button",
199
+ variant: "outline",
200
+ children: /*#__PURE__*/jsxRuntime.jsx(reactIcons.ArrowIOSBackwardIcon, {})
201
+ }), /*#__PURE__*/jsxRuntime.jsx(button.Button, {
202
+ "aria-label": "Next month",
203
+ className: dateTimePicker_module.arrow,
204
+ disabled: nextMonthButtonDisabled,
205
+ onClick: increaseMonth,
206
+ size: "x-small",
207
+ svgOnly: true,
208
+ type: "button",
209
+ variant: "outline",
210
+ children: /*#__PURE__*/jsxRuntime.jsx(reactIcons.ArrowIOSForwardIcon, {})
211
+ })]
189
212
  })]
190
- })]
191
- }),
192
- selected: selected ?? undefined,
193
- showPopperArrow: false,
194
- showTimeSelect: true,
195
- timeCaption: timeCaption,
196
- timeIntervals: timeIntervals
197
- })
213
+ }),
214
+ selected: selected ?? undefined,
215
+ showPopperArrow: false,
216
+ showTimeSelect: true,
217
+ timeCaption: timeCaption,
218
+ timeIntervals: timeIntervals
219
+ }, calendar.calendarKey)
220
+ })]
198
221
  })]
199
222
  })
200
223
  });
@@ -9,15 +9,11 @@ var DatePicker = require('react-datepicker');
9
9
  var cn = require('../../cn.js');
10
10
  require('../picker/picker-chrome.module.css.js');
11
11
  require('../picker/picker-day-grid.module.css.js');
12
+ var yearMonthView = require('../picker/year-month-view.js');
12
13
  var dayPicker_module = require('./day-picker.module.css.js');
13
14
  var jsxRuntime = require('react/jsx-runtime');
14
15
  var popover = require('../popover/popover.js');
15
16
  var button = require('../button/button.js');
16
- var typography = require('../typography/typography.js');
17
-
18
- const MONTHS = Array.from({
19
- length: 12
20
- }, (_, month) => month);
21
17
 
22
18
  // Where the calendar opens: the value's month, else today's, pulled inside
23
19
  // the bounds so an empty picker with a future `minDate` does not open on a
@@ -51,54 +47,17 @@ function DayPicker({
51
47
  const [open, setOpen] = react.useState(false);
52
48
  // The header's month opens a year-and-month grid in the same panel, so a
53
49
  // date years away is a few clicks instead of one click per month.
54
- const [view, setView] = react.useState("day");
55
- const [viewDate, setViewDate] = react.useState(() => initialViewDate(value, minDate, maxDate));
56
- // Remounts the calendar after a jump. A live calendar follows its keyboard
57
- // cursor before `openToDate`, so a fresh mount is the reliable way to land
58
- // on the picked month.
59
- const [calendarKey, setCalendarKey] = react.useState(0);
60
- // The day grid's height, held by the month grid so the panel does not
61
- // shrink under the pointer — a panel opened above its trigger would jump.
62
- const [dayViewHeight, setDayViewHeight] = react.useState();
63
- const focusAfterViewChange = react.useRef(false);
64
- const titleRef = react.useRef(null);
65
- const currentMonthRef = react.useRef(null);
66
-
67
- // A view change unmounts the control that had focus. Hand it to the
68
- // matching control in the new view instead of dropping it on the body.
69
- react.useEffect(() => {
70
- if (!focusAfterViewChange.current) {
71
- return;
72
- }
73
- focusAfterViewChange.current = false;
74
- (view === "month" ? currentMonthRef : titleRef).current?.focus();
75
- }, [view]);
50
+ const calendar = yearMonthView.useYearMonthView(() => initialViewDate(value, minDate, maxDate));
76
51
  const handleOpenChange = next => {
77
52
  setOpen(next);
78
53
  if (next) {
79
- setView("day");
80
- setViewDate(initialViewDate(value, minDate, maxDate));
81
- setCalendarKey(key => key + 1);
54
+ calendar.reset(initialViewDate(value, minDate, maxDate));
82
55
  }
83
56
  };
84
57
  const handleChange = date => {
85
58
  onValueChange?.(date);
86
59
  setOpen(false);
87
60
  };
88
- const changeView = next => {
89
- focusAfterViewChange.current = true;
90
- setView(next);
91
- };
92
- const jumpTo = (year, month) => {
93
- setViewDate(new Date(year, month, 1));
94
- setCalendarKey(key => key + 1);
95
- changeView("day");
96
- };
97
- const year = viewDate.getFullYear();
98
- const monthDisabled = month => {
99
- const first = dateFns.startOfMonth(new Date(year, month, 1));
100
- return minDate !== undefined && dateFns.endOfMonth(first) < minDate || maxDate !== undefined && first > maxDate;
101
- };
102
61
  return /*#__PURE__*/jsxRuntime.jsx("div", {
103
62
  className: cn.cn(dayPicker_module.root, className),
104
63
  ref: ref,
@@ -118,75 +77,20 @@ function DayPicker({
118
77
  }), /*#__PURE__*/jsxRuntime.jsxs(popover.Popover.Content, {
119
78
  "aria-label": "Select date",
120
79
  className: dayPicker_module.content,
121
- children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
122
- className: dayPicker_module.monthView,
123
- hidden: view !== "month",
124
- style: {
125
- minHeight: dayViewHeight
126
- },
127
- children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
128
- className: dayPicker_module.monthHeader,
129
- children: [/*#__PURE__*/jsxRuntime.jsxs("button", {
130
- "aria-label": "Back to days",
131
- className: dayPicker_module.title,
132
- onClick: () => changeView("day"),
133
- type: "button",
134
- children: [/*#__PURE__*/jsxRuntime.jsx(typography.Typography, {
135
- size: "small",
136
- type: "body",
137
- weight: "semibold",
138
- children: viewDate.toLocaleDateString(locale$1.code ?? "ko-KR", {
139
- year: "numeric"
140
- })
141
- }), /*#__PURE__*/jsxRuntime.jsx(reactIcons.ArrowDropUpIcon, {
142
- "aria-hidden": true,
143
- size: 16
144
- })]
145
- }), /*#__PURE__*/jsxRuntime.jsxs("div", {
146
- className: dayPicker_module.menu,
147
- children: [/*#__PURE__*/jsxRuntime.jsx(button.Button, {
148
- "aria-label": "Previous year",
149
- className: dayPicker_module.arrow,
150
- disabled: minDate !== undefined && year - 1 < minDate.getFullYear(),
151
- onClick: () => setViewDate(new Date(year - 1, 0, 1)),
152
- size: "x-small",
153
- svgOnly: true,
154
- type: "button",
155
- variant: "outline",
156
- children: /*#__PURE__*/jsxRuntime.jsx(reactIcons.ArrowIOSBackwardIcon, {})
157
- }), /*#__PURE__*/jsxRuntime.jsx(button.Button, {
158
- "aria-label": "Next year",
159
- className: dayPicker_module.arrow,
160
- disabled: maxDate !== undefined && year + 1 > maxDate.getFullYear(),
161
- onClick: () => setViewDate(new Date(year + 1, 0, 1)),
162
- size: "x-small",
163
- svgOnly: true,
164
- type: "button",
165
- variant: "outline",
166
- children: /*#__PURE__*/jsxRuntime.jsx(reactIcons.ArrowIOSForwardIcon, {})
167
- })]
168
- })]
169
- }), /*#__PURE__*/jsxRuntime.jsx("div", {
170
- className: dayPicker_module.monthGrid,
171
- children: MONTHS.map(month => {
172
- const current = value !== undefined && value.getFullYear() === year && value.getMonth() === month;
173
- const isViewed = viewDate.getMonth() === month;
174
- return /*#__PURE__*/jsxRuntime.jsx("button", {
175
- "aria-current": current ? "date" : undefined,
176
- className: dayPicker_module.monthCell,
177
- "data-selected": current || undefined,
178
- disabled: monthDisabled(month),
179
- onClick: () => jumpTo(year, month),
180
- ref: isViewed ? currentMonthRef : undefined,
181
- type: "button",
182
- children: dateFns.format(new Date(year, month, 1), "LLL", {
183
- locale: locale$1
184
- })
185
- }, month);
186
- })
187
- })]
80
+ children: [/*#__PURE__*/jsxRuntime.jsx(yearMonthView.YearMonthView, {
81
+ currentMonthRef: calendar.currentMonthRef,
82
+ hidden: calendar.view !== "month",
83
+ locale: locale$1,
84
+ maxDate: maxDate,
85
+ minDate: minDate,
86
+ minHeight: calendar.dayViewHeight,
87
+ onBack: () => calendar.changeView("day"),
88
+ onPick: calendar.jumpTo,
89
+ onYearChange: calendar.setViewDate,
90
+ selected: value,
91
+ viewDate: calendar.viewDate
188
92
  }), /*#__PURE__*/jsxRuntime.jsx("div", {
189
- hidden: view !== "day",
93
+ hidden: calendar.view !== "day",
190
94
  children: /*#__PURE__*/jsxRuntime.jsx(DatePicker, {
191
95
  dateFormat: dateFormat,
192
96
  dayClassName: date => {
@@ -211,8 +115,8 @@ function DayPicker({
211
115
  maxDate: maxDate,
212
116
  minDate: minDate,
213
117
  onChange: handleChange,
214
- onMonthChange: setViewDate,
215
- openToDate: viewDate,
118
+ onMonthChange: calendar.setViewDate,
119
+ openToDate: calendar.viewDate,
216
120
  renderCustomHeader: ({
217
121
  date,
218
122
  decreaseMonth,
@@ -220,28 +124,11 @@ function DayPicker({
220
124
  prevMonthButtonDisabled,
221
125
  nextMonthButtonDisabled
222
126
  }) => /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
223
- children: [/*#__PURE__*/jsxRuntime.jsxs("button", {
224
- "aria-label": "Choose year and month",
225
- className: dayPicker_module.title,
226
- onClick: event => {
227
- setDayViewHeight(event.currentTarget.closest(".react-datepicker")?.getBoundingClientRect().height);
228
- setViewDate(date);
229
- changeView("month");
230
- },
231
- ref: titleRef,
232
- type: "button",
233
- children: [/*#__PURE__*/jsxRuntime.jsx(typography.Typography, {
234
- size: "small",
235
- type: "body",
236
- weight: "semibold",
237
- children: date.toLocaleDateString(locale$1.code ?? "ko-KR", {
238
- year: "numeric",
239
- month: "long"
240
- })
241
- }), /*#__PURE__*/jsxRuntime.jsx(reactIcons.ArrowDropDownIcon, {
242
- "aria-hidden": true,
243
- size: 16
244
- })]
127
+ children: [/*#__PURE__*/jsxRuntime.jsx(yearMonthView.CalendarTitle, {
128
+ date: date,
129
+ locale: locale$1,
130
+ onPress: panel => calendar.openMonths(date, panel),
131
+ ref: calendar.titleRef
245
132
  }), /*#__PURE__*/jsxRuntime.jsxs("div", {
246
133
  className: dayPicker_module.menu,
247
134
  children: [/*#__PURE__*/jsxRuntime.jsx(button.Button, {
@@ -269,7 +156,7 @@ function DayPicker({
269
156
  }),
270
157
  selected: value,
271
158
  showPopperArrow: false
272
- }, calendarKey)
159
+ }, calendar.calendarKey)
273
160
  })]
274
161
  })]
275
162
  })
@@ -2,8 +2,8 @@
2
2
 
3
3
  var styleInject_es = require('../../node_modules/.pnpm/style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js');
4
4
 
5
- var css_248z = "@layer components{.day-picker-module_root__QVrbb{display:inline-block;transform:translateZ(0)}.day-picker-module_content__34qUu.day-picker-module_content__34qUu{border-radius:var(--cocso-radius-4);line-height:normal;min-width:260px;overflow:hidden;padding:var(--cocso-spacing-7)}.day-picker-module_menu__2eMt0{align-items:center;display:flex;gap:var(--cocso-spacing-3);justify-content:center}.day-picker-module_arrow__p9QLq{height:24px;width:24px}.day-picker-module_title__UokL8{align-items:center;background:none;border:0;border-radius:var(--cocso-radius-2);color:inherit;cursor:pointer;display:inline-flex;gap:var(--cocso-spacing-1);margin-inline-start:calc(var(--cocso-spacing-2)*-1);padding-block:var(--cocso-spacing-1);padding-inline:var(--cocso-spacing-2)}.day-picker-module_monthCell__lbR2S:focus-visible,.day-picker-module_title__UokL8:focus-visible{outline:2px solid var(--cocso-color-focus-ring);outline-offset:2px}.day-picker-module_monthView__tPMlr{display:flex;flex-direction:column}.day-picker-module_monthView__tPMlr[hidden]{display:none}.day-picker-module_monthHeader__mAlm5{align-items:center;display:flex;justify-content:space-between;padding-bottom:var(--cocso-spacing-5);width:100%}.day-picker-module_monthGrid__14EcZ{display:grid;flex:1;gap:var(--cocso-spacing-3);grid-auto-rows:1fr;grid-template-columns:repeat(3,1fr)}.day-picker-module_monthCell__lbR2S{align-items:center;background:none;border:0;border-radius:var(--cocso-radius-4);color:var(--cocso-color-text-primary);cursor:pointer;display:flex;font-size:var(--cocso-text-sm);font-weight:var(--cocso-font-weight-medium);justify-content:center;min-height:var(--cocso-spacing-14)}.day-picker-module_monthCell__lbR2S[data-selected]{background-color:var(--cocso-color-interactive-primary);color:var(--cocso-color-text-on-primary);font-weight:var(--cocso-font-weight-semibold)}.day-picker-module_monthCell__lbR2S:disabled{cursor:not-allowed;opacity:.4}.react-datepicker__day.day-picker-module_sunday__nVavs{color:var(--cocso-color-feedback-danger-text)}.react-datepicker__day.day-picker-module_saturday__ZYoB9{color:var(--cocso-color-feedback-info-text)}.react-datepicker{background-color:var(--cocso-color-surface-primary);color:var(--cocso-color-text-primary);display:block;font-size:.8rem;padding-inline:0;position:relative;width:100%}.react-datepicker__month-container{padding-block:0;width:100%}.react-datepicker__month{gap:var(--cocso-spacing-2)}.react-datepicker__week{align-items:center;display:flex;justify-content:space-between;text-align:center;white-space:nowrap;width:100%}@media (hover:hover) and (pointer:fine){.react-datepicker__day:hover{background-color:var(--cocso-color-interactive-secondary)}.react-datepicker__day.react-datepicker__day--selected:hover{background-color:var(--cocso-color-interactive-primary-hover)}.day-picker-module_monthCell__lbR2S:not(:disabled):hover,.day-picker-module_title__UokL8:hover{background-color:var(--cocso-color-interactive-secondary)}.day-picker-module_monthCell__lbR2S[data-selected]:not(:disabled):hover{background-color:var(--cocso-color-interactive-primary-hover)}}}";
6
- var styles = {"root":"day-picker-module_root__QVrbb","content":"day-picker-module_content__34qUu","menu":"day-picker-module_menu__2eMt0","arrow":"day-picker-module_arrow__p9QLq","title":"day-picker-module_title__UokL8","monthCell":"day-picker-module_monthCell__lbR2S","monthView":"day-picker-module_monthView__tPMlr","monthHeader":"day-picker-module_monthHeader__mAlm5","monthGrid":"day-picker-module_monthGrid__14EcZ","sunday":"day-picker-module_sunday__nVavs","saturday":"day-picker-module_saturday__ZYoB9"};
5
+ var css_248z = "@layer components{.day-picker-module_root__QVrbb{display:inline-block;transform:translateZ(0)}.day-picker-module_content__34qUu.day-picker-module_content__34qUu{border-radius:var(--cocso-radius-4);line-height:normal;min-width:260px;overflow:hidden;padding:var(--cocso-spacing-7)}.day-picker-module_menu__2eMt0{align-items:center;display:flex;gap:var(--cocso-spacing-3);justify-content:center}.day-picker-module_arrow__p9QLq{height:24px;width:24px}.react-datepicker__day.day-picker-module_sunday__nVavs{color:var(--cocso-color-feedback-danger-text)}.react-datepicker__day.day-picker-module_saturday__ZYoB9{color:var(--cocso-color-feedback-info-text)}.react-datepicker{background-color:var(--cocso-color-surface-primary);color:var(--cocso-color-text-primary);display:block;font-size:.8rem;padding-inline:0;position:relative;width:100%}.react-datepicker__month-container{padding-block:0;width:100%}.react-datepicker__month{gap:var(--cocso-spacing-2)}.react-datepicker__week{align-items:center;display:flex;justify-content:space-between;text-align:center;white-space:nowrap;width:100%}@media (hover:hover) and (pointer:fine){.react-datepicker__day:hover{background-color:var(--cocso-color-interactive-secondary)}.react-datepicker__day.react-datepicker__day--selected:hover{background-color:var(--cocso-color-interactive-primary-hover)}}}";
6
+ var styles = {"root":"day-picker-module_root__QVrbb","content":"day-picker-module_content__34qUu","menu":"day-picker-module_menu__2eMt0","arrow":"day-picker-module_arrow__p9QLq","sunday":"day-picker-module_sunday__nVavs","saturday":"day-picker-module_saturday__ZYoB9"};
7
7
  styleInject_es(css_248z);
8
8
 
9
9
  module.exports = styles;
@@ -0,0 +1,216 @@
1
+ "use client";
2
+ 'use strict';
3
+
4
+ var reactIcons = require('@cocso-ui/react-icons');
5
+ var dateFns = require('date-fns');
6
+ var react = require('react');
7
+ var yearMonthView_module = require('./year-month-view.module.css.js');
8
+ var jsxRuntime = require('react/jsx-runtime');
9
+ var typography = require('../typography/typography.js');
10
+ var button = require('../button/button.js');
11
+
12
+ const MONTHS = Array.from({
13
+ length: 12
14
+ }, (_, month) => month);
15
+ /**
16
+ * The state behind a calendar header that opens a year-and-month grid, shared
17
+ * by DayPicker and DateTimePicker so a date years away is a few clicks in
18
+ * either of them instead of one click per month.
19
+ */
20
+ function useYearMonthView(initial) {
21
+ const [view, setView] = react.useState("day");
22
+ const [viewDate, setViewDate] = react.useState(initial);
23
+ // Remounts the calendar after a jump. A live calendar follows its keyboard
24
+ // cursor before `openToDate`, so a fresh mount is the reliable way to land
25
+ // on the picked month.
26
+ const [calendarKey, setCalendarKey] = react.useState(0);
27
+ // The day grid's height, held by the month grid so the panel does not
28
+ // shrink under the pointer — a panel opened above its trigger would jump.
29
+ const [dayViewHeight, setDayViewHeight] = react.useState();
30
+ const focusAfterViewChange = react.useRef(false);
31
+ const titleElement = react.useRef(null);
32
+ // Set when the day view should take focus but its header is not mounted yet.
33
+ // A remounted calendar draws its header in a later pass when it carries a
34
+ // time list (DateTimePicker), after the view effect has already run.
35
+ const titleFocusPending = react.useRef(false);
36
+ const currentMonthRef = react.useRef(null);
37
+ const titleRef = react.useCallback(element => {
38
+ titleElement.current = element;
39
+ if (element && titleFocusPending.current) {
40
+ titleFocusPending.current = false;
41
+ element.focus();
42
+ }
43
+ }, []);
44
+
45
+ // A view change unmounts the control that had focus. Hand it to the
46
+ // matching control in the new view instead of dropping it on the body.
47
+ react.useEffect(() => {
48
+ if (!focusAfterViewChange.current) {
49
+ return;
50
+ }
51
+ focusAfterViewChange.current = false;
52
+ if (view === "month") {
53
+ currentMonthRef.current?.focus();
54
+ return;
55
+ }
56
+ const title = titleElement.current;
57
+ if (title?.isConnected) {
58
+ title.focus();
59
+ } else {
60
+ titleFocusPending.current = true;
61
+ }
62
+ }, [view]);
63
+ const changeView = next => {
64
+ focusAfterViewChange.current = true;
65
+ setView(next);
66
+ };
67
+
68
+ /** Back to the day grid on `date`'s month, as when the panel opens. */
69
+ const reset = date => {
70
+ setView("day");
71
+ setViewDate(date);
72
+ setCalendarKey(key => key + 1);
73
+ };
74
+ const openMonths = (date, calendar) => {
75
+ setDayViewHeight(calendar?.getBoundingClientRect().height);
76
+ setViewDate(date);
77
+ changeView("month");
78
+ };
79
+ const jumpTo = (year, month) => {
80
+ setViewDate(new Date(year, month, 1));
81
+ setCalendarKey(key => key + 1);
82
+ changeView("day");
83
+ };
84
+ return {
85
+ calendarKey,
86
+ changeView,
87
+ currentMonthRef,
88
+ dayViewHeight,
89
+ jumpTo,
90
+ openMonths,
91
+ reset,
92
+ setViewDate,
93
+ titleRef,
94
+ view,
95
+ viewDate
96
+ };
97
+ }
98
+ /** The day grid's "2026년 10월 ▾", pressed to open the month grid. */
99
+ function CalendarTitle({
100
+ date,
101
+ locale,
102
+ onPress,
103
+ ref
104
+ }) {
105
+ return /*#__PURE__*/jsxRuntime.jsxs("button", {
106
+ "aria-label": "Choose year and month",
107
+ className: yearMonthView_module.title,
108
+ onClick: event => onPress(event.currentTarget.closest(".react-datepicker")),
109
+ ref: ref,
110
+ type: "button",
111
+ children: [/*#__PURE__*/jsxRuntime.jsx(typography.Typography, {
112
+ size: "small",
113
+ type: "body",
114
+ weight: "semibold",
115
+ children: date.toLocaleDateString(locale.code ?? "ko-KR", {
116
+ year: "numeric",
117
+ month: "long"
118
+ })
119
+ }), /*#__PURE__*/jsxRuntime.jsx(reactIcons.ArrowDropDownIcon, {
120
+ "aria-hidden": true,
121
+ size: 16
122
+ })]
123
+ });
124
+ }
125
+ /** The year's twelve months, with the year paged by the header's arrows. */
126
+ function YearMonthView({
127
+ currentMonthRef,
128
+ hidden,
129
+ locale,
130
+ maxDate,
131
+ minDate,
132
+ minHeight,
133
+ onBack,
134
+ onPick,
135
+ onYearChange,
136
+ selected,
137
+ viewDate
138
+ }) {
139
+ const year = viewDate.getFullYear();
140
+ const monthDisabled = month => {
141
+ const first = dateFns.startOfMonth(new Date(year, month, 1));
142
+ return minDate !== undefined && dateFns.endOfMonth(first) < minDate || maxDate !== undefined && first > maxDate;
143
+ };
144
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
145
+ className: yearMonthView_module.monthView,
146
+ hidden: hidden,
147
+ style: {
148
+ minHeight
149
+ },
150
+ children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
151
+ className: yearMonthView_module.monthHeader,
152
+ children: [/*#__PURE__*/jsxRuntime.jsxs("button", {
153
+ "aria-label": "Back to days",
154
+ className: yearMonthView_module.title,
155
+ onClick: onBack,
156
+ type: "button",
157
+ children: [/*#__PURE__*/jsxRuntime.jsx(typography.Typography, {
158
+ size: "small",
159
+ type: "body",
160
+ weight: "semibold",
161
+ children: viewDate.toLocaleDateString(locale.code ?? "ko-KR", {
162
+ year: "numeric"
163
+ })
164
+ }), /*#__PURE__*/jsxRuntime.jsx(reactIcons.ArrowDropUpIcon, {
165
+ "aria-hidden": true,
166
+ size: 16
167
+ })]
168
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
169
+ className: yearMonthView_module.menu,
170
+ children: [/*#__PURE__*/jsxRuntime.jsx(button.Button, {
171
+ "aria-label": "Previous year",
172
+ className: yearMonthView_module.arrow,
173
+ disabled: minDate !== undefined && year - 1 < minDate.getFullYear(),
174
+ onClick: () => onYearChange(new Date(year - 1, 0, 1)),
175
+ size: "x-small",
176
+ svgOnly: true,
177
+ type: "button",
178
+ variant: "outline",
179
+ children: /*#__PURE__*/jsxRuntime.jsx(reactIcons.ArrowIOSBackwardIcon, {})
180
+ }), /*#__PURE__*/jsxRuntime.jsx(button.Button, {
181
+ "aria-label": "Next year",
182
+ className: yearMonthView_module.arrow,
183
+ disabled: maxDate !== undefined && year + 1 > maxDate.getFullYear(),
184
+ onClick: () => onYearChange(new Date(year + 1, 0, 1)),
185
+ size: "x-small",
186
+ svgOnly: true,
187
+ type: "button",
188
+ variant: "outline",
189
+ children: /*#__PURE__*/jsxRuntime.jsx(reactIcons.ArrowIOSForwardIcon, {})
190
+ })]
191
+ })]
192
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
193
+ className: yearMonthView_module.monthGrid,
194
+ children: MONTHS.map(month => {
195
+ const current = selected != null && selected.getFullYear() === year && selected.getMonth() === month;
196
+ const isViewed = viewDate.getMonth() === month;
197
+ return /*#__PURE__*/jsxRuntime.jsx("button", {
198
+ "aria-current": current ? "date" : undefined,
199
+ className: yearMonthView_module.monthCell,
200
+ "data-selected": current || undefined,
201
+ disabled: monthDisabled(month),
202
+ onClick: () => onPick(year, month),
203
+ ref: isViewed ? currentMonthRef : undefined,
204
+ type: "button",
205
+ children: dateFns.format(new Date(year, month, 1), "LLL", {
206
+ locale
207
+ })
208
+ }, month);
209
+ })
210
+ })]
211
+ });
212
+ }
213
+
214
+ exports.CalendarTitle = CalendarTitle;
215
+ exports.YearMonthView = YearMonthView;
216
+ exports.useYearMonthView = useYearMonthView;