wallet-core/packages/anastasis-webui/src/pages/home/ConfirmModal.tsx

85 lines
2.5 KiB
TypeScript
Raw Normal View History

2022-06-06 16:46:49 +02:00
/*
This file is part of GNU Anastasis
(C) 2021-2022 Anastasis SARL
GNU Anastasis is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
GNU Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with
GNU Anastasis; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
2021-11-10 22:10:45 +01:00
import { ComponentChildren, h, VNode } from "preact";
2022-06-06 05:54:55 +02:00
import { AsyncButton } from "../../components/AsyncButton.js";
2021-11-10 22:10:45 +01:00
export interface ConfirmModelProps {
active?: boolean;
description?: string;
onCancel?: () => void;
onConfirm?: () => Promise<void>;
2021-11-10 22:10:45 +01:00
label?: string;
cancelLabel?: string;
children?: ComponentChildren;
danger?: boolean;
disabled?: boolean;
}
export function ConfirmModal({
2022-06-06 05:10:38 +02:00
active,
description,
onCancel,
onConfirm,
children,
danger,
disabled,
label = "Confirm",
cancelLabel = "Dismiss",
2021-11-10 22:10:45 +01:00
}: ConfirmModelProps): VNode {
return (
2022-06-06 05:10:38 +02:00
<div class={active ? "modal is-active" : "modal"}>
2021-11-10 22:10:45 +01:00
<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>
2022-06-06 05:10:38 +02:00
<div
class="buttons is-right"
style={{ width: "100%" }}
onKeyDown={(e) => {
if (e.key === "Escape" && onCancel) onCancel();
}}
>
<AsyncButton
2021-11-12 17:12:27 +01:00
grabFocus
2021-11-10 22:10:45 +01:00
class={danger ? "button is-danger " : "button is-info "}
disabled={disabled}
onClick={onConfirm}
>
{label}
</AsyncButton>
2021-11-10 22:10:45 +01:00
</div>
</footer>
</div>
<button
class="modal-close is-large "
aria-label="close"
2022-06-06 05:10:38 +02:00
onClick={onCancel}
/>
2021-11-10 22:10:45 +01:00
</div>
);
}