budibase/packages/bbui/src/Modal/ModalContent.svelte

191 lines
4.6 KiB
Svelte
Raw Normal View History

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"
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"
import Icon from "../Icon/Icon.svelte"
2021-03-31 11:59:07 +02:00
import Context from "../context"
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
export let onCancel = undefined
2021-03-31 11:59:07 +02:00
export let disabled = false
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
export let dataCy = null
2021-11-25 18:14:07 +01: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
}
async function close() {
loading = true
if (!onCancel || (await onCancel()) !== false) {
cancel()
}
loading = false
}
2021-03-31 11:59:07 +02:00
</script>
<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"}
style="position: relative;"
role="dialog"
tabindex="-1"
aria-modal="true"
data-cy={dataCy}
>
<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}
{/if}
<!-- TODO: Remove content-grid class once Layout components are in bbui -->
<section class="spectrum-Dialog-content content-grid">
<slot />
</section>
{#if showCancelButton || showConfirmButton}
<div
class="spectrum-ButtonGroup spectrum-Dialog-buttonGroup spectrum-Dialog-buttonGroup--noFooter"
>
<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}
{#if showCancelButton}
<Button group secondary on:click={close}>{cancelText}</Button>
{/if}
{#if showConfirmButton}
<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>
{/if}
2021-03-31 11:59:07 +02:00
</div>
{/if}
{#if showCloseIcon}
<div class="close-icon">
<Icon hoverable name="Close" on:click={cancel} />
2021-03-31 11:59:07 +02:00
</div>
{/if}
</div>
2021-03-31 11:59:07 +02:00
</div>
<style>
2021-05-04 12:07:26 +02:00
.spectrum-Dialog--extraLarge {
2021-05-04 11:49:33 +02:00
width: 1000px;
}
.content-grid {
display: grid;
position: relative;
gap: var(--spacing-xl);
}
.spectrum-Dialog-content {
overflow: visible;
}
2021-04-22 14:59:00 +02:00
.spectrum-Dialog-heading {
font-family: var(--font-sans);
2021-04-22 14:59:00 +02:00
}
.spectrum-Dialog-heading.noDivider {
margin-bottom: 12px;
}
.spectrum-Dialog-buttonGroup {
gap: var(--spectrum-global-dimension-static-size-200);
}
2021-03-31 11:59:07 +02:00
.close-icon {
position: absolute;
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;
}
.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;
}
.confirm-wrap :global(.spectrum-Button-label) {
display: contents;
}
2021-03-31 11:59:07 +02:00
</style>