HapplyUI

Components

Button Group

A compound button group component with sizes, icons, and toggle group support via asChild.


Installation

bunx @happlyui/cli@latest add button-group

Dependencies

npm packages

  • @radix-ui/react-slot

Registry dependencies

These are automatically installed when you add this component.

  • tv
  • polymorphic
  • recursive-clone-children

Usage

import * as ButtonGroup from "@/components/ui/button-group"

<ButtonGroup.Root>
  <ButtonGroup.Item>
    <ButtonGroup.Icon as={GridIcon} />
    Grid view
  </ButtonGroup.Item>
  <ButtonGroup.Item>List view</ButtonGroup.Item>
</ButtonGroup.Root>

Examples

Default

A basic button group with icons and labels.

<ButtonGroup.Root>
  <ButtonGroup.Item>
    <ButtonGroup.Icon as={RiLayoutGridLine} />
    Grid view
  </ButtonGroup.Item>
  <ButtonGroup.Item>
    <ButtonGroup.Icon as={RiListCheck} />
    List view
  </ButtonGroup.Item>
  <ButtonGroup.Item>
    <ButtonGroup.Icon as={RiLayout2Line} />
    Gallery view
  </ButtonGroup.Item>
</ButtonGroup.Root>

Sizes

Button groups come in small (default), xsmall, and xxsmall sizes.

<ButtonGroup.Root size="small">...</ButtonGroup.Root>
<ButtonGroup.Root size="xsmall">...</ButtonGroup.Root>
<ButtonGroup.Root size="xxsmall">...</ButtonGroup.Root>

API Reference

ButtonGroup.Root

The container that groups items together with negative spacing.

PropTypeDefaultDescription
size'small' | 'xsmall' | 'xxsmall''small'The size of the button group items
asChildbooleanfalseRenders as child element using Radix Slot

ButtonGroup.Item

An individual button within the group. Supports active state via data-[state=on].

PropTypeDefaultDescription
asChildbooleanfalseRenders as child element using Radix Slot
disabledbooleanfalseDisables the button item

ButtonGroup.Icon

Polymorphic icon container that receives size from ButtonGroup.Root.

PropTypeDefaultDescription
asReact.ElementType'div'The element or component to render as

Previous
Button