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.json
Overview
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, RightInsetButton
content in the right segment, and the regular Button
children appear in the central segment.
How it Works
- Detection: The parent
Button
checks its direct children. If it finds an instance ofLeftInsetButton
orRightInsetButton
, it activates the group mode. - Structure: Instead of rendering a single
<button>
(orSlot
), the parentButton
renders adiv
wrapper withrole="group"
and flexbox styles (inline-flex
,items-stretch
). It also addsdivide-x
for visual separation between segments. - Segment Rendering:
- If
LeftInsetButton
is present, its children and props are used to render the left segment (as a<button>
orSlot
ifasChild
is used on the inset). - If
RightInsetButton
is present, its children and props are used to render the right segment. - Any other direct children of the main
Button
become the content of the central segment, along with the mainButton
'siconLeft
andiconRight
(if provided).
- If
- Styling: All segments inherit the
variant
andsize
from the parentButton
for 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
LeftInsetButton
orRightInsetButton
(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. TheisLoading
state and icons of the parentButton
do 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" |