@cerberus-design/react 0.6.1-next-2d28489 → 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 +13 -9
- package/build/legacy/{chunk-7ISHDUYN.js → chunk-5GEC53G7.js} +4 -4
- 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-BLJ4SRAF.js → chunk-UZIN7UOS.js} +18 -38
- package/build/legacy/chunk-UZIN7UOS.js.map +1 -0
- package/build/legacy/{chunk-SNSBODYR.js → chunk-WKSC2WCV.js} +21 -43
- package/build/legacy/chunk-WKSC2WCV.js.map +1 -0
- package/build/legacy/components/Input.js +2 -2
- 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/context/confirm-modal.js +2 -3
- package/build/legacy/context/prompt-modal.js +5 -7
- package/build/legacy/index.js +19 -19
- package/build/modern/_tsup-dts-rollup.d.ts +13 -9
- package/build/modern/{chunk-7ISHDUYN.js → chunk-5GEC53G7.js} +4 -4
- 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-4GURONLE.js → chunk-X2GKC3IU.js} +18 -38
- package/build/modern/chunk-X2GKC3IU.js.map +1 -0
- package/build/modern/{chunk-FZ75OJLJ.js → chunk-YHJTKBVE.js} +21 -43
- package/build/modern/chunk-YHJTKBVE.js.map +1 -0
- package/build/modern/components/Input.js +2 -2
- 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/context/confirm-modal.js +2 -3
- package/build/modern/context/prompt-modal.js +5 -7
- package/build/modern/index.js +19 -19
- package/package.json +2 -2
- package/src/components/ModalIcon.tsx +28 -0
- package/src/context/confirm-modal.tsx +20 -43
- package/src/context/prompt-modal.tsx +18 -41
- package/src/index.ts +1 -0
- package/build/legacy/chunk-BLJ4SRAF.js.map +0 -1
- package/build/legacy/chunk-SNSBODYR.js.map +0 -1
- package/build/modern/chunk-4GURONLE.js.map +0 -1
- package/build/modern/chunk-FZ75OJLJ.js.map +0 -1
- /package/build/legacy/{chunk-7ISHDUYN.js.map → chunk-5GEC53G7.js.map} +0 -0
- /package/build/legacy/{chunk-JJGZRBIR.js.map → chunk-CU7HXAKM.js.map} +0 -0
- /package/build/modern/{chunk-7ISHDUYN.js.map → chunk-5GEC53G7.js.map} +0 -0
- /package/build/modern/{chunk-JJGZRBIR.js.map → chunk-CU7HXAKM.js.map} +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useFieldContext
|
|
3
|
-
} from "./chunk-ZAU4JVLL.js";
|
|
4
1
|
import {
|
|
5
2
|
Show
|
|
6
3
|
} from "./chunk-4O4QFF4S.js";
|
|
4
|
+
import {
|
|
5
|
+
useFieldContext
|
|
6
|
+
} from "./chunk-ZAU4JVLL.js";
|
|
7
7
|
|
|
8
8
|
// src/components/Label.tsx
|
|
9
9
|
import { label } from "@cerberus/styled-system/recipes";
|
|
@@ -46,4 +46,4 @@ function Label(props) {
|
|
|
46
46
|
export {
|
|
47
47
|
Label
|
|
48
48
|
};
|
|
49
|
-
//# sourceMappingURL=chunk-
|
|
49
|
+
//# sourceMappingURL=chunk-CU7HXAKM.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// src/components/ModalIcon.tsx
|
|
2
|
+
import { cx } from "@cerberus-design/styled-system/css";
|
|
3
|
+
import { circle } from "@cerberus-design/styled-system/patterns";
|
|
4
|
+
import {
|
|
5
|
+
modalIcon
|
|
6
|
+
} from "@cerberus-design/styled-system/recipes";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
function ModalIcon(props) {
|
|
9
|
+
const { palette, ...nativeProps } = props;
|
|
10
|
+
return /* @__PURE__ */ jsx(
|
|
11
|
+
"div",
|
|
12
|
+
{
|
|
13
|
+
...nativeProps,
|
|
14
|
+
className: cx(
|
|
15
|
+
nativeProps.className,
|
|
16
|
+
modalIcon({
|
|
17
|
+
palette
|
|
18
|
+
}),
|
|
19
|
+
circle()
|
|
20
|
+
),
|
|
21
|
+
children: props.children
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
ModalIcon
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=chunk-G3JEWPLM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/ModalIcon.tsx"],"sourcesContent":["import { cx } from '@cerberus-design/styled-system/css'\nimport { circle } from '@cerberus-design/styled-system/patterns'\nimport {\n modalIcon,\n type ModalIconVariantProps,\n} from '@cerberus-design/styled-system/recipes'\nimport type { HTMLAttributes, PropsWithChildren } from 'react'\n\nexport type ModalIconBaseProps = HTMLAttributes<HTMLDivElement>\nexport type ModalIconProps = ModalIconBaseProps & ModalIconVariantProps\n\nexport function ModalIcon(props: PropsWithChildren<ModalIconProps>) {\n const { palette, ...nativeProps } = props\n return (\n <div\n {...nativeProps}\n className={cx(\n nativeProps.className,\n modalIcon({\n palette,\n }),\n circle(),\n )}\n >\n {props.children}\n </div>\n )\n}\n"],"mappings":";AAAA,SAAS,UAAU;AACnB,SAAS,cAAc;AACvB;AAAA,EACE;AAAA,OAEK;AASH;AAHG,SAAS,UAAU,OAA0C;AAClE,QAAM,EAAE,SAAS,GAAG,YAAY,IAAI;AACpC,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,WAAW;AAAA,QACT,YAAY;AAAA,QACZ,UAAU;AAAA,UACR;AAAA,QACF,CAAC;AAAA,QACD,OAAO;AAAA,MACT;AAAA,MAEC,gBAAM;AAAA;AAAA,EACT;AAEJ;","names":[]}
|
|
@@ -7,6 +7,9 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
Show
|
|
9
9
|
} from "./chunk-4O4QFF4S.js";
|
|
10
|
+
import {
|
|
11
|
+
ModalIcon
|
|
12
|
+
} from "./chunk-G3JEWPLM.js";
|
|
10
13
|
import {
|
|
11
14
|
trapFocus
|
|
12
15
|
} from "./chunk-JIZQFTW6.js";
|
|
@@ -23,11 +26,9 @@ import {
|
|
|
23
26
|
useRef,
|
|
24
27
|
useState
|
|
25
28
|
} from "react";
|
|
26
|
-
import { css
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
confirmModal
|
|
30
|
-
} from "@cerberus-design/styled-system/recipes";
|
|
29
|
+
import { css } from "@cerberus-design/styled-system/css";
|
|
30
|
+
import { hstack, vstack } from "@cerberus-design/styled-system/patterns";
|
|
31
|
+
import { modal } from "@cerberus-design/styled-system/recipes";
|
|
31
32
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
32
33
|
var ConfirmModalContext = createContext(null);
|
|
33
34
|
function ConfirmModal(props) {
|
|
@@ -35,11 +36,12 @@ function ConfirmModal(props) {
|
|
|
35
36
|
const resolveRef = useRef(null);
|
|
36
37
|
const [content, setContent] = useState(null);
|
|
37
38
|
const focusTrap = trapFocus(dialogRef);
|
|
39
|
+
const ConfirmIcon = $cerberusIcons.confirmModal;
|
|
38
40
|
const palette = useMemo(
|
|
39
41
|
() => content?.kind === "destructive" ? "danger" : "action",
|
|
40
42
|
[content]
|
|
41
43
|
);
|
|
42
|
-
const styles =
|
|
44
|
+
const styles = modal();
|
|
43
45
|
const handleChoice = useCallback((e) => {
|
|
44
46
|
const target = e.currentTarget;
|
|
45
47
|
if (target.value === "true") {
|
|
@@ -65,7 +67,7 @@ function ConfirmModal(props) {
|
|
|
65
67
|
props.children,
|
|
66
68
|
/* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsxs("dialog", { className: styles.dialog, onKeyDown: focusTrap, ref: dialogRef, children: [
|
|
67
69
|
/* @__PURE__ */ jsxs(
|
|
68
|
-
"
|
|
70
|
+
"section",
|
|
69
71
|
{
|
|
70
72
|
className: vstack({
|
|
71
73
|
alignItems: "flex-start",
|
|
@@ -73,7 +75,14 @@ function ConfirmModal(props) {
|
|
|
73
75
|
mb: "8"
|
|
74
76
|
}),
|
|
75
77
|
children: [
|
|
76
|
-
/* @__PURE__ */ jsx(
|
|
78
|
+
/* @__PURE__ */ jsx(
|
|
79
|
+
Show,
|
|
80
|
+
{
|
|
81
|
+
when: palette === "danger",
|
|
82
|
+
fallback: /* @__PURE__ */ jsx(ModalIcon, { palette: "action", children: /* @__PURE__ */ jsx(ConfirmIcon, { size: 24 }) }),
|
|
83
|
+
children: /* @__PURE__ */ jsx(ModalIcon, { palette: "danger", children: /* @__PURE__ */ jsx(ConfirmIcon, { size: 24 }) })
|
|
84
|
+
}
|
|
85
|
+
),
|
|
77
86
|
/* @__PURE__ */ jsx("h2", { className: styles.heading, children: content?.heading }),
|
|
78
87
|
/* @__PURE__ */ jsx("p", { className: styles.description, children: content?.description })
|
|
79
88
|
]
|
|
@@ -83,7 +92,6 @@ function ConfirmModal(props) {
|
|
|
83
92
|
"div",
|
|
84
93
|
{
|
|
85
94
|
className: hstack({
|
|
86
|
-
justifyContent: "stretch",
|
|
87
95
|
gap: "4"
|
|
88
96
|
}),
|
|
89
97
|
children: [
|
|
@@ -120,33 +128,6 @@ function ConfirmModal(props) {
|
|
|
120
128
|
] }) })
|
|
121
129
|
] });
|
|
122
130
|
}
|
|
123
|
-
function ConfirmModalIcon(props) {
|
|
124
|
-
const InfoIcon = $cerberusIcons.confirmModal;
|
|
125
|
-
return /* @__PURE__ */ jsx(
|
|
126
|
-
Show,
|
|
127
|
-
{
|
|
128
|
-
when: props.palette === "danger",
|
|
129
|
-
fallback: /* @__PURE__ */ jsx("div", { className: cx(confirmModal().icon, circle()), children: /* @__PURE__ */ jsx(InfoIcon, { size: 24 }) }),
|
|
130
|
-
children: /* @__PURE__ */ jsx(
|
|
131
|
-
"div",
|
|
132
|
-
{
|
|
133
|
-
className: cx(
|
|
134
|
-
confirmModal({
|
|
135
|
-
palette: "danger"
|
|
136
|
-
}).icon,
|
|
137
|
-
circle({
|
|
138
|
-
bgColor: "danger.surface.initial"
|
|
139
|
-
})
|
|
140
|
-
),
|
|
141
|
-
style: {
|
|
142
|
-
color: "var(--cerberus-colors-danger-text-100)"
|
|
143
|
-
},
|
|
144
|
-
children: /* @__PURE__ */ jsx(InfoIcon, { size: 24 })
|
|
145
|
-
}
|
|
146
|
-
)
|
|
147
|
-
}
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
131
|
function useConfirmModal() {
|
|
151
132
|
const context = useContext(ConfirmModalContext);
|
|
152
133
|
if (context === null) {
|
|
@@ -159,7 +140,6 @@ function useConfirmModal() {
|
|
|
159
140
|
|
|
160
141
|
export {
|
|
161
142
|
ConfirmModal,
|
|
162
|
-
ConfirmModalIcon,
|
|
163
143
|
useConfirmModal
|
|
164
144
|
};
|
|
165
|
-
//# sourceMappingURL=chunk-
|
|
145
|
+
//# sourceMappingURL=chunk-X2GKC3IU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/context/confirm-modal.tsx"],"sourcesContent":["'use client'\n\nimport {\n createContext,\n useCallback,\n useContext,\n useMemo,\n useRef,\n useState,\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 { $cerberusIcons } from '../config/defineIcons'\nimport { modal } from '@cerberus-design/styled-system/recipes'\nimport { trapFocus } from '../aria-helpers/trap-focus.aria'\nimport { ModalIcon } from '../components/ModalIcon'\nimport { Show } from '../components/Show'\n\n/**\n * This module provides a context and hook for the confirm modal.\n * @module\n */\n\nexport interface ShowConfirmModalOptions {\n kind?: 'destructive' | 'non-destructive'\n heading: string\n description?: string\n actionText: string\n cancelText: string\n}\nexport type ShowResult =\n | ((value: boolean | PromiseLike<boolean>) => void)\n | null\n\nexport interface ConfirmModalValue {\n show: (options: ShowConfirmModalOptions) => Promise<boolean>\n}\n\nconst ConfirmModalContext = createContext<ConfirmModalValue | null>(null)\n\nexport interface ConfirmModalProviderProps {}\n\n/**\n * Provides a confirm modal to the app.\n * @example\n * ```tsx\n * // Wrap the Provider around the root of the feature.\n * <ConfirmModal>\n * <SomeFeatureSection />\n * </ConfirmModal>\n *\n * // Use the hook to show the confirm modal.\n * const confirm = useConfirmModal()\n *\n * const handleClick = useCallback(async () => {\n * const userConsent = await confirm.show({\n * heading: 'Add new payment method?',\n * description:\n * 'This will add a new payment method to your account to be billed for future purchases.',\n * actionText: 'Yes, add payment method',\n * cancelText: 'No, cancel',\n * })\n * setConsent(userConsent)\n * }, [confirm])\n * ```\n */\nexport function ConfirmModal(\n props: PropsWithChildren<ConfirmModalProviderProps>,\n) {\n const dialogRef = useRef<HTMLDialogElement>(null)\n const resolveRef = useRef<ShowResult>(null)\n const [content, setContent] = useState<ShowConfirmModalOptions | null>(null)\n const focusTrap = trapFocus(dialogRef)\n const ConfirmIcon = $cerberusIcons.confirmModal\n\n const palette = useMemo(\n () => (content?.kind === 'destructive' ? 'danger' : 'action'),\n [content],\n )\n const styles = modal()\n\n const handleChoice = useCallback((e: MouseEvent<HTMLButtonElement>) => {\n const target = e.currentTarget as HTMLButtonElement\n if (target.value === 'true') {\n resolveRef.current?.(true)\n }\n resolveRef.current?.(false)\n dialogRef?.current?.close()\n }, [])\n\n const handleShow = useCallback((options: ShowConfirmModalOptions) => {\n return new Promise<boolean>((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 <ConfirmModalContext.Provider value={value}>\n {props.children}\n\n <Portal>\n <dialog className={styles.dialog} onKeyDown={focusTrap} ref={dialogRef}>\n <section\n className={vstack({\n alignItems: 'flex-start',\n gap: '4',\n mb: '8',\n })}\n >\n <Show\n when={palette === 'danger'}\n fallback={\n <ModalIcon palette=\"action\">\n <ConfirmIcon size={24} />\n </ModalIcon>\n }\n >\n <ModalIcon palette=\"danger\">\n <ConfirmIcon size={24} />\n </ModalIcon>\n </Show>\n <h2 className={styles.heading}>{content?.heading}</h2>\n <p className={styles.description}>{content?.description}</p>\n </section>\n\n <div\n className={hstack({\n gap: '4',\n })}\n >\n <Button\n autoFocus\n className={css({\n w: '1/2',\n })}\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 </ConfirmModalContext.Provider>\n )\n}\n\nexport function useConfirmModal(): ConfirmModalValue {\n const context = useContext(ConfirmModalContext)\n if (context === null) {\n throw new Error(\n 'useConfirmModal must be used within a ConfirmModal Provider',\n )\n }\n return context\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAGP,SAAS,WAAW;AACpB,SAAS,QAAQ,cAAc;AAE/B,SAAS,aAAa;AAkGZ,SAWQ,KAXR;AAzEV,IAAM,sBAAsB,cAAwC,IAAI;AA4BjE,SAAS,aACd,OACA;AACA,QAAM,YAAY,OAA0B,IAAI;AAChD,QAAM,aAAa,OAAmB,IAAI;AAC1C,QAAM,CAAC,SAAS,UAAU,IAAI,SAAyC,IAAI;AAC3E,QAAM,YAAY,UAAU,SAAS;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ACjD,oBAAC,OAAE,WAAW,OAAO,aAAc,mBAAS,aAAY;AAAA;AAAA;AAAA,MAC1D;AAAA,MAEA;AAAA,QAAC;AAAA;AAAA,UACC,WAAW,OAAO;AAAA,YAChB,KAAK;AAAA,UACP,CAAC;AAAA,UAED;AAAA;AAAA,cAAC;AAAA;AAAA,gBACC,WAAS;AAAA,gBACT,WAAW,IAAI;AAAA,kBACb,GAAG;AAAA,gBACL,CAAC;AAAA,gBACD,MAAK;AAAA,gBACL,SAAS;AAAA,gBACT;AAAA,gBACA,OAAM;AAAA,gBAEL,mBAAS;AAAA;AAAA,YACZ;AAAA,YACA;AAAA,cAAC;AAAA;AAAA,gBACC,WAAW,IAAI;AAAA,kBACb,GAAG;AAAA,gBACL,CAAC;AAAA,gBACD,MAAK;AAAA,gBACL,SAAS;AAAA,gBACT,OAAM;AAAA,gBACN,OAAM;AAAA,gBAEL,mBAAS;AAAA;AAAA,YACZ;AAAA;AAAA;AAAA,MACF;AAAA,OACF,GACF;AAAA,KACF;AAEJ;AAEO,SAAS,kBAAqC;AACnD,QAAM,UAAU,WAAW,mBAAmB;AAC9C,MAAI,YAAY,MAAM;AACpB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ConfirmModalIcon
|
|
3
|
-
} from "./chunk-4GURONLE.js";
|
|
4
1
|
import {
|
|
5
2
|
Portal
|
|
6
3
|
} from "./chunk-4CAT3FHV.js";
|
|
@@ -9,16 +6,19 @@ import {
|
|
|
9
6
|
} from "./chunk-2ATICEW3.js";
|
|
10
7
|
import {
|
|
11
8
|
Input
|
|
12
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-5GEC53G7.js";
|
|
13
10
|
import {
|
|
14
11
|
Label
|
|
15
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-CU7HXAKM.js";
|
|
13
|
+
import {
|
|
14
|
+
Show
|
|
15
|
+
} from "./chunk-4O4QFF4S.js";
|
|
16
16
|
import {
|
|
17
17
|
Field
|
|
18
18
|
} from "./chunk-ZAU4JVLL.js";
|
|
19
19
|
import {
|
|
20
|
-
|
|
21
|
-
} from "./chunk-
|
|
20
|
+
ModalIcon
|
|
21
|
+
} from "./chunk-G3JEWPLM.js";
|
|
22
22
|
import {
|
|
23
23
|
trapFocus
|
|
24
24
|
} from "./chunk-JIZQFTW6.js";
|
|
@@ -35,11 +35,9 @@ import {
|
|
|
35
35
|
useRef,
|
|
36
36
|
useState
|
|
37
37
|
} from "react";
|
|
38
|
-
import { css
|
|
39
|
-
import {
|
|
40
|
-
import {
|
|
41
|
-
confirmModal
|
|
42
|
-
} from "@cerberus-design/styled-system/recipes";
|
|
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";
|
|
43
41
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
44
42
|
var PromptModalContext = createContext(null);
|
|
45
43
|
function PromptModal(props) {
|
|
@@ -48,6 +46,7 @@ function PromptModal(props) {
|
|
|
48
46
|
const [content, setContent] = useState(null);
|
|
49
47
|
const [inputValue, setInputValue] = useState("");
|
|
50
48
|
const focusTrap = trapFocus(dialogRef);
|
|
49
|
+
const PromptIcon = $cerberusIcons.promptModal;
|
|
51
50
|
const isValid = useMemo(
|
|
52
51
|
() => inputValue === content?.key,
|
|
53
52
|
[inputValue, content]
|
|
@@ -56,7 +55,7 @@ function PromptModal(props) {
|
|
|
56
55
|
() => content?.kind === "destructive" ? "danger" : "action",
|
|
57
56
|
[content]
|
|
58
57
|
);
|
|
59
|
-
const styles =
|
|
58
|
+
const styles = modal();
|
|
60
59
|
const handleChange = useCallback(
|
|
61
60
|
(e) => {
|
|
62
61
|
setInputValue(e.currentTarget.value);
|
|
@@ -97,7 +96,14 @@ function PromptModal(props) {
|
|
|
97
96
|
gap: "4"
|
|
98
97
|
}),
|
|
99
98
|
children: [
|
|
100
|
-
/* @__PURE__ */ jsx(
|
|
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
|
+
),
|
|
101
107
|
/* @__PURE__ */ jsx("h2", { className: styles.heading, children: content?.heading }),
|
|
102
108
|
/* @__PURE__ */ jsx("p", { className: styles.description, children: content?.description })
|
|
103
109
|
]
|
|
@@ -179,33 +185,6 @@ function PromptModal(props) {
|
|
|
179
185
|
] }) })
|
|
180
186
|
] });
|
|
181
187
|
}
|
|
182
|
-
function PromptModalIcon(props) {
|
|
183
|
-
const PromptIcon = $cerberusIcons.promptModal;
|
|
184
|
-
return /* @__PURE__ */ jsx(
|
|
185
|
-
Show,
|
|
186
|
-
{
|
|
187
|
-
when: props.palette === "danger",
|
|
188
|
-
fallback: /* @__PURE__ */ jsx("div", { className: cx(confirmModal().icon, circle()), children: /* @__PURE__ */ jsx(PromptIcon, { size: 24 }) }),
|
|
189
|
-
children: /* @__PURE__ */ jsx(
|
|
190
|
-
"div",
|
|
191
|
-
{
|
|
192
|
-
className: cx(
|
|
193
|
-
confirmModal({
|
|
194
|
-
palette: "danger"
|
|
195
|
-
}).icon,
|
|
196
|
-
circle({
|
|
197
|
-
bgColor: "danger.surface.initial"
|
|
198
|
-
})
|
|
199
|
-
),
|
|
200
|
-
style: {
|
|
201
|
-
color: "var(--cerberus-colors-danger-text-100)"
|
|
202
|
-
},
|
|
203
|
-
children: /* @__PURE__ */ jsx(PromptIcon, { size: 24 })
|
|
204
|
-
}
|
|
205
|
-
)
|
|
206
|
-
}
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
188
|
function usePromptModal() {
|
|
210
189
|
const context = useContext(PromptModalContext);
|
|
211
190
|
if (context === null) {
|
|
@@ -216,7 +195,6 @@ function usePromptModal() {
|
|
|
216
195
|
|
|
217
196
|
export {
|
|
218
197
|
PromptModal,
|
|
219
|
-
PromptModalIcon,
|
|
220
198
|
usePromptModal
|
|
221
199
|
};
|
|
222
|
-
//# sourceMappingURL=chunk-
|
|
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,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C,WAAW,IAAI;AAAA,kBACb,GAAG;AAAA,gBACL,CAAC;AAAA,gBACD,MAAK;AAAA,gBACL,SAAS;AAAA,gBACT,OAAM;AAAA,gBACN,OAAM;AAAA,gBAEL,mBAAS;AAAA;AAAA,YACZ;AAAA;AAAA;AAAA,MACF;AAAA,OACF,GACF;AAAA,KACF;AAEJ;AAEO,SAAS,iBAAmC;AACjD,QAAM,UAAU,WAAW,kBAAkB;AAC7C,MAAI,YAAY,MAAM;AACpB,UAAM,IAAI,MAAM,2DAA2D;AAAA,EAC7E;AACA,SAAO;AACT;","names":[]}
|
|
@@ -1,9 +1,9 @@
|
|
|
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";
|
|
6
|
+
import "../chunk-ZAU4JVLL.js";
|
|
7
7
|
import "../chunk-6TXQZ3PB.js";
|
|
8
8
|
import "../chunk-C45DY4VE.js";
|
|
9
9
|
export {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
ConfirmModal,
|
|
4
|
-
ConfirmModalIcon,
|
|
5
4
|
useConfirmModal
|
|
6
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-X2GKC3IU.js";
|
|
7
6
|
import "../chunk-4CAT3FHV.js";
|
|
8
7
|
import "../chunk-2ATICEW3.js";
|
|
9
8
|
import "../chunk-4O4QFF4S.js";
|
|
9
|
+
import "../chunk-G3JEWPLM.js";
|
|
10
10
|
import "../chunk-JIZQFTW6.js";
|
|
11
11
|
import "../chunk-6TXQZ3PB.js";
|
|
12
12
|
import "../chunk-C45DY4VE.js";
|
|
13
13
|
export {
|
|
14
14
|
ConfirmModal,
|
|
15
|
-
ConfirmModalIcon,
|
|
16
15
|
useConfirmModal
|
|
17
16
|
};
|
|
18
17
|
//# sourceMappingURL=confirm-modal.js.map
|
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
PromptModal,
|
|
4
|
-
PromptModalIcon,
|
|
5
4
|
usePromptModal
|
|
6
|
-
} from "../chunk-
|
|
7
|
-
import "../chunk-4GURONLE.js";
|
|
5
|
+
} from "../chunk-YHJTKBVE.js";
|
|
8
6
|
import "../chunk-4CAT3FHV.js";
|
|
9
7
|
import "../chunk-2ATICEW3.js";
|
|
10
|
-
import "../chunk-
|
|
11
|
-
import "../chunk-
|
|
12
|
-
import "../chunk-ZAU4JVLL.js";
|
|
8
|
+
import "../chunk-5GEC53G7.js";
|
|
9
|
+
import "../chunk-CU7HXAKM.js";
|
|
13
10
|
import "../chunk-4O4QFF4S.js";
|
|
11
|
+
import "../chunk-ZAU4JVLL.js";
|
|
12
|
+
import "../chunk-G3JEWPLM.js";
|
|
14
13
|
import "../chunk-JIZQFTW6.js";
|
|
15
14
|
import "../chunk-6TXQZ3PB.js";
|
|
16
15
|
import "../chunk-C45DY4VE.js";
|
|
17
16
|
export {
|
|
18
17
|
PromptModal,
|
|
19
|
-
PromptModalIcon,
|
|
20
18
|
usePromptModal
|
|
21
19
|
};
|
|
22
20
|
//# sourceMappingURL=prompt-modal.js.map
|
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";
|
|
@@ -7,16 +14,13 @@ import {
|
|
|
7
14
|
import {
|
|
8
15
|
Toggle
|
|
9
16
|
} from "./chunk-TAZI77TP.js";
|
|
10
|
-
import {
|
|
11
|
-
PromptModal,
|
|
12
|
-
PromptModalIcon,
|
|
13
|
-
usePromptModal
|
|
14
|
-
} from "./chunk-FZ75OJLJ.js";
|
|
15
17
|
import {
|
|
16
18
|
ConfirmModal,
|
|
17
|
-
ConfirmModalIcon,
|
|
18
19
|
useConfirmModal
|
|
19
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-X2GKC3IU.js";
|
|
21
|
+
import {
|
|
22
|
+
NavMenuLink
|
|
23
|
+
} from "./chunk-6DIGPXAD.js";
|
|
20
24
|
import {
|
|
21
25
|
NavMenuList,
|
|
22
26
|
getPosition
|
|
@@ -40,9 +44,6 @@ import {
|
|
|
40
44
|
import {
|
|
41
45
|
TabList
|
|
42
46
|
} from "./chunk-X2JMXTBH.js";
|
|
43
|
-
import {
|
|
44
|
-
TabPanel
|
|
45
|
-
} from "./chunk-67S42J4B.js";
|
|
46
47
|
import {
|
|
47
48
|
useToggle
|
|
48
49
|
} from "./chunk-QEA6N6TN.js";
|
|
@@ -64,20 +65,20 @@ import {
|
|
|
64
65
|
} from "./chunk-SLHX5K6I.js";
|
|
65
66
|
import {
|
|
66
67
|
Input
|
|
67
|
-
} from "./chunk-
|
|
68
|
+
} from "./chunk-5GEC53G7.js";
|
|
68
69
|
import {
|
|
69
70
|
Label
|
|
70
|
-
} from "./chunk-
|
|
71
|
+
} from "./chunk-CU7HXAKM.js";
|
|
72
|
+
import {
|
|
73
|
+
Show
|
|
74
|
+
} from "./chunk-4O4QFF4S.js";
|
|
71
75
|
import {
|
|
72
76
|
Field,
|
|
73
77
|
useFieldContext
|
|
74
78
|
} from "./chunk-ZAU4JVLL.js";
|
|
75
79
|
import {
|
|
76
|
-
|
|
77
|
-
} from "./chunk-
|
|
78
|
-
import {
|
|
79
|
-
Show
|
|
80
|
-
} from "./chunk-4O4QFF4S.js";
|
|
80
|
+
ModalIcon
|
|
81
|
+
} from "./chunk-G3JEWPLM.js";
|
|
81
82
|
import "./chunk-55J6XMHW.js";
|
|
82
83
|
import {
|
|
83
84
|
createNavTriggerProps
|
|
@@ -109,7 +110,6 @@ export {
|
|
|
109
110
|
$cerberusIcons,
|
|
110
111
|
Button,
|
|
111
112
|
ConfirmModal,
|
|
112
|
-
ConfirmModalIcon,
|
|
113
113
|
FeatureFlag,
|
|
114
114
|
FeatureFlags,
|
|
115
115
|
Field,
|
|
@@ -118,13 +118,13 @@ export {
|
|
|
118
118
|
Input,
|
|
119
119
|
Label,
|
|
120
120
|
MODE_KEY,
|
|
121
|
+
ModalIcon,
|
|
121
122
|
NavMenu,
|
|
122
123
|
NavMenuLink,
|
|
123
124
|
NavMenuList,
|
|
124
125
|
NavMenuTrigger,
|
|
125
126
|
Portal,
|
|
126
127
|
PromptModal,
|
|
127
|
-
PromptModalIcon,
|
|
128
128
|
Radio,
|
|
129
129
|
Show,
|
|
130
130
|
THEME_KEY,
|
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
|
+
}
|
|
@@ -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
|
-
export 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 size={24} />
|
|
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 size={24} />
|
|
192
|
-
</div>
|
|
193
|
-
</Show>
|
|
194
|
-
)
|
|
195
|
-
}
|
|
196
|
-
|
|
197
174
|
export function useConfirmModal(): ConfirmModalValue {
|
|
198
175
|
const context = useContext(ConfirmModalContext)
|
|
199
176
|
if (context === null) {
|