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
|
2022-04-21 12:59:59 +02:00
|
|
|
export let dataCy = null
|
2022-08-30 11:49:19 +02:00
|
|
|
export let buttonCta = true
|
2021-06-21 10:57:17 +02:00
|
|
|
const { hide, cancel } = getContext(Context.Modal)
|
2021-03-31 11:59:07 +02:00
|
|
|
let loading = false
|
|
|
|
$: confirmDisabled = disabled || loading
|
|
|
|
|
2021-11-25 18:14:07 +01:00
|
|
|
async function secondary() {
|
|
|
|
loading = true
|
|
|
|
if (!secondaryAction || (await secondaryAction()) !== false) {
|
|
|
|
hide()
|
|
|
|
}
|
|
|
|
loading = false
|
|
|
|
}
|
|
|
|
|
2021-03-31 11:59:07 +02:00
|
|
|
async function confirm() {
|
|
|
|
loading = true
|
|
|
|
if (!onConfirm || (await onConfirm()) !== false) {
|
|
|
|
hide()
|
|
|
|
}
|
|
|
|
loading = false
|
|
|
|
}
|
2021-09-27 10:59:56 +02:00
|
|
|
|
|
|
|
async function close() {
|
|
|
|
loading = true
|
|
|
|
if (!onCancel || (await onCancel()) !== false) {
|
|
|
|
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"}
|
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"
|
2022-04-21 12:59:59 +02:00
|
|
|
data-cy={dataCy}
|
2021-05-04 12:04:42 +02:00
|
|
|
>
|
2021-04-08 15:46:34 +02:00
|
|
|
<div class="spectrum-Dialog-grid">
|
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}
|
|
|
|
<Divider size="M" />
|
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">
|
2021-04-08 15:46:34 +02:00
|
|
|
<slot />
|
|
|
|
</section>
|
|
|
|
{#if showCancelButton || showConfirmButton}
|
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}
|
2022-08-02 20:41:43 +02:00
|
|
|
<Button group secondary newStyles on:click={close}>
|
|
|
|
{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
|
2022-08-30 11:49:19 +02:00
|
|
|
cta={buttonCta}
|
2022-03-23 13:43:20 +01:00
|
|
|
{...$$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;
|
|
|
|
}
|
2021-04-22 14:59:00 +02:00
|
|
|
.spectrum-Dialog-heading {
|
2021-05-25 10:41:23 +02:00
|
|
|
font-family: var(--font-sans);
|
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>
|