react-confirm-animated-dialog-dk 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/README.md ADDED
@@ -0,0 +1 @@
1
+ "# confirm-modal"
package/dist/index.css ADDED
@@ -0,0 +1,54 @@
1
+ /* src/styles.css */
2
+ .cm-overlay {
3
+ position: fixed;
4
+ inset: 0;
5
+ background: rgba(0, 0, 0, 0.6);
6
+ display: flex;
7
+ align-items: center;
8
+ justify-content: center;
9
+ z-index: 9999;
10
+ }
11
+ .cm-modal {
12
+ background: white;
13
+ max-width: 420px;
14
+ width: 100%;
15
+ padding: 24px;
16
+ border-radius: 12px;
17
+ }
18
+ .cm-footer {
19
+ display: flex;
20
+ gap: 12px;
21
+ margin-top: 20px;
22
+ }
23
+ .cm-button {
24
+ flex: 1;
25
+ height: 40px;
26
+ border: none;
27
+ background: #111;
28
+ color: white;
29
+ cursor: pointer;
30
+ border-radius: 8px;
31
+ position: relative;
32
+ }
33
+ .cm-outline {
34
+ background: white;
35
+ border: 1px solid #ccc;
36
+ color: #333;
37
+ }
38
+ .cm-delete {
39
+ background: #e53935;
40
+ }
41
+ .cm-spinner {
42
+ position: absolute;
43
+ width: 16px;
44
+ height: 16px;
45
+ border: 2px solid white;
46
+ border-top: 2px solid transparent;
47
+ border-radius: 50%;
48
+ animation: spin .7s linear infinite;
49
+ }
50
+ @keyframes spin {
51
+ to {
52
+ transform: rotate(360deg);
53
+ }
54
+ }
package/dist/index.js ADDED
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ ConfirmModal: () => ConfirmModal
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // src/ConfirmModal.tsx
28
+ var import_react = require("react");
29
+ var import_jsx_runtime = require("react/jsx-runtime");
30
+ function AnimatedButton({
31
+ label,
32
+ isLoading,
33
+ onClick,
34
+ variant
35
+ }) {
36
+ const letters = label.split("");
37
+ const [isDropping, setIsDropping] = (0, import_react.useState)(false);
38
+ const [droppedCount, setDroppedCount] = (0, import_react.useState)(0);
39
+ const reset = (0, import_react.useCallback)(() => {
40
+ setIsDropping(false);
41
+ setDroppedCount(0);
42
+ }, []);
43
+ (0, import_react.useEffect)(() => {
44
+ if (isLoading && !isDropping) setIsDropping(true);
45
+ if (!isLoading && isDropping) reset();
46
+ }, [isLoading, isDropping, reset]);
47
+ (0, import_react.useEffect)(() => {
48
+ if (!isDropping) return;
49
+ if (droppedCount < letters.length) {
50
+ const t = setTimeout(() => setDroppedCount((c) => c + 1), 100);
51
+ return () => clearTimeout(t);
52
+ }
53
+ }, [isDropping, droppedCount, letters.length]);
54
+ const allDropped = isDropping && droppedCount >= letters.length;
55
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
56
+ "button",
57
+ {
58
+ className: `cm-button ${variant === "delete" ? "cm-delete" : ""}`,
59
+ onClick,
60
+ disabled: isLoading,
61
+ children: [
62
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "cm-button-content", children: letters.map((letter, i) => {
63
+ const gone = isDropping && i < droppedCount;
64
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
65
+ "span",
66
+ {
67
+ style: {
68
+ transform: gone ? "translateY(20px) rotate(10deg) scale(0.3)" : "none",
69
+ opacity: gone ? 0 : 1,
70
+ transition: "all 0.2s ease"
71
+ },
72
+ children: letter
73
+ },
74
+ i
75
+ );
76
+ }) }),
77
+ allDropped && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "cm-spinner" })
78
+ ]
79
+ }
80
+ );
81
+ }
82
+ function ConfirmModal({
83
+ open,
84
+ title = "Are you sure?",
85
+ description,
86
+ confirmLabel = "Confirm",
87
+ cancelLabel = "Cancel",
88
+ onConfirm,
89
+ onCancel,
90
+ isLoading = false,
91
+ type = "default"
92
+ }) {
93
+ if (!open) return null;
94
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "cm-overlay", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "cm-modal", children: [
95
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "cm-header", children: [
96
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { children: title }),
97
+ description && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: description })
98
+ ] }),
99
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "cm-footer", children: [
100
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
101
+ "button",
102
+ {
103
+ className: "cm-button cm-outline",
104
+ onClick: onCancel,
105
+ disabled: isLoading,
106
+ children: cancelLabel
107
+ }
108
+ ),
109
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
110
+ AnimatedButton,
111
+ {
112
+ label: confirmLabel,
113
+ isLoading,
114
+ onClick: onConfirm,
115
+ variant: type === "delete" ? "delete" : "default"
116
+ }
117
+ )
118
+ ] })
119
+ ] }) });
120
+ }
121
+ // Annotate the CommonJS export names for ESM import in node:
122
+ 0 && (module.exports = {
123
+ ConfirmModal
124
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,97 @@
1
+ // src/ConfirmModal.tsx
2
+ import { useEffect, useState, useCallback } from "react";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ function AnimatedButton({
5
+ label,
6
+ isLoading,
7
+ onClick,
8
+ variant
9
+ }) {
10
+ const letters = label.split("");
11
+ const [isDropping, setIsDropping] = useState(false);
12
+ const [droppedCount, setDroppedCount] = useState(0);
13
+ const reset = useCallback(() => {
14
+ setIsDropping(false);
15
+ setDroppedCount(0);
16
+ }, []);
17
+ useEffect(() => {
18
+ if (isLoading && !isDropping) setIsDropping(true);
19
+ if (!isLoading && isDropping) reset();
20
+ }, [isLoading, isDropping, reset]);
21
+ useEffect(() => {
22
+ if (!isDropping) return;
23
+ if (droppedCount < letters.length) {
24
+ const t = setTimeout(() => setDroppedCount((c) => c + 1), 100);
25
+ return () => clearTimeout(t);
26
+ }
27
+ }, [isDropping, droppedCount, letters.length]);
28
+ const allDropped = isDropping && droppedCount >= letters.length;
29
+ return /* @__PURE__ */ jsxs(
30
+ "button",
31
+ {
32
+ className: `cm-button ${variant === "delete" ? "cm-delete" : ""}`,
33
+ onClick,
34
+ disabled: isLoading,
35
+ children: [
36
+ /* @__PURE__ */ jsx("span", { className: "cm-button-content", children: letters.map((letter, i) => {
37
+ const gone = isDropping && i < droppedCount;
38
+ return /* @__PURE__ */ jsx(
39
+ "span",
40
+ {
41
+ style: {
42
+ transform: gone ? "translateY(20px) rotate(10deg) scale(0.3)" : "none",
43
+ opacity: gone ? 0 : 1,
44
+ transition: "all 0.2s ease"
45
+ },
46
+ children: letter
47
+ },
48
+ i
49
+ );
50
+ }) }),
51
+ allDropped && /* @__PURE__ */ jsx("div", { className: "cm-spinner" })
52
+ ]
53
+ }
54
+ );
55
+ }
56
+ function ConfirmModal({
57
+ open,
58
+ title = "Are you sure?",
59
+ description,
60
+ confirmLabel = "Confirm",
61
+ cancelLabel = "Cancel",
62
+ onConfirm,
63
+ onCancel,
64
+ isLoading = false,
65
+ type = "default"
66
+ }) {
67
+ if (!open) return null;
68
+ return /* @__PURE__ */ jsx("div", { className: "cm-overlay", children: /* @__PURE__ */ jsxs("div", { className: "cm-modal", children: [
69
+ /* @__PURE__ */ jsxs("div", { className: "cm-header", children: [
70
+ /* @__PURE__ */ jsx("h3", { children: title }),
71
+ description && /* @__PURE__ */ jsx("p", { children: description })
72
+ ] }),
73
+ /* @__PURE__ */ jsxs("div", { className: "cm-footer", children: [
74
+ /* @__PURE__ */ jsx(
75
+ "button",
76
+ {
77
+ className: "cm-button cm-outline",
78
+ onClick: onCancel,
79
+ disabled: isLoading,
80
+ children: cancelLabel
81
+ }
82
+ ),
83
+ /* @__PURE__ */ jsx(
84
+ AnimatedButton,
85
+ {
86
+ label: confirmLabel,
87
+ isLoading,
88
+ onClick: onConfirm,
89
+ variant: type === "delete" ? "delete" : "default"
90
+ }
91
+ )
92
+ ] })
93
+ ] }) });
94
+ }
95
+ export {
96
+ ConfirmModal
97
+ };
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "react-confirm-animated-dialog-dk",
3
+ "version": "1.0.0",
4
+ "main": "dist/index.js",
5
+ "module": "dist/index.mjs",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsup"
12
+ },
13
+ "peerDependencies": {
14
+ "react": ">=18"
15
+ },
16
+ "devDependencies": {
17
+ "@types/react": "^19.2.14",
18
+ "@types/react-dom": "^19.2.3",
19
+ "tsup": "^8.5.1",
20
+ "typescript": "^5.9.3"
21
+ }
22
+ }