2021-03-31 11:59:07 +02:00
|
|
|
<script>
|
2021-04-08 15:46:34 +02:00
|
|
|
import "@spectrum-css/divider/dist/index-vars.css"
|
|
|
|
|
|
|
|
import { getContext } from "svelte"
|
2021-03-31 11:59:07 +02:00
|
|
|
import Button from "../Button/Button.svelte"
|
|
|
|
import Icon from "../Icons/Icon.svelte"
|
|
|
|
import Context from "../context"
|
|
|
|
|
|
|
|
export let title = undefined
|
|
|
|
export let cancelText = "Cancel"
|
|
|
|
export let confirmText = "Confirm"
|
|
|
|
export let showCancelButton = true
|
|
|
|
export let showConfirmButton = true
|
|
|
|
export let showCloseIcon = true
|
|
|
|
export let onConfirm = undefined
|
|
|
|
export let disabled = false
|
|
|
|
|
|
|
|
const { hide } = getContext(Context.Modal)
|
|
|
|
let loading = false
|
|
|
|
$: confirmDisabled = disabled || loading
|
|
|
|
|
|
|
|
async function confirm() {
|
|
|
|
loading = true
|
|
|
|
if (!onConfirm || (await onConfirm()) !== false) {
|
|
|
|
hide()
|
|
|
|
}
|
|
|
|
loading = false
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2021-04-08 16:05:31 +02:00
|
|
|
<div class="spectrum-Dialog spectrum-Dialog--medium" role="dialog" tabindex="-1" aria-modal="true">
|
2021-04-08 15:46:34 +02:00
|
|
|
<div class="spectrum-Dialog-grid">
|
|
|
|
<h1 class="spectrum-Dialog-heading">{title}</h1>
|
2021-04-08 16:05:31 +02:00
|
|
|
<hr class="spectrum-Divider spectrum-Divider--sizeS spectrum-Divider--horizontal spectrum-Dialog-divider">
|
|
|
|
|
|
|
|
<!-- TODO: Remove content-grid class once Layout components are in bbui -->
|
|
|
|
<section class="spectrum-Dialog-content content-grid">
|
2021-04-08 15:46:34 +02:00
|
|
|
<slot />
|
|
|
|
</section>
|
|
|
|
{#if showCancelButton || showConfirmButton}
|
|
|
|
<div class="spectrum-ButtonGroup spectrum-Dialog-buttonGroup spectrum-Dialog-buttonGroup--noFooter">
|
|
|
|
<footer class="footer-content">
|
|
|
|
<slot name="footer" />
|
|
|
|
</footer>
|
|
|
|
<div class="buttons">
|
|
|
|
{#if showCancelButton}
|
|
|
|
<Button secondary on:click={hide}>{cancelText}</Button>
|
|
|
|
{/if}
|
|
|
|
{#if showConfirmButton}
|
|
|
|
<Button
|
|
|
|
primary
|
|
|
|
{...$$restProps}
|
|
|
|
disabled={confirmDisabled}
|
|
|
|
on:click={confirm}>
|
|
|
|
{confirmText}
|
|
|
|
</Button>
|
|
|
|
{/if}
|
|
|
|
</div>
|
2021-03-31 11:59:07 +02:00
|
|
|
</div>
|
2021-04-08 15:46:34 +02:00
|
|
|
{/if}
|
|
|
|
{#if showCloseIcon}
|
|
|
|
<div class="close-icon" on:click={hide}>
|
|
|
|
<Icon name="closeline" />
|
2021-03-31 11:59:07 +02:00
|
|
|
</div>
|
2021-04-08 15:46:34 +02:00
|
|
|
{/if}
|
|
|
|
</div>
|
2021-03-31 11:59:07 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
2021-04-08 15:46:34 +02:00
|
|
|
<style>
|
2021-04-08 16:05:31 +02:00
|
|
|
.content-grid {
|
|
|
|
display: grid;
|
|
|
|
position: relative;
|
|
|
|
gap: var(--spacing-xl);
|
|
|
|
color: var(--ink);
|
|
|
|
}
|
|
|
|
|
|
|
|
h1 {
|
|
|
|
font-weight: normal;
|
|
|
|
}
|
2021-03-31 11:59:07 +02:00
|
|
|
.close-icon {
|
|
|
|
position: absolute;
|
2021-04-08 15:46:34 +02:00
|
|
|
top: 15px;
|
|
|
|
right: 15px;
|
2021-03-31 11:59:07 +02:00
|
|
|
color: var(--ink);
|
|
|
|
font-size: var(--font-size-m);
|
|
|
|
}
|
|
|
|
.close-icon:hover {
|
|
|
|
color: var(--grey-6);
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
.close-icon :global(svg) {
|
|
|
|
margin-right: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
footer {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: space-between;
|
|
|
|
align-items: center;
|
|
|
|
gap: var(--spacing-m);
|
|
|
|
}
|
|
|
|
|
|
|
|
.footer-content {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: flex-start;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.buttons {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: flex-end;
|
|
|
|
align-items: center;
|
|
|
|
gap: var(--spacing-m);
|
|
|
|
}
|
|
|
|
</style>
|