Skip to content
Pebble Pro is here at $49 one timeSee what’s included ↗
Pebble
ComponentsDocsMCPPricing
⌕ Find a component↗Log in
All components 673

Categories

Core inputs & forms46Buttons & actions33Navigation36Overlays & feedback49Data display33Charts & data viz40Cards & layout43Marketing blocks38App shells & pages37AI interfaces40Text & typography effects33Backgrounds & visual effects38Motion & transitions32Numbers & counters32Media34E-commerce333D & interactive36Themed sets40
Start with the essentials.Installation guide ↗Connect your agent ↗
← All componentsButtons & actions

Button Group

Joined buttons as one raised object: toolbars with toggles, split buttons with a menu, text segments, vertical stacks and three sizes.

Preview

Toolbar · toggles

Split buttons

With a text segment

3 of 12

Vertical

100%

Sizes

Install

Add the editable source with the shadcn CLI. Your project also needs the shared theme tokens this component uses. Setup and requirements. The Pebble installer is not published yet.

npx shadcn@latest add https://pebbleui.com/r/button-group.json

Props

PropTypeDefaultDescription
variant"secondary" | "primary" | "outline""secondary"Group surface. primary is the lit key, for a split primary action.
size"sm" | "md" | "lg""md"Segment height: 32, 36 or 40 px.
orientation"horizontal" | "vertical""horizontal"Row or stack.
role"group" | "toolbar""group"toolbar also sets aria-orientation.
iconbooleanfalseButtonGroupItem. Square segment for a lone icon (needs aria-label).
asChildbooleanfalseButtonGroupItem / ButtonGroupText. Render a link or menu trigger as the segment.
Build notes
- The group carries the Pebble surface (`ring-1 ring-hairline
shadow-raised-xs inset-shadow-highlight`, or the lit-key gradient + edge +
  shine for `primary`). Items are transparent, ring-less segments, so joined
  edges never stack two rings or two shadows.
- Corners: items are `rounded-none` with `first:rounded-l-[inherit]
last:rounded-r-[inherit]` (top/bottom when vertical), inheriting the
  group's radius.
- Dividers: each non-first segment draws a `::before` hairline, inset 8 px
  from the ends, coloured by a `--group-divider` custom property that the
  group sets per variant (border, or an 18% primary-foreground mix on the
  key). A pressed/open segment hides its own and its next sibling's divider
  (`[&[aria-pressed=true]+*]:before:opacity-0`) so the dip reads as one
  shape.
- Press: segments don't scale (that would break the row); the icon dips to
  0.9 and the segment gets an inset shade over `--motion-fast`.
- Focus: `focus-visible:z-10` + a 2 px ember ring with no offset, so it sits
  above neighbours inside the group outline.
- Group variant, size and orientation pass to items through context.

<!-- PEBBLE-LICENSE -->
View source

registry/button/button-group/button-group.tsx

"use client";

/* PEBBLE-LICENSE
Built by Pebble. Component: button-group.

First-party license: MIT

The following first-party terms apply only to original Pebble material.

MIT License

Copyright (c) 2026 Praxys Solutions LLC (Pebble)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

THIRD-PARTY NOTICES
These notices apply to identified upstream portions; Pebble terms do not replace or narrow their rights.

Upstream: https://raw.githubusercontent.com/shadcn-ui/ui/main/LICENSE.md
MIT License

Copyright (c) 2023 shadcn

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
END PEBBLE-LICENSE */

import * as React from "react";
import { Slot } from "radix-ui";

import { cn } from "@/lib/utils";

// One raised object, cut into segments. The group carries the Pebble surface
// (ring, shadow, top light, or the lit key for `primary`); items are flat
// segments inside it, so joined edges never double up their rings.
const surfaces = {
  secondary:
    "bg-card text-foreground ring-1 ring-hairline shadow-raised-xs inset-shadow-highlight [--group-divider:var(--border)]",
  primary:
    "bg-linear-to-b from-key-top to-key-bottom text-primary-foreground ring-1 ring-key-edge shadow-[var(--key-shine),var(--elevation-sm)] [--group-divider:color-mix(in_oklch,var(--primary-foreground)_18%,transparent)]",
  outline: "bg-transparent text-foreground ring-1 ring-border [--group-divider:var(--border)]",
} as const;

// Segment states per surface: hover is a whisper, pressed/on/open sinks in.
const segments = {
  secondary:
    "aria-[pressed=false]:text-muted-foreground hover:text-foreground dark:aria-pressed:bg-foreground/10 hover:bg-muted/70 active:bg-muted active:shadow-[inset_0_1px_2px_var(--hairline)] aria-pressed:bg-muted aria-pressed:shadow-[inset_0_1px_2px_var(--hairline)] data-[state=open]:bg-muted",
  primary:
    "hover:bg-primary-foreground/8 active:bg-key-bottom active:shadow-[var(--key-press)] aria-pressed:bg-key-bottom aria-pressed:shadow-[var(--key-press)] data-[state=open]:bg-key-bottom data-[state=open]:shadow-[var(--key-press)]",
  outline: "hover:bg-muted active:bg-muted/80 aria-pressed:bg-muted data-[state=open]:bg-muted",
} as const;

const sizes = {
  sm: { item: "h-8 gap-1.5 px-2.5 text-[13px]", icon: "w-8", group: "rounded-md" },
  md: { item: "h-9 gap-2 px-3 text-sm", icon: "w-9", group: "rounded-md" },
  lg: { item: "h-10 gap-2 px-4 text-sm", icon: "w-10", group: "rounded-lg" },
} as const;

