Toolbar

Items in floating glass platters — 44 pt circles inset 4 on iOS 26, 28 pt on macOS and the web — with the prominent action filled.

navigation

Apple: Toolbars

· Base UI: Toolbar

Groups and a prominent action

"use client"

import {
  ArrowLeft01Icon,
  Bookmark01Icon,
  Share01Icon,
  Tick02Icon,
} from "@hugeicons/core-free-icons"

import {
  Toolbar,
  ToolbarButton,
  ToolbarGroup,
  ToolbarSpacer,
} from "@applecn/ui/components/toolbar"

export default function ToolbarBasic() {
  return (
    <div className="rounded-4xl bg-[linear-gradient(135deg,var(--system-orange),var(--system-pink))] py-4">
      <Toolbar aria-label="Document">
        <ToolbarButton icon={ArrowLeft01Icon} aria-label="Back" />
        <ToolbarSpacer />
        <ToolbarGroup>
          <ToolbarButton icon={Share01Icon} aria-label="Share" />
          <ToolbarButton icon={Bookmark01Icon} aria-label="Bookmark" />
        </ToolbarGroup>
        <ToolbarButton prominent icon={Tick02Icon} aria-label="Done" />
      </Toolbar>
    </div>
  )
}

Install

From the registry this site publishes, with dependencies resolved by the CLI.

npx shadcn@latest add https://applecn.vercel.app/r/toolbar.json

Source

packages/ui/src/components/toolbar.tsx

"use client"

import { Toolbar as ToolbarPrimitive } from "@base-ui/react/toolbar"
import type { IconSvgElement } from "@hugeicons/react"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
import { createContext, useContext, type ComponentProps } from "react"

import { Icon } from "./icon"

/**
 * Toolbars (HIG › Toolbars) under Liquid Glass: items sit in floating glass platters, each a
 * capsule of 44 pt circular buttons inset 4 (iOS 26; 28 pt on macOS and the web); a lone
 * button is its own glass circle; the one `prominent` action (Done, Submit) is the filled
 * circle at the trailing edge.
 */
const GroupContext = createContext(false)

type ToolbarProps = ToolbarPrimitive.Root.Props & {
  placement?: "top" | "bottom"
}

function Toolbar({ className, placement = "top", ...props }: ToolbarProps) {
  return (
    <ToolbarPrimitive.Root
      data-slot="toolbar"
      data-placement={placement}
      className={cn(
        "flex min-h-(--toolbar-height) items-center gap-2 px-4",
        placement === "bottom" && "pb-[env(safe-area-inset-bottom)]",
        className
      )}
      {...props}
    />
  )
}

function ToolbarGroup({ className, ...props }: ToolbarPrimitive.Group.Props) {
  return (
    <GroupContext.Provider value={true}>
      <ToolbarPrimitive.Group
        data-slot="toolbar-group"
        className={cn(
          "flex items-center gap-1 rounded-full glass p-(--toolbar-inset) macos:rounded-control web:rounded-control",
          className
        )}
        {...props}
      />
    </GroupContext.Provider>
  )
}

const toolbarButtonVariants = cva(
  "flex size-(--toolbar-item) shrink-0 pressable items-center justify-center rounded-full outline-none select-none focus-visible:ring-4 focus-visible:ring-ring/60 disabled:opacity-40 macos:rounded-control web:rounded-control [&_svg]:size-6 macos:[&_svg]:size-4 web:[&_svg]:size-5",
  {
    variants: {
      prominent: {
        true: "glass-prominent",
        false: "text-primary hover:bg-fill-4",
      },
      grouped: {
        true: "",
        false: "",
      },
    },
    compoundVariants: [{ prominent: false, grouped: false, class: "glass" }],
    defaultVariants: {
      prominent: false,
      grouped: false,
    },
  }
)

type ToolbarButtonProps = ToolbarPrimitive.Button.Props &
  Omit<VariantProps<typeof toolbarButtonVariants>, "grouped"> & {
    icon?: IconSvgElement
  }

function ToolbarButton({
  className,
  prominent = false,
  icon,
  children,
  ...props
}: ToolbarButtonProps) {
  const grouped = useContext(GroupContext)
  return (
    <ToolbarPrimitive.Button
      data-slot="toolbar-button"
      data-prominent={prominent || undefined}
      className={cn(toolbarButtonVariants({ prominent, grouped }), className)}
      {...props}
    >
      {icon ? <Icon icon={icon} weight="semibold" /> : null}
      {children}
    </ToolbarPrimitive.Button>
  )
}

function ToolbarSeparator({
  className,
  ...props
}: ToolbarPrimitive.Separator.Props) {
  return (
    <ToolbarPrimitive.Separator
      data-slot="toolbar-separator"
      className={cn("mx-1 h-6 w-[0.5px] bg-separator", className)}
      {...props}
    />
  )
}

type ToolbarSpacerProps = ComponentProps<"div"> & {
  kind?: "flexible" | "fixed"
}

function ToolbarSpacer({
  className,
  kind = "flexible",
  ...props
}: ToolbarSpacerProps) {
  return (
    <div
      data-slot="toolbar-spacer"
      data-kind={kind}
      aria-hidden="true"
      className={cn(kind === "flexible" ? "flex-1" : "w-5 shrink-0", className)}
      {...props}
    />
  )
}

export {
  Toolbar,
  ToolbarButton,
  ToolbarGroup,
  ToolbarSeparator,
  ToolbarSpacer,
  toolbarButtonVariants,
}
export type { ToolbarButtonProps, ToolbarProps, ToolbarSpacerProps }