# 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 `
# CloseButton
> An icon-only dismiss control with a built-in glyph and label
**Category**: components
**URL**: https://peakui.dev/en/docs/react/components/close-button
**Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(buttons)/close-button.mdx
## Usage
Renders an icon-only dismiss button: the X glyph and the accessible name `Close` are built in.
```tsx
import {CloseButton} from "@peakui/react";
```
```tsx
import {CloseButton} from "@peakui/react";
export function Basic() {
return ;
}
```
## Examples
### With a Custom Icon
Children replace the default glyph; the name still comes from `aria-label`.
```tsx
import {CircleXmark} from "@gravity-ui/icons";
import {CloseButton} from "@peakui/react";
export function WithCustomIcon() {
return (
{/* Children replace the default glyph; the label changes only through aria-label. */}
);
}
```
### Interactive
`onPress` fires on click and on Enter and Space alike.
```tsx
"use client";
import {CloseButton} from "@peakui/react";
import {useState} from "react";
export function Interactive() {
const [count, setCount] = useState(0);
return (
setCount(count + 1)}
/>
Clicked: {count} times
);
}
```
### Disabled State
```tsx
import {CloseButton} from "@peakui/react";
export function Disabled() {
return ;
}
```
## Customization
### Tailwind CSS
Pass utilities through `className`. They are merged with the button's own classes.
```tsx
```
### Global CSS
Override the button's classes in the `components` layer.
```css
@layer components {
.close-button--default {
@apply bg-danger-soft text-danger-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 CloseButton component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/close-button.css)):
#### Base Classes
- `.close-button` - Base styles: a 24px square icon-only button
#### Variant Classes
- `.close-button--default` - Default fill: `bg-default` background with a muted glyph
### Slots
- `[data-slot="close-button"]` - The button element
- `[data-slot="close-button-icon"]` - The default X glyph, an `svg`
### 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
### CloseButton
| Prop | Type | Default | Description |
| ----------- | ------------------------------------------------------- | ---------------- | ------------------------------------------------------- |
| `variant` | `'default'` | `'default'` | Visual variant |
| `children` | `ReactNode \| (values: ButtonRenderProps) => ReactNode` | built-in X glyph | 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 |
`aria-label` defaults to `Close` and a consumer value overrides it. `type` defaults to `button`. Every other [React Aria Button](https://react-aria.adobe.com/Button) prop is accepted.
### Render Props
When `children` or `className` is a function, it receives:
| Prop | Type | Description |
| ---------------- | --------- | ------------------------------------------ |
| `isPending` | `boolean` | Whether the button is waiting on an action |
| `isPressed` | `boolean` | Whether the button is currently pressed |
| `isHovered` | `boolean` | Whether the button is hovered |
| `isFocused` | `boolean` | Whether the button is focused |
| `isFocusVisible` | `boolean` | Whether the button is focused by keyboard |
| `isDisabled` | `boolean` | Whether the button is disabled |
# SegmentedControl
> Picks one option from a small set, with an indicator that slides to the chosen segment
**Category**: components
**URL**: https://peakui.dev/en/docs/react/components/segmented-control
**Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(buttons)/segmented-control.mdx
## Usage
```tsx
import {SegmentedControl} from "@peakui/react";
```
```tsx
import {SegmentedControl} from "@peakui/react";
export function Basic() {
return (
GridListTable
);
}
```
Each segment selects by its `id`, which is also the key in `selectedKey` and `defaultSelectedKey`.
Use `SegmentedControl` when the choice changes what the interface shows — a theme, a view mode, a
chart period, a table density. It is not a form control: nothing is submitted, and there is no
`name` or `value`. For a choice that travels with a form, use `RadioGroup`. For panels that swap
with the selection, use `Tabs`. For several independent toggles, or for multiple selection, use
`ToggleButtonGroup`.
An accessible name is required, because the control carries no visible label: pass `aria-label`, or
`aria-labelledby` pointing at a label you render yourself.
### Anatomy
```tsx
import {SegmentedControl} from "@peakui/react";
export default () => (
GridListTable
);
```
The indicator — the capsule around the selected segment — is rendered for you and is not a part you
place. It animates from the previous segment to the new one, and respects
`prefers-reduced-motion: reduce`, where it appears without animating.
The selection can never be *cleared*: `SegmentedControl` fixes single selection and refuses an empty
one, so clicking the selected segment again keeps it selected. It does not follow that a segment is
always selected — a control with neither `selectedKey` nor `defaultSelectedKey`, or one whose
`selectedKey` matches no segment, starts with nothing selected and renders no indicator. Passing
`selectedKey={undefined}` keeps the control *controlled* with nothing selected, which is how a
switcher waits for a value it does not have yet.
## Examples
### Sizes
`size` names the outer height of the capsule, matching a `Button` of the same size, so the control
lines up in a row with buttons.
```tsx
import {SegmentedControl} from "@peakui/react";
const sizes = ["sm", "md", "lg"] as const;
export function Sizes() {
return (
{sizes.map((size) => (
GridListTable
))}
);
}
```
At `sm` a segment is 24×24 on desktop — exactly the minimum of WCAG 2.2 AA
[SC 2.5.8 Target Size](https://www.w3.org/WAI/WCAG22/Understanding/target-size-minimum.html), with
no room to spare. Prefer `md` in headers, toolbars, and anywhere pointer precision matters; keep
`sm` for dense layouts you control.
### Icon-only segments
`isIconOnly` squares the segment, so the capsule reads as a circle rather than an oval. An icon
carries no accessible name, so give each segment its own `aria-label`.
```tsx
import {Display, Moon, Sun} from "@gravity-ui/icons";
import {SegmentedControl} from "@peakui/react";
export function IconOnly() {
return (
);
}
```
### Controlled
`onSelectionChange` hands over the newly selected key itself, not a set.
```tsx
"use client";
import {SegmentedControl} from "@peakui/react";
import {useState} from "react";
export function Controlled() {
const [view, setView] = useState("grid");
return (
setView(String(key))}
>
GridListTable
Selected: {view}
);
}
```
### Disabled State
`isDisabled` on the control disables every segment; on a segment it disables that one.
```tsx
import {SegmentedControl} from "@peakui/react";
export function Disabled() {
return (
GridListGrid
List
Table
);
}
```
### Width
The control hugs its content. Pass `className="w-full"` and it fills its container, sharing the
width equally between segments — there is no `fullWidth` prop, because a segment distributes by
design. A label is never truncated: in a container narrower than its content the segments keep their
labels and overflow instead.
```tsx
DayWeekMonth
```
## Keyboard
| Key | Behavior |
| ----------- | --------------------------------------------------------------- |
| Tab | Moves focus into the control, onto the selected segment |
| ← → | Moves focus between segments **without** changing the selection |
| Space Enter | Selects the focused segment |
The control reports itself as a radio group, while arrow keys move focus without selecting. ARIA
practices describe a radio group whose arrow keys also select; this behavior comes from the
underlying React Aria primitive and is documented here rather than worked around, so it stays
consistent with every other grouped control in the library.
## Customization
### Tailwind CSS
Pass utilities through `className`. They are merged with the control's own classes.
```tsx
Grid
List
```
### CSS Variables
Each custom property is the supported way to retheme the control.
```css
@layer components {
.segmented-control {
--segmented-control-bg: var(--color-surface-secondary);
--segmented-control-radius: var(--radius-lg);
--segmented-control-indicator-bg: var(--color-background);
--segmented-control-indicator-radius: var(--radius-md);
--segmented-control-indicator-shadow: none;
}
}
```
| Variable | Default | Controls |
| -------------------------------------- | --------------------------------- | ---------------------------------- |
| `--segmented-control-bg` | `var(--color-default)` | The capsule's background |
| `--segmented-control-radius` | `var(--radius-3xl)` | The capsule's corner radius |
| `--segmented-control-item-fg` | `var(--color-muted)` | An unselected segment's label |
| `--segmented-control-item-fg-selected` | `var(--color-segment-foreground)` | The selected segment's label |
| `--segmented-control-indicator-bg` | `var(--color-segment)` | The sliding indicator's background |
| `--segmented-control-indicator-radius` | `var(--radius-3xl)` | The indicator's corner radius |
| `--segmented-control-indicator-shadow` | `var(--shadow-surface)` | The indicator's shadow |
### Global CSS
Override the classes in the `components` layer.
```css
@layer components {
.segmented-control__item {
@apply px-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 SegmentedControl component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/segmented-control.css)):
#### Base & Layout Classes
- `.segmented-control` - The capsule container, and the `md` size
- `.segmented-control__item` - One segment
- `.segmented-control__indicator` - The sliding indicator behind the selected segment
#### Modifier Classes
- `.segmented-control--sm` - Small size
- `.segmented-control--md` - Medium size (default)
- `.segmented-control--lg` - Large size
- `.segmented-control__item--icon-only` - Square segment for a lone icon
### States
State lives on the segment as data attributes:
- `[data-selected]` - The selected segment
- `[data-hovered]` - Pointer over an unselected, enabled segment
- `[data-focus-visible]` - Keyboard focus
- `[data-disabled]` - Disabled segment, or every segment of a disabled control
### Slots
- `[data-slot="segmented-control"]`
- `[data-slot="segmented-control-item"]`
- `[data-slot="segmented-control-indicator"]`
## API Reference
### SegmentedControl
| Prop | Type | Default | Description |
| -------------------- | ---------------------- | ------- | ----------------------------------------------------------- |
| `selectedKey` | `Key` | - | Controlled selection |
| `defaultSelectedKey` | `Key` | - | Initial selection (uncontrolled) |
| `onSelectionChange` | `(key: Key) => void` | - | Called with the newly selected key |
| `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | Outer height of the capsule |
| `isDisabled` | `boolean` | - | Disables every segment |
| `aria-label` | `string` | - | Accessible name. Required unless `aria-labelledby` is given |
| `className` | `string` | - | Additional CSS classes |
| `children` | `React.ReactNode` | - | `SegmentedControl.Item`s, each selecting by its `id` |
Single selection is fixed and the selection can never be empty, so `selectionMode` and
`disallowEmptySelection` are not accepted. `orientation` is not accepted either: the control is
horizontal.
Every other [React Aria ToggleButtonGroup](https://react-aria.adobe.com/ToggleButtonGroup) prop is accepted.
### SegmentedControl.Item
| Prop | Type | Default | Description |
| ------------ | ----------------- | ------- | ----------------------------------------------------------------------------------------------------------------- |
| `id` | `Key` | - | The segment's key, used by `selectedKey`. Required — without it the segment leaves the group's selection entirely |
| `isDisabled` | `boolean` | - | Disables this segment |
| `isIconOnly` | `boolean` | `false` | Squares the segment for a lone icon, so the capsule is a circle |
| `aria-label` | `string` | - | Accessible name. Required when the segment holds only an icon |
| `className` | `string` | - | Additional CSS classes |
| `children` | `React.ReactNode` | - | The segment's label, an icon, or both |
The indicator is rendered inside each segment automatically; there is no `SegmentedControl.Indicator`
to place.
# ToggleButtonGroup
> Groups toggle buttons for single or multiple selection
**Category**: components
**URL**: https://peakui.dev/en/docs/react/components/toggle-button-group
**Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(buttons)/toggle-button-group.mdx
## Usage
```tsx
import {ToggleButton, ToggleButtonGroup} from "@peakui/react";
```
```tsx
import {Bold, Italic, Strikethrough, Underline} from "@gravity-ui/icons";
import {ToggleButton, ToggleButtonGroup} from "@peakui/react";
export function Basic() {
return (
);
}
```
Each `ToggleButton` in a group selects by its `id`, which is also the key in `selectedKeys` and `defaultSelectedKeys`.
### Anatomy
```tsx
import {ToggleButton, ToggleButtonGroup} from "@peakui/react";
export default () => (
First
Second
Third
);
```
## Examples
### Sizes
The `size` set on the group reaches every button, so the group stays uniform.
```tsx
import {Bold, Italic, Strikethrough, Underline} from "@gravity-ui/icons";
import {ToggleButton, ToggleButtonGroup} from "@peakui/react";
const items = [
{Icon: Bold, id: "bold", label: "Bold"},
{Icon: Italic, id: "italic", label: "Italic"},
{Icon: Underline, id: "underline", label: "Underline"},
{Icon: Strikethrough, id: "strikethrough", label: "Strikethrough"},
];
export function Sizes() {
return (
);
}
```
### Orientation
```tsx
import {Bold, Italic, Underline} from "@gravity-ui/icons";
import {ToggleButton, ToggleButtonGroup} from "@peakui/react";
export function Orientation() {
return (
);
}
```
### Full Width
```tsx
import {
Bold,
Italic,
TextAlignCenter,
TextAlignLeft,
TextAlignRight,
Underline,
} from "@gravity-ui/icons";
import {ToggleButton, ToggleButtonGroup} from "@peakui/react";
export function FullWidth() {
return (
Left
Center
Right
);
}
```
### Selection Mode
`selectionMode="single"` renders a radiogroup of mutually exclusive buttons; `selectionMode="multiple"` renders a toolbar of independent toggles.
```tsx
import {
Bold,
Italic,
Strikethrough,
TextAlignCenter,
TextAlignLeft,
TextAlignRight,
Underline,
} from "@gravity-ui/icons";
import {ToggleButton, ToggleButtonGroup} from "@peakui/react";
export function SelectionMode() {
return (
Left
Center
Right
);
}
```
### Detached
`isDetached` separates the buttons with gaps instead of joining their edges.
```tsx
import {Bold, Italic, Strikethrough, Underline} from "@gravity-ui/icons";
import {ToggleButton, ToggleButtonGroup} from "@peakui/react";
export function Detached() {
return (
);
}
```
### Without Separator
Omit `` and the buttons sit flush against each other.
```tsx
import {Bold, Italic, Strikethrough, Underline} from "@gravity-ui/icons";
import {ToggleButton, ToggleButtonGroup} from "@peakui/react";
export function WithoutSeparator() {
return (
);
}
```
### Controlled
```tsx
"use client";
import type {ToggleButtonGroupProps} from "@peakui/react";
import {Bold, Italic, Strikethrough, Underline} from "@gravity-ui/icons";
import {ToggleButton, ToggleButtonGroup} from "@peakui/react";
import {useState} from "react";
/* The selection type as the group itself declares it, so the state and the handler agree. */
type SelectedKeys = Parameters>[0];
export function Controlled() {
const [selectedKeys, setSelectedKeys] = useState(new Set(["bold"]));
return (
);
}
```
### Icon Only
An icon-only button has no visible text, so give it an `aria-label`.
```tsx
import {Bookmark, Heart} from "@gravity-ui/icons";
import {ToggleButton} from "@peakui/react";
export function IconOnly() {
return (
);
}
```
### Sizes
```tsx
import {Heart} from "@gravity-ui/icons";
import {ToggleButton} from "@peakui/react";
export function Sizes() {
return (
Small
Medium
Large
);
}
```
### Disabled
```tsx
import {Heart} from "@gravity-ui/icons";
import {ToggleButton} from "@peakui/react";
export function Disabled() {
return (
Like
Liked
);
}
```
### Controlled
Children can be a function that receives the button's state.
```tsx
"use client";
import {Heart, HeartFill} from "@gravity-ui/icons";
import {ToggleButton} from "@peakui/react";
import {useState} from "react";
export function Controlled() {
const [isSelected, setIsSelected] = useState(false);
return (
);
}
```
## Customization
### Tailwind CSS
Pass utilities through `className`. They are merged with the button's own classes.
```tsx
Rounded
```
### Global CSS
Override the button's classes in the `components` layer. Prefer the component variables where one exists: the selected state derives from them.
```css
@layer components {
.toggle-button--default {
--toggle-button-bg: var(--color-accent-soft);
--toggle-button-bg-hover: var(--color-accent-soft-hover);
--toggle-button-bg-pressed: var(--color-accent-soft-hover);
--toggle-button-fg: var(--color-accent-soft-foreground);
}
.toggle-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 ToggleButton component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui/blob/main/packages/styles/components/toggle-button.css)):
#### Base & Size Classes
- `.toggle-button` - Base toggle button styles
- `.toggle-button--sm` - Small size
- `.toggle-button--md` - Medium size
- `.toggle-button--lg` - Large size
#### Variant Classes
- `.toggle-button--default` - Neutral background, accent-soft when selected
- `.toggle-button--ghost` - Transparent background until hovered or selected
#### Modifier Classes
- `.toggle-button--icon-only` - Square button for a single icon
- `.toggle-button--icon-only.toggle-button--sm` - Small icon-only
- `.toggle-button--icon-only.toggle-button--lg` - Large icon-only
### Slots
- `[data-slot="toggle-button"]`
### CSS Variables
| Variable | Purpose |
| ------------------------------------- | ------------------------------------------ |
| `--toggle-button-bg` | Background color |
| `--toggle-button-bg-hover` | Background color when hovered |
| `--toggle-button-bg-pressed` | Background color when pressed |
| `--toggle-button-fg` | Text and icon color |
| `--toggle-button-bg-selected` | Background color when selected |
| `--toggle-button-bg-selected-hover` | Background color when selected and hovered |
| `--toggle-button-bg-selected-pressed` | Background color when selected and pressed |
| `--toggle-button-fg-selected` | Text and icon color when selected |
| `--toggle-button-border` | Border color |
| `--toggle-button-radius` | Corner radius |
### Interactive States
The toggle button supports both CSS pseudo-classes and data attributes:
- **Selected**: `[data-selected="true"]` (accent-soft background and foreground)
- **Hover**: `:hover` or `[data-hovered]`
- **Pressed**: `:active` or `[data-pressed]` (includes scale transform)
- **Focus**: `:focus-visible` or `[data-focus-visible]` (shows the focus ring)
- **Disabled**: `:disabled`, `[data-disabled]` or `[aria-disabled="true"]`
## API Reference
### ToggleButton
| Prop | Type | Default | Description |
| ----------------- | ------------------------------------------------------------------------- | ----------- | ---------------------------------------------------------------- |
| `variant` | `'default' \| 'ghost'` | `'default'` | Visual style |
| `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | Size of the toggle button |
| `isIconOnly` | `boolean` | `false` | Whether the button contains only an icon |
| `isSelected` | `boolean` | - | Controlled selected state |
| `defaultSelected` | `boolean` | `false` | Default selected state (uncontrolled) |
| `isDisabled` | `boolean` | `false` | Whether the toggle button is disabled |
| `onChange` | `(isSelected: boolean) => void` | - | Handler called when selection changes |
| `onPress` | `(e: PressEvent) => void` | - | Handler called when the button is pressed |
| `children` | `React.ReactNode \| (values: ToggleButtonRenderProps) => React.ReactNode` | - | Button content, or a function of the button's state |
| `className` | `string \| (values: ToggleButtonRenderProps) => string` | - | Additional classes, or a function of the button's state |
| `render` | `DOMRenderFunction<'button', ToggleButtonRenderProps>` | - | Replaces the rendered element. It must still return a `` |
There is no separate `isPressed` prop: a toggle button's pressed style comes from the interaction itself. Every other [React Aria ToggleButton](https://react-aria.adobe.com/ToggleButton) prop is accepted.
### Render Props
When `children` or `className` is a function, it receives:
| Prop | Type | Description |
| ---------------- | --------- | ----------------------------------------- |
| `isSelected` | `boolean` | Whether the button is currently selected |
| `isPressed` | `boolean` | Whether the button is currently pressed |
| `isHovered` | `boolean` | Whether the button is hovered |
| `isFocused` | `boolean` | Whether the button is focused |
| `isFocusVisible` | `boolean` | Whether the button is focused by keyboard |
| `isDisabled` | `boolean` | Whether the button is disabled |
# ContextMenu
> Menu opened by right-click, long-press or keyboard
**Category**: components
**URL**: https://peakui.dev/en/docs/react/components/context-menu
**Source**: https://raw.githubusercontent.com/peakui-dev/peakui/refs/heads/main/apps/docs/content/docs/en/react/components/(collections)/context-menu.mdx
## Usage
```tsx
import {ContextMenu} from "@peakui/react";
```
A context menu must never be the only path to an action: pair it with a visible control.
```tsx
"use client";
import type {Key} from "react";
import {Button, ContextMenu, Dropdown, Label} from "@peakui/react";
export function Basic() {
const onAction = (key: Key) => console.log(`Selected: ${String(key)}`);
return (
Right-click this region
{/* A context menu is never the only path to an action: the same actions stay visible. */}
Actions
);
}
```
### 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"}
setOpen((current) => !current)}>
Toggle menu
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 (
Actions
console.log(`Selected: ${key}`)}>
);
}
```
### Anatomy
```tsx
import {Button, Description, Dropdown, Kbd, Label, Separator} from "@peakui/react";
export default () => (
Actions
);
```
## 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 (
Actions
console.log(`Selected: ${key}`)}>
NOSD
);
}
```
### 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 (
Actions
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 (
Actions
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 (
Actions
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 (
Fruit
);
}
```
### 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 (
Fruits
{({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 (
Preferred Fruits
);
}
```
### 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 (
Styles
XCVBIUAHD
);
}
```
### With Keyboard Shortcuts
```tsx
"use client";
import {Button, Dropdown, Kbd, Label} from "@peakui/react";
export function WithKeyboardShortcuts() {
return (
Actions
console.log(`Selected: ${key}`)}>
NOSD
);
}
```
### With Submenus
```tsx
"use client";
import {Button, Dropdown, Label} from "@peakui/react";
export function WithSubmenus() {
return (
Share
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 (
Share
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 (
Jane Doe
jane@example.com
);
}
```
### Long Press Trigger
```tsx
import {Button, Dropdown, Label} from "@peakui/react";
export function LongPressTrigger() {
return (
Long Press
);
}
```
### 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 (
);
}
```
### 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"}
Actions
);
}
```
## Customization
### Tailwind CSS
```tsx
import {Button, Dropdown, Label} from "@peakui/react";
export function CustomStyles() {
return (
Actions
);
}
```
### 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 (
);
}
```
### 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 (
NewsTravelGamingNewsTravelGamingNewsTravelGaming
);
}
```
### Variants
`variant` switches the tag background between default and surface.
```tsx
import {Label, Tag, TagGroup} from "@peakui/react";
export function Variants() {
return (
NewsTravelGamingNewsTravelGaming
);
}
```
### Disabled State
`isDisabled` disables one tag; `disabledKeys` disables tags by id.
```tsx
import {Description, Label, Tag, TagGroup} from "@peakui/react";
export function Disabled() {
return (
NewsTravelGamingSome tags are disabledNewsTravelGamingTags 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)}
>
NewsTravelGamingShoppingChoose one category setMultipleSelected(keys)}
>
NewsTravelGamingShoppingChoose 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 (
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 (
);
}
```
### 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 (
);
}
```
### 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 (
);
}
```
### 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 (
);
}
```
### 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) => (
JD3
))}
);
}
```
### 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 (
Inbox
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 (
SmallMediumLarge
);
}
```
### 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 (
setValue(today(getLocalTimeZone()))}>
Set today
setValue(null)}>
Clear
);
}
```
### 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 () => (
{(segment) => }
);
```
## 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 () => (
TitleDescription
);
```
## 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 (
);
}
```
### 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.
Refresh
);
}
```
### 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 `
` 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
Create project
);
}
```
## 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 (
);
}
```
### 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 `
# 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
Saving
```
## 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 (
);
}
```
### 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)}
>
NewsTravelGamingShoppingSelect 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 (
APIDesignDocsPick 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 (
);
}
```
### 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 (
);
}
```
## 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 (
);
}
```
### Anatomy
```tsx
import {Fieldset} from "@peakui/react";
export default () => (
);
```
`Fieldset` renders a native `