2023-07-05 14:49:39 +02:00
|
|
|
<script context="module">
|
|
|
|
export const keepOpen = Symbol("keepOpen")
|
|
|
|
</script>
|
|
|
|
|
2021-03-31 11:59:07 +02:00
|
|
|
<script>
|
2021-04-16 10:02:16 +02:00
|
|
|
import "@spectrum-css/dialog/dist/index-vars.css"
|
2021-04-08 15:46:34 +02:00
|
|
|
import { getContext } from "svelte"
|
2021-03-31 11:59:07 +02:00
|
|
|
import Button from "../Button/Button.svelte"
|
2021-04-14 14:52:25 +02:00
|
|
|
import Divider from "../Divider/Divider.svelte"
|
2021-04-21 14:59:09 +02:00
|
|
|
import Icon from "../Icon/Icon.svelte"
|
2021-03-31 11:59:07 +02:00
|
|
|
import Context from "../context"
|
2022-03-23 13:43:20 +01:00
|
|
|
import ProgressCircle from "../ProgressCircle/ProgressCircle.svelte"
|
2021-03-31 11:59:07 +02:00
|
|
|
|
|
|
|
export let title = undefined
|
2021-05-04 12:07:26 +02:00
|
|
|
export let size = "S"
|
2021-03-31 11:59:07 +02:00
|
|
|
export let cancelText = "Cancel"
|
|
|
|
export let confirmText = "Confirm"
|
|
|
|
export let showCancelButton = true
|
|
|
|
export let showConfirmButton = true
|
|
|
|
export let showCloseIcon = true
|
|
|
|
export let onConfirm = undefined
|
2021-09-27 10:59:56 +02:00
|
|
|
export let onCancel = undefined
|
2021-03-31 11:59:07 +02:00
|
|
|
export let disabled = false
|
2021-07-30 14:57:33 +02:00
|
|
|
export let showDivider = true
|
2021-03-31 11:59:07 +02:00
|
|
|
|
2021-11-25 18:14:07 +01:00
|
|
|
export let showSecondaryButton = false
|
|
|
|
export let secondaryButtonText = undefined
|
|
|
|
export let secondaryAction = undefined
|
2021-12-11 10:59:09 +01:00
|
|
|
export let secondaryButtonWarning = false
|
2024-04-05 16:59:28 +02:00
|
|
|
export let custom = false
|
2023-02-01 09:20:46 +01:00
|
|
|
|
2021-06-21 10:57:17 +02:00
|
|
|
const { hide, cancel } = getContext(Context.Modal)
|
2024-09-09 13:36:03 +02:00
|
|
|
|
2021-03-31 11:59:07 +02:00
|
|
|
let loading = false
|
2024-09-09 13:36:03 +02:00
|
|
|
|
2021-03-31 11:59:07 +02:00
|
|
|
$: confirmDisabled = disabled || loading
|
|
|
|
|
2022-11-23 16:03:00 +01:00
|
|
|
async function secondary(e) {
|
2021-11-25 18:14:07 +01:00
|
|
|
loading = true
|
2023-07-05 14:49:39 +02:00
|
|
|
if (!secondaryAction || (await secondaryAction(e)) !== keepOpen) {
|
2021-11-25 18:14:07 +01:00
|
|
|
hide()
|
|
|
|
}
|
|
|
|
loading = false
|
|
|
|
}
|
|
|
|
|
2024-01-11 17:31:57 +01:00
|
|
|
export async function confirm() {
|
2021-03-31 11:59:07 +02:00
|
|
|
loading = true
|
2023-07-05 14:49:39 +02:00
|
|
|
if (!onConfirm || (await onConfirm()) !== keepOpen) {
|
2021-03-31 11:59:07 +02:00
|
|
|
hide()
|
|
|
|
}
|
|
|
|
loading = false
|
|
|
|
}
|
2021-09-27 10:59:56 +02:00
|
|
|
|
|
|
|
async function close() {
|
|
|
|
loading = true
|
2023-07-05 14:49:39 +02:00
|
|
|
if (!onCancel || (await onCancel()) !== keepOpen) {
|
2021-09-27 10:59:56 +02:00
|
|
|
cancel()
|
|
|
|
}
|
|
|
|
loading = false
|
|
|
|
}
|
2021-03-31 11:59:07 +02:00
|
|
|
</script>
|
|
|
|
|
2021-04-15 12:50:56 +02:00
|
|
|
<div
|
2021-05-04 12:07:26 +02:00
|
|
|
class="spectrum-Dialog"
|
|
|
|
class:spectrum-Dialog--small={size === "S"}
|
|
|
|
class:spectrum-Dialog--medium={size === "M"}
|
|
|
|
class:spectrum-Dialog--large={size === "L"}
|
|
|
|
class:spectrum-Dialog--extraLarge={size === "XL"}
|
2024-04-05 16:59:28 +02:00
|
|
|
class:no-grid={custom}
|
2021-04-21 14:59:09 +02:00
|
|
|
style="position: relative;"
|
2021-04-15 12:50:56 +02:00
|
|
|
role="dialog"
|
|
|
|
tabindex="-1"
|
2021-05-04 12:04:42 +02:00
|
|
|
aria-modal="true"
|
|
|
|
>
|
2024-04-05 16:59:28 +02:00
|
|
|
<div class="modal-core" class:spectrum-Dialog-grid={!custom}>
|
2022-04-26 13:04:07 +02:00
|
|
|
{#if title || $$slots.header}
|
|
|
|
<h1
|
|
|
|
class="spectrum-Dialog-heading spectrum-Dialog-heading--noHeader"
|
|
|
|
class:noDivider={!showDivider}
|
|
|
|
class:header-spacing={$$slots.header}
|
|
|
|
>
|
|
|
|
{#if title}
|
|
|
|
{title}
|
|
|
|
{:else if $$slots.header}
|
|
|
|
<slot name="header" />
|
|
|
|
{/if}
|
|
|
|
</h1>
|
|
|
|
{#if showDivider}
|
2022-08-04 12:06:49 +02:00
|
|
|
<Divider />
|
2022-04-20 10:23:09 +02:00
|
|
|
{/if}
|
2022-04-19 15:38:09 +02:00
|
|
|
{/if}
|
|
|
|
|
2021-04-08 16:05:31 +02:00
|
|
|
<!-- TODO: Remove content-grid class once Layout components are in bbui -->
|
|
|
|
<section class="spectrum-Dialog-content content-grid">
|
2024-09-09 13:36:03 +02:00
|
|
|
<slot {loading} />
|
2021-04-08 15:46:34 +02:00
|
|
|
</section>
|
2022-09-05 12:27:43 +02:00
|
|
|
{#if showCancelButton || showConfirmButton || $$slots.footer}
|
2021-04-15 12:50:56 +02:00
|
|
|
<div
|
2021-05-04 12:04:42 +02:00
|
|
|
class="spectrum-ButtonGroup spectrum-Dialog-buttonGroup spectrum-Dialog-buttonGroup--noFooter"
|
|
|
|
>
|
2021-04-15 12:50:56 +02:00
|
|
|
<slot name="footer" />
|
2021-11-25 18:14:07 +01:00
|
|
|
{#if showSecondaryButton && secondaryButtonText && secondaryAction}
|
|
|
|
<div class="secondary-action">
|
2021-12-11 10:59:09 +01:00
|
|
|
<Button
|
|
|
|
group
|
|
|
|
secondary
|
|
|
|
warning={secondaryButtonWarning}
|
|
|
|
on:click={secondary}>{secondaryButtonText}</Button
|
2021-11-25 18:14:07 +01:00
|
|
|
>
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
|
2021-04-15 12:50:56 +02:00
|
|
|
{#if showCancelButton}
|
2023-01-18 14:56:53 +01:00
|
|
|
<Button group secondary on:click={close}>
|
2022-08-02 20:41:43 +02:00
|
|
|
{cancelText}
|
|
|
|
</Button>
|
2021-04-15 12:50:56 +02:00
|
|
|
{/if}
|
|
|
|
{#if showConfirmButton}
|
2022-03-23 13:43:20 +01:00
|
|
|
<span class="confirm-wrap">
|
|
|
|
<Button
|
|
|
|
group
|
|
|
|
cta
|
|
|
|
{...$$restProps}
|
|
|
|
disabled={confirmDisabled}
|
|
|
|
on:click={confirm}
|
|
|
|
>
|
|
|
|
{#if loading}
|
|
|
|
<ProgressCircle overBackground={true} size="S" />
|
|
|
|
{/if}
|
|
|
|
{#if !loading}
|
|
|
|
{confirmText}
|
|
|
|
{/if}
|
|
|
|
</Button>
|
|
|
|
</span>
|
2021-04-15 12:50:56 +02:00
|
|
|
{/if}
|
2021-03-31 11:59:07 +02:00
|
|
|
</div>
|
2021-04-08 15:46:34 +02:00
|
|
|
{/if}
|
|
|
|
{#if showCloseIcon}
|
2021-07-30 15:13:16 +02:00
|
|
|
<div class="close-icon">
|
|
|
|
<Icon hoverable name="Close" on:click={cancel} />
|
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-05-04 12:07:26 +02:00
|
|
|
.spectrum-Dialog--extraLarge {
|
2021-05-04 11:49:33 +02:00
|
|
|
width: 1000px;
|
|
|
|
}
|
|
|
|
|
2021-04-08 16:05:31 +02:00
|
|
|
.content-grid {
|
|
|
|
display: grid;
|
|
|
|
position: relative;
|
|
|
|
gap: var(--spacing-xl);
|
|
|
|
}
|
|
|
|
|
2021-04-15 12:50:56 +02:00
|
|
|
.spectrum-Dialog-content {
|
|
|
|
overflow: visible;
|
|
|
|
}
|
2024-04-05 13:50:09 +02:00
|
|
|
|
|
|
|
.no-grid .spectrum-Dialog-content {
|
|
|
|
border-top: 2px solid var(--spectrum-global-color-gray-200);
|
|
|
|
border-bottom: 2px solid var(--spectrum-global-color-gray-200);
|
|
|
|
}
|
|
|
|
|
|
|
|
.no-grid .spectrum-Dialog-heading {
|
|
|
|
margin-top: 12px;
|
|
|
|
margin-left: 12px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.spectrum-Dialog.no-grid {
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.spectrum-Dialog.no-grid .spectrum-Dialog-buttonGroup {
|
|
|
|
padding: 12px;
|
|
|
|
}
|
|
|
|
|
2021-04-22 14:59:00 +02:00
|
|
|
.spectrum-Dialog-heading {
|
2023-01-18 14:56:53 +01:00
|
|
|
font-family: var(--font-accent);
|
|
|
|
font-weight: 600;
|
2021-04-22 14:59:00 +02:00
|
|
|
}
|
2021-07-30 14:57:33 +02:00
|
|
|
.spectrum-Dialog-heading.noDivider {
|
|
|
|
margin-bottom: 12px;
|
|
|
|
}
|
2021-04-15 12:50:56 +02:00
|
|
|
|
|
|
|
.spectrum-Dialog-buttonGroup {
|
|
|
|
gap: var(--spectrum-global-dimension-static-size-200);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
font-size: var(--font-size-m);
|
|
|
|
}
|
|
|
|
.close-icon :global(svg) {
|
|
|
|
margin-right: 0;
|
|
|
|
}
|
2021-09-14 15:39:45 +02:00
|
|
|
|
|
|
|
.header-spacing {
|
|
|
|
display: flex;
|
|
|
|
justify-content: space-between;
|
|
|
|
}
|
2021-11-25 18:14:07 +01:00
|
|
|
|
|
|
|
.secondary-action {
|
|
|
|
margin-right: auto;
|
|
|
|
}
|
2022-02-10 00:16:24 +01:00
|
|
|
|
|
|
|
.spectrum-Dialog-buttonGroup {
|
|
|
|
padding-left: 0;
|
|
|
|
}
|
2022-03-23 13:43:20 +01:00
|
|
|
|
|
|
|
.confirm-wrap :global(.spectrum-Button-label) {
|
|
|
|
display: contents;
|
|
|
|
}
|
2021-03-31 11:59:07 +02:00
|
|
|
</style>
|