budibase/packages/bbui/src/Drawer/Drawer.svelte

83 lines
1.6 KiB
Svelte
Raw Normal View History

2021-03-31 11:59:07 +02:00
<script>
import { slide } from "svelte/transition"
import Portal from "svelte-portal"
import Button from "../Button/Button.svelte"
2021-04-22 15:14:55 +02:00
import Body from "../Typography/Body.svelte"
import Heading from "../Typography/Heading.svelte"
2021-03-31 11:59:07 +02:00
export let title
let visible = false
export function show() {
if (visible) {
return
}
visible = true
}
export function hide() {
if (!visible) {
return
}
visible = false
}
function handleKey(e) {
if (visible && e.key === "Escape") {
hide()
}
}
</script>
<svelte:window on:keydown={handleKey} />
{#if visible}
<Portal>
<section class="drawer" transition:slide>
<header>
<div class="text">
<Heading size="XS">{title}</Heading>
<Body size="S">
2021-05-04 10:55:14 +02:00
<slot name="description" />
</Body>
2021-03-31 11:59:07 +02:00
</div>
2021-04-22 16:34:18 +02:00
<div class="buttons">
<Button secondary quiet on:click={hide}>Cancel</Button>
2021-03-31 11:59:07 +02:00
<slot name="buttons" />
</div>
</header>
<slot name="body" />
</section>
</Portal>
{/if}
<style>
.drawer {
position: absolute;
bottom: 0;
left: 260px;
width: calc(100% - 520px);
background: var(--background);
border-top: var(--border-light);
2021-03-31 11:59:07 +02:00
z-index: 2;
}
header {
display: flex;
justify-content: space-between;
align-items: center;
border-bottom: var(--border-light);
padding: var(--spacing-l) var(--spacing-xl);
gap: var(--spacing-xl);
2021-03-31 11:59:07 +02:00
}
.text {
display: flex;
flex-direction: column;
justify-content: center;
align-items: flex-start;
gap: var(--spacing-xs);
2021-03-31 11:59:07 +02:00
}
</style>