# ButtonGroup > Groups related buttons into one connected control **Category**: components **URL**: https://peakui.dev/en/docs/react/components/button-group **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(buttons)/button-group.mdx ## Usage ```tsx import {Button, ButtonGroup} from "@peakui/react"; ``` ```tsx import {Button, ButtonGroup} from "@peakui/react"; export function Basic() { return ( ); } ``` Put `` inside each button after the first to draw the divider between neighbors. Buttons inherit `size`, `variant`, `isDisabled` and `fullWidth` from the group; a button's own prop wins. ## Examples ### Variants ```tsx import type {ComponentProps} from "react"; import {Button, ButtonGroup} from "@peakui/react"; const VARIANTS: ComponentProps["variant"][] = [ "primary", "secondary", "tertiary", "outline", "ghost", "danger", ]; export function Variants() { return (
{VARIANTS.map((variant) => ( ))}
); } ``` ### Sizes ```tsx import type {ComponentProps} from "react"; import {Button, ButtonGroup} from "@peakui/react"; const SIZES: ComponentProps["size"][] = ["sm", "md", "lg"]; export function Sizes() { return (
{SIZES.map((size) => ( ))}
); } ``` ### Orientation The `orientation` prop arranges the buttons in a row or a column, and the group reads it from an enclosing React Aria toggle button group provider when the prop is omitted. ```tsx import {TextAlignCenter, TextAlignJustify, TextAlignLeft, TextAlignRight} from "@gravity-ui/icons"; import {Button, ButtonGroup} from "@peakui/react"; export function Orientation() { return (
Horizontal
Vertical
); } ``` ### With Icons ```tsx import { ChevronLeft, ChevronRight, Ellipsis, TextAlignCenter, TextAlignLeft, } from "@gravity-ui/icons"; import {Button, ButtonGroup} from "@peakui/react"; export function WithIcons() { return (
); } ``` ### Full Width ```tsx import {TextAlignCenter, TextAlignLeft, TextAlignRight} from "@gravity-ui/icons"; import {Button, ButtonGroup} from "@peakui/react"; export function FullWidth() { return (
); } ``` ### Disabled State ```tsx import {Button, ButtonGroup} from "@peakui/react"; /* Every button inherits the group's `isDisabled`; `isDisabled={false}` re-enables one button. */ export function Disabled() { return (
); } ``` ### Without Separator Omit `` and the buttons sit flush without dividers. ```tsx import {Button, ButtonGroup} from "@peakui/react"; export function WithoutSeparator() { return ( ); } ``` ## Customization ### Tailwind CSS ```tsx ``` ### Global CSS ```css @layer components { .button-group { @apply gap-2 rounded-lg; } .button-group__separator { @apply opacity-25; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The ButtonGroup component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/button-group.css)): #### Base & Orientation Classes - `.button-group` - Base group styles - `.button-group--horizontal` - Buttons in a row (default) - `.button-group--vertical` - Buttons in a column #### Modifier Classes - `.button-group--full-width` - Stretches the group to the container's width #### Element Classes - `.button-group__separator` - Divider between adjacent buttons ### Slots - `[data-slot="button-group"]` - `[data-slot="button-group-separator"]` ### Interactive States The group itself has no interactive states; it restyles the states of the buttons inside it: - **Pressed**: `:active` or `[data-pressed]` (the pressed scale is removed for a cohesive group) - **Focus**: `:focus-visible` or `[data-focus-visible]` (the focused button is raised above its neighbors) ## API Reference ### ButtonGroup | Prop | Type | Default | Description | | ------------- | --------------------------------------------------------------------------------------------- | -------------- | ----------------------------------------------------------------------------------------- | | `orientation` | `'horizontal' \| 'vertical'` | `'horizontal'` | Arranges the buttons in a row or a column | | `fullWidth` | `boolean` | `false` | Stretches the group and every button inside to the container's width | | `isDisabled` | `boolean` | - | Disables the group; every button inside inherits it, and a button's own `isDisabled` wins | | `variant` | `'primary' \| 'secondary' \| 'tertiary' \| 'outline' \| 'ghost' \| 'danger' \| 'danger-soft'` | - | Inherited by every button inside; a button's own `variant` wins | | `size` | `'sm' \| 'md' \| 'lg'` | - | Inherited by every button inside; a button's own `size` wins | | `children` | `React.ReactNode` | - | Buttons to group together | | `className` | `string \| (values: GroupRenderProps) => string` | - | Additional classes, or a function of the group's state | | `render` | `DOMRenderFunction<'div', GroupRenderProps>` | - | Replaces the rendered element. It must still return a `
` | Every other [React Aria Group](https://react-spectrum.adobe.com/react-aria/Group.html) prop is accepted. ### ButtonGroup.Separator | Prop | Type | Default | Description | | ----------- | -------------------------------------- | ------- | -------------------------------------------------------------- | | `children` | `React.ReactNode` | - | Separator content; renders nothing by default | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'span', undefined>` | - | Replaces the rendered element. It must still return a `` | The separator is `aria-hidden="true"`: it decorates the boundary and carries no meaning on its own. ### Render Props When `children` or `className` of the group is a function, it receives: | Prop | Type | Description | | ---------------- | --------- | ---------------------------------------------- | | `isHovered` | `boolean` | Whether the group is hovered | | `isFocusWithin` | `boolean` | Whether any button inside is focused | | `isFocusVisible` | `boolean` | Whether the focus inside was moved by keyboard | | `isDisabled` | `boolean` | Whether the group is disabled | | `isInvalid` | `boolean` | Whether the group is marked invalid | # Button > A pressable button with seven visual variants, three sizes, and disabled and pending states. **Category**: components **URL**: https://peakui.dev/en/docs/react/components/button **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(buttons)/button.mdx ## Usage ```tsx import {Button} from "@peakui/react"; ``` ```tsx "use client"; import {Button} from "@peakui/react"; export function Basic() { return ; } ``` The examples start with `"use client"`. The directive is needed only in a framework with React Server Components, such as Next.js, and only in a file that passes a function (like `onPress`) to a component or uses state: a server component cannot hand a function to `Button`. In a Vite or other client-only app it has no effect, and Vite's production build prints a warning that it was ignored, so leave it out there. ### Handling Presses `onPress` fires when the press is released over the button. It covers mouse, touch, pen and keyboard (Enter and Space) interactions alike: the event's `pointerType` says which one. Use `onPress`, not `onClick`. React Aria keeps `onClick` only as a compatibility alias and marks it not recommended, because its event is a mouse event and carries no details for other kinds of interaction. ```tsx ``` A button that is pending or disabled does not fire `onPress`. ## Examples ### Variants ```tsx import {Button} from "@peakui/react"; export function Variants() { return (
); } ``` ### Sizes ```tsx import {Button} from "@peakui/react"; export function Sizes() { return (
); } ``` ### With Icons Place an icon before or after the label. The button sizes any `svg` child and sets the gap. ```tsx import {Envelope, Plus, TrashBin} from "@gravity-ui/icons"; import {Button} from "@peakui/react"; export function WithIcons() { return (
); } ``` ### Icon Only An icon-only button has no visible text, so give it an `aria-label`. ```tsx import {Ellipsis, Gear, TrashBin} from "@gravity-ui/icons"; import {Button} from "@peakui/react"; export function IconOnly() { return (
); } ``` ### Loading `isPending` keeps the button focusable but stops it responding to presses. It does not add a spinner: put a [`Spinner`](https://peakui.dev/docs/react/components/spinner) in the children, and see that page for its `size`, `color` and label props. Keep the button's visible label in place and add the spinner beside it. The words "Saving" and "Loading" below are sample text: use the label the button already has, or a pending variant of it, never a spinner alone. ```tsx import {Button, Spinner} from "@peakui/react"; export function Loading() { return (
); } ``` ### Loading State Children can be a function that receives the button's state. ```tsx "use client"; import {Button, Spinner} from "@peakui/react"; import {useState} from "react"; export function LoadingState() { const [isPending, setIsPending] = useState(false); const handlePress = () => { setIsPending(true); setTimeout(() => setIsPending(false), 2000); }; return ( ); } ``` ### Pressed State The same function receives `isPressed`, which is true from the moment the press starts until it ends, so a label can depend on it. ```tsx "use client"; import {Button} from "@peakui/react"; export function PressedState() { return ( ); } ``` ### Full Width ```tsx import {Button} from "@peakui/react"; export function FullWidth() { return (
); } ``` ### Disabled State ```tsx import {Button} from "@peakui/react"; export function Disabled() { return (
); } ``` ### Link Styled as a Button To give a link the look of a button, apply `buttonVariants` to an ``. Do not try to make `Button` render an ``: its `render` function must still return a ` ``` ### Global CSS Override the button's classes in the `components` layer. Prefer the component variables where one exists: hover and pressed styles derive from them. ```css @layer components { .button--primary { --button-bg: var(--color-success); --button-bg-hover: var(--color-success-hover); --button-fg: var(--color-success-foreground); } .button--icon-only { @apply rounded-lg; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The Button component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/button.css)): #### Base & Size Classes - `.button` - Base button styles - `.button--sm` - Small size - `.button--md` - Medium size - `.button--lg` - Large size #### Variant Classes - `.button--primary` - `.button--secondary` - `.button--tertiary` - `.button--outline` - `.button--ghost` - `.button--danger` - `.button--danger-soft` `danger` is a solid fill: the `danger` color as the background with the `danger-foreground` text on it. `danger-soft` is a tint: the same red at low opacity (15% in the default theme) with the darker `danger-soft-foreground` text, so it sits quietly beside other controls. Use `danger` for the confirming action of a destructive step and `danger-soft` for a destructive option that should not dominate the page. #### Modifier Classes - `.button--icon-only` - Square button for a single icon - `.button--full-width` - Stretches to the container's width ### Slots - `[data-slot="button"]` ### CSS Variables | Variable | Purpose | | --------------------- | ----------------------------- | | `--button-bg` | Background color | | `--button-bg-hover` | Background color when hovered | | `--button-bg-pressed` | Background color when pressed | | `--button-fg` | Text and icon color | | `--button-border` | Border color | | `--button-radius` | Corner radius | ### Interactive States The button supports both CSS pseudo-classes and data attributes: - **Hover**: `:hover` or `[data-hovered]` - **Pressed**: `:active` or `[data-pressed]` - **Focus**: `:focus-visible` or `[data-focus-visible]` (shows the focus ring) - **Disabled**: `:disabled`, `[data-disabled]` or `[aria-disabled="true"]` - **Pending**: `[data-pending="true"]` ## API Reference ### Button | Prop | Type | Default | Description | | ------------ | --------------------------------------------------------------------------------------------- | ----------- | ------------------------------------------------------------------------------------------- | | `variant` | `'primary' \| 'secondary' \| 'tertiary' \| 'outline' \| 'ghost' \| 'danger' \| 'danger-soft'` | `'primary'` | Visual style | | `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | Size of the button | | `fullWidth` | `boolean` | `false` | Whether the button takes the full width of its container | | `isIconOnly` | `boolean` | `false` | Whether the button contains only an icon | | `isDisabled` | `boolean` | `false` | Whether the button is disabled | | `isPending` | `boolean` | `false` | Whether the button is waiting on an action. Presses are ignored; the button stays focusable | | `type` | `'button' \| 'submit' \| 'reset'` | `'button'` | Behavior of the button inside a form | | `onPress` | `(e: PressEvent) => void` | - | Handler called when the button is pressed | | `children` | `React.ReactNode \| (values: ButtonRenderProps) => React.ReactNode` | - | Button content, or a function of the button's state | | `className` | `string \| (values: ButtonRenderProps) => string` | - | Additional classes, or a function of the button's state | | `render` | `DOMRenderFunction<'button', ButtonRenderProps>` | - | Replaces the rendered element. It must still return a `
); } ``` ### Anatomy ```tsx import {ContextMenu, Label} from "@peakui/react"; // Opens from: right-click, touch long-press, Shift+F10 or the ContextMenu key. // Long-press: 500 ms (the underlying hook's default), touch only; a 10 px movement cancels it, // and releasing the finger does not activate the item under it. // Long-press is not discoverable. Automated tests cannot cover iOS Safari: // verify it by hand on iOS Safari and Android Chrome. // One Trigger per root. It is a plain div: not focusable, no role. // Focusable descendants make the region reachable by keyboard. // The Popover may be nested in the Trigger or sit beside it. export default () => ( ); ``` ## Examples ### With Sections ```tsx import {ContextMenu, Label} from "@peakui/react"; export function WithSections() { return ( Right-click this region ); } ``` ### With Native Escape `data-context-menu-native` on a descendant keeps the browser menu for pointer events; keyboard open still works there. ```tsx import {ContextMenu, Label} from "@peakui/react"; export function WithNativeEscape() { return ( Right-click here for the custom menu. Right-click this link for the browser menu ); } ``` ### Disabled `isDisabled` leaves the browser menu alone. ```tsx import {ContextMenu, Label} from "@peakui/react"; export function Disabled() { return ( Right-click this region: the browser menu stays ); } ``` ### Controlled An open without a pointer anchors at the Trigger's bottom-start corner. ```tsx "use client"; import {Button, ContextMenu, Label} from "@peakui/react"; import {useState} from "react"; export function Controlled() { const [isOpen, setOpen] = useState(false); return (

Menu: {isOpen ? "open" : "closed"}

