@nuvui/date-picker 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +36 -2
- package/dist/components/calendar/calendar.cjs +163 -0
- package/dist/components/calendar/calendar.d.cts +17 -0
- package/dist/components/calendar/calendar.d.ts +17 -0
- package/dist/components/calendar/calendar.js +163 -0
- package/dist/components/calendar/index.cjs +3 -0
- package/dist/components/calendar/index.d.cts +2 -0
- package/dist/components/calendar/index.d.ts +2 -0
- package/dist/components/calendar/index.js +2 -0
- package/dist/components/date-picker/date-picker.cjs +340 -0
- package/dist/components/date-picker/date-picker.d.cts +169 -0
- package/dist/components/date-picker/date-picker.d.ts +169 -0
- package/dist/components/date-picker/date-picker.js +339 -0
- package/dist/components/date-picker/index.cjs +4 -0
- package/dist/components/date-picker/index.d.cts +2 -0
- package/dist/components/date-picker/index.d.ts +2 -0
- package/dist/components/date-picker/index.js +2 -0
- package/dist/components/date-picker/popup.cjs +43 -0
- package/dist/components/date-picker/popup.js +43 -0
- package/dist/css/calendar.css +291 -0
- package/dist/css/date-picker.css +24 -0
- package/dist/index.cjs +13 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +4 -0
- package/dist/locale.cjs +9 -0
- package/dist/locale.d.cts +1 -0
- package/dist/locale.d.ts +1 -0
- package/dist/locale.js +1 -0
- package/dist/styles.css +314 -0
- package/dist/utils/cx.cjs +6 -0
- package/dist/utils/cx.js +6 -0
- package/dist/utils/dates.cjs +59 -0
- package/dist/utils/dates.js +54 -0
- package/dist/utils/use-controlled.cjs +31 -0
- package/dist/utils/use-controlled.js +31 -0
- package/dist/utils/use-date-text.cjs +83 -0
- package/dist/utils/use-date-text.js +83 -0
- package/dist/utils/use-is-phone.cjs +18 -0
- package/dist/utils/use-is-phone.js +18 -0
- package/package.json +118 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nuvraxis
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,37 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nuvui/date-picker
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A calendar, a date field and a date range field for [`@nuvui/react`](https://github.com/Nuvraxis/nuvui/tree/main/packages/ui). The calendar is [react-day-picker](https://daypicker.dev) with nuvui's styles, and the fields are built from nuvui's input group, popover and dialog.
|
|
4
|
+
|
|
5
|
+
This is early, and the package hasn't been released. See the [repository README](https://github.com/Nuvraxis/nuvui#readme) for where things stand.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @nuvui/date-picker @nuvui/react
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import "@nuvui/react/styles.css";
|
|
13
|
+
import "@nuvui/date-picker/styles.css";
|
|
14
|
+
import { DatePicker } from "@nuvui/date-picker";
|
|
15
|
+
|
|
16
|
+
export default function Page() {
|
|
17
|
+
return <DatePicker aria-label="Due date" name="due" />;
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## What's in it
|
|
22
|
+
|
|
23
|
+
- `Calendar`: a month of days to pick from. One day, several, or a range.
|
|
24
|
+
- `DatePicker`: a field a date is typed into, with a button that opens a calendar. In a popover on a wide screen, and in a sheet on a phone. With a `name`, it submits the date as `yyyy-MM-dd`.
|
|
25
|
+
- `DateRangePicker`: a field for each end of a range, and one calendar for both.
|
|
26
|
+
- `@nuvui/date-picker/locale`: every locale react-day-picker has.
|
|
27
|
+
- `TZDate`, from `@date-fns/tz`, for days in a time zone other than the browser's.
|
|
28
|
+
|
|
29
|
+
`@nuvui/react` is a peer dependency. `react-day-picker`, `date-fns` and `@date-fns/tz` are installed with the package.
|
|
30
|
+
|
|
31
|
+
It's a package of its own so that an app which only wants buttons and dialogs doesn't have to install a date library.
|
|
32
|
+
|
|
33
|
+
Docs will live at https://nuvui.nuvraxis.com.
|
|
34
|
+
|
|
35
|
+
## License
|
|
36
|
+
|
|
37
|
+
MIT
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
const require_cx = require("../../utils/cx.cjs");
|
|
3
|
+
let _nuvui_react_direction = require("@nuvui/react/direction");
|
|
4
|
+
let _nuvui_react_select = require("@nuvui/react/select");
|
|
5
|
+
let react = require("react");
|
|
6
|
+
let react_day_picker = require("react-day-picker");
|
|
7
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
|
+
//#region src/components/calendar/calendar.tsx
|
|
9
|
+
const classes = {
|
|
10
|
+
root: "nuv-calendar",
|
|
11
|
+
months: "nuv-calendar__months",
|
|
12
|
+
month: "nuv-calendar__month",
|
|
13
|
+
month_caption: "nuv-calendar__caption",
|
|
14
|
+
caption_label: "nuv-calendar__caption-label",
|
|
15
|
+
nav: "nuv-calendar__nav",
|
|
16
|
+
button_previous: "nuv-calendar__nav-button nuv-calendar__nav-button--previous",
|
|
17
|
+
button_next: "nuv-calendar__nav-button nuv-calendar__nav-button--next",
|
|
18
|
+
chevron: "nuv-calendar__chevron",
|
|
19
|
+
dropdowns: "nuv-calendar__dropdowns",
|
|
20
|
+
dropdown_root: "",
|
|
21
|
+
dropdown: "nuv-calendar__select",
|
|
22
|
+
months_dropdown: "nuv-calendar__select--month",
|
|
23
|
+
years_dropdown: "nuv-calendar__select--year",
|
|
24
|
+
month_grid: "nuv-calendar__grid",
|
|
25
|
+
weekdays: "nuv-calendar__weekdays",
|
|
26
|
+
weekday: "nuv-calendar__weekday",
|
|
27
|
+
weeks: "nuv-calendar__weeks",
|
|
28
|
+
week: "nuv-calendar__week",
|
|
29
|
+
week_number: "nuv-calendar__week-number",
|
|
30
|
+
week_number_header: "nuv-calendar__week-number-header",
|
|
31
|
+
day: "nuv-calendar__day",
|
|
32
|
+
day_button: "nuv-calendar__day-button",
|
|
33
|
+
footer: "nuv-calendar__footer",
|
|
34
|
+
today: "nuv-calendar__day--today",
|
|
35
|
+
outside: "nuv-calendar__day--outside",
|
|
36
|
+
disabled: "nuv-calendar__day--disabled",
|
|
37
|
+
hidden: "nuv-calendar__day--hidden",
|
|
38
|
+
focused: "nuv-calendar__day--focused",
|
|
39
|
+
selected: "nuv-calendar__day--selected",
|
|
40
|
+
range_start: "nuv-calendar__day--range-start",
|
|
41
|
+
range_middle: "nuv-calendar__day--range-middle",
|
|
42
|
+
range_end: "nuv-calendar__day--range-end",
|
|
43
|
+
weeks_before_enter: "",
|
|
44
|
+
weeks_before_exit: "",
|
|
45
|
+
weeks_after_enter: "",
|
|
46
|
+
weeks_after_exit: "",
|
|
47
|
+
caption_after_enter: "",
|
|
48
|
+
caption_after_exit: "",
|
|
49
|
+
caption_before_enter: "",
|
|
50
|
+
caption_before_exit: ""
|
|
51
|
+
};
|
|
52
|
+
const chevrons = {
|
|
53
|
+
left: "M10 3.5 5.5 8l4.5 4.5",
|
|
54
|
+
right: "M6 3.5 10.5 8 6 12.5",
|
|
55
|
+
up: "M3.5 10 8 5.5l4.5 4.5",
|
|
56
|
+
down: "M3.5 6 8 10.5 12.5 6"
|
|
57
|
+
};
|
|
58
|
+
function Chevron({ orientation = "left", className }) {
|
|
59
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
60
|
+
"aria-hidden": "true",
|
|
61
|
+
className,
|
|
62
|
+
viewBox: "0 0 16 16",
|
|
63
|
+
width: "16",
|
|
64
|
+
height: "16",
|
|
65
|
+
fill: "none",
|
|
66
|
+
stroke: "currentColor",
|
|
67
|
+
strokeWidth: "1.5",
|
|
68
|
+
strokeLinecap: "round",
|
|
69
|
+
strokeLinejoin: "round",
|
|
70
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: chevrons[orientation] })
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
const RootRefContext = (0, react.createContext)(void 0);
|
|
74
|
+
function assign(ref, node) {
|
|
75
|
+
if (typeof ref === "function") ref(node);
|
|
76
|
+
else if (ref) ref.current = node;
|
|
77
|
+
}
|
|
78
|
+
function Root({ rootRef, ...props }) {
|
|
79
|
+
const forwarded = (0, react.useContext)(RootRefContext);
|
|
80
|
+
const setRef = (0, react.useCallback)((node) => {
|
|
81
|
+
assign(rootRef, node);
|
|
82
|
+
assign(forwarded, node);
|
|
83
|
+
}, [rootRef, forwarded]);
|
|
84
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
85
|
+
ref: setRef,
|
|
86
|
+
...props
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function Dropdown({ options, value, onChange, disabled, className, style, "aria-label": label }) {
|
|
90
|
+
const { classNames } = (0, react_day_picker.useDayPicker)();
|
|
91
|
+
const selected = options?.find((option) => option.value === value);
|
|
92
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_nuvui_react_select.Select, {
|
|
93
|
+
value: String(value),
|
|
94
|
+
disabled,
|
|
95
|
+
onValueChange: (next) => onChange?.({ target: { value: next } }),
|
|
96
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_nuvui_react_select.SelectTrigger, {
|
|
97
|
+
className: require_cx.cx(classNames.dropdown, className),
|
|
98
|
+
style,
|
|
99
|
+
"aria-label": label,
|
|
100
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_nuvui_react_select.SelectValue, { children: selected?.label })
|
|
101
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_nuvui_react_select.SelectContent, {
|
|
102
|
+
className: "nuv-calendar__options",
|
|
103
|
+
children: options?.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_nuvui_react_select.SelectItem, {
|
|
104
|
+
value: String(option.value),
|
|
105
|
+
disabled: option.disabled,
|
|
106
|
+
children: option.label
|
|
107
|
+
}, option.value))
|
|
108
|
+
})]
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
const parts = {
|
|
112
|
+
Chevron,
|
|
113
|
+
Dropdown,
|
|
114
|
+
Root
|
|
115
|
+
};
|
|
116
|
+
const never = () => () => {};
|
|
117
|
+
function useHydrated() {
|
|
118
|
+
return (0, react.useSyncExternalStore)(never, () => true, () => false);
|
|
119
|
+
}
|
|
120
|
+
const noDay = /* @__PURE__ */ new Date(0);
|
|
121
|
+
const anyMonth = new Date(2001, 6);
|
|
122
|
+
const Calendar = (0, react.forwardRef)(function Calendar({ classNames, components, dir, navLayout = "around", ...props }, ref) {
|
|
123
|
+
const undated = !useHydrated() && props.today === void 0;
|
|
124
|
+
const unplaced = undated && props.month === void 0 && props.defaultMonth === void 0;
|
|
125
|
+
const direction = (0, _nuvui_react_direction.useDirection)(dir === "rtl" || dir === "ltr" ? dir : void 0);
|
|
126
|
+
const merged = (0, react.useMemo)(() => {
|
|
127
|
+
if (!classNames) return classes;
|
|
128
|
+
const result = { ...classes };
|
|
129
|
+
for (const key of Object.keys(classNames)) result[key] = require_cx.cx(classes[key], classNames[key]);
|
|
130
|
+
return result;
|
|
131
|
+
}, [classNames]);
|
|
132
|
+
const allParts = (0, react.useMemo)(() => components ? {
|
|
133
|
+
...parts,
|
|
134
|
+
...components
|
|
135
|
+
} : parts, [components]);
|
|
136
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RootRefContext.Provider, {
|
|
137
|
+
value: ref,
|
|
138
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_day_picker.DayPicker, {
|
|
139
|
+
classNames: merged,
|
|
140
|
+
components: allParts,
|
|
141
|
+
dir: direction,
|
|
142
|
+
navLayout,
|
|
143
|
+
...unplaced ? {
|
|
144
|
+
className: props.className,
|
|
145
|
+
style: props.style,
|
|
146
|
+
numberOfMonths: props.numberOfMonths,
|
|
147
|
+
showWeekNumber: props.showWeekNumber,
|
|
148
|
+
fixedWeeks: props.fixedWeeks,
|
|
149
|
+
hideNavigation: props.hideNavigation,
|
|
150
|
+
hideWeekdays: props.hideWeekdays,
|
|
151
|
+
captionLayout: props.captionLayout,
|
|
152
|
+
month: anyMonth,
|
|
153
|
+
today: noDay,
|
|
154
|
+
"data-pending": ""
|
|
155
|
+
} : {
|
|
156
|
+
...props,
|
|
157
|
+
...undated ? { today: noDay } : null
|
|
158
|
+
}
|
|
159
|
+
}, unplaced ? "pending" : "placed")
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
//#endregion
|
|
163
|
+
exports.Calendar = Calendar;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DateRange as DateRange$1, DayPickerLocale as CalendarLocale, DayPickerProps, Matcher as Matcher$1, PropsBase } from "react-day-picker";
|
|
2
|
+
//#region src/components/calendar/calendar.d.ts
|
|
3
|
+
type OmitFromEach<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
|
|
4
|
+
/**
|
|
5
|
+
* The options a calendar has whatever its `mode`. `CalendarProps` is these
|
|
6
|
+
* with `selected` and `onSelect`, whose types follow the mode.
|
|
7
|
+
*/
|
|
8
|
+
export type CalendarOptions = Omit<PropsBase, "animate">;
|
|
9
|
+
/**
|
|
10
|
+
* What react-day-picker's `DayPicker` takes, except `animate`. Its slide
|
|
11
|
+
* between months is drawn by react-day-picker's own stylesheet, which this
|
|
12
|
+
* package doesn't use.
|
|
13
|
+
*/
|
|
14
|
+
export type CalendarProps = OmitFromEach<DayPickerProps, "animate">;
|
|
15
|
+
export declare const Calendar: import("react").ForwardRefExoticComponent<CalendarProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export type { CalendarLocale, DateRange$1 as DateRange, Matcher$1 as Matcher };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DateRange as DateRange$1, DayPickerLocale as CalendarLocale, DayPickerProps, Matcher as Matcher$1, PropsBase } from "react-day-picker";
|
|
2
|
+
//#region src/components/calendar/calendar.d.ts
|
|
3
|
+
type OmitFromEach<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
|
|
4
|
+
/**
|
|
5
|
+
* The options a calendar has whatever its `mode`. `CalendarProps` is these
|
|
6
|
+
* with `selected` and `onSelect`, whose types follow the mode.
|
|
7
|
+
*/
|
|
8
|
+
export type CalendarOptions = Omit<PropsBase, "animate">;
|
|
9
|
+
/**
|
|
10
|
+
* What react-day-picker's `DayPicker` takes, except `animate`. Its slide
|
|
11
|
+
* between months is drawn by react-day-picker's own stylesheet, which this
|
|
12
|
+
* package doesn't use.
|
|
13
|
+
*/
|
|
14
|
+
export type CalendarProps = OmitFromEach<DayPickerProps, "animate">;
|
|
15
|
+
export declare const Calendar: import("react").ForwardRefExoticComponent<CalendarProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export type { CalendarLocale, DateRange$1 as DateRange, Matcher$1 as Matcher };
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cx } from "../../utils/cx.js";
|
|
3
|
+
import { useDirection } from "@nuvui/react/direction";
|
|
4
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@nuvui/react/select";
|
|
5
|
+
import { createContext, forwardRef, useCallback, useContext, useMemo, useSyncExternalStore } from "react";
|
|
6
|
+
import { DayPicker, useDayPicker } from "react-day-picker";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
//#region src/components/calendar/calendar.tsx
|
|
9
|
+
const classes = {
|
|
10
|
+
root: "nuv-calendar",
|
|
11
|
+
months: "nuv-calendar__months",
|
|
12
|
+
month: "nuv-calendar__month",
|
|
13
|
+
month_caption: "nuv-calendar__caption",
|
|
14
|
+
caption_label: "nuv-calendar__caption-label",
|
|
15
|
+
nav: "nuv-calendar__nav",
|
|
16
|
+
button_previous: "nuv-calendar__nav-button nuv-calendar__nav-button--previous",
|
|
17
|
+
button_next: "nuv-calendar__nav-button nuv-calendar__nav-button--next",
|
|
18
|
+
chevron: "nuv-calendar__chevron",
|
|
19
|
+
dropdowns: "nuv-calendar__dropdowns",
|
|
20
|
+
dropdown_root: "",
|
|
21
|
+
dropdown: "nuv-calendar__select",
|
|
22
|
+
months_dropdown: "nuv-calendar__select--month",
|
|
23
|
+
years_dropdown: "nuv-calendar__select--year",
|
|
24
|
+
month_grid: "nuv-calendar__grid",
|
|
25
|
+
weekdays: "nuv-calendar__weekdays",
|
|
26
|
+
weekday: "nuv-calendar__weekday",
|
|
27
|
+
weeks: "nuv-calendar__weeks",
|
|
28
|
+
week: "nuv-calendar__week",
|
|
29
|
+
week_number: "nuv-calendar__week-number",
|
|
30
|
+
week_number_header: "nuv-calendar__week-number-header",
|
|
31
|
+
day: "nuv-calendar__day",
|
|
32
|
+
day_button: "nuv-calendar__day-button",
|
|
33
|
+
footer: "nuv-calendar__footer",
|
|
34
|
+
today: "nuv-calendar__day--today",
|
|
35
|
+
outside: "nuv-calendar__day--outside",
|
|
36
|
+
disabled: "nuv-calendar__day--disabled",
|
|
37
|
+
hidden: "nuv-calendar__day--hidden",
|
|
38
|
+
focused: "nuv-calendar__day--focused",
|
|
39
|
+
selected: "nuv-calendar__day--selected",
|
|
40
|
+
range_start: "nuv-calendar__day--range-start",
|
|
41
|
+
range_middle: "nuv-calendar__day--range-middle",
|
|
42
|
+
range_end: "nuv-calendar__day--range-end",
|
|
43
|
+
weeks_before_enter: "",
|
|
44
|
+
weeks_before_exit: "",
|
|
45
|
+
weeks_after_enter: "",
|
|
46
|
+
weeks_after_exit: "",
|
|
47
|
+
caption_after_enter: "",
|
|
48
|
+
caption_after_exit: "",
|
|
49
|
+
caption_before_enter: "",
|
|
50
|
+
caption_before_exit: ""
|
|
51
|
+
};
|
|
52
|
+
const chevrons = {
|
|
53
|
+
left: "M10 3.5 5.5 8l4.5 4.5",
|
|
54
|
+
right: "M6 3.5 10.5 8 6 12.5",
|
|
55
|
+
up: "M3.5 10 8 5.5l4.5 4.5",
|
|
56
|
+
down: "M3.5 6 8 10.5 12.5 6"
|
|
57
|
+
};
|
|
58
|
+
function Chevron({ orientation = "left", className }) {
|
|
59
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
60
|
+
"aria-hidden": "true",
|
|
61
|
+
className,
|
|
62
|
+
viewBox: "0 0 16 16",
|
|
63
|
+
width: "16",
|
|
64
|
+
height: "16",
|
|
65
|
+
fill: "none",
|
|
66
|
+
stroke: "currentColor",
|
|
67
|
+
strokeWidth: "1.5",
|
|
68
|
+
strokeLinecap: "round",
|
|
69
|
+
strokeLinejoin: "round",
|
|
70
|
+
children: /* @__PURE__ */ jsx("path", { d: chevrons[orientation] })
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
const RootRefContext = createContext(void 0);
|
|
74
|
+
function assign(ref, node) {
|
|
75
|
+
if (typeof ref === "function") ref(node);
|
|
76
|
+
else if (ref) ref.current = node;
|
|
77
|
+
}
|
|
78
|
+
function Root({ rootRef, ...props }) {
|
|
79
|
+
const forwarded = useContext(RootRefContext);
|
|
80
|
+
const setRef = useCallback((node) => {
|
|
81
|
+
assign(rootRef, node);
|
|
82
|
+
assign(forwarded, node);
|
|
83
|
+
}, [rootRef, forwarded]);
|
|
84
|
+
return /* @__PURE__ */ jsx("div", {
|
|
85
|
+
ref: setRef,
|
|
86
|
+
...props
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function Dropdown({ options, value, onChange, disabled, className, style, "aria-label": label }) {
|
|
90
|
+
const { classNames } = useDayPicker();
|
|
91
|
+
const selected = options?.find((option) => option.value === value);
|
|
92
|
+
return /* @__PURE__ */ jsxs(Select, {
|
|
93
|
+
value: String(value),
|
|
94
|
+
disabled,
|
|
95
|
+
onValueChange: (next) => onChange?.({ target: { value: next } }),
|
|
96
|
+
children: [/* @__PURE__ */ jsx(SelectTrigger, {
|
|
97
|
+
className: cx(classNames.dropdown, className),
|
|
98
|
+
style,
|
|
99
|
+
"aria-label": label,
|
|
100
|
+
children: /* @__PURE__ */ jsx(SelectValue, { children: selected?.label })
|
|
101
|
+
}), /* @__PURE__ */ jsx(SelectContent, {
|
|
102
|
+
className: "nuv-calendar__options",
|
|
103
|
+
children: options?.map((option) => /* @__PURE__ */ jsx(SelectItem, {
|
|
104
|
+
value: String(option.value),
|
|
105
|
+
disabled: option.disabled,
|
|
106
|
+
children: option.label
|
|
107
|
+
}, option.value))
|
|
108
|
+
})]
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
const parts = {
|
|
112
|
+
Chevron,
|
|
113
|
+
Dropdown,
|
|
114
|
+
Root
|
|
115
|
+
};
|
|
116
|
+
const never = () => () => {};
|
|
117
|
+
function useHydrated() {
|
|
118
|
+
return useSyncExternalStore(never, () => true, () => false);
|
|
119
|
+
}
|
|
120
|
+
const noDay = /* @__PURE__ */ new Date(0);
|
|
121
|
+
const anyMonth = new Date(2001, 6);
|
|
122
|
+
const Calendar = forwardRef(function Calendar({ classNames, components, dir, navLayout = "around", ...props }, ref) {
|
|
123
|
+
const undated = !useHydrated() && props.today === void 0;
|
|
124
|
+
const unplaced = undated && props.month === void 0 && props.defaultMonth === void 0;
|
|
125
|
+
const direction = useDirection(dir === "rtl" || dir === "ltr" ? dir : void 0);
|
|
126
|
+
const merged = useMemo(() => {
|
|
127
|
+
if (!classNames) return classes;
|
|
128
|
+
const result = { ...classes };
|
|
129
|
+
for (const key of Object.keys(classNames)) result[key] = cx(classes[key], classNames[key]);
|
|
130
|
+
return result;
|
|
131
|
+
}, [classNames]);
|
|
132
|
+
const allParts = useMemo(() => components ? {
|
|
133
|
+
...parts,
|
|
134
|
+
...components
|
|
135
|
+
} : parts, [components]);
|
|
136
|
+
return /* @__PURE__ */ jsx(RootRefContext.Provider, {
|
|
137
|
+
value: ref,
|
|
138
|
+
children: /* @__PURE__ */ jsx(DayPicker, {
|
|
139
|
+
classNames: merged,
|
|
140
|
+
components: allParts,
|
|
141
|
+
dir: direction,
|
|
142
|
+
navLayout,
|
|
143
|
+
...unplaced ? {
|
|
144
|
+
className: props.className,
|
|
145
|
+
style: props.style,
|
|
146
|
+
numberOfMonths: props.numberOfMonths,
|
|
147
|
+
showWeekNumber: props.showWeekNumber,
|
|
148
|
+
fixedWeeks: props.fixedWeeks,
|
|
149
|
+
hideNavigation: props.hideNavigation,
|
|
150
|
+
hideWeekdays: props.hideWeekdays,
|
|
151
|
+
captionLayout: props.captionLayout,
|
|
152
|
+
month: anyMonth,
|
|
153
|
+
today: noDay,
|
|
154
|
+
"data-pending": ""
|
|
155
|
+
} : {
|
|
156
|
+
...props,
|
|
157
|
+
...undated ? { today: noDay } : null
|
|
158
|
+
}
|
|
159
|
+
}, unplaced ? "pending" : "placed")
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
//#endregion
|
|
163
|
+
export { Calendar };
|