Spaces:
Sleeping
Sleeping
Andrew
commited on
Commit
·
e522062
1
Parent(s):
f21352e
feat(ui): add reusable confirmation modal component
Browse files
src/lib/components/ConfirmModal.svelte
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import Modal from "./Modal.svelte";
|
| 3 |
+
import CarbonWarning from "~icons/carbon/warning";
|
| 4 |
+
|
| 5 |
+
interface Props {
|
| 6 |
+
title: string;
|
| 7 |
+
message: string;
|
| 8 |
+
confirmText?: string;
|
| 9 |
+
cancelText?: string;
|
| 10 |
+
variant?: "danger" | "warning" | "info";
|
| 11 |
+
onConfirm: () => void;
|
| 12 |
+
onCancel: () => void;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
let {
|
| 16 |
+
title,
|
| 17 |
+
message,
|
| 18 |
+
confirmText = "Confirm",
|
| 19 |
+
cancelText = "Cancel",
|
| 20 |
+
variant = "warning",
|
| 21 |
+
onConfirm,
|
| 22 |
+
onCancel,
|
| 23 |
+
}: Props = $props();
|
| 24 |
+
|
| 25 |
+
const variantStyles = {
|
| 26 |
+
danger: "bg-red-600 hover:bg-red-700 dark:bg-red-700 dark:hover:bg-red-800",
|
| 27 |
+
warning: "bg-yellow-600 hover:bg-yellow-700 dark:bg-yellow-700 dark:hover:bg-yellow-800",
|
| 28 |
+
info: "bg-blue-600 hover:bg-blue-700 dark:bg-blue-700 dark:hover:bg-blue-800",
|
| 29 |
+
};
|
| 30 |
+
|
| 31 |
+
const iconColors = {
|
| 32 |
+
danger: "text-red-600 dark:text-red-500",
|
| 33 |
+
warning: "text-yellow-600 dark:text-yellow-500",
|
| 34 |
+
info: "text-blue-600 dark:text-blue-500",
|
| 35 |
+
};
|
| 36 |
+
</script>
|
| 37 |
+
|
| 38 |
+
<Modal width="max-w-md" closeOnBackdrop={false} onclose={onCancel}>
|
| 39 |
+
<div class="p-6">
|
| 40 |
+
<!-- Icon and Title -->
|
| 41 |
+
<div class="mb-4 flex items-start gap-4">
|
| 42 |
+
<div
|
| 43 |
+
class={[
|
| 44 |
+
"flex size-12 shrink-0 items-center justify-center rounded-full",
|
| 45 |
+
variant === "danger"
|
| 46 |
+
? "bg-red-100 dark:bg-red-900/30"
|
| 47 |
+
: variant === "warning"
|
| 48 |
+
? "bg-yellow-100 dark:bg-yellow-900/30"
|
| 49 |
+
: "bg-blue-100 dark:bg-blue-900/30",
|
| 50 |
+
]}
|
| 51 |
+
>
|
| 52 |
+
<CarbonWarning class={["size-6", iconColors[variant]]} />
|
| 53 |
+
</div>
|
| 54 |
+
<div class="flex-1">
|
| 55 |
+
<h3 class="text-lg font-semibold text-gray-900 dark:text-gray-100">
|
| 56 |
+
{title}
|
| 57 |
+
</h3>
|
| 58 |
+
</div>
|
| 59 |
+
</div>
|
| 60 |
+
|
| 61 |
+
<!-- Message -->
|
| 62 |
+
<p class="mb-6 text-sm text-gray-600 dark:text-gray-400">
|
| 63 |
+
{message}
|
| 64 |
+
</p>
|
| 65 |
+
|
| 66 |
+
<!-- Actions -->
|
| 67 |
+
<div class="flex gap-3 justify-end">
|
| 68 |
+
<button
|
| 69 |
+
onclick={onCancel}
|
| 70 |
+
class="rounded-lg px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-700 transition-colors"
|
| 71 |
+
>
|
| 72 |
+
{cancelText}
|
| 73 |
+
</button>
|
| 74 |
+
<button
|
| 75 |
+
onclick={onConfirm}
|
| 76 |
+
class={[
|
| 77 |
+
"rounded-lg px-4 py-2 text-sm font-medium text-white transition-colors",
|
| 78 |
+
variantStyles[variant],
|
| 79 |
+
]}
|
| 80 |
+
>
|
| 81 |
+
{confirmText}
|
| 82 |
+
</button>
|
| 83 |
+
</div>
|
| 84 |
+
</div>
|
| 85 |
+
</Modal>
|
| 86 |
+
|