@nucleux/sheet 0.1.1
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 +183 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +31 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +155 -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/sheet
|
|
2
|
+
|
|
3
|
+
Sheet — a slide-over drawer panel — 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/sheet @nucleux/tokens
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`react` / `react-dom` are peer dependencies.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { Sheet, SheetHeader, SheetTitle, SheetBody, SheetFooter } from "@nucleux/sheet";
|
|
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,183 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var lucideReact = require('lucide-react');
|
|
6
|
+
var utils = require('@nucleux/utils');
|
|
7
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
+
|
|
9
|
+
function _interopNamespace(e) {
|
|
10
|
+
if (e && e.__esModule) return e;
|
|
11
|
+
var n = Object.create(null);
|
|
12
|
+
if (e) {
|
|
13
|
+
Object.keys(e).forEach(function (k) {
|
|
14
|
+
if (k !== 'default') {
|
|
15
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return e[k]; }
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
n.default = e;
|
|
24
|
+
return Object.freeze(n);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
28
|
+
|
|
29
|
+
// src/index.tsx
|
|
30
|
+
var SheetContext = React__namespace.createContext(null);
|
|
31
|
+
var sideClasses = {
|
|
32
|
+
right: "inset-y-0 right-0 h-full w-full max-w-sm border-l",
|
|
33
|
+
left: "inset-y-0 left-0 h-full w-full max-w-sm border-r",
|
|
34
|
+
top: "inset-x-0 top-0 w-full border-b",
|
|
35
|
+
bottom: "inset-x-0 bottom-0 w-full border-t"
|
|
36
|
+
};
|
|
37
|
+
function Sheet({
|
|
38
|
+
open,
|
|
39
|
+
onOpenChange,
|
|
40
|
+
side = "right",
|
|
41
|
+
children,
|
|
42
|
+
className,
|
|
43
|
+
dismissible = true
|
|
44
|
+
}) {
|
|
45
|
+
const baseId = React__namespace.useId();
|
|
46
|
+
const panelRef = React__namespace.useRef(null);
|
|
47
|
+
const close = React__namespace.useCallback(() => onOpenChange(false), [onOpenChange]);
|
|
48
|
+
React__namespace.useEffect(() => {
|
|
49
|
+
if (!open || !dismissible) return;
|
|
50
|
+
const onKey = (e) => {
|
|
51
|
+
if (e.key === "Escape") close();
|
|
52
|
+
};
|
|
53
|
+
document.addEventListener("keydown", onKey);
|
|
54
|
+
return () => document.removeEventListener("keydown", onKey);
|
|
55
|
+
}, [open, dismissible, close]);
|
|
56
|
+
React__namespace.useEffect(() => {
|
|
57
|
+
if (open) panelRef.current?.focus();
|
|
58
|
+
}, [open]);
|
|
59
|
+
if (!open) return null;
|
|
60
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
61
|
+
SheetContext.Provider,
|
|
62
|
+
{
|
|
63
|
+
value: { titleId: `${baseId}-title`, descriptionId: `${baseId}-desc`, onClose: close },
|
|
64
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "fixed inset-0 z-50", children: [
|
|
65
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
66
|
+
"div",
|
|
67
|
+
{
|
|
68
|
+
"aria-hidden": true,
|
|
69
|
+
className: "absolute inset-0 bg-foreground/50 animate-nx-fade-in",
|
|
70
|
+
onClick: dismissible ? close : void 0
|
|
71
|
+
}
|
|
72
|
+
),
|
|
73
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
74
|
+
"div",
|
|
75
|
+
{
|
|
76
|
+
ref: panelRef,
|
|
77
|
+
role: "dialog",
|
|
78
|
+
"aria-modal": "true",
|
|
79
|
+
"aria-labelledby": `${baseId}-title`,
|
|
80
|
+
"aria-describedby": `${baseId}-desc`,
|
|
81
|
+
tabIndex: -1,
|
|
82
|
+
className: utils.cn(
|
|
83
|
+
"absolute flex flex-col border-border bg-background shadow-lg outline-none animate-nx-fade-in",
|
|
84
|
+
sideClasses[side],
|
|
85
|
+
className
|
|
86
|
+
),
|
|
87
|
+
children
|
|
88
|
+
}
|
|
89
|
+
)
|
|
90
|
+
] })
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
var SheetHeader = React__namespace.forwardRef(
|
|
95
|
+
({ className, children, ...props }, ref) => {
|
|
96
|
+
const ctx = React__namespace.useContext(SheetContext);
|
|
97
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
98
|
+
"div",
|
|
99
|
+
{
|
|
100
|
+
ref,
|
|
101
|
+
className: utils.cn("flex items-center justify-between gap-4 border-b border-border p-4", className),
|
|
102
|
+
...props,
|
|
103
|
+
children: [
|
|
104
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "min-w-0 flex-1", children }),
|
|
105
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
106
|
+
"button",
|
|
107
|
+
{
|
|
108
|
+
type: "button",
|
|
109
|
+
"aria-label": "Close",
|
|
110
|
+
onClick: ctx?.onClose,
|
|
111
|
+
className: "shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
112
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "size-4" })
|
|
113
|
+
}
|
|
114
|
+
)
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
SheetHeader.displayName = "SheetHeader";
|
|
121
|
+
var SheetTitle = React__namespace.forwardRef(
|
|
122
|
+
({ className, ...props }, ref) => {
|
|
123
|
+
const ctx = React__namespace.useContext(SheetContext);
|
|
124
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
125
|
+
"h2",
|
|
126
|
+
{
|
|
127
|
+
ref,
|
|
128
|
+
id: ctx?.titleId,
|
|
129
|
+
className: utils.cn("text-sm font-semibold text-foreground", className),
|
|
130
|
+
...props
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
);
|
|
135
|
+
SheetTitle.displayName = "SheetTitle";
|
|
136
|
+
var SheetDescription = React__namespace.forwardRef(({ className, ...props }, ref) => {
|
|
137
|
+
const ctx = React__namespace.useContext(SheetContext);
|
|
138
|
+
return /* @__PURE__ */ jsxRuntime.jsx("p", { ref, id: ctx?.descriptionId, className: utils.cn("text-sm text-muted-foreground", className), ...props });
|
|
139
|
+
});
|
|
140
|
+
SheetDescription.displayName = "SheetDescription";
|
|
141
|
+
var SheetBody = React__namespace.forwardRef(
|
|
142
|
+
({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className: utils.cn("min-h-0 flex-1 overflow-y-auto p-4", className), ...props })
|
|
143
|
+
);
|
|
144
|
+
SheetBody.displayName = "SheetBody";
|
|
145
|
+
var SheetFooter = React__namespace.forwardRef(
|
|
146
|
+
({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
147
|
+
"div",
|
|
148
|
+
{
|
|
149
|
+
ref,
|
|
150
|
+
className: utils.cn("flex items-center justify-end gap-2 border-t border-border p-4", className),
|
|
151
|
+
...props
|
|
152
|
+
}
|
|
153
|
+
)
|
|
154
|
+
);
|
|
155
|
+
SheetFooter.displayName = "SheetFooter";
|
|
156
|
+
var SheetClose = React__namespace.forwardRef(
|
|
157
|
+
({ onClick, type = "button", ...props }, ref) => {
|
|
158
|
+
const ctx = React__namespace.useContext(SheetContext);
|
|
159
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
160
|
+
"button",
|
|
161
|
+
{
|
|
162
|
+
ref,
|
|
163
|
+
type,
|
|
164
|
+
onClick: (e) => {
|
|
165
|
+
onClick?.(e);
|
|
166
|
+
ctx?.onClose();
|
|
167
|
+
},
|
|
168
|
+
...props
|
|
169
|
+
}
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
);
|
|
173
|
+
SheetClose.displayName = "SheetClose";
|
|
174
|
+
|
|
175
|
+
exports.Sheet = Sheet;
|
|
176
|
+
exports.SheetBody = SheetBody;
|
|
177
|
+
exports.SheetClose = SheetClose;
|
|
178
|
+
exports.SheetDescription = SheetDescription;
|
|
179
|
+
exports.SheetFooter = SheetFooter;
|
|
180
|
+
exports.SheetHeader = SheetHeader;
|
|
181
|
+
exports.SheetTitle = SheetTitle;
|
|
182
|
+
//# sourceMappingURL=index.cjs.map
|
|
183
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":["React","jsx","jsxs","cn","X"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,IAAM,YAAA,GAAqBA,+BAAwC,IAAI,CAAA;AAIvE,IAAM,WAAA,GAAyC;AAAA,EAC7C,KAAA,EAAO,mDAAA;AAAA,EACP,IAAA,EAAM,kDAAA;AAAA,EACN,GAAA,EAAK,iCAAA;AAAA,EACL,MAAA,EAAQ;AACV,CAAA;AAqBO,SAAS,KAAA,CAAM;AAAA,EACpB,IAAA;AAAA,EACA,YAAA;A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A;AAEjB,IAAM,WAAA,GAAoBH,gBAAA,CAAA,UAAA;AAAA,EAC/B,CAAC,EAAE,SAAA,EAAW,GAAG,KAAA,IAAS,GAAA,qBACxBC,cAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACC,GAAA;AAAA,MACA,SAAA,EAAWE,QAAA,CAAG,gEAAA,EAAkE,SAAS,CAAA;AAAA,MACxF,GAAG;AAAA;AAAA;AAGV;AACA,WAAA,CAAY,WAAA,GAAc,aAAA;AAGnB,IAAM,UAAA,GAAmBH,gBAAA,CAAA,UAAA;AAAA,EAC9B,CAAC,EAAE,OAAA,EAAS,IAAA,GAAO,UAAU,GAAG,KAAA,IAAS,GAAA,KAAQ;AAC/C,IAAA,MAAM,GAAA,GAAYA,4BAAW,YAAY,CAAA;AACzC,IAAA,uBACEC,cAAA;AAAA,MAAC,QAAA;AAAA,MAAA;AAAA,QACC,GAAA;AAAA,QACA,IAAA;AAAA,QACA,OAAA,EAAS,CAAC,CAAA,KAAM;AACd,UAAA,OAAA,GAAU,CAAC,CAAA;AACX,UAAA,GAAA,EAAK,OAAA,EAAQ;AAAA,QACf,CAAA;AAAA,QACC,GAAG;AAAA;AAAA,KACN;AAAA,EAEJ;AACF;AACA,UAAA,CAAW,WAAA,GAAc,YAAA","file":"index.cjs","sourcesContent":["import * as React from \"react\";\nimport { X } from \"lucide-react\";\nimport { cn } from \"@nucleux/utils\";\n\ninterface SheetContextValue {\n titleId: string;\n descriptionId: string;\n onClose: () => void;\n}\nconst SheetContext = React.createContext<SheetContextValue | null>(null);\n\nexport type SheetSide = \"right\" | \"left\" | \"top\" | \"bottom\";\n\nconst sideClasses: Record<SheetSide, string> = {\n right: \"inset-y-0 right-0 h-full w-full max-w-sm border-l\",\n left: \"inset-y-0 left-0 h-full w-full max-w-sm border-r\",\n top: \"inset-x-0 top-0 w-full border-b\",\n bottom: \"inset-x-0 bottom-0 w-full border-t\",\n};\n\nexport interface SheetProps {\n /** Whether the sheet is open. */\n open: boolean;\n /** Called when the sheet requests to close (overlay click / Escape / close button). */\n onOpenChange: (open: boolean) => void;\n /** Which edge the sheet slides in from. */\n side?: SheetSide;\n /** Panel content — compose SheetHeader/Title/Description/Body/Footer. */\n children: React.ReactNode;\n /** Class overrides for the panel. */\n className?: string;\n /** Disable closing on overlay click / Escape. */\n dismissible?: boolean;\n}\n\n/**\n * A slide-over drawer anchored to a screen edge. Controlled via `open` /\n * `onOpenChange`; closes on overlay click, Escape, or {@link SheetClose}.\n */\nexport function Sheet({\n open,\n onOpenChange,\n side = \"right\",\n children,\n className,\n dismissible = true,\n}: SheetProps) {\n const baseId = React.useId();\n const panelRef = React.useRef<HTMLDivElement>(null);\n const close = React.useCallback(() => onOpenChange(false), [onOpenChange]);\n\n React.useEffect(() => {\n if (!open || !dismissible) return;\n const onKey = (e: KeyboardEvent) => {\n if (e.key === \"Escape\") close();\n };\n document.addEventListener(\"keydown\", onKey);\n return () => document.removeEventListener(\"keydown\", onKey);\n }, [open, dismissible, close]);\n\n React.useEffect(() => {\n if (open) panelRef.current?.focus();\n }, [open]);\n\n if (!open) return null;\n\n return (\n <SheetContext.Provider\n value={{ titleId: `${baseId}-title`, descriptionId: `${baseId}-desc`, onClose: close }}\n >\n <div className=\"fixed inset-0 z-50\">\n <div\n aria-hidden\n className=\"absolute inset-0 bg-foreground/50 animate-nx-fade-in\"\n onClick={dismissible ? close : undefined}\n />\n <div\n ref={panelRef}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-labelledby={`${baseId}-title`}\n aria-describedby={`${baseId}-desc`}\n tabIndex={-1}\n className={cn(\n \"absolute flex flex-col border-border bg-background shadow-lg outline-none animate-nx-fade-in\",\n sideClasses[side],\n className,\n )}\n >\n {children}\n </div>\n </div>\n </SheetContext.Provider>\n );\n}\n\nexport const SheetHeader = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(\n ({ className, children, ...props }, ref) => {\n const ctx = React.useContext(SheetContext);\n return (\n <div\n ref={ref}\n className={cn(\"flex items-center justify-between gap-4 border-b border-border p-4\", className)}\n {...props}\n >\n <div className=\"min-w-0 flex-1\">{children}</div>\n <button\n type=\"button\"\n aria-label=\"Close\"\n onClick={ctx?.onClose}\n className=\"shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n >\n <X className=\"size-4\" />\n </button>\n </div>\n );\n },\n);\nSheetHeader.displayName = \"SheetHeader\";\n\nexport const SheetTitle = React.forwardRef<HTMLHeadingElement, React.HTMLAttributes<HTMLHeadingElement>>(\n ({ className, ...props }, ref) => {\n const ctx = React.useContext(SheetContext);\n return (\n <h2\n ref={ref}\n id={ctx?.titleId}\n className={cn(\"text-sm font-semibold text-foreground\", className)}\n {...props}\n />\n );\n },\n);\nSheetTitle.displayName = \"SheetTitle\";\n\nexport const SheetDescription = React.forwardRef<\n HTMLParagraphElement,\n React.HTMLAttributes<HTMLParagraphElement>\n>(({ className, ...props }, ref) => {\n const ctx = React.useContext(SheetContext);\n return (\n <p ref={ref} id={ctx?.descriptionId} className={cn(\"text-sm text-muted-foreground\", className)} {...props} />\n );\n});\nSheetDescription.displayName = \"SheetDescription\";\n\nexport const SheetBody = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(\n ({ className, ...props }, ref) => (\n <div ref={ref} className={cn(\"min-h-0 flex-1 overflow-y-auto p-4\", className)} {...props} />\n ),\n);\nSheetBody.displayName = \"SheetBody\";\n\nexport const SheetFooter = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(\n ({ className, ...props }, ref) => (\n <div\n ref={ref}\n className={cn(\"flex items-center justify-end gap-2 border-t border-border p-4\", className)}\n {...props}\n />\n ),\n);\nSheetFooter.displayName = \"SheetFooter\";\n\n/** A button that closes the enclosing Sheet. */\nexport const SheetClose = React.forwardRef<HTMLButtonElement, React.ButtonHTMLAttributes<HTMLButtonElement>>(\n ({ onClick, type = \"button\", ...props }, ref) => {\n const ctx = React.useContext(SheetContext);\n return (\n <button\n ref={ref}\n type={type}\n onClick={(e) => {\n onClick?.(e);\n ctx?.onClose();\n }}\n {...props}\n />\n );\n },\n);\nSheetClose.displayName = \"SheetClose\";\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
type SheetSide = "right" | "left" | "top" | "bottom";
|
|
4
|
+
interface SheetProps {
|
|
5
|
+
/** Whether the sheet is open. */
|
|
6
|
+
open: boolean;
|
|
7
|
+
/** Called when the sheet requests to close (overlay click / Escape / close button). */
|
|
8
|
+
onOpenChange: (open: boolean) => void;
|
|
9
|
+
/** Which edge the sheet slides in from. */
|
|
10
|
+
side?: SheetSide;
|
|
11
|
+
/** Panel content — compose SheetHeader/Title/Description/Body/Footer. */
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
/** Class overrides for the panel. */
|
|
14
|
+
className?: string;
|
|
15
|
+
/** Disable closing on overlay click / Escape. */
|
|
16
|
+
dismissible?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A slide-over drawer anchored to a screen edge. Controlled via `open` /
|
|
20
|
+
* `onOpenChange`; closes on overlay click, Escape, or {@link SheetClose}.
|
|
21
|
+
*/
|
|
22
|
+
declare function Sheet({ open, onOpenChange, side, children, className, dismissible, }: SheetProps): React.JSX.Element | null;
|
|
23
|
+
declare const SheetHeader: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
24
|
+
declare const SheetTitle: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLHeadingElement> & React.RefAttributes<HTMLHeadingElement>>;
|
|
25
|
+
declare const SheetDescription: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLParagraphElement> & React.RefAttributes<HTMLParagraphElement>>;
|
|
26
|
+
declare const SheetBody: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
27
|
+
declare const SheetFooter: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
28
|
+
/** A button that closes the enclosing Sheet. */
|
|
29
|
+
declare const SheetClose: React.ForwardRefExoticComponent<React.ButtonHTMLAttributes<HTMLButtonElement> & React.RefAttributes<HTMLButtonElement>>;
|
|
30
|
+
|
|
31
|
+
export { Sheet, SheetBody, SheetClose, SheetDescription, SheetFooter, SheetHeader, type SheetProps, type SheetSide, SheetTitle };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
type SheetSide = "right" | "left" | "top" | "bottom";
|
|
4
|
+
interface SheetProps {
|
|
5
|
+
/** Whether the sheet is open. */
|
|
6
|
+
open: boolean;
|
|
7
|
+
/** Called when the sheet requests to close (overlay click / Escape / close button). */
|
|
8
|
+
onOpenChange: (open: boolean) => void;
|
|
9
|
+
/** Which edge the sheet slides in from. */
|
|
10
|
+
side?: SheetSide;
|
|
11
|
+
/** Panel content — compose SheetHeader/Title/Description/Body/Footer. */
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
/** Class overrides for the panel. */
|
|
14
|
+
className?: string;
|
|
15
|
+
/** Disable closing on overlay click / Escape. */
|
|
16
|
+
dismissible?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A slide-over drawer anchored to a screen edge. Controlled via `open` /
|
|
20
|
+
* `onOpenChange`; closes on overlay click, Escape, or {@link SheetClose}.
|
|
21
|
+
*/
|
|
22
|
+
declare function Sheet({ open, onOpenChange, side, children, className, dismissible, }: SheetProps): React.JSX.Element | null;
|
|
23
|
+
declare const SheetHeader: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
24
|
+
declare const SheetTitle: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLHeadingElement> & React.RefAttributes<HTMLHeadingElement>>;
|
|
25
|
+
declare const SheetDescription: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLParagraphElement> & React.RefAttributes<HTMLParagraphElement>>;
|
|
26
|
+
declare const SheetBody: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
27
|
+
declare const SheetFooter: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
28
|
+
/** A button that closes the enclosing Sheet. */
|
|
29
|
+
declare const SheetClose: React.ForwardRefExoticComponent<React.ButtonHTMLAttributes<HTMLButtonElement> & React.RefAttributes<HTMLButtonElement>>;
|
|
30
|
+
|
|
31
|
+
export { Sheet, SheetBody, SheetClose, SheetDescription, SheetFooter, SheetHeader, type SheetProps, type SheetSide, SheetTitle };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { X } from 'lucide-react';
|
|
4
|
+
import { cn } from '@nucleux/utils';
|
|
5
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
6
|
+
|
|
7
|
+
// src/index.tsx
|
|
8
|
+
var SheetContext = React.createContext(null);
|
|
9
|
+
var sideClasses = {
|
|
10
|
+
right: "inset-y-0 right-0 h-full w-full max-w-sm border-l",
|
|
11
|
+
left: "inset-y-0 left-0 h-full w-full max-w-sm border-r",
|
|
12
|
+
top: "inset-x-0 top-0 w-full border-b",
|
|
13
|
+
bottom: "inset-x-0 bottom-0 w-full border-t"
|
|
14
|
+
};
|
|
15
|
+
function Sheet({
|
|
16
|
+
open,
|
|
17
|
+
onOpenChange,
|
|
18
|
+
side = "right",
|
|
19
|
+
children,
|
|
20
|
+
className,
|
|
21
|
+
dismissible = true
|
|
22
|
+
}) {
|
|
23
|
+
const baseId = React.useId();
|
|
24
|
+
const panelRef = React.useRef(null);
|
|
25
|
+
const close = React.useCallback(() => onOpenChange(false), [onOpenChange]);
|
|
26
|
+
React.useEffect(() => {
|
|
27
|
+
if (!open || !dismissible) return;
|
|
28
|
+
const onKey = (e) => {
|
|
29
|
+
if (e.key === "Escape") close();
|
|
30
|
+
};
|
|
31
|
+
document.addEventListener("keydown", onKey);
|
|
32
|
+
return () => document.removeEventListener("keydown", onKey);
|
|
33
|
+
}, [open, dismissible, close]);
|
|
34
|
+
React.useEffect(() => {
|
|
35
|
+
if (open) panelRef.current?.focus();
|
|
36
|
+
}, [open]);
|
|
37
|
+
if (!open) return null;
|
|
38
|
+
return /* @__PURE__ */ jsx(
|
|
39
|
+
SheetContext.Provider,
|
|
40
|
+
{
|
|
41
|
+
value: { titleId: `${baseId}-title`, descriptionId: `${baseId}-desc`, onClose: close },
|
|
42
|
+
children: /* @__PURE__ */ jsxs("div", { className: "fixed inset-0 z-50", children: [
|
|
43
|
+
/* @__PURE__ */ jsx(
|
|
44
|
+
"div",
|
|
45
|
+
{
|
|
46
|
+
"aria-hidden": true,
|
|
47
|
+
className: "absolute inset-0 bg-foreground/50 animate-nx-fade-in",
|
|
48
|
+
onClick: dismissible ? close : void 0
|
|
49
|
+
}
|
|
50
|
+
),
|
|
51
|
+
/* @__PURE__ */ jsx(
|
|
52
|
+
"div",
|
|
53
|
+
{
|
|
54
|
+
ref: panelRef,
|
|
55
|
+
role: "dialog",
|
|
56
|
+
"aria-modal": "true",
|
|
57
|
+
"aria-labelledby": `${baseId}-title`,
|
|
58
|
+
"aria-describedby": `${baseId}-desc`,
|
|
59
|
+
tabIndex: -1,
|
|
60
|
+
className: cn(
|
|
61
|
+
"absolute flex flex-col border-border bg-background shadow-lg outline-none animate-nx-fade-in",
|
|
62
|
+
sideClasses[side],
|
|
63
|
+
className
|
|
64
|
+
),
|
|
65
|
+
children
|
|
66
|
+
}
|
|
67
|
+
)
|
|
68
|
+
] })
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
var SheetHeader = React.forwardRef(
|
|
73
|
+
({ className, children, ...props }, ref) => {
|
|
74
|
+
const ctx = React.useContext(SheetContext);
|
|
75
|
+
return /* @__PURE__ */ jsxs(
|
|
76
|
+
"div",
|
|
77
|
+
{
|
|
78
|
+
ref,
|
|
79
|
+
className: cn("flex items-center justify-between gap-4 border-b border-border p-4", className),
|
|
80
|
+
...props,
|
|
81
|
+
children: [
|
|
82
|
+
/* @__PURE__ */ jsx("div", { className: "min-w-0 flex-1", children }),
|
|
83
|
+
/* @__PURE__ */ jsx(
|
|
84
|
+
"button",
|
|
85
|
+
{
|
|
86
|
+
type: "button",
|
|
87
|
+
"aria-label": "Close",
|
|
88
|
+
onClick: ctx?.onClose,
|
|
89
|
+
className: "shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
90
|
+
children: /* @__PURE__ */ jsx(X, { className: "size-4" })
|
|
91
|
+
}
|
|
92
|
+
)
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
);
|
|
98
|
+
SheetHeader.displayName = "SheetHeader";
|
|
99
|
+
var SheetTitle = React.forwardRef(
|
|
100
|
+
({ className, ...props }, ref) => {
|
|
101
|
+
const ctx = React.useContext(SheetContext);
|
|
102
|
+
return /* @__PURE__ */ jsx(
|
|
103
|
+
"h2",
|
|
104
|
+
{
|
|
105
|
+
ref,
|
|
106
|
+
id: ctx?.titleId,
|
|
107
|
+
className: cn("text-sm font-semibold text-foreground", className),
|
|
108
|
+
...props
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
SheetTitle.displayName = "SheetTitle";
|
|
114
|
+
var SheetDescription = React.forwardRef(({ className, ...props }, ref) => {
|
|
115
|
+
const ctx = React.useContext(SheetContext);
|
|
116
|
+
return /* @__PURE__ */ jsx("p", { ref, id: ctx?.descriptionId, className: cn("text-sm text-muted-foreground", className), ...props });
|
|
117
|
+
});
|
|
118
|
+
SheetDescription.displayName = "SheetDescription";
|
|
119
|
+
var SheetBody = React.forwardRef(
|
|
120
|
+
({ className, ...props }, ref) => /* @__PURE__ */ jsx("div", { ref, className: cn("min-h-0 flex-1 overflow-y-auto p-4", className), ...props })
|
|
121
|
+
);
|
|
122
|
+
SheetBody.displayName = "SheetBody";
|
|
123
|
+
var SheetFooter = React.forwardRef(
|
|
124
|
+
({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
125
|
+
"div",
|
|
126
|
+
{
|
|
127
|
+
ref,
|
|
128
|
+
className: cn("flex items-center justify-end gap-2 border-t border-border p-4", className),
|
|
129
|
+
...props
|
|
130
|
+
}
|
|
131
|
+
)
|
|
132
|
+
);
|
|
133
|
+
SheetFooter.displayName = "SheetFooter";
|
|
134
|
+
var SheetClose = React.forwardRef(
|
|
135
|
+
({ onClick, type = "button", ...props }, ref) => {
|
|
136
|
+
const ctx = React.useContext(SheetContext);
|
|
137
|
+
return /* @__PURE__ */ jsx(
|
|
138
|
+
"button",
|
|
139
|
+
{
|
|
140
|
+
ref,
|
|
141
|
+
type,
|
|
142
|
+
onClick: (e) => {
|
|
143
|
+
onClick?.(e);
|
|
144
|
+
ctx?.onClose();
|
|
145
|
+
},
|
|
146
|
+
...props
|
|
147
|
+
}
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
SheetClose.displayName = "SheetClose";
|
|
152
|
+
|
|
153
|
+
export { Sheet, SheetBody, SheetClose, SheetDescription, SheetFooter, SheetHeader, SheetTitle };
|
|
154
|
+
//# sourceMappingURL=index.js.map
|
|
155
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":[],"mappings":";;;;;;AASA,IAAM,YAAA,GAAqB,oBAAwC,IAAI,CAAA;AAIvE,IAAM,WAAA,GAAyC;AAAA,EAC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KAAA,EAAA,EAAI,GAAA,EAAU,WAAW,EAAA,CAAG,oCAAA,EAAsC,SAAS,CAAA,EAAI,GAAG,KAAA,EAAO;AAE9F;AACA,SAAA,CAAU,WAAA,GAAc,WAAA;AAEjB,IAAM,WAAA,GAAoB,KAAA,CAAA,UAAA;AAAA,EAC/B,CAAC,EAAE,SAAA,EAAW,GAAG,KAAA,IAAS,GAAA,qBACxB,GAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACC,GAAA;AAAA,MACA,SAAA,EAAW,EAAA,CAAG,gEAAA,EAAkE,SAAS,CAAA;AAAA,MACxF,GAAG;AAAA;AAAA;AAGV;AACA,WAAA,CAAY,WAAA,GAAc,aAAA;AAGnB,IAAM,UAAA,GAAmB,KAAA,CAAA,UAAA;AAAA,EAC9B,CAAC,EAAE,OAAA,EAAS,IAAA,GAAO,UAAU,GAAG,KAAA,IAAS,GAAA,KAAQ;AAC/C,IAAA,MAAM,GAAA,GAAY,iBAAW,YAAY,CAAA;AACzC,IAAA,uBACE,GAAA;AAAA,MAAC,QAAA;AAAA,MAAA;AAAA,QACC,GAAA;AAAA,QACA,IAAA;AAAA,QACA,OAAA,EAAS,CAAC,CAAA,KAAM;AACd,UAAA,OAAA,GAAU,CAAC,CAAA;AACX,UAAA,GAAA,EAAK,OAAA,EAAQ;AAAA,QACf,CAAA;AAAA,QACC,GAAG;AAAA;AAAA,KACN;AAAA,EAEJ;AACF;AACA,UAAA,CAAW,WAAA,GAAc,YAAA","file":"index.js","sourcesContent":["import * as React from \"react\";\nimport { X } from \"lucide-react\";\nimport { cn } from \"@nucleux/utils\";\n\ninterface SheetContextValue {\n titleId: string;\n descriptionId: string;\n onClose: () => void;\n}\nconst SheetContext = React.createContext<SheetContextValue | null>(null);\n\nexport type SheetSide = \"right\" | \"left\" | \"top\" | \"bottom\";\n\nconst sideClasses: Record<SheetSide, string> = {\n right: \"inset-y-0 right-0 h-full w-full max-w-sm border-l\",\n left: \"inset-y-0 left-0 h-full w-full max-w-sm border-r\",\n top: \"inset-x-0 top-0 w-full border-b\",\n bottom: \"inset-x-0 bottom-0 w-full border-t\",\n};\n\nexport interface SheetProps {\n /** Whether the sheet is open. */\n open: boolean;\n /** Called when the sheet requests to close (overlay click / Escape / close button). */\n onOpenChange: (open: boolean) => void;\n /** Which edge the sheet slides in from. */\n side?: SheetSide;\n /** Panel content — compose SheetHeader/Title/Description/Body/Footer. */\n children: React.ReactNode;\n /** Class overrides for the panel. */\n className?: string;\n /** Disable closing on overlay click / Escape. */\n dismissible?: boolean;\n}\n\n/**\n * A slide-over drawer anchored to a screen edge. Controlled via `open` /\n * `onOpenChange`; closes on overlay click, Escape, or {@link SheetClose}.\n */\nexport function Sheet({\n open,\n onOpenChange,\n side = \"right\",\n children,\n className,\n dismissible = true,\n}: SheetProps) {\n const baseId = React.useId();\n const panelRef = React.useRef<HTMLDivElement>(null);\n const close = React.useCallback(() => onOpenChange(false), [onOpenChange]);\n\n React.useEffect(() => {\n if (!open || !dismissible) return;\n const onKey = (e: KeyboardEvent) => {\n if (e.key === \"Escape\") close();\n };\n document.addEventListener(\"keydown\", onKey);\n return () => document.removeEventListener(\"keydown\", onKey);\n }, [open, dismissible, close]);\n\n React.useEffect(() => {\n if (open) panelRef.current?.focus();\n }, [open]);\n\n if (!open) return null;\n\n return (\n <SheetContext.Provider\n value={{ titleId: `${baseId}-title`, descriptionId: `${baseId}-desc`, onClose: close }}\n >\n <div className=\"fixed inset-0 z-50\">\n <div\n aria-hidden\n className=\"absolute inset-0 bg-foreground/50 animate-nx-fade-in\"\n onClick={dismissible ? close : undefined}\n />\n <div\n ref={panelRef}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-labelledby={`${baseId}-title`}\n aria-describedby={`${baseId}-desc`}\n tabIndex={-1}\n className={cn(\n \"absolute flex flex-col border-border bg-background shadow-lg outline-none animate-nx-fade-in\",\n sideClasses[side],\n className,\n )}\n >\n {children}\n </div>\n </div>\n </SheetContext.Provider>\n );\n}\n\nexport const SheetHeader = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(\n ({ className, children, ...props }, ref) => {\n const ctx = React.useContext(SheetContext);\n return (\n <div\n ref={ref}\n className={cn(\"flex items-center justify-between gap-4 border-b border-border p-4\", className)}\n {...props}\n >\n <div className=\"min-w-0 flex-1\">{children}</div>\n <button\n type=\"button\"\n aria-label=\"Close\"\n onClick={ctx?.onClose}\n className=\"shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n >\n <X className=\"size-4\" />\n </button>\n </div>\n );\n },\n);\nSheetHeader.displayName = \"SheetHeader\";\n\nexport const SheetTitle = React.forwardRef<HTMLHeadingElement, React.HTMLAttributes<HTMLHeadingElement>>(\n ({ className, ...props }, ref) => {\n const ctx = React.useContext(SheetContext);\n return (\n <h2\n ref={ref}\n id={ctx?.titleId}\n className={cn(\"text-sm font-semibold text-foreground\", className)}\n {...props}\n />\n );\n },\n);\nSheetTitle.displayName = \"SheetTitle\";\n\nexport const SheetDescription = React.forwardRef<\n HTMLParagraphElement,\n React.HTMLAttributes<HTMLParagraphElement>\n>(({ className, ...props }, ref) => {\n const ctx = React.useContext(SheetContext);\n return (\n <p ref={ref} id={ctx?.descriptionId} className={cn(\"text-sm text-muted-foreground\", className)} {...props} />\n );\n});\nSheetDescription.displayName = \"SheetDescription\";\n\nexport const SheetBody = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(\n ({ className, ...props }, ref) => (\n <div ref={ref} className={cn(\"min-h-0 flex-1 overflow-y-auto p-4\", className)} {...props} />\n ),\n);\nSheetBody.displayName = \"SheetBody\";\n\nexport const SheetFooter = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(\n ({ className, ...props }, ref) => (\n <div\n ref={ref}\n className={cn(\"flex items-center justify-end gap-2 border-t border-border p-4\", className)}\n {...props}\n />\n ),\n);\nSheetFooter.displayName = \"SheetFooter\";\n\n/** A button that closes the enclosing Sheet. */\nexport const SheetClose = React.forwardRef<HTMLButtonElement, React.ButtonHTMLAttributes<HTMLButtonElement>>(\n ({ onClick, type = \"button\", ...props }, ref) => {\n const ctx = React.useContext(SheetContext);\n return (\n <button\n ref={ref}\n type={type}\n onClick={(e) => {\n onClick?.(e);\n ctx?.onClose();\n }}\n {...props}\n />\n );\n },\n);\nSheetClose.displayName = \"SheetClose\";\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nucleux/sheet",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"description": "Sheet — a slide-over drawer panel — Nucleux agentic UI for React.",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"nucleux",
|
|
9
|
+
"react",
|
|
10
|
+
"ui",
|
|
11
|
+
"components",
|
|
12
|
+
"agentic",
|
|
13
|
+
"ai",
|
|
14
|
+
"tailwind",
|
|
15
|
+
"sheet",
|
|
16
|
+
"drawer"
|
|
17
|
+
],
|
|
18
|
+
"main": "./dist/index.cjs",
|
|
19
|
+
"module": "./dist/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js",
|
|
25
|
+
"require": "./dist/index.cjs"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"README.md"
|
|
31
|
+
],
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"react": ">=18",
|
|
34
|
+
"react-dom": ">=18"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"lucide-react": "^0.469.0",
|
|
38
|
+
"@nucleux/utils": "0.1.1"
|
|
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/sheet"
|
|
54
|
+
},
|
|
55
|
+
"homepage": "https://github.com/intelligaia-open-labs/nucleux#readme",
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "tsup"
|
|
58
|
+
}
|
|
59
|
+
}
|