536 lines
15 KiB
Plaintext
536 lines
15 KiB
Plaintext
component Drawer {
|
|
outputs {
|
|
open(payload: { placement: string; sourceEvent: Event })
|
|
close(payload: { reason: string; placement: string; sourceEvent: Event })
|
|
cancel(payload: { placement: string; sourceEvent: Event })
|
|
}
|
|
|
|
props {
|
|
open: boolean = false
|
|
defaultOpen: boolean = false
|
|
placement: string = "right"
|
|
size: string = "md"
|
|
color: string = "primary"
|
|
variant: string = "default"
|
|
title: string = "Drawer"
|
|
description: string = ""
|
|
icon: string = ""
|
|
label: string = "Drawer"
|
|
closeLabel: string = "Close drawer"
|
|
showClose: boolean = true
|
|
closeOnBackdrop: boolean = true
|
|
closeOnEscape: boolean = true
|
|
// Open/close animation length in ms. 0 disables the animation entirely.
|
|
duration: number = 260
|
|
overlay: boolean = true
|
|
scrollable: boolean = true
|
|
triggerLabel: string = ""
|
|
triggerIcon: string = ""
|
|
class: string = ""
|
|
}
|
|
|
|
state visible = defaultOpen
|
|
|
|
functions {
|
|
shared function isOpen() {
|
|
return open || visible
|
|
}
|
|
|
|
client function showDrawer(sourceEvent) {
|
|
visible = true
|
|
output.open({
|
|
placement: placement,
|
|
sourceEvent: sourceEvent
|
|
})
|
|
}
|
|
|
|
client function hideDrawer(reason, sourceEvent) {
|
|
visible = false
|
|
output.close({
|
|
reason: reason,
|
|
placement: placement,
|
|
sourceEvent: sourceEvent
|
|
})
|
|
}
|
|
|
|
client function cancelDrawer(sourceEvent) {
|
|
output.cancel({
|
|
placement: placement,
|
|
sourceEvent: sourceEvent
|
|
})
|
|
hideDrawer("cancel", sourceEvent)
|
|
}
|
|
|
|
client function handleKeydown(sourceEvent) {
|
|
if (closeOnEscape && sourceEvent.key === "Escape") {
|
|
sourceEvent.preventDefault()
|
|
cancelDrawer(sourceEvent)
|
|
}
|
|
}
|
|
}
|
|
|
|
view {
|
|
<div
|
|
{...attrs}
|
|
data-ui-component="Drawer"
|
|
data-open='{open || visible ? "true" : "false"}'
|
|
data-placement='{placement}'
|
|
data-size='{size}'
|
|
data-color='{color}'
|
|
data-variant='{variant}'
|
|
data-overlay='{overlay ? "true" : "false"}'
|
|
data-scrollable='{scrollable ? "true" : "false"}'
|
|
class='wire-drawer {class}'
|
|
style='--drawer-duration: {duration}ms'
|
|
>
|
|
|
|
{#if triggerLabel}
|
|
<button
|
|
type="button"
|
|
class="wire-drawer__trigger"
|
|
aria-haspopup="dialog"
|
|
aria-expanded='{open || visible ? "true" : "false"}'
|
|
@click='showDrawer(event)'
|
|
>
|
|
{#if triggerIcon}
|
|
<span class='{triggerIcon}' aria-hidden="true"></span>
|
|
{/if}
|
|
<span>{triggerLabel}</span>
|
|
</button>
|
|
{/if}
|
|
|
|
<span class="wire-drawer__trigger-slot" @click='showDrawer(event)'>
|
|
<slot name="trigger"></slot>
|
|
</span>
|
|
|
|
<div
|
|
class="wire-drawer__layer"
|
|
role="presentation"
|
|
@keydown='handleKeydown(event)'
|
|
>
|
|
{#if overlay}
|
|
<button
|
|
type="button"
|
|
class="wire-drawer__backdrop"
|
|
aria-label='{closeLabel}'
|
|
@click='if (closeOnBackdrop) { cancelDrawer(event) }'
|
|
></button>
|
|
{/if}
|
|
|
|
<section
|
|
class="wire-drawer__panel"
|
|
role="dialog"
|
|
aria-modal="true"
|
|
aria-label='{label || title}'
|
|
tabindex="-1"
|
|
>
|
|
<div class="wire-drawer__handle" aria-hidden="true"></div>
|
|
|
|
<header class="wire-drawer__header">
|
|
<div class="wire-drawer__heading">
|
|
{#if icon}
|
|
<span class='wire-drawer__icon {icon}' aria-hidden="true"></span>
|
|
{/if}
|
|
|
|
<div class="wire-drawer__heading-copy">
|
|
<slot name="header"></slot>
|
|
{#if title}
|
|
<h2>{title}</h2>
|
|
{/if}
|
|
{#if description}
|
|
<p>{description}</p>
|
|
{/if}
|
|
</div>
|
|
</div>
|
|
|
|
{#if showClose}
|
|
<button
|
|
type="button"
|
|
class="wire-drawer__close"
|
|
aria-label='{closeLabel}'
|
|
@click='hideDrawer("close-button", event)'
|
|
>
|
|
<span class="icon-[lucide--x]" aria-hidden="true"></span>
|
|
</button>
|
|
{/if}
|
|
</header>
|
|
|
|
<div class="wire-drawer__body">
|
|
<slot></slot>
|
|
</div>
|
|
|
|
<footer class="wire-drawer__footer">
|
|
<slot name="footer"></slot>
|
|
</footer>
|
|
</section>
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
style {
|
|
.wire-drawer {
|
|
--drawer-accent: var(--wire-color-primary);
|
|
--drawer-soft: var(--wire-color-primary-soft);
|
|
position: relative;
|
|
display: inline-flex;
|
|
}
|
|
|
|
.wire-drawer[data-color="secondary"] {
|
|
--drawer-accent: var(--wire-color-secondary);
|
|
--drawer-soft: var(--wire-color-secondary-soft);
|
|
}
|
|
|
|
.wire-drawer[data-color="info"] {
|
|
--drawer-accent: var(--wire-color-info);
|
|
--drawer-soft: var(--wire-color-info-soft);
|
|
}
|
|
|
|
.wire-drawer[data-color="success"] {
|
|
--drawer-accent: var(--wire-color-success);
|
|
--drawer-soft: var(--wire-color-success-soft);
|
|
}
|
|
|
|
.wire-drawer[data-color="warning"] {
|
|
--drawer-accent: var(--wire-color-warning);
|
|
--drawer-soft: var(--wire-color-warning-soft);
|
|
}
|
|
|
|
.wire-drawer[data-color="danger"] {
|
|
--drawer-accent: var(--wire-color-danger);
|
|
--drawer-soft: var(--wire-color-danger-soft);
|
|
}
|
|
|
|
.wire-drawer__trigger,
|
|
.wire-drawer__trigger-slot {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 0.55rem;
|
|
}
|
|
|
|
.wire-drawer__trigger {
|
|
appearance: none;
|
|
min-height: 2.55rem;
|
|
padding: 0.65rem 1rem;
|
|
color: var(--wire-color-primary-contrast);
|
|
background: var(--drawer-accent);
|
|
border: 0;
|
|
border-radius: 0.8rem;
|
|
font: inherit;
|
|
font-size: 0.85rem;
|
|
font-weight: 650;
|
|
cursor: pointer;
|
|
}
|
|
|
|
/*
|
|
* The layer stays in the layout and is revealed by [data-open]; it used to
|
|
* be toggled with data-show, which sets display:none, and display cannot
|
|
* be transitioned -- the drawer simply snapped in and out. visibility is
|
|
* delayed by the duration on the way out so the panel can finish sliding
|
|
* before the layer is taken out of the hit-testing tree.
|
|
*/
|
|
.wire-drawer__layer {
|
|
position: fixed;
|
|
inset: 0;
|
|
z-index: 1200;
|
|
display: flex;
|
|
pointer-events: none;
|
|
visibility: hidden;
|
|
opacity: 0;
|
|
transition:
|
|
opacity var(--drawer-duration, 260ms) ease,
|
|
visibility 0s linear var(--drawer-duration, 260ms);
|
|
}
|
|
|
|
.wire-drawer[data-open="true"] .wire-drawer__layer {
|
|
visibility: visible;
|
|
opacity: 1;
|
|
transition:
|
|
opacity var(--drawer-duration, 260ms) ease,
|
|
visibility 0s linear 0s;
|
|
}
|
|
|
|
.wire-drawer__backdrop {
|
|
position: absolute;
|
|
inset: 0;
|
|
z-index: 0;
|
|
appearance: none;
|
|
padding: 0;
|
|
background: color-mix(in srgb, black 56%, transparent);
|
|
border: 0;
|
|
backdrop-filter: blur(7px);
|
|
pointer-events: auto;
|
|
}
|
|
|
|
.wire-drawer[data-overlay="false"] .wire-drawer__backdrop {
|
|
display: none;
|
|
}
|
|
|
|
.wire-drawer__panel {
|
|
position: relative;
|
|
z-index: 1;
|
|
display: flex;
|
|
flex-direction: column;
|
|
width: min(28rem, calc(100vw - 1rem));
|
|
max-height: 100%;
|
|
margin-left: auto;
|
|
color: var(--wire-color-text);
|
|
background:
|
|
radial-gradient(
|
|
circle at 100% 0%,
|
|
color-mix(in srgb, var(--drawer-accent) 8%, transparent),
|
|
transparent 34%
|
|
),
|
|
var(--wire-color-surface-raised);
|
|
border-left: 1px solid color-mix(in srgb, var(--drawer-accent) 18%, var(--wire-color-border));
|
|
box-shadow: -28px 0 80px color-mix(in srgb, black 28%, transparent);
|
|
pointer-events: auto;
|
|
overflow: hidden;
|
|
/* Slides in from whichever edge the placement puts it on. */
|
|
transform: translateX(100%);
|
|
transition: transform var(--drawer-duration, 260ms) cubic-bezier(0.32, 0.72, 0, 1);
|
|
}
|
|
|
|
.wire-drawer[data-open="true"] .wire-drawer__panel {
|
|
transform: none;
|
|
}
|
|
|
|
.wire-drawer[data-placement="left"] .wire-drawer__panel {
|
|
transform: translateX(-100%);
|
|
}
|
|
|
|
.wire-drawer[data-placement="top"] .wire-drawer__panel {
|
|
transform: translateY(-100%);
|
|
}
|
|
|
|
.wire-drawer[data-placement="bottom"] .wire-drawer__panel {
|
|
transform: translateY(100%);
|
|
}
|
|
|
|
.wire-drawer[data-open="true"][data-placement="left"] .wire-drawer__panel,
|
|
.wire-drawer[data-open="true"][data-placement="top"] .wire-drawer__panel,
|
|
.wire-drawer[data-open="true"][data-placement="bottom"] .wire-drawer__panel {
|
|
transform: none;
|
|
}
|
|
|
|
@media (prefers-reduced-motion: reduce) {
|
|
.wire-drawer__layer,
|
|
.wire-drawer__panel {
|
|
transition: none;
|
|
}
|
|
}
|
|
|
|
.wire-drawer[data-size="sm"] .wire-drawer__panel {
|
|
width: min(22rem, calc(100vw - 1rem));
|
|
}
|
|
|
|
.wire-drawer[data-size="lg"] .wire-drawer__panel {
|
|
width: min(38rem, calc(100vw - 1rem));
|
|
}
|
|
|
|
.wire-drawer[data-size="xl"] .wire-drawer__panel {
|
|
width: min(52rem, calc(100vw - 1rem));
|
|
}
|
|
|
|
.wire-drawer[data-size="full"] .wire-drawer__panel {
|
|
width: 100vw;
|
|
}
|
|
|
|
.wire-drawer[data-placement="left"] .wire-drawer__panel {
|
|
margin-right: auto;
|
|
margin-left: 0;
|
|
border-right: 1px solid color-mix(in srgb, var(--drawer-accent) 18%, var(--wire-color-border));
|
|
border-left: 0;
|
|
box-shadow: 28px 0 80px color-mix(in srgb, black 28%, transparent);
|
|
}
|
|
|
|
.wire-drawer[data-placement="top"] .wire-drawer__layer,
|
|
.wire-drawer[data-placement="bottom"] .wire-drawer__layer {
|
|
align-items: flex-start;
|
|
}
|
|
|
|
.wire-drawer[data-placement="top"] .wire-drawer__panel,
|
|
.wire-drawer[data-placement="bottom"] .wire-drawer__panel {
|
|
width: 100%;
|
|
max-height: min(80vh, 44rem);
|
|
margin: 0;
|
|
border: 0;
|
|
box-shadow: 0 24px 80px color-mix(in srgb, black 28%, transparent);
|
|
}
|
|
|
|
.wire-drawer[data-placement="top"] .wire-drawer__panel {
|
|
border-bottom: 1px solid color-mix(in srgb, var(--drawer-accent) 18%, var(--wire-color-border));
|
|
}
|
|
|
|
.wire-drawer[data-placement="bottom"] .wire-drawer__layer {
|
|
align-items: flex-end;
|
|
}
|
|
|
|
.wire-drawer[data-placement="bottom"] .wire-drawer__panel {
|
|
border-top: 1px solid color-mix(in srgb, var(--drawer-accent) 18%, var(--wire-color-border));
|
|
border-radius: 1.3rem 1.3rem 0 0;
|
|
}
|
|
|
|
.wire-drawer[data-variant="soft"] .wire-drawer__panel {
|
|
background:
|
|
linear-gradient(145deg, var(--drawer-soft), transparent 65%),
|
|
var(--wire-color-surface-raised);
|
|
}
|
|
|
|
.wire-drawer[data-variant="solid"] .wire-drawer__panel {
|
|
color: var(--wire-color-primary-contrast);
|
|
background: var(--drawer-accent);
|
|
border-color: color-mix(in srgb, white 18%, transparent);
|
|
}
|
|
|
|
.wire-drawer__handle {
|
|
display: none;
|
|
width: 2.75rem;
|
|
height: 0.28rem;
|
|
margin: 0.55rem auto 0;
|
|
background: color-mix(in srgb, var(--wire-color-text-muted) 48%, transparent);
|
|
border-radius: 999px;
|
|
}
|
|
|
|
.wire-drawer[data-placement="bottom"] .wire-drawer__handle {
|
|
display: block;
|
|
}
|
|
|
|
.wire-drawer__header {
|
|
display: flex;
|
|
align-items: flex-start;
|
|
justify-content: space-between;
|
|
gap: 1rem;
|
|
padding: 1.35rem 1.35rem 1.1rem;
|
|
border-bottom: 1px solid var(--wire-color-border);
|
|
}
|
|
|
|
.wire-drawer__heading {
|
|
display: flex;
|
|
align-items: flex-start;
|
|
gap: 0.85rem;
|
|
min-width: 0;
|
|
}
|
|
|
|
.wire-drawer__icon {
|
|
flex: 0 0 auto;
|
|
width: 1.25rem;
|
|
height: 1.25rem;
|
|
margin-top: 0.15rem;
|
|
color: var(--drawer-accent);
|
|
}
|
|
|
|
.wire-drawer[data-variant="solid"] .wire-drawer__icon {
|
|
color: currentColor;
|
|
}
|
|
|
|
.wire-drawer__heading-copy {
|
|
display: grid;
|
|
gap: 0.3rem;
|
|
min-width: 0;
|
|
}
|
|
|
|
.wire-drawer__heading-copy h2,
|
|
.wire-drawer__heading-copy p {
|
|
margin: 0;
|
|
}
|
|
|
|
.wire-drawer__heading-copy h2 {
|
|
font-size: 1.05rem;
|
|
font-weight: 650;
|
|
line-height: 1.3;
|
|
}
|
|
|
|
.wire-drawer__heading-copy p {
|
|
color: var(--wire-color-text-muted);
|
|
font-size: 0.8rem;
|
|
line-height: 1.55;
|
|
}
|
|
|
|
.wire-drawer[data-variant="solid"] .wire-drawer__heading-copy p {
|
|
color: color-mix(in srgb, currentColor 76%, transparent);
|
|
}
|
|
|
|
/*
|
|
* padding is reset explicitly: an app-level `button { padding: ... }` rule
|
|
* outranks the browser default and leaves this fixed-size button with a
|
|
* content box of a couple of pixels, which squeezes the icon to a sliver
|
|
* and reads as "the close button has no icon". Same trap as Modal.
|
|
*/
|
|
.wire-drawer__close {
|
|
appearance: none;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
flex: 0 0 auto;
|
|
padding: 0;
|
|
width: 2.35rem;
|
|
height: 2.35rem;
|
|
color: var(--wire-color-text-muted);
|
|
background: var(--wire-color-surface-soft);
|
|
border: 1px solid var(--wire-color-border);
|
|
border-radius: 0.75rem;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.wire-drawer__close:hover,
|
|
.wire-drawer__close:focus-visible {
|
|
color: var(--drawer-accent);
|
|
border-color: color-mix(in srgb, var(--drawer-accent) 34%, var(--wire-color-border));
|
|
outline: none;
|
|
}
|
|
|
|
/* Never let the glyph be shrunk by the flex container. */
|
|
.wire-drawer__close svg {
|
|
flex: 0 0 auto;
|
|
width: 1rem;
|
|
height: 1rem;
|
|
}
|
|
|
|
/*
|
|
* Slot content is authored by the host app, so the app global stylesheet
|
|
* styles it too. A bare element selector there (p { color: ... }) beats
|
|
* anything the panel merely *inherits*, which is how modal body copy ended
|
|
* up muted grey on a saturated background. State the colour explicitly;
|
|
* :where() keeps the specificity low enough that any class the app puts on
|
|
* its own slot content still wins.
|
|
*/
|
|
.wire-drawer__body {
|
|
flex: 1 1 auto;
|
|
min-height: 0;
|
|
padding: 1.35rem;
|
|
color: var(--wire-color-text);
|
|
}
|
|
|
|
.wire-drawer__body :where(p, li, dd, dt, h1, h2, h3, h4, h5, h6, span, label, code) {
|
|
color: inherit;
|
|
}
|
|
|
|
.wire-drawer[data-scrollable="true"] .wire-drawer__body {
|
|
overflow: auto;
|
|
overscroll-behavior: contain;
|
|
}
|
|
|
|
.wire-drawer__footer {
|
|
padding: 1rem 1.35rem 1.35rem;
|
|
border-top: 1px solid var(--wire-color-border);
|
|
}
|
|
|
|
.wire-drawer__footer:empty {
|
|
display: none;
|
|
}
|
|
|
|
@media (max-width: 639px) {
|
|
.wire-drawer[data-placement="right"] .wire-drawer__panel,
|
|
.wire-drawer[data-placement="left"] .wire-drawer__panel {
|
|
width: min(24rem, 100vw);
|
|
}
|
|
|
|
.wire-drawer__header,
|
|
.wire-drawer__body,
|
|
.wire-drawer__footer {
|
|
padding-inline: 1rem;
|
|
}
|
|
}
|
|
}
|
|
}
|