@nucleux/alert-dialog 0.2.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 +115 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +29 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +93 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -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/alert-dialog
|
|
2
|
+
|
|
3
|
+
Modal confirmation dialog — 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/alert-dialog @nucleux/tokens
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`react` / `react-dom` are peer dependencies.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { AlertDialog } from "@nucleux/alert-dialog";
|
|
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,115 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var utils = require('@nucleux/utils');
|
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
|
|
8
|
+
function _interopNamespace(e) {
|
|
9
|
+
if (e && e.__esModule) return e;
|
|
10
|
+
var n = Object.create(null);
|
|
11
|
+
if (e) {
|
|
12
|
+
Object.keys(e).forEach(function (k) {
|
|
13
|
+
if (k !== 'default') {
|
|
14
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return e[k]; }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
n.default = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
27
|
+
|
|
28
|
+
// src/index.tsx
|
|
29
|
+
function AlertDialog({
|
|
30
|
+
open,
|
|
31
|
+
onOpenChange,
|
|
32
|
+
title,
|
|
33
|
+
description,
|
|
34
|
+
confirmLabel = "Continue",
|
|
35
|
+
cancelLabel = "Cancel",
|
|
36
|
+
onConfirm,
|
|
37
|
+
onCancel,
|
|
38
|
+
destructive = false,
|
|
39
|
+
children,
|
|
40
|
+
className
|
|
41
|
+
}) {
|
|
42
|
+
const baseId = React__namespace.useId();
|
|
43
|
+
const cancelRef = React__namespace.useRef(null);
|
|
44
|
+
const cancel = React__namespace.useCallback(() => {
|
|
45
|
+
onCancel?.();
|
|
46
|
+
onOpenChange(false);
|
|
47
|
+
}, [onCancel, onOpenChange]);
|
|
48
|
+
const confirm = () => {
|
|
49
|
+
onConfirm?.();
|
|
50
|
+
onOpenChange(false);
|
|
51
|
+
};
|
|
52
|
+
React__namespace.useEffect(() => {
|
|
53
|
+
if (!open) return;
|
|
54
|
+
const onKey = (e) => {
|
|
55
|
+
if (e.key === "Escape") cancel();
|
|
56
|
+
};
|
|
57
|
+
document.addEventListener("keydown", onKey);
|
|
58
|
+
return () => document.removeEventListener("keydown", onKey);
|
|
59
|
+
}, [open, cancel]);
|
|
60
|
+
React__namespace.useEffect(() => {
|
|
61
|
+
if (open) cancelRef.current?.focus();
|
|
62
|
+
}, [open]);
|
|
63
|
+
if (!open) return null;
|
|
64
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "fixed inset-0 z-50 flex items-center justify-center p-4", children: [
|
|
65
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { "aria-hidden": true, className: "absolute inset-0 animate-nx-fade-in bg-foreground/50" }),
|
|
66
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
67
|
+
"div",
|
|
68
|
+
{
|
|
69
|
+
role: "alertdialog",
|
|
70
|
+
"aria-modal": "true",
|
|
71
|
+
"aria-labelledby": `${baseId}-title`,
|
|
72
|
+
"aria-describedby": description ? `${baseId}-desc` : void 0,
|
|
73
|
+
className: utils.cn(
|
|
74
|
+
"relative z-10 flex w-full max-w-md flex-col gap-4 rounded-xl border border-border bg-background p-6 shadow-lg outline-none animate-nx-fade-in",
|
|
75
|
+
className
|
|
76
|
+
),
|
|
77
|
+
children: [
|
|
78
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
79
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { id: `${baseId}-title`, className: "text-lg font-semibold text-foreground", children: title }),
|
|
80
|
+
description && /* @__PURE__ */ jsxRuntime.jsx("p", { id: `${baseId}-desc`, className: "text-sm text-muted-foreground", children: description })
|
|
81
|
+
] }),
|
|
82
|
+
children,
|
|
83
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-2 pt-2", children: [
|
|
84
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
85
|
+
"button",
|
|
86
|
+
{
|
|
87
|
+
ref: cancelRef,
|
|
88
|
+
type: "button",
|
|
89
|
+
onClick: cancel,
|
|
90
|
+
className: "inline-flex h-9 items-center justify-center rounded-md border border-input bg-background px-4 text-sm font-medium text-foreground shadow-sm transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",
|
|
91
|
+
children: cancelLabel
|
|
92
|
+
}
|
|
93
|
+
),
|
|
94
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
95
|
+
"button",
|
|
96
|
+
{
|
|
97
|
+
type: "button",
|
|
98
|
+
onClick: confirm,
|
|
99
|
+
className: utils.cn(
|
|
100
|
+
"inline-flex h-9 items-center justify-center rounded-md px-4 text-sm font-medium shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-offset-background",
|
|
101
|
+
destructive ? "bg-destructive text-destructive-foreground hover:bg-destructive/90 focus-visible:ring-destructive" : "bg-primary text-primary-foreground hover:bg-primary/90 focus-visible:ring-ring"
|
|
102
|
+
),
|
|
103
|
+
children: confirmLabel
|
|
104
|
+
}
|
|
105
|
+
)
|
|
106
|
+
] })
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
)
|
|
110
|
+
] });
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
exports.AlertDialog = AlertDialog;
|
|
114
|
+
//# sourceMappingURL=index.cjs.map
|
|
115
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":["React","jsxs","jsx","cn"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BO,SAAS,WAAA,CAAY;AAAA,EAC1B,IAAA;AAAA,EACA,YAAA;AAAA,EACA,KAAA;AAAA,EACA,WAAA;AAAA,EACA,YAAA,GAAe,UAAA;AAAA,EACf,WAAA,GAAc,QAAA;AAAA,EACd,SAAA;AAAA,EACA,QAAA;AAAA,EACA,WAAA,GAAc,KAAA;AAAA,EACd,QAAA;AAAA,EACA;AACF,CAAA,EAAqB;AACnB,EAAA,MAAM,SAAeA,gBAAA,CAAA,KAAA,EAAM;AAC3B,EAAA,MAAM,SAAA,GAAkBA,wBAA0B,IAAI,CAAA;AAEtD,EAAA,MAAM,MAAA,GAAeA,6BAAY,MAAM;AACrC,IAAA,QAAA,IAAW;AACX,IAAA,YAAA,CAAa,KAAK,CAAA;AAAA,EACpB,CAAA,EAAG,CAAC,QAAA,EAAU,YAAY,CAAC,CAAA;AAE3B,EAAA,MAAM,UAAU,MAAM;AACpB,IAAA,SAAA,IAAY;AACZ,IAAA,YAAA,CAAa,KAAK,CAAA;AAAA,EACpB,CAAA;AAEA,EAAMA,2BAAU,MAAM;AACpB,IAAA,IAAI,CAAC,IAAA,EAAM;AACX,IAAA,MA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,CAAA;AAAA,YACC,WAAA,mCACE,GAAA,EAAA,EAAE,EAAA,EAAI,GAAG,MAAM,CAAA,KAAA,CAAA,EAAS,SAAA,EAAU,+BAAA,EAChC,QAAA,EAAA,WAAA,EACH;AAAA,WAAA,EAEJ,CAAA;AAAA,UACC,QAAA;AAAA,0BACDD,eAAA,CAAC,KAAA,EAAA,EAAI,SAAA,EAAU,0CAAA,EACb,QAAA,EAAA;AAAA,4BAAAC,cAAA;AAAA,cAAC,QAAA;AAAA,cAAA;AAAA,gBACC,GAAA,EAAK,SAAA;AAAA,gBACL,IAAA,EAAK,QAAA;AAAA,gBACL,OAAA,EAAS,MAAA;AAAA,gBACT,SAAA,EAAU,uTAAA;AAAA,gBAET,QAAA,EAAA;AAAA;AAAA,aACH;AAAA,4BACAA,cAAA;AAAA,cAAC,QAAA;AAAA,cAAA;AAAA,gBACC,IAAA,EAAK,QAAA;AAAA,gBACL,OAAA,EAAS,OAAA;AAAA,gBACT,SAAA,EAAWC,QAAA;AAAA,kBACT,8NAAA;AAAA,kBACA,cACI,mGAAA,GACA;AAAA,iBACN;AAAA,gBAEC,QAAA,EAAA;AAAA;AAAA;AACH,WAAA,EACF;AAAA;AAAA;AAAA;AACF,GAAA,EACF,CAAA;AAEJ","file":"index.cjs","sourcesContent":["import * as React from \"react\";\nimport { cn } from \"@nucleux/utils\";\n\nexport interface AlertDialogProps {\n /** Whether the alert dialog is open. */\n open: boolean;\n /** Called when the dialog requests to close (Escape / a button). */\n onOpenChange: (open: boolean) => void;\n title: React.ReactNode;\n description?: React.ReactNode;\n /** Confirm button label. */\n confirmLabel?: string;\n /** Cancel button label. */\n cancelLabel?: string;\n onConfirm?: () => void;\n onCancel?: () => void;\n /** Style the confirm action as destructive. */\n destructive?: boolean;\n /** Extra content between the description and the actions. */\n children?: React.ReactNode;\n className?: string;\n}\n\n/**\n * A modal confirmation dialog for consequential actions. Unlike Dialog, it uses\n * role=\"alertdialog\", does not close on overlay click, and focuses Cancel by\n * default. Escape triggers cancel.\n */\nexport function AlertDialog({\n open,\n onOpenChange,\n title,\n description,\n confirmLabel = \"Continue\",\n cancelLabel = \"Cancel\",\n onConfirm,\n onCancel,\n destructive = false,\n children,\n className,\n}: AlertDialogProps) {\n const baseId = React.useId();\n const cancelRef = React.useRef<HTMLButtonElement>(null);\n\n const cancel = React.useCallback(() => {\n onCancel?.();\n onOpenChange(false);\n }, [onCancel, onOpenChange]);\n\n const confirm = () => {\n onConfirm?.();\n onOpenChange(false);\n };\n\n React.useEffect(() => {\n if (!open) return;\n const onKey = (e: KeyboardEvent) => {\n if (e.key === \"Escape\") cancel();\n };\n document.addEventListener(\"keydown\", onKey);\n return () => document.removeEventListener(\"keydown\", onKey);\n }, [open, cancel]);\n\n React.useEffect(() => {\n if (open) cancelRef.current?.focus();\n }, [open]);\n\n if (!open) return null;\n\n return (\n <div className=\"fixed inset-0 z-50 flex items-center justify-center p-4\">\n <div aria-hidden className=\"absolute inset-0 animate-nx-fade-in bg-foreground/50\" />\n <div\n role=\"alertdialog\"\n aria-modal=\"true\"\n aria-labelledby={`${baseId}-title`}\n aria-describedby={description ? `${baseId}-desc` : undefined}\n className={cn(\n \"relative z-10 flex w-full max-w-md flex-col gap-4 rounded-xl border border-border bg-background p-6 shadow-lg outline-none animate-nx-fade-in\",\n className,\n )}\n >\n <div className=\"flex flex-col gap-1\">\n <h2 id={`${baseId}-title`} className=\"text-lg font-semibold text-foreground\">\n {title}\n </h2>\n {description && (\n <p id={`${baseId}-desc`} className=\"text-sm text-muted-foreground\">\n {description}\n </p>\n )}\n </div>\n {children}\n <div className=\"flex items-center justify-end gap-2 pt-2\">\n <button\n ref={cancelRef}\n type=\"button\"\n onClick={cancel}\n className=\"inline-flex h-9 items-center justify-center rounded-md border border-input bg-background px-4 text-sm font-medium text-foreground shadow-sm transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background\"\n >\n {cancelLabel}\n </button>\n <button\n type=\"button\"\n onClick={confirm}\n className={cn(\n \"inline-flex h-9 items-center justify-center rounded-md px-4 text-sm font-medium shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-offset-background\",\n destructive\n ? \"bg-destructive text-destructive-foreground hover:bg-destructive/90 focus-visible:ring-destructive\"\n : \"bg-primary text-primary-foreground hover:bg-primary/90 focus-visible:ring-ring\",\n )}\n >\n {confirmLabel}\n </button>\n </div>\n </div>\n </div>\n );\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface AlertDialogProps {
|
|
4
|
+
/** Whether the alert dialog is open. */
|
|
5
|
+
open: boolean;
|
|
6
|
+
/** Called when the dialog requests to close (Escape / a button). */
|
|
7
|
+
onOpenChange: (open: boolean) => void;
|
|
8
|
+
title: React.ReactNode;
|
|
9
|
+
description?: React.ReactNode;
|
|
10
|
+
/** Confirm button label. */
|
|
11
|
+
confirmLabel?: string;
|
|
12
|
+
/** Cancel button label. */
|
|
13
|
+
cancelLabel?: string;
|
|
14
|
+
onConfirm?: () => void;
|
|
15
|
+
onCancel?: () => void;
|
|
16
|
+
/** Style the confirm action as destructive. */
|
|
17
|
+
destructive?: boolean;
|
|
18
|
+
/** Extra content between the description and the actions. */
|
|
19
|
+
children?: React.ReactNode;
|
|
20
|
+
className?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A modal confirmation dialog for consequential actions. Unlike Dialog, it uses
|
|
24
|
+
* role="alertdialog", does not close on overlay click, and focuses Cancel by
|
|
25
|
+
* default. Escape triggers cancel.
|
|
26
|
+
*/
|
|
27
|
+
declare function AlertDialog({ open, onOpenChange, title, description, confirmLabel, cancelLabel, onConfirm, onCancel, destructive, children, className, }: AlertDialogProps): React.JSX.Element | null;
|
|
28
|
+
|
|
29
|
+
export { AlertDialog, type AlertDialogProps };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface AlertDialogProps {
|
|
4
|
+
/** Whether the alert dialog is open. */
|
|
5
|
+
open: boolean;
|
|
6
|
+
/** Called when the dialog requests to close (Escape / a button). */
|
|
7
|
+
onOpenChange: (open: boolean) => void;
|
|
8
|
+
title: React.ReactNode;
|
|
9
|
+
description?: React.ReactNode;
|
|
10
|
+
/** Confirm button label. */
|
|
11
|
+
confirmLabel?: string;
|
|
12
|
+
/** Cancel button label. */
|
|
13
|
+
cancelLabel?: string;
|
|
14
|
+
onConfirm?: () => void;
|
|
15
|
+
onCancel?: () => void;
|
|
16
|
+
/** Style the confirm action as destructive. */
|
|
17
|
+
destructive?: boolean;
|
|
18
|
+
/** Extra content between the description and the actions. */
|
|
19
|
+
children?: React.ReactNode;
|
|
20
|
+
className?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A modal confirmation dialog for consequential actions. Unlike Dialog, it uses
|
|
24
|
+
* role="alertdialog", does not close on overlay click, and focuses Cancel by
|
|
25
|
+
* default. Escape triggers cancel.
|
|
26
|
+
*/
|
|
27
|
+
declare function AlertDialog({ open, onOpenChange, title, description, confirmLabel, cancelLabel, onConfirm, onCancel, destructive, children, className, }: AlertDialogProps): React.JSX.Element | null;
|
|
28
|
+
|
|
29
|
+
export { AlertDialog, type AlertDialogProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { cn } from '@nucleux/utils';
|
|
4
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
// src/index.tsx
|
|
7
|
+
function AlertDialog({
|
|
8
|
+
open,
|
|
9
|
+
onOpenChange,
|
|
10
|
+
title,
|
|
11
|
+
description,
|
|
12
|
+
confirmLabel = "Continue",
|
|
13
|
+
cancelLabel = "Cancel",
|
|
14
|
+
onConfirm,
|
|
15
|
+
onCancel,
|
|
16
|
+
destructive = false,
|
|
17
|
+
children,
|
|
18
|
+
className
|
|
19
|
+
}) {
|
|
20
|
+
const baseId = React.useId();
|
|
21
|
+
const cancelRef = React.useRef(null);
|
|
22
|
+
const cancel = React.useCallback(() => {
|
|
23
|
+
onCancel?.();
|
|
24
|
+
onOpenChange(false);
|
|
25
|
+
}, [onCancel, onOpenChange]);
|
|
26
|
+
const confirm = () => {
|
|
27
|
+
onConfirm?.();
|
|
28
|
+
onOpenChange(false);
|
|
29
|
+
};
|
|
30
|
+
React.useEffect(() => {
|
|
31
|
+
if (!open) return;
|
|
32
|
+
const onKey = (e) => {
|
|
33
|
+
if (e.key === "Escape") cancel();
|
|
34
|
+
};
|
|
35
|
+
document.addEventListener("keydown", onKey);
|
|
36
|
+
return () => document.removeEventListener("keydown", onKey);
|
|
37
|
+
}, [open, cancel]);
|
|
38
|
+
React.useEffect(() => {
|
|
39
|
+
if (open) cancelRef.current?.focus();
|
|
40
|
+
}, [open]);
|
|
41
|
+
if (!open) return null;
|
|
42
|
+
return /* @__PURE__ */ jsxs("div", { className: "fixed inset-0 z-50 flex items-center justify-center p-4", children: [
|
|
43
|
+
/* @__PURE__ */ jsx("div", { "aria-hidden": true, className: "absolute inset-0 animate-nx-fade-in bg-foreground/50" }),
|
|
44
|
+
/* @__PURE__ */ jsxs(
|
|
45
|
+
"div",
|
|
46
|
+
{
|
|
47
|
+
role: "alertdialog",
|
|
48
|
+
"aria-modal": "true",
|
|
49
|
+
"aria-labelledby": `${baseId}-title`,
|
|
50
|
+
"aria-describedby": description ? `${baseId}-desc` : void 0,
|
|
51
|
+
className: cn(
|
|
52
|
+
"relative z-10 flex w-full max-w-md flex-col gap-4 rounded-xl border border-border bg-background p-6 shadow-lg outline-none animate-nx-fade-in",
|
|
53
|
+
className
|
|
54
|
+
),
|
|
55
|
+
children: [
|
|
56
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
57
|
+
/* @__PURE__ */ jsx("h2", { id: `${baseId}-title`, className: "text-lg font-semibold text-foreground", children: title }),
|
|
58
|
+
description && /* @__PURE__ */ jsx("p", { id: `${baseId}-desc`, className: "text-sm text-muted-foreground", children: description })
|
|
59
|
+
] }),
|
|
60
|
+
children,
|
|
61
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-2 pt-2", children: [
|
|
62
|
+
/* @__PURE__ */ jsx(
|
|
63
|
+
"button",
|
|
64
|
+
{
|
|
65
|
+
ref: cancelRef,
|
|
66
|
+
type: "button",
|
|
67
|
+
onClick: cancel,
|
|
68
|
+
className: "inline-flex h-9 items-center justify-center rounded-md border border-input bg-background px-4 text-sm font-medium text-foreground shadow-sm transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",
|
|
69
|
+
children: cancelLabel
|
|
70
|
+
}
|
|
71
|
+
),
|
|
72
|
+
/* @__PURE__ */ jsx(
|
|
73
|
+
"button",
|
|
74
|
+
{
|
|
75
|
+
type: "button",
|
|
76
|
+
onClick: confirm,
|
|
77
|
+
className: cn(
|
|
78
|
+
"inline-flex h-9 items-center justify-center rounded-md px-4 text-sm font-medium shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-offset-background",
|
|
79
|
+
destructive ? "bg-destructive text-destructive-foreground hover:bg-destructive/90 focus-visible:ring-destructive" : "bg-primary text-primary-foreground hover:bg-primary/90 focus-visible:ring-ring"
|
|
80
|
+
),
|
|
81
|
+
children: confirmLabel
|
|
82
|
+
}
|
|
83
|
+
)
|
|
84
|
+
] })
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
)
|
|
88
|
+
] });
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export { AlertDialog };
|
|
92
|
+
//# sourceMappingURL=index.js.map
|
|
93
|
+
//# sourceMappingURL=index.js.map
|
|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AA;AAAA;AAAA,aACH;AAAA,4BACA,GAAA;AAAA,cAAC,QAAA;AAAA,cAAA;AAAA,gBACC,IAAA,EAAK,QAAA;AAAA,gBACL,OAAA,EAAS,OAAA;AAAA,gBACT,SAAA,EAAW,EAAA;AAAA,kBACT,8NAAA;AAAA,kBACA,cACI,mGAAA,GACA;AAAA,iBACN;AAAA,gBAEC,QAAA,EAAA;AAAA;AAAA;AACH,WAAA,EACF;AAAA;AAAA;AAAA;AACF,GAAA,EACF,CAAA;AAEJ","file":"index.js","sourcesContent":["import * as React from \"react\";\nimport { cn } from \"@nucleux/utils\";\n\nexport interface AlertDialogProps {\n /** Whether the alert dialog is open. */\n open: boolean;\n /** Called when the dialog requests to close (Escape / a button). */\n onOpenChange: (open: boolean) => void;\n title: React.ReactNode;\n description?: React.ReactNode;\n /** Confirm button label. */\n confirmLabel?: string;\n /** Cancel button label. */\n cancelLabel?: string;\n onConfirm?: () => void;\n onCancel?: () => void;\n /** Style the confirm action as destructive. */\n destructive?: boolean;\n /** Extra content between the description and the actions. */\n children?: React.ReactNode;\n className?: string;\n}\n\n/**\n * A modal confirmation dialog for consequential actions. Unlike Dialog, it uses\n * role=\"alertdialog\", does not close on overlay click, and focuses Cancel by\n * default. Escape triggers cancel.\n */\nexport function AlertDialog({\n open,\n onOpenChange,\n title,\n description,\n confirmLabel = \"Continue\",\n cancelLabel = \"Cancel\",\n onConfirm,\n onCancel,\n destructive = false,\n children,\n className,\n}: AlertDialogProps) {\n const baseId = React.useId();\n const cancelRef = React.useRef<HTMLButtonElement>(null);\n\n const cancel = React.useCallback(() => {\n onCancel?.();\n onOpenChange(false);\n }, [onCancel, onOpenChange]);\n\n const confirm = () => {\n onConfirm?.();\n onOpenChange(false);\n };\n\n React.useEffect(() => {\n if (!open) return;\n const onKey = (e: KeyboardEvent) => {\n if (e.key === \"Escape\") cancel();\n };\n document.addEventListener(\"keydown\", onKey);\n return () => document.removeEventListener(\"keydown\", onKey);\n }, [open, cancel]);\n\n React.useEffect(() => {\n if (open) cancelRef.current?.focus();\n }, [open]);\n\n if (!open) return null;\n\n return (\n <div className=\"fixed inset-0 z-50 flex items-center justify-center p-4\">\n <div aria-hidden className=\"absolute inset-0 animate-nx-fade-in bg-foreground/50\" />\n <div\n role=\"alertdialog\"\n aria-modal=\"true\"\n aria-labelledby={`${baseId}-title`}\n aria-describedby={description ? `${baseId}-desc` : undefined}\n className={cn(\n \"relative z-10 flex w-full max-w-md flex-col gap-4 rounded-xl border border-border bg-background p-6 shadow-lg outline-none animate-nx-fade-in\",\n className,\n )}\n >\n <div className=\"flex flex-col gap-1\">\n <h2 id={`${baseId}-title`} className=\"text-lg font-semibold text-foreground\">\n {title}\n </h2>\n {description && (\n <p id={`${baseId}-desc`} className=\"text-sm text-muted-foreground\">\n {description}\n </p>\n )}\n </div>\n {children}\n <div className=\"flex items-center justify-end gap-2 pt-2\">\n <button\n ref={cancelRef}\n type=\"button\"\n onClick={cancel}\n className=\"inline-flex h-9 items-center justify-center rounded-md border border-input bg-background px-4 text-sm font-medium text-foreground shadow-sm transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background\"\n >\n {cancelLabel}\n </button>\n <button\n type=\"button\"\n onClick={confirm}\n className={cn(\n \"inline-flex h-9 items-center justify-center rounded-md px-4 text-sm font-medium shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-offset-background\",\n destructive\n ? \"bg-destructive text-destructive-foreground hover:bg-destructive/90 focus-visible:ring-destructive\"\n : \"bg-primary text-primary-foreground hover:bg-primary/90 focus-visible:ring-ring\",\n )}\n >\n {confirmLabel}\n </button>\n </div>\n </div>\n </div>\n );\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nucleux/alert-dialog",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"description": "Modal confirmation dialog — Nucleux agentic UI for React.",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"nucleux",
|
|
9
|
+
"react",
|
|
10
|
+
"ui",
|
|
11
|
+
"components",
|
|
12
|
+
"agentic",
|
|
13
|
+
"ai",
|
|
14
|
+
"tailwind",
|
|
15
|
+
"alert-dialog"
|
|
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
|
+
"@nucleux/utils": "0.2.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"tsup": "^8.3.5",
|
|
40
|
+
"typescript": "^5.7.2",
|
|
41
|
+
"@types/react": "^18.3.18",
|
|
42
|
+
"react": "^18.3.1",
|
|
43
|
+
"lucide-react": "^0.469.0"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"license": "MIT",
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "git+https://github.com/intelligaia-open-labs/nucleux.git",
|
|
52
|
+
"directory": "packages/alert-dialog"
|
|
53
|
+
},
|
|
54
|
+
"homepage": "https://github.com/intelligaia-open-labs/nucleux#readme",
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsup"
|
|
57
|
+
}
|
|
58
|
+
}
|