Right-click this region
); } ``` ## Customization ### Tailwind CSS ```tsx Region {/* items */} ``` ### Global CSS ```css @layer components { .context-menu__trigger { @apply rounded-xl border border-dashed; } .context-menu__popover { @apply min-w-64 rounded-xl; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The ContextMenu component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/context-menu.css)): #### Element Classes - `.context-menu__trigger` - The region; draws nothing of its own - `.context-menu__anchor` - Zero-size fixed element the popover positions against, portaled to `body` - `.context-menu__popover` - The popover surface #### Shared Menu Classes - `.menu` - The menu container - `.menu-item` - Menu item - `.menu-section` - Menu section - `.menu-item__indicator` - Selection indicator of an item - `.menu-item__indicator--submenu` - Submenu indicator of an item - `.menu-item--default` - `.menu-item--danger` Inside `.context-menu__popover`, `[data-slot="context-menu-menu"]` gets `p-1.5` and `[data-slot="menu-item"]` gets `px-2.5`. ### Slots - `[data-slot="context-menu-trigger"]` - `[data-slot="context-menu-anchor"]` - `[data-slot="context-menu-popover"]` - `[data-slot="context-menu-menu"]` - `[data-slot="menu-item"]` - `[data-slot="menu-section"]` - `[data-slot="menu-item-indicator"]` - `[data-slot="menu-item-indicator--checkmark"]` - `[data-slot="menu-item-indicator--dot"]` - `[data-slot="submenu-indicator"]` ### Interactive States The component supports both CSS pseudo-classes and data attributes: - **Item hover**: `:hover` or `[data-hovered="true"]` on an item - **Item focus**: `:focus-visible` or `[data-focus-visible="true"]` on an item - **Item pressed**: `:active` or `[data-pressed="true"]` on an item - **Item selected**: `[aria-checked="true"]`, `[aria-selected="true"]` or `[data-selected="true"]` on an item - **Item disabled**: `[data-disabled="true"]` on an item - **Item submenu**: `[data-has-submenu="true"]` on an item - **Entering**: `[data-entering="true"]` on the popover - **Exiting**: `[data-exiting="true"]` on the popover - **Focus**: `:focus-visible` or `[data-focus-visible="true"]` on the popover - **Coarse pointer**: `@media (pointer: coarse)` sets `user-select: none` on the trigger; `[data-context-menu-native]` descendants keep `user-select: auto` - **Forced colors**: `@media (forced-colors: active)` draws a `ButtonBorder` border on the popover ## API Reference ### ContextMenu | Prop | Type | Default | Description | | -------------- | --------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `isOpen` | `boolean` | - | Whether the menu is open (controlled). Stays true if the Trigger unmounts: the parent owns the state. A parent that accepts an open asynchronously loses the keyboard focus target and anchor position | | `defaultOpen` | `boolean` | `false` | Whether the menu is open on first render (uncontrolled) | | `onOpenChange` | `(isOpen: boolean) => void` | - | Called when the menu opens or closes | | `isDisabled` | `boolean` | `false` | Leaves the browser menu alone, closes an open menu, and does not intercept clicks or drags of descendants | | `children` | `ReactNode` | - | Trigger and Popover | ### ContextMenu.Trigger | Prop | Type | Default | Description | | --------------- | --------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `render` | `DOMRenderFunction` | - | Custom render function; `E` defaults to `"div"` | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode` | - | The region content | | `onKeyDown` | `(event: KeyboardEvent) => void` | - | Shift+F10 or the ContextMenu key opens the menu anchored at the focused descendant, including an input, and focuses the first item; Escape closes it and focus returns. Ctrl, Alt and Meta chords, plain F10, a held key (`repeat`) and IME composition are ignored | | `onContextMenu` | `(event: MouseEvent) => void` | - | Runs first. A descendant that calls `stopPropagation` or `preventDefault` on `contextmenu` suppresses the menu | | `...rest` | `JSX.IntrinsicElements[E]` | - | Native attributes of the rendered element | ### ContextMenu.Popover | Prop | Type | Default | Description | | ----------- | -------------------------------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | | `placement` | `Placement` | `"bottom start"` | Placement against the anchor | | `offset` | `number` | `0` | Distance from the anchor in pixels | | `className` | `string \| ((values) => string)` | - | Additional CSS classes | | `children` | `ReactNode` | - | Popover content; required | | `...rest` | `PopoverProps` | - | React Aria [Popover](https://react-spectrum.adobe.com/react-aria/Popover.html#popover) attributes, except `isOpen`, `onOpenChange` and `triggerRef` | ### ContextMenu.Menu | Prop | Type | Default | Description | | ------------ | -------------------------------- | ------- | ---------------------------------------------------------------------------------------- | | `onAction` | `(key: Key) => void` | - | Called when an item is activated; the menu then closes | | `onClose` | `() => void` | - | Called when the menu closes itself | | `autoFocus` | `boolean \| "first" \| "last"` | - | Set by the open method: a keyboard open focuses the first item, a pointer open the menu | | `aria-label` | `string` | - | Accessible name of the menu | | `className` | `string \| ((values) => string)` | - | Additional CSS classes | | `children` | `ReactNode` | - | Menu content | | `...rest` | `MenuProps` | - | React Aria [Menu](https://react-spectrum.adobe.com/react-aria/Menu.html#menu) attributes | ### ContextMenu.Item Shared with Dropdown and Menu: the same menu-item part. | Prop | Type | Default | Description | | ------------ | ----------------------------- | ----------- | ------------------------------------------------------------------------------------------------ | | `id` | `Key` | - | Unique identifier for the item | | `textValue` | `string` | - | Text content of the item for typeahead | | `variant` | `"default" \| "danger"` | `"default"` | Visual variant of the item | | `isDisabled` | `boolean` | - | Whether the item is disabled | | `href` | `string` | - | Renders the item as a link to this URL | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode \| RenderFunction` | - | Item content or render function | | `...rest` | `MenuItemProps` | - | React Aria [MenuItem](https://react-spectrum.adobe.com/react-aria/Menu.html#menuitem) attributes | ### ContextMenu.Section | Prop | Type | Default | Description | | ----------- | ------------------ | ------- | ------------------------------------------------------------------------------------------------------ | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode` | - | Section content | | `...rest` | `MenuSectionProps` | - | React Aria [MenuSection](https://react-spectrum.adobe.com/react-aria/Menu.html#menusection) attributes | ### ContextMenu.ItemIndicator | Prop | Type | Default | Description | | ----------- | ----------------------------- | ------------- | ------------------------------------------- | | `type` | `"checkmark" \| "dot"` | `"checkmark"` | Type of indicator to display | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode \| RenderFunction` | - | Custom indicator content or render function | ### ContextMenu.SubmenuIndicator | Prop | Type | Default | Description | | ----------- | ----------- | ------- | ------------------------ | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode` | - | Custom indicator content | ### ContextMenu.SubmenuTrigger | Prop | Type | Default | Description | | ---------- | --------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | | `children` | `ReactNode` | - | The item and a `ContextMenu.Popover` holding the submenu; opening and selecting a submenu item are tested in jsdom only, with no story or browser test | | `...rest` | `SubmenuTriggerProps` | - | React Aria [SubmenuTrigger](https://react-spectrum.adobe.com/react-aria/Menu.html#submenutrigger) attributes |
# Dropdown > Dropdown menu triggered by a button **Category**: components **URL**: https://peakui.dev/en/docs/react/components/dropdown **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(collections)/dropdown.mdx ## Usage ```tsx import {Dropdown} from "@peakui/react"; ``` ```tsx "use client"; import {Button, Dropdown, Label} from "@peakui/react"; export function Basic() { return ( console.log(`Selected: ${key}`)}> ); } ``` ### Anatomy ```tsx import {Button, Description, Dropdown, Kbd, Label, Separator} from "@peakui/react"; export default () => ( ); ``` ## Examples ### With Icons ```tsx "use client"; import {FloppyDisk, FolderOpen, SquarePlus, TrashBin} from "@gravity-ui/icons"; import {Button, Dropdown, Kbd, Label} from "@peakui/react"; export function WithIcons() { return ( console.log(`Selected: ${key}`)}> N O S D ); } ``` ### With Descriptions ```tsx "use client"; import {FloppyDisk, FolderOpen, SquarePlus, TrashBin} from "@gravity-ui/icons"; import {Button, Description, Dropdown, Kbd, Label} from "@peakui/react"; export function WithDescriptions() { return ( console.log(`Selected: ${key}`)}>
Create a new file
N
Open an existing file
O
Save the current file
S
Move to trash
D
); } ``` ### With Disabled Items ```tsx "use client"; import {Pencil, SquarePlus, TrashBin} from "@gravity-ui/icons"; import {Button, Description, Dropdown, Kbd, Label, Separator} from "@peakui/react"; export function WithDisabledItems() { return ( console.log(key)}>
Create a new file
N
Make changes
E
Move to trash
D
); } ``` ### With Sections ```tsx "use client"; import {Pencil, SquarePlus, TrashBin} from "@gravity-ui/icons"; import {Button, Description, Dropdown, Kbd, Label, Separator} from "@peakui/react"; export function WithSections() { return ( console.log(`Selected: ${key}`)}>
Create a new file
N
Make changes
E
Move to trash
D
); } ``` ### With Single Selection ```tsx "use client"; import {Button, Dropdown, Label} from "@peakui/react"; import {useState} from "react"; export function WithSingleSelection() { const [selected, setSelected] = useState<"all" | Set>(new Set(["apple"])); return ( ); } ``` ### Single With Custom Indicator ```tsx "use client"; import {Button, Dropdown, Label} from "@peakui/react"; import {useState} from "react"; const CustomCheckmarkIcon = ( ); export function SingleWithCustomIndicator() { const [selected, setSelected] = useState<"all" | Set>(new Set(["apple"])); return ( {({isSelected}) => (isSelected ? CustomCheckmarkIcon : null)} {({isSelected}) => (isSelected ? CustomCheckmarkIcon : null)} {({isSelected}) => (isSelected ? CustomCheckmarkIcon : null)} {({isSelected}) => (isSelected ? CustomCheckmarkIcon : null)} {({isSelected}) => (isSelected ? CustomCheckmarkIcon : null)} ); } ``` ### With Multiple Selection ```tsx "use client"; import {Button, Dropdown, Label} from "@peakui/react"; import {useState} from "react"; export function WithMultipleSelection() { const [selected, setSelected] = useState<"all" | Set>(new Set(["apple"])); return ( ); } ``` ### With Section Level Selection ```tsx "use client"; import {Button, Dropdown, Kbd, Label, Separator} from "@peakui/react"; import {useState} from "react"; export function WithSectionLevelSelection() { const [textStyles, setTextStyles] = useState<"all" | Set>( new Set(["bold", "italic"]), ); const [textAlignment, setTextAlignment] = useState<"all" | Set>( new Set(["left"]), ); return ( X C V B I U A H D ); } ``` ### With Keyboard Shortcuts ```tsx "use client"; import {Button, Dropdown, Kbd, Label} from "@peakui/react"; export function WithKeyboardShortcuts() { return ( console.log(`Selected: ${key}`)}> N O S D ); } ``` ### With Submenus ```tsx "use client"; import {Button, Dropdown, Label} from "@peakui/react"; export function WithSubmenus() { return ( console.log(`Selected: ${key}`)}> ); } ``` ### With Custom Submenu Indicator ```tsx "use client"; import {ArrowRight} from "@gravity-ui/icons"; import {Button, Dropdown, Label} from "@peakui/react"; export function WithCustomSubmenuIndicator() { return ( console.log(`Selected: ${key}`)}> ); } ``` ### Custom Trigger ```tsx "use client"; import {ArrowRightFromSquare, Gear, Persons} from "@gravity-ui/icons"; import {Dropdown, Label} from "@peakui/react"; export function CustomTrigger() { return ( User avatar
Jane

Jane Doe

jane@example.com

); } ``` ### Long Press Trigger ```tsx import {Button, Dropdown, Label} from "@peakui/react"; export function LongPressTrigger() { return ( ); } ``` ### Controlled ```tsx "use client"; import {Button, Dropdown, Label} from "@peakui/react"; import {useState} from "react"; export function Controlled() { const [selected, setSelected] = useState<"all" | Set>(new Set(["bold"])); const selectedItems = Array.from(selected === "all" ? [] : selected); return (

Selected: {selectedItems.length > 0 ? selectedItems.join(", ") : "None"}

); } ``` ### Controlled Open State ```tsx "use client"; import {Button, Dropdown, Label} from "@peakui/react"; import {useState} from "react"; export function ControlledOpenState() { const [open, setOpen] = useState(false); return (

Dropdown is: {open ? "open" : "closed"}

); } ``` ## Customization ### Tailwind CSS ```tsx import {Button, Dropdown, Label} from "@peakui/react"; export function CustomStyles() { return ( ); } ``` ### Global CSS ```css @layer components { .dropdown { @apply flex flex-col gap-1; } .dropdown__trigger { @apply outline-none; } .dropdown__popover { @apply rounded-lg border border-border bg-overlay p-2; } .dropdown__menu { @apply flex flex-col gap-1; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The Dropdown component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/dropdown.css)): #### Base Classes - `.dropdown` - Base dropdown container - `.dropdown__trigger` - The trigger rendered by `Dropdown.Trigger` - `.dropdown__popover` - The popover that holds the open menu - `.dropdown__menu` - The menu container inside the popover ### Slots - `[data-slot="dropdown-trigger"]` - `[data-slot="dropdown-popover"]` - `[data-slot="dropdown-menu"]` - `[data-slot="dropdown-submenu-trigger"]` ### Interactive States The component supports both CSS pseudo-classes and data attributes: - **Focus**: `:focus-visible` or `[data-focus-visible="true"]` on the trigger - **Disabled**: `:disabled` or `[aria-disabled="true"]` on the trigger - **Pending**: `[data-pending="true"]` on the trigger - **Pressed**: `:active` or `[data-pressed="true"]` on the trigger - **Entering**: `[data-entering="true"]` on the popover - **Exiting**: `[data-exiting="true"]` on the popover ## API Reference ### Dropdown | Prop | Type | Default | Description | | -------------- | --------------------------- | --------- | ------------------------------------------------------------------------------------------------- | | `isOpen` | `boolean` | - | Sets the open state of the menu (controlled) | | `defaultOpen` | `boolean` | - | Sets the default open state of the menu (uncontrolled) | | `onOpenChange` | `(isOpen: boolean) => void` | - | Handler called when the open state changes | | `trigger` | `"press" \| "longPress"` | `"press"` | The type of interaction that triggers the menu | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode` | - | Dropdown content | | `...rest` | `MenuTriggerProps` | - | React Aria [MenuTrigger](https://react-spectrum.adobe.com/react-aria/MenuTrigger.html) attributes | ### Dropdown.Trigger | Prop | Type | Default | Description | | ----------- | ----------------------------- | ------- | --------------------------------------------------------------------------------------- | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode \| RenderFunction` | - | Trigger content or render function | | `...rest` | `ButtonProps` | - | React Aria [Button](https://react-spectrum.adobe.com/react-aria/Button.html) attributes | ### Dropdown.Popover | Prop | Type | Default | Description | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------- | ----------------------------------------------------------------------------------------- | | `placement` | `"bottom" \| "bottom left" \| "bottom right" \| "bottom start" \| "bottom end" \| "top" \| "top left" \| "top right" \| "top start" \| "top end" \| "left" \| "left top" \| "left bottom" \| "start" \| "start top" \| "start bottom" \| "right" \| "right top" \| "right bottom" \| "end" \| "end top" \| "end bottom"` | `"bottom"` | Placement of the popover relative to the trigger | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode` | - | Popover content | | `...rest` | `PopoverProps` | - | React Aria [Popover](https://react-spectrum.adobe.com/react-aria/Popover.html) attributes | ### Dropdown.Menu | Prop | Type | Default | Description | | --------------------- | ---------------------------------- | -------- | ---------------------------------------------------------------------------------------- | | `selectionMode` | `"single" \| "multiple" \| "none"` | `"none"` | Whether single or multiple selection is enabled | | `selectedKeys` | `Iterable` | - | The currently selected keys (controlled) | | `defaultSelectedKeys` | `Iterable` | - | The initial selected keys (uncontrolled) | | `onSelectionChange` | `(keys: Selection) => void` | - | Handler called when the selection changes | | `disabledKeys` | `Iterable` | - | Keys of disabled items | | `onAction` | `(key: Key) => void` | - | Handler called when an item is activated | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode` | - | Menu content | | `...rest` | `MenuProps` | - | React Aria [Menu](https://react-spectrum.adobe.com/react-aria/Menu.html#menu) attributes | ### Dropdown.Section | Prop | Type | Default | Description | | --------------------- | --------------------------- | ------- | ------------------------------------------------------------------------------------------------------ | | `selectionMode` | `"single" \| "multiple"` | - | Selection mode for items within this section | | `selectedKeys` | `Iterable` | - | The currently selected keys (controlled) | | `defaultSelectedKeys` | `Iterable` | - | The initial selected keys (uncontrolled) | | `onSelectionChange` | `(keys: Selection) => void` | - | Handler called when the selection changes | | `disabledKeys` | `Iterable` | - | Keys of disabled items | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode` | - | Section content | | `...rest` | `MenuSectionProps` | - | React Aria [MenuSection](https://react-spectrum.adobe.com/react-aria/Menu.html#menusection) attributes | ### Dropdown.Item | Prop | Type | Default | Description | | ------------ | ----------------------------- | ----------- | ------------------------------------------------------------------------------------------------ | | `id` | `Key` | - | Unique identifier for the item | | `textValue` | `string` | - | Text content of the item for typeahead | | `variant` | `"default" \| "danger"` | `"default"` | Visual variant of the item | | `isDisabled` | `boolean` | - | Whether the item is disabled | | `href` | `string` | - | Renders the item as a link to this URL | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode \| RenderFunction` | - | Item content or render function | | `...rest` | `MenuItemProps` | - | React Aria [MenuItem](https://react-spectrum.adobe.com/react-aria/Menu.html#menuitem) attributes | ### Dropdown.ItemIndicator | Prop | Type | Default | Description | | ----------- | ----------------------------- | ------------- | ------------------------------------------- | | `type` | `"checkmark" \| "dot"` | `"checkmark"` | Type of indicator to display | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode \| RenderFunction` | - | Custom indicator content or render function | ### Dropdown.SubmenuIndicator | Prop | Type | Default | Description | | ----------- | ----------- | ------- | ------------------------ | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode` | - | Custom indicator content | ### Dropdown.SubmenuTrigger | Prop | Type | Default | Description | | ----------- | --------------------- | ------- | ------------------------------------------------------------------------------------------------------------ | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode` | - | Submenu trigger content | | `...rest` | `SubmenuTriggerProps` | - | React Aria [SubmenuTrigger](https://react-spectrum.adobe.com/react-aria/Menu.html#submenutrigger) attributes | ### Render Props When using render functions with `Dropdown.Item`, these values are provided: | Prop | Type | Description | | ------------ | --------- | --------------------------------- | | `isSelected` | `boolean` | Whether the item is selected | | `isFocused` | `boolean` | Whether the item is focused | | `isDisabled` | `boolean` | Whether the item is disabled | | `isPressed` | `boolean` | Whether the item is being pressed | | `hasSubmenu` | `boolean` | Whether the item opens a submenu | When using render functions with `Dropdown.ItemIndicator`, these values are provided: | Prop | Type | Description | | ----------------- | --------- | --------------------------------------------- | | `isSelected` | `boolean` | Whether the item is selected | | `isIndeterminate` | `boolean` | Whether the item is in an indeterminate state |
# ListBox > A listbox displays selectable options **Category**: components **URL**: https://peakui.dev/en/docs/react/components/list-box **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(collections)/list-box.mdx ## Usage ```tsx import { ListBox } from "@peakui/react"; ``` ```tsx import {Description, Label, ListBox} from "@peakui/react"; export function Basic() { return ( B
bob@peakui.dev
F
fred@peakui.dev
M
martha@peakui.dev
); } ``` ### Anatomy ```tsx import { Description, Label, ListBox } from "@peakui/react"; export default () => ( ); ``` ## Examples ### With Sections ```tsx "use client"; import {Pencil, SquarePlus, TrashBin} from "@gravity-ui/icons"; import {Description, Kbd, Label, ListBox, Separator, Surface} from "@peakui/react"; export function WithSections() { return ( alert(`Selected item: ${key}`)} > {/* A visible section heading needs a Header part; until one ships, aria-label names the group. */}
Create a new file
N
Make changes
E
Move to trash
D
); } ``` ### With Disabled Items ```tsx "use client"; import {Pencil, SquarePlus, TrashBin} from "@gravity-ui/icons"; import {Description, Kbd, Label, ListBox, Separator, Surface} from "@peakui/react"; export function WithDisabledItems() { return ( alert(`Selected item: ${key}`)} >
Create a new file
N
Make changes
E
Move to trash
D
); } ``` ### Multi Select ```tsx import {Description, Label, ListBox, Surface} from "@peakui/react"; export function MultiSelect() { return ( B
bob@peakui.dev
F
fred@peakui.dev
M
martha@peakui.dev
); } ``` ### Controlled ```tsx "use client"; import type {ListBoxProps} from "@peakui/react"; import {Check} from "@gravity-ui/icons"; import {Description, Label, ListBox, Surface} from "@peakui/react"; import {useState} from "react"; /* The selection type as the listbox itself declares it, so the state and the handler agree. */ type SelectedKeys = Parameters["onSelectionChange"]>>[0]; export function Controlled() { const [selected, setSelected] = useState(new Set(["1"])); const selectedItems = selected === "all" ? "All" : [...selected].join(", "); return (
B
bob@peakui.dev
{({isSelected}) => isSelected ? : null }
F
fred@peakui.dev
{({isSelected}) => isSelected ? : null }
M
martha@peakui.dev
{({isSelected}) => isSelected ? : null }

Selected: {selectedItems.length > 0 ? selectedItems : "None"}

); } ``` ### Custom Check Icon ```tsx "use client"; import {Check} from "@gravity-ui/icons"; import {Description, Label, ListBox, Surface} from "@peakui/react"; export function CustomCheckIcon() { return ( B
bob@peakui.dev
{({isSelected}) => isSelected ? : null }
F
fred@peakui.dev
{({isSelected}) => isSelected ? : null }
M
martha@peakui.dev
{({isSelected}) => isSelected ? : null }
); } ``` ### Render Function ```tsx "use client"; import {Description, Label, ListBox} from "@peakui/react"; export function RenderFunction() { return (
} selectionMode="single" > } textValue="Bob" > B
bob@peakui.dev
} textValue="Fred" > F
fred@peakui.dev
} textValue="Martha" > M
martha@peakui.dev
); } ``` ## Customization ### Tailwind CSS ```tsx import {Description, Label, ListBox} from "@peakui/react"; export function CustomStyles() { return ( B
bob@peakui.dev
F
fred@peakui.dev
); } ``` ### Global CSS ```css @layer components { .list-box { @apply rounded-lg border border-border bg-surface p-2; } .list-box-item { @apply rounded px-2 py-1 cursor-pointer; } .list-box-item--danger { @apply text-danger; } .list-box-item__indicator { @apply text-accent; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The ListBox component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/list-box.css)): #### Base Classes - `.list-box` - Base listbox container - `.list-box-item` - Individual listbox item - `.list-box-item__indicator` - Selection indicator icon - `.list-box-section` - Section container for grouping items #### Variant Classes - `.list-box--default` - Default variant - `.list-box--danger` - Danger variant - `.list-box-item--default` - Default item variant - `.list-box-item--danger` - Danger item variant ### Slots - `[data-slot="list-box"]` - The listbox root - `[data-slot="list-box-item"]` - A listbox item - `[data-slot="list-box-item-indicator"]` - The selection indicator - `[data-slot="list-box-item-indicator--checkmark"]` - The default checkmark glyph - `[data-slot="list-box-section"]` - A section ### Interactive States The component supports both CSS pseudo-classes and data attributes: - **Hover**: `:hover` or `[data-hovered="true"]` on item - **Focus**: `:focus-visible` or `[data-focus-visible="true"]` on item - **Pressed**: `:active` or `[data-pressed="true"]` on item - **Selected**: `[aria-selected="true"]` or `[data-selected="true"]` on item - **Disabled**: `[data-disabled="true"]` on item - **Indicator visible**: `[data-visible="true"]` on the indicator ## API Reference ### ListBox | Prop | Type | Default | Description | | --------------------- | -------------------------------------------------------------------------- | ----------- | --------------------------------------------------------------- | | `aria-label` | `string` | - | Accessibility label for the listbox | | `aria-labelledby` | `string` | - | ID of element that labels the listbox | | `selectionMode` | `"none" \| "single" \| "multiple"` | `"single"` | Selection behavior | | `selectedKeys` | `Selection` | - | Controlled selected keys | | `defaultSelectedKeys` | `Selection` | - | Initial selected keys | | `onSelectionChange` | `(keys: Selection) => void` | - | Handler called when selection changes | | `disabledKeys` | `Iterable` | - | Keys of disabled items | | `onAction` | `(key: Key) => void` | - | Handler called when an item is activated | | `variant` | `"default" \| "danger"` | `"default"` | Visual variant | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode` | - | ListBox items and sections | | `render` | `DOMRenderFunction` | - | Overrides the default DOM element with a custom render function | ### ListBox.Item | Prop | Type | Default | Description | | ------------ | ------------------------------------------------------------------- | ----------- | --------------------------------------------------------------- | | `id` | `Key` | - | Unique identifier for the item | | `textValue` | `string` | - | Text value for accessibility and typeahead | | `isDisabled` | `boolean` | `false` | Whether this item is disabled | | `variant` | `"default" \| "danger"` | `"default"` | Visual variant | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode \| ((renderProps: ListBoxItemRenderProps) => ReactNode)` | - | Item content or render function | | `render` | `(props, renderProps: ListBoxItemRenderProps) => ReactElement` | - | Overrides the default DOM element with a custom render function | ### ListBox.ItemIndicator | Prop | Type | Default | Description | | ----------- | ------------------------------------------------------------------- | ------- | ------------------------------------------- | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode \| ((renderProps: ListBoxItemRenderProps) => ReactNode)` | - | Custom indicator content or render function | ### ListBox.Section | Prop | Type | Default | Description | | ------------ | ----------- | ------- | -------------------------------------- | | `aria-label` | `string` | - | Accessibility label for the group | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode` | - | Section content: a heading, then items | ### Render Props When using render functions with `ListBox.Item` or `ListBox.ItemIndicator`, these values are provided: | Prop | Type | Description | | ------------ | --------- | --------------------------------- | | `isSelected` | `boolean` | Whether the item is selected | | `isFocused` | `boolean` | Whether the item is focused | | `isDisabled` | `boolean` | Whether the item is disabled | | `isPressed` | `boolean` | Whether the item is being pressed | # Menu > Inline menu that is always visible **Category**: components **URL**: https://peakui.dev/en/docs/react/components/menu **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(collections)/menu.mdx ## Usage ```tsx import {Menu} from "@peakui/react"; ``` ```tsx import {Label, Menu} from "@peakui/react"; export function Basic() { return (
); } ``` ### Anatomy ```tsx import {Label, Menu, Separator} from "@peakui/react"; // Menu.Item, Menu.Section and the indicators are the menu parts shared with Dropdown. // Dividers use Separator; there is no Menu.Separator. export default () => ( ); ``` ## Examples ### With Sections ```tsx import {Label, Menu, Separator} from "@peakui/react"; export function WithSections() { return (
); } ``` ### With Selection ```tsx import {Label, Menu} from "@peakui/react"; export function WithSelection() { return (
); } ``` ## Customization ### Tailwind CSS ```tsx ``` ### Global CSS ```css @layer components { .menu { @apply gap-1 rounded-xl border border-border p-2; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The Menu component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/menu.css)): #### Base Classes - `.menu` - Inline menu container - `.menu-item` - Menu item - `.menu-section` - Menu section #### Element Classes - `.menu-item__indicator` - Selection indicator of an item - `.menu-item__indicator--submenu` - Submenu indicator of an item #### Variant Classes - `.menu-item--default` - `.menu-item--danger` ### Slots - `[data-slot="menu"]` - `[data-slot="menu-item"]` - `[data-slot="menu-section"]` - `[data-slot="menu-item-indicator"]` - `[data-slot="menu-item-indicator--checkmark"]` - `[data-slot="menu-item-indicator--dot"]` - `[data-slot="submenu-indicator"]` ### Interactive States The component supports both CSS pseudo-classes and data attributes: - **Selection mode**: `[data-selection-mode]` on the menu - **Hover**: `:hover` or `[data-hovered="true"]` on an item - **Focus**: `:focus-visible` or `[data-focus-visible="true"]` on an item - **Pressed**: `:active` or `[data-pressed="true"]` on an item - **Selected**: `[aria-checked="true"]`, `[aria-selected="true"]` or `[data-selected="true"]` on an item; `[data-visible]` on its indicator - **Disabled**: `[data-disabled="true"]` on an item - **Submenu**: `[data-has-submenu="true"]` on an item ## API Reference ### Menu | Prop | Type | Default | Description | | --------------------- | ---------------------------------- | -------- | ---------------------------------------------------------------------------------------- | | `selectionMode` | `"single" \| "multiple" \| "none"` | `"none"` | Whether single or multiple selection is enabled | | `selectedKeys` | `Iterable` | - | The currently selected keys (controlled) | | `defaultSelectedKeys` | `Iterable` | - | The initial selected keys (uncontrolled) | | `onSelectionChange` | `(keys: Selection) => void` | - | Handler called when the selection changes | | `disabledKeys` | `Iterable` | - | Keys of disabled items | | `onAction` | `(key: Key) => void` | - | Handler called when an item is activated | | `className` | `string \| ((values) => string)` | - | Additional CSS classes | | `children` | `ReactNode` | - | Menu content | | `...rest` | `MenuProps` | - | React Aria [Menu](https://react-spectrum.adobe.com/react-aria/Menu.html#menu) attributes | ### Menu.Item | Prop | Type | Default | Description | | ------------ | ----------------------------- | ----------- | ------------------------------------------------------------------------------------------------ | | `id` | `Key` | - | Unique identifier for the item | | `textValue` | `string` | - | Text content of the item for typeahead | | `variant` | `"default" \| "danger"` | `"default"` | Visual variant of the item | | `isDisabled` | `boolean` | - | Whether the item is disabled | | `href` | `string` | - | Renders the item as a link to this URL | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode \| RenderFunction` | - | Item content or render function | | `...rest` | `MenuItemProps` | - | React Aria [MenuItem](https://react-spectrum.adobe.com/react-aria/Menu.html#menuitem) attributes | ### Menu.Section | Prop | Type | Default | Description | | ----------- | ------------------ | ------- | ------------------------------------------------------------------------------------------------------ | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode` | - | Section content | | `...rest` | `MenuSectionProps` | - | React Aria [MenuSection](https://react-spectrum.adobe.com/react-aria/Menu.html#menusection) attributes | ### Menu.ItemIndicator | Prop | Type | Default | Description | | ----------- | ----------------------------- | ------------- | ------------------------------------------- | | `type` | `"checkmark" \| "dot"` | `"checkmark"` | Type of indicator to display | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode \| RenderFunction` | - | Custom indicator content or render function | ### Menu.SubmenuIndicator | Prop | Type | Default | Description | | ----------- | ----------- | ------- | ------------------------ | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode` | - | Custom indicator content |
# TagGroup > A focusable list of selectable and removable tags **Category**: components **URL**: https://peakui.dev/en/docs/react/components/tag-group **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(collections)/tag-group.mdx ## Usage ```tsx import {TagGroup} from "@peakui/react"; ``` ```tsx import {PlanetEarth, Rocket, ShoppingBag, SquareArticle} from "@gravity-ui/icons"; import {Tag, TagGroup} from "@peakui/react"; export function Basic() { return ( News Travel Gaming Shopping ); } ``` ### Anatomy ```tsx import {Description, Label, Tag, TagGroup} from "@peakui/react"; export default () => ( Tag label Optional hint ); ``` ## Examples ### Sizes `size` on the group scales every tag. ```tsx import {Label, Tag, TagGroup} from "@peakui/react"; export function Sizes() { return (
News Travel Gaming News Travel Gaming News Travel Gaming
); } ``` ### Variants `variant` switches the tag background between default and surface. ```tsx import {Label, Tag, TagGroup} from "@peakui/react"; export function Variants() { return (
News Travel Gaming News Travel Gaming
); } ``` ### Disabled State `isDisabled` disables one tag; `disabledKeys` disables tags by id. ```tsx import {Description, Label, Tag, TagGroup} from "@peakui/react"; export function Disabled() { return (
News Travel Gaming Some tags are disabled News Travel Gaming Tags disabled via disabledKeys prop
); } ``` ### Selection Modes `selectionMode` allows a single or multiple selected tags. ```tsx "use client"; import {Description, Label, Tag, TagGroup} from "@peakui/react"; import {useState} from "react"; export function SelectionModes() { const [singleSelected, setSingleSelected] = useState>( new Set(["news"]), ); const [multipleSelected, setMultipleSelected] = useState>( new Set(["news", "travel"]), ); return (
setSingleSelected(keys)} > News Travel Gaming Shopping Choose one category setMultipleSelected(keys)} > News Travel Gaming Shopping Choose multiple categories
); } ``` ### Controlled Selection `selectedKeys` with `onSelectionChange` controls the selection from state. ```tsx "use client"; import {Description, Label, Tag, TagGroup} from "@peakui/react"; import {useState} from "react"; export function Controlled() { const [selected, setSelected] = useState>(new Set(["news", "travel"])); return (
setSelected(keys)} > News Travel Gaming Shopping Selected: {Array.from(selected).length > 0 ? Array.from(selected).join(", ") : "None"}
); } ``` ### With Prefix Any element prefix renders before the label. ```tsx import {PlanetEarth, Rocket, ShoppingBag, SquareArticle} from "@gravity-ui/icons"; import {Description, Label, Tag, TagGroup} from "@peakui/react"; export function WithPrefix() { return ( News Travel Gaming Shopping Tags with icons ); } ``` ### With Remove Button `onRemove` renders a remove button in every tag automatically. ```tsx "use client"; import {CircleXmarkFill} from "@gravity-ui/icons"; import {Description, EmptyState, Label, Tag, TagGroup} from "@peakui/react"; import {useState} from "react"; export function WithRemoveButton() { type TagItem = {id: string; name: string}; const [tags, setTags] = useState([ {id: "news", name: "News"}, {id: "travel", name: "Travel"}, {id: "gaming", name: "Gaming"}, {id: "shopping", name: "Shopping"}, ]); const [frameworks, setFrameworks] = useState([ {id: "react", name: "React"}, {id: "vue", name: "Vue"}, {id: "angular", name: "Angular"}, {id: "svelte", name: "Svelte"}, ]); const onRemoveTags = (keys: Set) => { setTags(tags.filter((tag) => !keys.has(tag.id))); }; const onRemoveFrameworks = (keys: Set) => { setFrameworks(frameworks.filter((framework) => !keys.has(framework.id))); }; return (
No categories found} > {(tag) => ( {tag.name} )} Click the X to remove tags
No frameworks found} > {(tag) => ( {(renderProps) => ( <> {tag.name} {!!renderProps.allowsRemoving && ( )} )} )} Custom remove button with icon
No frameworks found} > {(tag) => ( {tag.name} )} Custom remove button as a compound part
); } ``` ### Render Function `render` on the root replaces the rendered element. ```tsx "use client"; import {PlanetEarth, Rocket, ShoppingBag, SquareArticle} from "@gravity-ui/icons"; import {Tag, TagGroup} from "@peakui/react"; export function RenderFunction() { return (
} selectionMode="single" > News Travel Gaming Shopping ); } ``` ## Customization ### Tailwind CSS ```tsx import {PlanetEarth, Rocket, ShoppingBag, SquareArticle} from "@gravity-ui/icons"; import {Tag, TagGroup} from "@peakui/react"; const tagClass = "group/tag gap-1.5 rounded-full border border-neutral-300/80 bg-white/80 px-2.5 py-1 text-sm font-medium text-neutral-700 shadow-sm ring-1 ring-black/5 backdrop-blur-sm transition-colors data-[selected=true]:border-neutral-500 data-[selected=true]:bg-neutral-900 data-[selected=true]:text-neutral-50 dark:border-neutral-600/80 dark:bg-neutral-900/60 dark:text-neutral-200 dark:ring-white/10 dark:data-[selected=true]:border-neutral-400 dark:data-[selected=true]:bg-neutral-100 dark:data-[selected=true]:text-neutral-900"; const iconClass = "size-4 shrink-0 text-neutral-500 group-data-[selected=true]/tag:text-current dark:text-neutral-400"; export function CustomStyles() { return ( News Travel Gaming Shopping ); } ``` ### Global CSS ```css @layer components { .tag-group { @apply flex flex-col gap-2; } .tag-group__list { @apply flex flex-wrap gap-2; } .tag { @apply rounded-full px-3 py-1; } .tag__remove-button { @apply ml-1; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The TagGroup component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/tag-group.css) and [tag.css](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/tag.css)): #### Base Classes - `.tag-group` - Base tag group container - `.tag-group__list` - Container for the list of tags - `.tag` - Base tag styles - `.tag__remove-button` - Remove button trigger #### Size Classes - `.tag--sm` - Small size tag - `.tag--md` - Medium size tag (default) - `.tag--lg` - Large size tag #### Variant Classes - `.tag--default` - Default variant - `.tag--surface` - Surface variant with surface background #### Field Slot Classes - `.tag-group [slot="description"]` - Description slot styles - `.tag-group [data-slot="description"]` - Description slot styles, data-attribute form - `.tag-group [slot="errorMessage"]` - Error message slot styles - `.tag-group [data-slot="error-message"]` - Error message slot styles, data-attribute form ### Slots - `[data-slot="tag-group"]` - The tag group root - `[data-slot="tag-group-list"]` - The list of tags - `[data-slot="tag"]` - A single tag - `[data-slot="tag-remove-button"]` - The remove button inside a tag ### Interactive States The component supports both CSS pseudo-classes and data attributes: - **Hover**: `:hover` or `[data-hovered="true"]` on the tag - **Focus**: `:focus-visible` or `[data-focus-visible]` on the tag - **Selected**: `[data-selected="true"]` or `[aria-selected="true"]` on the tag - **Disabled**: `[data-disabled="true"]` or `[aria-disabled="true"]` on the tag ## API Reference ### TagGroup | Prop | Type | Default | Description | | --------------------- | ------------------------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | | `selectionMode` | `"none" \| "single" \| "multiple"` | `"none"` | The type of selection that is allowed | | `selectedKeys` | `Selection` | - | The currently selected keys (controlled) | | `defaultSelectedKeys` | `Selection` | - | The initial selected keys (uncontrolled) | | `onSelectionChange` | `(keys: Selection) => void` | - | Handler called when the selection changes | | `disabledKeys` | `Iterable` | - | Keys of disabled tags | | `isDisabled` | `boolean` | - | Whether the tag group is disabled | | `onRemove` | `(keys: Set) => void` | - | Handler called when tags are removed | | `size` | `"sm" \| "md" \| "lg"` | `"md"` | Size of the tags in the group | | `variant` | `"default" \| "surface"` | `"default"` | Visual variant of the tags | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode` | - | TagGroup content | | `render` | `DOMRenderFunction<"div", undefined>` | - | Replaces the rendered `
` with a custom render function | | `...rest` | `React Aria TagGroup attributes` | - | Focus, keyboard navigation and DOM attributes of the underlying [React Aria TagGroup](https://react-spectrum.adobe.com/react-aria-components/TagGroup.html) | ### TagGroup.List | Prop | Type | Default | Description | | ------------------ | ---------------------------------------------- | ------- | ------------------------------------------------------------------ | | `items` | `Iterable` | - | The items to display in the tag list | | `renderEmptyState` | `(props: TagListRenderProps) => ReactNode` | - | Function to render when the list is empty | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode \| ((item: T) => ReactElement)` | - | TagList content or item render function | | `render` | `DOMRenderFunction<"div", TagListRenderProps>` | - | Replaces the rendered `
` with a custom render function | | `...rest` | `React Aria TagList attributes` | - | Collection and DOM attributes of the underlying React Aria TagList | Name the group with `aria-label` or a `Label`; without one the grid has no accessible name. ### Tag | Prop | Type | Default | Description | | ------------ | ----------------------------------------------------------- | ------- | ---------------------------------------------------------------------------------------------------------- | | `id` | `Key` | - | The unique identifier for the tag | | `textValue` | `string` | - | A string representation of the tag's content, used for accessibility; falls back to the first string child | | `isDisabled` | `boolean` | - | Whether the tag is disabled | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode \| ((renderProps: TagRenderProps) => ReactNode)` | - | Tag content or render function | | `render` | `DOMRenderFunction<"div", undefined>` | - | Replaces the rendered `
` with a custom render function | | `...rest` | `React Aria Tag attributes` | - | Selection, hover, focus and press attributes of the underlying React Aria Tag | `size` and `variant` are inherited from the parent `TagGroup` and cannot be set on individual tags. ### Tag.RemoveButton | Prop | Type | Default | Description | | ----------- | ------------------------------ | ------- | ------------------------------------------------------------ | | `className` | `string` | - | Additional CSS classes | | `children` | `ReactNode` | - | Custom remove button content (defaults to close icon) | | `...rest` | `React Aria Button attributes` | - | Press and DOM attributes of the underlying React Aria Button | When `onRemove` is provided to `TagGroup`, a remove button renders automatically; a `Tag.RemoveButton` passed as a child of `Tag` replaces it. ### Render Props When the `Tag` children is a function, it receives these values: | Prop | Type | Description | | ---------------- | --------- | -------------------------------------------------- | | `isSelected` | `boolean` | Whether the tag is selected | | `isDisabled` | `boolean` | Whether the tag is disabled | | `isHovered` | `boolean` | Whether the tag is hovered | | `isPressed` | `boolean` | Whether the tag is pressed | | `isFocused` | `boolean` | Whether the tag is focused | | `isFocusVisible` | `boolean` | Whether the tag has keyboard focus | | `allowsRemoving` | `boolean` | Whether the tag group allows the tag to be removed | # ColorArea > Two-channel color selection on a gradient area **Category**: components **URL**: https://peakui.dev/en/docs/react/components/color-area **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(colors)/color-area.mdx ## Usage ```tsx import {ColorArea} from "@peakui/react"; ``` ```tsx import {ColorArea} from "@peakui/react"; export function Basic() { return ( ); } ``` ### Anatomy ```tsx import {ColorArea} from "@peakui/react"; export default () => ( ); ``` ## Examples ### With Dots ```tsx import {ColorArea} from "@peakui/react"; export function WithDots() { return ( ); } ``` ### RGB Channels ```tsx import {ColorArea} from "@peakui/react"; export function RgbChannels() { return ( ); } ``` ### Disabled ```tsx import {ColorArea} from "@peakui/react"; export function Disabled() { return ( ); } ``` ## Customization ### Tailwind CSS ```tsx ``` ### Global CSS ```css @layer components { .color-area { @apply max-w-64; } .color-area__thumb { @apply size-5; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The ColorArea component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/color-area.css)): #### Base Classes - `.color-area` - Gradient area, square, up to 224px wide - `.color-area__thumb` - Draggable thumb with a white border #### Modifier Classes - `.color-area--show-dots` - Dot grid over the gradient ### Slots - `[data-slot="color-area"]` - `[data-slot="color-area-thumb"]` ### CSS Variables | Variable | Purpose | | --------------------------- | ----------------------------------------------------------- | | `--color-area-background` | The gradient, set by the component from the current value | | `--color-area-thumb-color` | The thumb fill, set by the component from the current value | | `--color-area-ring` | The inset ring on the area and the thumb | | `--color-area-thumb-border` | The thumb border colour | ### Interactive States - **Focus**: `:focus-visible` or `[data-focus-visible="true"]` on `.color-area__thumb` - **Dragging**: `[data-dragging="true"]` on `.color-area__thumb` enlarges the thumb - **Disabled**: `[data-disabled="true"]` on `.color-area` and `.color-area__thumb` ## API Reference ### ColorArea | Prop | Type | Default | Description | | -------------- | -------------------------------------------------------------------- | ------- | --------------------------------------------------------- | | `showDots` | `boolean` | `false` | Overlays a dot grid on the gradient | | `xChannel` | `ColorChannel` | - | The channel on the horizontal axis | | `yChannel` | `ColorChannel` | - | The channel on the vertical axis | | `colorSpace` | `"rgb" \| "hsl" \| "hsb"` | - | The color space of the area | | `value` | `string \| Color` | - | The current color (controlled) | | `defaultValue` | `string \| Color` | - | The initial color (uncontrolled) | | `onChange` | `(value: Color) => void` | - | Called as the thumb moves | | `onChangeEnd` | `(value: Color) => void` | - | Called when a drag or key press ends | | `isDisabled` | `boolean` | `false` | Disables the area | | `className` | `string \| ((values: ColorAreaRenderProps) => string)` | - | Additional classes, or a function of the render props | | `style` | `CSSProperties \| ((values: ColorAreaRenderProps) => CSSProperties)` | - | Inline styles, or a function of the render props | | `...rest` | | | Every React Aria `ColorArea` prop, including `aria-label` | ### ColorArea.Thumb | Prop | Type | Default | Description | | ----------- | --------------------------------------------------------------------- | ------- | ----------------------------------------------------- | | `className` | `string \| ((values: ColorThumbRenderProps) => string)` | - | Additional classes, or a function of the render props | | `style` | `CSSProperties \| ((values: ColorThumbRenderProps) => CSSProperties)` | - | Inline styles, or a function of the render props | | `...rest` | | | Every React Aria `ColorThumb` prop | ### Render Props `className` and `style` functions on `ColorArea.Thumb` receive these values: | Prop | Type | Description | | ---------------- | --------------- | ------------------------------------ | | `isDragging` | `boolean` | Whether the thumb is being dragged | | `isDisabled` | `boolean` | Whether the thumb is disabled | | `isFocusVisible` | `boolean` | Whether the thumb has keyboard focus | | `defaultStyle` | `CSSProperties` | The position and colour RAC computes | # ColorField > Text field for editing a hex color **Category**: components **URL**: https://peakui.dev/en/docs/react/components/color-field **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(colors)/color-field.mdx ## Usage ```tsx import {ColorField, ColorInputGroup, Label} from "@peakui/react"; ``` ```tsx import {ColorField, ColorInputGroup, Label} from "@peakui/react"; export function Basic() { return ( ); } ``` ## Examples ### With Swatch ```tsx import {ColorField, ColorInputGroup, ColorSwatch, Label} from "@peakui/react"; export function WithSwatch() { return ( ); } ``` ### Invalid ```tsx import {ColorField, ColorInputGroup, FieldError, Label} from "@peakui/react"; export function Invalid() { return ( Pick a colour from the brand palette. ); } ``` ## Customization ### Tailwind CSS ```tsx ``` ### Global CSS ```css @layer components { .color-field { @apply gap-2; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The ColorField component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/color-field.css)): #### Base Classes - `.color-field` - Column of label, group and messages #### Modifier Classes - `.color-field--full-width` - Fills the container width ### Slots - `[data-slot="color-field"]` ### Interactive States - **Invalid**: `[data-invalid="true"]` or `[aria-invalid="true"]` hides the description ## API Reference ### ColorField | Prop | Type | Default | Description | | -------------- | ------------------------------------------------------- | ------- | ----------------------------------------------------- | | `fullWidth` | `boolean` | `false` | Makes the field fill its container | | `value` | `string \| Color \| null` | - | The current color (controlled) | | `defaultValue` | `string \| Color` | - | The initial color (uncontrolled) | | `onChange` | `(color: Color \| null) => void` | - | Called when a typed value is committed | | `channel` | `ColorChannel` | - | Edit one channel instead of the whole hex color | | `isDisabled` | `boolean` | `false` | Disables the field | | `isInvalid` | `boolean` | - | Marks the field invalid | | `isRequired` | `boolean` | `false` | Requires a value; sets `data-required` | | `className` | `string \| ((values: ColorFieldRenderProps) => string)` | - | Additional classes, or a function of the render props | | `...rest` | | | Every React Aria `ColorField` prop | ### Render Props `className` and `children` functions receive these values: | Prop | Type | Description | | ------------ | --------- | ----------------------------- | | `isDisabled` | `boolean` | Whether the field is disabled | | `isInvalid` | `boolean` | Whether the field is invalid | # ColorInputGroup > Hex input with a swatch prefix or suffix **Category**: components **URL**: https://peakui.dev/en/docs/react/components/color-input-group **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(colors)/color-input-group.mdx ## Usage ```tsx import {ColorField, ColorInputGroup, ColorSwatch} from "@peakui/react"; ``` ```tsx import {ColorField, ColorInputGroup, ColorSwatch} from "@peakui/react"; export function Basic() { return ( ); } ``` ### Anatomy ```tsx import {ColorField, ColorInputGroup, ColorSwatch} from "@peakui/react"; export default () => ( hex ); ``` ## Examples ### Secondary ```tsx import {ColorField, ColorInputGroup, ColorSwatch} from "@peakui/react"; export function Secondary() { return ( ); } ``` ### With Suffix ```tsx import {ColorField, ColorInputGroup} from "@peakui/react"; export function WithSuffix() { return ( hex ); } ``` ### Full Width ```tsx import {ColorField, ColorInputGroup, ColorSwatch} from "@peakui/react"; export function FullWidth() { return ( ); } ``` ## Customization ### Tailwind CSS ```tsx ``` ### Global CSS ```css @layer components { .color-input-group { --color-input-group-radius: var(--radius-lg); } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The ColorInputGroup component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/color-input-group.css)): #### Base Classes - `.color-input-group` - Shell with fill, border and focus ring - `.color-input-group__input` - Borderless, transparent control - `.color-input-group__prefix` - Slot before the control - `.color-input-group__suffix` - Slot after the control #### Variant Classes - `.color-input-group--primary` - Field fill with shadow (default) - `.color-input-group--secondary` - Neutral fill without shadow #### Modifier Classes - `.color-input-group--full-width` - Fills the container width ### Slots - `[data-slot="color-input-group"]` - `[data-slot="color-input-group-input"]` - `[data-slot="color-input-group-prefix"]` - `[data-slot="color-input-group-suffix"]` ### CSS Variables | Variable | Purpose | | ---------------------------------- | --------------------------- | | `--color-input-group-bg` | Fill | | `--color-input-group-bg-hover` | Fill on hover | | `--color-input-group-bg-focus` | Fill on focus | | `--color-input-group-fg` | Text colour | | `--color-input-group-placeholder` | Placeholder and slot colour | | `--color-input-group-border` | Border colour | | `--color-input-group-border-hover` | Border colour on hover | | `--color-input-group-border-focus` | Border colour on focus | | `--color-input-group-radius` | Corner radius | | `--color-input-group-shadow` | Field shadow | ### Interactive States - **Hover**: `:hover` or `[data-hovered]` on `.color-input-group` - **Focus**: the shell shows the ring while `.color-input-group__input` has `:focus` or `[data-focused]` - **Invalid**: `[data-invalid]` or `[aria-invalid="true"]` on `.color-input-group` - **Disabled**: `[data-disabled]` or `[aria-disabled="true"]` on `.color-input-group` ## API Reference ### ColorInputGroup | Prop | Type | Default | Description | | ----------- | -------------------------------------------------- | ----------- | ----------------------------------------------------- | | `variant` | `"primary" \| "secondary"` | `"primary"` | Visual style of the group | | `fullWidth` | `boolean` | `false` | Makes the group fill its container | | `className` | `string \| ((values: GroupRenderProps) => string)` | - | Additional classes, or a function of the render props | | `...rest` | | | Every React Aria `Group` prop | ### ColorInputGroup.Prefix | Prop | Type | Default | Description | | ----------- | --------------------------------- | ------- | ------------------------------------------------------ | | `render` | `DOMRenderFunction` | - | Replaces the rendered element; `E` defaults to `"div"` | | `className` | `string` | - | Additional classes | | `...rest` | | | Every attribute of the rendered element | ### ColorInputGroup.Input | Prop | Type | Default | Description | | ----------- | -------------------------------------------------- | ------- | ----------------------------------------------------- | | `className` | `string \| ((values: InputRenderProps) => string)` | - | Additional classes, or a function of the render props | | `...rest` | | | Every React Aria `Input` prop | ### ColorInputGroup.Suffix | Prop | Type | Default | Description | | ----------- | --------------------------------- | ------- | ------------------------------------------------------ | | `render` | `DOMRenderFunction` | - | Replaces the rendered element; `E` defaults to `"div"` | | `className` | `string` | - | Additional classes | | `...rest` | | | Every attribute of the rendered element | ### Render Props `className` on `ColorInputGroup` receives these values: | Prop | Type | Description | | --------------- | --------- | --------------------------------- | | `isHovered` | `boolean` | Whether the group is hovered | | `isFocusWithin` | `boolean` | Whether focus is inside the group | | `isDisabled` | `boolean` | Whether the group is disabled | | `isInvalid` | `boolean` | Whether the group is invalid | # ColorPicker > A composable color picker container with popover **Category**: components **URL**: https://peakui.dev/en/docs/react/components/color-picker **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(colors)/color-picker.mdx ## Usage ```tsx import {ColorPicker, ColorSwatch, Label} from "@peakui/react"; ``` ```tsx "use client"; import {ColorPicker, ColorSlider, ColorSwatch, Label} from "@peakui/react"; export function Basic() { return ( ); } ``` ### Anatomy The ColorPicker is a container: it owns the value and the popover, and the editors composed inside it ([ColorArea](https://peakui.dev/docs/react/components/color-area), [ColorSlider](https://peakui.dev/docs/react/components/color-slider), [ColorSwatchPicker](https://peakui.dev/docs/react/components/color-swatch-picker), [ColorField](https://peakui.dev/docs/react/components/color-field)) read and write that value through the picker's state. ```tsx import {ColorPicker, ColorSlider, ColorSwatch, Label} from "@peakui/react"; export default () => ( ); ``` ## Examples ### Controlled ```tsx "use client"; import {Shuffle as ShuffleIcon} from "@gravity-ui/icons"; import { Button, ColorPicker, ColorSlider, ColorSwatch, ColorSwatchPicker, Label, } from "@peakui/react"; import {useState} from "react"; const colorPresets = [ "#ef4444", // red-500 "#f97316", // orange-500 "#eab308", // yellow-500 "#22c55e", // green-500 "#06b6d4", // cyan-500 "#3b82f6", // blue-500 "#8b5cf6", // violet-500 "#ec4899", // pink-500 "#f43f5e", // rose-500 ]; export function Controlled() { const [color, setColor] = useState("#325578"); const shuffleColor = () => { const hue = Math.floor(Math.random() * 360); const saturation = 50 + Math.floor(Math.random() * 50); // 50-100% const lightness = 40 + Math.floor(Math.random() * 30); // 40-70% setColor(`hsl(${hue}, ${saturation}%, ${lightness}%)`); }; return (
setColor(next.toString("hex"))}> {colorPresets.map((preset) => ( ))}

