Drawer
Preview
<script setup lang="ts">
import { ref } from 'vue'
import { Drawer } from 'beui-vue'
const open = ref(false)
const side = ref<'left' | 'right'>('right')
function openWith(next: 'left' | 'right') {
side.value = next
open.value = true
}
</script>
<template>
<div class="actions">
<button type="button" class="secondary" @click="openWith('left')">Open left</button>
<button type="button" class="primary" @click="openWith('right')">Open right</button>
<Drawer v-model:open="open" :side="side" aria-label="Demo drawer" class="panel">
<h2>Drawer</h2>
<p>Slides in from the {{ side }}. Press Esc or click outside to close.</p>
<button type="button" class="secondary close" @click="open = false">Close</button>
</Drawer>
</div>
</template>
<style scoped>
.actions { display: flex; align-items: center; gap: .75rem; }
button { display: inline-flex; box-sizing: border-box; align-items: center; justify-content: center; height: 2.5rem; padding: 0 1.25rem; border: 1px solid transparent; border-radius: 999px; font: inherit; font-size: .875rem; font-weight: 500; line-height: 1.25rem; cursor: pointer; transition: background-color .15s, color .15s; }
.secondary { border-color: var(--beui-border); background: var(--beui-card); color: var(--beui-foreground); }
.secondary:hover { background: color-mix(in srgb, var(--beui-card) 70%, transparent); }
.primary { border-width: 0; background: var(--beui-primary); color: var(--beui-primary-foreground); }
.primary:hover { background: color-mix(in srgb, var(--beui-primary) 90%, transparent); }
:global(.be-drawer.panel) { gap: 1rem; padding: 1.5rem; }
h2 { margin: 0; font-size: .875rem; line-height: 1.25rem; font-weight: 600; color: var(--beui-foreground); }
p { margin: 0; font-size: .875rem; line-height: 1.25rem; color: var(--beui-muted-foreground); }
.close { margin-top: auto; }
</style><script lang="ts">
/** English defaults. Override per instance with `labels`. */
export const drawerMessages = { close: 'Close' }
export type DrawerMessages = typeof drawerMessages
</script>
<script setup lang="ts">
import { AnimatePresence, motion } from 'motion-v'
import { useReducedMotion } from '../core/reduced-motion'
import { computed, onMounted, shallowRef, useAttrs, useTemplateRef } from 'vue'
import { easeOut, panelSpring } from '../core/motion'
import PresenceGate from './PresenceGate.vue'
import { elementOf, useBodyLock, useFocusTrap } from './overlay-kit'
defineOptions({ inheritAttrs: false })
const { side = 'right', ariaLabel, dismissable = true, backdropClassName, labels } = defineProps<{
side?: 'left' | 'right'
ariaLabel?: string
/** Close when the backdrop is clicked or Escape is pressed. Default true. */
dismissable?: boolean
/** Class for the backdrop. */
backdropClassName?: string
labels?: Partial<DrawerMessages>
}>()
// `label` and `backdrop-class` were this port's earlier names for `ariaLabel` and `backdropClassName`;
// they still work as plain attributes.
const attrs = useAttrs()
const dialogLabel = computed(() => ariaLabel ?? (attrs.label as string | undefined))
const backdropClasses = computed(() => backdropClassName ?? (attrs['backdrop-class'] as string | undefined) ?? (attrs.backdropClass as string | undefined))
const open = defineModel<boolean>('open', { default: false })
const t = computed(() => ({ ...drawerMessages, ...labels }))
const reduce = useReducedMotion()
const panel = useTemplateRef<unknown>('panel')
// The panel portals to <body>, which the server cannot do.
const mounted = shallowRef(false)
onMounted(() => { mounted.value = true })
function close() { open.value = false }
// Focus moves into the panel on open, Tab stays inside it, and focus returns
// to the opener on close.
useFocusTrap(() => open.value, () => elementOf(panel.value), { onEscape: () => { if (dismissable) close() } })
useBodyLock(() => open.value)
const offscreen = computed(() => (side === 'right' ? '100%' : '-100%'))
const fade = { duration: 0.2, ease: easeOut } as const
</script>
<template>
<Teleport v-if="mounted" to="body">
<!-- Two fixed siblings, no wrapper: the backdrop spans the viewport edges but
paints the scrim, and the panel is inset off one side and paints its own
surface. Both hang off `PresenceGate`, so interaction releases in the same
commit that starts the exit. -->
<AnimatePresence>
<PresenceGate v-if="open" key="backdrop" v-slot="{ gate }">
<motion.button type="button" class="be-drawer-backdrop" :class="backdropClasses" :aria-label="t.close" tabindex="-1"
:initial="{ opacity: 0 }" :animate="{ opacity: 1 }" :exit="{ opacity: 0 }" :transition="{ duration: 0.25, ease: easeOut }"
:inert="gate.inert" :style="gate.style" @click="dismissable && close()" />
</PresenceGate>
<PresenceGate v-if="open" key="panel" v-slot="{ gate }">
<motion.div ref="panel" class="be-drawer" :class="[side === 'right' ? 'be-drawer-right' : 'be-drawer-left', $attrs.class]" tabindex="-1" role="dialog" aria-modal="true" :aria-label="dialogLabel"
:initial="reduce ? { opacity: 0 } : { x: offscreen }" :animate="reduce ? { opacity: 1 } : { x: 0 }" :exit="reduce ? { opacity: 0 } : { x: offscreen }"
:transition="reduce ? fade : panelSpring" :inert="gate.inert" :style="gate.style">
<slot :close="close" />
</motion.div>
</PresenceGate>
</AnimatePresence>
</Teleport>
</template>
<style scoped>
.be-drawer-backdrop { position: fixed; inset: 0; z-index: 50; width: 100%; height: 100%; padding: 0; border: 0; cursor: default; background: rgb(0 0 0 / .4); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
.be-drawer { position: fixed; top: 0; bottom: 0; z-index: 50; box-sizing: border-box; display: flex; flex-direction: column; width: 20rem; max-width: 85vw; background: var(--beui-background); color: var(--beui-foreground); box-shadow: 0 25px 50px -12px rgb(0 0 0 / .25); outline: none; }
.be-drawer-right { right: 0; border-left: 1px solid var(--beui-border); }
.be-drawer-left { left: 0; border-right: 1px solid var(--beui-border); }
</style>Install
Add it with your package manager, or copy the source manually.
Run it in a project set up with shadcn-vue. The source is copied to components/beui and its dependencies are added to your package.json. Read the shadcn-vue guide
$ bunx --bun shadcn-vue@latest add @beui-vue/drawer$ bun add beui-vueDownload the release archive to your project root, then install the local file.
$ bun add ./beui-vue-0.1.0.tgzImport the shared styles once in your application.
import Drawer from '@/components/beui/layout/Drawer.vue'
import '@/components/beui/styles.css'API Reference
v-model:open?booleanfalseside?"left" | "right"rightclass?stringClass for the panel surface.
—backdropClassName?stringClass for the backdrop.
—ariaLabel?string—dismissable?booleanClose when the backdrop is clicked or Escape is pressed. Default true.
truelabels?Partial<DrawerMessages>Override any built-in string.
—Related components
Popover
Gooey popover whose panel oozes out of the trigger through an SVG goo filter with a liquid neck that stretches and pinches, then crisp content fades in on top. The Morph variant reveals its full-size panel from the corner nearest the trigger on one synchronized spring clip. Click or hover trigger, controlled or uncontrolled.
Morphing Modal
Family-app-style modal. A single panel that morphs its height as you navigate between inner views, with blur cross-fade on content.
Tooltip
Composable hover, focus and tap tooltip with a subtle scale and fade, collision-aware side and alignment, an optional arrow, a pointer corridor onto hoverable content, one label at a time, keyboard-only focus reveal and optional cursor tracking.
Updated