type Variant = keyof typeof surfaces;
type Size = keyof typeof sizes;
type Orientation = "horizontal" | "vertical";

const GroupContext = React.createContext<{
  variant: Variant;
  size: Size;
  orientation: Orientation;
}>({ variant: "secondary", size: "md", orientation: "horizontal" });

export type ButtonGroupProps = React.ComponentProps<"div"> & {
  variant?: Variant;
  size?: Size;
  orientation?: Orientation;
};

export function ButtonGroup({
  variant = "secondary",
  size = "md",
  orientation = "horizontal",
  className,
  role = "group",
  ...props
}: ButtonGroupProps) {
  const value = React.useMemo(() => ({ variant, size, orientation }), [variant, size, orientation]);
  return (
    <GroupContext.Provider value={value}>
      <div
        role={role}
        data-slot="button-group"
        data-variant={variant}
        data-size={size}
        data-orientation={orientation}
        aria-orientation={role === "toolbar" ? orientation : undefined}
        className={cn(
          "group/button-group inline-flex w-fit items-stretch",
          orientation === "vertical" && "flex-col",
          surfaces[variant],
          sizes[size].group,
          className,
        )}
        {...props}
      />
    </GroupContext.Provider>
  );
}

// A hairline between neighbouring segments, inset from the edges so the
// group still reads as one object. Drawn by the later segment of each pair.
const divider =
  "relative not-first:before:pointer-events-none not-first:before:absolute not-first:before:bg-(--group-divider) not-first:before:transition-opacity not-first:before:duration-(--motion-fast)";
const dividers = {
  horizontal: "not-first:before:inset-y-2 not-first:before:left-0 not-first:before:w-px",
  vertical: "not-first:before:inset-x-2 not-first:before:top-0 not-first:before:h-px",
} as const;
// Outer corners follow the group; inner corners stay square.
const corners = {
  horizontal: "rounded-none first:rounded-l-[inherit] last:rounded-r-[inherit]",
  vertical: "rounded-none first:rounded-t-[inherit] last:rounded-b-[inherit]",
} as const;

export type ButtonGroupItemProps = React.ComponentProps<"button"> & {
  /** Square segment for a lone icon (give it an `aria-label`). */
  icon?: boolean;
  asChild?: boolean;
};

export function ButtonGroupItem({
  icon = false,
  asChild = false,
  className,
  type,
  ...props
}: ButtonGroupItemProps) {
  const { variant, size, orientation } = React.useContext(GroupContext);
  const Comp = asChild ? Slot.Root : "button";
  return (
    <Comp
      data-slot="button-group-item"
      type={asChild ? undefined : (type ?? "button")}
      className={cn(
        "inline-flex shrink-0 cursor-pointer items-center justify-center font-medium whitespace-nowrap select-none",
        "[&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
        "transition-[background-color,box-shadow,color] duration-(--motion-fast) ease-enter motion-reduce:transition-none",
        // The icon dips on press: the segment itself stays put in the row.
        "[&_svg]:transition-transform [&_svg]:duration-(--motion-fast) active:[&_svg]:scale-90 motion-reduce:active:[&_svg]:scale-100",
        "focus-visible:z-10 focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none",
        "disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50",
        // Hide the divider next to a sunken segment so it reads as one dip.
        "aria-pressed:before:opacity-0 data-[state=open]:before:opacity-0 [&[aria-pressed=true]+*]:before:opacity-0 [&[data-state=open]+*]:before:opacity-0",
        divider,
        dividers[orientation],
        corners[orientation],
        segments[variant],
        sizes[size].item,
        icon && cn(sizes[size].icon, "px-0"),
        orientation === "vertical" && !icon && "justify-start",
        className,
      )}
      {...props}
    />
  );
}

/** A non-interactive segment: a count, a label or a page indicator. */
export function ButtonGroupText({
  className,
  asChild = false,
  ...props
}: React.ComponentProps<"span"> & { asChild?: boolean }) {
  const { size, orientation } = React.useContext(GroupContext);
  const Comp = asChild ? Slot.Root : "span";
  return (
    <Comp
      data-slot="button-group-text"
      className={cn(
        "inline-flex items-center justify-center text-muted-foreground tabular-nums group-data-[variant=primary]/button-group:text-primary-foreground/70",
        "[&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
        divider,
        dividers[orientation],
        corners[orientation],
        sizes[size].item,
        "font-normal",
        className,
      )}
      {...props}
    />
  );
}

/** An explicit full-height rule, for groups mixing segments with other content. */
export function ButtonGroupSeparator({ className, ...props }: React.ComponentProps<"div">) {
  const { orientation } = React.useContext(GroupContext);
  return (
    <div
      data-slot="button-group-separator"
      role="none"
      className={cn(
        "shrink-0 self-stretch bg-(--group-divider)",
        orientation === "horizontal" ? "w-px" : "h-px",
        className,
      )}
      {...props}
    />
  );
}
Pebble

Small details.
Better interfaces.

React components to explore, make your own, and build on.

Library

  • Components
  • Installation
  • Pricing

Resources

  • For agents
  • About
  • Support

Legal

  • License
  • Terms
  • Privacy
  • Final sale

Built by Pebble

A product of Praxys Solutions LLC ↗

Pebble Pro is live

$49 one time, lifetime updates ↗