Updated
Expand Button
Customize
Blur
Soft
None
Gap6px
Size40px
Radius12px
Installation
npx shadcn@latest add https://uibrik.com/r/expand-button.jsonInstall the packages
npm install motion react-use-measureAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/expand-button/expand-button.tsx"use client"; import { motion, type HTMLMotionProps } from "motion/react"; import { useState, type ReactNode } from "react"; import useMeasure from "react-use-measure"; import { cn } from "@/lib/utils"; const EASE_OUT: [number, number, number, number] = [0.23, 1, 0.32, 1]; // Each look has a resting shade and an open one a step stronger, so the open // button stands out from its neighbours. const VARIANTS = { soft: { rest: "bg-neutral-100 dark:bg-neutral-900", open: "bg-neutral-200/70 dark:bg-neutral-800" }, ghost: { rest: "bg-transparent", open: "bg-muted" }, outline: { rest: "bg-background shadow-[inset_0_0_0_1px_var(--border)]", open: "bg-muted shadow-[inset_0_0_0_1px_var(--border)]", }, } as const; /** * How the label appears as the button opens. * - blur: comes into focus as it slides in * - slide: slides in from behind the icon
Adds the files to
components/uibrik/expand-button and installs motion and react-use-measure. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/expand-button.Usage
import { ExpandButton } from "@/components/uibrik/expand-button/expand-button";<ExpandButton icon={<IconPlus size={20} />} label="New file" reveal="blur" variant="soft" size={40} radius={12} expanded={false} onClick={(event) => {}}/>Where to use Expand Button
Compact toolbars
Icon buttons reveal their label on hover or focus, so toolbars stay small but clear.
Pairs with Fold Toolbar
Floating actions
A label that springs open explains what a floating button does before it is pressed.
Mobile headers
Icon-only buttons save space while focus still shows the label for accessibility.
Props
ExpandButton- reveal
- Type "blur" | "slide" | "fade"
- "blur"
- How the label appears as the button opens.
- variant
- Type "soft" | "ghost" | "outline"
- "soft"
- Tinted, transparent until open, or outlined.
- size
- Type number
- 40
- Height, and resting width.
- radius
- Type number
- 12
- Corner radius.
- iconrequired
- Type ReactNode
- –
- Shown at rest.
- labelrequired
- Type string
- –
- Revealed on hover or keyboard focus. Also the accessible name.
- expanded
- Type boolean
- false
- Keep the label showing, e.g. for the active item.
- onClick
- Type MouseEventHandler<HTMLButtonElement>
- –
- Called on click, like any button.
- className
- Type string
- –
- Classes for the button.