@cerberus-design/react 0.6.1-next-1315bf2 → 0.6.1-next-8062b70
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/build/legacy/_tsup-dts-rollup.d.ts +78 -0
- package/build/legacy/{chunk-5RA3ZIXA.js → chunk-5GEC53G7.js} +5 -5
- package/build/legacy/{chunk-3TYUA4C7.js → chunk-6TXQZ3PB.js} +2 -2
- package/build/legacy/{chunk-SCAVVE6E.js → chunk-C45DY4VE.js} +2 -1
- package/build/legacy/chunk-C45DY4VE.js.map +1 -0
- package/build/legacy/{chunk-JJGZRBIR.js → chunk-CU7HXAKM.js} +4 -4
- package/build/legacy/chunk-G3JEWPLM.js +29 -0
- package/build/legacy/chunk-G3JEWPLM.js.map +1 -0
- package/build/legacy/{chunk-VLVKNEA5.js → chunk-TAZI77TP.js} +2 -2
- package/build/legacy/{chunk-YRUUO4AP.js → chunk-UZIN7UOS.js} +19 -38
- package/build/legacy/chunk-UZIN7UOS.js.map +1 -0
- package/build/legacy/chunk-WKSC2WCV.js +202 -0
- package/build/legacy/chunk-WKSC2WCV.js.map +1 -0
- package/build/legacy/components/Input.js +4 -4
- package/build/legacy/components/Label.js +2 -2
- package/build/legacy/components/ModalIcon.js +7 -0
- package/build/legacy/components/ModalIcon.js.map +1 -0
- package/build/legacy/components/Toggle.js +3 -3
- package/build/legacy/config/cerbIcons.js +1 -1
- package/build/legacy/config/defineIcons.js +2 -2
- package/build/legacy/context/confirm-modal.js +4 -3
- package/build/legacy/context/prompt-modal.js +20 -0
- package/build/legacy/context/prompt-modal.js.map +1 -0
- package/build/legacy/index.js +24 -14
- package/build/modern/_tsup-dts-rollup.d.ts +78 -0
- package/build/modern/{chunk-5RA3ZIXA.js → chunk-5GEC53G7.js} +5 -5
- package/build/modern/{chunk-3TYUA4C7.js → chunk-6TXQZ3PB.js} +2 -2
- package/build/modern/{chunk-SCAVVE6E.js → chunk-C45DY4VE.js} +2 -1
- package/build/modern/chunk-C45DY4VE.js.map +1 -0
- package/build/modern/{chunk-JJGZRBIR.js → chunk-CU7HXAKM.js} +4 -4
- package/build/modern/chunk-G3JEWPLM.js +29 -0
- package/build/modern/chunk-G3JEWPLM.js.map +1 -0
- package/build/modern/{chunk-VLVKNEA5.js → chunk-TAZI77TP.js} +2 -2
- package/build/modern/{chunk-BVK6GEDZ.js → chunk-X2GKC3IU.js} +19 -38
- package/build/modern/chunk-X2GKC3IU.js.map +1 -0
- package/build/modern/chunk-YHJTKBVE.js +200 -0
- package/build/modern/chunk-YHJTKBVE.js.map +1 -0
- package/build/modern/components/Input.js +4 -4
- package/build/modern/components/Label.js +2 -2
- package/build/modern/components/ModalIcon.js +7 -0
- package/build/modern/components/ModalIcon.js.map +1 -0
- package/build/modern/components/Toggle.js +3 -3
- package/build/modern/config/cerbIcons.js +1 -1
- package/build/modern/config/defineIcons.js +2 -2
- package/build/modern/context/confirm-modal.js +4 -3
- package/build/modern/context/prompt-modal.js +20 -0
- package/build/modern/context/prompt-modal.js.map +1 -0
- package/build/modern/index.js +24 -14
- package/package.json +2 -2
- package/src/components/ModalIcon.tsx +28 -0
- package/src/config/cerbIcons.ts +2 -0
- package/src/context/confirm-modal.tsx +20 -43
- package/src/context/prompt-modal.tsx +231 -0
- package/src/index.ts +2 -0
- package/build/legacy/chunk-SCAVVE6E.js.map +0 -1
- package/build/legacy/chunk-YRUUO4AP.js.map +0 -1
- package/build/modern/chunk-BVK6GEDZ.js.map +0 -1
- package/build/modern/chunk-SCAVVE6E.js.map +0 -1
- /package/build/legacy/{chunk-5RA3ZIXA.js.map → chunk-5GEC53G7.js.map} +0 -0
- /package/build/legacy/{chunk-3TYUA4C7.js.map → chunk-6TXQZ3PB.js.map} +0 -0
- /package/build/legacy/{chunk-JJGZRBIR.js.map → chunk-CU7HXAKM.js.map} +0 -0
- /package/build/legacy/{chunk-VLVKNEA5.js.map → chunk-TAZI77TP.js.map} +0 -0
- /package/build/modern/{chunk-5RA3ZIXA.js.map → chunk-5GEC53G7.js.map} +0 -0
- /package/build/modern/{chunk-3TYUA4C7.js.map → chunk-6TXQZ3PB.js.map} +0 -0
- /package/build/modern/{chunk-JJGZRBIR.js.map → chunk-CU7HXAKM.js.map} +0 -0
- /package/build/modern/{chunk-VLVKNEA5.js.map → chunk-TAZI77TP.js.map} +0 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Portal
|
|
3
|
+
} from "./chunk-4CAT3FHV.js";
|
|
4
|
+
import {
|
|
5
|
+
Button
|
|
6
|
+
} from "./chunk-2ATICEW3.js";
|
|
7
|
+
import {
|
|
8
|
+
Input
|
|
9
|
+
} from "./chunk-5GEC53G7.js";
|
|
10
|
+
import {
|
|
11
|
+
Label
|
|
12
|
+
} from "./chunk-CU7HXAKM.js";
|
|
13
|
+
import {
|
|
14
|
+
Show
|
|
15
|
+
} from "./chunk-4O4QFF4S.js";
|
|
16
|
+
import {
|
|
17
|
+
Field
|
|
18
|
+
} from "./chunk-ZAU4JVLL.js";
|
|
19
|
+
import {
|
|
20
|
+
ModalIcon
|
|
21
|
+
} from "./chunk-G3JEWPLM.js";
|
|
22
|
+
import {
|
|
23
|
+
trapFocus
|
|
24
|
+
} from "./chunk-JIZQFTW6.js";
|
|
25
|
+
import {
|
|
26
|
+
$cerberusIcons
|
|
27
|
+
} from "./chunk-6TXQZ3PB.js";
|
|
28
|
+
|
|
29
|
+
// src/context/prompt-modal.tsx
|
|
30
|
+
import {
|
|
31
|
+
createContext,
|
|
32
|
+
useCallback,
|
|
33
|
+
useContext,
|
|
34
|
+
useMemo,
|
|
35
|
+
useRef,
|
|
36
|
+
useState
|
|
37
|
+
} from "react";
|
|
38
|
+
import { css } from "@cerberus-design/styled-system/css";
|
|
39
|
+
import { hstack, vstack } from "@cerberus-design/styled-system/patterns";
|
|
40
|
+
import { modal } from "@cerberus-design/styled-system/recipes";
|
|
41
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
42
|
+
var PromptModalContext = createContext(null);
|
|
43
|
+
function PromptModal(props) {
|
|
44
|
+
const dialogRef = useRef(null);
|
|
45
|
+
const resolveRef = useRef(null);
|
|
46
|
+
const [content, setContent] = useState(null);
|
|
47
|
+
const [inputValue, setInputValue] = useState("");
|
|
48
|
+
const focusTrap = trapFocus(dialogRef);
|
|
49
|
+
const PromptIcon = $cerberusIcons.promptModal;
|
|
50
|
+
const isValid = useMemo(
|
|
51
|
+
() => inputValue === content?.key,
|
|
52
|
+
[inputValue, content]
|
|
53
|
+
);
|
|
54
|
+
const palette = useMemo(
|
|
55
|
+
() => content?.kind === "destructive" ? "danger" : "action",
|
|
56
|
+
[content]
|
|
57
|
+
);
|
|
58
|
+
const styles = modal();
|
|
59
|
+
const handleChange = useCallback(
|
|
60
|
+
(e) => {
|
|
61
|
+
setInputValue(e.currentTarget.value);
|
|
62
|
+
},
|
|
63
|
+
[content]
|
|
64
|
+
);
|
|
65
|
+
const handleChoice = useCallback(
|
|
66
|
+
(e) => {
|
|
67
|
+
const target = e.currentTarget;
|
|
68
|
+
if (target.value === "true") {
|
|
69
|
+
resolveRef.current?.(inputValue);
|
|
70
|
+
}
|
|
71
|
+
dialogRef?.current?.close();
|
|
72
|
+
},
|
|
73
|
+
[inputValue]
|
|
74
|
+
);
|
|
75
|
+
const handleShow = useCallback((options) => {
|
|
76
|
+
return new Promise((resolve) => {
|
|
77
|
+
setContent({ ...options, kind: options.kind || "non-destructive" });
|
|
78
|
+
dialogRef?.current?.showModal();
|
|
79
|
+
resolveRef.current = resolve;
|
|
80
|
+
});
|
|
81
|
+
}, []);
|
|
82
|
+
const value = useMemo(
|
|
83
|
+
() => ({
|
|
84
|
+
show: handleShow
|
|
85
|
+
}),
|
|
86
|
+
[handleShow]
|
|
87
|
+
);
|
|
88
|
+
return /* @__PURE__ */ jsxs(PromptModalContext.Provider, { value, children: [
|
|
89
|
+
props.children,
|
|
90
|
+
/* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsxs("dialog", { className: styles.dialog, onKeyDown: focusTrap, ref: dialogRef, children: [
|
|
91
|
+
/* @__PURE__ */ jsxs(
|
|
92
|
+
"div",
|
|
93
|
+
{
|
|
94
|
+
className: vstack({
|
|
95
|
+
alignItems: "flex-start",
|
|
96
|
+
gap: "4"
|
|
97
|
+
}),
|
|
98
|
+
children: [
|
|
99
|
+
/* @__PURE__ */ jsx(
|
|
100
|
+
Show,
|
|
101
|
+
{
|
|
102
|
+
when: palette === "danger",
|
|
103
|
+
fallback: /* @__PURE__ */ jsx(ModalIcon, { palette: "action", children: /* @__PURE__ */ jsx(PromptIcon, { size: 24 }) }),
|
|
104
|
+
children: /* @__PURE__ */ jsx(ModalIcon, { palette: "danger", children: /* @__PURE__ */ jsx(PromptIcon, { size: 24 }) })
|
|
105
|
+
}
|
|
106
|
+
),
|
|
107
|
+
/* @__PURE__ */ jsx("h2", { className: styles.heading, children: content?.heading }),
|
|
108
|
+
/* @__PURE__ */ jsx("p", { className: styles.description, children: content?.description })
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
),
|
|
112
|
+
/* @__PURE__ */ jsx(
|
|
113
|
+
"div",
|
|
114
|
+
{
|
|
115
|
+
className: vstack({
|
|
116
|
+
alignItems: "flex-start",
|
|
117
|
+
mt: "4",
|
|
118
|
+
mb: "8"
|
|
119
|
+
}),
|
|
120
|
+
children: /* @__PURE__ */ jsxs(Field, { invalid: !isValid, children: [
|
|
121
|
+
/* @__PURE__ */ jsxs(Label, { htmlFor: "confirm", size: "md", children: [
|
|
122
|
+
"Type",
|
|
123
|
+
/* @__PURE__ */ jsx(
|
|
124
|
+
"strong",
|
|
125
|
+
{
|
|
126
|
+
className: css({
|
|
127
|
+
textTransform: "uppercase"
|
|
128
|
+
}),
|
|
129
|
+
children: content?.key
|
|
130
|
+
}
|
|
131
|
+
),
|
|
132
|
+
"to confirm"
|
|
133
|
+
] }),
|
|
134
|
+
/* @__PURE__ */ jsx(
|
|
135
|
+
Input,
|
|
136
|
+
{
|
|
137
|
+
id: "confirm",
|
|
138
|
+
name: "confirm",
|
|
139
|
+
onChange: handleChange,
|
|
140
|
+
type: "text"
|
|
141
|
+
}
|
|
142
|
+
)
|
|
143
|
+
] })
|
|
144
|
+
}
|
|
145
|
+
),
|
|
146
|
+
/* @__PURE__ */ jsxs(
|
|
147
|
+
"div",
|
|
148
|
+
{
|
|
149
|
+
className: hstack({
|
|
150
|
+
justifyContent: "stretch",
|
|
151
|
+
gap: "4"
|
|
152
|
+
}),
|
|
153
|
+
children: [
|
|
154
|
+
/* @__PURE__ */ jsx(
|
|
155
|
+
Button,
|
|
156
|
+
{
|
|
157
|
+
autoFocus: true,
|
|
158
|
+
className: css({
|
|
159
|
+
w: "1/2"
|
|
160
|
+
}),
|
|
161
|
+
disabled: !isValid,
|
|
162
|
+
name: "confirm",
|
|
163
|
+
onClick: handleChoice,
|
|
164
|
+
palette,
|
|
165
|
+
value: "true",
|
|
166
|
+
children: content?.actionText
|
|
167
|
+
}
|
|
168
|
+
),
|
|
169
|
+
/* @__PURE__ */ jsx(
|
|
170
|
+
Button,
|
|
171
|
+
{
|
|
172
|
+
className: css({
|
|
173
|
+
w: "1/2"
|
|
174
|
+
}),
|
|
175
|
+
name: "cancel",
|
|
176
|
+
onClick: handleChoice,
|
|
177
|
+
usage: "outlined",
|
|
178
|
+
value: "false",
|
|
179
|
+
children: content?.cancelText
|
|
180
|
+
}
|
|
181
|
+
)
|
|
182
|
+
]
|
|
183
|
+
}
|
|
184
|
+
)
|
|
185
|
+
] }) })
|
|
186
|
+
] });
|
|
187
|
+
}
|
|
188
|
+
function usePromptModal() {
|
|
189
|
+
const context = useContext(PromptModalContext);
|
|
190
|
+
if (context === null) {
|
|
191
|
+
throw new Error("usePromptModal must be used within a PromptModal Provider");
|
|
192
|
+
}
|
|
193
|
+
return context;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export {
|
|
197
|
+
PromptModal,
|
|
198
|
+
usePromptModal
|
|
199
|
+
};
|
|
200
|
+
//# sourceMappingURL=chunk-YHJTKBVE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/context/prompt-modal.tsx"],"sourcesContent":["'use client'\n\nimport {\n createContext,\n useCallback,\n useContext,\n useMemo,\n useRef,\n useState,\n type ChangeEvent,\n type MouseEvent,\n type PropsWithChildren,\n} from 'react'\nimport { Portal } from '../components/Portal'\nimport { Button } from '../components/Button'\nimport { css } from '@cerberus-design/styled-system/css'\nimport { hstack, vstack } from '@cerberus-design/styled-system/patterns'\nimport { modal } from '@cerberus-design/styled-system/recipes'\nimport { trapFocus } from '../aria-helpers/trap-focus.aria'\nimport { Input } from '../components/Input'\nimport { Field } from './field'\nimport { Label } from '../components/Label'\nimport { $cerberusIcons } from '../config/defineIcons'\nimport { ModalIcon } from '../components/ModalIcon'\nimport { Show } from '../components/Show'\n\n/**\n * This module provides a context and hook for the prompt modal.\n * @module\n */\n\nexport interface ShowPromptModalOptions {\n kind?: 'destructive' | 'non-destructive'\n heading: string\n description?: string\n key: string\n actionText: string\n cancelText: string\n}\nexport type PromptShowResult =\n | ((value: string | PromiseLike<string>) => void)\n | null\n\nexport interface PromptModalValue {\n show: (options: ShowPromptModalOptions) => Promise<string>\n}\n\nconst PromptModalContext = createContext<PromptModalValue | null>(null)\n\nexport interface PromptModalProviderProps {}\n\n/**\n * Provides a prompt modal to the app.\n * @example\n * ```tsx\n * // Wrap the Provider around the root of the feature.\n * <PromptModal>\n * <SomeFeatureSection />\n * </PromptModal>\n *\n * // Use the hook to show the prompt modal.\n * const prompt = usePromptModal()\n *\n * const handleClick = useCallback(async () => {\n * const accepted = await prompt.show({\n * kind: 'destructive',\n * heading: 'Delete channel?',\n * description:\n * 'This will permanently delete a channel on your account. There is no going back.',\n * key: CHANNEL_NAME,\n * actionText: 'Yes, delete channel',\n * cancelText: 'No, cancel',\n * })\n * // do something with accepted\n * }, [prompt])\n * ```\n */\nexport function PromptModal(\n props: PropsWithChildren<PromptModalProviderProps>,\n) {\n const dialogRef = useRef<HTMLDialogElement>(null)\n const resolveRef = useRef<PromptShowResult>(null)\n const [content, setContent] = useState<ShowPromptModalOptions | null>(null)\n const [inputValue, setInputValue] = useState<string>('')\n const focusTrap = trapFocus(dialogRef)\n const PromptIcon = $cerberusIcons.promptModal\n\n const isValid = useMemo(\n () => inputValue === content?.key,\n [inputValue, content],\n )\n\n const palette = useMemo(\n () => (content?.kind === 'destructive' ? 'danger' : 'action'),\n [content],\n )\n const styles = modal()\n\n const handleChange = useCallback(\n (e: ChangeEvent<HTMLInputElement>) => {\n setInputValue(e.currentTarget.value)\n },\n [content],\n )\n\n const handleChoice = useCallback(\n (e: MouseEvent<HTMLButtonElement>) => {\n const target = e.currentTarget as HTMLButtonElement\n if (target.value === 'true') {\n resolveRef.current?.(inputValue)\n }\n dialogRef?.current?.close()\n },\n [inputValue],\n )\n\n const handleShow = useCallback((options: ShowPromptModalOptions) => {\n return new Promise<string>((resolve) => {\n setContent({ ...options, kind: options.kind || 'non-destructive' })\n dialogRef?.current?.showModal()\n resolveRef.current = resolve\n })\n }, [])\n\n const value = useMemo(\n () => ({\n show: handleShow,\n }),\n [handleShow],\n )\n\n return (\n <PromptModalContext.Provider value={value}>\n {props.children}\n\n <Portal>\n <dialog className={styles.dialog} onKeyDown={focusTrap} ref={dialogRef}>\n <div\n className={vstack({\n alignItems: 'flex-start',\n gap: '4',\n })}\n >\n <Show\n when={palette === 'danger'}\n fallback={\n <ModalIcon palette=\"action\">\n <PromptIcon size={24} />\n </ModalIcon>\n }\n >\n <ModalIcon palette=\"danger\">\n <PromptIcon size={24} />\n </ModalIcon>\n </Show>\n <h2 className={styles.heading}>{content?.heading}</h2>\n <p className={styles.description}>{content?.description}</p>\n </div>\n\n <div\n className={vstack({\n alignItems: 'flex-start',\n mt: '4',\n mb: '8',\n })}\n >\n <Field invalid={!isValid}>\n <Label htmlFor=\"confirm\" size=\"md\">\n Type\n <strong\n className={css({\n textTransform: 'uppercase',\n })}\n >\n {content?.key}\n </strong>\n to confirm\n </Label>\n <Input\n id=\"confirm\"\n name=\"confirm\"\n onChange={handleChange}\n type=\"text\"\n />\n </Field>\n </div>\n\n <div\n className={hstack({\n justifyContent: 'stretch',\n gap: '4',\n })}\n >\n <Button\n autoFocus\n className={css({\n w: '1/2',\n })}\n disabled={!isValid}\n name=\"confirm\"\n onClick={handleChoice}\n palette={palette}\n value=\"true\"\n >\n {content?.actionText}\n </Button>\n <Button\n className={css({\n w: '1/2',\n })}\n name=\"cancel\"\n onClick={handleChoice}\n usage=\"outlined\"\n value=\"false\"\n >\n {content?.cancelText}\n </Button>\n </div>\n </dialog>\n </Portal>\n </PromptModalContext.Provider>\n )\n}\n\nexport function usePromptModal(): PromptModalValue {\n const context = useContext(PromptModalContext)\n if (context === null) {\n throw new Error('usePromptModal must be used within a PromptModal Provider')\n }\n return context\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAGP,SAAS,WAAW;AACpB,SAAS,QAAQ,cAAc;AAC/B,SAAS,aAAa;AAwHZ,SAUQ,KAVR;AA1FV,IAAM,qBAAqB,cAAuC,IAAI;AA8B/D,SAAS,YACd,OACA;AACA,QAAM,YAAY,OAA0B,IAAI;AAChD,QAAM,aAAa,OAAyB,IAAI;AAChD,QAAM,CAAC,SAAS,UAAU,IAAI,SAAwC,IAAI;AAC1E,QAAM,CAAC,YAAY,aAAa,IAAI,SAAiB,EAAE;AACvD,QAAM,YAAY,UAAU,SAAS;AACrC,QAAM,aAAa,eAAe;AAElC,QAAM,UAAU;AAAA,IACd,MAAM,eAAe,SAAS;AAAA,IAC9B,CAAC,YAAY,OAAO;AAAA,EACtB;AAEA,QAAM,UAAU;AAAA,IACd,MAAO,SAAS,SAAS,gBAAgB,WAAW;AAAA,IACpD,CAAC,OAAO;AAAA,EACV;AACA,QAAM,SAAS,MAAM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M;AACpB,UAAM,IAAI,MAAM,2DAA2D;AAAA,EAC7E;AACA,SAAO;AACT;","names":[]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
Input
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-ZAU4JVLL.js";
|
|
4
|
+
} from "../chunk-5GEC53G7.js";
|
|
6
5
|
import "../chunk-4O4QFF4S.js";
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-ZAU4JVLL.js";
|
|
7
|
+
import "../chunk-6TXQZ3PB.js";
|
|
8
|
+
import "../chunk-C45DY4VE.js";
|
|
9
9
|
export {
|
|
10
10
|
Input
|
|
11
11
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
Toggle
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-TAZI77TP.js";
|
|
5
5
|
import "../chunk-ZAU4JVLL.js";
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-6TXQZ3PB.js";
|
|
7
|
+
import "../chunk-C45DY4VE.js";
|
|
8
8
|
export {
|
|
9
9
|
Toggle
|
|
10
10
|
};
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
import {
|
|
3
3
|
ConfirmModal,
|
|
4
4
|
useConfirmModal
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-X2GKC3IU.js";
|
|
6
6
|
import "../chunk-4CAT3FHV.js";
|
|
7
7
|
import "../chunk-2ATICEW3.js";
|
|
8
8
|
import "../chunk-4O4QFF4S.js";
|
|
9
|
+
import "../chunk-G3JEWPLM.js";
|
|
9
10
|
import "../chunk-JIZQFTW6.js";
|
|
10
|
-
import "../chunk-
|
|
11
|
-
import "../chunk-
|
|
11
|
+
import "../chunk-6TXQZ3PB.js";
|
|
12
|
+
import "../chunk-C45DY4VE.js";
|
|
12
13
|
export {
|
|
13
14
|
ConfirmModal,
|
|
14
15
|
useConfirmModal
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
PromptModal,
|
|
4
|
+
usePromptModal
|
|
5
|
+
} from "../chunk-YHJTKBVE.js";
|
|
6
|
+
import "../chunk-4CAT3FHV.js";
|
|
7
|
+
import "../chunk-2ATICEW3.js";
|
|
8
|
+
import "../chunk-5GEC53G7.js";
|
|
9
|
+
import "../chunk-CU7HXAKM.js";
|
|
10
|
+
import "../chunk-4O4QFF4S.js";
|
|
11
|
+
import "../chunk-ZAU4JVLL.js";
|
|
12
|
+
import "../chunk-G3JEWPLM.js";
|
|
13
|
+
import "../chunk-JIZQFTW6.js";
|
|
14
|
+
import "../chunk-6TXQZ3PB.js";
|
|
15
|
+
import "../chunk-C45DY4VE.js";
|
|
16
|
+
export {
|
|
17
|
+
PromptModal,
|
|
18
|
+
usePromptModal
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=prompt-modal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/build/modern/index.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PromptModal,
|
|
3
|
+
usePromptModal
|
|
4
|
+
} from "./chunk-YHJTKBVE.js";
|
|
5
|
+
import {
|
|
6
|
+
TabPanel
|
|
7
|
+
} from "./chunk-67S42J4B.js";
|
|
1
8
|
import {
|
|
2
9
|
Tag
|
|
3
10
|
} from "./chunk-Z6IWNVPN.js";
|
|
@@ -6,11 +13,14 @@ import {
|
|
|
6
13
|
} from "./chunk-TCO46FK7.js";
|
|
7
14
|
import {
|
|
8
15
|
Toggle
|
|
9
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-TAZI77TP.js";
|
|
10
17
|
import {
|
|
11
18
|
ConfirmModal,
|
|
12
19
|
useConfirmModal
|
|
13
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-X2GKC3IU.js";
|
|
21
|
+
import {
|
|
22
|
+
NavMenuLink
|
|
23
|
+
} from "./chunk-6DIGPXAD.js";
|
|
14
24
|
import {
|
|
15
25
|
NavMenuList,
|
|
16
26
|
getPosition
|
|
@@ -34,9 +44,6 @@ import {
|
|
|
34
44
|
import {
|
|
35
45
|
TabList
|
|
36
46
|
} from "./chunk-X2JMXTBH.js";
|
|
37
|
-
import {
|
|
38
|
-
TabPanel
|
|
39
|
-
} from "./chunk-67S42J4B.js";
|
|
40
47
|
import {
|
|
41
48
|
useToggle
|
|
42
49
|
} from "./chunk-QEA6N6TN.js";
|
|
@@ -58,20 +65,20 @@ import {
|
|
|
58
65
|
} from "./chunk-SLHX5K6I.js";
|
|
59
66
|
import {
|
|
60
67
|
Input
|
|
61
|
-
} from "./chunk-
|
|
68
|
+
} from "./chunk-5GEC53G7.js";
|
|
62
69
|
import {
|
|
63
70
|
Label
|
|
64
|
-
} from "./chunk-
|
|
71
|
+
} from "./chunk-CU7HXAKM.js";
|
|
72
|
+
import {
|
|
73
|
+
Show
|
|
74
|
+
} from "./chunk-4O4QFF4S.js";
|
|
65
75
|
import {
|
|
66
76
|
Field,
|
|
67
77
|
useFieldContext
|
|
68
78
|
} from "./chunk-ZAU4JVLL.js";
|
|
69
79
|
import {
|
|
70
|
-
|
|
71
|
-
} from "./chunk-
|
|
72
|
-
import {
|
|
73
|
-
Show
|
|
74
|
-
} from "./chunk-4O4QFF4S.js";
|
|
80
|
+
ModalIcon
|
|
81
|
+
} from "./chunk-G3JEWPLM.js";
|
|
75
82
|
import "./chunk-55J6XMHW.js";
|
|
76
83
|
import {
|
|
77
84
|
createNavTriggerProps
|
|
@@ -90,8 +97,8 @@ import {
|
|
|
90
97
|
import {
|
|
91
98
|
$cerberusIcons,
|
|
92
99
|
defineIcons
|
|
93
|
-
} from "./chunk-
|
|
94
|
-
import "./chunk-
|
|
100
|
+
} from "./chunk-6TXQZ3PB.js";
|
|
101
|
+
import "./chunk-C45DY4VE.js";
|
|
95
102
|
import {
|
|
96
103
|
MODE_KEY,
|
|
97
104
|
THEME_KEY,
|
|
@@ -111,11 +118,13 @@ export {
|
|
|
111
118
|
Input,
|
|
112
119
|
Label,
|
|
113
120
|
MODE_KEY,
|
|
121
|
+
ModalIcon,
|
|
114
122
|
NavMenu,
|
|
115
123
|
NavMenuLink,
|
|
116
124
|
NavMenuList,
|
|
117
125
|
NavMenuTrigger,
|
|
118
126
|
Portal,
|
|
127
|
+
PromptModal,
|
|
119
128
|
Radio,
|
|
120
129
|
Show,
|
|
121
130
|
THEME_KEY,
|
|
@@ -136,6 +145,7 @@ export {
|
|
|
136
145
|
useFeatureFlags,
|
|
137
146
|
useFieldContext,
|
|
138
147
|
useNavMenuContext,
|
|
148
|
+
usePromptModal,
|
|
139
149
|
useTabsContext,
|
|
140
150
|
useTabsKeyboardNavigation,
|
|
141
151
|
useTheme,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cerberus-design/react",
|
|
3
|
-
"version": "0.6.1-next-
|
|
3
|
+
"version": "0.6.1-next-8062b70",
|
|
4
4
|
"description": "The Cerberus Design React component library.",
|
|
5
5
|
"browserslist": "> 0.25%, not dead",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"react-dom": "^18",
|
|
24
24
|
"tsup": "^8.1.0",
|
|
25
25
|
"@cerberus-design/configs": "0.0.0",
|
|
26
|
-
"@cerberus-design/styled-system": "0.6.1-next-
|
|
26
|
+
"@cerberus-design/styled-system": "0.6.1-next-8062b70"
|
|
27
27
|
},
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { cx } from '@cerberus-design/styled-system/css'
|
|
2
|
+
import { circle } from '@cerberus-design/styled-system/patterns'
|
|
3
|
+
import {
|
|
4
|
+
modalIcon,
|
|
5
|
+
type ModalIconVariantProps,
|
|
6
|
+
} from '@cerberus-design/styled-system/recipes'
|
|
7
|
+
import type { HTMLAttributes, PropsWithChildren } from 'react'
|
|
8
|
+
|
|
9
|
+
export type ModalIconBaseProps = HTMLAttributes<HTMLDivElement>
|
|
10
|
+
export type ModalIconProps = ModalIconBaseProps & ModalIconVariantProps
|
|
11
|
+
|
|
12
|
+
export function ModalIcon(props: PropsWithChildren<ModalIconProps>) {
|
|
13
|
+
const { palette, ...nativeProps } = props
|
|
14
|
+
return (
|
|
15
|
+
<div
|
|
16
|
+
{...nativeProps}
|
|
17
|
+
className={cx(
|
|
18
|
+
nativeProps.className,
|
|
19
|
+
modalIcon({
|
|
20
|
+
palette,
|
|
21
|
+
}),
|
|
22
|
+
circle(),
|
|
23
|
+
)}
|
|
24
|
+
>
|
|
25
|
+
{props.children}
|
|
26
|
+
</div>
|
|
27
|
+
)
|
|
28
|
+
}
|
package/src/config/cerbIcons.ts
CHANGED
|
@@ -8,12 +8,14 @@ import type { ElementType } from 'react'
|
|
|
8
8
|
|
|
9
9
|
export interface DefinedIcons {
|
|
10
10
|
confirmModal?: CarbonIconType | ElementType
|
|
11
|
+
promptModal?: CarbonIconType | ElementType
|
|
11
12
|
invalid: CarbonIconType | ElementType
|
|
12
13
|
toggleChecked?: CarbonIconType | ElementType
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
export const defaultIcons: DefinedIcons = {
|
|
16
17
|
confirmModal: Information,
|
|
18
|
+
promptModal: Information,
|
|
17
19
|
invalid: WarningFilled,
|
|
18
20
|
toggleChecked: Checkmark,
|
|
19
21
|
}
|
|
@@ -12,14 +12,12 @@ import {
|
|
|
12
12
|
} from 'react'
|
|
13
13
|
import { Portal } from '../components/Portal'
|
|
14
14
|
import { Button } from '../components/Button'
|
|
15
|
-
import { css
|
|
16
|
-
import {
|
|
15
|
+
import { css } from '@cerberus-design/styled-system/css'
|
|
16
|
+
import { hstack, vstack } from '@cerberus-design/styled-system/patterns'
|
|
17
17
|
import { $cerberusIcons } from '../config/defineIcons'
|
|
18
|
-
import {
|
|
19
|
-
confirmModal,
|
|
20
|
-
type ConfirmModalVariantProps,
|
|
21
|
-
} from '@cerberus-design/styled-system/recipes'
|
|
18
|
+
import { modal } from '@cerberus-design/styled-system/recipes'
|
|
22
19
|
import { trapFocus } from '../aria-helpers/trap-focus.aria'
|
|
20
|
+
import { ModalIcon } from '../components/ModalIcon'
|
|
23
21
|
import { Show } from '../components/Show'
|
|
24
22
|
|
|
25
23
|
/**
|
|
@@ -77,12 +75,13 @@ export function ConfirmModal(
|
|
|
77
75
|
const resolveRef = useRef<ShowResult>(null)
|
|
78
76
|
const [content, setContent] = useState<ShowConfirmModalOptions | null>(null)
|
|
79
77
|
const focusTrap = trapFocus(dialogRef)
|
|
78
|
+
const ConfirmIcon = $cerberusIcons.confirmModal
|
|
80
79
|
|
|
81
80
|
const palette = useMemo(
|
|
82
81
|
() => (content?.kind === 'destructive' ? 'danger' : 'action'),
|
|
83
82
|
[content],
|
|
84
83
|
)
|
|
85
|
-
const styles =
|
|
84
|
+
const styles = modal()
|
|
86
85
|
|
|
87
86
|
const handleChoice = useCallback((e: MouseEvent<HTMLButtonElement>) => {
|
|
88
87
|
const target = e.currentTarget as HTMLButtonElement
|
|
@@ -114,21 +113,31 @@ export function ConfirmModal(
|
|
|
114
113
|
|
|
115
114
|
<Portal>
|
|
116
115
|
<dialog className={styles.dialog} onKeyDown={focusTrap} ref={dialogRef}>
|
|
117
|
-
<
|
|
116
|
+
<section
|
|
118
117
|
className={vstack({
|
|
119
118
|
alignItems: 'flex-start',
|
|
120
119
|
gap: '4',
|
|
121
120
|
mb: '8',
|
|
122
121
|
})}
|
|
123
122
|
>
|
|
124
|
-
<
|
|
123
|
+
<Show
|
|
124
|
+
when={palette === 'danger'}
|
|
125
|
+
fallback={
|
|
126
|
+
<ModalIcon palette="action">
|
|
127
|
+
<ConfirmIcon size={24} />
|
|
128
|
+
</ModalIcon>
|
|
129
|
+
}
|
|
130
|
+
>
|
|
131
|
+
<ModalIcon palette="danger">
|
|
132
|
+
<ConfirmIcon size={24} />
|
|
133
|
+
</ModalIcon>
|
|
134
|
+
</Show>
|
|
125
135
|
<h2 className={styles.heading}>{content?.heading}</h2>
|
|
126
136
|
<p className={styles.description}>{content?.description}</p>
|
|
127
|
-
</
|
|
137
|
+
</section>
|
|
128
138
|
|
|
129
139
|
<div
|
|
130
140
|
className={hstack({
|
|
131
|
-
justifyContent: 'stretch',
|
|
132
141
|
gap: '4',
|
|
133
142
|
})}
|
|
134
143
|
>
|
|
@@ -162,38 +171,6 @@ export function ConfirmModal(
|
|
|
162
171
|
)
|
|
163
172
|
}
|
|
164
173
|
|
|
165
|
-
// This is to help show the variant styles for the icon since Panda is
|
|
166
|
-
// not syncing correctly for the danger variant.
|
|
167
|
-
function ConfirmModalIcon(props: ConfirmModalVariantProps) {
|
|
168
|
-
const InfoIcon = $cerberusIcons.confirmModal
|
|
169
|
-
return (
|
|
170
|
-
<Show
|
|
171
|
-
when={props.palette === 'danger'}
|
|
172
|
-
fallback={
|
|
173
|
-
<div className={cx(confirmModal().icon, circle())}>
|
|
174
|
-
<InfoIcon />
|
|
175
|
-
</div>
|
|
176
|
-
}
|
|
177
|
-
>
|
|
178
|
-
<div
|
|
179
|
-
className={cx(
|
|
180
|
-
confirmModal({
|
|
181
|
-
palette: 'danger',
|
|
182
|
-
}).icon,
|
|
183
|
-
circle({
|
|
184
|
-
bgColor: 'danger.surface.initial',
|
|
185
|
-
}),
|
|
186
|
-
)}
|
|
187
|
-
style={{
|
|
188
|
-
color: 'var(--cerberus-colors-danger-text-100)',
|
|
189
|
-
}}
|
|
190
|
-
>
|
|
191
|
-
<InfoIcon />
|
|
192
|
-
</div>
|
|
193
|
-
</Show>
|
|
194
|
-
)
|
|
195
|
-
}
|
|
196
|
-
|
|
197
174
|
export function useConfirmModal(): ConfirmModalValue {
|
|
198
175
|
const context = useContext(ConfirmModalContext)
|
|
199
176
|
if (context === null) {
|