Button
Metallic Button
MetallicButton.vue<script setup lang="ts">
import { MetallicButton } from 'beui-vue'
</script>
<template>
<div class="row">
<MetallicButton>Continue <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M7 7h10v10" /><path d="M7 17 17 7" /></svg></MetallicButton>
<MetallicButton size="sm"><svg class="small" viewBox="0 0 24 24" aria-hidden="true"><path d="M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z" /><path d="M20 3v4" /><path d="M22 5h-4" /><path d="M4 17v2" /><path d="M5 18H3" /></svg>Generate</MetallicButton>
<MetallicButton size="icon" aria-label="Magic tools"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z" /><path d="M20 3v4" /><path d="M22 5h-4" /><path d="M4 17v2" /><path d="M5 18H3" /></svg></MetallicButton>
</div>
</template>
<style scoped>
.row { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .75rem; padding: 2.5rem 1.5rem; }
.row svg { width: 1rem; height: 1rem; flex: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; fill: none; }
.row svg.small { width: .875rem; height: .875rem; }
</style><script setup lang="ts">
import ButtonBase from '../ButtonBase.vue'
const {paused = false, size = 'md', pressScale} = defineProps<{
/** Stops the traveling reflection while preserving the chrome rim. */
paused?: boolean
size?: 'sm' | 'md' | 'lg' | 'icon'
pressScale?: number
}>()
</script>
<template>
<ButtonBase class="chrome" variant="ghost" :size="size" :press-scale="pressScale" :data-paused="paused"><span class="rim" aria-hidden="true" /><span class="reflection" aria-hidden="true" /><span class="inset" aria-hidden="true" /><span class="label"><slot /></span></ButtonBase>
</template>
<style scoped>
/* Outranks ButtonBase's ghost variant (colour, hover tint, icon radius), which is scoped to its own component. */
.be-button.chrome[data-variant] { isolation:isolate; position:relative; overflow:hidden; border:0; background:transparent; box-shadow:0 8px 22px rgb(0 0 0 / .16); color:var(--beui-foreground); }
.be-button.chrome[data-size=icon] { border-radius:999px; }
.be-button.chrome[data-variant]:focus-visible { outline:2px solid var(--beui-ring); outline-offset:2px; }
@media (hover:hover) { .be-button.chrome[data-variant]:hover { background:transparent; color:var(--beui-foreground); } }
.chrome > span:not(.label) { position:absolute; pointer-events:none; }
.rim { inset:0 -18%; background:linear-gradient(105deg,#111,#737373 14%,#fafafa 26%,#525252 38%,#0a0a0a 50%,#a3a3a3 64%,white 75%,#404040 87%,#111); }
.reflection { inset:0 auto 0 -58%; width:52%; background:linear-gradient(90deg,transparent,#ffffff80 48%,transparent); opacity:.5; filter:blur(3px); mix-blend-mode:screen; transform:skewX(-12deg); }
.inset { inset:2px; border-radius:inherit; background:var(--beui-background); box-shadow:inset 0 1px 0 #ffffff47,inset 0 -1px 0 #00000029; transition:background-color .15s cubic-bezier(.4,0,.2,1); }
@media (hover:hover) { .chrome:hover .inset { background:color-mix(in oklab, var(--beui-muted) 40%, transparent); } }
.label { position:relative; display:inline-flex; align-items:center; gap:.5rem; }
@media (prefers-reduced-motion:no-preference) {
.chrome:not([data-paused=true]) .rim { animation:beui-rim 8s cubic-bezier(.77,0,.175,1) infinite; }
.chrome:not([data-paused=true]) .reflection { transition:transform 2.4s cubic-bezier(.77,0,.175,1); }
.chrome:not([data-paused=true]):hover .reflection { transform:translateX(310%) skewX(-12deg); }
}
@keyframes beui-rim { 50% { transform:translateX(13%); } }
</style>Install
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/button-metallic$ 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 MetallicButton from '@/components/beui/actions/MetallicButton.vue'
import '@/components/beui/styles.css'API Reference
class?string—size?"sm" | "md" | "lg" | "icon"mdpressScale?number—paused?booleanStops the traveling reflection while preserving the chrome rim.
falseButton
ButtonBase.vue<script setup lang="ts">
import { ButtonBase } from 'beui-vue'
</script>
<template>
<div class="button-demo">
<div class="row">
<ButtonBase variant="primary" size="md">Continue <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12h14" /><path d="m12 5 7 7-7 7" /></svg></ButtonBase>
<ButtonBase variant="secondary" size="md"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" /><path d="m7 10 5 5 5-5" /><path d="M12 15V3" /></svg>Download</ButtonBase>
<ButtonBase variant="outline" size="md">Outline</ButtonBase>
<ButtonBase variant="ghost" size="md">Ghost</ButtonBase>
</div>
<div class="row">
<ButtonBase variant="primary" size="sm">Small</ButtonBase>
<ButtonBase variant="primary" size="md">Medium</ButtonBase>
<ButtonBase variant="primary" size="lg">Large</ButtonBase>
<ButtonBase variant="secondary" size="icon" aria-label="Delete"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M3 6h18" /><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6" /><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2" /><path d="M10 11v6" /><path d="M14 11v6" /></svg></ButtonBase>
</div>
<div class="row">
<ButtonBase variant="primary" size="md" ripple>Ripple</ButtonBase>
<ButtonBase variant="outline" size="md" ripple>Tap me</ButtonBase>
</div>
</div>
</template>
<style scoped>
.button-demo { display: flex; flex-direction: column; align-items: center; gap: 1.5rem; }
.row { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .75rem; }
.row svg { width: 1rem; height: 1rem; flex: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; fill: none; }
</style><script setup lang="ts">
import { motion } from 'motion-v'
import { useReducedMotion } from './core/reduced-motion'
import { shallowRef } from 'vue'
import { easeOut, pressSpring } from './core/motion'
import { useMountedMedia } from './core/mounted-media'
const { variant = 'primary', size = 'md', pressScale = 0.93, ripple = false, disabled = false, type = 'button', href, hover = true } = defineProps<{
variant?: 'primary' | 'secondary' | 'ghost' | 'outline'
size?: 'sm' | 'md' | 'lg' | 'icon'
pressScale?: number
/** Set false to drop the hover lift (stateful buttons keep only the press). */
hover?: boolean
ripple?: boolean
disabled?: boolean
type?: 'button' | 'submit' | 'reset'
href?: string
}>()
const emit = defineEmits<{ click: [event: MouseEvent] }>()
const reduce = useReducedMotion()
// Hover lift is gated on a true hover device: touch fires a sticky phantom :hover on tap.
const canHover = useMountedMedia('(hover: hover) and (pointer: fine)')
const ripples = shallowRef<{ id: number; size: number; left: number; top: number }[]>([])
let seed = 0
function press(event: PointerEvent) {
if (!ripple || disabled || reduce.value || event.button !== 0) return
const rect = (event.currentTarget as HTMLElement).getBoundingClientRect()
const size = Math.max(rect.width, rect.height) * 2
ripples.value = [...ripples.value, { id: ++seed, size, left: event.clientX - rect.left - size / 2, top: event.clientY - rect.top - size / 2 }]
}
function activate(event: MouseEvent) {
if (disabled) event.preventDefault()
else emit('click', event)
}
</script>
<template>
<component :is="href !== undefined ? motion.a : motion.button" class="be-button" :data-variant="variant" :data-size="size"
:type="href === undefined ? type : undefined" :href="disabled ? undefined : href" :disabled="href === undefined ? disabled : undefined"
:role="href !== undefined && disabled ? 'link' : undefined" :aria-disabled="href !== undefined && disabled || undefined"
:while-press="!reduce && !disabled ? { scale: pressScale } : undefined" :while-hover="!reduce && hover && canHover && !disabled ? { scale: 1.02 } : undefined"
:transition="pressSpring" @pointerdown="press" @click="activate">
<span v-if="ripple" class="be-ripple-mask" aria-hidden="true">
<motion.span v-for="drop in ripples" :key="drop.id" class="be-ripple"
:style="{ left: `${drop.left}px`, top: `${drop.top}px`, width: `${drop.size}px`, height: `${drop.size}px` }"
:initial="{ scale: 0.05, opacity: 0.3 }" :animate="{ scale: 1, opacity: 0 }" :transition="{ duration: 1.6, ease: easeOut }"
@animation-complete="ripples = ripples.filter(item => item.id !== drop.id)" />
</span>
<slot />
</component>
</template>
<style scoped>
.be-button { position: relative; box-sizing: border-box; display: inline-flex; align-items: center; justify-content: center; flex: none; height: 2.5rem; gap: .5rem; padding: 0 1.25rem; border: 0 solid var(--beui-border); border-radius: 999px; font: inherit; font-size: .875rem; font-weight: 500; line-height: 1.25rem; text-decoration: none; user-select: none; cursor: pointer; 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-button[data-variant=primary] { background: var(--beui-primary); color: var(--beui-primary-foreground); }
.be-button[data-variant=secondary] { background: var(--beui-card); color: var(--beui-foreground); border-width: 1px; }
.be-button[data-variant=outline] { background: transparent; color: var(--beui-foreground); border-width: 1px; }
.be-button[data-variant=ghost] { background: transparent; color: var(--beui-muted-foreground); }
.be-button[data-size=sm] { height: 2rem; padding: 0 .75rem; font-size: .75rem; line-height: 1rem; gap: .375rem; }
.be-button[data-size=lg] { height: 3rem; padding: 0 1.5rem; font-size: 1rem; line-height: 1.5rem; }
.be-button[data-size=icon] { height: 2rem; width: 2rem; padding: 0; border-radius: .5rem; }
.be-button:disabled, .be-button[aria-disabled=true] { opacity: .5; cursor: default; pointer-events: none; }
.be-ripple-mask { position: absolute; inset: 0; pointer-events: none; overflow: hidden; border-radius: inherit; }
.be-ripple { position: absolute; border-radius: 50%; background: currentColor; }
@media (hover: hover) { .be-button[data-variant=primary]:hover { background: color-mix(in oklab, var(--beui-primary) 90%, transparent); } .be-button:is([data-variant=ghost], [data-variant=outline]):hover { color: var(--beui-foreground); background: color-mix(in oklab, var(--beui-muted) 60%, transparent); } }
</style>Install
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/button-base$ 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 ButtonBase from '@/components/beui/ButtonBase.vue'
import '@/components/beui/styles.css'API Reference
Button
class?string—size?"sm" | "md" | "lg" | "icon"mdvariant?"primary" | "secondary" | "ghost" | "outline"primarypressScale?number0.93ripple?booleanSpawn a Material-style ripple from the press point. Off by default.
falsehover?booleanSet false to drop the hover lift (stateful buttons keep only the press).
truedisabled?booleanfalsetype?"button" | "submit" | "reset"buttonhref?string—@click?(event: MouseEvent) => void—ButtonLink
class?string—size?"sm" | "md" | "lg" | "icon"mdvariant?"primary" | "secondary" | "ghost" | "outline"primarypressScale?number0.93href?stringStateful Button
StatefulButton.vue<script setup lang="ts">
import { onBeforeUnmount, ref } from 'vue'
import { StatefulButton } from 'beui-vue'
type ButtonState = 'idle' | 'loading' | 'success' | 'error'
const okState = ref<ButtonState>('idle')
const errState = ref<ButtonState>('idle')
const timers = new Set<ReturnType<typeof setTimeout>>()
function later(callback: () => void, delay: number) {
const id = setTimeout(() => { timers.delete(id); callback() }, delay)
timers.add(id)
}
function run(target: 'ok' | 'err') {
const state = target === 'ok' ? okState : errState
state.value = 'loading'
later(() => {
state.value = target === 'ok' ? 'success' : 'error'
later(() => { state.value = 'idle' }, 1800)
}, 1400)
}
onBeforeUnmount(() => timers.forEach(clearTimeout))
</script>
<template>
<div class="stateful-demo">
<StatefulButton :state="okState" variant="primary" size="md" loading-text="Saving" success-text="Saved" @click="run('ok')">
Save changes
<template #icon>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14" /><path d="m12 5 7 7-7 7" /></svg>
</template>
</StatefulButton>
<StatefulButton :state="errState" variant="secondary" size="md" loading-text="Submitting" error-text="Failed" @click="run('err')">Submit</StatefulButton>
</div>
</template>
<style scoped>
.stateful-demo { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .75rem; }
</style><script lang="ts">
export type ButtonState = 'idle' | 'loading' | 'success' | 'error'
/** English defaults. Override per instance with `labels`. */
export const statefulButtonMessages = {
loading: 'Loading',
success: 'Done',
error: 'Try again',
}
export type StatefulButtonMessages = typeof statefulButtonMessages
</script>
<script setup lang="ts">
import { AnimatePresence, motion } from 'motion-v'
import { useReducedMotion } from '../core/reduced-motion'
import { Comment, computed, Fragment, nextTick, onMounted, shallowRef, Text, useSlots, useTemplateRef, watch, type VNode } from 'vue'
import ButtonBase from '../ButtonBase.vue'
import { easeOut, swapSpring } from '../core/motion'
const props = defineProps<{
state?: ButtonState
variant?: 'primary' | 'secondary' | 'ghost' | 'outline'
size?: 'sm' | 'md' | 'lg' | 'icon'
pressScale?: number
/** Spawn a Material-style ripple from the press point. Off by default. */
ripple?: boolean
disabled?: boolean
loadingText?: string
successText?: string
errorText?: string
/** Override any built-in string. */
labels?: Partial<StatefulButtonMessages>
}>()
defineSlots<{
/** The idle label. */
default(): unknown
/** Shown after the idle label while the button is idle. */
icon?(): unknown
}>()
const CASCADE_STAGGER = 0.025
const ROLL_BLUR = 'blur(6px)'
const slots = useSlots()
const reduce = useReducedMotion()
const state = computed(() => props.state ?? 'idle')
const busy = computed(() => state.value === 'loading')
const strings = computed(() => ({ ...statefulButtonMessages, ...props.labels }))
function textOf(nodes: VNode[] | undefined): string | null {
let out = ''
for (const node of nodes ?? []) {
if (node.type === Comment) continue
if (node.type === Text || typeof node.children === 'string') {
out += String(node.children)
} else if (node.type === Fragment && Array.isArray(node.children)) {
const inner = textOf(node.children as VNode[])
if (inner === null) return null
out += inner
} else return null
}
return out
}
// A plain-string label cascades letter by letter; rich content swaps as one block.
const idleLabel = computed(() => {
const content = slots.default?.()
return textOf(content)?.replace(/\s+/g, ' ').trim() ?? null
})
const stateLabel = computed<string | null>(() => {
if (state.value === 'loading') return props.loadingText ?? strings.value.loading
if (state.value === 'success') return props.successText ?? strings.value.success
if (state.value === 'error') return props.errorText ?? strings.value.error
return idleLabel.value
})
const textKey = computed(() => (stateLabel.value !== null ? `${state.value}-${stateLabel.value}` : state.value))
const cascade = computed(() => stateLabel.value !== null && !reduce.value)
const letters = computed(() => (stateLabel.value ?? '').split(''))
const iconIn = { opacity: 0, width: 0, scale: 0.7, filter: ROLL_BLUR }
const iconRest = { opacity: 1, width: '1.5rem', scale: 1, filter: 'blur(0px)', transition: swapSpring }
const iconOut = { opacity: 0, width: 0, scale: 0.7, filter: ROLL_BLUR, transition: { duration: 0.16, ease: easeOut } }
const iconMotion = computed(() => reduce.value
? { initial: { opacity: 0 }, animate: { opacity: 1, transition: { duration: 0.15 } }, exit: { opacity: 0, transition: { duration: 0.15 } } }
: { initial: iconIn, animate: iconRest, exit: iconOut })
function letterMotion(index: number) {
const delay = index * CASCADE_STAGGER
return {
initial: { opacity: 0, y: '105%', filter: ROLL_BLUR },
animate: { opacity: 1, y: '0%', filter: 'blur(0px)', transition: { ...swapSpring, delay } },
exit: { opacity: 0, y: '-105%', filter: ROLL_BLUR, transition: { duration: 0.16, ease: easeOut, delay: delay * 0.5 } },
}
}
const blockMotion = computed(() => reduce.value
? { initial: { opacity: 0 }, animate: { opacity: 1, transition: { duration: 0.15 } }, exit: { opacity: 0, transition: { duration: 0.15 } } }
: {
initial: { opacity: 0, y: 14, filter: ROLL_BLUR },
animate: { opacity: 1, y: 0, filter: 'blur(0px)', transition: swapSpring },
exit: { opacity: 0, y: -14, filter: ROLL_BLUR, transition: swapSpring },
})
// The slot width follows the invisible measuring copy, so the button grows and
// shrinks around the label with the same spring as the text swap.
const measure = useTemplateRef<HTMLElement>('measure')
const width = shallowRef<number>()
function syncWidth() {
const next = measure.value?.offsetWidth
if (next && next !== width.value) width.value = next
}
onMounted(() => {
syncWidth()
// The label is measured with the fallback font when the web font is still loading; measure again
// once it is in, or the last glyph is clipped by the narrower slot.
void document.fonts?.ready.then(syncWidth)
})
watch([textKey, cascade], () => nextTick(syncWidth), { flush: 'post' })
</script>
<template>
<ButtonBase :variant="variant" :size="size" :press-scale="pressScale" :ripple="ripple" :disabled="disabled || busy" :aria-busy="busy" :hover="false">
<span class="be-stateful-row" aria-live="polite">
<AnimatePresence :initial="false">
<motion.span v-if="state === 'loading'" key="loading-icon" class="be-stateful-icon" v-bind="iconMotion">
<svg class="be-stateful-svg be-stateful-spin" viewBox="0 0 24 24" aria-hidden="true"><path d="M21 12a9 9 0 1 1-6.219-8.56" /></svg>
</motion.span>
<motion.span v-else-if="state === 'success'" key="success-icon" class="be-stateful-icon" v-bind="iconMotion">
<svg class="be-stateful-svg" viewBox="0 0 24 24" aria-hidden="true"><path d="M20 6 9 17l-5-5" /></svg>
</motion.span>
<motion.span v-else-if="state === 'error'" key="error-icon" class="be-stateful-icon" v-bind="iconMotion">
<svg class="be-stateful-svg" viewBox="0 0 24 24" aria-hidden="true"><path d="M18 6 6 18" /><path d="m6 6 12 12" /></svg>
</motion.span>
</AnimatePresence>
<motion.span class="be-stateful-text" :initial="false" :animate="{ width }" :transition="reduce ? { duration: 0 } : swapSpring">
<span ref="measure" class="be-stateful-measure" aria-hidden="true">
<template v-if="cascade"><span v-for="(char, index) in letters" :key="index" class="be-stateful-letter">{{ char }}</span></template>
<template v-else-if="state === 'idle' && stateLabel === null"><slot /></template>
<template v-else>{{ stateLabel }}</template>
</span>
<template v-if="cascade">
<span class="be-stateful-sr">{{ stateLabel }}</span>
<AnimatePresence :initial="false">
<motion.span :key="`cascade-${textKey}`" aria-hidden="true" class="be-stateful-layer" initial="initial" animate="animate" exit="exit">
<motion.span
v-for="(char, index) in letters"
:key="index"
v-bind="letterMotion(index)"
class="be-stateful-letter be-stateful-letter-live"
>{{ char }}</motion.span>
</motion.span>
</AnimatePresence>
</template>
<AnimatePresence v-else :initial="false">
<motion.span :key="`text-${textKey}`" class="be-stateful-layer be-stateful-block" v-bind="blockMotion">
<slot v-if="state === 'idle' && stateLabel === null" />
<template v-else>{{ stateLabel }}</template>
</motion.span>
</AnimatePresence>
</motion.span>
<AnimatePresence :initial="false">
<motion.span v-if="state === 'idle' && $slots.icon" key="idle-icon" class="be-stateful-icon" v-bind="iconMotion">
<slot name="icon" />
</motion.span>
</AnimatePresence>
</span>
</ButtonBase>
</template>
<style scoped>
.be-stateful-row { position: relative; display: inline-flex; align-items: center; justify-content: center; overflow: hidden; }
.be-stateful-icon { display: inline-grid; flex-shrink: 0; place-items: center; overflow: hidden; }
.be-stateful-svg { width: 1rem; height: 1rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.be-stateful-spin { animation: be-stateful-spin 1s linear infinite; }
.be-stateful-text { position: relative; display: inline-block; overflow: hidden; white-space: nowrap; vertical-align: bottom; }
.be-stateful-measure { visibility: hidden; display: inline-block; white-space: nowrap; }
.be-stateful-layer { position: absolute; top: 0; left: 0; display: inline-block; white-space: pre; }
.be-stateful-block { will-change: opacity, filter, transform; }
.be-stateful-letter { display: inline-block; white-space: pre; }
.be-stateful-letter-live { will-change: opacity, filter, transform; }
.be-stateful-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
@keyframes be-stateful-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .be-stateful-spin { animation: none; } }
</style>Install
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/button-stateful$ 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 StatefulButton from '@/components/beui/actions/StatefulButton.vue'
import '@/components/beui/styles.css'API Reference
class?string—size?"sm" | "md" | "lg" | "icon"—labels?Partial<StatefulButtonMessages>Override any built-in string.
—variant?"primary" | "secondary" | "ghost" | "outline"—#icon?slotShown after the idle label while the button is idle.
—pressScale?number—ripple?booleanSpawn a Material-style ripple from the press point. Off by default.
—state?ButtonState—loadingText?string—successText?string—errorText?string—disabled?boolean—#default?slotThe idle label.
—Magnetic Button
MagneticButton.vue<script setup lang="ts">
import { MagneticButton } from 'beui-vue'
</script>
<template>
<div class="row">
<MagneticButton variant="primary" size="md" :strength="0.35">Hover me <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12h14" /><path d="m12 5 7 7-7 7" /></svg></MagneticButton>
<MagneticButton variant="secondary" size="md" :strength="0.25">Subtle pull</MagneticButton>
<MagneticButton variant="outline" size="md" :strength="0.5">Strong pull</MagneticButton>
</div>
</template>
<style scoped>
.row { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 1rem; }
.row svg { width: 1rem; height: 1rem; flex: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; fill: none; }
</style><script setup lang="ts">
import { motion } from 'motion-v'
import ButtonBase from '../ButtonBase.vue'
import { useHoverSpring } from './use-hover-spring'
defineOptions({inheritAttrs:false})
const {strength = 0.25, magneticClassName, variant, size, pressScale, ripple} = defineProps<{
/** Magnetic pull strength. Default 0.25. */
strength?: number
/** Class applied to the magnetic wrapper. */
magneticClassName?: string
variant?: 'primary' | 'secondary' | 'ghost' | 'outline'
size?: 'sm' | 'md' | 'lg' | 'icon'
pressScale?: number
/** Spawn a Material-style ripple from the press point. Off by default. */
ripple?: boolean
}>()
const {horizontal, vertical, reset, position} = useHoverSpring()
function move(event: PointerEvent) {
const point = position(event)
if (!point) return
horizontal.set((point.left - point.rect.width / 2) * strength)
vertical.set((point.top - point.rect.height / 2) * strength)
}
</script>
<template>
<motion.span class="magnet" :class="magneticClassName" :style="{x:horizontal, y:vertical}" @pointermove="move" @pointerleave="reset">
<ButtonBase v-bind="$attrs" :variant="variant" :size="size" :press-scale="pressScale" :ripple="ripple"><slot /></ButtonBase>
</motion.span>
</template>
<style scoped>.magnet { display:inline-block; }</style>Install
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/button-magnetic$ 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 MagneticButton from '@/components/beui/actions/MagneticButton.vue'
import '@/components/beui/styles.css'API Reference
class?string—size?"sm" | "md" | "lg" | "icon"—variant?"primary" | "secondary" | "ghost" | "outline"—pressScale?number—ripple?booleanSpawn a Material-style ripple from the press point. Off by default.
—strength?numberMagnetic pull strength. Default 0.25.
0.25magneticClassName?stringClass applied to the magnetic wrapper.
—Used in these Pro blocks
Related components
Select
Composable select primitives whose panel unfolds out of the trigger on one spring and pulls away into its own pill, plus a Morph variant where the trigger grows into the panel via shared layout.
Switch
Toggle with a spring-driven thumb and press feedback.
Checkbox
Form choice control with a draw-on checkmark, spring press feedback and indeterminate state support.
Updated