Bouncy Accordion
Preview
<script setup lang="ts">
import { BouncyAccordion } from 'beui-vue'
import { defineComponent, h, type PropType } from 'vue'
/** Inline Lucide glyphs for the layout demos (generated from lucide-react, ISC). Inner markup of 24x24 stroked icons. */
const ICONS: Record<string, string> = {
"ArrowRight": "<path d=\"M5 12h14\"></path><path d=\"m12 5 7 7-7 7\"></path>",
"ArrowUp": "<path d=\"m5 12 7-7 7 7\"></path><path d=\"M12 19V5\"></path>",
"ArrowUpRight": "<path d=\"M7 7h10v10\"></path><path d=\"M7 17 17 7\"></path>",
"BarChart3": "<path d=\"M3 3v16a2 2 0 0 0 2 2h16\"></path><path d=\"M18 17V9\"></path><path d=\"M13 17V5\"></path><path d=\"M8 17v-3\"></path>",
"Bell": "<path d=\"M10.268 21a2 2 0 0 0 3.464 0\"></path><path d=\"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326\"></path>",
"Braces": "<path d=\"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1\"></path><path d=\"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1\"></path>",
"Building2": "<path d=\"M10 12h4\"></path><path d=\"M10 8h4\"></path><path d=\"M14 21v-3a2 2 0 0 0-4 0v3\"></path><path d=\"M6 10H4a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-2\"></path><path d=\"M6 21V5a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v16\"></path>",
"Calendar": "<path d=\"M8 2v3\"></path><path d=\"M16 2v3\"></path><rect x=\"3\" y=\"3\" width=\"18\" height=\"18\" rx=\"2\"></rect><path d=\"M3 9h18\"></path>",
"CalendarClock": "<path d=\"M16 14v2.2l1.6 1\"></path><path d=\"M16 2v3\"></path><path d=\"M21 7.338V5a2 2 0 00-2-2H5a2 2 0 00-2 2v14a2 2 0 002 2h2.338\"></path><path d=\"M3 9h5.859\"></path><path d=\"M8 2v3\"></path><circle cx=\"16\" cy=\"16\" r=\"6\"></circle>",
"Check": "<path d=\"M20 6 9 17l-5-5\"></path>",
"CheckCircle2": "<circle cx=\"12\" cy=\"12\" r=\"10\"></circle><path d=\"m9 12 2 2 4-4\"></path>",
"ChevronDown": "<path d=\"m6 9 6 6 6-6\"></path>",
"ChevronLeft": "<path d=\"m15 18-6-6 6-6\"></path>",
"ChevronRight": "<path d=\"m9 18 6-6-6-6\"></path>",
"ChevronUp": "<path d=\"m18 15-6-6-6 6\"></path>",
"ChevronsUpDown": "<path d=\"m7 15 5 5 5-5\"></path><path d=\"m7 9 5-5 5 5\"></path>",
"Circle": "<circle cx=\"12\" cy=\"12\" r=\"10\"></circle>",
"CircleUserRound": "<path d=\"M17.925 20.056a6 6 0 0 0-11.851.001\"></path><circle cx=\"12\" cy=\"11\" r=\"4\"></circle><circle cx=\"12\" cy=\"12\" r=\"10\"></circle>",
"Command": "<path d=\"M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3\"></path>",
"File": "<path d=\"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z\"></path><path d=\"M14 2v5a1 1 0 0 0 1 1h5\"></path>",
"FileCode2": "<path d=\"M4 12.15V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2h-3.35\"></path><path d=\"M14 2v5a1 1 0 0 0 1 1h5\"></path><path d=\"m5 16-3 3 3 3\"></path><path d=\"m9 22 3-3-3-3\"></path>",
"FileJson2": "<path d=\"M14 22h4a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v6\"></path><path d=\"M14 2v5a1 1 0 0 0 1 1h5\"></path><path d=\"M5 14a1 1 0 0 0-1 1v2a1 1 0 0 1-1 1 1 1 0 0 1 1 1v2a1 1 0 0 0 1 1\"></path><path d=\"M9 22a1 1 0 0 0 1-1v-2a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-2a1 1 0 0 0-1-1\"></path>",
"FileText": "<path d=\"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z\"></path><path d=\"M14 2v5a1 1 0 0 0 1 1h5\"></path><path d=\"M10 9H8\"></path><path d=\"M16 13H8\"></path><path d=\"M16 17H8\"></path>",
"Folder": "<path d=\"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z\"></path>",
"FolderKanban": "<path d=\"M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.93a2 2 0 0 1-1.66-.9l-.82-1.2A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13c0 1.1.9 2 2 2Z\"></path><path d=\"M8 10v4\"></path><path d=\"M12 10v2\"></path><path d=\"M16 10v6\"></path>",
"FolderOpen": "<path d=\"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2\"></path>",
"GitPullRequest": "<circle cx=\"18\" cy=\"18\" r=\"3\"></circle><circle cx=\"6\" cy=\"6\" r=\"3\"></circle><path d=\"M13 6h3a2 2 0 0 1 2 2v7\"></path><line x1=\"6\" x2=\"6\" y1=\"9\" y2=\"21\"></line>",
"GripVertical": "<circle cx=\"9\" cy=\"12\" r=\"1\"></circle><circle cx=\"9\" cy=\"5\" r=\"1\"></circle><circle cx=\"9\" cy=\"19\" r=\"1\"></circle><circle cx=\"15\" cy=\"12\" r=\"1\"></circle><circle cx=\"15\" cy=\"5\" r=\"1\"></circle><circle cx=\"15\" cy=\"19\" r=\"1\"></circle>",
"Heart": "<path d=\"M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5\"></path>",
"Home": "<path d=\"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8\"></path><path d=\"M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z\"></path>",
"House": "<path d=\"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8\"></path><path d=\"M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z\"></path>",
"Inbox": "<polyline points=\"22 12 16 12 14 15 10 15 8 12 2 12\"></polyline><path d=\"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z\"></path>",
"Layers": "<path d=\"M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z\"></path><path d=\"M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12\"></path><path d=\"M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17\"></path>",
"LayoutGrid": "<rect width=\"7\" height=\"7\" x=\"3\" y=\"3\" rx=\"1\"></rect><rect width=\"7\" height=\"7\" x=\"14\" y=\"3\" rx=\"1\"></rect><rect width=\"7\" height=\"7\" x=\"14\" y=\"14\" rx=\"1\"></rect><rect width=\"7\" height=\"7\" x=\"3\" y=\"14\" rx=\"1\"></rect>",
"ListTodo": "<path d=\"M13 5h8\"></path><path d=\"M13 12h8\"></path><path d=\"M13 19h8\"></path><path d=\"m3 17 2 2 4-4\"></path><rect x=\"3\" y=\"4\" width=\"6\" height=\"6\" rx=\"1\"></rect>",
"LoaderCircle": "<path d=\"M21 12a9 9 0 1 1-6.219-8.56\"></path>",
"Mail": "<path d=\"m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7\"></path><rect x=\"2\" y=\"4\" width=\"20\" height=\"16\" rx=\"2\"></rect>",
"MessageCircle": "<path d=\"M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719\"></path>",
"Minus": "<path d=\"M5 12h14\"></path>",
"Music": "<path d=\"M9 18V5l12-2v13\"></path><circle cx=\"6\" cy=\"18\" r=\"3\"></circle><circle cx=\"18\" cy=\"16\" r=\"3\"></circle>",
"NotebookTabs": "<path d=\"M2 6h4\"></path><path d=\"M2 10h4\"></path><path d=\"M2 14h4\"></path><path d=\"M2 18h4\"></path><rect width=\"16\" height=\"20\" x=\"4\" y=\"2\" rx=\"2\"></rect><path d=\"M15 2v20\"></path><path d=\"M15 7h5\"></path><path d=\"M15 12h5\"></path><path d=\"M15 17h5\"></path>",
"PackageCheck": "<path d=\"M12 22V12\"></path><path d=\"m16 17 2 2 4-4\"></path><path d=\"M21 11.127V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.729l7 4a2 2 0 0 0 2 .001l1.32-.753\"></path><path d=\"M3.29 7 12 12l8.71-5\"></path><path d=\"m7.5 4.27 8.997 5.148\"></path>",
"Palette": "<path d=\"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z\"></path><circle cx=\"13.5\" cy=\"6.5\" r=\".5\" fill=\"currentColor\"></circle><circle cx=\"17.5\" cy=\"10.5\" r=\".5\" fill=\"currentColor\"></circle><circle cx=\"6.5\" cy=\"12.5\" r=\".5\" fill=\"currentColor\"></circle><circle cx=\"8.5\" cy=\"7.5\" r=\".5\" fill=\"currentColor\"></circle>",
"PanelLeft": "<rect width=\"18\" height=\"18\" x=\"3\" y=\"3\" rx=\"2\"></rect><path d=\"M9 3v18\"></path>",
"Plus": "<path d=\"M5 12h14\"></path><path d=\"M12 5v14\"></path>",
"RadioTower": "<path d=\"M4.9 16.1C1 12.2 1 5.8 4.9 1.9\"></path><path d=\"M7.8 4.7a6.14 6.14 0 0 0-.8 7.5\"></path><circle cx=\"12\" cy=\"9\" r=\"2\"></circle><path d=\"M16.2 4.8c2 2 2.26 5.11.8 7.47\"></path><path d=\"M19.1 1.9a9.96 9.96 0 0 1 0 14.1\"></path><path d=\"M9.5 18h5\"></path><path d=\"m8 22 4-11 4 11\"></path>",
"Rocket": "<path d=\"M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5\"></path><path d=\"M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 0 0-2.91-.09\"></path><path d=\"M9 12a22 22 0 0 1 2-3.95A12.88 12.88 0 0 1 22 2c0 2.72-.78 7.5-6 11a22.4 22.4 0 0 1-4 2z\"></path><path d=\"M9 12H4s.55-3.03 2-4c1.62-1.08 5 .05 5 .05\"></path>",
"Search": "<path d=\"m21 21-4.34-4.34\"></path><circle cx=\"11\" cy=\"11\" r=\"8\"></circle>",
"Settings": "<path d=\"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915\"></path><circle cx=\"12\" cy=\"12\" r=\"3\"></circle>",
"ShieldCheck": "<path d=\"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z\"></path><path d=\"m9 12 2 2 4-4\"></path>",
"Sparkles": "<path d=\"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z\"></path><path d=\"M20 2v4\"></path><path d=\"M22 4h-4\"></path><circle cx=\"4\" cy=\"20\" r=\"2\"></circle>",
"Target": "<circle cx=\"12\" cy=\"12\" r=\"10\"></circle><circle cx=\"12\" cy=\"12\" r=\"6\"></circle><circle cx=\"12\" cy=\"12\" r=\"2\"></circle>",
"Undo2": "<path d=\"M9 14 4 9l5-5\"></path><path d=\"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11\"></path>",
"Workflow": "<rect width=\"8\" height=\"8\" x=\"3\" y=\"3\" rx=\"2\"></rect><path d=\"M7 11v4a2 2 0 0 0 2 2h4\"></path><rect width=\"8\" height=\"8\" x=\"13\" y=\"13\" rx=\"2\"></rect>",
"X": "<path d=\"M18 6 6 18\"></path><path d=\"m6 6 12 12\"></path>"
}
export type LucideName = string
export const LucideIcon = defineComponent({
name: 'LucideIcon',
props: { name: { type: String as PropType<LucideName>, required: true }, size: { type: Number, default: 16 }, strokeWidth: { type: Number, default: 2 } },
setup: props => () => h('svg', {
xmlns: 'http://www.w3.org/2000/svg', width: props.size, height: props.size, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor',
'stroke-width': props.strokeWidth, 'stroke-linecap': 'round', 'stroke-linejoin': 'round', 'aria-hidden': 'true', innerHTML: ICONS[props.name] ?? '',
}),
})
const items = [
{ id: 'brief', title: 'Release Brief', icon: 'FileText', description: 'Collect launch notes, owners, and risks in one compact handoff before the release window opens.' },
{ id: 'launch', title: 'Launch Checklist', icon: 'ShieldCheck', description: 'Verify copy, links, analytics, rollback steps, and final approvals without leaving the queue.' },
{ id: 'campaign', title: 'Campaign Notes', icon: 'RadioTower', description: 'Keep channel-specific notes close to the task while preserving a calm collapsed list.' },
{ id: 'calendar', title: 'Rollout Calendar', icon: 'CalendarClock', description: 'Plan announcements, staging checks, reminders, and quiet periods around the same timeline.' },
{ id: 'ship', title: 'Ship Build', icon: 'PackageCheck', description: 'Track the current artifact, deploy status, and final sign-off before marking the release complete.' },
{ id: 'archive', title: 'Archive Assets', icon: 'FolderKanban', description: 'Move final copy, images, and source files into the campaign folder once the rollout is done.' },
]
</script>
<template>
<div class="stage">
<div class="box">
<BouncyAccordion :items="items" default-value="calendar">
<template #icon="{ item }"><LucideIcon :name="item.icon!" :size="16" /></template>
</BouncyAccordion>
</div>
</div>
</template>
<style scoped>
.stage { display: flex; min-height: 24rem; width: 100%; align-items: center; justify-content: center; }
.box { width: 100%; max-width: 24rem; height: 480px; }
</style><script setup lang="ts">
import { LayoutGroup, motion } from 'motion-v'
import { useReducedMotion } from '../core/reduced-motion'
import { computed, reactive, shallowRef, useId, watch } from 'vue'
import { easeOut } from '../core/motion'
interface Item { id: string; title: string; description?: string; disabled?: boolean; icon?: string }
const { items, defaultValue = null, collapsible = true, classNames } = defineProps<{
items: readonly Item[]
/** Open row when uncontrolled (no `v-model`). */
defaultValue?: string | null
/** Allow closing the open row by activating it again. */
collapsible?: boolean
classNames?: { root?: string; item?: string; trigger?: string; icon?: string; title?: string; chevron?: string; content?: string; description?: string }
}>()
const model = defineModel<string | null>()
// Controlled when the parent binds `v-model`; otherwise the open row is local state seeded by `defaultValue`.
const local = shallowRef<string | null>(defaultValue)
const active = computed<string | null>({
get: () => (model.value !== undefined ? model.value : local.value),
set: value => { local.value = value; model.value = value },
})
defineSlots<{
/** Panel content of a row. Falls back to the item's `description`. */
default?: (props: { item: Item }) => unknown
/** Row title. Falls back to the item's `title`. */
title?: (props: { item: Item }) => unknown
/** Leading icon of a row. Falls back to the item's `icon` text. */
icon?: (props: { item: Item }) => unknown
}>()
const reduce = useReducedMotion()
const uid = useId()
// Local springs keep the accordion's connected groups moving together while
// avoiding scale projection on text-heavy row contents.
// Gap spring: must not overshoot y — positive y overshoot drifts items below
// their mt-3 resting point and briefly overlaps the next item.
const ROW_TRANSITION = { type: 'spring', duration: 0.55, bounce: 0.38 } as const
const CONTENT_OPEN_TRANSITION = { type: 'spring', duration: 0.58, bounce: 0.32 } as const
// The card, its panel and the rows below all share this one curve on close,
// so they bounce together. When the rows sprang on a different curve than the
// card, the next row overshot into the collapsed card, which read as a stutter.
const CLOSE_TRANSITION = { type: 'spring', duration: 0.55, bounce: 0.38 } as const
const DESCRIPTION_TRANSITION = { duration: 0.18, ease: easeOut } as const
const CHEVRON_TRANSITION = { type: 'spring', duration: 0.42, bounce: 0.28 } as const
const instant = { duration: 0 } as const
// The item that closed in the latest change, tracked before the render so the
// rows that move because of it pick the close curve in the same commit.
const closedId = shallowRef<string | null>(null)
watch(active, (next, previous) => {
if (previous !== next) closedId.value = previous
}, { flush: 'sync' })
const activeIndex = computed(() => items.findIndex(item => item.id === active.value))
const closedIndex = computed(() => items.findIndex(item => item.id === closedId.value))
// Panel heights, measured from the content the rows render and kept live so a
// reflowing description keeps the open panel the right size.
const heights = reactive<Record<string, number>>({})
const observers = new Map<string, ResizeObserver>()
function bindContent(id: string, element: Element | { $el?: unknown } | null) {
observers.get(id)?.disconnect()
observers.delete(id)
// A ref on a motion component resolves to its instance, not its node.
const node = element && '$el' in element ? element.$el : element
if (!(node instanceof HTMLElement)) return
const measure = () => { heights[id] = node.offsetHeight }
measure()
const observer = new ResizeObserver(measure)
observer.observe(node)
observers.set(id, observer)
}
function toggle(id: string) {
if (active.value === id) {
if (collapsible) active.value = null
return
}
active.value = id
}
function geometry(index: number) {
const open = active.value === items[index]!.id
const previousIsOpen = activeIndex.value === index - 1
const nextIsOpen = activeIndex.value === index + 1
return {
open,
startsGroup: open || index === 0 || previousIsOpen,
endsGroup: open || index === items.length - 1 || nextIsOpen,
separatedFromPrevious: index > 0 && (open || previousIsOpen),
// Rows at or below a closing item move with it, on its curve.
closing: closedIndex.value !== -1 && index >= closedIndex.value,
}
}
function panelHeight(item: Item, open: boolean) {
if (!item.description) return 0
if (!open) return 1
// Closed at 1px, not 0: a layout animation scales from the old size to the
// new one, and a 0px target has no finite scale, so the panel would snap
// shut instead of animating.
return heights[item.id] || 'auto'
}
</script>
<template>
<div class="be-accordion" :class="classNames?.root">
<!-- React measures every row before it writes any DOM. Vue patches the rows one after
another, so a row below the one that closed measured itself after that row had
already shrunk: it saw no move, jumped up under the collapsing card, and left a gap
as the card bounced. In a LayoutGroup the first row to measure makes them all
measure at once, before any of them changes. -->
<LayoutGroup>
<motion.div v-for="(item, index) in items" :key="item.id" layout="position" :initial="false"
:style="{ marginTop: geometry(index).separatedFromPrevious ? 12 : 0 }"
:transition="reduce ? instant : geometry(index).closing ? CLOSE_TRANSITION : ROW_TRANSITION">
<motion.div
:layout="!reduce"
:data-state="geometry(index).open ? 'open' : 'closed'"
:initial="false"
:animate="{
borderTopLeftRadius: geometry(index).startsGroup ? 28 : 0,
borderTopRightRadius: geometry(index).startsGroup ? 28 : 0,
borderBottomLeftRadius: geometry(index).endsGroup ? 28 : 0,
borderBottomRightRadius: geometry(index).endsGroup ? 28 : 0,
}"
:transition="reduce ? instant : { ...ROW_TRANSITION, layout: geometry(index).open ? CONTENT_OPEN_TRANSITION : CLOSE_TRANSITION }"
class="be-accordion-card" :class="[classNames?.item, item.disabled && 'be-accordion-disabled']">
<motion.button :layout="!reduce" :transition="reduce ? instant : { layout: geometry(index).open ? CONTENT_OPEN_TRANSITION : CLOSE_TRANSITION }"
:id="`${uid}-${item.id}-trigger`" type="button" :disabled="item.disabled"
:aria-expanded="geometry(index).open" :aria-controls="`${uid}-${item.id}-content`" class="be-accordion-trigger" :class="classNames?.trigger"
@click="toggle(item.id)">
<span v-if="item.icon || $slots.icon" class="be-accordion-icon" :class="classNames?.icon" aria-hidden="true"><slot name="icon" :item="item">{{ item.icon }}</slot></span>
<span class="be-accordion-title" :class="classNames?.title"><slot name="title" :item="item">{{ item.title }}</slot></span>
<motion.span aria-hidden="true" class="be-accordion-chevron" :class="classNames?.chevron"
:animate="{ rotate: geometry(index).open ? 180 : 0 }" :transition="reduce ? instant : CHEVRON_TRANSITION" :initial="false">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6" /></svg>
</motion.span>
</motion.button>
<motion.section :layout="!reduce" :id="`${uid}-${item.id}-content`" :aria-labelledby="`${uid}-${item.id}-trigger`"
:aria-hidden="!geometry(index).open" :inert="!geometry(index).open" :initial="false"
:style="{ height: panelHeight(item, geometry(index).open), originY: 0 }"
:transition="reduce ? instant : geometry(index).open ? CONTENT_OPEN_TRANSITION : CLOSE_TRANSITION"
class="be-accordion-panel" :class="classNames?.content">
<motion.div :ref="element => bindContent(item.id, element)"
:layout="!reduce" :initial="false" :animate="{ opacity: geometry(index).open ? 1 : 0 }"
:transition="reduce ? instant : { ...DESCRIPTION_TRANSITION, layout: geometry(index).open ? CONTENT_OPEN_TRANSITION : CLOSE_TRANSITION }"
class="be-accordion-body">
<div class="be-accordion-description" :class="classNames?.description">
<slot :item="item">{{ item.description }}</slot>
</div>
</motion.div>
</motion.section>
</motion.div>
</motion.div>
</LayoutGroup>
</div>
</template>
<style scoped>
.be-accordion { width: 100%; }
.be-accordion-card { overflow: hidden; background: var(--beui-card); color: var(--beui-foreground); }
.be-accordion-disabled { opacity: .5; }
.be-accordion-trigger { display: flex; box-sizing: border-box; width: 100%; min-height: 54px; align-items: center; gap: 1rem; padding: 0 1.25rem; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.be-accordion-trigger { transition: color .15s cubic-bezier(.4, 0, .2, 1), background-color .15s cubic-bezier(.4, 0, .2, 1), border-color .15s cubic-bezier(.4, 0, .2, 1); }
.be-accordion-trigger:focus-visible { outline: none; background: color-mix(in srgb, var(--beui-muted) 25%, transparent); }
.be-accordion-trigger:disabled { pointer-events: none; }
.be-accordion-icon { display: grid; height: 1.75rem; width: 1.75rem; flex: none; place-items: center; color: var(--beui-muted-foreground); }
.be-accordion-title { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; font-weight: 500; color: var(--beui-foreground); }
.be-accordion-chevron { display: grid; height: 1.5rem; width: 1.5rem; flex: none; place-items: center; color: var(--beui-muted-foreground); }
.be-accordion-chevron svg { width: 1rem; height: 1rem; }
.be-accordion-panel { overflow: hidden; }
.be-accordion-body { padding: 0 1.25rem 1.25rem; }
.be-accordion-description { font-size: 15px; line-height: 1.5rem; color: var(--beui-muted-foreground); }
</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/bouncy-accordion$ 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 BouncyAccordion from '@/components/beui/layout/BouncyAccordion.vue'
import '@/components/beui/styles.css'API Reference
itemsreadonly Item[]—v-model?string | null—defaultValue?string | nullOpen row when uncontrolled (no `v-model`).
nullcollapsible?booleanAllow closing the open row by activating it again.
trueclass?string—classNames?{ root?: string; item?: string; trigger?: string; icon?: string; title?: string; chevron?: string; content?: string; description?: string }—#default?slotPanel content of a row. Falls back to the item's `description`.
—#title?slotRow title. Falls back to the item's `title`.
—#icon?slotLeading icon of a row. Falls back to the item's `icon` text.
—Related components
Table
Virtualized data table that stays smooth at 10k+ rows, with sortable headers, row selection, column resize and reorder, and a sticky header. Minimal, reduced-motion-safe motion.
Sortable List
Composable sortable list with group, item, drag handle, content and undo parts, plus a shared state hook. Spring layout, keyboard reordering, accessible position announcements, and controlled or uncontrolled items.
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.
Updated