Overflow Actions
Preview
<script setup lang="ts">
import { ref } from 'vue'
import { OverflowActions } from 'beui-vue'
// lucide Eye, Pin, GitBranch, CalendarClock.
const icons: Record<string, string> = {
preview: '<path d="M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"/><circle cx="12" cy="12" r="3"/>',
pin: '<path d="M12 17v5"/><path d="M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z"/>',
branch: '<line x1="6" x2="6" y1="3" y2="15"/><circle cx="18" cy="6" r="3"/><circle cx="6" cy="18" r="3"/><path d="M18 9a9 9 0 0 1-9 9"/>',
schedule: '<path d="M16 14v2.2l1.6 1"/><path d="M16 2v4"/><path d="M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5"/><path d="M3 10h5"/><path d="M8 2v4"/><circle cx="16" cy="16" r="6"/>',
}
const primaryActions = [{ id: 'preview', label: 'Preview' }, { id: 'pin', label: 'Pin' }]
const overflowActions = [{ id: 'branch', label: 'Branch' }, { id: 'schedule', label: 'Schedule' }]
const expanded = ref(false)
</script>
<template>
<div class="overflow-stage">
<OverflowActions v-model:expanded="expanded" :primary-actions="primaryActions" :overflow-actions="overflowActions"
open-label="Open action rail" close-label="Collapse action rail">
<template #icon="{ item }">
<svg viewBox="0 0 24 24" aria-hidden="true" class="overflow-svg" v-html="icons[item.id]" />
</template>
</OverflowActions>
</div>
</template>
<style scoped>
.overflow-stage { display: flex; width: 100%; align-items: center; justify-content: center; }
.overflow-svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
</style><script lang="ts">
export type OverflowActionsSize = 'sm' | 'md'
export type OverflowActionItem = {
id: string
label: string
icon?: string
onClick?: () => void
disabled?: boolean
ariaLabel?: string
}
export type OverflowActionsClassNames = {
root?: string
track?: string
action?: string
primaryAction?: string
overflowAction?: string
toggle?: string
icon?: string
label?: string
}
</script>
<script setup lang="ts">
import { AnimatePresence, motion, mountedStates } from 'motion-v'
import { useReducedMotion } from '../core/reduced-motion'
import { computed, onBeforeUnmount, onBeforeUpdate, useId, useTemplateRef, watch } from 'vue'
import { easeOut } from '../core/motion'
import { useMountedMedia } from '../core/mounted-media'
import { useOpenState } from '../primitives/state'
import { overflowActionsMessages } from './messages'
import OverflowActionButton from './OverflowActionButton.vue'
const props = withDefaults(defineProps<{
primaryActions: readonly OverflowActionItem[]
overflowActions: readonly OverflowActionItem[]
expanded?: boolean
defaultExpanded?: boolean
collapseOnAction?: boolean
/** Default `md`. */
size?: OverflowActionsSize
openLabel?: string
closeLabel?: string
/** Override any built-in string. */
labels?: Partial<typeof overflowActionsMessages>
className?: string
classNames?: OverflowActionsClassNames
}>(), { expanded: undefined, defaultExpanded: false, collapseOnAction: false, size: 'md' })
const emit = defineEmits<{
'update:expanded': [value: boolean]
expandedChange: [value: boolean]
action: [item: OverflowActionItem]
}>()
defineSlots<{
/** Replaces an action's icon. */
icon?(props: { item: OverflowActionItem }): unknown
}>()
// This needs a softer layout spring than the app defaults so the overflow group
// stays visually attached to the toggle while entering and leaving.
const SHELL_TRANSITION = { type: 'spring', stiffness: 220, damping: 17, mass: 0.85 } as const
const ICON_VARIANTS = {
hidden: { opacity: 0, filter: 'blur(3px)' },
visible: { opacity: 1, filter: 'blur(0px)', transition: { duration: 0.18, ease: easeOut } },
exit: { opacity: 0, filter: 'blur(3px)', transition: { duration: 0.18, ease: easeOut } },
}
const reduceMotion = useReducedMotion()
const reduce = computed(() => Boolean(reduceMotion.value))
const canHover = useMountedMedia('(hover: hover) and (pointer: fine)')
const t = computed(() => ({ ...overflowActionsMessages, ...props.labels }))
const overflowId = `be-overflow-${useId().replace(/[^a-zA-Z0-9_-]/g, '')}`
const { open: isExpanded, setOpen: setExpanded } = useOpenState(
() => props.expanded,
props.defaultExpanded,
next => { emit('update:expanded', next); emit('expandedChange', next) },
)
const transition = computed(() => (reduce.value ? { duration: 0 } : SHELL_TRANSITION))
const toggleLabel = computed(() => (isExpanded.value ? (props.closeLabel ?? t.value.close) : (props.openLabel ?? t.value.open)))
// The overflow group leaves with `popLayout`, which takes it out of flow. Pin it
// to the viewport position it held while open so it fades where it was instead
// of sliding along with the toggle.
let overflowNode: HTMLElement | null = null
let overflowLeft = 0
function setOverflowNode(element: unknown) {
if (!element) return
const node = (element as { $el?: unknown }).$el ?? element
if (node instanceof HTMLElement) overflowNode = node
}
watch(isExpanded, expanded => {
const node = overflowNode
if (!node) return
if (!expanded) {
node.style.left = `${overflowLeft - node.getBoundingClientRect().left}px`
return
}
node.style.left = ''
overflowLeft = node.getBoundingClientRect().left
}, { flush: 'post' })
onBeforeUnmount(() => { overflowNode = null })
// React measures every layout box before any of the commit's DOM changes. A
// motion component here measures in its own beforeUpdate, which runs after the
// siblings before it have already patched, so the toggle would be measured
// where the new actions already pushed it and never glide. Measuring the
// shells, the actions and the toggle from this component's beforeUpdate, which
// runs before any of them patches, restores that.
const root = useTemplateRef<{ $el?: HTMLElement }>('root')
onBeforeUpdate(() => {
const el = root.value?.$el
if (!el || reduce.value) return
const nodes = [el, ...el.querySelectorAll<HTMLElement>('.be-overflow-track, .be-overflow-group, .be-overflow-cell, .be-overflow-toggle')]
for (const node of nodes) {
const state = mountedStates.get(node)
if (state && !state.isExiting) state.getSnapshot(true)
}
})
function handleAction(item: OverflowActionItem) {
item.onClick?.()
emit('action', item)
if (props.collapseOnAction) setExpanded(false)
}
const actionClass = (extra?: string) => [props.classNames?.action, extra].filter(Boolean).join(' ')
</script>
<template>
<motion.div ref="root" layout :transition="transition" class="be-overflow" :class="[classNames?.root, className]">
<motion.div layout :transition="transition" class="be-overflow-track" :class="[`is-${size}`, classNames?.track]">
<motion.div layout :transition="transition" class="be-overflow-group" :class="`is-${size}`">
<OverflowActionButton v-for="item in primaryActions" :key="item.id" :item="item" :size="size" :reduce="reduce" :can-hover="canHover"
:layout-transition="transition" :class-name="actionClass(classNames?.primaryAction)"
:icon-class-name="classNames?.icon" :label-class-name="classNames?.label" @action="handleAction">
<template v-if="$slots.icon" #icon="slotProps"><slot name="icon" v-bind="slotProps" /></template>
</OverflowActionButton>
</motion.div>
<AnimatePresence mode="popLayout" :initial="false">
<motion.div v-if="isExpanded" :ref="setOverflowNode" key="overflow-actions" :id="overflowId" layout :aria-hidden="!isExpanded"
:transition="transition" class="be-overflow-group be-overflow-extra" :class="`is-${size}`">
<OverflowActionButton v-for="item in overflowActions" :key="item.id" :item="item" :size="size" :reduce="reduce" :can-hover="canHover"
overflow :visible="isExpanded" :layout-transition="transition" :class-name="actionClass(classNames?.overflowAction)"
:icon-class-name="classNames?.icon" :label-class-name="classNames?.label" @action="handleAction">
<template v-if="$slots.icon" #icon="slotProps"><slot name="icon" v-bind="slotProps" /></template>
</OverflowActionButton>
</motion.div>
</AnimatePresence>
<motion.button
type="button"
layout
class="be-overflow-toggle"
:class="[`is-${size}`, classNames?.toggle]"
:aria-expanded="isExpanded"
:aria-controls="isExpanded ? overflowId : undefined"
:aria-label="toggleLabel"
:title="toggleLabel"
:while-press="reduce ? undefined : { scale: 0.96 }"
:while-hover="reduce || !canHover ? undefined : { scale: 1.03 }"
:transition="transition"
@click="setExpanded(!isExpanded)">
<AnimatePresence mode="popLayout" :initial="false">
<motion.span :key="isExpanded ? 'close' : 'open'" :variants="ICON_VARIANTS" :initial="reduce ? { opacity: 0 } : 'hidden'"
:animate="reduce ? { opacity: 1 } : 'visible'" :exit="reduce ? { opacity: 0 } : 'exit'" class="be-overflow-toggle-icon">
<svg v-if="isExpanded" viewBox="0 0 24 24" aria-hidden="true" :class="`is-${size}`"><path d="M18 6 6 18" /><path d="m6 6 12 12" /></svg>
<svg v-else viewBox="0 0 24 24" aria-hidden="true" :class="`is-${size}`"><circle cx="12" cy="12" r="1" /><circle cx="19" cy="12" r="1" /><circle cx="5" cy="12" r="1" /></svg>
</motion.span>
</AnimatePresence>
</motion.button>
</motion.div>
</motion.div>
</template>
<style scoped>
.be-overflow { display: inline-flex; color: var(--beui-foreground); }
.be-overflow-track { position: relative; display: inline-flex; align-items: center; overflow: hidden; box-sizing: border-box; border: 1px solid var(--beui-border); border-radius: 9999px; background: var(--beui-card); }
.be-overflow-track.is-sm { gap: .25rem; padding: .25rem; font-size: .75rem; line-height: 1rem; }
.be-overflow-track.is-md { gap: .375rem; padding: .375rem; font-size: .875rem; line-height: 1.25rem; }
.be-overflow-group { display: inline-flex; align-items: center; }
.be-overflow-group.is-sm { gap: .25rem; }
.be-overflow-group.is-md { gap: .375rem; }
.be-overflow-extra { position: relative; width: max-content; }
.be-overflow-toggle { position: relative; display: inline-grid; flex: none; place-items: center; margin: 0; padding: 0; border: 0; border-radius: 9999px; background: var(--beui-primary); color: var(--beui-primary-foreground); cursor: pointer; outline: none; }
.be-overflow-toggle:disabled { pointer-events: none; opacity: .5; }
.be-overflow-toggle:focus-visible { box-shadow: 0 0 0 2px var(--beui-background), 0 0 0 4px var(--beui-ring); }
.be-overflow-toggle.is-sm { width: 2rem; height: 2rem; }
.be-overflow-toggle.is-md { width: 2.25rem; height: 2.25rem; }
.be-overflow-toggle-icon { display: inline-grid; place-items: center; }
.be-overflow-toggle svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.be-overflow-toggle svg.is-sm { width: .875rem; height: .875rem; }
.be-overflow-toggle svg.is-md { width: 1rem; height: 1rem; }
</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/overflow-actions$ 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 OverflowActions from '@/components/beui/blocks/OverflowActions.vue'
import '@/components/beui/styles.css'API Reference
primaryActionsreadonly OverflowActionItem[]—overflowActionsreadonly OverflowActionItem[]—v-model:expanded?booleanundefineddefaultExpanded?booleanfalse@action?(item: OverflowActionItem) => void—collapseOnAction?booleanfalsesize?OverflowActionsSizeDefault `md`.
mdopenLabel?string—closeLabel?string—labels?Partial<typeof overflowActionsMessages>Override any built-in string.
—className?string—classNames?OverflowActionsClassNames—@expanded-change?(value: boolean) => void—#icon?{ item: OverflowActionItem }Replaces an action's icon.
—Related components
Expandable Action Bar
Compact icon actions that expand into labeled controls on hover or focus with shared layout motion.
Expandable Tabs
Icon tab bar where the active tab expands to a labelled pill, with a panel above that morphs height and slides content direction-aware on switch.
Bloom Menu
A button that morphs open into a menu and blooms iris-out from the center, the grid revealing in every direction with radially staggered items.
Updated