@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.
- package/dist/cjs/components/date-time-picker/date-time-picker.js +99 -76
- package/dist/cjs/components/day-picker/day-picker.js +24 -137
- package/dist/cjs/components/day-picker/day-picker.module.css.js +2 -2
- package/dist/cjs/components/picker/year-month-view.js +216 -0
- package/dist/cjs/components/picker/year-month-view.module.css.js +9 -0
- package/dist/cjs/components/skeleton/skeleton.module.css.js +1 -1
- package/dist/cjs/components/switch/switch.js +4 -5
- package/dist/cjs/components/switch/switch.module.css.js +1 -1
- package/dist/cjs/ecosystem/codegen/generated/switch.css.js +1 -1
- package/dist/cjs/token/color.d.ts +1 -0
- package/dist/cjs/token/color.js +2 -1
- package/dist/esm/components/date-time-picker/date-time-picker.mjs +99 -76
- package/dist/esm/components/day-picker/day-picker.mjs +27 -140
- package/dist/esm/components/day-picker/day-picker.module.css.mjs +1 -1
- package/dist/esm/components/picker/year-month-view.mjs +212 -0
- package/dist/esm/components/picker/year-month-view.module.css.mjs +3 -0
- package/dist/esm/components/switch/switch.mjs +4 -5
- package/dist/esm/index.css +1 -1
- package/dist/esm/token/color.d.mts +1 -0
- package/dist/esm/token/color.mjs +2 -1
- package/package.json +2 -2
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var styleInject_es = require('../../node_modules/.pnpm/style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js');
|
|
4
|
+
|
|
5
|
+
var css_248z = "@layer components{.year-month-view-module_title__xCQjI{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)}.year-month-view-module_monthCell__Tju2y:focus-visible,.year-month-view-module_title__xCQjI:focus-visible{outline:2px solid var(--cocso-color-focus-ring);outline-offset:2px}.year-month-view-module_menu__WInY3{align-items:center;display:flex;gap:var(--cocso-spacing-3);justify-content:center}.year-month-view-module_arrow__oIH1T{height:24px;width:24px}.year-month-view-module_monthView__6rbV7{display:flex;flex-direction:column}.year-month-view-module_monthView__6rbV7[hidden]{display:none}.year-month-view-module_monthHeader__3ZcdS{align-items:center;display:flex;justify-content:space-between;padding-bottom:var(--cocso-spacing-5);width:100%}.year-month-view-module_monthGrid__jGMsB{display:grid;flex:1;gap:var(--cocso-spacing-3);grid-auto-rows:1fr;grid-template-columns:repeat(3,1fr)}.year-month-view-module_monthCell__Tju2y{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)}.year-month-view-module_monthCell__Tju2y[data-selected]{background-color:var(--cocso-color-interactive-primary);color:var(--cocso-color-text-on-primary);font-weight:var(--cocso-font-weight-semibold)}.year-month-view-module_monthCell__Tju2y:disabled{cursor:not-allowed;opacity:.4}@media (hover:hover) and (pointer:fine){.year-month-view-module_monthCell__Tju2y:not(:disabled):hover,.year-month-view-module_title__xCQjI:hover{background-color:var(--cocso-color-interactive-secondary)}.year-month-view-module_monthCell__Tju2y[data-selected]:not(:disabled):hover{background-color:var(--cocso-color-interactive-primary-hover)}}}";
|
|
6
|
+
var styles = {"title":"year-month-view-module_title__xCQjI","monthCell":"year-month-view-module_monthCell__Tju2y","menu":"year-month-view-module_menu__WInY3","arrow":"year-month-view-module_arrow__oIH1T","monthView":"year-month-view-module_monthView__6rbV7","monthHeader":"year-month-view-module_monthHeader__3ZcdS","monthGrid":"year-month-view-module_monthGrid__jGMsB"};
|
|
7
|
+
styleInject_es(css_248z);
|
|
8
|
+
|
|
9
|
+
module.exports = styles;
|
|
@@ -2,7 +2,7 @@
|
|
|
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{.skeleton-module_skeleton__fula5{background-color:var(--cocso-skeleton-bg-color);border-radius:var(--cocso-skeleton-border-radius);height:var(--cocso-skeleton-height);width:var(--cocso-skeleton-width,100%)}.skeleton-module_pulse__YLysm{animation:skeleton-module_skeleton-pulse__Yp45W var(--cocso-duration-decorative-slow) var(--cocso-easing-default) infinite}.skeleton-module_wave__GxWJ1{overflow:hidden;position:relative}.skeleton-module_wave__GxWJ1:after{animation:skeleton-module_skeleton-wave__zaVNu var(--cocso-duration-decorative-slow) var(--cocso-easing-default) infinite;background:linear-gradient(90deg,transparent,hsla(0,0%,100%,.4),transparent);content:\"\";inset:0;position:absolute}@keyframes skeleton-module_skeleton-pulse__Yp45W{0%,to{opacity:1}50%{opacity:.4}}@keyframes skeleton-module_skeleton-wave__zaVNu{0%{transform:translateX(-100%)}to{transform:translateX(100%)}}@media (prefers-reduced-motion:reduce){.skeleton-module_pulse__YLysm,.skeleton-module_wave__GxWJ1:after{animation:none}}}";
|
|
5
|
+
var css_248z = "@layer components{.skeleton-module_skeleton__fula5{--cocso-skeleton-edge-fade-size:min(var(--cocso-skeleton-edge-fade,12px),25%);background-color:var(--cocso-skeleton-bg-color);border-radius:var(--cocso-skeleton-border-radius);height:var(--cocso-skeleton-height);mask-composite:intersect;mask-image:linear-gradient(to right,transparent,#000 var(--cocso-skeleton-edge-fade-size),#000 calc(100% - var(--cocso-skeleton-edge-fade-size)),transparent),linear-gradient(to bottom,transparent,#000 var(--cocso-skeleton-edge-fade-size),#000 calc(100% - var(--cocso-skeleton-edge-fade-size)),transparent);width:var(--cocso-skeleton-width,100%)}.cocso-skeleton--variant-circular.skeleton-module_skeleton__fula5{mask-composite:add;mask-image:radial-gradient(closest-side,#000 calc(100% - var(--cocso-skeleton-edge-fade, 12px)),transparent)}.skeleton-module_pulse__YLysm{animation:skeleton-module_skeleton-pulse__Yp45W var(--cocso-duration-decorative-slow) var(--cocso-easing-default) infinite}.skeleton-module_wave__GxWJ1{overflow:hidden;position:relative}.skeleton-module_wave__GxWJ1:after{animation:skeleton-module_skeleton-wave__zaVNu var(--cocso-duration-decorative-slow) var(--cocso-easing-default) infinite;background:linear-gradient(90deg,transparent,hsla(0,0%,100%,.4),transparent);content:\"\";inset:0;position:absolute}@keyframes skeleton-module_skeleton-pulse__Yp45W{0%,to{opacity:1}50%{opacity:.4}}@keyframes skeleton-module_skeleton-wave__zaVNu{0%{transform:translateX(-100%)}to{transform:translateX(100%)}}@media (prefers-reduced-motion:reduce){.skeleton-module_pulse__YLysm,.skeleton-module_wave__GxWJ1:after{animation:none}}}";
|
|
6
6
|
var styles = {"skeleton":"skeleton-module_skeleton__fula5","pulse":"skeleton-module_pulse__YLysm","wave":"skeleton-module_wave__GxWJ1"};
|
|
7
7
|
styleInject_es(css_248z);
|
|
8
8
|
|
|
@@ -11,11 +11,10 @@ var color = require('../../token/color.js');
|
|
|
11
11
|
var typography = require('../typography/typography.js');
|
|
12
12
|
var _switch$1 = require('@base-ui/react/switch');
|
|
13
13
|
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
// page
|
|
17
|
-
|
|
18
|
-
const UNCHECKED_BG = color.colors.surfaceNeutral;
|
|
14
|
+
// A semantic token, not a raw ramp entry: the raw ramp keeps its light value
|
|
15
|
+
// when the theme flips. The off track is a solid fill that clears 3:1 against
|
|
16
|
+
// the page and the thumb on its own, so it draws no outline.
|
|
17
|
+
const UNCHECKED_BG = color.colors.interactiveControlOff;
|
|
19
18
|
/** Toggle switch component with optional label and size options. */
|
|
20
19
|
function Switch({
|
|
21
20
|
ref,
|
|
@@ -2,7 +2,7 @@
|
|
|
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{.switch-module_wrapper__mB3eH{align-items:center;display:flex;gap:var(--cocso-spacing-5);min-height:24px}.switch-module_wrapper__mB3eH[data-disabled]{cursor:not-allowed;opacity:.4}.switch-module_switch__KrHDz{--cocso-switch-width:inherit;--cocso-switch-height:inherit;--cocso-switch-bg-color:inherit;background-color:var(--cocso-switch-bg-color);border-radius:var(--cocso-radius-full);
|
|
5
|
+
var css_248z = "@layer components{.switch-module_wrapper__mB3eH{align-items:center;display:flex;gap:var(--cocso-spacing-5);min-height:24px}.switch-module_wrapper__mB3eH[data-disabled]{cursor:not-allowed;opacity:.4}.switch-module_switch__KrHDz{--cocso-switch-width:inherit;--cocso-switch-height:inherit;--cocso-switch-bg-color:inherit;background-color:var(--cocso-switch-bg-color);border-radius:var(--cocso-radius-full);cursor:pointer;height:var(--cocso-switch-height);opacity:1;position:relative;width:var(--cocso-switch-width)}.switch-module_switch__KrHDz:focus-visible{outline:2px solid var(--cocso-color-focus-ring);outline-offset:2px}.switch-module_switch__KrHDz[data-disabled]{cursor:not-allowed;opacity:.4}.switch-module_switch__KrHDz[data-checked]{--cocso-switch-bg-color:var(--cocso-switch-checked-bg-color)}.switch-module_thumb__sXgSl{--cocso-switch-thumb-size:inherit;background-color:var(--cocso-switch-thumb-color);border-radius:var(--cocso-radius-full);box-shadow:var(--cocso-shadow-thumb);display:block;height:var(--cocso-switch-thumb-size);position:absolute;top:50%;transform:translate(var(--cocso-switch-thumb-offset),-50%);transition:transform var(--cocso-duration-fast) var(--cocso-easing-soft);width:var(--cocso-switch-thumb-size);will-change:transform}.switch-module_thumb__sXgSl[data-checked]{transform:translate(calc(var(--cocso-switch-width) - var(--cocso-switch-thumb-size) - var(--cocso-switch-thumb-offset)),-50%)}@media (prefers-reduced-motion:reduce){.switch-module_thumb__sXgSl{transition:none}}}";
|
|
6
6
|
var styles = {"wrapper":"switch-module_wrapper__mB3eH","switch":"switch-module_switch__KrHDz","thumb":"switch-module_thumb__sXgSl"};
|
|
7
7
|
styleInject_es(css_248z);
|
|
8
8
|
|
|
@@ -2,5 +2,5 @@
|
|
|
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 = ".cocso-switch{--cocso-switch-thumb-color:var(--cocso-color-text-on-primary);--cocso-switch-switch-bg-color:var(--cocso-color-
|
|
5
|
+
var css_248z = ".cocso-switch{--cocso-switch-thumb-color:var(--cocso-color-text-on-primary);--cocso-switch-switch-bg-color:var(--cocso-color-interactive-control-off)}.cocso-switch:where(.cocso-switch--variant-primary){--cocso-switch-checked-bg-color:var(--cocso-color-interactive-primary);--cocso-switch-switch-bg-color-hover:var(--cocso-color-interactive-primary-hover)}.cocso-switch:where(.cocso-switch--variant-success){--cocso-switch-checked-bg-color:var(--cocso-color-interactive-success);--cocso-switch-switch-bg-color-hover:var(--cocso-color-interactive-success-hover-subtle)}.cocso-switch:where(.cocso-switch--variant-error){--cocso-switch-checked-bg-color:var(--cocso-color-interactive-danger);--cocso-switch-switch-bg-color-hover:var(--cocso-color-interactive-danger-hover-subtle)}.cocso-switch:where(.cocso-switch--variant-warning){--cocso-switch-checked-bg-color:var(--cocso-color-interactive-warning-active);--cocso-switch-switch-bg-color-hover:var(--cocso-color-interactive-warning-hover-subtle)}.cocso-switch:where(.cocso-switch--variant-info){--cocso-switch-checked-bg-color:var(--cocso-color-interactive-info);--cocso-switch-switch-bg-color-hover:var(--cocso-color-interactive-info-hover-subtle)}.cocso-switch:where(.cocso-switch--size-large){--cocso-switch-width:40px;--cocso-switch-height:22px;--cocso-switch-thumb-size:18px;--cocso-switch-thumb-offset:2px}.cocso-switch:where(.cocso-switch--size-medium){--cocso-switch-width:36px;--cocso-switch-height:20px;--cocso-switch-thumb-size:16px;--cocso-switch-thumb-offset:2px}.cocso-switch:where(.cocso-switch--size-small){--cocso-switch-width:32px;--cocso-switch-height:18px;--cocso-switch-thumb-size:14px;--cocso-switch-thumb-offset:2px}.cocso-switch:where(.cocso-switch--variant-primary.cocso-switch--checked-true){--cocso-switch-switch-bg-color:var(--cocso-color-interactive-primary)}.cocso-switch:where(.cocso-switch--variant-success.cocso-switch--checked-true){--cocso-switch-switch-bg-color:var(--cocso-color-interactive-success)}.cocso-switch:where(.cocso-switch--variant-error.cocso-switch--checked-true){--cocso-switch-switch-bg-color:var(--cocso-color-interactive-danger)}.cocso-switch:where(.cocso-switch--variant-warning.cocso-switch--checked-true){--cocso-switch-switch-bg-color:var(--cocso-color-interactive-warning-active)}.cocso-switch:where(.cocso-switch--variant-info.cocso-switch--checked-true){--cocso-switch-switch-bg-color:var(--cocso-color-interactive-info)}.cocso-switch:where(.cocso-switch--checked-false){--cocso-switch-switch-bg-color-hover:var(--cocso-color-interactive-control-off-hover)}";
|
|
6
6
|
styleInject_es(css_248z);
|
package/dist/cjs/token/color.js
CHANGED
|
@@ -112,7 +112,8 @@ const colors = {
|
|
|
112
112
|
textSecondary: "var(--cocso-color-text-secondary)",
|
|
113
113
|
textTertiary: "var(--cocso-color-text-tertiary)",
|
|
114
114
|
textOnPrimary: "var(--cocso-color-text-on-primary)",
|
|
115
|
-
surfaceNeutral: "var(--cocso-color-surface-neutral)"
|
|
115
|
+
surfaceNeutral: "var(--cocso-color-surface-neutral)",
|
|
116
|
+
interactiveControlOff: "var(--cocso-color-interactive-control-off)"
|
|
116
117
|
};
|
|
117
118
|
|
|
118
119
|
exports.colors = colors;
|
|
@@ -5,11 +5,11 @@ import { ko } from 'date-fns/locale';
|
|
|
5
5
|
import { useState, useMemo } from 'react';
|
|
6
6
|
import DatePicker from 'react-datepicker';
|
|
7
7
|
import { cn } from '../../cn.mjs';
|
|
8
|
+
import { useYearMonthView, YearMonthView, CalendarTitle } from '../picker/year-month-view.mjs';
|
|
8
9
|
import styles from './date-time-picker.module.css.mjs';
|
|
9
10
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
10
11
|
import { Popover } from '../popover/popover.mjs';
|
|
11
12
|
import { Button } from '../button/button.mjs';
|
|
12
|
-
import { Typography } from '../typography/typography.mjs';
|
|
13
13
|
|
|
14
14
|
const isSameDay = (a, b) => a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
|
|
15
15
|
const atTime = (day, hours, minutes) => {
|
|
@@ -57,14 +57,24 @@ function DateTimePicker({
|
|
|
57
57
|
const [draft, setDraft] = useState(null);
|
|
58
58
|
const selected = value ?? draft;
|
|
59
59
|
|
|
60
|
-
// The month to open on: `minDate`'s
|
|
61
|
-
|
|
60
|
+
// The month to open on: the selection's, else `minDate`'s if it is still
|
|
61
|
+
// ahead of today, else today's.
|
|
62
|
+
const openingMonth = () => {
|
|
62
63
|
if (selected) {
|
|
63
|
-
return
|
|
64
|
+
return selected;
|
|
64
65
|
}
|
|
65
66
|
const now = new Date();
|
|
66
|
-
return minDate && minDate.getTime() > now.getTime() ? minDate :
|
|
67
|
-
}
|
|
67
|
+
return minDate && minDate.getTime() > now.getTime() ? minDate : now;
|
|
68
|
+
};
|
|
69
|
+
// The header opens a year-and-month grid, as in DayPicker — a date years
|
|
70
|
+
// away is a few clicks instead of one per month.
|
|
71
|
+
const calendar = useYearMonthView(openingMonth);
|
|
72
|
+
const handleOpenChange = next => {
|
|
73
|
+
setOpen(next);
|
|
74
|
+
if (next) {
|
|
75
|
+
calendar.reset(openingMonth());
|
|
76
|
+
}
|
|
77
|
+
};
|
|
68
78
|
|
|
69
79
|
// A bound that only applies on the day it falls on: on any other day the
|
|
70
80
|
// whole day is open. Without this a `minDate` of 3pm today would also cut
|
|
@@ -105,7 +115,7 @@ function DateTimePicker({
|
|
|
105
115
|
ref: ref,
|
|
106
116
|
...props,
|
|
107
117
|
children: /*#__PURE__*/jsxs(Popover, {
|
|
108
|
-
onOpenChange:
|
|
118
|
+
onOpenChange: handleOpenChange,
|
|
109
119
|
open: open,
|
|
110
120
|
children: [/*#__PURE__*/jsx(Popover.Trigger, {
|
|
111
121
|
render: trigger ?? /*#__PURE__*/jsx(Button, {
|
|
@@ -116,81 +126,94 @@ function DateTimePicker({
|
|
|
116
126
|
locale
|
|
117
127
|
}) : "Select date and time"
|
|
118
128
|
})
|
|
119
|
-
}), /*#__PURE__*/
|
|
129
|
+
}), /*#__PURE__*/jsxs(Popover.Content, {
|
|
120
130
|
"aria-label": "Select date and time",
|
|
121
131
|
className: styles.content,
|
|
122
|
-
children: /*#__PURE__*/jsx(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const day = date.getDay();
|
|
126
|
-
if (day === 0) {
|
|
127
|
-
return styles.sunday;
|
|
128
|
-
}
|
|
129
|
-
if (day === 6) {
|
|
130
|
-
return styles.saturday;
|
|
131
|
-
}
|
|
132
|
-
return "";
|
|
133
|
-
},
|
|
134
|
-
disabled: disabled,
|
|
135
|
-
filterTime: filterTime
|
|
136
|
-
// Six weeks always, for the same reason as DayPicker: a five-week month made
|
|
137
|
-
// the panel shorter, and paging into a six-week one could flip it above the trigger.
|
|
138
|
-
,
|
|
139
|
-
fixedHeight: true,
|
|
140
|
-
inline: true,
|
|
132
|
+
children: [/*#__PURE__*/jsx(YearMonthView, {
|
|
133
|
+
currentMonthRef: calendar.currentMonthRef,
|
|
134
|
+
hidden: calendar.view !== "month",
|
|
141
135
|
locale: locale,
|
|
142
136
|
maxDate: maxDate,
|
|
143
|
-
maxTime: bounds.maxTime,
|
|
144
137
|
minDate: minDate,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
138
|
+
minHeight: calendar.dayViewHeight,
|
|
139
|
+
onBack: () => calendar.changeView("day"),
|
|
140
|
+
onPick: calendar.jumpTo,
|
|
141
|
+
onYearChange: calendar.setViewDate,
|
|
142
|
+
selected: selected,
|
|
143
|
+
viewDate: calendar.viewDate
|
|
144
|
+
}), /*#__PURE__*/jsx("div", {
|
|
145
|
+
hidden: calendar.view !== "day",
|
|
146
|
+
children: /*#__PURE__*/jsx(DatePicker, {
|
|
147
|
+
dateFormat: dateFormat,
|
|
148
|
+
dayClassName: date => {
|
|
149
|
+
const day = date.getDay();
|
|
150
|
+
if (day === 0) {
|
|
151
|
+
return styles.sunday;
|
|
152
|
+
}
|
|
153
|
+
if (day === 6) {
|
|
154
|
+
return styles.saturday;
|
|
155
|
+
}
|
|
156
|
+
return "";
|
|
157
|
+
},
|
|
158
|
+
disabled: disabled,
|
|
159
|
+
filterTime: filterTime
|
|
160
|
+
// Six weeks always, for the same reason as DayPicker: a five-week month made
|
|
161
|
+
// the panel shorter, and paging into a six-week one could flip it above the trigger.
|
|
162
|
+
,
|
|
163
|
+
fixedHeight: true,
|
|
164
|
+
inline: true,
|
|
165
|
+
locale: locale,
|
|
166
|
+
maxDate: maxDate,
|
|
167
|
+
maxTime: bounds.maxTime,
|
|
168
|
+
minDate: minDate,
|
|
169
|
+
minTime: bounds.minTime,
|
|
170
|
+
onChange: handleChange,
|
|
171
|
+
onMonthChange: calendar.setViewDate,
|
|
172
|
+
openToDate: calendar.viewDate,
|
|
173
|
+
renderCustomHeader: ({
|
|
174
|
+
date,
|
|
175
|
+
decreaseMonth,
|
|
176
|
+
increaseMonth,
|
|
177
|
+
prevMonthButtonDisabled,
|
|
178
|
+
nextMonthButtonDisabled
|
|
179
|
+
}) => /*#__PURE__*/jsxs(Fragment, {
|
|
180
|
+
children: [/*#__PURE__*/jsx(CalendarTitle, {
|
|
181
|
+
date: date,
|
|
182
|
+
locale: locale,
|
|
183
|
+
onPress: panel => calendar.openMonths(date, panel),
|
|
184
|
+
ref: calendar.titleRef
|
|
185
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
186
|
+
className: styles.menu,
|
|
187
|
+
children: [/*#__PURE__*/jsx(Button, {
|
|
188
|
+
"aria-label": "Previous month",
|
|
189
|
+
className: styles.arrow,
|
|
190
|
+
disabled: prevMonthButtonDisabled,
|
|
191
|
+
onClick: decreaseMonth,
|
|
192
|
+
size: "x-small",
|
|
193
|
+
svgOnly: true,
|
|
194
|
+
type: "button",
|
|
195
|
+
variant: "outline",
|
|
196
|
+
children: /*#__PURE__*/jsx(ArrowIOSBackwardIcon, {})
|
|
197
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
198
|
+
"aria-label": "Next month",
|
|
199
|
+
className: styles.arrow,
|
|
200
|
+
disabled: nextMonthButtonDisabled,
|
|
201
|
+
onClick: increaseMonth,
|
|
202
|
+
size: "x-small",
|
|
203
|
+
svgOnly: true,
|
|
204
|
+
type: "button",
|
|
205
|
+
variant: "outline",
|
|
206
|
+
children: /*#__PURE__*/jsx(ArrowIOSForwardIcon, {})
|
|
207
|
+
})]
|
|
185
208
|
})]
|
|
186
|
-
})
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
})
|
|
209
|
+
}),
|
|
210
|
+
selected: selected ?? undefined,
|
|
211
|
+
showPopperArrow: false,
|
|
212
|
+
showTimeSelect: true,
|
|
213
|
+
timeCaption: timeCaption,
|
|
214
|
+
timeIntervals: timeIntervals
|
|
215
|
+
}, calendar.calendarKey)
|
|
216
|
+
})]
|
|
194
217
|
})]
|
|
195
218
|
})
|
|
196
219
|
});
|
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import { format
|
|
2
|
+
import { ArrowIOSBackwardIcon, ArrowIOSForwardIcon } from '@cocso-ui/react-icons';
|
|
3
|
+
import { format } from 'date-fns';
|
|
4
4
|
import { ko } from 'date-fns/locale';
|
|
5
|
-
import { useState
|
|
5
|
+
import { useState } from 'react';
|
|
6
6
|
import DatePicker from 'react-datepicker';
|
|
7
7
|
import { cn } from '../../cn.mjs';
|
|
8
|
+
import { useYearMonthView, YearMonthView, CalendarTitle } from '../picker/year-month-view.mjs';
|
|
8
9
|
import styles from './day-picker.module.css.mjs';
|
|
9
10
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
10
11
|
import { Popover } from '../popover/popover.mjs';
|
|
11
12
|
import { Button } from '../button/button.mjs';
|
|
12
|
-
import { Typography } from '../typography/typography.mjs';
|
|
13
|
-
|
|
14
|
-
const MONTHS = Array.from({
|
|
15
|
-
length: 12
|
|
16
|
-
}, (_, month) => month);
|
|
17
13
|
|
|
18
14
|
// Where the calendar opens: the value's month, else today's, pulled inside
|
|
19
15
|
// the bounds so an empty picker with a future `minDate` does not open on a
|
|
@@ -47,54 +43,17 @@ function DayPicker({
|
|
|
47
43
|
const [open, setOpen] = useState(false);
|
|
48
44
|
// The header's month opens a year-and-month grid in the same panel, so a
|
|
49
45
|
// date years away is a few clicks instead of one click per month.
|
|
50
|
-
const
|
|
51
|
-
const [viewDate, setViewDate] = useState(() => initialViewDate(value, minDate, maxDate));
|
|
52
|
-
// Remounts the calendar after a jump. A live calendar follows its keyboard
|
|
53
|
-
// cursor before `openToDate`, so a fresh mount is the reliable way to land
|
|
54
|
-
// on the picked month.
|
|
55
|
-
const [calendarKey, setCalendarKey] = useState(0);
|
|
56
|
-
// The day grid's height, held by the month grid so the panel does not
|
|
57
|
-
// shrink under the pointer — a panel opened above its trigger would jump.
|
|
58
|
-
const [dayViewHeight, setDayViewHeight] = useState();
|
|
59
|
-
const focusAfterViewChange = useRef(false);
|
|
60
|
-
const titleRef = useRef(null);
|
|
61
|
-
const currentMonthRef = useRef(null);
|
|
62
|
-
|
|
63
|
-
// A view change unmounts the control that had focus. Hand it to the
|
|
64
|
-
// matching control in the new view instead of dropping it on the body.
|
|
65
|
-
useEffect(() => {
|
|
66
|
-
if (!focusAfterViewChange.current) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
focusAfterViewChange.current = false;
|
|
70
|
-
(view === "month" ? currentMonthRef : titleRef).current?.focus();
|
|
71
|
-
}, [view]);
|
|
46
|
+
const calendar = useYearMonthView(() => initialViewDate(value, minDate, maxDate));
|
|
72
47
|
const handleOpenChange = next => {
|
|
73
48
|
setOpen(next);
|
|
74
49
|
if (next) {
|
|
75
|
-
|
|
76
|
-
setViewDate(initialViewDate(value, minDate, maxDate));
|
|
77
|
-
setCalendarKey(key => key + 1);
|
|
50
|
+
calendar.reset(initialViewDate(value, minDate, maxDate));
|
|
78
51
|
}
|
|
79
52
|
};
|
|
80
53
|
const handleChange = date => {
|
|
81
54
|
onValueChange?.(date);
|
|
82
55
|
setOpen(false);
|
|
83
56
|
};
|
|
84
|
-
const changeView = next => {
|
|
85
|
-
focusAfterViewChange.current = true;
|
|
86
|
-
setView(next);
|
|
87
|
-
};
|
|
88
|
-
const jumpTo = (year, month) => {
|
|
89
|
-
setViewDate(new Date(year, month, 1));
|
|
90
|
-
setCalendarKey(key => key + 1);
|
|
91
|
-
changeView("day");
|
|
92
|
-
};
|
|
93
|
-
const year = viewDate.getFullYear();
|
|
94
|
-
const monthDisabled = month => {
|
|
95
|
-
const first = startOfMonth(new Date(year, month, 1));
|
|
96
|
-
return minDate !== undefined && endOfMonth(first) < minDate || maxDate !== undefined && first > maxDate;
|
|
97
|
-
};
|
|
98
57
|
return /*#__PURE__*/jsx("div", {
|
|
99
58
|
className: cn(styles.root, className),
|
|
100
59
|
ref: ref,
|
|
@@ -114,75 +73,20 @@ function DayPicker({
|
|
|
114
73
|
}), /*#__PURE__*/jsxs(Popover.Content, {
|
|
115
74
|
"aria-label": "Select date",
|
|
116
75
|
className: styles.content,
|
|
117
|
-
children: [/*#__PURE__*/
|
|
118
|
-
|
|
119
|
-
hidden: view !== "month",
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
type: "button",
|
|
130
|
-
children: [/*#__PURE__*/jsx(Typography, {
|
|
131
|
-
size: "small",
|
|
132
|
-
type: "body",
|
|
133
|
-
weight: "semibold",
|
|
134
|
-
children: viewDate.toLocaleDateString(locale.code ?? "ko-KR", {
|
|
135
|
-
year: "numeric"
|
|
136
|
-
})
|
|
137
|
-
}), /*#__PURE__*/jsx(ArrowDropUpIcon, {
|
|
138
|
-
"aria-hidden": true,
|
|
139
|
-
size: 16
|
|
140
|
-
})]
|
|
141
|
-
}), /*#__PURE__*/jsxs("div", {
|
|
142
|
-
className: styles.menu,
|
|
143
|
-
children: [/*#__PURE__*/jsx(Button, {
|
|
144
|
-
"aria-label": "Previous year",
|
|
145
|
-
className: styles.arrow,
|
|
146
|
-
disabled: minDate !== undefined && year - 1 < minDate.getFullYear(),
|
|
147
|
-
onClick: () => setViewDate(new Date(year - 1, 0, 1)),
|
|
148
|
-
size: "x-small",
|
|
149
|
-
svgOnly: true,
|
|
150
|
-
type: "button",
|
|
151
|
-
variant: "outline",
|
|
152
|
-
children: /*#__PURE__*/jsx(ArrowIOSBackwardIcon, {})
|
|
153
|
-
}), /*#__PURE__*/jsx(Button, {
|
|
154
|
-
"aria-label": "Next year",
|
|
155
|
-
className: styles.arrow,
|
|
156
|
-
disabled: maxDate !== undefined && year + 1 > maxDate.getFullYear(),
|
|
157
|
-
onClick: () => setViewDate(new Date(year + 1, 0, 1)),
|
|
158
|
-
size: "x-small",
|
|
159
|
-
svgOnly: true,
|
|
160
|
-
type: "button",
|
|
161
|
-
variant: "outline",
|
|
162
|
-
children: /*#__PURE__*/jsx(ArrowIOSForwardIcon, {})
|
|
163
|
-
})]
|
|
164
|
-
})]
|
|
165
|
-
}), /*#__PURE__*/jsx("div", {
|
|
166
|
-
className: styles.monthGrid,
|
|
167
|
-
children: MONTHS.map(month => {
|
|
168
|
-
const current = value !== undefined && value.getFullYear() === year && value.getMonth() === month;
|
|
169
|
-
const isViewed = viewDate.getMonth() === month;
|
|
170
|
-
return /*#__PURE__*/jsx("button", {
|
|
171
|
-
"aria-current": current ? "date" : undefined,
|
|
172
|
-
className: styles.monthCell,
|
|
173
|
-
"data-selected": current || undefined,
|
|
174
|
-
disabled: monthDisabled(month),
|
|
175
|
-
onClick: () => jumpTo(year, month),
|
|
176
|
-
ref: isViewed ? currentMonthRef : undefined,
|
|
177
|
-
type: "button",
|
|
178
|
-
children: format(new Date(year, month, 1), "LLL", {
|
|
179
|
-
locale
|
|
180
|
-
})
|
|
181
|
-
}, month);
|
|
182
|
-
})
|
|
183
|
-
})]
|
|
76
|
+
children: [/*#__PURE__*/jsx(YearMonthView, {
|
|
77
|
+
currentMonthRef: calendar.currentMonthRef,
|
|
78
|
+
hidden: calendar.view !== "month",
|
|
79
|
+
locale: locale,
|
|
80
|
+
maxDate: maxDate,
|
|
81
|
+
minDate: minDate,
|
|
82
|
+
minHeight: calendar.dayViewHeight,
|
|
83
|
+
onBack: () => calendar.changeView("day"),
|
|
84
|
+
onPick: calendar.jumpTo,
|
|
85
|
+
onYearChange: calendar.setViewDate,
|
|
86
|
+
selected: value,
|
|
87
|
+
viewDate: calendar.viewDate
|
|
184
88
|
}), /*#__PURE__*/jsx("div", {
|
|
185
|
-
hidden: view !== "day",
|
|
89
|
+
hidden: calendar.view !== "day",
|
|
186
90
|
children: /*#__PURE__*/jsx(DatePicker, {
|
|
187
91
|
dateFormat: dateFormat,
|
|
188
92
|
dayClassName: date => {
|
|
@@ -207,8 +111,8 @@ function DayPicker({
|
|
|
207
111
|
maxDate: maxDate,
|
|
208
112
|
minDate: minDate,
|
|
209
113
|
onChange: handleChange,
|
|
210
|
-
onMonthChange: setViewDate,
|
|
211
|
-
openToDate: viewDate,
|
|
114
|
+
onMonthChange: calendar.setViewDate,
|
|
115
|
+
openToDate: calendar.viewDate,
|
|
212
116
|
renderCustomHeader: ({
|
|
213
117
|
date,
|
|
214
118
|
decreaseMonth,
|
|
@@ -216,28 +120,11 @@ function DayPicker({
|
|
|
216
120
|
prevMonthButtonDisabled,
|
|
217
121
|
nextMonthButtonDisabled
|
|
218
122
|
}) => /*#__PURE__*/jsxs(Fragment, {
|
|
219
|
-
children: [/*#__PURE__*/
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
setViewDate(date);
|
|
225
|
-
changeView("month");
|
|
226
|
-
},
|
|
227
|
-
ref: titleRef,
|
|
228
|
-
type: "button",
|
|
229
|
-
children: [/*#__PURE__*/jsx(Typography, {
|
|
230
|
-
size: "small",
|
|
231
|
-
type: "body",
|
|
232
|
-
weight: "semibold",
|
|
233
|
-
children: date.toLocaleDateString(locale.code ?? "ko-KR", {
|
|
234
|
-
year: "numeric",
|
|
235
|
-
month: "long"
|
|
236
|
-
})
|
|
237
|
-
}), /*#__PURE__*/jsx(ArrowDropDownIcon, {
|
|
238
|
-
"aria-hidden": true,
|
|
239
|
-
size: 16
|
|
240
|
-
})]
|
|
123
|
+
children: [/*#__PURE__*/jsx(CalendarTitle, {
|
|
124
|
+
date: date,
|
|
125
|
+
locale: locale,
|
|
126
|
+
onPress: panel => calendar.openMonths(date, panel),
|
|
127
|
+
ref: calendar.titleRef
|
|
241
128
|
}), /*#__PURE__*/jsxs("div", {
|
|
242
129
|
className: styles.menu,
|
|
243
130
|
children: [/*#__PURE__*/jsx(Button, {
|
|
@@ -265,7 +152,7 @@ function DayPicker({
|
|
|
265
152
|
}),
|
|
266
153
|
selected: value,
|
|
267
154
|
showPopperArrow: false
|
|
268
|
-
}, calendarKey)
|
|
155
|
+
}, calendar.calendarKey)
|
|
269
156
|
})]
|
|
270
157
|
})]
|
|
271
158
|
})
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
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","
|
|
1
|
+
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"};
|
|
2
2
|
|
|
3
3
|
export { styles as default };
|