flotilla/src/lib/components/Confirm.svelte

58 lines
1.7 KiB
Svelte
Raw Normal View History

2024-10-11 00:49:42 +00:00
<script lang="ts">
2025-02-04 03:28:29 +00:00
import {preventDefault} from "@lib/html"
2025-09-10 22:26:39 +00:00
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
import AltArrowRight from "@assets/icons/alt-arrow-right.svg?dataurl"
2024-10-11 00:49:42 +00:00
import Icon from "@lib/components/Icon.svelte"
import Button from "@lib/components/Button.svelte"
2024-10-16 18:27:27 +00:00
import Spinner from "@lib/components/Spinner.svelte"
2024-10-11 00:49:42 +00:00
import ModalHeader from "@lib/components/ModalHeader.svelte"
2026-02-02 18:09:14 +00:00
import ModalTitle from "@lib/components/ModalTitle.svelte"
import ModalSubtitle from "@lib/components/ModalSubtitle.svelte"
2024-10-11 00:49:42 +00:00
import ModalFooter from "@lib/components/ModalFooter.svelte"
2026-01-30 22:14:12 +00:00
import Modal from "@lib/components/Modal.svelte"
import ModalBody from "@lib/components/ModalBody.svelte"
2024-10-11 00:49:42 +00:00
2025-02-04 00:37:14 +00:00
interface Props {
title?: string
subtitle?: string
message: any
confirm: any
}
const {subtitle = "", message, confirm, ...restProps}: Props = $props()
2024-10-11 00:49:42 +00:00
2025-02-04 00:37:14 +00:00
let loading = $state(false)
2024-10-16 18:27:27 +00:00
const tryConfirm = async () => {
loading = true
try {
await confirm()
} finally {
loading = false
}
}
2024-10-11 00:49:42 +00:00
const back = () => history.back()
</script>
2026-01-30 22:14:12 +00:00
<Modal tag="form" onsubmit={preventDefault(tryConfirm)}>
<ModalBody>
<ModalHeader>
2026-02-02 18:09:14 +00:00
<ModalTitle>{restProps.title || "Are you sure?"}</ModalTitle>
<ModalSubtitle>{subtitle}</ModalSubtitle>
2026-01-30 22:14:12 +00:00
</ModalHeader>
<p class="text-center">{message}</p>
</ModalBody>
2024-10-11 00:49:42 +00:00
<ModalFooter>
<Button class="button button-link" onclick={back}>
2025-09-10 22:26:39 +00:00
<Icon icon={AltArrowLeft} />
2024-10-11 00:49:42 +00:00
Go back
</Button>
<Button type="submit" class="button button-primary" disabled={loading}>
2024-10-16 18:27:27 +00:00
<Spinner {loading}>Confirm</Spinner>
2025-09-10 22:26:39 +00:00
<Icon icon={AltArrowRight} />
2024-10-11 00:49:42 +00:00
</Button>
</ModalFooter>
2026-01-30 22:14:12 +00:00
</Modal>