2020-10-02 13:00:17 +02:00
|
|
|
<script>
|
|
|
|
import { getContext } from "svelte"
|
|
|
|
import { Button } from "@budibase/bbui"
|
|
|
|
import { ContextKey } from "./context"
|
|
|
|
|
|
|
|
export let cancelText = "Cancel"
|
|
|
|
export let confirmText = "Confirm"
|
|
|
|
export let showCancelButton = true
|
|
|
|
export let showConfirmButton = true
|
|
|
|
export let onConfirm
|
|
|
|
|
|
|
|
const modalContext = getContext(ContextKey)
|
2020-10-02 20:09:19 +02:00
|
|
|
let loading = false
|
2020-10-02 13:00:17 +02:00
|
|
|
|
|
|
|
function hide() {
|
|
|
|
modalContext.hide()
|
|
|
|
}
|
|
|
|
|
|
|
|
async function confirm() {
|
2020-10-02 20:09:19 +02:00
|
|
|
loading = true
|
2020-10-02 13:00:17 +02:00
|
|
|
if (!onConfirm || (await onConfirm()) !== false) {
|
|
|
|
hide()
|
|
|
|
}
|
2020-10-02 20:09:19 +02:00
|
|
|
loading = false
|
2020-10-02 13:00:17 +02:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2020-10-02 20:09:19 +02:00
|
|
|
<footer>
|
|
|
|
<div class="content">
|
|
|
|
<slot />
|
|
|
|
</div>
|
|
|
|
<div class="buttons">
|
2020-10-02 13:00:17 +02:00
|
|
|
{#if showCancelButton}
|
|
|
|
<Button secondary on:click={hide}>{cancelText}</Button>
|
|
|
|
{/if}
|
|
|
|
{#if showConfirmButton}
|
2020-10-02 20:09:19 +02:00
|
|
|
<Button
|
|
|
|
primary
|
|
|
|
{...$$restProps}
|
|
|
|
disabled={$$props.disabled || loading}
|
|
|
|
on:click={confirm}>
|
|
|
|
{confirmText}
|
|
|
|
</Button>
|
2020-10-02 13:00:17 +02:00
|
|
|
{/if}
|
2020-10-02 20:09:19 +02:00
|
|
|
</div>
|
|
|
|
</footer>
|
2020-10-02 13:00:17 +02:00
|
|
|
|
|
|
|
<style>
|
|
|
|
footer {
|
2020-10-02 20:09:19 +02:00
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: space-between;
|
|
|
|
align-items: center;
|
|
|
|
gap: var(--spacing-m);
|
|
|
|
}
|
|
|
|
.buttons {
|
2020-10-02 13:00:17 +02:00
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: flex-end;
|
|
|
|
align-items: center;
|
|
|
|
gap: var(--spacing-m);
|
|
|
|
}
|
|
|
|
</style>
|