Selected: {color}

); } ``` ### With Swatches ```tsx "use client"; import { ColorArea, ColorField, ColorInputGroup, ColorPicker, ColorSlider, ColorSwatch, ColorSwatchPicker, Label, } from "@peakui/react"; const colorPresets = [ "#ef4444", // red-500 "#f97316", // orange-500 "#eab308", // yellow-500 "#22c55e", // green-500 "#06b6d4", // cyan-500 "#3b82f6", // blue-500 "#8b5cf6", // violet-500 "#ec4899", // pink-500 "#f43f5e", // rose-500 ]; export function WithSwatches() { return ( {colorPresets.map((preset) => ( ))} ); } ``` ## Customization ### Tailwind CSS ```tsx "use client"; import {ColorPicker, ColorSlider, ColorSwatch, Label} from "@peakui/react"; export function CustomStyles() { return ( ); } ``` ### Global CSS ```css @layer components { .color-picker { @apply inline-flex; } .color-picker__trigger { @apply inline-flex items-center gap-4 rounded-lg; } .color-picker__popover { @apply p-4 rounded-xl; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The ColorPicker component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/color-picker.css)): #### Base & Element Classes - `.color-picker` - Base container - `.color-picker__trigger` - Trigger button - `.color-picker__popover` - Popover container ### Slots - `[data-slot="color-picker"]` - `[data-slot="color-picker-trigger"]` - `[data-slot="color-picker-popover"]` ### Interactive States The component supports both CSS pseudo-classes and data attributes: - **Focus**: `:focus-visible` or `[data-focus-visible="true"]` on trigger - **Disabled**: `:disabled`, `[data-disabled="true"]` or `[aria-disabled="true"]` on trigger ## API Reference ### ColorPicker Inherits from [React Aria ColorPicker](https://react-spectrum.adobe.com/react-aria/ColorPicker.html). | Prop | Type | Default | Description | | -------------- | ------------------------ | ------- | --------------------------------------------------------------------------------------------- | | `value` | `string \| Color` | - | The current color value (controlled) | | `defaultValue` | `string \| Color` | - | The default color value (uncontrolled) | | `onChange` | `(color: Color) => void` | - | Handler called when the color changes | | `children` | `ReactNode` | - | Content of the color picker (Trigger, Popover) | | `className` | `string` | - | Additional class name for the wrapper element | | `...rest` | | | Every React Aria `ColorPicker` attribute is accepted, including `isDisabled` and `aria-label` | ### ColorPicker.Trigger | Prop | Type | Default | Description | | ----------- | --------------------------------------------------------- | ------- | -------------------------------------------------- | | `className` | `string` | - | Additional classes | | `children` | `ReactNode \| ((values: ButtonRenderProps) => ReactNode)` | - | Trigger content, or a function of the render props | | `...rest` | | | Every React Aria `Button` attribute is accepted | ### ColorPicker.Popover | Prop | Type | Default | Description | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------- | ------------------------------------------------ | | `placement` | `"bottom" \| "bottom left" \| "bottom right" \| "bottom start" \| "bottom end" \| "top" \| "top left" \| "top right" \| "top start" \| "top end" \| "left" \| "left top" \| "left bottom" \| "start" \| "start top" \| "start bottom" \| "right" \| "right top" \| "right bottom" \| "end" \| "end top" \| "end bottom"` | `"bottom left"` | Placement of the popover relative to the trigger | | `className` | `string` | - | Additional classes | | `children` | `ReactNode` | - | Popover content | | `...rest` | | | Every React Aria `Popover` attribute is accepted | ### Related Types #### Color Represents a color value. See [React Aria Color](https://react-spectrum.adobe.com/react-aria/ColorPicker.html#color) for the full API. | Method | Description | | ---------------------------------- | ---------------------------------------------------------------------------- | | `toString(format)` | Converts the color to a string in the given format (hex, rgb, hsl, hsb, css) | | `toFormat(format)` | Converts the color to the given format and returns a new Color | | `getChannelValue(channel)` | Returns the numeric value for a given channel | | `withChannelValue(channel, value)` | Sets the numeric value for a channel and returns a new Color | #### parseColor ```tsx import {parseColor} from "react-aria-components"; // Parse from string const color = parseColor("#ff0000"); const hslColor = parseColor("hsl(0, 100%, 50%)"); ```
# ColorSlider > Slider for one color channel **Category**: components **URL**: https://peakui.dev/en/docs/react/components/color-slider **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(colors)/color-slider.mdx ## Usage ```tsx import {ColorSlider, Label} from "@peakui/react"; ``` ```tsx import {ColorSlider, Label} from "@peakui/react"; export function Basic() { return (
); } ``` ### Anatomy ```tsx import {ColorSlider, Label} from "@peakui/react"; export default () => ( ); ``` ## Examples ### Alpha ```tsx import {ColorSlider, Label} from "@peakui/react"; export function Alpha() { return (
); } ``` ### RGB ```tsx import {ColorSlider, Label} from "@peakui/react"; export function Rgb() { return (
); } ``` ### Vertical ```tsx import {ColorSlider, Label} from "@peakui/react"; export function Vertical() { return (
); } ``` ### Without Label ```tsx import {ColorSlider} from "@peakui/react"; export function WithoutLabel() { return (
); } ``` ## Customization ### Tailwind CSS ```tsx ``` ### Global CSS ```css @layer components { .color-slider__track { @apply h-6; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The ColorSlider component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/color-slider.css)): #### Base Classes - `.color-slider` - Grid of label, output and track - `.color-slider__track` - Gradient track with edge caps - `.color-slider__thumb` - Draggable thumb with a white border - `.color-slider__output` - Formatted channel value ### Slots - `[data-slot="color-slider"]` - `[data-slot="color-slider-track"]` - `[data-slot="color-slider-thumb"]` - `[data-slot="color-slider-output"]` ### CSS Variables | Variable | Purpose | | ----------------------------- | --------------------------------------------------------- | | `--track-start-color` | Colour at the channel minimum, set by `ColorSlider.Track` | | `--track-end-color` | Colour at the channel maximum, set by `ColorSlider.Track` | | `--color-slider-checker` | Transparency checkerboard under the gradient | | `--color-slider-ring` | The inset ring on the track and its caps | | `--color-slider-thumb-border` | The thumb border colour | ### Interactive States - **Focus**: `[data-focus-visible="true"]` on `.color-slider__thumb` - **Dragging**: `[data-dragging="true"]` on `.color-slider__thumb` - **Orientation**: `[data-orientation="horizontal"]` or `[data-orientation="vertical"]` on `.color-slider` - **Disabled**: `[data-disabled="true"]` on `.color-slider` and `.color-slider__thumb` ## API Reference ### ColorSlider | Prop | Type | Default | Description | | -------------- | ----------------------------------------------------------------------------------------------- | -------------- | ------------------------------------------------------------------------------------------- | | `channel` | `"hue" \| "saturation" \| "lightness" \| "brightness" \| "red" \| "green" \| "blue" \| "alpha"` | - | The channel the slider edits; an invalid pair with `colorSpace` is corrected in development | | `colorSpace` | `"rgb" \| "hsl" \| "hsb"` | - | The colour space of the channel | | `orientation` | `"horizontal" \| "vertical"` | `"horizontal"` | The slider axis | | `value` | `string \| Color` | - | The current colour (controlled) | | `defaultValue` | `string \| Color` | - | The initial colour (uncontrolled) | | `onChange` | `(value: Color) => void` | - | Called as the thumb moves | | `onChangeEnd` | `(value: Color) => void` | - | Called when a drag or key press ends | | `isDisabled` | `boolean` | `false` | Disables the slider | | `className` | `string \| ((values: ColorSliderRenderProps) => string)` | - | Additional classes, or a function of the render props | | `...rest` | | | Every React Aria `ColorSlider` prop, including `aria-label` | ### ColorSlider.Output | Prop | Type | Default | Description | | ----------- | --------------------------------------------------------- | --------------------------- | ----------------------------------------------------- | | `children` | `ReactNode \| ((values: SliderRenderProps) => ReactNode)` | The formatted channel value | Replaces the value, for example `210°` | | `className` | `string \| ((values: SliderRenderProps) => string)` | - | Additional classes, or a function of the render props | | `...rest` | | | Every React Aria `SliderOutput` prop | ### ColorSlider.Track | Prop | Type | Default | Description | | ----------- | ---------------------------------------------------------------------- | ------- | ----------------------------------------------------- | | `className` | `string \| ((values: SliderTrackRenderProps) => string)` | - | Additional classes, or a function of the render props | | `style` | `CSSProperties \| ((values: SliderTrackRenderProps) => CSSProperties)` | - | Inline styles, merged over the gradient | | `...rest` | | | Every React Aria `SliderTrack` prop | ### ColorSlider.Thumb | Prop | Type | Default | Description | | ----------- | ------------------------------------------------------- | ------- | ----------------------------------------------------- | | `className` | `string \| ((values: ColorThumbRenderProps) => string)` | - | Additional classes, or a function of the render props | | `...rest` | | | Every React Aria `ColorThumb` prop | ### Render Props `children` and `className` functions on `ColorSlider` receive these values: | Prop | Type | Description | | ------------- | ------------------ | ---------------------------------- | | `orientation` | `Orientation` | The slider axis | | `isDisabled` | `boolean` | Whether the slider is disabled | | `state` | `ColorSliderState` | The state of the underlying slider |
# ColorSwatchPicker > A list of color swatches to choose from **Category**: components **URL**: https://peakui.dev/en/docs/react/components/color-swatch-picker **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(colors)/color-swatch-picker.mdx ## Usage ```tsx import {ColorSwatchPicker} from "@peakui/react"; ``` ```tsx import {ColorSwatchPicker} from "@peakui/react"; const COLORS = ["#EF4444", "#F59E0B", "#10B981", "#0485F7", "#D946EF"]; export function Basic() { return ( {COLORS.map((color) => ( ))} ); } ``` ### Anatomy ```tsx import {ColorSwatchPicker} from "@peakui/react"; export default () => ( ); ``` ## Examples ### Sizes ```tsx import {ColorSwatchPicker} from "@peakui/react"; const COLORS = ["#EF4444", "#10B981", "#0485F7"]; export function Sizes() { return (
{(["xs", "sm", "md", "lg", "xl"] as const).map((size) => ( {COLORS.map((color) => ( ))} ))}
); } ``` ### Shapes ```tsx import {ColorSwatchPicker} from "@peakui/react"; const COLORS = ["#EF4444", "#10B981", "#0485F7"]; export function Shapes() { return (
{(["circle", "square"] as const).map((variant) => ( {COLORS.map((color) => ( ))} ))}
); } ``` ### Stack ```tsx import {ColorSwatchPicker} from "@peakui/react"; const COLORS = ["#EF4444", "#10B981", "#0485F7"]; export function Stack() { return ( {COLORS.map((color) => ( ))} ); } ``` ### Disabled ```tsx import {ColorSwatchPicker} from "@peakui/react"; const COLORS = ["#EF4444", "#10B981", "#0485F7"]; export function Disabled() { return ( {COLORS.map((color) => ( ))} ); } ``` ## Customization ### Tailwind CSS ```tsx ``` ### Global CSS ```css @layer components { .color-swatch-picker { @apply gap-3; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The ColorSwatchPicker component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/color-swatch-picker.css)): #### Base Classes - `.color-swatch-picker` - Wrapping row of swatches - `.color-swatch-picker__item` - One selectable swatch - `.color-swatch-picker__swatch` - The coloured fill - `.color-swatch-picker__indicator` - Check shown when selected #### Layout Classes - `.color-swatch-picker--grid` - Wrapping row (default) - `.color-swatch-picker--stack` - Single column #### Size Classes - `.color-swatch-picker--xs` - Extra small (16px) - `.color-swatch-picker--sm` - Small (24px) - `.color-swatch-picker--md` - Medium (32px, default) - `.color-swatch-picker--lg` - Large (36px) - `.color-swatch-picker--xl` - Extra large (40px) #### Shape Classes - `.color-swatch-picker--circle` - Circular items (default) - `.color-swatch-picker--square` - Rounded square items ### Slots - `[data-slot="color-swatch-picker"]` - `[data-slot="color-swatch-picker-item"]` - `[data-slot="color-swatch-picker-swatch"]` - `[data-slot="color-swatch-picker-indicator"]` - `[data-slot="color-swatch-picker-checkmark"]` ### CSS Variables | Variable | Purpose | | ------------------------ | --------------------------------------------------------------------------- | | `--color-swatch-current` | The item colour, set by `ColorSwatchPicker.Item`; colours the selected ring | ### Interactive States - **Focus**: `:focus-visible` or `[data-focus-visible="true"]` on `.color-swatch-picker__item` - **Selected**: `[data-selected="true"]` on `.color-swatch-picker__item` shows the ring and the check - **Hover**: `:hover` on `.color-swatch-picker__swatch` enlarges the swatch - **Disabled**: `[data-disabled="true"]` on `.color-swatch-picker__item` ## API Reference ### ColorSwatchPicker | Prop | Type | Default | Description | | -------------- | -------------------------------------------------------------- | ---------- | ----------------------------------------------------------------- | | `size` | `"xs" \| "sm" \| "md" \| "lg" \| "xl"` | `"md"` | Size of the items | | `variant` | `"circle" \| "square"` | `"circle"` | Shape of the items | | `layout` | `"grid" \| "stack"` | `"grid"` | Row that wraps, or a single column | | `value` | `string \| Color` | - | The selected colour (controlled) | | `defaultValue` | `string \| Color` | - | The initially selected colour (uncontrolled) | | `onChange` | `(value: Color) => void` | - | Called when the selection changes | | `className` | `string \| ((values: ColorSwatchPickerRenderProps) => string)` | - | Additional classes, or a function of the render props | | `...rest` | | | Every React Aria `ColorSwatchPicker` prop, including `aria-label` | ### ColorSwatchPicker.Item | Prop | Type | Default | Description | | ------------ | -------------------------------------------------------------------------------- | ------- | ----------------------------------------------------- | | `color` | `string \| Color` | - | The colour of the item | | `isDisabled` | `boolean` | `false` | Disables the item | | `className` | `string \| ((values: ColorSwatchPickerItemRenderProps) => string)` | - | Additional classes, or a function of the render props | | `style` | `CSSProperties \| ((values: ColorSwatchPickerItemRenderProps) => CSSProperties)` | - | Inline styles, merged over the item colour | | `...rest` | | | Every React Aria `ColorSwatchPickerItem` prop | ### ColorSwatchPicker.Swatch | Prop | Type | Default | Description | | ----------- | -------------------------------------------------------- | ------- | ----------------------------------------------------- | | `className` | `string \| ((values: ColorSwatchRenderProps) => string)` | - | Additional classes, or a function of the render props | | `...rest` | | | Every React Aria `ColorSwatch` prop | ### ColorSwatchPicker.Indicator | Prop | Type | Default | Description | | ----------- | ------------------------------------------------------------------------ | ------------ | -------------------------------------------------------------- | | `children` | `ReactNode \| ((values: ColorSwatchPickerItemRenderProps) => ReactNode)` | A check mark | Replaces the check; black on light colours, white on dark ones | | `render` | `DOMRenderFunction` | - | Replaces the rendered element; `E` defaults to `"span"` | | `className` | `string` | - | Additional classes | | `...rest` | | | Every attribute of the rendered element | ### Render Props `children`, `className` and `style` functions on `ColorSwatchPicker.Item` receive these values: | Prop | Type | Description | | ---------------- | --------- | ----------------------------------- | | `color` | `Color` | The colour of the item | | `isSelected` | `boolean` | Whether the item is selected | | `isDisabled` | `boolean` | Whether the item is disabled | | `isFocusVisible` | `boolean` | Whether the item has keyboard focus |
# ColorSwatch > A visual preview of a color value **Category**: components **URL**: https://peakui.dev/en/docs/react/components/color-swatch **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(colors)/color-swatch.mdx ## Usage ```tsx import {ColorSwatch} from "@peakui/react"; ``` ```tsx import {ColorSwatch} from "@peakui/react"; export function Basic() { return (
); } ``` ## Examples ### Sizes ```tsx import {ColorSwatch} from "@peakui/react"; export function Sizes() { return (
); } ``` ### Shapes ```tsx import {ColorSwatch} from "@peakui/react"; export function Shapes() { return (
); } ``` ### Transparency ```tsx import {ColorSwatch} from "@peakui/react"; export function Transparency() { return (
); } ``` ### Render Function `render` replaces the rendered element; the swatch's props and custom property flow into it. ```tsx "use client"; import {ColorSwatch} from "@peakui/react"; export function RenderFunction() { return (
} />
} />
} />
); } ``` ### Accessibility Use `colorName` to provide a custom accessible name for the color, and `aria-label` to add context about how the color is used. ```tsx import {ColorSwatch} from "@peakui/react"; export function Accessibility() { return (
); } ``` ## Customization ### Tailwind CSS ```tsx "use client"; import {ColorSwatch} from "@peakui/react"; export function CustomStyles() { const colors = ["#0485F7", "#EF4444", "#F59E0B"]; return (
{/* Glow effect */}
Glow Effect
{colors.map((color) => ( ({ boxShadow: `0 0 20px 2px ${color}`, })} /> ))}
{/* Gradient swatch */}
Gradient
{colors.map((color) => ( ({ background: `linear-gradient(135deg, ${c.toString("css")}, white)`, })} /> ))}
); } ``` ### Global CSS ```css @layer components { .color-swatch { @apply border-2 border-white; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The ColorSwatch component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/color-swatch.css)): #### Base Classes - `.color-swatch` - Base swatch styles with checkered background for transparency #### Shape Classes - `.color-swatch--circle` - Circular shape (default) - `.color-swatch--square` - Square shape with rounded corners #### Size Classes - `.color-swatch--xs` - Extra small (16px) - `.color-swatch--sm` - Small (24px) - `.color-swatch--md` - Medium (32px, default) - `.color-swatch--lg` - Large (36px) - `.color-swatch--xl` - Extra large (40px) ### Slots - `[data-slot="color-swatch"]` ### CSS Variables | Variable | Purpose | | ------------------------ | --------------------------------------------- | | `--color-swatch-current` | The swatch's color, set from the `color` prop | ## API Reference ### ColorSwatch | Prop | Type | Default | Description | | ------------ | ------------------------------------------------------------------------------ | ---------- | ---------------------------------------------------------------------------- | | `color` | `string \| Color` | - | The color value to display (hex, rgb, hsl, etc.) | | `colorName` | `string` | - | Accessible name for the color (overrides auto-generated description) | | `shape` | `"circle" \| "square"` | `"circle"` | Shape of the swatch | | `size` | `"xs" \| "sm" \| "md" \| "lg" \| "xl"` | `"md"` | Size of the swatch | | `className` | `string \| ((values: ColorSwatchRenderProps) => string)` | - | Additional classes, or a function of the render props | | `style` | `CSSProperties \| ((values: ColorSwatchRenderProps) => CSSProperties)` | - | Inline styles, or a function of the render props | | `render` | `DOMRenderFunction` | - | Replaces the rendered element with a custom render function | | `aria-label` | `string` | - | Context about how the color is used; appended to the color's own description | | `...rest` | | | Every `
` attribute is accepted, including `aria-labelledby` and `id` | ### Render Props `className` and `style` functions receive these values: | Prop | Type | Description | | ------- | ------- | ------------------------------------------- | | `color` | `Color` | The parsed color value, from the color prop | The `color` object provides methods like `color.toString("css")`, `color.toString("hex")` and `color.getChannelValue("alpha")`. # Slider > Selects one or more values within a range **Category**: components **URL**: https://peakui.dev/en/docs/react/components/slider **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(controls)/slider.mdx ## Usage ```tsx import {Slider} from "@peakui/react"; ``` ```tsx import {Label, Slider} from "@peakui/react"; export function Basic() { return ( ); } ``` ### Anatomy ```tsx ``` ## Examples ### Disabled ```tsx import {Label, Slider} from "@peakui/react"; export function Disabled() { return ( ); } ``` ### Range Pass an array to `defaultValue` and render one `Slider.Thumb` per value through the track's render function. ```tsx "use client"; import {Label, Slider} from "@peakui/react"; export function Range() { return ( {({state}) => ( <> {state.values.map((_, i) => ( ))} )} ); } ``` ### Vertical ```tsx import {Label, Slider} from "@peakui/react"; export function Vertical() { return (
); } ``` ### Controlled Control the value with `value` and `onChange`. ```tsx "use client"; import {Label, Slider} from "@peakui/react"; import {useState} from "react"; export function Controlled() { const [value, setValue] = useState(25); return (
{ if (typeof nextValue === "number") { setValue(nextValue); } }} >

Current value: {value}

); } ``` ### Custom Value Formatting Use `formatOptions` to format the displayed value. ```tsx import {Label, Slider} from "@peakui/react"; export function CustomValueFormatting() { return ( ); } ``` ### Custom Output Customize `Slider.Output` to control how the selected values are shown. ```tsx "use client"; import {Label, Slider} from "@peakui/react"; export function CustomOutput() { return ( {({state}) => state.values.map((_, i) => state.getThumbValueLabel(i)).join(" – ")} {({state}) => ( <> {state.values.map((_, i) => ( ))} )} ); } ``` ### Render Function ```tsx "use client"; import {Label, Slider} from "@peakui/react"; export function RenderFunction() { return (
} > ); } ``` ## Customization ### Tailwind CSS ```tsx import {Label, Slider} from "@peakui/react"; export function CustomStyles() { return ( ); } ``` ### Global CSS ```css .slider { @apply grid w-full gap-1; } .slider__output { @apply text-muted text-sm; } ``` ## Styling Reference ### CSS Classes | Class | Description | | :---------------- | :------------------------------------------------- | | `.slider` | The slider container element | | `.slider__output` | The output element displaying the current value(s) | | `.slider__track` | The track element containing the fill and thumbs | | `.slider__fill` | The fill element showing the selected range | | `.slider__thumb` | The thumb element | | `.slider__marks` | The marks element | ### Slots | Slot | Description | | :---------------------------- | :------------------------------------------------- | | `[data-slot="slider"]` | The slider container element | | `[data-slot="slider-output"]` | The output element displaying the current value(s) | | `[data-slot="slider-track"]` | The track element containing the fill and thumbs | | `[data-slot="slider-fill"]` | The fill element showing the selected range | | `[data-slot="slider-thumb"]` | The thumb element | | `[data-slot="slider-marks"]` | The marks element | ### Interactive States The component supports both CSS pseudo-classes and data attributes: | State | Attribute | | :--------------------------- | :------------------------------------------------------------ | | Disabled | `[data-disabled="true"]` / `:disabled` on the slider or thumb | | Dragging | `[data-dragging="true"]` on the thumb | | Keyboard focused | `[data-focus-visible="true"]` / `:focus-visible` on the thumb | | Vertical | `[data-orientation="vertical"]` on the slider | | Fill starts at the beginning | `[data-fill-start="true"]` on the track | | Fill ends at the end | `[data-fill-end="true"]` on the track | ## API Reference ### Slider.Root | Prop | Type | Default | Description | | :-------------- | :-------------------------------------------- | :------------- | :---------------------------------------------- | | `value` | `number \| number[]` | - | Controlled value | | `defaultValue` | `number \| number[]` | - | Uncontrolled initial value | | `onChange` | `(value: number \| number[]) => void` | - | Called when the value changes | | `onChangeEnd` | `(value: number \| number[]) => void` | - | Called when dragging ends | | `minValue` | `number` | `0` | Lower bound | | `maxValue` | `number` | `100` | Upper bound | | `step` | `number` | `1` | Step size | | `formatOptions` | `Intl.NumberFormatOptions` | - | Locale-aware formatting of the value label | | `orientation` | `"horizontal" \| "vertical"` | `"horizontal"` | Orientation of the slider | | `isDisabled` | `boolean` | - | Disables the slider | | `render` | `DOMRenderFunction<'div', SliderRenderProps>` | - | Replaces the rendered element | | `...rest` | | | Every React Aria `Slider` attribute is accepted | Each thumb renders a visually hidden native `` carrying the `slider` role, its value and its keyboard interaction. ### Slider.Output | Prop | Type | Default | Description | | :--------- | :-------------------------------------------------- | :----------- | :---------------------------------------------------- | | `children` | `ReactNode \| RenderFunction` | value labels | Overrides the joined value labels | | `render` | `DOMRenderFunction<'div', SliderOutputRenderProps>` | - | Replaces the rendered element | | `...rest` | | | Every React Aria `SliderOutput` attribute is accepted | ### Slider.Track | Prop | Type | Default | Description | | :-------- | :------------------------------------------------- | :------ | :--------------------------------------------------- | | `render` | `DOMRenderFunction<'div', SliderTrackRenderProps>` | - | Replaces the rendered element | | `...rest` | | | Every React Aria `SliderTrack` attribute is accepted | ### Slider.Fill | Prop | Type | Default | Description | | :-------- | :-------------------------------- | :------ | :----------------------------------------------------- | | `style` | `CSSProperties` | - | Merged under the computed fill geometry | | `render` | `DOMRenderFunction` | - | Replaces the rendered element; `E` defaults to `'div'` | | `...rest` | | | Every `
` attribute is accepted | ### Slider.Thumb | Prop | Type | Default | Description | | :----------- | :------------------------------------------------- | :------ | :---------------------------------------------------------- | | `index` | `number` | `0` | Index of the thumb within the slider | | `isDisabled` | `boolean` | - | Disables this thumb | | `name` | `string` | - | Name of the hidden input, used when submitting an HTML form | | `render` | `DOMRenderFunction<'div', SliderThumbRenderProps>` | - | Replaces the rendered element | | `...rest` | | | Every React Aria `SliderThumb` attribute is accepted | ### Slider.Marks | Prop | Type | Default | Description | | :-------- | :-------------------------------- | :------ | :----------------------------------------------------- | | `render` | `DOMRenderFunction` | - | Replaces the rendered element; `E` defaults to `'div'` | | `...rest` | | | Every `
` attribute is accepted | Planned: `Slider.Marks` is a placeholder that renders an empty element — marks support is not implemented yet. ### Render Props `children` and `className` of `Slider.Root`, `Slider.Output`, `Slider.Track` and `Slider.Thumb` accept a function receiving the respective React Aria render props, including `state` with `values` and `getThumbValueLabel`. # Badge > A small indicator anchored over another element, such as a count or a status dot **Category**: components **URL**: https://peakui.dev/en/docs/react/components/badge **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(data-display)/badge.mdx ## Usage ```tsx import {Badge} from "@peakui/react"; ``` ```tsx import {Avatar, Badge} from "@peakui/react"; // A portrait drawn as an SVG data URI; use your own image URL. const photo = (hue: number) => `data:image/svg+xml,${encodeURIComponent( ``, )}`; const PEOPLE = [ {color: "danger", count: "5", hue: 140, name: "John Doe"}, {color: "accent", count: "New", hue: 280, name: "Kate Wilson"}, {color: "success", count: "3", hue: 30, name: "Emily Chen"}, ] as const; export function Basic() { return (
{PEOPLE.map(({color, count, hue, name}) => ( {name.replace(/[^A-Z]/g, "")} {count} ))}
); } ``` ### Anatomy ```tsx import {Badge} from "@peakui/react"; export default () => ( {/* the element the badge sits over */} 5 ); ``` A string or a number passed as `children` is wrapped in `Badge.Label` for you. ### Badge or Chip `Badge` is positioned over a sibling inside `Badge.Anchor`: an avatar with a count, an icon with a dot. `Chip` is an inline label that takes its own place in the flow. ### Accessibility A badge has no role and is not announced when it changes, so its meaning belongs in the accessible name of the element it sits over, as in `aria-label="Inbox, 5 unread"`. The badge renders a plain ``, so `aria-label` on the badge itself is prohibited and assistive technology ignores it; an icon inside a badge carries its own name through `role="img"`. ## Examples ### Placements The names are physical: `top-right` is the top right corner in every writing direction. ```tsx import {Avatar, Badge} from "@peakui/react"; const PLACEMENTS = ["top-right", "top-left", "bottom-right", "bottom-left"] as const; export function Placements() { return (
{PLACEMENTS.map((placement) => (
JD 1 {placement}
))}
); } ``` ### Colors ```tsx import {Avatar, Badge} from "@peakui/react"; const COLORS = ["default", "accent", "success", "warning", "danger"] as const; export function Colors() { return (
{COLORS.map((color) => ( JD 3 ))}
); } ``` ### Variants ```tsx import {Avatar, Badge} from "@peakui/react"; const COLORS = ["default", "accent", "success", "warning", "danger"] as const; const VARIANTS = ["primary", "secondary", "soft"] as const; export function Variants() { return (
{VARIANTS.map((variant) => (
{variant} {COLORS.map((color) => ( JD 3 ))}
))}
); } ``` ### Sizes ```tsx import {Avatar, Badge} from "@peakui/react"; const SIZES = ["sm", "md", "lg"] as const; export function Sizes() { return (
{SIZES.map((size) => (
JD 99+ {size}
))}
); } ``` ### Dot A badge without children is a dot. ```tsx import {Avatar, Badge} from "@peakui/react"; const COLORS = ["accent", "success", "warning", "danger"] as const; export function Dot() { return (
{COLORS.map((color) => ( JD ))}
); } ``` ### With Content Text wider than the badge's height renders as a rounded rectangle; a single character stays a circle. ```tsx import {Bell} from "@gravity-ui/icons"; import {Avatar, Badge} from "@peakui/react"; const COUNTS = ["5", "99+", "New"] as const; export function WithContent() { return (
{COUNTS.map((count) => ( JD {count} ))} JD {/* An icon carries no name of its own, and a roleless span cannot take aria-label. */}
); } ``` ### On a Button ```tsx import {Badge, Button} from "@peakui/react"; export function OnButton() { return ( 5 ); } ``` ## Customization ### Tailwind CSS ```tsx import {Avatar, Badge} from "@peakui/react"; export function CustomStyles() { return ( JD {/* tabular-nums keeps the width steady as the count changes. */} 12 ); } ``` ### Global CSS ```css @layer components { .badge { --badge-border: var(--color-surface); } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The Badge component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/badge.css)): #### Base & Element Classes - `.badge-anchor` - The wrapper the badge is positioned against - `.badge` - The indicator - `.badge__label` - The text inside it #### Size Classes - `.badge--sm`, `.badge--md` (default), `.badge--lg` #### Color Classes - `.badge--default`, `.badge--accent`, `.badge--success`, `.badge--warning`, `.badge--danger` #### Variant Classes - `.badge--primary` (default), `.badge--secondary`, `.badge--soft` #### Placement Classes - `.badge--top-right` (default), `.badge--top-left`, `.badge--bottom-right`, `.badge--bottom-left` ### Slots - `[data-slot="badge-anchor"]` - `[data-slot="badge"]` - `[data-slot="badge-label"]` ### CSS Variables | Variable | Purpose | | ---------------- | ------------------------------------------------------------------------------------- | | `--badge-bg` | Fill, set by the variant and color classes | | `--badge-fg` | Text color | | `--badge-border` | The ring that separates the badge from what it covers; the page background by default | ## API Reference ### Badge | Prop | Type | Default | Description | | ----------- | -------------------------------------------------------------- | ------------- | ----------------------------------------------------------------- | | `color` | `'default' \| 'accent' \| 'success' \| 'warning' \| 'danger'` | `'default'` | Color role | | `variant` | `'primary' \| 'secondary' \| 'soft'` | `'primary'` | Fill style | | `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | Size | | `placement` | `'top-right' \| 'top-left' \| 'bottom-right' \| 'bottom-left'` | `'top-right'` | Corner of the anchor | | `children` | `ReactNode` | - | A string or number is wrapped in `Badge.Label`; omit it for a dot | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction` | - | Replaces the rendered element; `E` defaults to `'span'` | | `...rest` | | | Every `` attribute is accepted | ### Badge.Anchor | Prop | Type | Default | Description | | ----------- | --------------------------------- | ------- | ------------------------------------------------------- | | `children` | `ReactNode` | - | The element the badge sits over, and the badge | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction` | - | Replaces the rendered element; `E` defaults to `'span'` | | `...rest` | | | Every `` attribute is accepted | ### Badge.Label | Prop | Type | Default | Description | | ----------- | --------------------------------- | ------- | ------------------------------------------------------- | | `children` | `ReactNode` | - | The text | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction` | - | Replaces the rendered element; `E` defaults to `'span'` | | `...rest` | | | Every `` attribute is accepted |
# Chip > A compact label for statuses, filters and attributes **Category**: components **URL**: https://peakui.dev/en/docs/react/components/chip **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(data-display)/chip.mdx ## Usage ```tsx import {Chip} from "@peakui/react"; ``` ```tsx import {Chip} from "@peakui/react"; export function Basic() { return Label; } ``` ## Examples ### Sizes ```tsx import {Chip} from "@peakui/react"; export function Sizes() { return (
Small Medium Large
); } ``` ### Colors ```tsx import {Chip} from "@peakui/react"; export function Colors() { return (
Default Accent Success Warning Danger
); } ``` ### Variants ```tsx import {Chip} from "@peakui/react"; export function Variants() { return (
Primary Secondary Tertiary Soft
); } ``` ### With Icons Icons are plain children of the root; the label stays in `Chip.Label`. ```tsx import {CircleDashed} from "@gravity-ui/icons"; import {Chip} from "@peakui/react"; export function WithIcons() { return ( Label ); } ``` ### Statuses A small glyph before the label turns a chip into a status. ```tsx import {CircleFill} from "@gravity-ui/icons"; import {Chip} from "@peakui/react"; const STATUSES = [ {children: "Information", color: "accent"}, {children: "Completed", color: "success"}, {children: "Pending", color: "warning"}, {children: "Failed", color: "danger"}, ] as const; export function Statuses() { return (
{STATUSES.map(({children, color}) => ( {children} ))}
); } ``` ## Customization ### Tailwind CSS ```tsx Label ``` ### Global CSS ```css @layer components { .chip { --chip-bg: var(--color-accent-soft); --chip-fg: var(--color-accent-soft-foreground); } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The Chip component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/chip.css)): #### Base & Size Classes - `.chip` - Base chip styles; carries the `md` size - `.chip--sm` - Small size - `.chip--md` - Medium size; empty, the base class carries it - `.chip--lg` - Large size #### Variant Classes - `.chip--primary` - Solid background, set per color by a compound class - `.chip--secondary` - Neutral background; no additional styles - `.chip--tertiary` - Transparent background - `.chip--soft` - Muted background, set per color by a compound class #### Color Classes - `.chip--accent` - `.chip--default` - `.chip--success` - `.chip--warning` - `.chip--danger` #### Element Classes - `.chip__label` - The label; adds horizontal padding ### Slots - `[data-slot="chip"]` - The root element - `[data-slot="chip-label"]` - The label element ### CSS Variables | Variable | Purpose | | ----------- | --------------------- | | `--chip-bg` | Chip background color | | `--chip-fg` | Chip text color | ## API Reference ### Chip | Prop | Type | Default | Description | | ----------- | ------------------------------------------------------------- | ------------- | ------------------------------------------------------------- | | `children` | `ReactNode` | - | Chip content; strings and numbers become the label (required) | | `color` | `'accent' \| 'danger' \| 'default' \| 'success' \| 'warning'` | `'default'` | Chip color | | `size` | `'sm' \| 'md' \| 'lg'` | `-` | Chip size; the base class already carries `md` | | `variant` | `'primary' \| 'secondary' \| 'soft' \| 'tertiary'` | `'secondary'` | Chip variant | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'span', undefined>` | - | Replaces the rendered `` with your own element | Every other attribute of a `` is accepted. ### Chip.Label | Prop | Type | Default | Description | | ----------- | -------------------------------------- | ------- | ---------------------------------------------------- | | `children` | `ReactNode` | - | Label content | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'span', undefined>` | - | Replaces the rendered `` with your own element | Every other attribute of a `` is accepted.
# DateField > Segmented field for typing a date **Category**: components **URL**: https://peakui.dev/en/docs/react/components/date-field **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(date-and-time)/date-field.mdx ## Usage ```tsx import {DateField, Label} from "@peakui/react"; ``` ```tsx "use client"; import {DateField, Label} from "@peakui/react"; export function Basic() { return ( {(segment) => } ); } ``` ### Anatomy ```tsx import {DateField, Description, FieldError, Label} from "@peakui/react"; export default () => ( ); ``` ## Examples ### Variants ```tsx "use client"; import {DateField, Label} from "@peakui/react"; export function Variants() { return (
{(segment) => } {(segment) => }
); } ``` ### With Prefix and Suffix ```tsx "use client"; import {Calendar, ChevronDown} from "@gravity-ui/icons"; import {DateField, Label} from "@peakui/react"; export function WithPrefixAndSuffix() { return ( {(segment) => } ); } ``` ### With Description ```tsx "use client"; import {DateField, Description, Label} from "@peakui/react"; export function WithDescription() { return ( {(segment) => } Enter your date of birth ); } ``` ### Required ```tsx "use client"; import {DateField, Label} from "@peakui/react"; export function Required() { return ( {(segment) => } ); } ``` ### Disabled ```tsx "use client"; import {parseDate} from "@internationalized/date"; import {DateField, Description, Label} from "@peakui/react"; export function Disabled() { return ( {(segment) => } This date field is disabled ); } ``` ### Full Width ```tsx "use client"; import {DateField, Label} from "@peakui/react"; export function FullWidth() { return (
{(segment) => }
); } ``` ### Invalid ```tsx "use client"; import {DateField, FieldError, Label} from "@peakui/react"; export function Invalid() { return ( {(segment) => } Date must be in the future ); } ``` ### Granularity ```tsx "use client"; import {parseZonedDateTime} from "@internationalized/date"; import {DateField, Label} from "@peakui/react"; export function Granularity() { return ( {(segment) => } ); } ``` ### Controlled ```tsx "use client"; import type {DateValue} from "@internationalized/date"; import {getLocalTimeZone, today} from "@internationalized/date"; import {Button, DateField, Description, Label} from "@peakui/react"; import {useState} from "react"; export function Controlled() { const [value, setValue] = useState(null); return (
{(segment) => } Current value: {value ? value.toString() : "(empty)"}
); } ``` ### With Validation ```tsx "use client"; import type {DateValue} from "@internationalized/date"; import {getLocalTimeZone, today} from "@internationalized/date"; import {DateField, Description, FieldError, Label} from "@peakui/react"; import {useState} from "react"; export function WithValidation() { const [value, setValue] = useState(null); const minValue = today(getLocalTimeZone()); const isInvalid = value !== null && value.compare(minValue) < 0; return ( {(segment) => } {isInvalid ? ( Date must be today or in the future ) : ( Enter a date from today onwards )} ); } ``` ## Customization ### Tailwind CSS ```tsx {(segment) => } ``` ### Global CSS ```css @layer components { .date-input-group { --date-input-group-radius: var(--radius-lg); } .date-input-group__segment { @apply font-mono; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The DateField component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/date-field.css) and [group styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/date-input-group.css)): #### Field Classes - `.date-field` - Column of label, group and messages - `.date-field--full-width` - Fills the container width #### Group Classes - `.date-input-group` - Shell with fill, border and focus ring - `.date-input-group__input` - Borderless, transparent segmented input - `.date-input-group__input-container` - Horizontal scroll area around the input - `.date-input-group__segment` - One editable part of the date - `.date-input-group__prefix` - Slot before the input - `.date-input-group__suffix` - Slot after the input #### Variant Classes - `.date-input-group--primary` - Field fill with shadow (default) - `.date-input-group--secondary` - Neutral fill without shadow #### Modifier Classes - `.date-input-group--full-width` - Fills the container width ### Slots - `[data-slot="date-field"]` - `[data-slot="date-input-group"]` - `[data-slot="date-input-group-input"]` - `[data-slot="date-input-group-input-container"]` - `[data-slot="date-input-group-segment"]` - `[data-slot="date-input-group-prefix"]` - `[data-slot="date-input-group-suffix"]` ### CSS Variables | Variable | Purpose | | --------------------------------- | --------------------------- | | `--date-input-group-bg` | Fill | | `--date-input-group-bg-hover` | Fill on hover | | `--date-input-group-bg-focus` | Fill on focus | | `--date-input-group-fg` | Text colour | | `--date-input-group-placeholder` | Placeholder and slot colour | | `--date-input-group-border` | Border colour | | `--date-input-group-border-hover` | Border colour on hover | | `--date-input-group-border-focus` | Border colour on focus | | `--date-input-group-radius` | Corner radius | | `--date-input-group-shadow` | Field shadow | ### Interactive States - **Hover**: `:hover` or `[data-hovered]` on `.date-input-group` - **Focus**: `:focus-within` or `[data-focus-within]` on `.date-input-group`; `:focus` or `[data-focused]` on `.date-input-group__segment` - **Placeholder**: `[data-placeholder]` on `.date-input-group__segment` - **Invalid**: `[data-invalid]` or `[aria-invalid="true"]` on `.date-input-group`, `[data-invalid]` on the segment, and the field hides its description - **Disabled**: `[data-disabled]` or `[aria-disabled="true"]` on `.date-input-group` ## API Reference ### DateField | Prop | Type | Default | Description | | ------------------------- | ------------------------------------------------------ | ------- | ------------------------------------------------------------ | | `fullWidth` | `boolean` | `false` | Makes the field fill its container | | `value` | `DateValue \| null` | - | The current date (controlled) | | `defaultValue` | `DateValue \| null` | - | The initial date (uncontrolled) | | `onChange` | `(value: MappedDateValue \| null) => void` | - | Called when the date changes | | `minValue` | `DateValue \| null` | - | Earliest valid date | | `maxValue` | `DateValue \| null` | - | Latest valid date | | `isDateUnavailable` | `(date: DateValue) => boolean` | - | Marks a date invalid | | `placeholderValue` | `DateValue \| null` | - | Date the empty segments start from when stepped | | `granularity` | `"day" \| "hour" \| "minute" \| "second"` | - | Smallest unit shown; `"day"` for dates, `"minute"` for times | | `hourCycle` | `12 \| 24` | - | Clock used for hours; follows the locale by default | | `hideTimeZone` | `boolean` | `false` | Hides the time zone of a zoned value | | `shouldForceLeadingZeros` | `boolean` | - | Pads every segment to its full width | | `isDisabled` | `boolean` | `false` | Disables the field | | `isReadOnly` | `boolean` | `false` | Keeps the value but blocks editing | | `isRequired` | `boolean` | `false` | Requires a value; sets `data-required` | | `isInvalid` | `boolean` | - | Marks the field invalid | | `name` | `string` | - | Name of the hidden input submitted with a form | | `className` | `string \| ((values: DateFieldRenderProps) => string)` | - | Additional classes, or a function of the render props | | `...rest` | | | Every React Aria `DateField` prop | ### DateField.Group | Prop | Type | Default | Description | | ----------- | -------------------------------------------------- | ----------- | ----------------------------------------------------- | | `variant` | `"primary" \| "secondary"` | `"primary"` | Visual style of the group | | `fullWidth` | `boolean` | `false` | Makes the group fill its container | | `className` | `string \| ((values: GroupRenderProps) => string)` | - | Additional classes, or a function of the render props | | `...rest` | | | Every React Aria `Group` prop | ### DateField.Input | Prop | Type | Default | Description | | ----------- | ------------------------------------------------------ | ------- | ----------------------------------------------------- | | `children` | `(segment: DateSegment) => ReactElement` | - | Renders one segment; pass it to `DateField.Segment` | | `className` | `string \| ((values: DateInputRenderProps) => string)` | - | Additional classes, or a function of the render props | | `...rest` | | | Every React Aria `DateInput` prop | ### DateField.InputContainer | Prop | Type | Default | Description | | ----------- | --------------------------------- | ------- | ------------------------------------------------------ | | `render` | `DOMRenderFunction` | - | Replaces the rendered element; `E` defaults to `"div"` | | `className` | `string` | - | Additional classes | | `...rest` | | | Every attribute of the rendered element | ### DateField.Segment | Prop | Type | Default | Description | | ----------- | ------------- | ------- | --------------------------------------- | | `segment` | `DateSegment` | - | The segment passed by `DateField.Input` | | `className` | `string` | - | Additional classes | | `...rest` | | | Every React Aria `DateSegment` prop | ### DateField.Prefix | Prop | Type | Default | Description | | ----------- | --------------------------------- | ------- | ------------------------------------------------------ | | `render` | `DOMRenderFunction` | - | Replaces the rendered element; `E` defaults to `"div"` | | `className` | `string` | - | Additional classes | | `...rest` | | | Every attribute of the rendered element | ### DateField.Suffix | Prop | Type | Default | Description | | ----------- | --------------------------------- | ------- | ------------------------------------------------------ | | `render` | `DOMRenderFunction` | - | Replaces the rendered element; `E` defaults to `"div"` | | `className` | `string` | - | Additional classes | | `...rest` | | | Every attribute of the rendered element | ### Render Props `className` on `DateField` receives these values: | Prop | Type | Description | | ------------ | --------- | ------------------------------ | | `isInvalid` | `boolean` | Whether the field is invalid | | `isDisabled` | `boolean` | Whether the field is disabled | | `isReadOnly` | `boolean` | Whether the field is read only |
# TimeField > Segmented field for typing a time **Category**: components **URL**: https://peakui.dev/en/docs/react/components/time-field **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(date-and-time)/time-field.mdx ## Usage ```tsx import {TimeField, Label} from "@peakui/react"; ``` ```tsx "use client"; import {Label, TimeField} from "@peakui/react"; export function Basic() { return ( {(segment) => } ); } ``` ### Anatomy ```tsx import {TimeField, Description, FieldError, Label} from "@peakui/react"; export default () => ( ); ``` ## Examples ### Variants ```tsx "use client"; import {Label, TimeField} from "@peakui/react"; export function Variants() { return (
{(segment) => } {(segment) => }
); } ``` ### With Prefix and Suffix ```tsx "use client"; import {Clock} from "@gravity-ui/icons"; import {Label, TimeField} from "@peakui/react"; export function WithPrefixAndSuffix() { return ( {(segment) => } UTC ); } ``` ### With Description ```tsx "use client"; import {Description, Label, TimeField} from "@peakui/react"; export function WithDescription() { return ( {(segment) => } Enter the start of the meeting ); } ``` ### Required ```tsx "use client"; import {Description, Label, TimeField} from "@peakui/react"; export function Required() { return ( {(segment) => } Required field ); } ``` ### Disabled ```tsx "use client"; import {Time} from "@internationalized/date"; import {Description, Label, TimeField} from "@peakui/react"; export function Disabled() { return ( {(segment) => } This time field is disabled ); } ``` ### Full Width ```tsx "use client"; import {Label, TimeField} from "@peakui/react"; export function FullWidth() { return (
{(segment) => }
); } ``` ### Invalid ```tsx "use client"; import {FieldError, Label, TimeField} from "@peakui/react"; export function Invalid() { return ( {(segment) => } Time must be within opening hours ); } ``` ### Granularity ```tsx "use client"; import {Time} from "@internationalized/date"; import {Label, TimeField} from "@peakui/react"; export function Granularity() { return ( {(segment) => } ); } ``` ### Hour Cycle ```tsx "use client"; import {Time} from "@internationalized/date"; import {Label, TimeField} from "@peakui/react"; export function HourCycle() { return (
{(segment) => } {(segment) => }
); } ``` ### Controlled ```tsx "use client"; import {Time} from "@internationalized/date"; import {Button, Description, Label, TimeField} from "@peakui/react"; import {useState} from "react"; export function Controlled() { const [value, setValue] = useState
# Alert > A status message with an icon, title and description **Category**: components **URL**: https://peakui.dev/en/docs/react/components/alert **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(feedback)/alert.mdx ## Usage ```tsx import {Alert} from "@peakui/react"; ``` ```tsx import {Alert} from "@peakui/react"; export function Basic() { return ( New features available Check out our latest updates including dark mode support and improved accessibility features. ); } ``` Content inside an Alert reads the default surface level, even when the Alert sits on a raised `Surface`. ### Anatomy ```tsx import {Alert} from "@peakui/react"; export default () => ( Title Description ); ``` ## Examples ### Statuses ```tsx import {Alert} from "@peakui/react"; const STATUSES = [ {description: "General information for the reader.", status: "default", title: "New features"}, {description: "A new version is available.", status: "accent", title: "Update available"}, {description: "Your payment has been processed.", status: "success", title: "Payment successful"}, { description: "You're using 90% of your storage quota.", status: "warning", title: "Storage almost full", }, { description: "We're experiencing connection issues.", status: "danger", title: "Unable to connect", }, ] as const; export function Statuses() { return (
{STATUSES.map(({description, status, title}) => ( {title} {description} ))}
); } ``` ### With Actions ```tsx import {Alert, Button} from "@peakui/react"; export function WithActions() { return ( Update available A new version of the application is available. Please refresh to get the latest features and bug fixes. ); } ``` ### Without Description ```tsx import {Alert, CloseButton} from "@peakui/react"; export function WithoutDescription() { return ( Profile updated successfully ); } ``` ### Custom Indicator `Alert.Indicator` shows the status icon by default; children replace it. ```tsx import {Alert, Spinner} from "@peakui/react"; export function CustomIndicator() { return ( Processing your request Please wait while we sync your data. This may take a few moments. ); } ``` ## Customization ### Tailwind CSS ```tsx … ``` ### Global CSS ```css @layer components { .alert { @apply rounded-2xl; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The Alert component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/alert.css)): #### Base Class - `.alert` - Base alert styles #### Status Classes - `.alert--default` - `.alert--accent` - `.alert--success` - `.alert--warning` - `.alert--danger` #### Element Classes - `.alert__indicator` - The status icon slot - `.alert__content` - The text container - `.alert__title` - The title element - `.alert__description` - The description element ### Slots - `[data-slot="alert-root"]` - The root element - `[data-slot="alert-indicator"]` - The status icon slot - `[data-slot="alert-content"]` - The text container - `[data-slot="alert-title"]` - The title element - `[data-slot="alert-description"]` - The description element - `[data-slot="alert-default-icon"]` - The icon the indicator renders by default ## API Reference ### Alert | Prop | Type | Default | Description | | ----------- | ------------------------------------------------------------- | ----------- | --------------------------------------------------- | | `children` | `ReactNode` | - | Alert content (required) | | `status` | `'accent' \| 'danger' \| 'default' \| 'success' \| 'warning'` | `'default'` | Alert status; sets the indicator and title color | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered `
` with your own element | Every other attribute of a `
` is accepted. ### Alert.Indicator | Prop | Type | Default | Description | | ----------- | ------------------------------------- | ------- | --------------------------------------------------- | | `children` | `ReactNode` | - | Custom indicator; replaces the default status icon | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered `
` with your own element | Every other attribute of a `
` is accepted. ### Alert.Content | Prop | Type | Default | Description | | ----------- | ------------------------------------- | ------- | --------------------------------------------------- | | `children` | `ReactNode` | - | Content children | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered `
` with your own element | Every other attribute of a `
` is accepted. ### Alert.Title | Prop | Type | Default | Description | | ----------- | ----------------------------------- | ------- | ------------------------------------------------- | | `children` | `ReactNode` | - | Title text | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'p', undefined>` | - | Replaces the rendered `

` with your own element | Every other attribute of a `

` is accepted. ### Alert.Description | Prop | Type | Default | Description | | ----------- | -------------------------------------- | ------- | ---------------------------------------------------- | | `children` | `ReactNode` | - | Description text | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'span', undefined>` | - | Replaces the rendered `` with your own element | Every other attribute of a `` is accepted. # EmptyState > A placeholder for content with nothing to show **Category**: components **URL**: https://peakui.dev/en/docs/react/components/empty-state **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(feedback)/empty-state.mdx ## Usage ```tsx import {EmptyState} from "@peakui/react"; ``` ```tsx import {EmptyState} from "@peakui/react"; export function Basic() { return ; } ``` Omitted or empty children render the component's own default message, `No results found`. ## Examples ### Custom Message ```tsx import {EmptyState} from "@peakui/react"; export function CustomMessage() { return No projects match the current filters; } ``` ### With Icon ```tsx import {Magnifier} from "@gravity-ui/icons"; import {EmptyState} from "@peakui/react"; export function WithIcon() { return (

