53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
|
import { ComponentChildren, h, VNode } from "preact";
|
||
|
|
||
|
export interface ConfirmModelProps {
|
||
|
active?: boolean;
|
||
|
description?: string;
|
||
|
onCancel?: () => void;
|
||
|
onConfirm?: () => void;
|
||
|
label?: string;
|
||
|
cancelLabel?: string;
|
||
|
children?: ComponentChildren;
|
||
|
danger?: boolean;
|
||
|
disabled?: boolean;
|
||
|
}
|
||
|
|
||
|
export function ConfirmModal({
|
||
|
active, description, onCancel, onConfirm, children, danger, disabled, label = "Confirm", cancelLabel = "Dismiss"
|
||
|
}: ConfirmModelProps): VNode {
|
||
|
return (
|
||
|
<div class={active ? "modal is-active" : "modal"}>
|
||
|
<div class="modal-background " onClick={onCancel} />
|
||
|
<div class="modal-card" style={{ maxWidth: 700 }}>
|
||
|
<header class="modal-card-head">
|
||
|
{!description ? null : (
|
||
|
<p class="modal-card-title">
|
||
|
<b>{description}</b>
|
||
|
</p>
|
||
|
)}
|
||
|
<button class="delete " aria-label="close" onClick={onCancel} />
|
||
|
</header>
|
||
|
<section class="modal-card-body">{children}</section>
|
||
|
<footer class="modal-card-foot">
|
||
|
<button class="button" onClick={onCancel}>
|
||
|
{cancelLabel}
|
||
|
</button>
|
||
|
<div class="buttons is-right" style={{ width: "100%" }}>
|
||
|
<button
|
||
|
class={danger ? "button is-danger " : "button is-info "}
|
||
|
disabled={disabled}
|
||
|
onClick={onConfirm}
|
||
|
>
|
||
|
{label}
|
||
|
</button>
|
||
|
</div>
|
||
|
</footer>
|
||
|
</div>
|
||
|
<button
|
||
|
class="modal-close is-large "
|
||
|
aria-label="close"
|
||
|
onClick={onCancel} />
|
||
|
</div>
|
||
|
);
|
||
|
}
|