SplitButton

A main action and a menu of its alternatives, as two halves of one pill. Each half presses on its own. Buttons.

Open playground

About

SplitButton is a React component in the Buttons category of smoui. It is typed, ships no stylesheet, follows your theme through CSS variables, and honors prefers-reduced-motion. Import it with import { SplitButton } from "@ashutoshswamy/smoui" and set children, onClick, items among its 4 props.

Install

Terminal
npm i @ashutoshswamy/smoui

Usage

TSX
import { SplitButton } from "@ashutoshswamy/smoui";

<SplitButton
  onClick={publish}
  onSelect={(id) => run(id)}
  items={[
    { id: "later", label: "Schedule", icon: "clock" },
    { id: "draft", label: "Save as draft", icon: "document" },
  ]}
>
  Publish
</SplitButton>

Props 4

children

Label of the main action.

ReactNode
onClick

The main action.

() => void
items

Menu rows: id, label, icon, shortcut, danger, separator, disabled.

DropdownItem[]
onSelect

Called with the id of the chosen menu row.

(id: string) => void