@planningcenter/sweetest-alert 2.0.3 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +59 -59
- package/dist/style.css +1 -0
- package/dist/sweetest_alert.d.ts +14 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -128,6 +128,8 @@ SweetestAlert({
|
|
|
128
128
|
const { isConfirmed, isDismissed } = await SweetestAlert({
|
|
129
129
|
title: "Leave without saving?",
|
|
130
130
|
content: "Your draft will be lost if you leave now.",
|
|
131
|
+
confirmButton: "Leave",
|
|
132
|
+
cancelButton: "Stay",
|
|
131
133
|
})
|
|
132
134
|
|
|
133
135
|
if (isConfirmed) {
|
|
@@ -290,6 +292,7 @@ SweetestAlert({
|
|
|
290
292
|
| `onConfirm` | Callback executed when confirm button is clicked. If it returns a promise, the dialog stays open with a loading confirm button until it settles — see [Async Confirm](#async-confirm). |
|
|
291
293
|
| `onCancel` | Callback executed when cancel button is clicked. Not called when `onConfirm` rejects. |
|
|
292
294
|
| `confirmButton` | Custom text for the confirm button. Defaults to "Okay". |
|
|
295
|
+
| `cancelButton` | Custom text for the cancel button. Defaults to "Cancel". An escape hatch, not a first choice — a consistent "Cancel" is what makes dialogs recognizable at a glance. Only override it when generic copy reads awkwardly next to a customized `confirmButton` (e.g. "Are you sure you want to cancel this registration?" paired with `confirmButton: "Yes, cancel it"` leaves the default `cancelButton: "Cancel"` ambiguous — does clicking it cancel the registration, or cancel out of the dialog?). |
|
|
293
296
|
| `hideCancel` | When `true`, hides the cancel button for simple notifications. Defaults to `false`. |
|
|
294
297
|
| `confirmation` | When set (`{ match, label?, description? }`), requires the user to type `match` before the confirm button is enabled. Case-sensitive; surrounding whitespace is ignored. Pressing Enter in the box confirms. An empty or whitespace-only `match` means no requirement. Reserve for destructive actions — see [Confirmation Input](#confirmation-input). |
|
|
295
298
|
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require("react");let e=require("react-dom/client"),t=require("@planningcenter/tapestry"),n=require("react/jsx-runtime");var r=`M8,0c4.41828,0 8,3.58172 8,8c0,4.41828 -3.58172,8 -8,8c-4.41828,0 -8,-3.58172 -8,-8c0,-4.41828 3.58172,-8 8,-8M12.57,6.07l-1.14,-1.14l-4.43,4.44l-2.43,-2.44l-1.14,1.14l3.57,3.56z`,i=`M15.669,13.676c0.13528,0.2343 0.13541,0.52294 0.00036,0.75737c-0.13505,0.23443 -0.38481,0.37911 -0.65536,0.37963h-14.028c-0.27081,0.0001 -0.52105,-0.14447 -0.65623,-0.37913c-0.13518,-0.23466 -0.13471,-0.52366 0.00123,-0.75787l7.014,-12.115c0.13497,-0.23419 0.3847,-0.37849 0.655,-0.37849c0.2703,0 0.52003,0.14431 0.655,0.37849l7.014,12.115M8.757,11.028h-1.514v1.514h1.514zM8.757,6.485h-1.514v3.029h1.514z`,a=`M8.8,4h-1.6v1.6h1.6zM8.8,7.2h-1.6v4.8h1.6zM8,0c4.41828,0 8,3.58172 8,8c0,4.41828 -3.58172,8 -8,8c-4.41828,0 -8,-3.58172 -8,-8c0,-4.41828 3.58172,-8 8,-8`,o=`M11.395,10.262l-2.262,-2.262l2.262,-2.262l-1.132,-1.132l-2.262,2.262l-2.263,-2.262l-1.131,1.132l2.262,2.262l-2.262,2.262l1.131,1.132l2.263,-2.262l2.262,2.262zM13.659,2.343c3.12218,3.12514 3.12218,8.18886 0,11.314c-2.28834,2.28863 -5.73017,2.97305 -8.72,1.734c-2.99134,-1.23749 -4.94222,-4.15558 -4.94244,-7.39278c-0.00022,-3.2372 1.95027,-6.15555 4.94143,-7.39345c2.99117,-1.2379 6.43353,-0.55139 8.72101,1.73923`,s=`Uh oh!`,c=`Something went wrong, please try again. If the error continues, please contact support.`,l=e=>`Doesn’t match. Type ${e} exactly, including capitalization.`;function u(){let e;return{promise:new Promise(t=>{e=t}),resolve:e}}function d(e){return typeof(e!==null&&(typeof e==`object`||typeof e==`function`)?e.then:void 0)==`function`}function f({onCancel:f,onConfirm:p,
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require("react");let e=require("react-dom/client"),t=require("@planningcenter/tapestry"),n=require("react/jsx-runtime");var r=`M8,0c4.41828,0 8,3.58172 8,8c0,4.41828 -3.58172,8 -8,8c-4.41828,0 -8,-3.58172 -8,-8c0,-4.41828 3.58172,-8 8,-8M12.57,6.07l-1.14,-1.14l-4.43,4.44l-2.43,-2.44l-1.14,1.14l3.57,3.56z`,i=`M15.669,13.676c0.13528,0.2343 0.13541,0.52294 0.00036,0.75737c-0.13505,0.23443 -0.38481,0.37911 -0.65536,0.37963h-14.028c-0.27081,0.0001 -0.52105,-0.14447 -0.65623,-0.37913c-0.13518,-0.23466 -0.13471,-0.52366 0.00123,-0.75787l7.014,-12.115c0.13497,-0.23419 0.3847,-0.37849 0.655,-0.37849c0.2703,0 0.52003,0.14431 0.655,0.37849l7.014,12.115M8.757,11.028h-1.514v1.514h1.514zM8.757,6.485h-1.514v3.029h1.514z`,a=`M8.8,4h-1.6v1.6h1.6zM8.8,7.2h-1.6v4.8h1.6zM8,0c4.41828,0 8,3.58172 8,8c0,4.41828 -3.58172,8 -8,8c-4.41828,0 -8,-3.58172 -8,-8c0,-4.41828 3.58172,-8 8,-8`,o=`M11.395,10.262l-2.262,-2.262l2.262,-2.262l-1.132,-1.132l-2.262,2.262l-2.263,-2.262l-1.131,1.132l2.262,2.262l-2.262,2.262l1.131,1.132l2.263,-2.262l2.262,2.262zM13.659,2.343c3.12218,3.12514 3.12218,8.18886 0,11.314c-2.28834,2.28863 -5.73017,2.97305 -8.72,1.734c-2.99134,-1.23749 -4.94222,-4.15558 -4.94244,-7.39278c-0.00022,-3.2372 1.95027,-6.15555 4.94143,-7.39345c2.99117,-1.2379 6.43353,-0.55139 8.72101,1.73923`,s=`Uh oh!`,c=`Something went wrong, please try again. If the error continues, please contact support.`,l=e=>`Doesn’t match. Type ${e} exactly, including capitalization.`;function u(){let e;return{promise:new Promise(t=>{e=t}),resolve:e}}function d(e){return typeof(e!==null&&(typeof e==`object`||typeof e==`function`)?e.then:void 0)==`function`}function f({onCancel:f,onConfirm:p,cancelButton:m=`Cancel`,confirmButton:h=`Okay`,confirmation:g,content:_,hideCancel:v=!1,title:y,type:b=`warning`}){let x=document.createElement(`dialog`);x.className=`pco-sweetest-alert`,document.body.appendChild(x);let S=(0,e.createRoot)(x),C=g?.match.trim()??``,w=C.length>0,T=!1,E=`idle`,D=``,O=!1,{promise:k,resolve:A}=u(),j=()=>{T||(T=!0,E=`idle`,A({isConfirmed:!1,isDismissed:!0}),S.unmount(),x.remove())},M=e=>{T||(A({isConfirmed:!1,isDismissed:!0}),j(),e&&f?.())},N=async e=>{E=`pending`,U();let t;try{t=await e}catch{if(T)return;E=`error`,U();return}T||(A({isConfirmed:!0,isDismissed:!1,value:t}),j())},P=()=>D.trim()===C,F=()=>{if(T||E!==`idle`||w&&!P())return;let e=p?.();if(!d(e)){A({isConfirmed:!0,isDismissed:!1}),j();return}N(e)},I=e=>{let t=P();D=e.target.value;let n=O&&D.trim()!==``&&!P(),r=P()!==t||n!==O;O=n,r&&U()},L=()=>{let e=D.trim()!==``&&!P();e!==O&&(O=e,U())},R=e=>{e.preventDefault(),F()},z=e=>{E===`pending`&&e.preventDefault()},B=()=>{T||E===`pending`||M(E!==`error`)},V=e=>{switch(e){case`success`:return r;case`error`:return o;case`info`:return a;case`danger`:case`warning`:return i}},H=()=>{let e=E===`error`,r=E===`pending`,i=e?`error`:b;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(`svg`,{className:`pco-sweetest-alert__icon pco-sweetest-alert--${i}`,width:`48`,height:`48`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,n.jsx)(`path`,{d:V(i)})}),(0,n.jsx)(`h2`,{className:`pco-sweetest-alert__title`,children:e?s:y}),(0,n.jsx)(`div`,{className:`pco-sweetest-alert__body`,children:e?(0,n.jsx)(`p`,{children:c}):typeof _==`string`?(0,n.jsx)(`p`,{children:_}):_}),!e&&w&&(0,n.jsx)(`form`,{className:`pco-sweetest-alert__confirmation`,onSubmit:R,children:(0,n.jsx)(t.Input,{autoCapitalize:`none`,autoComplete:`off`,autoFocus:!0,description:O?l(C):g.description,disabled:r,invalid:O,label:g.label??(0,n.jsxs)(n.Fragment,{children:[`Type `,(0,n.jsx)(`strong`,{children:C}),` to confirm`]}),onBlur:L,onChange:I,spellCheck:!1})}),(0,n.jsxs)(`div`,{className:`pco-sweetest-alert__actions`,children:[!e&&!v&&(0,n.jsx)(t.Button,{label:m,kind:`ghost`,disabled:r,onClick:()=>M(!0)}),(0,n.jsx)(t.Button,{label:e?`Okay`:h,kind:!e&&b===`danger`?`delete`:`primary`,loading:r,disabled:!e&&w&&!P(),onClick:e?()=>M(!1):F})]})]})},U=()=>S.render(H());return U(),x.showModal(),x.addEventListener(`cancel`,z),x.addEventListener(`close`,B),Object.assign(k,{show:()=>x.showModal(),close:()=>{E!==`pending`&&x.close()},cleanup:j})}exports.SweetestAlert=f;
|
package/dist/index.js
CHANGED
|
@@ -16,60 +16,60 @@ function p() {
|
|
|
16
16
|
function m(e) {
|
|
17
17
|
return typeof (e !== null && (typeof e == "object" || typeof e == "function") ? e.then : void 0) == "function";
|
|
18
18
|
}
|
|
19
|
-
function h({ onCancel: h, onConfirm: g,
|
|
20
|
-
let
|
|
21
|
-
|
|
22
|
-
let
|
|
23
|
-
|
|
19
|
+
function h({ onCancel: h, onConfirm: g, cancelButton: _ = "Cancel", confirmButton: v = "Okay", confirmation: y, content: b, hideCancel: x = !1, title: S, type: C = "warning" }) {
|
|
20
|
+
let w = document.createElement("dialog");
|
|
21
|
+
w.className = "pco-sweetest-alert", document.body.appendChild(w);
|
|
22
|
+
let T = e(w), E = y?.match.trim() ?? "", D = E.length > 0, O = !1, k = "idle", A = "", j = !1, { promise: M, resolve: N } = p(), P = () => {
|
|
23
|
+
O || (O = !0, k = "idle", N({
|
|
24
24
|
isConfirmed: !1,
|
|
25
25
|
isDismissed: !0
|
|
26
|
-
}),
|
|
27
|
-
},
|
|
28
|
-
|
|
26
|
+
}), T.unmount(), w.remove());
|
|
27
|
+
}, F = (e) => {
|
|
28
|
+
O || (N({
|
|
29
29
|
isConfirmed: !1,
|
|
30
30
|
isDismissed: !0
|
|
31
|
-
}),
|
|
32
|
-
},
|
|
33
|
-
|
|
31
|
+
}), P(), e && h?.());
|
|
32
|
+
}, I = async (e) => {
|
|
33
|
+
k = "pending", K();
|
|
34
34
|
let t;
|
|
35
35
|
try {
|
|
36
36
|
t = await e;
|
|
37
37
|
} catch {
|
|
38
|
-
if (
|
|
39
|
-
|
|
38
|
+
if (O) return;
|
|
39
|
+
k = "error", K();
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
O || (N({
|
|
43
43
|
isConfirmed: !0,
|
|
44
44
|
isDismissed: !1,
|
|
45
45
|
value: t
|
|
46
|
-
}),
|
|
47
|
-
},
|
|
48
|
-
if (
|
|
46
|
+
}), P());
|
|
47
|
+
}, L = () => A.trim() === E, R = () => {
|
|
48
|
+
if (O || k !== "idle" || D && !L()) return;
|
|
49
49
|
let e = g?.();
|
|
50
50
|
if (!m(e)) {
|
|
51
|
-
|
|
51
|
+
N({
|
|
52
52
|
isConfirmed: !0,
|
|
53
53
|
isDismissed: !1
|
|
54
|
-
}),
|
|
54
|
+
}), P();
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
|
-
|
|
58
|
-
},
|
|
59
|
-
let t =
|
|
60
|
-
|
|
61
|
-
let n =
|
|
62
|
-
|
|
63
|
-
},
|
|
64
|
-
let e =
|
|
65
|
-
e !==
|
|
66
|
-
}, B = (e) => {
|
|
67
|
-
e.preventDefault(), L();
|
|
57
|
+
I(e);
|
|
58
|
+
}, z = (e) => {
|
|
59
|
+
let t = L();
|
|
60
|
+
A = e.target.value;
|
|
61
|
+
let n = j && A.trim() !== "" && !L(), r = L() !== t || n !== j;
|
|
62
|
+
j = n, r && K();
|
|
63
|
+
}, B = () => {
|
|
64
|
+
let e = A.trim() !== "" && !L();
|
|
65
|
+
e !== j && (j = e, K());
|
|
68
66
|
}, V = (e) => {
|
|
69
|
-
|
|
70
|
-
}, H = () => {
|
|
71
|
-
|
|
72
|
-
}, U = (
|
|
67
|
+
e.preventDefault(), R();
|
|
68
|
+
}, H = (e) => {
|
|
69
|
+
k === "pending" && e.preventDefault();
|
|
70
|
+
}, U = () => {
|
|
71
|
+
O || k === "pending" || F(k !== "error");
|
|
72
|
+
}, W = (e) => {
|
|
73
73
|
switch (e) {
|
|
74
74
|
case "success": return o;
|
|
75
75
|
case "error": return l;
|
|
@@ -77,8 +77,8 @@ function h({ onCancel: h, onConfirm: g, confirmButton: _ = "Okay", confirmation:
|
|
|
77
77
|
case "danger":
|
|
78
78
|
case "warning": return s;
|
|
79
79
|
}
|
|
80
|
-
},
|
|
81
|
-
let e =
|
|
80
|
+
}, G = () => {
|
|
81
|
+
let e = k === "error", o = k === "pending", s = e ? "error" : C;
|
|
82
82
|
return /* @__PURE__ */ a(r, { children: [
|
|
83
83
|
/* @__PURE__ */ i("svg", {
|
|
84
84
|
className: `pco-sweetest-alert__icon pco-sweetest-alert--${s}`,
|
|
@@ -86,59 +86,59 @@ function h({ onCancel: h, onConfirm: g, confirmButton: _ = "Okay", confirmation:
|
|
|
86
86
|
height: "48",
|
|
87
87
|
viewBox: "0 0 16 16",
|
|
88
88
|
"aria-hidden": "true",
|
|
89
|
-
children: /* @__PURE__ */ i("path", { d:
|
|
89
|
+
children: /* @__PURE__ */ i("path", { d: W(s) })
|
|
90
90
|
}),
|
|
91
91
|
/* @__PURE__ */ i("h2", {
|
|
92
92
|
className: "pco-sweetest-alert__title",
|
|
93
|
-
children: e ? u :
|
|
93
|
+
children: e ? u : S
|
|
94
94
|
}),
|
|
95
95
|
/* @__PURE__ */ i("div", {
|
|
96
96
|
className: "pco-sweetest-alert__body",
|
|
97
|
-
children: e ? /* @__PURE__ */ i("p", { children: d }) : typeof
|
|
97
|
+
children: e ? /* @__PURE__ */ i("p", { children: d }) : typeof b == "string" ? /* @__PURE__ */ i("p", { children: b }) : b
|
|
98
98
|
}),
|
|
99
|
-
!e &&
|
|
99
|
+
!e && D && /* @__PURE__ */ i("form", {
|
|
100
100
|
className: "pco-sweetest-alert__confirmation",
|
|
101
|
-
onSubmit:
|
|
101
|
+
onSubmit: V,
|
|
102
102
|
children: /* @__PURE__ */ i(n, {
|
|
103
103
|
autoCapitalize: "none",
|
|
104
104
|
autoComplete: "off",
|
|
105
105
|
autoFocus: !0,
|
|
106
|
-
description:
|
|
106
|
+
description: j ? f(E) : y.description,
|
|
107
107
|
disabled: o,
|
|
108
|
-
invalid:
|
|
109
|
-
label:
|
|
108
|
+
invalid: j,
|
|
109
|
+
label: y.label ?? /* @__PURE__ */ a(r, { children: [
|
|
110
110
|
"Type ",
|
|
111
|
-
/* @__PURE__ */ i("strong", { children:
|
|
111
|
+
/* @__PURE__ */ i("strong", { children: E }),
|
|
112
112
|
" to confirm"
|
|
113
113
|
] }),
|
|
114
|
-
onBlur:
|
|
115
|
-
onChange:
|
|
114
|
+
onBlur: B,
|
|
115
|
+
onChange: z,
|
|
116
116
|
spellCheck: !1
|
|
117
117
|
})
|
|
118
118
|
}),
|
|
119
119
|
/* @__PURE__ */ a("div", {
|
|
120
120
|
className: "pco-sweetest-alert__actions",
|
|
121
|
-
children: [!e && !
|
|
122
|
-
label:
|
|
121
|
+
children: [!e && !x && /* @__PURE__ */ i(t, {
|
|
122
|
+
label: _,
|
|
123
123
|
kind: "ghost",
|
|
124
124
|
disabled: o,
|
|
125
|
-
onClick: () =>
|
|
125
|
+
onClick: () => F(!0)
|
|
126
126
|
}), /* @__PURE__ */ i(t, {
|
|
127
|
-
label: e ? "Okay" :
|
|
128
|
-
kind: !e &&
|
|
127
|
+
label: e ? "Okay" : v,
|
|
128
|
+
kind: !e && C === "danger" ? "delete" : "primary",
|
|
129
129
|
loading: o,
|
|
130
|
-
disabled: !e &&
|
|
131
|
-
onClick: e ? () =>
|
|
130
|
+
disabled: !e && D && !L(),
|
|
131
|
+
onClick: e ? () => F(!1) : R
|
|
132
132
|
})]
|
|
133
133
|
})
|
|
134
134
|
] });
|
|
135
|
-
},
|
|
136
|
-
return
|
|
137
|
-
show: () =>
|
|
135
|
+
}, K = () => T.render(G());
|
|
136
|
+
return K(), w.showModal(), w.addEventListener("cancel", H), w.addEventListener("close", U), Object.assign(M, {
|
|
137
|
+
show: () => w.showModal(),
|
|
138
138
|
close: () => {
|
|
139
|
-
|
|
139
|
+
k !== "pending" && w.close();
|
|
140
140
|
},
|
|
141
|
-
cleanup:
|
|
141
|
+
cleanup: P
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
144
|
//#endregion
|
package/dist/style.css
CHANGED
package/dist/sweetest_alert.d.ts
CHANGED
|
@@ -74,6 +74,19 @@ type AlertOptions = {
|
|
|
74
74
|
onConfirm?: () => unknown;
|
|
75
75
|
/** Text for the confirm button. Defaults to `"Okay"`. */
|
|
76
76
|
confirmButton?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Text for the cancel button. Defaults to `"Cancel"`.
|
|
79
|
+
*
|
|
80
|
+
* This is an escape hatch, not a first choice. A consistent "Cancel" across
|
|
81
|
+
* every dialog is what lets people recognize and dismiss one without
|
|
82
|
+
* reading it closely. Reach for this only when a generic "Cancel" reads
|
|
83
|
+
* awkwardly next to a customized `confirmButton` — e.g. on "Are you sure
|
|
84
|
+
* you want to cancel this registration?", pairing `confirmButton: "Yes,
|
|
85
|
+
* cancel it"` leaves the default `cancelButton: "Cancel"` ambiguous: does
|
|
86
|
+
* clicking it cancel the registration, or cancel out of this dialog?
|
|
87
|
+
* Leave it unset otherwise.
|
|
88
|
+
*/
|
|
89
|
+
cancelButton?: string;
|
|
77
90
|
/** Required. The body content explaining the alert. Accepts a string or React node. */
|
|
78
91
|
content: string | React.ReactNode;
|
|
79
92
|
/** When `true`, hides the cancel button for simple notifications. Defaults to `false`. */
|
|
@@ -137,7 +150,7 @@ type AlertOptions = {
|
|
|
137
150
|
* - `cleanup()` — unmounts the React root and removes the dialog from the
|
|
138
151
|
* DOM immediately, regardless of pending state
|
|
139
152
|
*/
|
|
140
|
-
export declare function SweetestAlert({ onCancel, onConfirm, confirmButton, confirmation, content, hideCancel, title, type, }: AlertOptions): Promise<AlertResult> & {
|
|
153
|
+
export declare function SweetestAlert({ onCancel, onConfirm, cancelButton, confirmButton, confirmation, content, hideCancel, title, type, }: AlertOptions): Promise<AlertResult> & {
|
|
141
154
|
show: () => void;
|
|
142
155
|
close: () => void;
|
|
143
156
|
cleanup: () => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planningcenter/sweetest-alert",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "The sweetest alert ever",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"packageManager": "yarn@4.14.1+sha512.64df448055b2d37ba269d7db535a469b8da93f8ef1140c25fd7a83c00a8fbaacb214ca0e02553b92a2c54cef78bb67d0b4817fab02001df0e24fac0faccc3b42",
|