import { For, Show, createEffect, createSignal } from "solid-js" import Modal from "@/components/Modal" type ConfirmDialogProps = { open: boolean title: string description: string /** Optional bullet points shown in a warning box below the description */ details?: string[] confirmLabel: string busyLabel?: string busy?: boolean tone?: "danger" | "primary" onConfirm: () => void | Promise onClose: () => void } const TONE_STYLES: Record, string> = { danger: "bg-red-600 text-white hover:bg-red-700", primary: "bg-blue-600 text-white hover:bg-blue-700", } const DETAIL_BOX_STYLES: Record, string> = { danger: "border-amber-200 bg-amber-50 text-amber-800", primary: "border-blue-200 bg-blue-50 text-blue-800", } type ConfirmDialogSnapshot = { title: string description: string details?: string[] confirmLabel: string busyLabel?: string busy: boolean tone: NonNullable } export default function ConfirmDialog(props: ConfirmDialogProps) { const [snapshot, setSnapshot] = createSignal({ title: props.title, description: props.description, details: props.details ? [...props.details] : undefined, confirmLabel: props.confirmLabel, busyLabel: props.busyLabel, busy: props.busy ?? false, tone: props.tone ?? "primary", }) createEffect(() => { if (!props.open) return setSnapshot({ title: props.title, description: props.description, details: props.details ? [...props.details] : undefined, confirmLabel: props.confirmLabel, busyLabel: props.busyLabel, busy: props.busy ?? false, tone: props.tone ?? "primary", }) }) const content = () => props.open ? { title: props.title, description: props.description, details: props.details, confirmLabel: props.confirmLabel, busyLabel: props.busyLabel, busy: props.busy ?? false, tone: props.tone ?? "primary", } : snapshot() const tone = () => content().tone const confirmText = () => content().busy ? (content().busyLabel ?? content().confirmLabel) : content().confirmLabel function handleClose() { if (props.busy) return props.onClose() } function handleConfirm() { if (props.busy) return void props.onConfirm() } return (

{content().title}

{content().description}

0}>
    {(item) => (
  • {item}
  • )}
) }