Updated
Split Button
Customize
Solid
Medium
End
Below
Radius12px
Stagger0.030s
Installation
npx shadcn@latest add https://uibrik.com/r/split-button.jsonInstall the packages
npm install @tabler/icons-react 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/split-button/split-button.tsx"use client"; import { IconCheck, IconChevronDown } from "@tabler/icons-react"; import { AnimatePresence, motion } from "motion/react"; import { useEffect, useId, useRef, useState, type KeyboardEvent } 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]; const SIZES = { sm: { height: 32, padX: 12, font: 13, chevron: 15, toggle: 30 }, md: { height: 40, padX: 16, font: 14, chevron: 17, toggle: 38 }, lg: { height: 48, padX: 20, font: 15, chevron: 19, toggle: 46 }, } as const; // One neutral ramp per theme. Solid inverts against the page (near-black on // light, near-white on dark) and steps one shade toward the page on hover; // soft and outline stay quiet for secondary actions. `divider` is the seam // between the two segments, `open` holds the chevron in its hover shade while // its menu is open. const VARIANTS = { solid: { segment:
Adds the files to
components/uibrik/split-button and installs @tabler/icons-react, motion and react-use-measure. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/split-button.Usage
import { SplitButton } from "@/components/uibrik/split-button/split-button";const options = ["Merge pull request", "Squash and merge", "Rebase and merge"];<SplitButton options={options} variant="solid" size="md" align="end" side="bottom" radius={12} stagger={0.03} defaultIndex={0} onAction={(option, index) => {}} onSelect={(option, index) => {}}/>Where to use Split Button
Save options
A primary button with alternatives like save as draft keeps the main action prominent.
Deploy and merge
The chosen action rolling into the main label remembers the user's preference.
Export formats
PDF, CSV and PNG options fit under one export button.
Pairs with Dropdown Menu
Props
SplitButton- options
- Type string[]
- ["Merge pull request","Squash and merge","Rebase and merge"]
- Actions the main button can run.
- variant
- Type "solid" | "soft" | "outline"
- "solid"
- Primary, or a quieter look for secondary actions.
- size
- Type "sm" | "md" | "lg"
- "md"
- Height, padding and text size.
- align
- Type "end" | "start"
- "end"
- Which edge of the button the menu lines up with.
- side
- Type "bottom" | "top"
- "bottom"
- Open the menu below the button, or above it (e.g. in a footer).
- radius
- Type number
- 12
- Corner radius.
- stagger
- Type number
- 0.03
- Delay between menu items as they unfold.
- defaultIndex
- Type number
- 0
- Index of the option chosen at first.
- onAction
- Type (option: string, index: number) => void
- –
- Called with the chosen option when the main button is pressed.
- onSelect
- Type (option: string, index: number) => void
- –
- Called when a different option is chosen from the menu.
- className
- Type string
- –
- Classes for the wrapper.