@nucleux/md3-date-picker 0.4.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 +26 -0
- package/dist/index.cjs +106 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +84 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nucleux
|
|
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
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# @nucleux/md3-date-picker
|
|
2
|
+
|
|
3
|
+
Material 3 date picker — Nucleux agentic UI for React.
|
|
4
|
+
|
|
5
|
+
Part of **[Nucleux](https://github.com/intelligaia-open-labs/nucleux)** — agentic UI components for React. Install a single component, or the full kit via [`@nucleux/react`](https://www.npmjs.com/package/@nucleux/react).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @nucleux/md3-date-picker @nucleux/tokens
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`react` / `react-dom` are peer dependencies.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { Md3DatePicker } from "@nucleux/md3-date-picker";
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Requires the theme once in your app: `import "@nucleux/tokens/styles.css";`
|
|
22
|
+
and the Tailwind preset from `@nucleux/tokens/preset`.
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
|
|
26
|
+
MIT © Nucleux
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var lucideReact = require('lucide-react');
|
|
6
|
+
var calendar = require('@nucleux/calendar');
|
|
7
|
+
var utils = require('@nucleux/utils');
|
|
8
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
9
|
+
|
|
10
|
+
function _interopNamespace(e) {
|
|
11
|
+
if (e && e.__esModule) return e;
|
|
12
|
+
var n = Object.create(null);
|
|
13
|
+
if (e) {
|
|
14
|
+
Object.keys(e).forEach(function (k) {
|
|
15
|
+
if (k !== 'default') {
|
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return e[k]; }
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
n.default = e;
|
|
25
|
+
return Object.freeze(n);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
29
|
+
|
|
30
|
+
// src/index.tsx
|
|
31
|
+
var formatDate = (d) => d.toLocaleDateString(void 0, { year: "numeric", month: "short", day: "numeric" });
|
|
32
|
+
var md3CalendarClassNames = {
|
|
33
|
+
caption_label: "text-sm font-medium text-md-on-surface",
|
|
34
|
+
nav_button: "inline-flex h-8 w-8 items-center justify-center rounded-full text-md-on-surface-variant hover:bg-md-on-surface/[0.08]",
|
|
35
|
+
head_cell: "w-9 text-xs font-normal text-md-on-surface-variant",
|
|
36
|
+
day: "inline-flex h-9 w-9 items-center justify-center rounded-full text-sm text-md-on-surface hover:bg-md-on-surface/[0.08]",
|
|
37
|
+
day_selected: "bg-md-primary text-md-on-primary hover:bg-md-primary",
|
|
38
|
+
day_today: "border border-md-primary",
|
|
39
|
+
day_outside: "text-md-on-surface-variant opacity-40"
|
|
40
|
+
};
|
|
41
|
+
var Md3DatePicker = React__namespace.forwardRef(
|
|
42
|
+
({ value, defaultValue, onValueChange, label = "Date", disabled = false, className, "aria-label": ariaLabel, ...rest }, ref) => {
|
|
43
|
+
const isControlled = value !== void 0;
|
|
44
|
+
const [internal, setInternal] = React__namespace.useState(defaultValue);
|
|
45
|
+
const selected = isControlled ? value : internal;
|
|
46
|
+
const [open, setOpen] = React__namespace.useState(false);
|
|
47
|
+
const rootRef = React__namespace.useRef(null);
|
|
48
|
+
React__namespace.useEffect(() => {
|
|
49
|
+
if (!open) return;
|
|
50
|
+
const onDown = (e) => {
|
|
51
|
+
if (!rootRef.current?.contains(e.target)) setOpen(false);
|
|
52
|
+
};
|
|
53
|
+
const onKey = (e) => e.key === "Escape" && setOpen(false);
|
|
54
|
+
document.addEventListener("mousedown", onDown);
|
|
55
|
+
document.addEventListener("keydown", onKey);
|
|
56
|
+
return () => {
|
|
57
|
+
document.removeEventListener("mousedown", onDown);
|
|
58
|
+
document.removeEventListener("keydown", onKey);
|
|
59
|
+
};
|
|
60
|
+
}, [open]);
|
|
61
|
+
const choose = (date) => {
|
|
62
|
+
if (!isControlled) setInternal(date);
|
|
63
|
+
onValueChange?.(date);
|
|
64
|
+
setOpen(false);
|
|
65
|
+
};
|
|
66
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: rootRef, className: utils.cn("relative inline-block", className), ...rest, children: [
|
|
67
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
68
|
+
"button",
|
|
69
|
+
{
|
|
70
|
+
ref,
|
|
71
|
+
type: "button",
|
|
72
|
+
disabled,
|
|
73
|
+
"aria-label": ariaLabel ?? label,
|
|
74
|
+
"aria-haspopup": "dialog",
|
|
75
|
+
"aria-expanded": open,
|
|
76
|
+
onClick: () => setOpen((o) => !o),
|
|
77
|
+
className: utils.cn(
|
|
78
|
+
"flex h-14 w-64 items-center justify-between gap-2 rounded-md-xs border border-md-outline bg-transparent px-4 text-left text-base text-md-on-surface outline-none focus-visible:border-md-primary",
|
|
79
|
+
"disabled:pointer-events-none disabled:opacity-[0.38]"
|
|
80
|
+
),
|
|
81
|
+
children: [
|
|
82
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: utils.cn("flex flex-col", !selected && "justify-center"), children: [
|
|
83
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-md-on-surface-variant", children: label }),
|
|
84
|
+
selected && /* @__PURE__ */ jsxRuntime.jsx("span", { children: formatDate(selected) })
|
|
85
|
+
] }),
|
|
86
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.CalendarDays, { "aria-hidden": true, className: "h-5 w-5 shrink-0 text-md-on-surface-variant" })
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
),
|
|
90
|
+
open && /* @__PURE__ */ jsxRuntime.jsx(
|
|
91
|
+
"div",
|
|
92
|
+
{
|
|
93
|
+
role: "dialog",
|
|
94
|
+
"aria-label": "Choose date",
|
|
95
|
+
className: "absolute z-50 mt-2 animate-nx-fade-in rounded-md-md bg-md-surface-container-high p-2 shadow-md-3",
|
|
96
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(calendar.Calendar, { mode: "single", selected, onSelect: choose, classNames: md3CalendarClassNames, initialFocus: true })
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
] });
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
Md3DatePicker.displayName = "Md3DatePicker";
|
|
103
|
+
|
|
104
|
+
exports.Md3DatePicker = Md3DatePicker;
|
|
105
|
+
//# sourceMappingURL=index.cjs.map
|
|
106
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":["React","jsxs","cn","jsx","CalendarDays","Calendar"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,IAAM,UAAA,GAAa,CAAC,CAAA,KAClB,CAAA,CAAE,kBAAA,CAAmB,MAAA,EAAW,EAAE,IAAA,EAAM,SAAA,EAAW,KAAA,EAAO,OAAA,EAAS,GAAA,EAAK,WAAW,CAAA;AAGrF,IAAM,qBAAA,GAAwB;AAAA,EAC5B,aAAA,EAAe,wCAAA;AAAA,EACf,UAAA,EACE,uHAAA;AAAA,EACF,SAAA,EAAW,oDAAA;AAAA,EACX,GAAA,EAAK,uHAAA;AAAA,EACL,YAAA,EAAc,sDAAA;AAAA,EACd,SAAA,EAAW,0BAAA;AAAA,EACX,WAAA,EAAa;AACf,CAAA;AAGO,IAAM,aAAA,GAAsBA,gBAAA,CAAA,UAAA;AAAA,EACjC,CAAC,EAAE,KAAA,EAAO,YAAA,EAAc,eAAe,KAAA,GAAQ,MAAA,EAAQ,QAAA,GAAW,KAAA,EAAO,WAAW,YAAA,EAAc,SAAA,EAAW,GAAG,IAAA,IAAQ,GAAA,KAAQ;AAC9H,IAAA,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AAA,EAEJ;AACF;AACA,aAAA,CAAc,WAAA,GAAc,eAAA","file":"index.cjs","sourcesContent":["import * as React from \"react\";\nimport { CalendarDays } from \"lucide-react\";\nimport { Calendar } from \"@nucleux/calendar\";\nimport { cn } from \"@nucleux/utils\";\n\nexport interface Md3DatePickerProps {\n value?: Date;\n defaultValue?: Date;\n onValueChange?: (date: Date | undefined) => void;\n label?: string;\n disabled?: boolean;\n className?: string;\n \"aria-label\"?: string;\n}\n\nconst formatDate = (d: Date) =>\n d.toLocaleDateString(undefined, { year: \"numeric\", month: \"short\", day: \"numeric\" });\n\n// Material 3 restyle of the react-day-picker grid.\nconst md3CalendarClassNames = {\n caption_label: \"text-sm font-medium text-md-on-surface\",\n nav_button:\n \"inline-flex h-8 w-8 items-center justify-center rounded-full text-md-on-surface-variant hover:bg-md-on-surface/[0.08]\",\n head_cell: \"w-9 text-xs font-normal text-md-on-surface-variant\",\n day: \"inline-flex h-9 w-9 items-center justify-center rounded-full text-sm text-md-on-surface hover:bg-md-on-surface/[0.08]\",\n day_selected: \"bg-md-primary text-md-on-primary hover:bg-md-primary\",\n day_today: \"border border-md-primary\",\n day_outside: \"text-md-on-surface-variant opacity-40\",\n} as const;\n\n/** A Material Design 3 date picker: an outlined field that opens a calendar. */\nexport const Md3DatePicker = React.forwardRef<HTMLButtonElement, Md3DatePickerProps>(\n ({ value, defaultValue, onValueChange, label = \"Date\", disabled = false, className, \"aria-label\": ariaLabel, ...rest }, ref) => {\n const isControlled = value !== undefined;\n const [internal, setInternal] = React.useState<Date | undefined>(defaultValue);\n const selected = isControlled ? value : internal;\n const [open, setOpen] = React.useState(false);\n const rootRef = React.useRef<HTMLDivElement>(null);\n\n React.useEffect(() => {\n if (!open) return;\n const onDown = (e: MouseEvent) => {\n if (!rootRef.current?.contains(e.target as Node)) setOpen(false);\n };\n const onKey = (e: KeyboardEvent) => e.key === \"Escape\" && setOpen(false);\n document.addEventListener(\"mousedown\", onDown);\n document.addEventListener(\"keydown\", onKey);\n return () => {\n document.removeEventListener(\"mousedown\", onDown);\n document.removeEventListener(\"keydown\", onKey);\n };\n }, [open]);\n\n const choose = (date: Date | undefined) => {\n if (!isControlled) setInternal(date);\n onValueChange?.(date);\n setOpen(false);\n };\n\n return (\n <div ref={rootRef} className={cn(\"relative inline-block\", className)} {...rest}>\n <button\n ref={ref}\n type=\"button\"\n disabled={disabled}\n aria-label={ariaLabel ?? label}\n aria-haspopup=\"dialog\"\n aria-expanded={open}\n onClick={() => setOpen((o) => !o)}\n className={cn(\n \"flex h-14 w-64 items-center justify-between gap-2 rounded-md-xs border border-md-outline bg-transparent px-4 text-left text-base text-md-on-surface outline-none focus-visible:border-md-primary\",\n \"disabled:pointer-events-none disabled:opacity-[0.38]\",\n )}\n >\n <span className={cn(\"flex flex-col\", !selected && \"justify-center\")}>\n <span className=\"text-xs text-md-on-surface-variant\">{label}</span>\n {selected && <span>{formatDate(selected)}</span>}\n </span>\n <CalendarDays aria-hidden className=\"h-5 w-5 shrink-0 text-md-on-surface-variant\" />\n </button>\n\n {open && (\n <div\n role=\"dialog\"\n aria-label=\"Choose date\"\n className=\"absolute z-50 mt-2 animate-nx-fade-in rounded-md-md bg-md-surface-container-high p-2 shadow-md-3\"\n >\n <Calendar mode=\"single\" selected={selected} onSelect={choose} classNames={md3CalendarClassNames} initialFocus />\n </div>\n )}\n </div>\n );\n },\n);\nMd3DatePicker.displayName = \"Md3DatePicker\";\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface Md3DatePickerProps {
|
|
4
|
+
value?: Date;
|
|
5
|
+
defaultValue?: Date;
|
|
6
|
+
onValueChange?: (date: Date | undefined) => void;
|
|
7
|
+
label?: string;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
className?: string;
|
|
10
|
+
"aria-label"?: string;
|
|
11
|
+
}
|
|
12
|
+
/** A Material Design 3 date picker: an outlined field that opens a calendar. */
|
|
13
|
+
declare const Md3DatePicker: React.ForwardRefExoticComponent<Md3DatePickerProps & React.RefAttributes<HTMLButtonElement>>;
|
|
14
|
+
|
|
15
|
+
export { Md3DatePicker, type Md3DatePickerProps };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface Md3DatePickerProps {
|
|
4
|
+
value?: Date;
|
|
5
|
+
defaultValue?: Date;
|
|
6
|
+
onValueChange?: (date: Date | undefined) => void;
|
|
7
|
+
label?: string;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
className?: string;
|
|
10
|
+
"aria-label"?: string;
|
|
11
|
+
}
|
|
12
|
+
/** A Material Design 3 date picker: an outlined field that opens a calendar. */
|
|
13
|
+
declare const Md3DatePicker: React.ForwardRefExoticComponent<Md3DatePickerProps & React.RefAttributes<HTMLButtonElement>>;
|
|
14
|
+
|
|
15
|
+
export { Md3DatePicker, type Md3DatePickerProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { CalendarDays } from 'lucide-react';
|
|
4
|
+
import { Calendar } from '@nucleux/calendar';
|
|
5
|
+
import { cn } from '@nucleux/utils';
|
|
6
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
7
|
+
|
|
8
|
+
// src/index.tsx
|
|
9
|
+
var formatDate = (d) => d.toLocaleDateString(void 0, { year: "numeric", month: "short", day: "numeric" });
|
|
10
|
+
var md3CalendarClassNames = {
|
|
11
|
+
caption_label: "text-sm font-medium text-md-on-surface",
|
|
12
|
+
nav_button: "inline-flex h-8 w-8 items-center justify-center rounded-full text-md-on-surface-variant hover:bg-md-on-surface/[0.08]",
|
|
13
|
+
head_cell: "w-9 text-xs font-normal text-md-on-surface-variant",
|
|
14
|
+
day: "inline-flex h-9 w-9 items-center justify-center rounded-full text-sm text-md-on-surface hover:bg-md-on-surface/[0.08]",
|
|
15
|
+
day_selected: "bg-md-primary text-md-on-primary hover:bg-md-primary",
|
|
16
|
+
day_today: "border border-md-primary",
|
|
17
|
+
day_outside: "text-md-on-surface-variant opacity-40"
|
|
18
|
+
};
|
|
19
|
+
var Md3DatePicker = React.forwardRef(
|
|
20
|
+
({ value, defaultValue, onValueChange, label = "Date", disabled = false, className, "aria-label": ariaLabel, ...rest }, ref) => {
|
|
21
|
+
const isControlled = value !== void 0;
|
|
22
|
+
const [internal, setInternal] = React.useState(defaultValue);
|
|
23
|
+
const selected = isControlled ? value : internal;
|
|
24
|
+
const [open, setOpen] = React.useState(false);
|
|
25
|
+
const rootRef = React.useRef(null);
|
|
26
|
+
React.useEffect(() => {
|
|
27
|
+
if (!open) return;
|
|
28
|
+
const onDown = (e) => {
|
|
29
|
+
if (!rootRef.current?.contains(e.target)) setOpen(false);
|
|
30
|
+
};
|
|
31
|
+
const onKey = (e) => e.key === "Escape" && setOpen(false);
|
|
32
|
+
document.addEventListener("mousedown", onDown);
|
|
33
|
+
document.addEventListener("keydown", onKey);
|
|
34
|
+
return () => {
|
|
35
|
+
document.removeEventListener("mousedown", onDown);
|
|
36
|
+
document.removeEventListener("keydown", onKey);
|
|
37
|
+
};
|
|
38
|
+
}, [open]);
|
|
39
|
+
const choose = (date) => {
|
|
40
|
+
if (!isControlled) setInternal(date);
|
|
41
|
+
onValueChange?.(date);
|
|
42
|
+
setOpen(false);
|
|
43
|
+
};
|
|
44
|
+
return /* @__PURE__ */ jsxs("div", { ref: rootRef, className: cn("relative inline-block", className), ...rest, children: [
|
|
45
|
+
/* @__PURE__ */ jsxs(
|
|
46
|
+
"button",
|
|
47
|
+
{
|
|
48
|
+
ref,
|
|
49
|
+
type: "button",
|
|
50
|
+
disabled,
|
|
51
|
+
"aria-label": ariaLabel ?? label,
|
|
52
|
+
"aria-haspopup": "dialog",
|
|
53
|
+
"aria-expanded": open,
|
|
54
|
+
onClick: () => setOpen((o) => !o),
|
|
55
|
+
className: cn(
|
|
56
|
+
"flex h-14 w-64 items-center justify-between gap-2 rounded-md-xs border border-md-outline bg-transparent px-4 text-left text-base text-md-on-surface outline-none focus-visible:border-md-primary",
|
|
57
|
+
"disabled:pointer-events-none disabled:opacity-[0.38]"
|
|
58
|
+
),
|
|
59
|
+
children: [
|
|
60
|
+
/* @__PURE__ */ jsxs("span", { className: cn("flex flex-col", !selected && "justify-center"), children: [
|
|
61
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-md-on-surface-variant", children: label }),
|
|
62
|
+
selected && /* @__PURE__ */ jsx("span", { children: formatDate(selected) })
|
|
63
|
+
] }),
|
|
64
|
+
/* @__PURE__ */ jsx(CalendarDays, { "aria-hidden": true, className: "h-5 w-5 shrink-0 text-md-on-surface-variant" })
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
),
|
|
68
|
+
open && /* @__PURE__ */ jsx(
|
|
69
|
+
"div",
|
|
70
|
+
{
|
|
71
|
+
role: "dialog",
|
|
72
|
+
"aria-label": "Choose date",
|
|
73
|
+
className: "absolute z-50 mt-2 animate-nx-fade-in rounded-md-md bg-md-surface-container-high p-2 shadow-md-3",
|
|
74
|
+
children: /* @__PURE__ */ jsx(Calendar, { mode: "single", selected, onSelect: choose, classNames: md3CalendarClassNames, initialFocus: true })
|
|
75
|
+
}
|
|
76
|
+
)
|
|
77
|
+
] });
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
Md3DatePicker.displayName = "Md3DatePicker";
|
|
81
|
+
|
|
82
|
+
export { Md3DatePicker };
|
|
83
|
+
//# sourceMappingURL=index.js.map
|
|
84
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":[],"mappings":";;;;;;;AAeA,IAAM,UAAA,GAAa,CAAC,CAAA,KAClB,CAAA,CAAE,kBAAA,CAAmB,MAAA,EAAW,EAAE,IAAA,EAAM,SAAA,EAAW,KAAA,EAAO,OAAA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,EAC3C,CAAA;AAAA,4BACA,GAAA,CAAC,YAAA,EAAA,EAAa,aAAA,EAAW,IAAA,EAAC,WAAU,6CAAA,EAA8C;AAAA;AAAA;AAAA,OACpF;AAAA,MAEC,IAAA,oBACC,GAAA;AAAA,QAAC,KAAA;AAAA,QAAA;AAAA,UACC,IAAA,EAAK,QAAA;AAAA,UACL,YAAA,EAAW,aAAA;AAAA,UACX,SAAA,EAAU,kGAAA;AAAA,UAEV,QAAA,kBAAA,GAAA,CAAC,QAAA,EAAA,EAAS,IAAA,EAAK,QAAA,EAAS,QAAA,EAAoB,UAAU,MAAA,EAAQ,UAAA,EAAY,qBAAA,EAAuB,YAAA,EAAY,IAAA,EAAC;AAAA;AAAA;AAChH,KAAA,EAEJ,CAAA;AAAA,EAEJ;AACF;AACA,aAAA,CAAc,WAAA,GAAc,eAAA","file":"index.js","sourcesContent":["import * as React from \"react\";\nimport { CalendarDays } from \"lucide-react\";\nimport { Calendar } from \"@nucleux/calendar\";\nimport { cn } from \"@nucleux/utils\";\n\nexport interface Md3DatePickerProps {\n value?: Date;\n defaultValue?: Date;\n onValueChange?: (date: Date | undefined) => void;\n label?: string;\n disabled?: boolean;\n className?: string;\n \"aria-label\"?: string;\n}\n\nconst formatDate = (d: Date) =>\n d.toLocaleDateString(undefined, { year: \"numeric\", month: \"short\", day: \"numeric\" });\n\n// Material 3 restyle of the react-day-picker grid.\nconst md3CalendarClassNames = {\n caption_label: \"text-sm font-medium text-md-on-surface\",\n nav_button:\n \"inline-flex h-8 w-8 items-center justify-center rounded-full text-md-on-surface-variant hover:bg-md-on-surface/[0.08]\",\n head_cell: \"w-9 text-xs font-normal text-md-on-surface-variant\",\n day: \"inline-flex h-9 w-9 items-center justify-center rounded-full text-sm text-md-on-surface hover:bg-md-on-surface/[0.08]\",\n day_selected: \"bg-md-primary text-md-on-primary hover:bg-md-primary\",\n day_today: \"border border-md-primary\",\n day_outside: \"text-md-on-surface-variant opacity-40\",\n} as const;\n\n/** A Material Design 3 date picker: an outlined field that opens a calendar. */\nexport const Md3DatePicker = React.forwardRef<HTMLButtonElement, Md3DatePickerProps>(\n ({ value, defaultValue, onValueChange, label = \"Date\", disabled = false, className, \"aria-label\": ariaLabel, ...rest }, ref) => {\n const isControlled = value !== undefined;\n const [internal, setInternal] = React.useState<Date | undefined>(defaultValue);\n const selected = isControlled ? value : internal;\n const [open, setOpen] = React.useState(false);\n const rootRef = React.useRef<HTMLDivElement>(null);\n\n React.useEffect(() => {\n if (!open) return;\n const onDown = (e: MouseEvent) => {\n if (!rootRef.current?.contains(e.target as Node)) setOpen(false);\n };\n const onKey = (e: KeyboardEvent) => e.key === \"Escape\" && setOpen(false);\n document.addEventListener(\"mousedown\", onDown);\n document.addEventListener(\"keydown\", onKey);\n return () => {\n document.removeEventListener(\"mousedown\", onDown);\n document.removeEventListener(\"keydown\", onKey);\n };\n }, [open]);\n\n const choose = (date: Date | undefined) => {\n if (!isControlled) setInternal(date);\n onValueChange?.(date);\n setOpen(false);\n };\n\n return (\n <div ref={rootRef} className={cn(\"relative inline-block\", className)} {...rest}>\n <button\n ref={ref}\n type=\"button\"\n disabled={disabled}\n aria-label={ariaLabel ?? label}\n aria-haspopup=\"dialog\"\n aria-expanded={open}\n onClick={() => setOpen((o) => !o)}\n className={cn(\n \"flex h-14 w-64 items-center justify-between gap-2 rounded-md-xs border border-md-outline bg-transparent px-4 text-left text-base text-md-on-surface outline-none focus-visible:border-md-primary\",\n \"disabled:pointer-events-none disabled:opacity-[0.38]\",\n )}\n >\n <span className={cn(\"flex flex-col\", !selected && \"justify-center\")}>\n <span className=\"text-xs text-md-on-surface-variant\">{label}</span>\n {selected && <span>{formatDate(selected)}</span>}\n </span>\n <CalendarDays aria-hidden className=\"h-5 w-5 shrink-0 text-md-on-surface-variant\" />\n </button>\n\n {open && (\n <div\n role=\"dialog\"\n aria-label=\"Choose date\"\n className=\"absolute z-50 mt-2 animate-nx-fade-in rounded-md-md bg-md-surface-container-high p-2 shadow-md-3\"\n >\n <Calendar mode=\"single\" selected={selected} onSelect={choose} classNames={md3CalendarClassNames} initialFocus />\n </div>\n )}\n </div>\n );\n },\n);\nMd3DatePicker.displayName = \"Md3DatePicker\";\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nucleux/md3-date-picker",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"description": "Material 3 date picker — Nucleux agentic UI for React.",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"nucleux",
|
|
9
|
+
"react",
|
|
10
|
+
"ui",
|
|
11
|
+
"components",
|
|
12
|
+
"agentic",
|
|
13
|
+
"ai",
|
|
14
|
+
"tailwind",
|
|
15
|
+
"md3-date-picker"
|
|
16
|
+
],
|
|
17
|
+
"main": "./dist/index.cjs",
|
|
18
|
+
"module": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js",
|
|
24
|
+
"require": "./dist/index.cjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"README.md"
|
|
30
|
+
],
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"react": ">=18",
|
|
33
|
+
"react-dom": ">=18"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"lucide-react": "^0.469.0",
|
|
37
|
+
"@nucleux/utils": "0.4.0",
|
|
38
|
+
"@nucleux/calendar": "0.4.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"tsup": "^8.3.5",
|
|
42
|
+
"typescript": "^5.7.2",
|
|
43
|
+
"@types/react": "^18.3.18",
|
|
44
|
+
"react": "^18.3.1"
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
},
|
|
49
|
+
"license": "MIT",
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "git+https://github.com/intelligaia-open-labs/nucleux.git",
|
|
53
|
+
"directory": "packages/md3-date-picker"
|
|
54
|
+
},
|
|
55
|
+
"homepage": "https://github.com/intelligaia-open-labs/nucleux#readme",
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "tsup"
|
|
58
|
+
}
|
|
59
|
+
}
|