@molecule/app-danger-zone-react 1.0.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 ADDED
@@ -0,0 +1,115 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work.
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship.
43
+
44
+ "Contribution" shall mean any work of authorship, including the
45
+ original version of the Work and any modifications or additions
46
+ to that Work, that is intentionally submitted to the Licensor for
47
+ inclusion in the Work by the copyright owner or by an individual or
48
+ Legal Entity authorized to submit on behalf of the copyright owner.
49
+
50
+ "Contributor" shall mean Licensor and any individual or Legal Entity
51
+ on behalf of whom a Contribution has been received by the Licensor and
52
+ subsequently incorporated within the Work.
53
+
54
+ 2. Grant of Copyright License. Subject to the terms and conditions of
55
+ this License, each Contributor hereby grants to You a perpetual,
56
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
57
+ copyright license to reproduce, prepare Derivative Works of,
58
+ publicly display, publicly perform, sublicense, and distribute the
59
+ Work and such Derivative Works in Source or Object form.
60
+
61
+ 3. Grant of Patent License. Subject to the terms and conditions of
62
+ this License, each Contributor hereby grants to You a perpetual,
63
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
64
+ patent license to make, have made, use, offer to sell, sell, import,
65
+ and otherwise transfer the Work.
66
+
67
+ 4. Redistribution. You may reproduce and distribute copies of the
68
+ Work or Derivative Works thereof in any medium, with or without
69
+ modifications, and in Source or Object form, provided that You
70
+ meet the following conditions:
71
+
72
+ (a) You must give any other recipients of the Work or
73
+ Derivative Works a copy of this License; and
74
+
75
+ (b) You must cause any modified files to carry prominent notices
76
+ stating that You changed the files; and
77
+
78
+ (c) You must retain, in the Source form of any Derivative Works
79
+ that You distribute, all copyright, patent, trademark, and
80
+ attribution notices from the Source form of the Work,
81
+ excluding those notices that do not pertain to any part of
82
+ the Derivative Works; and
83
+
84
+ (d) If the Work includes a "NOTICE" text file as part of its
85
+ distribution, then any Derivative Works that You distribute must
86
+ include a readable copy of the attribution notices contained
87
+ within such NOTICE file.
88
+
89
+ 5. Submission of Contributions.
90
+
91
+ 6. Trademarks. This License does not grant permission to use the trade
92
+ names, trademarks, service marks, or product names of the Licensor.
93
+
94
+ 7. Disclaimer of Warranty. Unless required by applicable law or
95
+ agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
96
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
97
+
98
+ 8. Limitation of Liability. In no event and under no legal theory shall
99
+ any Contributor be liable to You for damages.
100
+
101
+ 9. Accepting Warranty or Additional Liability.
102
+
103
+ Copyright 2026 Molecule Dev, Inc.
104
+
105
+ Licensed under the Apache License, Version 2.0 (the "License");
106
+ you may not use this file except in compliance with the License.
107
+ You may obtain a copy of the License at
108
+
109
+ http://www.apache.org/licenses/LICENSE-2.0
110
+
111
+ Unless required by applicable law or agreed to in writing, software
112
+ distributed under the License is distributed on an "AS IS" BASIS,
113
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
114
+ See the License for the specific language governing permissions and
115
+ limitations under the License.
@@ -0,0 +1,33 @@
1
+ import type { JSX, ReactNode } from 'react';
2
+ /** Props for {@link ConfirmDialog}. */
3
+ export interface ConfirmDialogProps {
4
+ /** Whether the dialog is open. */
5
+ open: boolean;
6
+ /** Called when the dialog should close (escape, backdrop, cancel). */
7
+ onClose: () => void;
8
+ /** Title. */
9
+ title: ReactNode;
10
+ /** Body / warning text. */
11
+ description: ReactNode;
12
+ /** Confirm-button label (e.g. "Delete"). */
13
+ confirmLabel?: ReactNode;
14
+ /** Cancel-button label. */
15
+ cancelLabel?: ReactNode;
16
+ /** Called when the user confirms. */
17
+ onConfirm: () => void | Promise<void>;
18
+ /** Is the confirm action destructive? Defaults to true. */
19
+ destructive?: boolean;
20
+ /** Extra body content between description and footer. */
21
+ children?: ReactNode;
22
+ /** Disables both buttons. Set it yourself while your `onConfirm` promise is pending — the dialog does not track it and does not auto-close. */
23
+ loading?: boolean;
24
+ }
25
+ /**
26
+ * Are-you-sure-style confirmation modal for destructive actions.
27
+ *
28
+ * Use standalone (around delete buttons, revoke tokens, irreversible
29
+ * migrations) or wrap DangerZoneSection's action with this dialog.
30
+ * @param props - Component props (see {@link ConfirmDialogProps}).
31
+ */
32
+ export declare function ConfirmDialog({ open, onClose, title, description, confirmLabel, cancelLabel, onConfirm, destructive, children, loading, }: ConfirmDialogProps): JSX.Element;
33
+ //# sourceMappingURL=ConfirmDialog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfirmDialog.d.ts","sourceRoot":"","sources":["../src/ConfirmDialog.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAM3C,uCAAuC;AACvC,MAAM,WAAW,kBAAkB;IACjC,kCAAkC;IAClC,IAAI,EAAE,OAAO,CAAA;IACb,sEAAsE;IACtE,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,aAAa;IACb,KAAK,EAAE,SAAS,CAAA;IAChB,2BAA2B;IAC3B,WAAW,EAAE,SAAS,CAAA;IACtB,4CAA4C;IAC5C,YAAY,CAAC,EAAE,SAAS,CAAA;IACxB,2BAA2B;IAC3B,WAAW,CAAC,EAAE,SAAS,CAAA;IACvB,qCAAqC;IACrC,SAAS,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACrC,2DAA2D;IAC3D,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,yDAAyD;IACzD,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,+IAA+I;IAC/I,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,EAC5B,IAAI,EACJ,OAAO,EACP,KAAK,EACL,WAAW,EACX,YAAY,EACZ,WAAW,EACX,SAAS,EACT,WAAkB,EAClB,QAAQ,EACR,OAAO,GACR,EAAE,kBAAkB,GAAG,GAAG,CAAC,OAAO,CA2BlC"}
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useTranslation } from '@molecule/app-react';
3
+ import { getClassMap } from '@molecule/app-ui';
4
+ import { Button, Modal } from '@molecule/app-ui-react';
5
+ /**
6
+ * Are-you-sure-style confirmation modal for destructive actions.
7
+ *
8
+ * Use standalone (around delete buttons, revoke tokens, irreversible
9
+ * migrations) or wrap DangerZoneSection's action with this dialog.
10
+ * @param props - Component props (see {@link ConfirmDialogProps}).
11
+ */
12
+ export function ConfirmDialog({ open, onClose, title, description, confirmLabel, cancelLabel, onConfirm, destructive = true, children, loading, }) {
13
+ const cm = getClassMap();
14
+ const { t } = useTranslation();
15
+ return (_jsx(Modal, { open: open, onClose: onClose, children: _jsxs("div", { className: cm.stack(3), children: [_jsx("h2", { className: cm.cn(cm.textSize('lg'), cm.fontWeight('bold')), children: title }), _jsx("p", { className: cm.textSize('sm'), children: description }), children, _jsxs("div", { className: cm.flex({ justify: 'end', gap: 'sm' }), children: [_jsx(Button, { variant: "ghost", onClick: onClose, disabled: loading, children: cancelLabel ?? t('confirm.cancel', {}, { defaultValue: 'Cancel' }) }), _jsx(Button, { variant: "solid", color: destructive ? 'error' : 'primary', onClick: () => void onConfirm(), disabled: loading, children: loading
16
+ ? '…'
17
+ : (confirmLabel ?? t('confirm.confirm', {}, { defaultValue: 'Confirm' })) })] })] }) }));
18
+ }
@@ -0,0 +1,30 @@
1
+ import type { JSX, ReactNode } from 'react';
2
+ /** Props for {@link DangerZoneSection}. */
3
+ export interface DangerZoneSectionProps {
4
+ /** Section title. */
5
+ title: ReactNode;
6
+ /** Explanation of the destructive action. */
7
+ description: ReactNode;
8
+ /** Label on the action button (e.g. "Delete account"). */
9
+ actionLabel: ReactNode;
10
+ /** Called when the button is clicked. */
11
+ onAction: () => void;
12
+ /** When true, the button disables and shows a loading label. */
13
+ loading?: boolean;
14
+ /** When true, the button is disabled without loading. */
15
+ disabled?: boolean;
16
+ /** Additional content between description and button (e.g. a confirm-text input). */
17
+ children?: ReactNode;
18
+ /** Extra classes on the Card. */
19
+ className?: string;
20
+ /** `data-mol-id` for AI-agent selectors. */
21
+ dataMolId?: string;
22
+ }
23
+ /**
24
+ * Card-wrapped section for destructive actions — delete account,
25
+ * reset data, revoke access. Uses the error/danger accent color and
26
+ * puts the action on the right.
27
+ * @param props - Component props (see {@link DangerZoneSectionProps}).
28
+ */
29
+ export declare function DangerZoneSection({ title, description, actionLabel, onAction, loading, disabled, children, className, dataMolId, }: DangerZoneSectionProps): JSX.Element;
30
+ //# sourceMappingURL=DangerZoneSection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DangerZoneSection.d.ts","sourceRoot":"","sources":["../src/DangerZoneSection.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAK3C,2CAA2C;AAC3C,MAAM,WAAW,sBAAsB;IACrC,qBAAqB;IACrB,KAAK,EAAE,SAAS,CAAA;IAChB,6CAA6C;IAC7C,WAAW,EAAE,SAAS,CAAA;IACtB,0DAA0D;IAC1D,WAAW,EAAE,SAAS,CAAA;IACtB,yCAAyC;IACzC,QAAQ,EAAE,MAAM,IAAI,CAAA;IACpB,gEAAgE;IAChE,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,yDAAyD;IACzD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,qFAAqF;IACrF,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,iCAAiC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,KAAK,EACL,WAAW,EACX,WAAW,EACX,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,SAAS,GACV,EAAE,sBAAsB,GAAG,GAAG,CAAC,OAAO,CAkBtC"}
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { getClassMap } from '@molecule/app-ui';
3
+ import { Button, Card } from '@molecule/app-ui-react';
4
+ /**
5
+ * Card-wrapped section for destructive actions — delete account,
6
+ * reset data, revoke access. Uses the error/danger accent color and
7
+ * puts the action on the right.
8
+ * @param props - Component props (see {@link DangerZoneSectionProps}).
9
+ */
10
+ export function DangerZoneSection({ title, description, actionLabel, onAction, loading, disabled, children, className, dataMolId, }) {
11
+ const cm = getClassMap();
12
+ return (_jsx(Card, { className: className, "data-mol-id": dataMolId, children: _jsxs("div", { className: cm.stack(3), children: [_jsxs("header", { className: cm.stack(1), children: [_jsx("h3", { className: cm.cn(cm.textSize('base'), cm.fontWeight('semibold')), children: title }), _jsx("p", { className: cm.textSize('sm'), children: description })] }), children, _jsx("div", { className: cm.flex({ justify: 'end' }), children: _jsx(Button, { variant: "solid", color: "error", onClick: onAction, disabled: disabled || loading, children: loading ? '…' : actionLabel }) })] }) }));
13
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * React destructive-action primitives.
3
+ *
4
+ * Exports:
5
+ * - `<DangerZoneSection>` — Card with title/description/button for delete/reset/revoke.
6
+ * - `<ConfirmDialog>` — standalone "Are you sure?" modal.
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * import { ConfirmDialog, DangerZoneSection } from '@molecule/app-danger-zone-react'
11
+ *
12
+ * <DangerZoneSection
13
+ * title="Delete account"
14
+ * description="This permanently removes your account and all data."
15
+ * actionLabel="Delete account"
16
+ * onAction={() => setConfirmOpen(true)}
17
+ * />
18
+ *
19
+ * <ConfirmDialog
20
+ * open={confirmOpen}
21
+ * onClose={() => setConfirmOpen(false)}
22
+ * title="Delete account?"
23
+ * description="This action cannot be undone."
24
+ * confirmLabel="Delete"
25
+ * onConfirm={handleDelete}
26
+ * />
27
+ * ```
28
+ *
29
+ * @remarks
30
+ * `<ConfirmDialog>` does NOT track `onConfirm`'s promise and does NOT close
31
+ * itself on confirm: set `loading` yourself while the action runs, then call
32
+ * `onClose()` when it settles — otherwise users can double-fire the
33
+ * destructive action or be left staring at an open dialog. Cancel/Confirm
34
+ * fall back to the `confirm.*` i18n keys (companion bond:
35
+ * `@molecule/app-locales-danger-zone`); pass `confirmLabel`/`cancelLabel`
36
+ * for action-specific wording ("Delete", "Revoke"). `destructive` (default
37
+ * true) only switches the confirm button color.
38
+ *
39
+ * @module
40
+ */
41
+ export * from './ConfirmDialog.js';
42
+ export * from './DangerZoneSection.js';
43
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,42 @@
1
+ /**
2
+ * React destructive-action primitives.
3
+ *
4
+ * Exports:
5
+ * - `<DangerZoneSection>` — Card with title/description/button for delete/reset/revoke.
6
+ * - `<ConfirmDialog>` — standalone "Are you sure?" modal.
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * import { ConfirmDialog, DangerZoneSection } from '@molecule/app-danger-zone-react'
11
+ *
12
+ * <DangerZoneSection
13
+ * title="Delete account"
14
+ * description="This permanently removes your account and all data."
15
+ * actionLabel="Delete account"
16
+ * onAction={() => setConfirmOpen(true)}
17
+ * />
18
+ *
19
+ * <ConfirmDialog
20
+ * open={confirmOpen}
21
+ * onClose={() => setConfirmOpen(false)}
22
+ * title="Delete account?"
23
+ * description="This action cannot be undone."
24
+ * confirmLabel="Delete"
25
+ * onConfirm={handleDelete}
26
+ * />
27
+ * ```
28
+ *
29
+ * @remarks
30
+ * `<ConfirmDialog>` does NOT track `onConfirm`'s promise and does NOT close
31
+ * itself on confirm: set `loading` yourself while the action runs, then call
32
+ * `onClose()` when it settles — otherwise users can double-fire the
33
+ * destructive action or be left staring at an open dialog. Cancel/Confirm
34
+ * fall back to the `confirm.*` i18n keys (companion bond:
35
+ * `@molecule/app-locales-danger-zone`); pass `confirmLabel`/`cancelLabel`
36
+ * for action-specific wording ("Delete", "Revoke"). `destructive` (default
37
+ * true) only switches the confirm button color.
38
+ *
39
+ * @module
40
+ */
41
+ export * from './ConfirmDialog.js';
42
+ export * from './DangerZoneSection.js';
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@molecule/app-danger-zone-react",
3
+ "version": "1.0.0",
4
+ "description": "DangerZoneSection + ConfirmDialog for destructive actions (delete account, reset, revoke)",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "test": "vitest run",
11
+ "test:watch": "vitest"
12
+ },
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "keywords": [
23
+ "molecule",
24
+ "danger-zone",
25
+ "react"
26
+ ],
27
+ "license": "Apache-2.0",
28
+ "peerDependencies": {
29
+ "@molecule/app-react": "^1.0.0",
30
+ "@molecule/app-ui": "^1.0.0",
31
+ "@molecule/app-ui-react": "^1.0.0",
32
+ "react": "^18.0.0 || ^19.0.0"
33
+ },
34
+ "devDependencies": {
35
+ "@molecule/app-react": "1.0.0",
36
+ "@molecule/app-ui": "1.0.0",
37
+ "@molecule/app-ui-react": "1.0.0",
38
+ "@types/node": "26.1.2",
39
+ "@types/react": "19.2.17",
40
+ "@types/react-dom": "19.2.3",
41
+ "react": "19.2.8",
42
+ "react-dom": "19.2.8",
43
+ "typescript": "6.0.3",
44
+ "vitest": "4.1.10"
45
+ }
46
+ }