@behivetech/molecules.confirm-dialog 0.0.0-stage → 0.2.2
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/README.md +10 -2
- package/confirm-dialog.example.tsx +23 -0
- package/confirm-dialog.module.scss +19 -0
- package/confirm-dialog.tsx +66 -0
- package/dist/index.cjs +194 -0
- package/dist/index.css +15 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +180 -0
- package/docs.json +71 -0
- package/index.ts +2 -0
- package/package.json +60 -3
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ConfirmDialog
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TODO: Add component description.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```jsx
|
|
8
|
+
import { ConfirmDialog } from "@behivetech/molecules.confirm-dialog";
|
|
9
|
+
|
|
10
|
+
<ConfirmDialog>Content</ConfirmDialog>;
|
|
11
|
+
```
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { ConfirmDialog } from "./confirm-dialog.js";
|
|
3
|
+
|
|
4
|
+
export const BasicConfirmDialog = () => {
|
|
5
|
+
const [open, setOpen] = useState(false);
|
|
6
|
+
|
|
7
|
+
return (
|
|
8
|
+
<>
|
|
9
|
+
<button type="button" onClick={() => setOpen(true)}>
|
|
10
|
+
Delete page
|
|
11
|
+
</button>
|
|
12
|
+
<ConfirmDialog
|
|
13
|
+
open={open}
|
|
14
|
+
onOpenChange={setOpen}
|
|
15
|
+
title="Delete page"
|
|
16
|
+
message='Are you sure you want to delete "About Us"? This cannot be undone.'
|
|
17
|
+
confirmLabel="Delete"
|
|
18
|
+
variant="danger"
|
|
19
|
+
onConfirm={() => console.log("confirmed delete")}
|
|
20
|
+
/>
|
|
21
|
+
</>
|
|
22
|
+
);
|
|
23
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Content of a Material Design 3 basic dialog; the dialog itself is Modal.
|
|
2
|
+
|
|
3
|
+
.BHT__ConfirmDialog {
|
|
4
|
+
&__message {
|
|
5
|
+
font-family: var(--md-sys-typescale-body-medium-font, var(--font-body));
|
|
6
|
+
font-size: var(--md-sys-typescale-body-medium-size, 0.875rem);
|
|
7
|
+
font-weight: var(--md-sys-typescale-body-medium-weight, 400);
|
|
8
|
+
line-height: var(--md-sys-typescale-body-medium-line-height, 1.25rem);
|
|
9
|
+
letter-spacing: var(--md-sys-typescale-body-medium-tracking, 0.0179em);
|
|
10
|
+
color: var(--md-sys-color-on-surface-variant, var(--color-text-muted));
|
|
11
|
+
margin: 0 0 var(--spacing-5, 1.25rem);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
&__actions {
|
|
15
|
+
display: flex;
|
|
16
|
+
justify-content: flex-end;
|
|
17
|
+
gap: var(--spacing-3, 0.75rem);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { getClassName } from "@bht-component-registry/class-names";
|
|
3
|
+
import { Modal } from "@behivetech/atoms.modal";
|
|
4
|
+
import { Button } from "@behivetech/atoms.button";
|
|
5
|
+
import styles from "./confirm-dialog.module.scss";
|
|
6
|
+
|
|
7
|
+
export interface ConfirmDialogProps {
|
|
8
|
+
/** Whether the dialog is open */
|
|
9
|
+
open: boolean;
|
|
10
|
+
/** Called when the dialog should close (cancel, confirm, backdrop click, Escape) */
|
|
11
|
+
onOpenChange: (open: boolean) => void;
|
|
12
|
+
/** Dialog title */
|
|
13
|
+
title: string;
|
|
14
|
+
/** Confirmation message/body content */
|
|
15
|
+
message: ReactNode;
|
|
16
|
+
/** Confirm button label; defaults to "Confirm" */
|
|
17
|
+
confirmLabel?: string;
|
|
18
|
+
/** Cancel button label; defaults to "Cancel" */
|
|
19
|
+
cancelLabel?: string;
|
|
20
|
+
/** Called when the confirm button is clicked, before the dialog closes */
|
|
21
|
+
onConfirm: () => void;
|
|
22
|
+
/** Renders the confirm button as a destructive action; defaults to "default" */
|
|
23
|
+
variant?: "default" | "danger";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A `Modal` pre-wired with a message and confirm/cancel actions, for "are you
|
|
28
|
+
* sure?" moments — e.g. confirming a delete.
|
|
29
|
+
*/
|
|
30
|
+
export const ConfirmDialog = ({
|
|
31
|
+
open,
|
|
32
|
+
onOpenChange,
|
|
33
|
+
title,
|
|
34
|
+
message,
|
|
35
|
+
confirmLabel = "Confirm",
|
|
36
|
+
cancelLabel = "Cancel",
|
|
37
|
+
onConfirm,
|
|
38
|
+
variant = "default",
|
|
39
|
+
}: ConfirmDialogProps) => {
|
|
40
|
+
const [, getChildClass] = getClassName({
|
|
41
|
+
rootClass: "BHT__ConfirmDialog",
|
|
42
|
+
styles,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
if (!open) return null;
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<Modal title={title} onClose={() => onOpenChange(false)}>
|
|
49
|
+
<p className={getChildClass("message")}>{message}</p>
|
|
50
|
+
<div className={getChildClass("actions")}>
|
|
51
|
+
<Button variant="ghost" onClick={() => onOpenChange(false)}>
|
|
52
|
+
{cancelLabel}
|
|
53
|
+
</Button>
|
|
54
|
+
<Button
|
|
55
|
+
variant={variant === "danger" ? "danger" : "primary"}
|
|
56
|
+
onClick={() => {
|
|
57
|
+
onConfirm();
|
|
58
|
+
onOpenChange(false);
|
|
59
|
+
}}
|
|
60
|
+
>
|
|
61
|
+
{confirmLabel}
|
|
62
|
+
</Button>
|
|
63
|
+
</div>
|
|
64
|
+
</Modal>
|
|
65
|
+
);
|
|
66
|
+
};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
+
|
|
33
|
+
// ../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js
|
|
34
|
+
var require_classnames = __commonJS({
|
|
35
|
+
"../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js"(exports2, module2) {
|
|
36
|
+
"use strict";
|
|
37
|
+
(function() {
|
|
38
|
+
"use strict";
|
|
39
|
+
var hasOwn = {}.hasOwnProperty;
|
|
40
|
+
function classNames() {
|
|
41
|
+
var classes = "";
|
|
42
|
+
for (var i = 0; i < arguments.length; i++) {
|
|
43
|
+
var arg = arguments[i];
|
|
44
|
+
if (arg) {
|
|
45
|
+
classes = appendClass(classes, parseValue(arg));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return classes;
|
|
49
|
+
}
|
|
50
|
+
function parseValue(arg) {
|
|
51
|
+
if (typeof arg === "string" || typeof arg === "number") {
|
|
52
|
+
return arg;
|
|
53
|
+
}
|
|
54
|
+
if (typeof arg !== "object") {
|
|
55
|
+
return "";
|
|
56
|
+
}
|
|
57
|
+
if (Array.isArray(arg)) {
|
|
58
|
+
return classNames.apply(null, arg);
|
|
59
|
+
}
|
|
60
|
+
if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
|
|
61
|
+
return arg.toString();
|
|
62
|
+
}
|
|
63
|
+
var classes = "";
|
|
64
|
+
for (var key in arg) {
|
|
65
|
+
if (hasOwn.call(arg, key) && arg[key]) {
|
|
66
|
+
classes = appendClass(classes, key);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return classes;
|
|
70
|
+
}
|
|
71
|
+
function appendClass(value, newClass) {
|
|
72
|
+
if (!newClass) {
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
if (value) {
|
|
76
|
+
return value + " " + newClass;
|
|
77
|
+
}
|
|
78
|
+
return value + newClass;
|
|
79
|
+
}
|
|
80
|
+
if (typeof module2 !== "undefined" && module2.exports) {
|
|
81
|
+
classNames.default = classNames;
|
|
82
|
+
module2.exports = classNames;
|
|
83
|
+
} else if (typeof define === "function" && typeof define.amd === "object" && define.amd) {
|
|
84
|
+
define("classnames", [], function() {
|
|
85
|
+
return classNames;
|
|
86
|
+
});
|
|
87
|
+
} else {
|
|
88
|
+
window.classNames = classNames;
|
|
89
|
+
}
|
|
90
|
+
})();
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// index.ts
|
|
95
|
+
var index_exports = {};
|
|
96
|
+
__export(index_exports, {
|
|
97
|
+
ConfirmDialog: () => ConfirmDialog
|
|
98
|
+
});
|
|
99
|
+
module.exports = __toCommonJS(index_exports);
|
|
100
|
+
|
|
101
|
+
// ../../../../packages/registry/class-names/dist/index.js
|
|
102
|
+
var import_classnames = __toESM(require_classnames(), 1);
|
|
103
|
+
var getClassName = ({
|
|
104
|
+
className,
|
|
105
|
+
modifiers = {},
|
|
106
|
+
rootClass,
|
|
107
|
+
styles = {}
|
|
108
|
+
}) => {
|
|
109
|
+
function getModifiers() {
|
|
110
|
+
const updatedModifiers = {};
|
|
111
|
+
const modifierKeys = Object.keys(modifiers);
|
|
112
|
+
if (modifierKeys.length) {
|
|
113
|
+
modifierKeys.forEach((modKey) => {
|
|
114
|
+
const classKey = `${rootClass}--${modKey}`;
|
|
115
|
+
const newClassName = styles[classKey] || classKey;
|
|
116
|
+
updatedModifiers[newClassName] = modifiers[modKey] ?? false;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return updatedModifiers;
|
|
120
|
+
}
|
|
121
|
+
function getChildClass(childClassName) {
|
|
122
|
+
const classKey = `${rootClass}__${childClassName}`;
|
|
123
|
+
return styles[classKey] || classKey;
|
|
124
|
+
}
|
|
125
|
+
function getRootStyles() {
|
|
126
|
+
return (0, import_classnames.default)(
|
|
127
|
+
className,
|
|
128
|
+
{
|
|
129
|
+
...getModifiers()
|
|
130
|
+
},
|
|
131
|
+
styles[rootClass] || rootClass
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
return [getRootStyles(), getChildClass];
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// confirm-dialog.tsx
|
|
138
|
+
var import_atoms = require("@behivetech/atoms.modal");
|
|
139
|
+
var import_atoms2 = require("@behivetech/atoms.button");
|
|
140
|
+
|
|
141
|
+
// confirm-dialog.module.scss
|
|
142
|
+
var confirm_dialog_module_default = {
|
|
143
|
+
"BHT__ConfirmDialog__message": "BHT__ConfirmDialog__message",
|
|
144
|
+
"BHT__ConfirmDialog__actions": "BHT__ConfirmDialog__actions"
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// confirm-dialog.tsx
|
|
148
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
149
|
+
var ConfirmDialog = ({
|
|
150
|
+
open,
|
|
151
|
+
onOpenChange,
|
|
152
|
+
title,
|
|
153
|
+
message,
|
|
154
|
+
confirmLabel = "Confirm",
|
|
155
|
+
cancelLabel = "Cancel",
|
|
156
|
+
onConfirm,
|
|
157
|
+
variant = "default"
|
|
158
|
+
}) => {
|
|
159
|
+
const [, getChildClass] = getClassName({
|
|
160
|
+
rootClass: "BHT__ConfirmDialog",
|
|
161
|
+
styles: confirm_dialog_module_default
|
|
162
|
+
});
|
|
163
|
+
if (!open) return null;
|
|
164
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_atoms.Modal, { title, onClose: () => onOpenChange(false), children: [
|
|
165
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: getChildClass("message"), children: message }),
|
|
166
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: getChildClass("actions"), children: [
|
|
167
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_atoms2.Button, { variant: "ghost", onClick: () => onOpenChange(false), children: cancelLabel }),
|
|
168
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
169
|
+
import_atoms2.Button,
|
|
170
|
+
{
|
|
171
|
+
variant: variant === "danger" ? "danger" : "primary",
|
|
172
|
+
onClick: () => {
|
|
173
|
+
onConfirm();
|
|
174
|
+
onOpenChange(false);
|
|
175
|
+
},
|
|
176
|
+
children: confirmLabel
|
|
177
|
+
}
|
|
178
|
+
)
|
|
179
|
+
] })
|
|
180
|
+
] });
|
|
181
|
+
};
|
|
182
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
183
|
+
0 && (module.exports = {
|
|
184
|
+
ConfirmDialog
|
|
185
|
+
});
|
|
186
|
+
/*! Bundled license information:
|
|
187
|
+
|
|
188
|
+
classnames/index.js:
|
|
189
|
+
(*!
|
|
190
|
+
Copyright (c) 2018 Jed Watson.
|
|
191
|
+
Licensed under the MIT License (MIT), see
|
|
192
|
+
http://jedwatson.github.io/classnames
|
|
193
|
+
*)
|
|
194
|
+
*/
|
package/dist/index.css
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* esbuild-sass-plugin:css-chunkconfirm-dialog.module.scss */
|
|
2
|
+
.BHT__ConfirmDialog__message {
|
|
3
|
+
font-family: var(--md-sys-typescale-body-medium-font, var(--font-body));
|
|
4
|
+
font-size: var(--md-sys-typescale-body-medium-size, 0.875rem);
|
|
5
|
+
font-weight: var(--md-sys-typescale-body-medium-weight, 400);
|
|
6
|
+
line-height: var(--md-sys-typescale-body-medium-line-height, 1.25rem);
|
|
7
|
+
letter-spacing: var(--md-sys-typescale-body-medium-tracking, 0.0179em);
|
|
8
|
+
color: var(--md-sys-color-on-surface-variant, var(--color-text-muted));
|
|
9
|
+
margin: 0 0 var(--spacing-5, 1.25rem);
|
|
10
|
+
}
|
|
11
|
+
.BHT__ConfirmDialog__actions {
|
|
12
|
+
display: flex;
|
|
13
|
+
justify-content: flex-end;
|
|
14
|
+
gap: var(--spacing-3, 0.75rem);
|
|
15
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
interface ConfirmDialogProps {
|
|
5
|
+
/** Whether the dialog is open */
|
|
6
|
+
open: boolean;
|
|
7
|
+
/** Called when the dialog should close (cancel, confirm, backdrop click, Escape) */
|
|
8
|
+
onOpenChange: (open: boolean) => void;
|
|
9
|
+
/** Dialog title */
|
|
10
|
+
title: string;
|
|
11
|
+
/** Confirmation message/body content */
|
|
12
|
+
message: ReactNode;
|
|
13
|
+
/** Confirm button label; defaults to "Confirm" */
|
|
14
|
+
confirmLabel?: string;
|
|
15
|
+
/** Cancel button label; defaults to "Cancel" */
|
|
16
|
+
cancelLabel?: string;
|
|
17
|
+
/** Called when the confirm button is clicked, before the dialog closes */
|
|
18
|
+
onConfirm: () => void;
|
|
19
|
+
/** Renders the confirm button as a destructive action; defaults to "default" */
|
|
20
|
+
variant?: "default" | "danger";
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A `Modal` pre-wired with a message and confirm/cancel actions, for "are you
|
|
24
|
+
* sure?" moments — e.g. confirming a delete.
|
|
25
|
+
*/
|
|
26
|
+
declare const ConfirmDialog: ({ open, onOpenChange, title, message, confirmLabel, cancelLabel, onConfirm, variant, }: ConfirmDialogProps) => react.JSX.Element | null;
|
|
27
|
+
|
|
28
|
+
export { ConfirmDialog, type ConfirmDialogProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
// ../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js
|
|
28
|
+
var require_classnames = __commonJS({
|
|
29
|
+
"../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js"(exports, module) {
|
|
30
|
+
"use strict";
|
|
31
|
+
(function() {
|
|
32
|
+
"use strict";
|
|
33
|
+
var hasOwn = {}.hasOwnProperty;
|
|
34
|
+
function classNames() {
|
|
35
|
+
var classes = "";
|
|
36
|
+
for (var i = 0; i < arguments.length; i++) {
|
|
37
|
+
var arg = arguments[i];
|
|
38
|
+
if (arg) {
|
|
39
|
+
classes = appendClass(classes, parseValue(arg));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return classes;
|
|
43
|
+
}
|
|
44
|
+
function parseValue(arg) {
|
|
45
|
+
if (typeof arg === "string" || typeof arg === "number") {
|
|
46
|
+
return arg;
|
|
47
|
+
}
|
|
48
|
+
if (typeof arg !== "object") {
|
|
49
|
+
return "";
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(arg)) {
|
|
52
|
+
return classNames.apply(null, arg);
|
|
53
|
+
}
|
|
54
|
+
if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
|
|
55
|
+
return arg.toString();
|
|
56
|
+
}
|
|
57
|
+
var classes = "";
|
|
58
|
+
for (var key in arg) {
|
|
59
|
+
if (hasOwn.call(arg, key) && arg[key]) {
|
|
60
|
+
classes = appendClass(classes, key);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return classes;
|
|
64
|
+
}
|
|
65
|
+
function appendClass(value, newClass) {
|
|
66
|
+
if (!newClass) {
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
if (value) {
|
|
70
|
+
return value + " " + newClass;
|
|
71
|
+
}
|
|
72
|
+
return value + newClass;
|
|
73
|
+
}
|
|
74
|
+
if (typeof module !== "undefined" && module.exports) {
|
|
75
|
+
classNames.default = classNames;
|
|
76
|
+
module.exports = classNames;
|
|
77
|
+
} else if (typeof define === "function" && typeof define.amd === "object" && define.amd) {
|
|
78
|
+
define("classnames", [], function() {
|
|
79
|
+
return classNames;
|
|
80
|
+
});
|
|
81
|
+
} else {
|
|
82
|
+
window.classNames = classNames;
|
|
83
|
+
}
|
|
84
|
+
})();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// ../../../../packages/registry/class-names/dist/index.js
|
|
89
|
+
var import_classnames = __toESM(require_classnames(), 1);
|
|
90
|
+
var getClassName = ({
|
|
91
|
+
className,
|
|
92
|
+
modifiers = {},
|
|
93
|
+
rootClass,
|
|
94
|
+
styles = {}
|
|
95
|
+
}) => {
|
|
96
|
+
function getModifiers() {
|
|
97
|
+
const updatedModifiers = {};
|
|
98
|
+
const modifierKeys = Object.keys(modifiers);
|
|
99
|
+
if (modifierKeys.length) {
|
|
100
|
+
modifierKeys.forEach((modKey) => {
|
|
101
|
+
const classKey = `${rootClass}--${modKey}`;
|
|
102
|
+
const newClassName = styles[classKey] || classKey;
|
|
103
|
+
updatedModifiers[newClassName] = modifiers[modKey] ?? false;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return updatedModifiers;
|
|
107
|
+
}
|
|
108
|
+
function getChildClass(childClassName) {
|
|
109
|
+
const classKey = `${rootClass}__${childClassName}`;
|
|
110
|
+
return styles[classKey] || classKey;
|
|
111
|
+
}
|
|
112
|
+
function getRootStyles() {
|
|
113
|
+
return (0, import_classnames.default)(
|
|
114
|
+
className,
|
|
115
|
+
{
|
|
116
|
+
...getModifiers()
|
|
117
|
+
},
|
|
118
|
+
styles[rootClass] || rootClass
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
return [getRootStyles(), getChildClass];
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// confirm-dialog.tsx
|
|
125
|
+
import { Modal } from "@behivetech/atoms.modal";
|
|
126
|
+
import { Button } from "@behivetech/atoms.button";
|
|
127
|
+
|
|
128
|
+
// confirm-dialog.module.scss
|
|
129
|
+
var confirm_dialog_module_default = {
|
|
130
|
+
"BHT__ConfirmDialog__message": "BHT__ConfirmDialog__message",
|
|
131
|
+
"BHT__ConfirmDialog__actions": "BHT__ConfirmDialog__actions"
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// confirm-dialog.tsx
|
|
135
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
136
|
+
var ConfirmDialog = ({
|
|
137
|
+
open,
|
|
138
|
+
onOpenChange,
|
|
139
|
+
title,
|
|
140
|
+
message,
|
|
141
|
+
confirmLabel = "Confirm",
|
|
142
|
+
cancelLabel = "Cancel",
|
|
143
|
+
onConfirm,
|
|
144
|
+
variant = "default"
|
|
145
|
+
}) => {
|
|
146
|
+
const [, getChildClass] = getClassName({
|
|
147
|
+
rootClass: "BHT__ConfirmDialog",
|
|
148
|
+
styles: confirm_dialog_module_default
|
|
149
|
+
});
|
|
150
|
+
if (!open) return null;
|
|
151
|
+
return /* @__PURE__ */ jsxs(Modal, { title, onClose: () => onOpenChange(false), children: [
|
|
152
|
+
/* @__PURE__ */ jsx("p", { className: getChildClass("message"), children: message }),
|
|
153
|
+
/* @__PURE__ */ jsxs("div", { className: getChildClass("actions"), children: [
|
|
154
|
+
/* @__PURE__ */ jsx(Button, { variant: "ghost", onClick: () => onOpenChange(false), children: cancelLabel }),
|
|
155
|
+
/* @__PURE__ */ jsx(
|
|
156
|
+
Button,
|
|
157
|
+
{
|
|
158
|
+
variant: variant === "danger" ? "danger" : "primary",
|
|
159
|
+
onClick: () => {
|
|
160
|
+
onConfirm();
|
|
161
|
+
onOpenChange(false);
|
|
162
|
+
},
|
|
163
|
+
children: confirmLabel
|
|
164
|
+
}
|
|
165
|
+
)
|
|
166
|
+
] })
|
|
167
|
+
] });
|
|
168
|
+
};
|
|
169
|
+
export {
|
|
170
|
+
ConfirmDialog
|
|
171
|
+
};
|
|
172
|
+
/*! Bundled license information:
|
|
173
|
+
|
|
174
|
+
classnames/index.js:
|
|
175
|
+
(*!
|
|
176
|
+
Copyright (c) 2018 Jed Watson.
|
|
177
|
+
Licensed under the MIT License (MIT), see
|
|
178
|
+
http://jedwatson.github.io/classnames
|
|
179
|
+
*)
|
|
180
|
+
*/
|
package/docs.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://github.com/behivetech/bht-component-registry/docs.schema.json",
|
|
3
|
+
"version": 2,
|
|
4
|
+
"generatedAt": "2026-10-20T05:50:08.506Z",
|
|
5
|
+
"docs": [
|
|
6
|
+
{
|
|
7
|
+
"displayName": "ConfirmDialog",
|
|
8
|
+
"description": "A `Modal` pre-wired with a message and confirm/cancel actions, for \"are you\nsure?\" moments — e.g. confirming a delete.",
|
|
9
|
+
"extendsNative": false,
|
|
10
|
+
"props": [
|
|
11
|
+
{
|
|
12
|
+
"name": "message",
|
|
13
|
+
"type": "ReactNode",
|
|
14
|
+
"required": true,
|
|
15
|
+
"defaultValue": null,
|
|
16
|
+
"description": "Confirmation message/body content"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "onConfirm",
|
|
20
|
+
"type": "() => void",
|
|
21
|
+
"required": true,
|
|
22
|
+
"defaultValue": null,
|
|
23
|
+
"description": "Called when the confirm button is clicked, before the dialog closes"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "onOpenChange",
|
|
27
|
+
"type": "(open: boolean) => void",
|
|
28
|
+
"required": true,
|
|
29
|
+
"defaultValue": null,
|
|
30
|
+
"description": "Called when the dialog should close (cancel, confirm, backdrop click, Escape)"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"name": "open",
|
|
34
|
+
"type": "boolean",
|
|
35
|
+
"required": true,
|
|
36
|
+
"defaultValue": null,
|
|
37
|
+
"description": "Whether the dialog is open"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"name": "title",
|
|
41
|
+
"type": "string",
|
|
42
|
+
"required": true,
|
|
43
|
+
"defaultValue": null,
|
|
44
|
+
"description": "Dialog title"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"name": "cancelLabel",
|
|
48
|
+
"type": "string",
|
|
49
|
+
"required": false,
|
|
50
|
+
"defaultValue": "Cancel",
|
|
51
|
+
"description": "Cancel button label; defaults to \"Cancel\""
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"name": "confirmLabel",
|
|
55
|
+
"type": "string",
|
|
56
|
+
"required": false,
|
|
57
|
+
"defaultValue": "Confirm",
|
|
58
|
+
"description": "Confirm button label; defaults to \"Confirm\""
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"name": "variant",
|
|
62
|
+
"type": "\"default\" | \"danger\"",
|
|
63
|
+
"required": false,
|
|
64
|
+
"defaultValue": "default",
|
|
65
|
+
"description": "Renders the confirm button as a destructive action; defaults to \"default\""
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
],
|
|
70
|
+
"functions": []
|
|
71
|
+
}
|
package/index.ts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@behivetech/molecules.confirm-dialog",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"private": false,
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
12
|
+
},
|
|
13
|
+
"./styles.css": "./dist/index.css"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"index.ts",
|
|
19
|
+
"confirm-dialog.tsx",
|
|
20
|
+
"confirm-dialog.module.scss",
|
|
21
|
+
"*.example.tsx",
|
|
22
|
+
"docs.json"
|
|
23
|
+
],
|
|
24
|
+
"registry": {
|
|
25
|
+
"status": "stable",
|
|
26
|
+
"tags": []
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@behivetech/atoms.button": "0.4.2",
|
|
30
|
+
"@behivetech/atoms.modal": "0.2.2"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"react": "^19.2.7",
|
|
34
|
+
"react-dom": "^19.2.7"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/react": "19.2.17",
|
|
38
|
+
"@types/react-dom": "19.2.3",
|
|
39
|
+
"eslint": "^9.39.5",
|
|
40
|
+
"tsup": "^8.5.1",
|
|
41
|
+
"typescript": "^6.0.3",
|
|
42
|
+
"vitest": "^4.1.10",
|
|
43
|
+
"@bht-component-registry/env": "0.1.0",
|
|
44
|
+
"@bht-component-registry/class-names": "0.0.6"
|
|
45
|
+
},
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "https://github.com/behivetech/bht-galaxy.git",
|
|
49
|
+
"directory": "registry/behivetech/molecules/confirm-dialog"
|
|
50
|
+
},
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"registry": "https://registry.npmjs.org",
|
|
53
|
+
"access": "public",
|
|
54
|
+
"provenance": true
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "tsup && bht-registry-docgen",
|
|
58
|
+
"dev": "tsup --watch",
|
|
59
|
+
"lint": "eslint . --max-warnings 0",
|
|
60
|
+
"check-types": "tsc --noEmit",
|
|
61
|
+
"test": "vitest run"
|
|
62
|
+
}
|
|
6
63
|
}
|