Button
A supercharged button component with additional variants, animations, extensions and auxiliar subcomponents.
Playground
Customize the Button properties to see different variations.
Customize
Installation
pnpm dlx shadcn@latest add https://shadcn-ui-variants.vercel.app/r/button.jsonOverview
This is a highly versatile button component built upon Radix UI's Slot. It supports various visual styles, sizes, loading states, icons, icon animations, and a unique mechanism for creating segmented button groups using LeftInsetButton andRightInsetButton child components.
Examples
Split Button
Compact Action Group
Inset with `asChild`
Double InsetButtons
Subcomponents
Concept
LeftInsetButton and RightInsetButton are special marker components used as direct children of the main Button component. They are not rendered directly but signal to the parent Button to switch into a "button group" rendering mode. This mode creates a visually segmented button where theLeftInsetButton content appears in the left segment, RightInsetButtoncontent in the right segment, and the regular Button children appear in the central segment.
How it Works
- Detection: The parent
Buttonchecks its direct children. If it finds an instance ofLeftInsetButtonorRightInsetButton, it activates the group mode. - Structure: Instead of rendering a single
<button>(orSlot), the parentButtonrenders adivwrapper withrole="group"and flexbox styles (inline-flex,items-stretch). It also addsdivide-xfor visual separation between segments. - Segment Rendering:
- If
LeftInsetButtonis present, its children and props are used to render the left segment (as a<button>orSlotifasChildis used on the inset). - If
RightInsetButtonis present, its children and props are used to render the right segment. - Any other direct children of the main
Buttonbecome the content of the central segment, along with the mainButton'siconLeftandiconRight(if provided).
- If
- Styling: All segments inherit the
variantandsizefrom the parentButtonfor visual consistency. Appropriaterounded-s-md,rounded-e-md, or no rounding is applied based on the segment's position. - Props Application:
- Props passed directly to
LeftInsetButtonorRightInsetButton(likeonClick,disabled,className,aria-label,asChild) apply only to that specific segment. - Props passed to the parent
Button(likeonClick,isLoading,iconLeft,iconRight,disabled) apply only to the central segment when in group mode. TheisLoadingstate and icons of the parentButtondo not affect the inset segments.
- Props passed directly to
Props for Inset Buttons
These components accept standard button attributes:
children: Content for the inset segment (e.g., an icon, text).onClick: Handler specific to clicking this segment.disabled: Disables only this segment.className: Additional classes for this segment.asChild: Renders the segment as its child element (e.g., an<a>tag).aria-label, etc.: Accessibility and other standard attributes.
Button Props
| Prop | Type | Default |
|---|---|---|
variant | enum | "default" |
size | enum | "default" |
isLoading | boolean | false |
disabled | boolean | false |
iconLeft | React.ReactElement | — |
iconRight | React.ReactElement | — |
iconAnimation | enum | "none" |
iconAnimationTarget | enum | "none" |