Nothing found

Try a different query or reset the filters

); } ``` ### With Action ```tsx import {Button, EmptyState} from "@peakui/react"; export function WithAction() { return (

No projects yet

Create the first project to get started

); } ``` ## Customization ### Tailwind CSS The block ships no layout of its own: width, centering and gaps come from the consumer. ```tsx Nothing here yet ``` ### Global CSS ```css @layer components { .empty-state { @apply py-8 text-center; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The EmptyState component uses this CSS class ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/empty-state.css)): - `.empty-state` - Base styles with compact padding and muted text ### Slots - `[data-slot="empty-state"]` - The root element ## API Reference ### EmptyState | Prop | Type | Default | Description | | ----------- | ------------------------------------- | -------------------- | ---------------------------------------------------------------------- | | `children` | `ReactNode` | `"No results found"` | Content; the default message renders when children is omitted or empty | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered `
` with your own element | Every other attribute of a `
` is accepted. # Meter > Shows a quantity within a known range, such as disk usage **Category**: components **URL**: https://peakui.dev/en/docs/react/components/meter **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(feedback)/meter.mdx ## Usage ```tsx import {Label, Meter} from "@peakui/react"; ``` ```tsx import {Label, Meter} from "@peakui/react"; export function Basic() { return ( ); } ``` ### Anatomy ```tsx import {Label, Meter} from "@peakui/react"; export default () => ( ); ``` A meter shows where a value sits within a known range (storage used, a score). For the progress of a task that finishes, use `ProgressBar`. ## Examples ### Sizes ```tsx import {Label, Meter} from "@peakui/react"; export function Sizes() { return (
); } ``` ### Colors ```tsx import {Label, Meter} from "@peakui/react"; const COLORS = [ {color: "default", label: "Default"}, {color: "accent", label: "Accent"}, {color: "success", label: "Success"}, {color: "warning", label: "Warning"}, {color: "danger", label: "Danger"}, ] as const; export function Colors() { return (
{COLORS.map(({color, label}) => ( ))}
); } ``` ### Without Label Without a visible `Label`, `aria-label` names the meter. ```tsx import {Meter} from "@peakui/react"; export function WithoutLabel() { return ( ); } ``` ### Custom Value `minValue`, `maxValue` and `formatOptions` set the range and the display format. ```tsx import {Label, Meter} from "@peakui/react"; export function CustomValue() { return ( ); } ``` ## Customization ### Tailwind CSS ```tsx import {Label, Meter} from "@peakui/react"; export function CustomStyles() { return ( ); } ``` ### Global CSS ```css @layer components { .meter__track { @apply h-3 rounded-full; } .meter__fill { @apply rounded-full; } .meter--success { --meter-fill: var(--color-success); } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The Meter component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/meter.css)): #### Base & Element Classes - `.meter` - Base container (grid layout) - `.meter__output` - Value text display - `.meter__track` - Track background - `.meter__fill` - Filled portion of the track #### Size Classes - `.meter--sm` - Small size, thinner track - `.meter--md` - Medium size, the default - `.meter--lg` - Large size, thicker track #### Color Classes - `.meter--default` - `.meter--accent` - `.meter--success` - `.meter--warning` - `.meter--danger` ### Slots - `[data-slot="meter"]` - `[data-slot="meter-output"]` - `[data-slot="meter-track"]` - `[data-slot="meter-fill"]` ### CSS Variables | Variable | Purpose | | -------------- | ------------------------------------ | | `--meter-fill` | Fill color, set by the color classes | ### Interactive States The component supports both CSS pseudo-classes and data attributes: - **Disabled**: `:disabled`, `[data-disabled="true"]` or `[aria-disabled="true"]` ## API Reference ### Meter | Prop | Type | Default | Description | | --------------- | ------------------------------------------------------------- | -------------------- | ---------------------------------------------------------------------- | | `value` | `number` | `0` | The current value | | `minValue` | `number` | `0` | The smallest value | | `maxValue` | `number` | `100` | The largest value | | `formatOptions` | `Intl.NumberFormatOptions` | `{style: 'percent'}` | Display format of the value | | `valueLabel` | `ReactNode` | - | Text announced as the value, such as "2 of 5" | | `color` | `'default' \| 'accent' \| 'success' \| 'warning' \| 'danger'` | `'accent'` | Color of the fill | | `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | Height of the track | | `children` | `ReactNode \| (values: MeterRenderProps) => ReactNode` | - | Content, or a function of the render props | | `className` | `string \| (values: MeterRenderProps) => string` | - | Additional classes, or a function of the render props | | `...rest` | | | Every React Aria `Meter` attribute is accepted, including `aria-label` | ### Meter.Output | Prop | Type | Default | Description | | ----------- | --------------------------------- | --------------- | ------------------------------------------------------- | | `children` | `ReactNode` | formatted value | Replaces the formatted value | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction` | - | Replaces the rendered element; `E` defaults to `'span'` | | `...rest` | | | Every `` attribute is accepted | ### Meter.Track | Prop | Type | Default | Description | | ----------- | --------------------------------- | ------- | ------------------------------------------------------ | | `children` | `ReactNode` | - | Holds `Meter.Fill` | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction` | - | Replaces the rendered element; `E` defaults to `'div'` | | `...rest` | | | Every `
` attribute is accepted | ### Meter.Fill | Prop | Type | Default | Description | | ----------- | --------------------------------- | ------- | ------------------------------------------------------ | | `children` | `ReactNode` | - | Content inside the fill | | `className` | `string` | - | Additional classes | | `style` | `CSSProperties` | - | Merged under the computed `width` | | `render` | `DOMRenderFunction` | - | Replaces the rendered element; `E` defaults to `'div'` | | `...rest` | | | Every `
` attribute is accepted | ### Render Props | Prop | Type | Description | | ------------ | --------------------- | ----------------------------------------------------------- | | `percentage` | `number \| undefined` | The value as a percentage between `minValue` and `maxValue` | | `valueText` | `string \| undefined` | The formatted value | # ProgressBar > Shows determinate or indeterminate progress of an operation **Category**: components **URL**: https://peakui.dev/en/docs/react/components/progress-bar **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(feedback)/progress-bar.mdx ## Usage ```tsx import {Label, ProgressBar} from "@peakui/react"; ``` ```tsx import {Label, ProgressBar} from "@peakui/react"; export function Basic() { return ( ); } ``` ### Anatomy ```tsx import {Label, ProgressBar} from "@peakui/react"; export default () => ( ); ``` ## Examples ### Sizes ```tsx import {Label, ProgressBar} from "@peakui/react"; export function Sizes() { return (
); } ``` ### Colors ```tsx import {Label, ProgressBar} from "@peakui/react"; const COLORS = [ {color: "default", label: "Default"}, {color: "accent", label: "Accent"}, {color: "success", label: "Success"}, {color: "warning", label: "Warning"}, {color: "danger", label: "Danger"}, ] as const; export function Colors() { return (
{COLORS.map(({color, label}) => ( ))}
); } ``` ### Without Label Without a visible `Label`, `aria-label` names the progress bar. ```tsx import {ProgressBar} from "@peakui/react"; export function WithoutLabel() { return ( ); } ``` ### Indeterminate `isIndeterminate` removes the value and animates the fill. ```tsx import {Label, ProgressBar} from "@peakui/react"; export function Indeterminate() { return ( ); } ``` ### Custom Value `minValue`, `maxValue` and `formatOptions` set the range and the display format. ```tsx import {Label, ProgressBar} from "@peakui/react"; export function CustomValue() { return ( ); } ``` ## Customization ### Tailwind CSS ```tsx import {Label, ProgressBar} from "@peakui/react"; export function CustomStyles() { return ( ); } ``` ### Global CSS ```css @layer components { .progress-bar__track { @apply h-3 rounded-full; } .progress-bar__fill { @apply rounded-full; } .progress-bar--success { --progress-bar-fill: var(--color-success); } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The ProgressBar component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/progress-bar.css)): #### Base & Element Classes - `.progress-bar` - Base container (grid layout) - `.progress-bar__output` - Value text display - `.progress-bar__track` - Track background - `.progress-bar__fill` - Filled portion of the track #### Size Classes - `.progress-bar--sm` - Small size, thinner track - `.progress-bar--md` - Medium size, the default - `.progress-bar--lg` - Large size, thicker track #### Color Classes - `.progress-bar--default` - `.progress-bar--accent` - `.progress-bar--success` - `.progress-bar--warning` - `.progress-bar--danger` ### Slots - `[data-slot="progress-bar"]` - `[data-slot="progress-bar-output"]` - `[data-slot="progress-bar-track"]` - `[data-slot="progress-bar-fill"]` ### CSS Variables | Variable | Purpose | | --------------------- | ------------------------------------ | | `--progress-bar-fill` | Fill color, set by the color classes | ### Interactive States The component supports both CSS pseudo-classes and data attributes: - **Indeterminate**: `:not([aria-valuenow])` - **Disabled**: `:disabled`, `[data-disabled="true"]` or `[aria-disabled="true"]` ## API Reference ### ProgressBar | Prop | Type | Default | Description | | ----------------- | ------------------------------------------------------------- | -------------------- | ---------------------------------------------------------------------------- | | `value` | `number` | `0` | The current value | | `minValue` | `number` | `0` | The smallest value | | `maxValue` | `number` | `100` | The largest value | | `isIndeterminate` | `boolean` | - | Whether progress is unknown; leaves out `aria-valuenow` and the fill width | | `formatOptions` | `Intl.NumberFormatOptions` | `{style: 'percent'}` | Display format of the value | | `valueLabel` | `ReactNode` | - | Text announced as the value, such as "2 of 5" | | `color` | `'default' \| 'accent' \| 'success' \| 'warning' \| 'danger'` | `'accent'` | Color of the fill | | `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | Height of the track | | `children` | `ReactNode \| (values: ProgressBarRenderProps) => ReactNode` | - | Content, or a function of the render props | | `className` | `string \| (values: ProgressBarRenderProps) => string` | - | Additional classes, or a function of the render props | | `...rest` | | | Every React Aria `ProgressBar` attribute is accepted, including `aria-label` | ### ProgressBar.Output | Prop | Type | Default | Description | | ----------- | --------------------------------- | --------------- | ------------------------------------------------------- | | `children` | `ReactNode` | formatted value | Replaces the formatted value | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction` | - | Replaces the rendered element; `E` defaults to `'span'` | | `...rest` | | | Every `` attribute is accepted | ### ProgressBar.Track | Prop | Type | Default | Description | | ----------- | --------------------------------- | ------- | ------------------------------------------------------ | | `children` | `ReactNode` | - | Holds `ProgressBar.Fill` | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction` | - | Replaces the rendered element; `E` defaults to `'div'` | | `...rest` | | | Every `
` attribute is accepted | ### ProgressBar.Fill | Prop | Type | Default | Description | | ----------- | --------------------------------- | ------- | ------------------------------------------------------ | | `children` | `ReactNode` | - | Content inside the fill | | `className` | `string` | - | Additional classes | | `style` | `CSSProperties` | - | Merged under the computed `width` | | `render` | `DOMRenderFunction` | - | Replaces the rendered element; `E` defaults to `'div'` | | `...rest` | | | Every `
` attribute is accepted | ### Render Props | Prop | Type | Description | | ----------------- | --------------------- | ----------------------------------------------------------- | | `percentage` | `number \| undefined` | The value as a percentage between `minValue` and `maxValue` | | `valueText` | `string \| undefined` | The formatted value | | `isIndeterminate` | `boolean` | Whether progress is unknown | # ProgressCircle > A circular indicator for determinate or indeterminate progress **Category**: components **URL**: https://peakui.dev/en/docs/react/components/progress-circle **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(feedback)/progress-circle.mdx ## Usage ```tsx import {ProgressCircle} from "@peakui/react"; ``` ```tsx import {ProgressCircle} from "@peakui/react"; export function Basic() { return ( ); } ``` ### Anatomy ```tsx import {ProgressCircle} from "@peakui/react"; export default () => ( ); ``` `ProgressCircle` is a React Aria `ProgressBar`: it has the `progressbar` role and the same value attributes, so assistive technology announces it as progress. Give it a name with `aria-label` or `aria-labelledby`. When the indicator must be announced as progress, prefer `ProgressCircle` to `Spinner`, which is a plain status region. ## Examples ### Sizes ```tsx import {ProgressCircle} from "@peakui/react"; export function Sizes() { return (
); } ``` ### Colors ```tsx import {ProgressCircle} from "@peakui/react"; export function Colors() { return (
); } ``` ### Indeterminate `isIndeterminate` removes the value and spins the circle. ```tsx import {ProgressCircle} from "@peakui/react"; export function Indeterminate() { return ( ); } ``` ### With Label ```tsx import {Label, ProgressCircle} from "@peakui/react"; export function WithLabel() { return (
); } ``` ### Custom SVG Props Each part is a composable component, so SVG attributes such as `strokeWidth` can be overridden directly. The arc's length and rotation are computed for the default geometry, a circle of radius 16 centred at 18 in a 36 by 36 box. Changing `r`, `cx`, `cy` or `viewBox` therefore also needs `strokeDasharray`, `strokeDashoffset` and `transform` on `ProgressCircle.FillCircle`, or the arc will not match the ring or the value. ```tsx import {ProgressCircle} from "@peakui/react"; export function CustomSvg() { return ( ); } ``` ## Customization ### Tailwind CSS ```tsx import {ProgressCircle} from "@peakui/react"; export function CustomStyles() { return ( ); } ``` ### Global CSS ```css @layer components { .progress-circle__track { @apply size-12; } .progress-circle__fill-circle { stroke: var(--color-success); } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The ProgressCircle component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/progress-circle.css)): #### Base & Element Classes - `.progress-circle` - Base container - `.progress-circle__track` - The SVG element - `.progress-circle__track-circle` - The ring behind the arc - `.progress-circle__fill-circle` - The progress arc #### Size Classes - `.progress-circle--sm` - Small size - `.progress-circle--md` - Medium size, the default - `.progress-circle--lg` - Large size #### Color Classes - `.progress-circle--default` - `.progress-circle--accent` - `.progress-circle--success` - `.progress-circle--warning` - `.progress-circle--danger` ### Slots - `[data-slot="progress-circle"]` - `[data-slot="progress-circle-track"]` - `[data-slot="progress-circle-track-circle"]` - `[data-slot="progress-circle-fill-circle"]` ### CSS Variables | Variable | Purpose | | -------------------------------- | ----------------------------------- | | `--progress-circle-stroke` | Arc color, set by the color classes | | `--progress-circle-track-stroke` | Ring color | ### Interactive States - **Indeterminate**: `:not([aria-valuenow])` - **Disabled**: `:disabled`, `[data-disabled="true"]` or `[aria-disabled="true"]` ## API Reference ### ProgressCircle | Prop | Type | Default | Description | | ----------------- | ------------------------------------------------------------- | -------------------- | ---------------------------------------------------------------------------- | | `value` | `number` | `0` | The current value | | `minValue` | `number` | `0` | The smallest value | | `maxValue` | `number` | `100` | The largest value | | `isIndeterminate` | `boolean` | - | Whether progress is unknown; leaves out `aria-valuenow` | | `formatOptions` | `Intl.NumberFormatOptions` | `{style: 'percent'}` | Display format of the value | | `color` | `'default' \| 'accent' \| 'success' \| 'warning' \| 'danger'` | `'accent'` | Color of the arc | | `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | Size of the circle | | `children` | `ReactNode \| (values: ProgressBarRenderProps) => ReactNode` | - | Content, or a function of the render props | | `className` | `string \| (values: ProgressBarRenderProps) => string` | - | Additional classes, or a function of the render props | | `...rest` | | | Every React Aria `ProgressBar` attribute is accepted, including `aria-label` | ### ProgressCircle.Track | Prop | Type | Default | Description | | ----------- | --------------------------------- | ------- | ------------------------------------------------------ | | `children` | `ReactNode` | - | Holds the two circles | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction` | - | Replaces the rendered element; `E` defaults to `'svg'` | | `...rest` | | | Every `` attribute is accepted, such as `viewBox` | ### ProgressCircle.TrackCircle and ProgressCircle.FillCircle | Prop | Type | Default | Description | | ----------- | --------------------------------- | ------- | --------------------------------------------------------------------------------- | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction` | - | Replaces the rendered element; `E` defaults to `'circle'` | | `...rest` | | | Every `` attribute is accepted, such as `r`, `cx`, `cy` and `strokeWidth` | ### Render Props | Prop | Type | Description | | ----------------- | --------------------- | ----------------------------------------------------------- | | `percentage` | `number \| undefined` | The value as a percentage between `minValue` and `maxValue` | | `valueText` | `string \| undefined` | The formatted value | | `isIndeterminate` | `boolean` | Whether progress is unknown |
# Skeleton > A placeholder showing the shape of content that is still loading **Category**: components **URL**: https://peakui.dev/en/docs/react/components/skeleton **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(feedback)/skeleton.mdx ## Usage ```tsx import {Skeleton} from "@peakui/react"; ``` ```tsx import {Skeleton} from "@peakui/react"; export function Basic() { return (
); } ``` Skeletons are decorative: the component sets no role, so hide them from assistive technology with `aria-hidden` when they stand alone. ## Examples ### Text Content ```tsx import {Skeleton} from "@peakui/react"; export function TextContent() { return (
); } ``` ### User Profile ```tsx import {Skeleton} from "@peakui/react"; export function UserProfile() { return (
); } ``` ### List Items ```tsx import {Skeleton} from "@peakui/react"; export function List() { return (
{Array.from({length: 3}).map((_, index) => (
))}
); } ``` ### Grid ```tsx import {Skeleton} from "@peakui/react"; export function Grid() { return (
); } ``` ### Single Shimmer Put the `skeleton--shimmer` class on a parent and `animationType="none"` on the children for one synchronized shimmer passing over all of them. ```tsx import {Skeleton} from "@peakui/react"; export function SingleShimmer() { return (
); } ``` ### Animation Types `animationType` picks the animation per component; `shimmer` is the default. ```tsx import {Skeleton} from "@peakui/react"; export function AnimationTypes() { return (

Shimmer

Pulse

None

); } ``` ## Customization ### Tailwind CSS Size and shape come from the consumer — the block itself ships with no dimensions. ```tsx ``` ### Global CSS Set `--skeleton-animation` on `:root` to change the default animation type for every Skeleton at once; the `animationType` prop still wins per component. ```css @layer components { .skeleton { @apply bg-surface-secondary/70; } .skeleton--pulse { @apply animate-pulse; } } :root { /* Possible values: shimmer, pulse, none */ --skeleton-animation: pulse; } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The Skeleton component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/skeleton.css)): #### Base Class - `.skeleton` - Base skeleton styles with background and rounded corners #### Animation Variant Classes - `.skeleton--shimmer` - Shimmer animation with a moving gradient (default) - `.skeleton--pulse` - Pulse animation - `.skeleton--none` - Static placeholder without animation ### Slots - `[data-slot="skeleton"]` - The root element ## API Reference ### Skeleton | Prop | Type | Default | Description | | --------------- | ------------------------------------- | ------------------------------------- | ---------------------------------------------------------- | | `animationType` | `'shimmer' \| 'pulse' \| 'none'` | `'shimmer'` or `--skeleton-animation` | Animation type; the CSS variable sets the app-wide default | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered `
` with your own element | Every other attribute of a `
` is accepted. # Spinner > A loading indicator in four sizes and five colors, announced to assistive technology as a status. **Category**: components **URL**: https://peakui.dev/en/docs/react/components/spinner **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(feedback)/spinner.mdx ## Usage ```tsx import {Spinner} from "@peakui/react"; ``` ```tsx import {Spinner} from "@peakui/react"; export function Basic() { return ; } ``` ## Examples ### Sizes ```tsx import {Spinner} from "@peakui/react"; export function Sizes() { return (
); } ``` ### Colors `color="current"` takes the text color of the parent, which is what you want inside a button. ```tsx import {Spinner} from "@peakui/react"; export function Colors() { return (
); } ``` ### Custom Label The spinner has `role="status"` and is labelled "Loading" by default. Pass `aria-label` to say what is loading. ```tsx import {Spinner} from "@peakui/react"; export function CustomLabel() { return (
Uploading the file
); } ``` When the spinner sits next to text that already says what is happening, hide it from assistive technology with `aria-hidden` instead: ```tsx ``` ## Customization ### Tailwind CSS The spinner draws with `currentColor`, so any text color utility recolors it. ```tsx ``` ### Global CSS ```css @layer components { .spinner--lg { @apply size-10; } } ``` ## Styling Reference ### CSS Classes The Spinner component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/spinner.css)): #### Base & Size Classes - `.spinner` - Base spinner styles - `.spinner--sm` - Small size - `.spinner--md` - Medium size - `.spinner--lg` - Large size - `.spinner--xl` - Extra large size #### Color Classes - `.spinner--current` - Inherits the parent's text color - `.spinner--accent` - `.spinner--success` - `.spinner--warning` - `.spinner--danger` ### Slots - `[data-slot="spinner"]` - The root element - `[data-slot="spinner-icon"]` - The animated SVG ## API Reference ### Spinner | Prop | Type | Default | Description | | ------------ | ------------------------------------------------------------- | ----------- | ---------------------------------------------------- | | `size` | `'sm' \| 'md' \| 'lg' \| 'xl'` | `'md'` | Size of the spinner | | `color` | `'current' \| 'accent' \| 'success' \| 'warning' \| 'danger'` | `'accent'` | Color of the spinner | | `aria-label` | `string` | `'Loading'` | Accessible name announced for the status | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'span', undefined>` | - | Replaces the rendered `` with your own element | Every other attribute of a `` is accepted.
# CheckboxGroup > Group of related checkboxes **Category**: components **URL**: https://peakui.dev/en/docs/react/components/checkbox-group **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(forms)/checkbox-group.mdx ## Usage ```tsx import {Checkbox, CheckboxGroup} from "@peakui/react"; ``` ```tsx import {Checkbox, CheckboxGroup, Description, Label} from "@peakui/react"; export function Basic() { return ( Choose all that apply Coding Love building software Design Enjoy creating beautiful interfaces Writing Passionate about content creation ); } ``` ## Examples ### Indeterminate Select All ```tsx "use client"; import {Checkbox, CheckboxGroup} from "@peakui/react"; import {useState} from "react"; const ALL = ["coding", "design", "writing"] as const; export function Indeterminate() { const [selected, setSelected] = useState(["coding"]); return (
0 && selected.length < ALL.length} isSelected={selected.length === ALL.length} name="select-all" onChange={(isSelected: boolean) => { setSelected(isSelected ? [...ALL] : []); }} > Select all
{ALL.map((value) => ( {value} ))}
); } ``` ### Disabled ```tsx import {Checkbox, CheckboxGroup, Description, Label} from "@peakui/react"; export function Disabled() { return ( Feature selection is temporarily disabled Feature 1 This feature is coming soon Feature 2 This feature is coming soon ); } ``` ## Customization ### Tailwind CSS ```tsx Option A ``` ### Global CSS ```css .checkbox-group { gap: 0.5rem; } ``` ## Styling Reference ### CSS Classes | Class | Description | | :------------------------------------------------------- | :------------------------ | | `.checkbox-group` | The group wrapper element | | `.checkbox-group--primary`, `.checkbox-group--secondary` | Variant modifiers | ### Slots | Slot | Description | | :----------------------------- | :------------------------ | | `[data-slot="checkbox-group"]` | The group wrapper element | ### Interactive States The group itself renders no interactive states; the styles apply to its `[data-slot="checkbox"]` children. ## API Reference ### CheckboxGroup.Root | Prop | Type | Default | Description | | :------------- | :--------------------------------------------------- | :---------- | :----------------------------------------------------- | | `variant` | `"primary" \| "secondary"` | `"primary"` | Visual variant inherited by child checkboxes | | `value` | `string[]` | - | Controlled selected values | | `defaultValue` | `string[]` | - | Uncontrolled initial values | | `isDisabled` | `boolean` | - | Disables every child checkbox | | `isReadOnly` | `boolean` | - | Makes every child checkbox read-only | | `name` | `string` | - | The name used when submitting an HTML form | | `onChange` | `(value: string[]) => void` | - | Called when the selection changes | | `render` | `DOMRenderFunction<'div', CheckboxGroupRenderProps>` | - | Replaces the rendered element | | `...rest` | | | Every React Aria `CheckboxGroup` attribute is accepted | ### Render Props `children` and `className` accept a function receiving the group render props (`isDisabled`, `isReadOnly`, `isRequired`, `isInvalid`, `state`).
# Checkbox > Selectable box with label and indicator **Category**: components **URL**: https://peakui.dev/en/docs/react/components/checkbox **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(forms)/checkbox.mdx ## Usage ```tsx import {Checkbox} from "@peakui/react"; ``` ```tsx import {Checkbox} from "@peakui/react"; export function Basic() { return ( Accept terms and conditions ); } ``` ### Anatomy ```tsx Label text ``` ## Examples ### Variants ```tsx import {Checkbox, Description} from "@peakui/react"; export function Variants() { return (
Primary checkbox Standard styling with default background Secondary checkbox Lower emphasis variant for use in surfaces
); } ``` ### Indeterminate ```tsx import {Checkbox, Description} from "@peakui/react"; export function Indeterminate() { return ( Select all Shows indeterminate state ); } ``` ### Disabled ```tsx import {Checkbox, Description} from "@peakui/react"; export function Disabled() { return ( Feature This feature is coming soon ); } ``` ### Invalid ```tsx import {Checkbox, FieldError} from "@peakui/react"; export function Invalid() { return ( I agree to the terms You must accept the terms to continue ); } ``` ### Controlled ```tsx "use client"; import {Checkbox} from "@peakui/react"; import {useState} from "react"; export function Controlled() { const [isSelected, setIsSelected] = useState(true); return (
Email notifications

Status: {isSelected ? "Enabled" : "Disabled"}

); } ``` ## Customization ### Tailwind CSS ```tsx Label text ``` ### Global CSS ```css .checkbox { --checkbox-control-bg: var(--default); } ``` ## Styling Reference ### CSS Classes | Class | Description | | :------------------------------------------- | :-------------------------------------------- | | `.checkbox` | The field wrapper element | | `.checkbox--primary`, `.checkbox--secondary` | Variant modifiers | | `.checkbox__content` | The clickable label wrapping control and text | | `.checkbox__control` | The square box the indicator sits in | | `.checkbox__indicator` | The indicator container | ### Slots | Slot | Description | | :-------------------------------------------------------- | :--------------------------------- | | `[data-slot="checkbox"]` | The field wrapper element | | `[data-slot="checkbox-content"]` | The clickable label element | | `[data-slot="checkbox-control"]` | The square box element | | `[data-slot="checkbox-indicator"]` | The indicator container element | | `[data-slot="checkbox-default-indicator--checkmark"]` | The default checkmark SVG | | `[data-slot="checkbox-default-indicator--indeterminate"]` | The default indeterminate line SVG | ### CSS Variables | Variable | Purpose | | :---------------------- | :----------------------------------------------------- | | `--checkbox-control-bg` | Unselected background of the secondary variant control | ### Interactive States The component supports both CSS pseudo-classes and data attributes: | State | Attribute | | :---------------- | :---------------------------- | | Selected | `[data-selected="true"]` | | Indeterminate | `[data-indeterminate="true"]` | | Hovered | `[data-hovered="true"]` | | Pressed | `[data-pressed="true"]` | | Focused (visible) | `[data-focus-visible="true"]` | | Disabled | `[data-disabled="true"]` | | Invalid | `[data-invalid="true"]` | ## API Reference ### Checkbox.Root | Prop | Type | Default | Description | | :---------------- | :--------------------------------------------------- | :---------- | :----------------------------------------------------- | | `variant` | `"primary" \| "secondary"` | `"primary"` | Visual variant; inherited from the group when unset | | `name` | `string` | - | The name used when submitting an HTML form | | `isSelected` | `boolean` | - | Controlled selected state | | `defaultSelected` | `boolean` | - | Uncontrolled initial selected state | | `isIndeterminate` | `boolean` | - | Indeterminate state | | `isDisabled` | `boolean` | - | Disables the checkbox | | `isInvalid` | `boolean` | - | Marks the checkbox invalid | | `isRequired` | `boolean` | - | Marks the checkbox required | | `validate` | `(isSelected) => boolean \| string` | - | Validation function | | `onChange` | `(isSelected) => void` | - | Called when the selected state changes | | `render` | `DOMRenderFunction<'div', CheckboxFieldRenderProps>` | - | Replaces the rendered element | | `...rest` | | | Every React Aria `CheckboxField` attribute is accepted | ### Checkbox.Content | Prop | Type | Default | Description | | :-------- | :------------------------------------------------------ | :------ | :------------------------------------------------------ | | `render` | `DOMRenderFunction<'label', CheckboxButtonRenderProps>` | - | Replaces the rendered label element | | `...rest` | | | Every React Aria `CheckboxButton` attribute is accepted | ### Checkbox.Control | Prop | Type | Default | Description | | :------- | :------------------------------------- | :------ | :---------------------------- | | `render` | `DOMRenderFunction<'span', undefined>` | - | Replaces the rendered element | ### Checkbox.Indicator | Prop | Type | Default | Description | | :--------- | :------------------------------------- | :----------- | :------------------------------------------------ | | `children` | `ReactNode \| ((state) => ReactNode)` | default SVGs | Custom indicator; receives the field render props | | `render` | `DOMRenderFunction<'span', undefined>` | - | Replaces the rendered element | ### Render Props `children` and `className` of `Checkbox.Root` and `Checkbox.Content` accept a function receiving the respective React Aria render props.
# Description > Helper text for a form field, linked to the control so assistive technology reads it with the label. **Category**: components **URL**: https://peakui.dev/en/docs/react/components/description **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(forms)/description.mdx ## Usage ```tsx import {Description} from "@peakui/react"; ``` ```tsx import {Description, Input, Label, TextField} from "@peakui/react"; export function Basic() { return ( We never share your email with anyone. ); } ``` `Description` belongs inside a field such as `TextField`. The field links it to the control with `aria-describedby`; you do not set any ids. Outside a field, `Description` still renders its ``, but nothing links it to a control, so assistive technology does not read it with one. For free-standing helper text, use a plain element with the `description` class: `

`. ## Customization ### Tailwind CSS ```tsx Optional ``` ### Global CSS ```css @layer components { .description { @apply text-xs; } } ``` ## Styling Reference ### CSS Classes The Description component uses this CSS class ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/description.css)): - `.description` - Base description styles ### Slots - `[data-slot="description"]` ## API Reference ### Description | Prop | Type | Default | Description | | ------------- | ----------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------- | | `children` | `React.ReactNode` | - | The helper text | | `className` | `string` | - | Additional classes | | `elementType` | `string` | `'span'` | The element to render | | `render` | `DOMRenderFunction` | - | Replaces the rendered element with your own. React Aria types it loosely because `elementType` can change the element | The `slot` defaults to `description`; it is what links the text to the field, so leave it as it is inside a field. # ErrorMessage > Error text displayed through a parent's error slot **Category**: components **URL**: https://peakui.dev/en/docs/react/components/error-message **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(forms)/error-message.mdx ## Usage ```tsx import {ErrorMessage} from "@peakui/react"; ``` ```tsx "use client"; import {Description, ErrorMessage, Label, Tag, TagGroup} from "@peakui/react"; import {useState} from "react"; export function Basic() { const [selected, setSelected] = useState>(new Set()); const isInvalid = Array.from(selected).length === 0; return ( setSelected(keys)} > News Travel Gaming Shopping Select at least one category {!!isInvalid && <>Please select at least one category} ); } ``` `ErrorMessage` presents the `errorMessage` slot of a parent such as `TagGroup`; the parent decides when the message shows. For a form field's validation errors, use [FieldError](https://peakui.dev/docs/react/components/field-error), which renders them while the field is invalid. Outside a parent that publishes the `errorMessage` slot, `ErrorMessage` still renders its ``, but nothing links it to a control. Inside such a parent, the message is announced with it through `aria-describedby` while it is mounted. ## Customization ### Tailwind CSS ```tsx "use client"; import {Description, ErrorMessage, Label, Tag, TagGroup} from "@peakui/react"; import {useState} from "react"; export function CustomStyles() { const [selected, setSelected] = useState>(new Set()); const isInvalid = Array.from(selected).length === 0; return ( API Design Docs Pick at least one topic {!!isInvalid && <>Choose at least one topic} ); } ``` ### Global CSS ```css @layer components { .error-message { @apply text-sm font-medium; } } ``` ## Styling Reference ### CSS Classes The ErrorMessage component uses this CSS class ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/error-message.css)): - `.error-message` - Base error message styles ### Slots - `[data-slot="error-message"]` ## API Reference ### ErrorMessage | Prop | Type | Default | Description | | ------------- | ----------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------- | | `children` | `React.ReactNode` | - | The error message | | `className` | `string` | - | Additional classes | | `elementType` | `string` | `'span'` | The element to render | | `render` | `DOMRenderFunction` | - | Replaces the rendered element with your own. React Aria types it loosely because `elementType` can change the element | The `slot` defaults to `errorMessage`; it is what links the message to the parent, so leave it as it is. # FieldError > A validation message for a form field, rendered only while the field is invalid. **Category**: components **URL**: https://peakui.dev/en/docs/react/components/field-error **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(forms)/field-error.mdx ## Usage ```tsx import {FieldError} from "@peakui/react"; ``` ```tsx "use client"; import {FieldError, Input, Label, TextField} from "@peakui/react"; import {useState} from "react"; export function Basic() { const [value, setValue] = useState("jr"); const isInvalid = value.length > 0 && value.length < 3; return ( A username has at least 3 characters. ); } ``` `FieldError` belongs inside a field such as `TextField`. It renders only while the field is invalid, and the field links it to the control with `aria-describedby`. Outside a field it renders nothing. ## Examples ### Native Validation A bare `` shows the field's own messages, which for a built-in constraint are the browser's, in the browser's language and wording. To write a message of your own for each kind of error, use the children function and read `validationDetails`, as in the next example. Without children, `FieldError` shows the field's own validation messages: the browser's messages for constraints such as `isRequired` and `type="email"`, and the strings returned from the field's `validate` function. Submit the form empty to see it. ```tsx "use client"; import {Button, FieldError, Input, Label, TextField} from "@peakui/react"; export function Validation() { return (

{ event.preventDefault(); }} > {/* Without children, FieldError shows the browser's validation message. */}
); } ``` ### Render Function Per-error messages need the children function: `{({validationDetails}) => ...}`. `validationDetails` is the control's native `ValidityState`, so `valueMissing`, `tooShort`, `typeMismatch` and the rest say which constraint failed. A static child such as `Invalid` replaces every message with that one text. ```tsx "use client"; import {Button, FieldError, Input, Label, TextField} from "@peakui/react"; export function RenderFunction() { return (
{ event.preventDefault(); }} > {({validationDetails}) => validationDetails.valueMissing ? "Enter a password." : "Use at least 8 characters." }
); } ``` ## Customization ### Tailwind CSS ```tsx Enter a valid email address. ``` ### Global CSS ```css @layer components { .field-error { @apply text-xs; } } ``` ## Styling Reference ### CSS Classes The FieldError component uses this CSS class ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/field-error.css)): - `.field-error` - Base error message styles ### Interactive States - **Visible**: `[data-visible]` - present whenever the message is rendered ### Slots - `[data-slot="field-error"]` ## API Reference ### FieldError | Prop | Type | Default | Description | | ------------- | ----------------------------------------------------------------------- | -------- | ----------------------------------------------------------------------------------------------- | | `children` | `React.ReactNode \| (values: FieldErrorRenderProps) => React.ReactNode` | - | The message, or a function of the validation state. Defaults to the field's validation messages | | `className` | `string \| (values: FieldErrorRenderProps) => string` | - | Additional classes, or a function of the validation state | | `elementType` | `string` | `'span'` | The element to render. Use `'div'` for block-level children | | `render` | `DOMRenderFunction<'div', FieldErrorRenderProps>` | - | Replaces the rendered element with your own | ### Render Props When `children` or `className` is a function, it receives: | Prop | Type | Description | | ------------------- | --------------- | ---------------------------------------- | | `isInvalid` | `boolean` | Whether the field is invalid | | `validationErrors` | `string[]` | The current error messages | | `validationDetails` | `ValidityState` | The native validity state of the control |
# Fieldset > Groups related form fields under a legend, with a slot for the actions that belong to them. **Category**: components **URL**: https://peakui.dev/en/docs/react/components/fieldset **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(forms)/fieldset.mdx ## Usage ```tsx import {Fieldset} from "@peakui/react"; ``` ```tsx import {Button, Description, Fieldset, Input, Label, TextField} from "@peakui/react"; export function Basic() { return (
Profile Used for account notifications only.
); } ``` ### Anatomy ```tsx import {Fieldset} from "@peakui/react"; export default () => (
{/* fields */} {/* buttons */}
); ``` `Fieldset` renders a native `
`, and `Fieldset.Legend` a native ``, so the group is announced with its name by assistive technology. ## Examples ### Disabled `disabled` disables every control inside the group: the native inputs through the browser, and PeakUI buttons through React Aria, so that their state and styles agree. ```tsx import {Button, Fieldset, Input, Label, TextField} from "@peakui/react"; export function Disabled() { return (
Billing address
); } ``` ### Custom Element Each part accepts a `render` function to change the element it renders. Spread the props it receives onto your element. ```tsx "use client"; import {Fieldset, Input, Label, TextField} from "@peakui/react"; export function RenderProp() { return (
{/* `render` swaps the element and keeps the part's class, data-slot and ref. */} }> Shipping address
}>
); } ``` ## Customization ### Tailwind CSS ```tsx
Profile {/* fields */}
``` ### Global CSS ```css @layer components { .fieldset__legend { @apply text-lg font-semibold; } .fieldset__actions { @apply justify-end; } } ``` ## Styling Reference ### CSS Classes The Fieldset component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/fieldset.css)): - `.fieldset` - The root - `.fieldset__legend` - The legend - `.fieldset__group` - The container of the fields - `.fieldset__actions` - The container of the actions ### Slots - `[data-slot="fieldset"]` - `[data-slot="fieldset-legend"]` - `[data-slot="fieldset-group"]` - `[data-slot="fieldset-actions"]` ### Interactive States - **Disabled**: `[data-disabled]` on the root ## API Reference ### Fieldset | Prop | Type | Default | Description | | ----------- | ------------------------------------------ | ------- | -------------------------------------------------------- | | `disabled` | `boolean` | `false` | Disables every control inside the group | | `children` | `React.ReactNode` | - | The legend, the group and the actions | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'fieldset', undefined>` | - | Replaces the rendered `
` with your own element | Every other attribute of a `
` is accepted. ### Fieldset.Legend | Prop | Type | Default | Description | | ----------- | ---------------------------------------- | ------- | ------------------------------------------------------ | | `children` | `React.ReactNode` | - | The name of the group | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'legend', undefined>` | - | Replaces the rendered `` with your own element | ### Fieldset.Group | Prop | Type | Default | Description | | ----------- | ------------------------------------- | ------- | --------------------------------------------------- | | `children` | `React.ReactNode` | - | The fields | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered `
` with your own element | ### Fieldset.Actions | Prop | Type | Default | Description | | ----------- | ------------------------------------- | ------- | --------------------------------------------------- | | `children` | `React.ReactNode` | - | The buttons that act on the group | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered `
` with your own element | # Form > Validation-aware form wrapper **Category**: components **URL**: https://peakui.dev/en/docs/react/components/form **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(forms)/form.mdx ## Usage ```tsx import {Form} from "@peakui/react"; ``` ```tsx import {Button, Description, FieldError, Form, Input, Label, TextField} from "@peakui/react"; export function Basic() { return (
We never share it
); } ``` ## Examples Fields inside a form validate on submit; blocking an invalid submission is the browser's native constraint validation. ### Validation Behavior ```tsx
{/* fields validate on blur and show errors without blocking submit */}
``` ## Customization ### Tailwind CSS ```tsx
{/* fields */}
``` ### Global CSS ```css .form { gap: 1rem; } ``` ## Styling Reference ### CSS Classes | Class | Description | | :------ | :--------------- | | `.form` | The form element | ### Slots | Slot | Description | | :------------------- | :--------------- | | `[data-slot="form"]` | The form element | ## API Reference ### Form.Root | Prop | Type | Default | Description | | :------------------- | :----------------------------------- | :--------- | :-------------------------------------------------------------------------------------------------------------------------------- | | `validationErrors` | `Record` | - | Server-side errors keyed by field name | | `validationBehavior` | `"native" \| "aria"` | `"native"` | With `native`, the browser blocks invalid submits (`noValidate` stays off); with `aria`, validation is announced without blocking | | `onSubmit` | `(event) => void` | - | Native submit handler; read values from the form elements | | `...rest` | | | Every React Aria `Form` attribute is accepted |
# InputGroup > An input or a text area with a prefix and a suffix inside one shared frame. **Category**: components **URL**: https://peakui.dev/en/docs/react/components/input-group **Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(forms)/input-group.mdx ## Usage ```tsx import {InputGroup} from "@peakui/react"; ``` ```tsx import {Magnifier} from "@gravity-ui/icons"; import {InputGroup} from "@peakui/react"; export function Basic() { return ( ); } ``` ### Anatomy ```tsx import {InputGroup} from "@peakui/react"; export default () => ( {/* or */} ); ``` The group draws the frame and the focus ring; the control inside it is borderless. Clicking the prefix or the suffix focuses the control, unless the click lands on something interactive of its own, such as a button. ## Examples ### With Prefix ```tsx import {InputGroup} from "@peakui/react"; export function WithPrefix() { return ( @ ); } ``` ### With Suffix ```tsx import {InputGroup} from "@peakui/react"; export function WithSuffix() { return ( .example.com ); } ``` ### With Prefix and Suffix ```tsx import {InputGroup} from "@peakui/react"; export function WithPrefixAndSuffix() { return ( https:// .com ); } ``` ### With a Button A button in the suffix keeps its own behavior: pressing it does not move focus to the input. ```tsx "use client"; import {Eye, EyeSlash} from "@gravity-ui/icons"; import {Button, InputGroup} from "@peakui/react"; import {useState} from "react"; export function WithButton() { const [isVisible, setIsVisible] = useState(false); return ( ); } ``` ### With TextArea ```tsx import {Pencil} from "@gravity-ui/icons"; import {InputGroup} from "@peakui/react"; export function WithTextArea() { return ( ); } ``` ### Variants ```tsx import {InputGroup} from "@peakui/react"; export function Variants() { return (
@ @
); } ``` ### In a TextField Inside a `TextField` the group takes the field's label, invalid and disabled states, and its `variant`. ```tsx import {Description, FieldError, InputGroup, Label, TextField} from "@peakui/react"; export function InTextField() { return (
@ Shown on your public profile. @ A handle cannot contain spaces.
); } ``` ## Customization ### Tailwind CSS ```tsx @ ``` ### Global CSS ```css @layer components { .input-group { --input-group-radius: var(--radius-lg); } .input-group__prefix, .input-group__suffix { @apply text-xs uppercase; } } ``` ## Styling Reference ### CSS Classes The InputGroup component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/input-group.css)): #### Base & Variant Classes - `.input-group` - The frame around the control and its slots - `.input-group--primary` - Primary variant - `.input-group--secondary` - Secondary variant - `.input-group--full-width` - Stretches to the container's width #### Element Classes - `.input-group__input` - The control, both the input and the text area - `.input-group__prefix` - Content before the control - `.input-group__suffix` - Content after the control ### Slots - `[data-slot="input-group"]` - `[data-slot="input-group-input"]` - `[data-slot="input-group-textarea"]` - `[data-slot="input-group-prefix"]` - `[data-slot="input-group-suffix"]` ### CSS Variables | Variable | Purpose | | ---------------------------- | -------------------------------------------- | | `--input-group-bg` | Background color | | `--input-group-bg-hover` | Background color when hovered | | `--input-group-bg-focus` | Background color when the control is focused | | `--input-group-fg` | Text color | | `--input-group-placeholder` | Placeholder color | | `--input-group-border` | Border color | | `--input-group-border-hover` | Border color when hovered | | `--input-group-border-focus` | Border color when the control is focused | | `--input-group-radius` | Corner radius | | `--input-group-shadow` | Box shadow | ### Interactive States - **Hover**: `:hover` or `[data-hovered]` - **Focus**: the control's `:focus` or `[data-focused]`, styled on the group itself. `[data-focus-within]` is not styled: it is also set when a button in the prefix or suffix has focus, and the group should not look like a focused field then - **Invalid**: `[data-invalid]` or `[aria-invalid="true"]` - **Disabled**: `[data-disabled]` or `[aria-disabled="true"]` ## API Reference ### InputGroup | Prop | Type | Default | Description | | ------------ | ------------------------------------------------------------------ | ----------- | ------------------------------------------------------------------------- | | `variant` | `'primary' \| 'secondary'` | `'primary'` | Surface style. Inside a `TextField` it defaults to the field's `variant` | | `fullWidth` | `boolean` | `false` | Whether the group takes the full width of its container | | `isDisabled` | `boolean` | `false` | Whether the group is disabled. Set by the field when inside a `TextField` | | `isInvalid` | `boolean` | `false` | Whether the group is invalid. Set by the field when inside a `TextField` | | `children` | `React.ReactNode \| (values: GroupRenderProps) => React.ReactNode` | - | The control and its slots | | `className` | `string \| (values: GroupRenderProps) => string` | - | Additional classes, or a function of the group's state | ### InputGroup.Input Renders an `` and accepts its attributes, such as `type`, `placeholder`, `value`, `defaultValue` and `onChange`. | Prop | Type | Default | Description | | ----------- | ------------------------------------------------ | ------- | ------------------------------------------------------ | | `className` | `string \| (values: InputRenderProps) => string` | - | Additional classes, or a function of the input's state | ### InputGroup.TextArea Renders a `