The host says: {isExpanded ? "open" : "closed"}.
AI can make mistakes. Check important info.
Here is an answer backed by a single web source.
Referenced an uploaded document.
This ships the build to every user.
` - `.code-block__line` - One source line - `.code-block__token` - One highlighted token ### Slots - `[data-slot="code-block"]` - `[data-slot="code-block-header"]` - `[data-slot="code-block-copy-button"]` - `[data-slot="code-block-code"]` - `[data-slot="code-block-pre"]` - `[data-slot="code-block-line"]` - `[data-slot="code-block-token"]` ### CSS Variables | Variable | Purpose | | ---------------------------------- | -------------------------------------------------------------------------------------- | | `--code-block-bg` | Panel background; defaults to `var(--color-surface-secondary)` | | `--code-block-fg` | Text colour of plain code; defaults to `var(--color-surface-secondary-foreground)` | | `--code-block-radius` | Corner radius; defaults to `var(--radius-2xl)` | | `--code-block-padding` | Inset of the code; defaults to `0.75rem` | | `--code-block-font-size` | Code font size; defaults to `0.8125rem` | | `--code-block-header-gap` | Space between header items; defaults to `0.5rem` | | `--code-block-token-max-lightness` | Highest OKLCH lightness of a token in a light scheme, for contrast; defaults to `0.52` | | `--code-block-token-min-lightness` | Lowest OKLCH lightness of a token in a dark scheme, for contrast; defaults to `0.72` | ### Interactive States - **Highlighted**: `[data-highlighted="true"]` on `.code-block__pre` once colours are applied - **Copied**: `[data-copied="true"]` on the copy button for two seconds after a copy - **Focus**: `:focus-visible` on `.code-block__pre`, the keyboard stop that scrolls long lines - **Forced colors**: `@media (forced-colors: active)` draws the panel's edge as a `CanvasText` border and leaves token colours to the system ## API Reference ### CodeBlock | Prop | Type | Default | Description | | ----------- | ------------------------------------- | ------- | --------------------------------------------------- | | `children` | `ReactNode` | - | `Header` and `Code` | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered `` with your own element | | `...rest` | `ComponentProps<'div'>` | - | Native `` attributes | ### CodeBlock.Header | Prop | Type | Default | Description | | ----------- | ------------------------------------- | ------- | --------------------------------------------------- | | `children` | `ReactNode` | - | A label and actions | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered `` with your own element | | `...rest` | `ComponentProps<'div'>` | - | Native `` attributes | ### CodeBlock.Code | Prop | Type | Default | Description | | ----------- | ----------------------------------------- | ---------------------------------------------- | ------------------------------------------------------------------------------------------------------ | | `code` | `string` | - | The code to render | | `language` | `string` | `'plaintext'` | Highlighter language id or alias; an unknown one renders as plain text | | `theme` | `string \| {light: string; dark: string}` | `{light: 'github-light', dark: 'github-dark'}` | Highlighter theme for both colour schemes, or one per scheme; the scheme is the theme's `color-scheme` | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered `` with your own element | | `...rest` | `Omit, 'children'>` | - | Native ` ` attributes | ### CodeBlock.CopyButton | Prop | Type | Default | Description | | ------------ | --------------------------------------------------------------------------------------------- | ------------------------------ | ---------------------------------------------------------------------- | | `code` | `string` | - | Text written to the clipboard | | `aria-label` | `string` | `'Copy code'`, then `'Copied'` | Accessible label; yours replaces both | | `children` | `ReactNode` | copy glyph, then a check | Replaces the glyph | | `variant` | `'primary' \| 'secondary' \| 'tertiary' \| 'outline' \| 'ghost' \| 'danger' \| 'danger-soft'` | `'ghost'` | Core button style | | `size` | `'sm' \| 'md' \| 'lg'` | `'sm'` | Core button size | | `onPress` | `(e: PressEvent) => void` | - | Called after the copy starts; a refused clipboard changes nothing | | `className` | `string \| ((values: ButtonRenderProps) => string)` | - | Additional classes | | `render` | `DOMRenderFunction<'button', ButtonRenderProps>` | - | Replaces the rendered element; receives the props with `data-slot` set | | `...rest` | `ButtonProps` | - | Every other core Button prop |# Markdown > Streaming markdown for AI answers, block by block **Category**: components **URL**: https://peakui.pro/en/docs/react/components/markdown **Source**: https://raw.githubusercontent.com/peakui-dev/peakui-pro/refs/heads/main/apps/docs/content/docs/en/react/components/(ai)/markdown.mdx ## Usage `Markdown` is imported from its own subpath and needs four optional peers. ```bash npm install marked react-markdown remark-gfm shiki ``` ```tsx import {Markdown} from "@peakui-pro/react/markdown"; ``` ````tsx import {Markdown} from "@peakui-pro/react/markdown"; const response = [ "### Release notes", "", "This release adds **streaming** answers and fixes [two bugs](https://example.com).", "", "- Inline `code` keeps its own style", "- Fenced code is highlighted", "", "```ts", 'const status: "ready" | "streaming" = "ready";', "```", ].join("\n"); export function Basic() { return ( ); } ```` ## Examples ### Streaming Pass the whole string on every update; only the block that grew re-renders. ```tsx "use client"; import {Markdown} from "@peakui-pro/react/markdown"; import {useEffect, useState} from "react"; const answer = [ "### Streaming demo", "", "Each update re-renders only the block that changed.", "", "1. First item", "2. Second item", ].join("\n"); export function Streaming() { const [length, setLength] = useState(0); useEffect(() => { if (length >= answer.length) return; const timer = setTimeout(() => setLength((value) => value + 4), 30); return () => clearTimeout(timer); }, [length]); // Pass the whole string on every update; earlier blocks keep their DOM. return ({response} ); } ``` ### Custom Components `components` replaces the element for a tag; keep the object stable. ```tsx "use client"; import type {MarkdownComponents} from "@peakui-pro/react/markdown"; import {Markdown} from "@peakui-pro/react/markdown"; // Defined once, outside the component: a new object on every render re-renders every block. const components: MarkdownComponents = { a: ({children, href}) => ( {children} ↗ ), }; export function CustomComponents() { return ({answer.slice(0, length)} Read the [component docs](https://example.com/docs) or the [changelog](https://example.com/changelog). ); } ``` ### GFM ```tsx import {Markdown} from "@peakui-pro/react/markdown"; const table = [ "| Package | Optional peers |", "| --- | --- |", "| `code-block` | shiki |", "| `markdown` | marked, react-markdown, remark-gfm |", "", "- [x] Highlight fenced code", "- [ ] Write the changelog", "", "~~Root import~~ subpath import.", ].join("\n"); export function Gfm() { return{table} ; } ``` ### Images And Links No image loads unless `isImageAllowed` allows it; live links show their destination. ```tsx "use client"; import {Markdown} from "@peakui-pro/react/markdown"; const answer = [ "", "", "[Read the guide](https://docs.example/guide) or [claim a prize](https://phish.example).", ].join("\n"); // Stable functions, outside the component: a host decides what may load and what is a live link. const isImageAllowed = (src: string) => new URL(src).host === "cdn.example"; const isLinkAllowed = (href: string) => href.startsWith("https://docs.example/"); export function ImagesAndLinks() { return ({answer} ); } ``` ### In A Message ```tsx import {ChatMessage} from "@peakui-pro/react"; import {Markdown} from "@peakui-pro/react/markdown"; const reply = "Pass the **whole** answer on every update: earlier blocks stay as they are, and `code` keeps its style."; export function InAMessage() { return (); } ``` ## Customization ### Tailwind CSS ```tsx {reply} {answer} ``` ### Global CSS ```css @layer components { .markdown { --markdown-link-color: var(--color-accent); --markdown-line-height: 1.75; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The Markdown component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui-pro/blob/main/packages/styles/components/markdown.css)): #### Base Classes - `.markdown` - Root, a column of blocks #### Element Classes - `.markdown__block` - One top-level block: a heading, paragraph, list, table, quote or fence - `.markdown__inline-code` - Inline code - `.markdown__image` - A loaded image, or an inert one's alt text and host - `.markdown__image-host` - The host an inert image names - `.markdown__link-destination` - The destination a live link shows - `.markdown__link-text` - A refused link, as text A fence renders a `CodeBlock`, with its `.code-block` classes. Elements inside a block are styled by tag through `:where()`, so any class you add wins. ### Slots - `[data-slot="markdown"]` - `[data-slot="markdown-block"]` - `[data-slot="markdown-inline-code"]` - `[data-slot="markdown-image"]` - `[data-slot="markdown-link-destination"]` - `[data-slot="markdown-link-text"]` ### CSS Variables | Variable | Purpose | | --------------------------- | ---------------------------------------------------------------------- | | `--markdown-block-gap` | Space between blocks; defaults to `0.75rem` | | `--markdown-font-size` | Body text size; defaults to `var(--text-sm)` | | `--markdown-line-height` | Body line height; defaults to `1.65` | | `--markdown-heading-color` | Heading and table header colour; defaults to `var(--color-foreground)` | | `--markdown-link-color` | Link colour; defaults to `var(--color-link)` | | `--markdown-inline-code-bg` | Inline code background; defaults to `var(--color-default)` | | `--markdown-quote-border` | Quote rule colour; defaults to `var(--color-border)` | | `--markdown-table-border` | Table and rule line colour; defaults to `var(--color-separator)` | ### Interactive States - **Focus**: `:focus-visible` on a link draws the core focus ring - **Inert image**: `[data-inert="true"]` on `.markdown__image` when no image was fetched - **Forced colors**: `@media (forced-colors: active)` paints links in `LinkText` and outlines inline code ## API Reference ### Markdown | Prop | Type | Default | Description | | ---------------- | ------------------------------------------------- | ---------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `children` | `string` | `''` | The markdown source. Raw HTML in it is shown as text, never parsed; `javascript:` URLs are removed | | `isImageAllowed` | `(src: string) => boolean` | - | Whether an image may be fetched. Without it no image loads: each renders as its alt text and host. Only an http(s) image with alt text can load | | `isLinkAllowed` | `(href: string) => boolean` | absolute `http`, `https`, `mailto` | Whether a link is live. A refused link renders as text; a live one shows its host (or address) and has its URL as `title` | | `components` | `MarkdownComponents` | - | Element overrides by tag name, merged over the defaults (`pre` renders a `CodeBlock`, `code` inline code, `li` names task checkboxes, `img` and `a` apply the two policies above). An override of `img` or `a` replaces its policy. A new object on every render re-renders every block | | `id` | `string` | generated | Seed of the blocks' keys, and the root's `id` | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered `` with your own element | | `...rest` | `Omit, 'children' \| 'id'>` | - | Native ` ` attributes |# PromptInput > Message composer with attachments, toolbar and stop **Category**: components **URL**: https://peakui.pro/en/docs/react/components/prompt-input **Source**: https://raw.githubusercontent.com/peakui-dev/peakui-pro/refs/heads/main/apps/docs/content/docs/en/react/components/(ai)/prompt-input.mdx ## Usage ```tsx import {PromptInput} from "@peakui-pro/react"; ``` ```tsx "use client"; import {Paperclip} from "@gravity-ui/icons"; import {PromptInput} from "@peakui-pro/react"; import {useState} from "react"; export function Basic() { const [value, setValue] = useState(""); return ( setValue("")} onValueChange={setValue} > ); } ``` ### Anatomy ```tsx import {PromptInput} from "@peakui-pro/react"; export default () => (AI can make mistakes. Check important info. {/* Queued follow-ups, above the shell. */} ); ``` ## Examples ### Run State `status` turns send into stop while `submitted` or `streaming`; the text area goes read-only. ```tsx "use client"; import type {PromptInputStatus} from "@peakui-pro/react"; import {PromptInput} from "@peakui-pro/react"; import {useRef, useState} from "react"; export function RunState() { const [value, setValue] = useState(""); const [status, setStatus] = useState{/* Presentational grip: rows do not reorder by drag. */} Queued prompt text {/* ChatAttachment children; their remove buttons come before the text in the tab order. */} {/* Enter submits, Shift+Enter adds a line. */} ... {/* Send, or Stop while submitted or streaming. */} AI can make mistakes. Check important info. ("ready"); const timer = useRef (undefined); // Stands in for a chat request: submitted, then streaming, then ready. const send = () => { setValue(""); setStatus("submitted"); timer.current = window.setTimeout(() => { setStatus("streaming"); timer.current = window.setTimeout(() => setStatus("ready"), 3000); }, 600); }; const stop = () => { window.clearTimeout(timer.current); setStatus("ready"); }; return ( ); } ``` ### Secondary `variant="secondary"` for a composer that sits on a surface. ```tsx "use client"; import {Paperclip} from "@gravity-ui/icons"; import {PromptInput} from "@peakui-pro/react"; import {useState} from "react"; export function Secondary() { const [value, setValue] = useState(""); return ( ); } ``` ### Inline `layout="inline"` keeps the toolbars and the growing text on one row. ```tsx "use client"; import {Paperclip} from "@gravity-ui/icons"; import {PromptInput} from "@peakui-pro/react"; import {useState} from "react"; export function Inline() { const [value, setValue] = useState(""); return (setValue("")} onValueChange={setValue} > ); } ``` ### Compact `layout="compact"` starts as a pill and stacks once the text wraps or a file is attached. ```tsx "use client"; import {Paperclip} from "@gravity-ui/icons"; import {PromptInput} from "@peakui-pro/react"; import {useState} from "react"; export function Compact() { const [value, setValue] = useState(""); return (setValue("")} onValueChange={setValue} > ); } ``` ### Review Composer ```tsx "use client"; import {CodeFork, Microphone} from "@gravity-ui/icons"; import {Button} from "@peakui/react"; import {PromptInput} from "@peakui-pro/react"; import {useState} from "react"; export function ReviewComposer() { const [value, setValue] = useState(""); return (setValue("")} onValueChange={setValue} > ); } ``` ### Queue ```tsx "use client"; import {ArrowRotateLeft, Plus} from "@gravity-ui/icons"; import {PromptInput} from "@peakui-pro/react"; import {useState} from "react"; export function Queue() { const [value, setValue] = useState(""); const [queue, setQueue] = useState(["Add dark mode support to the settings page."]); return ( // While an answer streams, `allowSubmitWhileRunning` lets Enter queue the next prompt.setValue("")} onValueChange={setValue} > develop · Local · 32% of the task donesetQueue([])} onValueChange={setValue} onSubmit={(text) => { setQueue((current) => [...current, text]); setValue(""); }} > ); } ``` ### With Suggestions ```tsx "use client"; import {Microphone} from "@gravity-ui/icons"; import {PromptInput, PromptSuggestion} from "@peakui-pro/react"; import {useState} from "react"; const suggestions = [ "Build a kanban board", "Draft an onboarding checklist", "Plan a metrics dashboard", ]; export function WithSuggestions() { const [value, setValue] = useState(""); return ({queue.map((text) => ( ))} {text} setQueue((current) => current.filter((item) => item !== text))} /> ); } ``` ### With Attachments Render `PromptInput.Shell` through `ChatAttachmentInput.Dropzone` to make it the drop target. ```tsx "use client"; import {Paperclip} from "@gravity-ui/icons"; import {ChatAttachment, ChatAttachmentInput, PromptInput} from "@peakui-pro/react"; import {useState} from "react"; export function WithAttachments() { const [value, setValue] = useState(""); const [files, setFiles] = useStatesetValue("")} onValueChange={setValue}> {suggestions.map((prompt) => ( setValue(prompt)}> {prompt} ))}([]); return ( setFiles((current) => [...current, ...added])}> ); } ``` ## Customization ### Tailwind CSS ```tsxsetValue("")} onValueChange={setValue} > {/* The whole shell is the drop target; keep `props.children` for the keyboard drop button. */} {props.children} } >{files.map((file) => ( ))} setFiles((current) => current.filter((item) => item !== file))} /> ``` ### Global CSS ```css @layer components { .prompt-input { --prompt-input-radius: 1.5rem; --prompt-input-inset: 0.5rem; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The PromptInput component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui-pro/blob/main/packages/styles/components/prompt-input.css)): #### Base Classes - `.prompt-input` - Root state wrapper #### Size Classes - `.prompt-input--sm` - `.prompt-input--md` - Default, empty: the base class carries it - `.prompt-input--lg` #### Layout Classes - `.prompt-input__shell--stacked` - Default - `.prompt-input__shell--inline` - `.prompt-input__shell--compact` #### Variant Classes - `.prompt-input__shell--primary` - Default - `.prompt-input__shell--secondary` #### Element Classes - `.prompt-input__shell` - Composer surface - `.prompt-input__content` - Attachments and text area - `.prompt-input__attachments` - Attachment row, hidden while empty - `.prompt-input__textarea` - Text area, beside the core `.textarea` - `.prompt-input__toolbar` - Toolbar row - `.prompt-input__toolbar-start` - Leading toolbar actions - `.prompt-input__toolbar-end` - Trailing toolbar actions - `.prompt-input__action` - Toolbar action, beside the core `.button` - `.prompt-input__send` - Send and stop button - `.prompt-input__footer` - Disclaimer - `.prompt-input__queue` - Queued prompts card - `.prompt-input__queue-list` - Scrolling list, beside the core `.scroll-shadow` - `.prompt-input__queue-list-items` - The `ul` of queued rows - `.prompt-input__queue-item` - Queued row - `.prompt-input__queue-item-handle` - Grip, presentational - `.prompt-input__queue-item-body` - Icon and text - `.prompt-input__queue-item-icon` - Leading icon - `.prompt-input__queue-item-content` - Prompt text, clamped to two lines - `.prompt-input__queue-item-description` - Secondary text - `.prompt-input__queue-item-attachments` - Attachment previews in a row - `.prompt-input__queue-item-attachments-overflow` - Hidden attachment count - `.prompt-input__queue-item-actions` - Row actions - `.prompt-input__queue-item-remove` - Remove button - `.prompt-input__queue-item-more` - More button - `.prompt-input__queue-item-action` - Any other row action ### Slots - `[data-slot="prompt-input"]` - `[data-slot="prompt-input-shell"]` - `[data-slot="prompt-input-content"]` - `[data-slot="prompt-input-attachments"]` - `[data-slot="prompt-input-textarea"]` - `[data-slot="prompt-input-toolbar"]` - `[data-slot="prompt-input-toolbar-start"]` - `[data-slot="prompt-input-toolbar-end"]` - `[data-slot="prompt-input-action"]` - `[data-slot="prompt-input-send"]` - `[data-slot="prompt-input-footer"]` - `[data-slot="prompt-input-queue"]` - `[data-slot="prompt-input-queue-list"]` - on the `ul`; the scrolling root keeps the core's `scroll-shadow` - `[data-slot="prompt-input-queue-item"]` - `[data-slot="prompt-input-queue-item-handle"]` - `[data-slot="prompt-input-queue-item-body"]` - `[data-slot="prompt-input-queue-item-icon"]` - `[data-slot="prompt-input-queue-item-content"]` - `[data-slot="prompt-input-queue-item-description"]` - `[data-slot="prompt-input-queue-item-attachments"]` - `[data-slot="prompt-input-queue-item-attachments-overflow"]` - `[data-slot="prompt-input-queue-item-actions"]` - `[data-slot="prompt-input-queue-item-remove"]` - `[data-slot="prompt-input-queue-item-more"]` - `[data-slot="prompt-input-queue-item-action"]` ### CSS Variables | Variable | Purpose | | --------------------------------- | ------------------------------------------------------------------------------------------------ | | `--prompt-input-radius` | Shell and queue corner; defaults to `var(--radius-2xl)` | | `--prompt-input-pill-radius` | Corner of the inline and compact shell; defaults to `1.5rem` | | `--prompt-input-bg` | Shell and queue fill; defaults to `var(--color-surface)`, `var(--color-default)` for `secondary` | | `--prompt-input-inset` | Toolbar and attachment inset; defaults to `0.75rem` | | `--prompt-input-gap` | Space between queue, shell and footer; defaults to `0.5rem` | | `--prompt-input-min-height` | Text area height at rest; defaults to `3.5rem` | | `--prompt-input-pill-height` | Height of the inline and compact row; defaults to `3rem` | | `--prompt-input-toolbar-height` | Toolbar row height; follows the control size | | `--prompt-input-max-height` | Tallest text area before it scrolls; set from `maxHeight` | | `--prompt-input-queue-max-height` | Tallest queue list before it scrolls; defaults to `10rem` | ### Interactive States - **Status**: `[data-status="ready" | "submitted" | "streaming" | "error"]` on the root and on `.prompt-input__send` - **Running**: `[data-pending="true"]` on the root while `submitted` or `streaming` - **Expanded**: `[data-expanded="true"]` on a compact root once it stacks - **Disabled**: `[data-disabled="true"]` on the root - **Focus**: the shell draws the focus ring while its text area has focus - **Drop target**: `[data-drop-target]` on a shell rendered through `ChatAttachmentInput.Dropzone`, with its dashed outline - **Read-only**: `[readonly]` on the text area while a response runs - **Queue actions**: `[data-actions-visibility="hover"]` hides row actions until hover or keyboard focus in the row - **Forced colors**: the shell and the queue keep a `ButtonBorder` boundary ## API Reference ### PromptInput | Prop | Type | Default | Description | | ---------------- | -------------------------------------------------- | ----------- | -------------------------------------------------------------------------------------------------- | | `value` | `string` | internal | Controlled text | | `onValueChange` | `(value: string) => void` | - | Called when the text changes | | `onSubmit` | `(value: string) => void` | - | Called with the text when it is submitted; an uncontrolled composer then clears itself | | `onStop` | `() => void` | - | Called by the send button while `submitted` or `streaming`; without it the button is disabled then | | `status` | `'ready' \| 'submitted' \| 'streaming' \| 'error'` | `'ready'` | Run state | | `isDisabled` | `boolean` | `false` | Disables the text area and every control | | `lockInputOnRun` | `boolean` | `true` | Makes the text area read-only while `submitted` or `streaming`; focus stays in it | | `maxHeight` | `number \| string` | `240` | Tallest text area, in pixels or any CSS length; also `--prompt-input-max-height` | | `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | Composer size | | `variant` | `'primary' \| 'secondary'` | `'primary'` | Shell surface | | `layout` | `'stacked' \| 'compact' \| 'inline'` | `'stacked'` | Arrangement of the text and the toolbars | | `render` | `DOMRenderFunction ` | - | Replaces the rendered element; `E` defaults to `'div'` | | `...rest` | `ComponentProps<'div'>` | - | Native attributes | ### PromptInput.TextArea | Prop | Type | Default | Description | | ------------------------- | --------------------------------- | ----------------------------- | ------------------------------------------------------------------------------------------------ | | `disableAutosize` | `boolean` | `false` | Leaves the height to CSS instead of growing with the text | | `allowSubmitWhileRunning` | `boolean` | `false` | Lets Enter submit while a response runs, to queue follow-ups; pair with `lockInputOnRun={false}` | | `aria-label` | `string` | `'Message input'` | Accessible name | | `placeholder` | `string` | `'What do you want to know?'` | Text shown while empty | | `...rest` | `ComponentProps ` | - | Every core TextArea prop except `value` and `defaultValue`, which the root owns | ### PromptInput.Action | Prop | Type | Default | Description | | --------- | ------------- | ------- | ----------------------------------------------------------------------------------- | | `tooltip` | `ReactNode` | - | Tooltip on the button; still one tab stop | | `...rest` | `ButtonProps` | - | Core Button props; icon-only, `tertiary` and the composer's control size by default | ### PromptInput.Send | Prop | Type | Default | Description | | ------------ | ------------- | ---------------------------------- | ----------------------------------------------------------------------------- | | `aria-label` | `string` | `'Send message'` or `'Stop'` | Named for what it does in the current status | | `children` | `ReactNode` | send, spinner, stop or error glyph | Custom glyph | | `...rest` | `ButtonProps` | - | Core Button props; disabled while there is nothing to send or nothing to stop | ### PromptInput.Shell, Content, Attachments, Toolbar, ToolbarStart, ToolbarEnd | Prop | Type | Default | Description | | --------- | ------------------------------------- | ------- | ----------------------------- | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered ` ` | | `...rest` | `ComponentProps<'div'>` | - | Native attributes | ### PromptInput.Footer | Prop | Type | Default | Description | | --------- | ----------------------------------- | ------- | --------------------------- | | `render` | `DOMRenderFunction<'p', undefined>` | - | Replaces the rendered `` | | `...rest` | `ComponentProps<'p'>` | - | Native attributes | ### PromptInput.Queue | Prop | Type | Default | Description | | ------------------- | ----------------------- | --------- | ------------------------------------------------------------------------------------------------ | | `actionsVisibility` | `'always' \| 'hover'` | `'hover'` | When row actions show; `hover` also shows them on keyboard focus in the row, and always on touch | | `...rest` | `ComponentProps<'div'>` | - | Native attributes | ### PromptInput.Queue.List | Prop | Type | Default | Description | | --------- | ------------------------------------- | ------- | ----------------------- | | `...rest` | `ComponentProps
` | - | Core ScrollShadow props | ### PromptInput.Queue.Item | Prop | Type | Default | Description | | --------- | ------------------------------------ | ------- | ---------------------------- | | `render` | `DOMRenderFunction<'li', undefined>` | - | Replaces the rendered ` ` | | `...rest` | `ComponentProps<'li'>` | - | Native attributes | ### PromptInput.Queue.Item.Body, Handle, Icon, Content, Description, Attachments, Actions | Prop | Type | Default | Description | | ---------- | ---------------------------------------- | ----------------- | ---------------------------------------------------------------------- | | `children` | `ReactNode` | grip for `Handle` | Slot content; `Handle` and `Icon` are hidden from assistive technology | | `...rest` | `ComponentProps<'div' \| 'span' \| 'p'>` | - | Native attributes of the slot's element | ### PromptInput.Queue.Item.AttachmentsOverflow | Prop | Type | Default | Description | | ------------- | -------- | --------- | --------------------------------------------- | | `hiddenCount` | `number` | - | Attachments not shown, rendered as `+2 files` | | `noun` | `string` | `'files'` | Noun after the count | ### PromptInput.Queue.Item.Remove, More, Action | Prop | Type | Default | Description | | ------------ | ------------- | ------------------------------------------------ | ------------------------------------------ | | `aria-label` | `string` | `'Remove queued prompt'`, `'More queue actions'` | Default names of `Remove` and `More` | | `children` | `ReactNode` | trash, ellipsis | Custom glyph | | `...rest` | `ButtonProps` | - | Core Button props; small, ghost, icon-only | # PromptSuggestion > Suggested prompts and starter cards for chat empty states **Category**: components **URL**: https://peakui.pro/en/docs/react/components/prompt-suggestion **Source**: https://raw.githubusercontent.com/peakui-dev/peakui-pro/refs/heads/main/apps/docs/content/docs/en/react/components/(ai)/prompt-suggestion.mdx ## Usage ```tsx import {PromptSuggestion} from "@peakui-pro/react"; ``` ```tsx import {PromptSuggestion} from "@peakui-pro/react"; export function Basic() { return ( ); } ``` ### Anatomy ```tsx import {PromptSuggestion} from "@peakui-pro/react"; export default () => ( {/* `Items` is a plain div: name the set so a screen reader announces it as a group. */} What do you want to work on? Ask a question or start from one of the suggestions below. Draft a weekly project update email Summarize this meeting transcript Help me plan a product launch checklist Brainstorm names for a developer tools startup ); ``` ## Examples ### Cards `variant="card"` lays the item slots out as cards in a grid. ```tsx import {PromptSuggestion} from "@peakui-pro/react"; export function Cards() { return ( {/* A plain div: `role` and `aria-label` are yours to add. */} What can I help with? Start from a suggested prompt. Summarize this document Create a concise summary. Used 12 times this week ... About 2 minutes ); } ``` ### Cards With All Slots Compose `ItemMeta`, `ItemTags` and `ItemFooter` after the title and description. ```tsx import {Chip} from "@peakui/react"; import {PromptSuggestion} from "@peakui-pro/react"; export function CardsWithAllSlots() { return ( Starter prompts for everyday work Pick one to see what kinds of conversations this template is designed for. Weekly project update Turn rough notes into a clear weekly update. Meeting summary Capture decisions, owners, and next steps. ); } ``` ### Named Group `Items` has no group semantics by default; add `role="group"` and a label. ```tsx import {PromptSuggestion} from "@peakui-pro/react"; export function NamedGroup() { return ( Weekly project update Turn rough notes into a clear weekly update. Used 12 times this week About 2 minutes {/* A plain div by default: `role="group"` and a label turn it into a named set. */} ); } ``` ### Disabled `isDisabled` dims one suggestion and takes it out of the tab order. ```tsx import {PromptSuggestion} from "@peakui-pro/react"; export function Disabled() { return (Draft a weekly project update email Summarize this meeting transcript Help me plan a product launch checklist Write a reply to a support ticket Brainstorm names for a developer tools startup ); } ``` ### Press Handler `onPress` hands the host the chosen prompt, to send to a composer. ```tsx "use client"; import {PromptSuggestion} from "@peakui-pro/react"; import {useState} from "react"; const prompts = [ "Draft a weekly project update email", "Summarize this meeting transcript", "Help me plan a product launch checklist", ]; export function PressHandler() { const [chosen, setChosen] = useState Draft a weekly project update email Summarize this meeting transcript Help me plan a product launch checklist (null); return ( ); } ``` ## Customization ### Tailwind CSS ```tsx{prompts.map((prompt) => ( setChosen(prompt)}> {prompt} ))}{chosen ? `Chosen: ${chosen}` : "Nothing chosen yet."}
``` ### Global CSS ```css @layer components { .prompt-suggestion { --prompt-suggestion-gap: 1.5rem; --prompt-suggestion-pill-radius: var(--radius-xl); } .prompt-suggestion--card { --prompt-suggestion-card-min-width: 18rem; --prompt-suggestion-card-padding: 1.25rem; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The PromptSuggestion component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui-pro/blob/main/packages/styles/components/prompt-suggestion.css)): #### Base Classes - `.prompt-suggestion` - Root - `.prompt-suggestion--pill` - Default layout: a grid of two columns, then one - `.prompt-suggestion--card` - Card layout: a grid that adds columns as the width allows #### Element Classes - `.prompt-suggestion__header` - Title and description wrapper - `.prompt-suggestion__title` - Header title - `.prompt-suggestion__description` - Header description - `.prompt-suggestion__items` - Suggestion grid - `.prompt-suggestion__item` - One suggestion, beside the core `.button` classes - `.prompt-suggestion__item-label` - Pill text wrapper - `.prompt-suggestion__item-end-icon` - Pill chevron - `.prompt-suggestion__item-title` - Card title - `.prompt-suggestion__item-description` - Card description - `.prompt-suggestion__item-meta` - Card meta line - `.prompt-suggestion__item-tags` - Card tag row - `.prompt-suggestion__item-footer` - Card footer #### Modifier Classes - `.prompt-suggestion__items--pill`, `.prompt-suggestion__items--card` - Grid per layout - `.prompt-suggestion__item--pill`, `.prompt-suggestion__item--card` - Item per layout ### Slots - `[data-slot="prompt-suggestion"]` - `[data-slot="prompt-suggestion-header"]` - `[data-slot="prompt-suggestion-title"]` - `[data-slot="prompt-suggestion-description"]` - `[data-slot="prompt-suggestion-items"]` - `[data-slot="prompt-suggestion-item"]` - `[data-slot="prompt-suggestion-item-label"]` - `[data-slot="prompt-suggestion-item-end-icon"]` - `[data-slot="prompt-suggestion-item-title"]` - `[data-slot="prompt-suggestion-item-description"]` - `[data-slot="prompt-suggestion-item-meta"]` - `[data-slot="prompt-suggestion-item-tags"]` - `[data-slot="prompt-suggestion-item-footer"]` ### CSS Variables | Variable | Purpose | | ------------------------------------ | ----------------------------------------------------------------------- | | `--prompt-suggestion-gap` | Space between the header and the items; defaults to `2rem` | | `--prompt-suggestion-items-gap` | Space between items; defaults to `0.5rem`, `0.75rem` in the card layout | | `--prompt-suggestion-pill-min-width` | Narrowest pill column; defaults to `18rem` | | `--prompt-suggestion-pill-radius` | Pill corner radius; defaults to `var(--radius-2xl)` | | `--prompt-suggestion-card-min-width` | Narrowest card column; defaults to `14rem` | | `--prompt-suggestion-card-padding` | Card padding; defaults to `1rem` | | `--prompt-suggestion-card-radius` | Card corner radius; defaults to `var(--radius-2xl)` | ### Interactive States The item is the core button and takes its states: - **Hover**: `:hover` or `[data-hovered]` - **Pressed**: `:active` or `[data-pressed]`, scaled to `0.97` by the core button - **Focus**: `:focus-visible` or `[data-focus-visible]` - **Disabled**: `:disabled`, `[data-disabled]` or `[aria-disabled="true"]`, dimmed by the core button - **Forced colors**: `@media (forced-colors: active)` paints the chevron and the card text in `ButtonText`, so an enabled item never reads as disabled ## API Reference ### PromptSuggestion | Prop | Type | Default | Description | | ----------- | ------------------------------------- | -------- | ---------------------------------------------------------------------------------------------- | | `variant` | `'pill' \| 'card'` | `'pill'` | Layout: a grid of short prompts with a chevron, or a grid of cards that compose the item slots | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered ` Draft a weekly project update email ` with your own element | | `...rest` | `ComponentProps<'div'>` | - | Native `` attributes | ### PromptSuggestion.Header | Prop | Type | Default | Description | | ----------- | ------------------------------------- | ------- | --------------------------------------------------- | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered `` with your own element | | `...rest` | `ComponentProps<'div'>` | - | Native `` attributes | ### PromptSuggestion.Title | Prop | Type | Default | Description | | ----------- | ------------------------------------ | ------- | ---------------------------------------------------------------------- | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'h2', undefined>` | - | Replaces the rendered ``, to set the heading level your page needs | | `...rest` | `ComponentProps<'h2'>` | - | Native `
` attributes | ### PromptSuggestion.Description | Prop | Type | Default | Description | | ----------- | ----------------------------------- | ------- | ------------------------------------------------- | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'p', undefined>` | - | Replaces the rendered `
` with your own element | | `...rest` | `ComponentProps<'p'>` | - | Native `
` attributes | ### PromptSuggestion.Items | Prop | Type | Default | Description | | ----------- | ------------------------------------- | ------- | -------------------------------------------------------------------------------------- | | `className` | `string` | - | Additional classes | | `role` | `string` | - | None by default; pass `"group"` with `aria-label` so a screen reader announces the set | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered `
` with your own element | | `...rest` | `ComponentProps<'div'>` | - | Native `` attributes | ### PromptSuggestion.Item | Prop | Type | Default | Description | | ------------ | --------------------------------------------------------------------------------------------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `children` | `React.ReactNode \| (values: ButtonRenderProps) => React.ReactNode` | - | The prompt text, or the item slots in the card layout. The accessible name is the whole content, not the title alone | | `variant` | `'primary' \| 'secondary' \| 'tertiary' \| 'outline' \| 'ghost' \| 'danger' \| 'danger-soft'` | `'outline'` | Core button style, which sets only the fill and the border: the item always sets its text to the foreground colour. In `pill`, `outline`, `ghost`, `secondary`, `tertiary` and `danger-soft` work; `primary` and `danger` put that text on a solid fill, under 4.5:1 in the light theme, so do not use them. In `card`, none works: the surface fill and the surface shadow are fixed and every variant renders alike | | `isDisabled` | `boolean` | `false` | Whether the suggestion is disabled | | `onPress` | `(e: PressEvent) => void` | - | Handler called when the suggestion is pressed | | `className` | `string \| (values: ButtonRenderProps) => string` | - | Additional classes, or a function of the button's state | | `render` | `DOMRenderFunction<'button', ButtonRenderProps>` | - | Replaces the rendered element; receives the props with `data-slot` set | | `...rest` | `ButtonProps` | - | Every other core Button prop | ### PromptSuggestion.ItemTitle, ItemDescription, ItemMeta, ItemTags, ItemFooter | Prop | Type | Default | Description | | ----------- | -------------------------------------- | ------- | ------------------------------------------------------------------------------------------------ | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'span', undefined>` | - | Replaces the rendered ``; the slots are spans because a button holds phrasing content only | | `...rest` | `ComponentProps<'span'>` | - | Native `` attributes | ### Render Props | Prop | Type | Description | | ---------------- | --------- | ------------------------------------------- | | `isPending` | `boolean` | Whether the item is waiting on an operation | | `isPressed` | `boolean` | Whether the item is currently pressed | | `isHovered` | `boolean` | Whether the item is hovered | | `isFocused` | `boolean` | Whether the item is focused | | `isFocusVisible` | `boolean` | Whether the item is focused by keyboard | | `isDisabled` | `boolean` | Whether the item is disabled |# TextShimmer > Animated shimmer text for thinking and loading labels **Category**: components **URL**: https://peakui.pro/en/docs/react/components/text-shimmer **Source**: https://raw.githubusercontent.com/peakui-dev/peakui-pro/refs/heads/main/apps/docs/content/docs/en/react/components/(ai)/text-shimmer.mdx ## Usage ```tsx import {TextShimmer} from "@peakui-pro/react"; ``` ```tsx import {TextShimmer} from "@peakui-pro/react"; export function Basic() { return ( ); } ``` ## Examples ### Color Utility `className` colors both layers; raise `--text-shimmer-rest` for a color dimmer than `text-foreground`. ```tsx import {TextShimmer} from "@peakui-pro/react"; export function ColorUtility() { return (Thinking... Generating response... ); } ``` ### Long Text ```tsx import {TextShimmer} from "@peakui-pro/react"; export function LongText() { return (Thinking... Searching the web... ); } ``` ### In Sentence ```tsx import {TextShimmer} from "@peakui-pro/react"; export function InSentence() { return (Reading the attached files, comparing them against the previous quarter and drafting a summary of what changed The assistant is
); } ``` ### Custom Spread `--spread` sets how far the highlight takes to fade out on each side. ```tsx import {TextShimmer} from "@peakui-pro/react"; export function CustomSpread() { return (thinking through your question and will answer in a moment.); } ``` ## Customization ### Tailwind CSS ```tsxNarrow highlight Wide highlight Searching the web... ``` ### Global CSS ```css @layer components { .text-shimmer { --spread: 6ch; /* 60% holds 4.5:1 for the default foreground on --background only. */ --text-shimmer-rest: 70%; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The TextShimmer component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui-pro/blob/main/packages/styles/components/text-shimmer.css)): #### Base Classes - `.text-shimmer` - The root; an inline box that takes its color and size from the context #### Element Classes - `.text-shimmer__text` - The readable layer, drawn at `--text-shimmer-rest` of its color - `.text-shimmer__highlight` - An inert copy whose letters mask the sweeping gradient ### Slots - `[data-slot="text-shimmer"]` - The root element - `[data-slot="text-shimmer-text"]` - The readable layer - `[data-slot="text-shimmer-highlight"]` - The inert mask copy ### CSS Variables | Variable | Purpose | | --------------------- | ---------------------------------------------------------------------------- | | `--spread` | Width of the highlight falloff on each side of its center; defaults to `4ch` | | `--text-shimmer-rest` | Share of its color the label keeps between sweeps; defaults to `60%` | ### Interactive States The sweep is the component's only motion, and these conditions remove it: - **Reduced motion**: `@media (prefers-reduced-motion: reduce)` hides the highlight and draws the text fully opaque - **Forced colors**: `@media (forced-colors: active)` does the same, so the system palette colors a solid label - **No `mask-clip: text` support**: `@supports not ((mask-clip: text) or (-webkit-mask-clip: text))` shows solid text and no sweep ## API Reference ### TextShimmer | Prop | Type | Default | Description | | ----------- | -------------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `children` | `ReactNode` | - | The label. Rendered twice, the second copy inert and `aria-hidden`, so an `id` or an interactive element in it is duplicated | | `className` | `string` | - | Additional classes, including color and text size utilities. The contrast guarantee of 4.5:1 at the default `--text-shimmer-rest` covers the default foreground on `--background` only | | `render` | `DOMRenderFunction<'span', undefined>` | - | Replaces the rendered `` with your own element | | `...rest` | `ComponentProps<'span'>` | - | Native `` attributes |# AreaChart > Area chart with gradient fills and stacked series **Category**: components **URL**: https://peakui.pro/en/docs/react/components/area-chart **Source**: https://raw.githubusercontent.com/peakui-dev/peakui-pro/refs/heads/main/apps/docs/content/docs/en/react/components/(charts)/area-chart.mdx ## Usage `AreaChart` is imported from its own subpath and needs the optional `recharts` peer. ```bash npm install recharts ``` ```tsx import {AreaChart} from "@peakui-pro/react/area-chart"; ``` ```tsx "use client"; // the Y axis takes a tick formatter, which is a function prop import {AreaChart} from "@peakui-pro/react/area-chart"; import {MONTHS} from "./_data.ts"; export function Basic() { return ( ); } ``` ### Anatomy ```tsx import {AreaChart} from "@peakui-pro/react/area-chart"; // Only the root is this package's own; the parts are the charting library's components under // PeakUI names. The root is not exported from `@peakui-pro/react`, so an app that renders no // chart never needs the peer installed, not even to render on a server. export default () => ( `$${value / 1000}k`} width={44} /> } /> ); ``` ### Accessibility The plot takes focus and answers the arrow keys, so `aria-label` names it, not the wrapper. ```tsx // Named by a string, or by the element that already carries the metric's title. } /> ``` ## Examples ### Multi Area ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {AreaChart} from "@peakui-pro/react/area-chart"; import {MONTHS} from "./_data.ts"; export function MultiArea() { return ( ); } ``` ### Stacked One `stackId` across the series: each area sits on the one below it. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {AreaChart} from "@peakui-pro/react/area-chart"; const CHANNELS = [ {month: "Jan", organic: 15_200, paid: 8400, referral: 3100}, {month: "Feb", organic: 16_800, paid: 9100, referral: 3400}, {month: "Mar", organic: 15_900, paid: 8800, referral: 2900}, {month: "Apr", organic: 18_400, paid: 10_200, referral: 3800}, {month: "May", organic: 17_600, paid: 9800, referral: 3500}, {month: "Jun", organic: 20_100, paid: 11_400, referral: 4200}, ]; const SERIES = [ ["organic", "Organic", "var(--chart-4)"], ["paid", "Paid Ads", "var(--chart-3)"], ["referral", "Referral", "var(--chart-2)"], ] as const; export function Stacked() { return ( } /> ); } ``` ### Sparkline ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {AreaChart} from "@peakui-pro/react/area-chart"; const SPARK = [ {point: 1, value: 12}, {point: 2, value: 18}, {point: 3, value: 15}, {point: 4, value: 24}, {point: 5, value: 21}, {point: 6, value: 30}, ]; export function Sparkline() { return ( {SERIES.map(([key, , color]) => ( ))} } /> {SERIES.map(([key, name, color]) => ( ))} ); } ``` ### Custom Tooltip ```tsx "use client"; import {AreaChart} from "@peakui-pro/react/area-chart"; import {MONTHS} from "./_data.ts"; export function CustomTooltip() { return ( {/* No axis, no grid, no tooltip: a sparkline is a shape, not a plot. */} ); } ``` ## Customization ### Tailwind CSS ```tsx `${label} 2026`} valueFormatter={(value) => Number(value).toLocaleString("en-US", { currency: "USD", maximumFractionDigits: 0, style: "currency", }) } /> } /> ``` ### Global CSS ```css @layer components { .chart { --chart-axis-size: 11px; --chart-grid-opacity: 0.4; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The AreaChart component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui-pro/blob/main/packages/styles/components/area-chart.css)): #### Base Classes - `.chart` - The block every chart carries; axis type, grid, tooltip cursor and active dot - `.area-chart` - This chart's own block; the rounded joins of a series line ### Slots - `[data-slot="area-chart"]` - The root element ### CSS Variables | Variable | Purpose | | ------------------------- | --------------------------------------------------------- | | `--chart-axis-size` | Type size of the axis labels; set on `.chart` | | `--chart-grid-opacity` | How far the grid recedes behind the data; set on `.chart` | | `--chart-1` … `--chart-5` | The series ramp, derived from the theme's accent | ## API Reference ### AreaChart | Prop | Type | Default | Description | | ----------------- | ---------------------------------------------------------------- | ---------------------------------------- | ----------------------------------------------------------------------------------------- | | `data` | `Record []` | - | **Required.** One object per point on the x axis; a `null` field is a missing observation | | `height` | ``number \| `${number}%` `` | `300` | Height of the plot | | `width` | ``number \| `${number}%` `` | `'100%'` | Width of the plot | | `margin` | `{top?: number; right?: number; bottom?: number; left?: number}` | `{top: 8, right: 8, bottom: 0, left: 0}` | Space between the plot and the root's edges | | `children` | `ReactNode` | - | The chart's parts | | `aria-label` | `string` | - | Names the plot, which is what takes focus — not the wrapping ` ` | | `aria-labelledby` | `string` | - | Names the plot by another element's `id` | | `className` | `string` | - | Additional classes | | `...rest` | `ComponentProps<'div'>` | - | Native `` attributes, on the wrapper | ### AreaChart.Area The charting library's `Area`, re-exported. See the [Recharts Area API](https://recharts.github.io/en-US/api/Area/). ### AreaChart.XAxis The charting library's `XAxis`, re-exported. See the [Recharts XAxis API](https://recharts.github.io/en-US/api/XAxis/). ### AreaChart.YAxis The charting library's `YAxis`, re-exported. See the [Recharts YAxis API](https://recharts.github.io/en-US/api/YAxis/). ### AreaChart.Grid The charting library's `CartesianGrid`, re-exported. See the [Recharts CartesianGrid API](https://recharts.github.io/en-US/api/CartesianGrid/). ### AreaChart.Tooltip The charting library's `Tooltip`, re-exported. See the [Recharts Tooltip API](https://recharts.github.io/en-US/api/Tooltip/). ### AreaChart.TooltipContent `ChartTooltip.Content`, for the `content` prop of `AreaChart.Tooltip`. Its props are on the [ChartTooltip page](https://peakui.dev/docs/react/components/chart-tooltip).# BarChart > Bar chart with grouped, stacked and horizontal layouts **Category**: components **URL**: https://peakui.pro/en/docs/react/components/bar-chart **Source**: https://raw.githubusercontent.com/peakui-dev/peakui-pro/refs/heads/main/apps/docs/content/docs/en/react/components/(charts)/bar-chart.mdx ## Usage `BarChart` is imported from its own subpath and needs the optional `recharts` peer. ```bash npm install recharts ``` ```tsx import {BarChart} from "@peakui-pro/react/bar-chart"; ``` ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {BarChart} from "@peakui-pro/react/bar-chart"; import {MONTHS, compact} from "./_data.ts"; export function Basic() { return ( ); } ``` ### Anatomy ```tsx import {BarChart} from "@peakui-pro/react/bar-chart"; // Only the root is this package's own; the parts are the charting library's components under // PeakUI names. The root is not exported from `@peakui-pro/react`, so an app that renders no // chart never needs the peer installed, not even to render on a server. export default () => ( } /> ); ``` ### Accessibility The plot takes focus and answers the arrow keys, so `aria-label` names it, not the wrapper. A bar is told apart by colour and by its position, so give each series a `name` the tooltip can print, and keep a gap between grouped bars. ```tsx // Named by a string, or by the element that already carries the metric's title. } /> // A chart that only repeats a figure printed beside it leaves the keyboard layer out. ``` ## Examples ### Grouped Two series side by side in each category: no `stackId`, so every bar starts at the baseline. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {BarChart} from "@peakui-pro/react/bar-chart"; import {MONTHS, compact} from "./_data.ts"; export function Grouped() { return ( ); } ``` ### Stacked One `stackId` across the series: each bar sits on the one below it, and the column is the total. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {BarChart} from "@peakui-pro/react/bar-chart"; import {compact} from "./_data.ts"; const CHANNELS = [ {direct: 1200, month: "Jan", organic: 15_200, paid: 8400}, {direct: 1400, month: "Feb", organic: 16_800, paid: 9100}, {direct: 1100, month: "Mar", organic: 15_900, paid: 8800}, {direct: 1800, month: "Apr", organic: 18_400, paid: 10_200}, {direct: 1600, month: "May", organic: 17_600, paid: 9800}, {direct: 2100, month: "Jun", organic: 20_100, paid: 11_400}, ]; export function Stacked() { return ( } /> ); } ``` ### Horizontal `layout="vertical"` swaps the axes: the categories run down the y axis and the bars run along x. The x axis then takes `type="number"` and the y axis `type="category"`. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {BarChart} from "@peakui-pro/react/bar-chart"; import {REGIONS, compact} from "./_data.ts"; export function Horizontal() { return ( } /> {/* One stackId across the series: each bar sits on the one below it. */} ); } ``` ### Horizontal Stacked ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {BarChart} from "@peakui-pro/react/bar-chart"; import {REGIONS, compact} from "./_data.ts"; export function HorizontalStacked() { return ( } /> ); } ``` ### Comparison ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {BarChart} from "@peakui-pro/react/bar-chart"; import {REGIONS, compact} from "./_data.ts"; export function Comparison() { return ( } /> ); } ``` ### KPI With Bar Chart `KPI.Chart` renders an area. A bar chart is composed by hand beside the KPI parts. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {BarChart} from "@peakui-pro/react/bar-chart"; import {KPI} from "@peakui-pro/react/kpi"; import {MONTHS} from "./_data.ts"; /* `KPI.Chart` renders an area; a bar is composed by hand beside the KPI parts. */ export function KPIWithBarChart() { return ( } /> ); } ``` ### Custom Tooltip ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {BarChart} from "@peakui-pro/react/bar-chart"; import {MONTHS} from "./_data.ts"; export function CustomTooltip() { return ( Total Revenue +3.3% ); } ``` ## Customization ### Tailwind CSS ```tsx `${label} 2026`} valueFormatter={(value) => Number(value).toLocaleString("en-US", { currency: "USD", maximumFractionDigits: 0, style: "currency", }) } /> } /> ``` ### Global CSS ```css @layer components { .chart { --chart-axis-size: 11px; --chart-grid-opacity: 0.4; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The BarChart component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui-pro/blob/main/packages/styles/components/bar-chart.css)): #### Base Classes - `.chart` - The block every cartesian chart carries; axis type, grid, tooltip cursor and dots - `.bar-chart` - This chart's own block ### Slots - `[data-slot="bar-chart"]` - The root element ### CSS Variables | Variable | Purpose | | ------------------------- | --------------------------------------------------------- | | `--chart-axis-size` | Type size of the axis labels; set on `.chart` | | `--chart-grid-opacity` | How far the grid recedes behind the data; set on `.chart` | | `--chart-1` … `--chart-5` | The series ramp, derived from the theme's accent | ## API Reference ### BarChart | Prop | Type | Default | Description | | -------------------- | ---------------------------------------------------------------- | ---------------------------------------- | ------------------------------------------------------------------------------ | | `data` | `Record []` | - | **Required.** One object per category; a `null` field is a missing observation | | `height` | ``number \| `${number}%` `` | `300` | Height of the plot | | `width` | ``number \| `${number}%` `` | `'100%'` | Width of the plot | | `margin` | `{top?: number; right?: number; bottom?: number; left?: number}` | `{top: 8, right: 8, bottom: 0, left: 0}` | Space between the plot and the root's edges | | `layout` | `'horizontal' \| 'vertical'` | `'horizontal'` | `'horizontal'` stands the bars on the x axis; `'vertical'` lays them along it | | `accessibilityLayer` | `boolean` | `true` | Whether the plot is focusable and answers the arrow keys | | `children` | `ReactNode` | - | The chart's parts | | `aria-label` | `string` | - | Names the plot, which is what takes focus — not the wrapping ` ` | | `aria-labelledby` | `string` | - | Names the plot by another element's `id` | | `className` | `string` | - | Additional classes | | `...rest` | `ComponentProps<'div'>` | - | Native `` attributes, on the wrapper | ### BarChart.Bar The charting library's `Bar`, re-exported. See the [Recharts Bar API](https://recharts.github.io/en-US/api/Bar/). ### BarChart.XAxis The charting library's `XAxis`, re-exported. See the [Recharts XAxis API](https://recharts.github.io/en-US/api/XAxis/). ### BarChart.YAxis The charting library's `YAxis`, re-exported. See the [Recharts YAxis API](https://recharts.github.io/en-US/api/YAxis/). ### BarChart.Grid The charting library's `CartesianGrid`, re-exported. See the [Recharts CartesianGrid API](https://recharts.github.io/en-US/api/CartesianGrid/). ### BarChart.Tooltip The charting library's `Tooltip`, re-exported. See the [Recharts Tooltip API](https://recharts.github.io/en-US/api/Tooltip/). ### BarChart.TooltipContent `ChartTooltip.Content`, for the `content` prop of `BarChart.Tooltip`. Its props are on the [ChartTooltip page](https://peakui.dev/docs/react/components/chart-tooltip).# ChartTooltip > Tooltip card for a chart data point **Category**: components **URL**: https://peakui.pro/en/docs/react/components/chart-tooltip **Source**: https://raw.githubusercontent.com/peakui-dev/peakui-pro/refs/heads/main/apps/docs/content/docs/en/react/components/(charts)/chart-tooltip.mdx ## Usage ```tsx import {ChartTooltip} from "@peakui-pro/react"; ``` ```tsx import {ChartTooltip} from "@peakui-pro/react"; export function Basic() { return ( ); } ``` ### Anatomy ```tsx import {ChartTooltip} from "@peakui-pro/react"; // The card imports nothing from a chart library, so it ships from the package root. // `Content` is the adapter a chart passes as its tooltip's `content`; the parts below // stay usable on their own. export default () => ( January Revenue $12,400 Expenses $8,200 ); ``` ## Examples ### Line Indicator `indicator` is set on the root and reaches every indicator in the card. ```tsx import {ChartTooltip} from "@peakui-pro/react"; export function LineIndicator() { return ( ); } ``` ### No Header ```tsx import {ChartTooltip} from "@peakui-pro/react"; export function NoHeader() { return ( March 2026 Organic 15,200 Paid Ads 8,400 ); } ``` ### Chart Colors `--chart-1` to `--chart-5` are derived from the theme's accent, darkest to lightest. ```tsx import {ChartTooltip} from "@peakui-pro/react"; const RAMP = [ ["chart-1", "Darkest"], ["chart-2", "Dark"], ["chart-3", "Accent"], ["chart-4", "Light"], ["chart-5", "Lightest"], ] as const; export function ChartColors() { return ( Sales 458 ); } ``` ### Auto Content `ChartTooltip.Content` turns a chart's payload into the card. ```tsx import {ChartTooltip} from "@peakui-pro/react"; const PAYLOAD = [ {color: "var(--chart-3)", dataKey: "revenue", name: "Revenue", value: 18_200}, {color: "var(--chart-1)", dataKey: "expenses", name: "Expenses", value: 9800}, ]; export function AutoContent() { return ( All Chart Colors {RAMP.map(([token, name]) => ())} {token} {name} ); } ``` ### Custom Formatters ```tsx "use client"; import {ChartTooltip} from "@peakui-pro/react"; const PAYLOAD = [ {color: "var(--chart-3)", dataKey: "portfolio", name: "Portfolio", value: 24_801.32}, {color: "var(--chart-1)", dataKey: "benchmark", name: "Benchmark", value: 21_500}, ]; export function CustomFormatters() { return (new Date(String(label)).toLocaleDateString("en-US", { day: "numeric", month: "long", timeZone: "UTC", year: "numeric", }) } valueFormatter={(value) => Number(value).toLocaleString("en-US", {currency: "USD", style: "currency"}) } /> ); } ``` ### Inactive ```tsx import {ChartTooltip} from "@peakui-pro/react"; export function Inactive() { return ( ); } ``` ## Customization ### Tailwind CSS ```tsxAn inactive tooltip renders nothing at all.
Never shown ... ``` ### Global CSS ```css @layer components { .chart-tooltip { --chart-tooltip-gap: calc(var(--spacing) * 2); --chart-tooltip-indicator-size: calc(var(--spacing) * 2.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 ChartTooltip component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui-pro/blob/main/packages/styles/components/chart-tooltip.css)): #### Base Classes - `.chart-tooltip` - The card; a column on the surface colour, with the surface shadow #### Element Classes - `.chart-tooltip__header` - The hovered point's own label - `.chart-tooltip__item` - One series row - `.chart-tooltip__label` - The series name; takes the slack so every value ends on one edge - `.chart-tooltip__value` - The series value; tabular numerals #### Indicator Classes - `.chart-tooltip__indicator` - The colour marker; its colour is written inline from the series - `.chart-tooltip__indicator--dot` - A round dot - `.chart-tooltip__indicator--line` - A segment of the series line, stood on end ### Slots - `[data-slot="chart-tooltip"]` - The card - `[data-slot="chart-tooltip-header"]` - The header - `[data-slot="chart-tooltip-item"]` - A series row - `[data-slot="chart-tooltip-indicator"]` - The colour marker - `[data-slot="chart-tooltip-label"]` - The series name - `[data-slot="chart-tooltip-value"]` - The series value ### CSS Variables | Variable | Purpose | | -------------------------------- | -------------------------------------------------------------- | | `--chart-tooltip-gap` | Space between the header and the rows, and between rows | | `--chart-tooltip-indicator-size` | The dot's box; the line is half as wide and half again as tall | ## API Reference ### ChartTooltip | Prop | Type | Default | Description | | ----------- | ------------------------------------- | ------- | ------------------------------------------------------------------ | | `active` | `boolean` | `true` | Whether the card is shown. `false` renders nothing | | `indicator` | `'dot' \| 'line'` | `'dot'` | Shape of the colour marker; shared with every part through context | | `children` | `ReactNode` | - | The parts | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered `` with your own element | | `...rest` | `ComponentProps<'div'>` | - | Native `` attributes | ### ChartTooltip.Content | Prop | Type | Default | Description | | ---------------- | ---------------------------------------- | ------- | ----------------------------------------------------------------------- | | `active` | `boolean` | - | The chart passes this: whether the pointer is over a point | | `label` | `string \| number` | - | The chart passes this: the hovered point's label | | `payload` | `readonly ChartTooltipPayloadEntry[]` | - | The chart passes this: one entry per series at the hovered point | | `hideHeader` | `boolean` | `false` | Leaves out the label row | | `indicator` | `'dot' \| 'line'` | `'dot'` | Shape of the colour marker | | `labelFormatter` | `(label: string \| number) => ReactNode` | - | Formats the header's label | | `valueFormatter` | `(value: string \| number) => ReactNode` | - | Formats each value; a range series is formatted end by end, then joined | ### ChartTooltip.Header | Prop | Type | Default | Description | | ----------- | ------------------------------------- | ------- | --------------------------------------------------- | | `children` | `ReactNode` | - | The hovered point's label | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered `` with your own element | | `...rest` | `ComponentProps<'div'>` | - | Native `` attributes | ### ChartTooltip.Item | Prop | Type | Default | Description | | ----------- | ------------------------------------- | ------- | --------------------------------------------------- | | `children` | `ReactNode` | - | Typically an indicator, a label and a value | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered `` with your own element | | `...rest` | `ComponentProps<'div'>` | - | Native `` attributes | ### ChartTooltip.Indicator | Prop | Type | Default | Description | | ----------- | -------------------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------- | | `color` | `string` | - | The series' colour, written as the element's inline background. Any CSS colour, including a `var()` from the chart ramp | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'span', undefined>` | - | Replaces the rendered `` with your own element | | `...rest` | `ComponentProps<'span'>` | - | Native `` attributes; a `style` of your own wins over `color` | ### ChartTooltip.Label | Prop | Type | Default | Description | | ----------- | -------------------------------------- | ------- | ---------------------------------------------------- | | `children` | `ReactNode` | - | The series name | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'span', undefined>` | - | Replaces the rendered `` with your own element | | `...rest` | `ComponentProps<'span'>` | - | Native `` attributes | ### ChartTooltip.Value | Prop | Type | Default | Description | | ----------- | -------------------------------------- | ------- | ---------------------------------------------------- | | `children` | `ReactNode` | - | The series value | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'span', undefined>` | - | Replaces the rendered `` with your own element | | `...rest` | `ComponentProps<'span'>` | - | Native `` attributes | ### ChartTooltipPayloadEntry | Field | Type | Description | | --------- | --------------------------------------------------- | --------------------------------------------------- | | `name` | `string \| number` | The series name; the card falls back to `dataKey` | | `value` | `string \| number \| readonly (string \| number)[]` | The value at the hovered point; an array is a range | | `color` | `string` | The series colour | | `dataKey` | `string \| number` | The field the series reads | | `payload` | `unknown` | The whole data point the entry came from |# ComposedChart > Bars, lines and areas on one plot, with a second axis for a measure of another unit **Category**: components **URL**: https://peakui.pro/en/docs/react/components/composed-chart **Source**: https://raw.githubusercontent.com/peakui-dev/peakui-pro/refs/heads/main/apps/docs/content/docs/en/react/components/(charts)/composed-chart.mdx ## Usage `ComposedChart` is imported from its own subpath and needs the optional `recharts` peer. ```bash npm install recharts ``` ```tsx import {ComposedChart} from "@peakui-pro/react/composed-chart"; ``` ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {ComposedChart} from "@peakui-pro/react/composed-chart"; import {REVENUE_AND_ORDERS, dollars} from "./_data.ts"; /* Bars for a quantity and a line for the count beside it, each on its own axis. */ export function Basic() { return ( ); } ``` ### Anatomy ```tsx import {ComposedChart} from "@peakui-pro/react/composed-chart"; // Only the root is this package's own; the parts are the charting library's components under // PeakUI names. The root is not exported from `@peakui-pro/react`, so an app that renders no // chart never needs the peer installed, not even to render on a server. export default () => ( } /> ); ``` ### Two axes A measure in another unit (a rate beside a count) gets its own `YAxis`. Give each axis a `yAxisId` and point every series at one with the same `yAxisId`; a series with no id uses the first axis. ### Series order Series are drawn in the order they are written, so a later series sits on top of an earlier one. Write the area first, then the bars, then the line, and the line stays readable over both. ### Missing observations A `null` field in `data` is a gap: a line or an area breaks at that category instead of falling to zero. Set `connectNulls` on the series to draw across it. ### Accessibility The plot takes focus and answers the arrow keys, so `aria-label` names it, not the wrapper. Series are told apart by colour; when two must still read without it, dash a line with `strokeDasharray` (see Area With Line) and give every series a `name` the tooltip can print. ```tsx // Named by a string, or by the element that already carries the metric's title. } /> // A chart that only repeats a figure printed beside it leaves the keyboard layer out. ``` ## Examples ### Stacked Bar With Line One `stackId` across the bars stacks them; the line is a share of the column and sits on the right-hand axis, fixed to `domain={[0, 100]}`. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {ComposedChart} from "@peakui-pro/react/composed-chart"; import {COMMITS, compact, percent} from "./_data.ts"; /* One `stackId` across the bars; the line is the share of the column, on the right-hand axis. */ export function StackedBarWithLine() { return ( ); } ``` ### Area With Line An area carries the measure and a dashed line the target it is held against. The fill is a gradient defined in the chart's ` } /> `. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {ComposedChart} from "@peakui-pro/react/composed-chart"; import {SESSIONS, compact} from "./_data.ts"; /* An area carries the measure, a dashed line the target it is held against. */ export function AreaWithLine() { return ( ); } ``` ### Bar With Area ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {ComposedChart} from "@peakui-pro/react/composed-chart"; import {IMPRESSIONS, compact, percent} from "./_data.ts"; /* Bars for the count, an area under the rate on the right-hand axis. */ export function BarWithArea() { return ( } /> ); } ``` ### Multi Type All three kinds on one plot: the area and the bars read the left axis, the line the right. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {ComposedChart} from "@peakui-pro/react/composed-chart"; import {ANALYTICS, compact, percent} from "./_data.ts"; /* All three kinds on one plot: an area, a bar and a line with dots, on two axes. */ export function MultiType() { return ( } /> ); } ``` ## Customization ### Tailwind CSS ```tsx } /> ``` ### Global CSS ```css @layer components { .chart { --chart-axis-size: 11px; --chart-grid-opacity: 0.4; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The ComposedChart component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui-pro/blob/main/packages/styles/components/composed-chart.css)): #### Base Classes - `.chart` - The block every cartesian chart carries; axis type, grid, tooltip cursor and dots - `.composed-chart` - This chart's own block; gives the root its width ### Slots - `[data-slot="composed-chart"]` - The root element ### CSS Variables | Variable | Purpose | | ------------------------- | --------------------------------------------------------- | | `--chart-axis-size` | Type size of the axis labels; set on `.chart` | | `--chart-grid-opacity` | How far the grid recedes behind the data; set on `.chart` | | `--chart-1` … `--chart-5` | The series ramp, derived from the theme's accent | ## API Reference ### ComposedChart | Prop | Type | Default | Description | | -------------------- | ---------------------------------------------------------------- | ---------------------------------------- | ------------------------------------------------------------------------------ | | `data` | `Record []` | - | **Required.** One object per category; a `null` field is a missing observation | | `height` | ``number \| `${number}%` `` | `300` | Height of the plot | | `width` | ``number \| `${number}%` `` | `'100%'` | Width of the plot | | `margin` | `{top?: number; right?: number; bottom?: number; left?: number}` | `{top: 8, right: 8, bottom: 0, left: 0}` | Space between the plot and the root's edges | | `accessibilityLayer` | `boolean` | `true` | Whether the plot is focusable and answers the arrow keys | | `children` | `ReactNode` | - | The chart's parts | | `aria-label` | `string` | - | Names the plot, which is what takes focus — not the wrapping ` ` | | `aria-labelledby` | `string` | - | Names the plot by another element's `id` | | `className` | `string` | - | Additional classes | | `...rest` | `ComponentProps<'div'>` | - | Native `` attributes, on the wrapper | ### ComposedChart.Bar The charting library's `Bar`, re-exported. See the [Recharts Bar API](https://recharts.github.io/en-US/api/Bar/). ### ComposedChart.Line The charting library's `Line`, re-exported. See the [Recharts Line API](https://recharts.github.io/en-US/api/Line/). ### ComposedChart.Area The charting library's `Area`, re-exported. See the [Recharts Area API](https://recharts.github.io/en-US/api/Area/). ### ComposedChart.XAxis The charting library's `XAxis`, re-exported. See the [Recharts XAxis API](https://recharts.github.io/en-US/api/XAxis/). ### ComposedChart.YAxis The charting library's `YAxis`, re-exported. See the [Recharts YAxis API](https://recharts.github.io/en-US/api/YAxis/). ### ComposedChart.Grid The charting library's `CartesianGrid`, re-exported. See the [Recharts CartesianGrid API](https://recharts.github.io/en-US/api/CartesianGrid/). ### ComposedChart.Tooltip The charting library's `Tooltip`, re-exported. See the [Recharts Tooltip API](https://recharts.github.io/en-US/api/Tooltip/). ### ComposedChart.TooltipContent `ChartTooltip.Content`, for the `content` prop of `ComposedChart.Tooltip`. Its props are on the [ChartTooltip page](https://peakui.dev/docs/react/components/chart-tooltip).# LineChart > Line chart with several series, dots, dashed comparisons and gaps for missing data **Category**: components **URL**: https://peakui.pro/en/docs/react/components/line-chart **Source**: https://raw.githubusercontent.com/peakui-dev/peakui-pro/refs/heads/main/apps/docs/content/docs/en/react/components/(charts)/line-chart.mdx ## Usage `LineChart` is imported from its own subpath and needs the optional `recharts` peer. ```bash npm install recharts ``` ```tsx import {LineChart} from "@peakui-pro/react/line-chart"; ``` Two series on one plot, with a straight line between observations (`type="linear"`). ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {LineChart} from "@peakui-pro/react/line-chart"; import {SESSIONS, thousands} from "./_data.ts"; export function Basic() { return ( ); } ``` ### Anatomy ```tsx import {LineChart} from "@peakui-pro/react/line-chart"; // Only the root is this package's own; the parts are the charting library's components under // PeakUI names. The root is not exported from `@peakui-pro/react`, so an app that renders no // chart never needs the peer installed, not even to render on a server. export default () => ( } /> ); ``` ### Missing observations A `null` field in `data` is a gap: the line breaks at that category instead of falling to zero. Set `connectNulls` on the `Line` to draw across it instead. ```tsx const data = [ {month: "Jun", revenue: 8400}, {month: "Jul", revenue: null}, // no report this month {month: "Aug", revenue: 9200}, ]; ``` ### Accessibility The plot takes focus and answers the arrow keys, so `aria-label` names it, not the wrapper. Series are told apart by colour; when two lines must still read without it, dash one of them with `strokeDasharray` (see Dashed Comparison) and give every series a `name` the tooltip can print. ```tsx // Named by a string, or by the element that already carries the metric's title. } /> // A sparkline that only repeats a figure printed beside it leaves the keyboard layer out. ``` ## Examples ### Portfolio The range control swaps `data`; the chart is the same element throughout. A hidden `YAxis` with `domain={["dataMin", "dataMax"]}` lets the line fill the plot. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {SegmentedControl} from "@peakui/react"; import {LineChart} from "@peakui-pro/react/line-chart"; import {useState} from "react"; import {RANGES} from "./_data.ts"; type Range = keyof typeof RANGES; /* The range switch swaps `data`; the chart is the same element throughout. */ export function Portfolio() { const [range, setRange] = useState ("1M"); const data = RANGES[range].map((value, step) => ({step, value})); return ( ); } ``` ### KPI With Chart `KPI.Chart` renders an area. A line is composed by hand in the right column of `KPI.Content`, where it keeps its own box and never pushes the figure. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {TrendChip} from "@peakui-pro/react"; import {KPI} from "@peakui-pro/react/kpi"; import {LineChart} from "@peakui-pro/react/line-chart"; import {SPARK} from "./_data.ts"; /* * `KPI.Chart` renders an area. A line is composed by hand in the content's right column, where it * keeps its own box and never pushes the figure. */ export function KPIWithChart() { return (setRange(key as Range)} > {Object.keys(RANGES).map((key) => ( {key} ))}$24,801.32"Balance"} />} /> ); } ``` ### Stats With Chart ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {TrendChip} from "@peakui-pro/react"; import {LineChart} from "@peakui-pro/react/line-chart"; import {REVENUE, compact} from "./_data.ts"; /* Figure cards over one chart: the cards state totals, the plot shows how they got there. */ export function StatsWithChart() { return ( Total Revenue 3.3% last 30d ); } ``` ### Multi Line Chart Colors Series colours are the consumer's: `var(--chart-1)` to `var(--chart-5)`. There is no colour prop. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {LineChart} from "@peakui-pro/react/line-chart"; import {CHANNELS, thousands} from "./_data.ts"; /* Four series on one ramp: `--chart-1` to `--chart-4`, lightest to darkest. */ const SERIES = [ ["organic", "Organic", "var(--chart-4)"], ["paid", "Paid Ads", "var(--chart-3)"], ["referral", "Referral", "var(--chart-2)"], ["direct", "Direct", "var(--chart-1)"], ] as const; export function MultiLineChartColors() { return ({( [ ["Revenue", "$228,441", "+3.3%", "up"], ["Expenses", "$25,108", "-3.3%", "down"], ["Sales", "458", "+3.3%", "up"], ] as const ).map(([title, value, change, trend]) => ({title}))}{value}{change} } /> ); } ``` ### Sparkline No axis, no grid, no tooltip, and a height that fits beside a figure. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {LineChart} from "@peakui-pro/react/line-chart"; import {SPARK} from "./_data.ts"; /* A shape, not a plot: no axis, no grid, no tooltip, and a height that fits beside a figure. */ export function Sparkline() { return ( } /> {SERIES.map(([key, name, color]) => ( ))} {( [ ["Revenue", "var(--color-success)", false], ["Churn", "var(--color-danger)", true], ["Users", "var(--chart-3)", false], ] as const ).map(([label, color, reverse]) => (); } ``` ### Custom Tooltip ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {LineChart} from "@peakui-pro/react/line-chart"; import {SESSIONS, thousands} from "./_data.ts"; /* The same card the chart renders by default, given a formatter and the line indicator. */ export function CustomTooltip() { return ({label}))}); } ``` ### With Dots A dot on every observation. The shared stylesheet outlines it in the surface colour and leaves the fill to you, so pass the series colour in `dot`. The gap in July is a `null` field. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {LineChart} from "@peakui-pro/react/line-chart"; import {REVENUE_WITH_GAP, compact} from "./_data.ts"; /* * A dot on every observation, filled in the series colour: the shared stylesheet outlines it in the * surface and leaves the fill to the caller. The July field is `null`, so the line breaks there. */ export function WithDots() { return ( `${label} 2026`} valueFormatter={(value) => `${Number(value).toLocaleString("en-US")} sessions`} /> } /> ); } ``` ### Dashed Comparison `strokeDasharray` turns the second series into a pattern, which still separates it from the first when colour is not available. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {LineChart} from "@peakui-pro/react/line-chart"; import {REVENUE, compact} from "./_data.ts"; /* The second series is dashed: a pattern, so it still reads when colour is not available. */ export function DashedComparison() { return ( } /> ); } ``` ## Customization ### Tailwind CSS ```tsx } /> ``` ### Global CSS ```css @layer components { .chart { --chart-axis-size: 11px; --chart-grid-opacity: 0.4; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The LineChart component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui-pro/blob/main/packages/styles/components/line-chart.css)): #### Base Classes - `.chart` - The block every cartesian chart carries; axis type, grid, tooltip cursor and dots - `.line-chart` - This chart's own block; gives a series line round joins and ends ### Slots - `[data-slot="line-chart"]` - The root element ### CSS Variables | Variable | Purpose | | ------------------------- | --------------------------------------------------------- | | `--chart-axis-size` | Type size of the axis labels; set on `.chart` | | `--chart-grid-opacity` | How far the grid recedes behind the data; set on `.chart` | | `--chart-1` … `--chart-5` | The series ramp, derived from the theme's accent | ## API Reference ### LineChart | Prop | Type | Default | Description | | -------------------- | ---------------------------------------------------------------- | ---------------------------------------- | ------------------------------------------------------------------------------ | | `data` | `Record []` | - | **Required.** One object per category; a `null` field is a missing observation | | `height` | ``number \| `${number}%` `` | `300` | Height of the plot | | `width` | ``number \| `${number}%` `` | `'100%'` | Width of the plot | | `margin` | `{top?: number; right?: number; bottom?: number; left?: number}` | `{top: 8, right: 8, bottom: 0, left: 0}` | Space between the plot and the root's edges | | `accessibilityLayer` | `boolean` | `true` | Whether the plot is focusable and answers the arrow keys | | `children` | `ReactNode` | - | The chart's parts | | `aria-label` | `string` | - | Names the plot, which is what takes focus — not the wrapping ` ` | | `aria-labelledby` | `string` | - | Names the plot by another element's `id` | | `className` | `string` | - | Additional classes | | `...rest` | `ComponentProps<'div'>` | - | Native `` attributes, on the wrapper | ### LineChart.Line The charting library's `Line`, re-exported. See the [Recharts Line API](https://recharts.github.io/en-US/api/Line/). ### LineChart.XAxis The charting library's `XAxis`, re-exported. See the [Recharts XAxis API](https://recharts.github.io/en-US/api/XAxis/). ### LineChart.YAxis The charting library's `YAxis`, re-exported. See the [Recharts YAxis API](https://recharts.github.io/en-US/api/YAxis/). ### LineChart.Grid The charting library's `CartesianGrid`, re-exported. See the [Recharts CartesianGrid API](https://recharts.github.io/en-US/api/CartesianGrid/). ### LineChart.Tooltip The charting library's `Tooltip`, re-exported. See the [Recharts Tooltip API](https://recharts.github.io/en-US/api/Tooltip/). ### LineChart.TooltipContent `ChartTooltip.Content`, for the `content` prop of `LineChart.Tooltip`. Its props are on the [ChartTooltip page](https://peakui.dev/docs/react/components/chart-tooltip).# PieChart > A whole shared out as sectors, as a donut, or as nested rings **Category**: components **URL**: https://peakui.pro/en/docs/react/components/pie-chart **Source**: https://raw.githubusercontent.com/peakui-dev/peakui-pro/refs/heads/main/apps/docs/content/docs/en/react/components/(charts)/pie-chart.mdx ## Usage `PieChart` is imported from its own subpath and needs the optional `recharts` peer. ```bash npm install recharts ``` ```tsx import {PieChart} from "@peakui-pro/react/pie-chart"; ``` ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {PieChart} from "@peakui-pro/react/pie-chart"; import {BROWSERS} from "./_data.ts"; /* A whole shared out: the data belongs to the `Pie`, one `Cell` colours each sector. */ export function Basic() { return ( ); } ``` ### Anatomy ```tsx import {PieChart} from "@peakui-pro/react/pie-chart"; // Only the root is this package's own; the parts are the charting library's components under // PeakUI names. The root is not exported from `@peakui-pro/react`, so an app that renders no // chart never needs the peer installed, not even to render on a server. export default () => (} /> {BROWSERS.map((row) => ( ))} ); ``` ### Data belongs to the Pie `PieChart` takes no `data`. Each `Pie` has its own, which is what lets one chart hold two rings (see Nested Donut). Name the field that holds the value with `dataKey` and the one that holds the slice's name with `nameKey`; the tooltip prints both. ### Colouring sectors Give each sector its colour with a `Cell`, or put a `fill` on every row of the data and map it to a `Cell`. Use the series ramp `var(--chart-2)` … `var(--chart-5)`. `--chart-1` is the darkest step and nearly vanishes on a dark surface. A sector is a large shape the reader has to find, so the examples on this page start at `--chart-5` and work down. ### Separating sectors Sectors are drawn with no outline. The gap between two is `paddingAngle`, in degrees, which stays the colour of whatever sits behind the chart. `cornerRadius` rounds each sector's ends. ### A hole Set `innerRadius` on the `Pie` to turn the pie into a donut. Whatever you want in the hole goes in one of two places: a `PieChart.Label` inside the `Pie`, drawn in the plot's own coordinates, or any React node laid over the chart (see Donut With Content). ### Zero and empty data A `Pie` whose values sum to zero, or whose `data` is empty, draws no sector and does not throw. Show your own empty state beside it. ### Accessibility The plot takes focus and answers the arrow keys, so `aria-label` names it, not the wrapper. Sectors are told apart by colour; add a second cue the reader can use without it: separate them with `paddingAngle`, and print each value and name beside the ring in a legend or a breakdown (see With Breakdown). ```tsx // Named by a string, or by the element that already carries the chart's title. } /> {/* … */} {/* … */} // A chart that only repeats a figure printed beside it leaves the keyboard layer out.{/* … */} ``` ## Examples ### Donut An `innerRadius` makes the ring and `paddingAngle` separates its sectors. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {PieChart} from "@peakui-pro/react/pie-chart"; import {LEGEND_CLASS, TRAFFIC} from "./_data.ts"; /* An `innerRadius` makes the ring; `paddingAngle` separates two sectors, in place of a stroke. */ export function Donut() { return (); } ``` ### Donut With Label A `Label` inside the `Pie` draws in the hole. Its `content` receives the ring's `viewBox`, whose `cx` and `cy` are the centre. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {PieChart} from "@peakui-pro/react/pie-chart"; import {LEGEND_CLASS, STORAGE} from "./_data.ts"; /* A `Label` inside the `Pie` draws in the hole, in the plot's own coordinates. */ export function DonutWithLabel() { return (} /> {TRAFFIC.map((row) => ( ))} {TRAFFIC.map((row) => (
- {row.name} ({row.value.toLocaleString("en-US")})
))}); } ``` ### Donut With Content Any React node can fill the hole: lay it over the chart in a `relative` wrapper, centre it, and set `pointer-events-none` so the pointer still reaches the sectors beneath. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {PieChart} from "@peakui-pro/react/pie-chart"; import {DEVICES, total} from "./_data.ts"; /* * The hole holds any React node: a figure laid over the chart and centred on it. * `pointer-events-none` lets the pointer through to the sectors underneath. */ export function DonutWithContent() { return (} /> {STORAGE.map((row) => ( ))} { const {cx, cy} = viewBox as {cx: number; cy: number}; return ( ); }} /> 100 GB used {STORAGE.map((row) => (
- {row.name} ({row.value} GB)
))}); } ``` ### With Breakdown The ring beside the figures it draws. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {PieChart} from "@peakui-pro/react/pie-chart"; import {PLANS, total} from "./_data.ts"; /* The ring beside the figures it draws: the list is the cue the colours alone do not give. */ export function WithBreakdown() { return (} /> {DEVICES.map((row) => ( ))} 4.5K Devices{DEVICES.map((row) => (
- {row.name} {row.value.toLocaleString("en-US")} ({Math.round((row.value / total(DEVICES)) * 100)}%)
))}); } ``` ### Custom Tooltip `TooltipContent` takes a `valueFormatter`; `hideHeader` leaves out the row above the slice, which a pie has no use for. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {PieChart} from "@peakui-pro/react/pie-chart"; import {BROWSERS} from "./_data.ts"; /* The tooltip card is the shared one; its formatters turn a bare value into a sentence. */ export function CustomTooltip() { return (} /> {PLANS.map((row) => ( ))} {total(PLANS).toLocaleString("en-US")} Total{PLANS.map((row) => (
- {row.name} {row.value} ({((row.value / total(PLANS)) * 100).toFixed(1)}%)
))}); } ``` ### Nested Donut Two `Pie`s in one chart, each with its own radii. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {PieChart} from "@peakui-pro/react/pie-chart"; import {LAST_YEAR, THIS_YEAR} from "./_data.ts"; /* Two `Pie`s in one chart: the inner ring is last year, the outer one this. */ export function NestedDonut() { return (`${value}% of visits`} /> } /> {BROWSERS.map((row) => ( ))} ); } ``` ## Customization ### Tailwind CSS ```tsx} /> {LAST_YEAR.map((row) => ( ))} {THIS_YEAR.map((row) => ( ))} Inner ring last year, outer ring this year
``` ### Global CSS ```css @layer components { .chart-polar { --chart-axis-size: 11px; --chart-grid-opacity: 0.4; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The PieChart component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui-pro/blob/main/packages/styles/components/pie-chart.css)): #### Base Classes - `.chart-polar` - The block every polar chart carries; grid, tick text, the hidden tooltip cursor and the raised tooltip - `.pie-chart` - This chart's own block; gives the root its width, removes sector outlines and mutes label text and lines ### Slots - `[data-slot="pie-chart"]` - The root element ### CSS Variables | Variable | Purpose | | ------------------------- | ------------------------------------------------------------------- | | `--chart-axis-size` | Type size of tick text; set on `.chart-polar` | | `--chart-grid-opacity` | How far a polar grid recedes behind the data; set on `.chart-polar` | | `--chart-1` … `--chart-5` | The series ramp, derived from the theme's accent | ## API Reference ### PieChart | Prop | Type | Default | Description | | -------------------- | --------------------------- | -------- | -------------------------------------------------------------------- | | `height` | ``number \| `${number}%` `` | `300` | Height of the plot | | `width` | ``number \| `${number}%` `` | `'100%'` | Width of the plot | | `accessibilityLayer` | `boolean` | `true` | Whether the plot is focusable and answers the arrow keys | | `children` | `ReactNode` | - | The chart's parts | | `aria-label` | `string` | - | Names the plot, which is what takes focus — not the wrapping ` ` | | `aria-labelledby` | `string` | - | Names the plot by another element's `id` | | `className` | `string` | - | Additional classes | | `...rest` | `ComponentProps<'div'>` | - | Native `` attributes, on the wrapper | There is no `data` and no `margin`: a pie's data belongs to its `Pie`, and a polar chart sizes itself from its container. ### PieChart.Pie The charting library's `Pie`, re-exported. See the [Recharts Pie API](https://recharts.github.io/en-US/api/Pie/). ### PieChart.Cell The charting library's `Cell`, re-exported. See the [Recharts Cell API](https://recharts.github.io/en-US/api/Cell/). ### PieChart.Label The charting library's `Label`, re-exported. See the [Recharts Label API](https://recharts.github.io/en-US/api/Label/). ### PieChart.Tooltip The charting library's `Tooltip`, re-exported. See the [Recharts Tooltip API](https://recharts.github.io/en-US/api/Tooltip/). ### PieChart.TooltipContent `ChartTooltip.Content`, for the `content` prop of `PieChart.Tooltip`. Its props are on the [ChartTooltip page](https://peakui.dev/docs/react/components/chart-tooltip).# RadarChart > Several measures compared across shared categories, drawn as an outline around a centre **Category**: components **URL**: https://peakui.pro/en/docs/react/components/radar-chart **Source**: https://raw.githubusercontent.com/peakui-dev/peakui-pro/refs/heads/main/apps/docs/content/docs/en/react/components/(charts)/radar-chart.mdx ## Usage `RadarChart` is imported from its own subpath and needs the optional `recharts` peer. ```bash npm install recharts ``` ```tsx import {RadarChart} from "@peakui-pro/react/radar-chart"; ``` ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {RadarChart} from "@peakui-pro/react/radar-chart"; import {FIRST, SKILLS} from "./_data.ts"; /* One series: an outline, a soft fill and a dot at each spoke. */ export function Basic() { return ( ); } ``` ### Anatomy ```tsx import {RadarChart} from "@peakui-pro/react/radar-chart"; // Only the root is this package's own; the parts are the charting library's components under // PeakUI names. The root is not exported from `@peakui-pro/react`, so an app that renders no // chart never needs the peer installed, not even to render on a server. export default () => (} /> ); ``` ### Data belongs to the chart `data` is one object per spoke. `AngleAxis` reads the spoke's name from `dataKey`; each `Radar` reads its own field from every row. Two `Radar`s over the same rows are a comparison. ### Colouring a series A `Radar` takes its colour from `stroke` and `fill`; set both to a token of the series ramp, `var(--chart-2)` … `var(--chart-5)`, and lower `fillOpacity` so overlapping areas stay legible (0.15 for one or two series, 0.1 for three). `--chart-1` is the darkest step and has too little contrast on a dark surface, so the examples on this page do not use it. ### Dots `dot` draws a marker at each value. Give it `fillOpacity: 1` for a solid one. With `fill="none"` on the `Radar` the dots inherit the missing fill, so pass their `fill` as well (see Dots Only). ### Zero and empty data A chart whose `data` is empty renders its container and draws no outline. Show your own empty state beside it. ### Accessibility The plot takes focus and answers the arrow keys, so `aria-label` names it, not the wrapper. Series are told apart by colour; add a second cue the reader can use without it: name each series in a legend, show `dot` markers, or give a series a `strokeDasharray`. ```tsx // Named by a string, or by the element that already carries the chart's title. } /> {/* … */} {/* … */} // A chart that only repeats a figure printed beside it leaves the keyboard layer out.{/* … */} ``` ## Examples ### Comparison Two series over the same spokes. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {RadarChart} from "@peakui-pro/react/radar-chart"; import {FIRST, LEGEND_CLASS, PLATFORMS, SECOND} from "./_data.ts"; /* Two series over the same spokes; the shapes overlap where they agree. */ export function Comparison() { return (); } ``` ### Multi Series Three series; lighter fills keep their overlaps legible. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {RadarChart} from "@peakui-pro/react/radar-chart"; import {DEVICES, FIRST, LEGEND_CLASS, SECOND, THIRD} from "./_data.ts"; /* Three series with no dots; lighter fills keep the overlaps legible. */ export function MultiSeries() { return (} /> {( [ ["Team A", FIRST], ["Team B", SECOND], ] as const ).map(([label, color]) => (
- {label}
))}); } ``` ### Dots Only `fill="none"` drops the area. The dots inherit it, so they take their own `fill`. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {RadarChart} from "@peakui-pro/react/radar-chart"; import {FIRST, SKILLS} from "./_data.ts"; /* * `fill="none"` drops the area, and the dots inherit it: give them their own `fill`, or they * vanish with it. */ export function DotsOnly() { return (} /> {( [ ["Desktop", FIRST], ["Mobile", SECOND], ["Tablet", THIRD], ] as const ).map(([label, color]) => (
- {label}
))}); } ``` ### With Radius Axis `RadiusAxis` prints the scale along one spoke. `angle` places it and `domain` fixes the scale. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {RadarChart} from "@peakui-pro/react/radar-chart"; import {FIRST, LEGEND_CLASS, SECOND, SPRINT} from "./_data.ts"; /* A radius axis prints the scale along one spoke; `domain` fixes it at 0 to 100. */ export function WithRadiusAxis() { return (} /> ); } ``` ## Customization ### Tailwind CSS ```tsx} /> {( [ ["Current", SECOND], ["Target", FIRST], ] as const ).map(([label, color]) => (
- {label}
))}``` ### Global CSS ```css @layer components { .chart-polar { --chart-axis-size: 11px; --chart-grid-opacity: 0.4; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The RadarChart component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui-pro/blob/main/packages/styles/components/radar-chart.css)): #### Base Classes - `.chart-polar` - The block every polar chart carries; grid, tick text, the hidden tooltip cursor and the raised tooltip - `.radar-chart` - This chart's own block; gives the root its width, sets the category labels to 11px and rounds the outline's joins ### Slots - `[data-slot="radar-chart"]` - The root element ### CSS Variables | Variable | Purpose | | ------------------------- | --------------------------------------------------------------------- | | `--chart-axis-size` | Type size of tick text; set on `.chart-polar` | | `--chart-grid-opacity` | How far the polar grid recedes behind the data; set on `.chart-polar` | | `--chart-1` … `--chart-5` | The series ramp, derived from the theme's accent | ## API Reference ### RadarChart | Prop | Type | Default | Description | | -------------------- | -------------------------------------------- | -------- | -------------------------------------------------------------------- | | `data` | `Record []` | - | One object per spoke; each series reads its own field | | `height` | ``number \| `${number}%` `` | `300` | Height of the plot | | `width` | ``number \| `${number}%` `` | `'100%'` | Width of the plot | | `accessibilityLayer` | `boolean` | `true` | Whether the plot is focusable and answers the arrow keys | | `children` | `ReactNode` | - | The chart's parts | | `aria-label` | `string` | - | Names the plot, which is what takes focus — not the wrapping ` ` | | `aria-labelledby` | `string` | - | Names the plot by another element's `id` | | `className` | `string` | - | Additional classes | | `...rest` | `ComponentProps<'div'>` | - | Native `` attributes, on the wrapper | There is no `margin`: a polar chart sizes itself from its container. ### RadarChart.Radar The charting library's `Radar`, re-exported. See the [Recharts Radar API](https://recharts.github.io/en-US/api/Radar/). ### RadarChart.Grid The charting library's `PolarGrid`, re-exported. See the [Recharts PolarGrid API](https://recharts.github.io/en-US/api/PolarGrid/). ### RadarChart.AngleAxis The charting library's `PolarAngleAxis`, re-exported. See the [Recharts PolarAngleAxis API](https://recharts.github.io/en-US/api/PolarAngleAxis/). ### RadarChart.RadiusAxis The charting library's `PolarRadiusAxis`, re-exported. See the [Recharts PolarRadiusAxis API](https://recharts.github.io/en-US/api/PolarRadiusAxis/). ### RadarChart.Tooltip The charting library's `Tooltip`, re-exported. See the [Recharts Tooltip API](https://recharts.github.io/en-US/api/Tooltip/). ### RadarChart.TooltipContent `ChartTooltip.Content`, for the `content` prop of `RadarChart.Tooltip`. Its props are on the [ChartTooltip page](https://peakui.dev/docs/react/components/chart-tooltip).# RadialChart > Progress shown as concentric rings, a dial, or a single ring around a figure **Category**: components **URL**: https://peakui.pro/en/docs/react/components/radial-chart **Source**: https://raw.githubusercontent.com/peakui-dev/peakui-pro/refs/heads/main/apps/docs/content/docs/en/react/components/(charts)/radial-chart.mdx ## Usage `RadialChart` is imported from its own subpath and needs the optional `recharts` peer. ```bash npm install recharts ``` ```tsx import {RadialChart} from "@peakui-pro/react/radial-chart"; ``` ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {RadialChart} from "@peakui-pro/react/radial-chart"; import {ACTIVITY} from "./_data.ts"; /* * Rows are rings, the first innermost. `AngleAxis` fixes the scale at 0–100 so each value reads as * a share of its goal; without it the longest bar would fill the circle. `cornerRadius` is half * the bar's thickness, which rounds both ends fully. */ export function Basic() { return ( ); } ``` ### Anatomy ```tsx import {RadialChart} from "@peakui-pro/react/radial-chart"; // Only the root is this package's own; the parts are the charting library's components under // PeakUI names. The root is not exported from `@peakui-pro/react`, so an app that renders no // chart never needs the peer installed, not even to render on a server. export default () => ({[...ACTIVITY].reverse().map((row) => (
))}- {row.name}
- {row.goal}
} /> {ACTIVITY.map((row) => ( ))} ); ``` ### Data belongs to the chart `data` is one object per ring. The first row is the innermost ring. A single row is a gauge or a progress ring. `Bar` reads each row's `dataKey`, and its `background` prop draws the empty track under every bar; the track takes the `--default` surface colour. ### Fixing the scale Without an `AngleAxis`, the largest value fills the sweep. Add one with `type="number"`, `domain={[0, 100]}` and `tick={false}` to make each value a percentage of its own goal. Give it `angleAxisId={0}` to be certain the bars read it. ### The sweep `startAngle` and `endAngle` are degrees, counter-clockwise from three o'clock. The defaults, 90 and -270, make one full circle that starts at twelve o'clock and fills clockwise. A dial is a shorter sweep: 225 to -45 leaves the bottom quarter open (see Gauge). `innerRadius` and `outerRadius` take pixels or a percentage of the plot's radius, and `barSize` is the ring's thickness in pixels. With several rows, the rings share the space between the two radii. `cornerRadius` on the `Bar`, half the thickness, rounds both ends fully. ### Colouring rings Give each ring its colour with a `Cell`, or put a `fill` on every row of the data and map it to a `Cell`. Use the series ramp `var(--chart-2)` … `var(--chart-5)`. `--chart-1` is the darkest step and nearly vanishes on a dark surface, `--chart-2` is little better, and a ring is thin, so the examples on this page use `--chart-3` to `--chart-5`. ### A figure in the middle The ring's centre is empty. Lay any React node over the chart in a `relative` wrapper, centre it, and set `pointer-events-none` so the pointer still reaches the bar beneath (see Gauge and Progress Ring). ### Zero and empty data A chart whose `data` is empty renders its container and draws no bar. Show your own empty state beside it. ### Accessibility The plot takes focus and answers the arrow keys, so `aria-label` names it, not the wrapper. Rings are told apart by colour; add a second cue the reader can use without it: print each ring's name and value beside the chart (see the first example) and state a single figure's value in the name. ```tsx // Named by a string, or by the element that already carries the chart's title. } /> {/* … */} {/* … */} // A chart that only repeats a figure printed beside it leaves the keyboard layer out.{/* … */} ``` ## Examples ### Gauge A shorter sweep, `startAngle={225}` to `endAngle={-45}`, leaves the bottom open. The figure sits in the middle. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {RadialChart} from "@peakui-pro/react/radial-chart"; import {INNER} from "./_data.ts"; /* * A dial open at the bottom: it starts at 7:30 (225°) and runs clockwise to 4:30 (-45°), 270° in * all. The figure is a sibling laid over the middle of the chart; `pointer-events-none` lets the * pointer through to the bar underneath. */ export function Gauge() { return (); } ``` ### Progress Ring The default sweep with one row. A thicker `barSize` and a tighter band put the ring at the edge. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {RadialChart} from "@peakui-pro/react/radial-chart"; import {INNER} from "./_data.ts"; /* * The default sweep, a full circle from twelve o'clock, with a single row: the bar fills clockwise * to its share of a goal. A thicker bar (`barSize`) sits in a ring that hugs the edge. */ export function ProgressRing() { return ( Active Users 1,358); } ``` ### With Legend Rings share a fixed scale, `domain={[0, 128]}`, so each reads as a share of the whole. The legend is the same rows, listed beside the figures. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {RadialChart} from "@peakui-pro/react/radial-chart"; import {INNER, MIDDLE, OUTER} from "./_data.ts"; /* The first row is the innermost ring, and the legend lists the same rows, largest first. */ const STORAGE = [ {fill: INNER, name: "System", value: 18}, {fill: MIDDLE, name: "Media", value: 28}, {fill: OUTER, name: "Documents", value: 42}, ]; /* * The scale is fixed at the disk's 128 GB, so a ring is a share of the whole. Radii are pixels: * a percentage is taken of the plot minus its own inset. */ export function WithLegend() { return ( 75% 7,452 / 10,000); } ``` ### Gauge Grid One single-row chart per card, repeated in a grid. ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {RadialChart} from "@peakui-pro/react/radial-chart"; import {INNER, MIDDLE, OUTER} from "./_data.ts"; const GAUGES = [ {color: INNER, label: "Conversion", value: 75}, {color: MIDDLE, label: "Engagement", value: 75}, {color: OUTER, label: "Bounce Rate", value: 35}, {color: INNER, label: "Errors", value: 90}, ]; /* Four dials, each a one-row chart with its own figure laid over the middle. */ export function GaugeGrid() { return ({STORAGE.map((row) => ( ))} 88 GB used{[...STORAGE].reverse().map((row) => (
- {row.name} {row.value} GB
))}{GAUGES.map((gauge) => (); } ``` ## Customization ### Tailwind CSS ```tsx{gauge.label}))} {gauge.value}%``` ### Global CSS ```css @layer components { .radial-chart .recharts-radial-bar-background-sector { fill: var(--border); } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The RadialChart component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui-pro/blob/main/packages/styles/components/radial-chart.css)): #### Base Classes - `.chart-polar` - The block every polar chart carries; tick text, the hidden tooltip cursor, the raised tooltip and the focus ring - `.radial-chart` - This chart's own block; gives the root its width and paints each ring's empty track in `--default` ### Slots - `[data-slot="radial-chart"]` - The root element ### CSS Variables | Variable | Purpose | | ------------------------- | ------------------------------------------------ | | `--default` | The colour of each ring's empty track | | `--chart-1` … `--chart-5` | The series ramp, derived from the theme's accent | ## API Reference ### RadialChart | Prop | Type | Default | Description | | -------------------- | ------------------------------------ | -------- | -------------------------------------------------------------------- | | `data` | `Record []` | - | One object per ring; the first is the innermost | | `height` | ``number \| `${number}%` `` | `300` | Height of the plot | | `width` | ``number \| `${number}%` `` | `'100%'` | Width of the plot | | `barSize` | `number` | `10` | Thickness of each ring, in pixels | | `innerRadius` | `number \| string` | `'30%'` | Where the innermost ring starts | | `outerRadius` | `number \| string` | `'80%'` | Where the outermost ring ends | | `startAngle` | `number` | `90` | Where the sweep starts, degrees counter-clockwise from three o'clock | | `endAngle` | `number` | `-270` | Where the sweep ends | | `accessibilityLayer` | `boolean` | `true` | Whether the plot is focusable and answers the arrow keys | | `children` | `ReactNode` | - | The chart's parts | | `aria-label` | `string` | - | Names the plot, which is what takes focus — not the wrapping ` ` | | `aria-labelledby` | `string` | - | Names the plot by another element's `id` | | `className` | `string` | - | Additional classes | | `...rest` | `ComponentProps<'div'>` | - | Native `` attributes, on the wrapper | There is no `margin`: a polar chart sizes itself from its container. ### RadialChart.Bar The charting library's `RadialBar`, re-exported. See the [Recharts RadialBar API](https://recharts.github.io/en-US/api/RadialBar/). ### RadialChart.Cell The charting library's `Cell`, re-exported. See the [Recharts Cell API](https://recharts.github.io/en-US/api/Cell/). ### RadialChart.AngleAxis The charting library's `PolarAngleAxis`, re-exported. See the [Recharts PolarAngleAxis API](https://recharts.github.io/en-US/api/PolarAngleAxis/). ### RadialChart.Tooltip The charting library's `Tooltip`, re-exported. See the [Recharts Tooltip API](https://recharts.github.io/en-US/api/Tooltip/). ### RadialChart.TooltipContent `ChartTooltip.Content`, for the `content` prop of `RadialChart.Tooltip`. Its props are on the [ChartTooltip page](https://peakui.dev/docs/react/components/chart-tooltip).# KPIGroup > Several metrics on one surface **Category**: components **URL**: https://peakui.pro/en/docs/react/components/kpi-group **Source**: https://raw.githubusercontent.com/peakui-dev/peakui-pro/refs/heads/main/apps/docs/content/docs/en/react/components/(data-display)/kpi-group.mdx ## Usage ```tsx import {KPIGroup} from "@peakui-pro/react"; ``` ```tsx import {KPIGroup} from "@peakui-pro/react"; import {KPI} from "@peakui-pro/react/kpi"; export function Basic() { return ( ); } ``` ### Anatomy ```tsx import {KPIGroup} from "@peakui-pro/react"; // The group ships from the package root: it imports no chart, so laying out metrics needs no // charting library. Inside it a KPI card gives up its own background, shadow and radius — one // surface, with a hairline between the metrics. export default () => ( Total Subscribers 12% Avg. Open Rate 2.02% ); ``` ## Examples ### With From Suffix ```tsx import {KPIGroup} from "@peakui-pro/react"; import {KPI} from "@peakui-pro/react/kpi"; export function WithFromSuffix() { return ( ); } ``` ### Vertical ```tsx import {KPIGroup} from "@peakui-pro/react"; import {KPI} from "@peakui-pro/react/kpi"; export function Vertical() { return ( Total Subscribers from 70,946 12% Avg. Open Rate from 56.14% 2.02% ); } ``` ## Customization ### Tailwind CSS ```tsx Revenue +3.3% Expenses -13.0% ``` ### Global CSS ```css @layer components { .kpi-group { --kpi-group-separator-color: var(--border-secondary); --kpi-group-separator-inset: calc(var(--spacing) * 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 KPIGroup component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui-pro/blob/main/packages/styles/components/kpi-group.css)): #### Base & Orientation Classes - `.kpi-group` - The shared surface; the cards inside it drop their own - `.kpi-group--horizontal` - Metrics side by side, each taking an equal share of the width - `.kpi-group--vertical` - Metrics stacked #### Element Classes - `.kpi-group__separator` - The hairline between two metrics ### Slots - `[data-slot="kpi-group"]` - The group - `[data-slot="kpi-group-separator"]` - A hairline ### CSS Variables | Variable | Purpose | | ----------------------------- | ------------------------------------------------------------ | | `--kpi-group-separator-color` | Colour of the hairline | | `--kpi-group-separator-inset` | How far a vertical hairline stops short of the group's edges | ## API Reference ### KPIGroup | Prop | Type | Default | Description | | ------------- | ------------------------------------- | -------------- | ------------------------------------------------------------------- | | `orientation` | `'horizontal' \| 'vertical'` | `'horizontal'` | Which way the metrics are laid out, and which way the hairlines run | | `children` | `ReactNode` | - | The metrics and the hairlines between them | | `aria-label` | `string` | - | Names the set; each card inside already names its own metric | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered ` ` with your own element | | `...rest` | `ComponentProps<'div'>` | - | Native `` attributes. `role` is `group` and can be overridden | ### KPIGroup.Separator | Prop | Type | Default | Description | | ------------- | -------------------------------------- | ------- | -------------------------------------------------------------------------------- | | `aria-hidden` | `boolean` | `true` | Hidden by default: it is decoration between metrics that already name themselves | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'span', undefined>` | - | Replaces the rendered `` with your own element | | `...rest` | `ComponentProps<'span'>` | - | Native `` attributes |# KPI > Metric card with a figure, a trend and a sparkline **Category**: components **URL**: https://peakui.pro/en/docs/react/components/kpi **Source**: https://raw.githubusercontent.com/peakui-dev/peakui-pro/refs/heads/main/apps/docs/content/docs/en/react/components/(data-display)/kpi.mdx ## Usage `KPI` is imported from its own subpath and needs the optional `recharts` peer. ```bash npm install recharts ``` ```tsx import {KPI} from "@peakui-pro/react/kpi"; ``` ```tsx import {KPI} from "@peakui-pro/react/kpi"; export function Basic() { return ( ); } ``` ### Anatomy ```tsx import {KPI} from "@peakui-pro/react/kpi"; // The card is a group named by its own title, so each one in a row announces its own metric. // `Actions` sits in the card's corner and is written outside the header. export default () => (Total Revenue +3.3% New Customers +1.0% ); ``` ### Missing Observations A gap in the data is `null`, never `0`: zero is a reading, and it drops the line to the floor. ```tsx // Without `connectNulls` the line breaks at the gap, which is what a reader should see. // With it, the line is drawn across — an estimate, so say so where the card is read. const data = [{value: 12400}, {value: 14100}, {value: null}, {value: 17800}]; ``` ## Examples ### With Icon `status` tints the tile and its glyph; without one the tile is neutral. ```tsx import {Persons, TriangleExclamation} from "@gravity-ui/icons"; import {KPI} from "@peakui-pro/react/kpi"; export function WithIcon() { return ( ); } ``` ### With Actions ```tsx import {CircleCheck} from "@gravity-ui/icons"; import {KPI} from "@peakui-pro/react/kpi"; export function WithActions() { return (Total Users +33% Total Sales 0.0% ); } ``` ### With Footer ```tsx import {Persons} from "@gravity-ui/icons"; import {KPI} from "@peakui-pro/react/kpi"; export function WithFooter() { return ( {/* The default name is "More actions"; pass your own when the menu is about one metric. */} Conversion Rate +1.7% ); } ``` ### With Progress `status` colours the bar; a metric that is simply filling up reads as success. ```tsx import {CircleCheck, TriangleExclamation} from "@gravity-ui/icons"; import {KPI} from "@peakui-pro/react/kpi"; export function WithProgress() { return ( Total Subscribers +122 Updated 5 minutes ago ); } ``` ### With Chart Bottom ```tsx import {KPI} from "@peakui-pro/react/kpi"; import {SERIES} from "./_data.ts"; export function WithChartBottom() { return (Server Load Disk Usage {/* The default name is "Progress"; name it when a card has more than one number. */} ); } ``` ### With Chart Inline ```tsx import {ArrowUpRight} from "@gravity-ui/icons"; import {TrendChip} from "@peakui-pro/react"; import {KPI} from "@peakui-pro/react/kpi"; import {SERIES} from "./_data.ts"; export function WithChartInline() { return ( Total Revenue {/* No tooltip: the plot repeats the figure, so it is hidden and off the tab order. */} +3.3% ); } ``` ### With Chart Tooltip ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {AreaChart} from "@peakui-pro/react/area-chart"; import {KPI} from "@peakui-pro/react/kpi"; import {SERIES} from "./_data.ts"; export function WithChartTooltip() { return ( Total Clicks {/* In the right column the plot keeps its own box: no bleed, no fade. */}3.5% last 30d ); } ``` ### With Chart Connect Nulls ```tsx import {KPI} from "@peakui-pro/react/kpi"; import {GAPPED} from "./_data.ts"; export function WithChartConnectNulls() { return ( Total Revenue {/* With a tooltip the plot carries numbers of its own: it stays reachable from the keyboard and the card's title names it. */} +3.3% } />} /> ); } ``` ## Customization ### Tailwind CSS ```tsxReported Revenue {/* March is missing, so the line breaks there. */} Estimated Revenue {/* The same data, drawn across the gap. */} ``` ### Global CSS ```css @layer components { .kpi { --kpi-icon-size: calc(var(--spacing) * 10); --kpi-chart-fade: 20%; } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The KPI component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui-pro/blob/main/packages/styles/components/kpi.css)): #### Base Classes - `.kpi` - Added to the Card root, beside the Card's own classes #### Element Classes - `.kpi__header` - The tile, the title and whatever sits beside them, on one line - `.kpi__icon` - The status tile - `.kpi__title` - The metric's name; quieter than the figure - `.kpi__actions` - The menu, in the card's corner and out of the header's flow - `.kpi__content` - The figure and whatever shares its line, as grid columns - `.kpi__value` - The figure - `.kpi__trend` - The trend chip - `.kpi__progress` - The progress bar; it takes the content's full width - `.kpi__chart` - The sparkline; bleeds to the card's edges and fades at both ends - `.kpi__separator` - The rule above a footer - `.kpi__footer` - The line under the rule #### Data Attributes - `[data-status="success"]`, `[data-status="warning"]`, `[data-status="danger"]` - On the icon ### Slots - `[data-slot="card"]` - The root element, a Card - `[data-slot="kpi-header"]`, `[data-slot="kpi-icon"]`, `[data-slot="kpi-title"]` - The header row - `[data-slot="kpi-actions"]` - The menu's box - `[data-slot="kpi-content"]`, `[data-slot="kpi-value"]` - The figure's row - `[data-slot="kpi-chart"]` - The sparkline's box - `[data-slot="kpi-footer"]` - The footer ### CSS Variables | Variable | Purpose | | --------------------- | -------------------------------------------------------- | | `--kpi-icon-size` | Width and height of the status tile | | `--kpi-actions-inset` | Distance of the menu from the card's top and end edges | | `--kpi-chart-fade` | Width of the sparkline's fade at each end | | `--kpi-padding` | How far the sparkline bleeds; mirrors the Card's padding | ## API Reference ### KPI | Prop | Type | Default | Description | | ----------- | --------------------------------------------------------- | ----------- | ---------------------------------------------------------------------------------------------------------- | | `children` | `ReactNode` | - | The card's parts | | `variant` | `'default' \| 'secondary' \| 'tertiary' \| 'transparent'` | `'default'` | Card variant | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered ` ` with your own element | | `...rest` | `ComponentProps<'div'>` | - | Every other Card prop. `role` is `group` and `aria-labelledby` points at the title; both can be overridden | ### KPI.Icon | Prop | Type | Default | Description | | ----------- | ------------------------------------- | ------- | --------------------------------------------------- | | `status` | `'success' \| 'warning' \| 'danger'` | - | Tints the tile and its glyph; neutral without one | | `children` | `ReactNode` | - | The glyph | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered `` with your own element | | `...rest` | `ComponentProps<'div'>` | - | Native `` attributes | ### KPI.Title | Prop | Type | Default | Description | | ----------- | ------------------------------------- | ------- | ------------------------------------------------------------------------------------ | | `children` | `ReactNode` | - | The metric's name. It also names the card, so every card in a row needs one | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered `` with your own element | | `...rest` | `ComponentProps<'div'>` | - | Native `` attributes; `id` is the card's own and overriding it unnames the card | ### KPI.Value | Prop | Type | Default | Description | | ----------- | ---------------------------------- | ------- | ------------------------------------------------------------------------------------------------- | | `value` | `number` | - | **Required.** The figure | | `children` | `(formatted: string) => ReactNode` | - | Receives the formatted figure; the result fills the value element | | `className` | `string` | - | Additional classes, on the value's box | | `...rest` | `NumberValueProps` | - | Every `NumberValue` prop: `style`, `currency`, `notation`, `locale`, `formatOptions` and the rest | ### KPI.Trend | Prop | Type | Default | Description | | --------- | ---------------- | ------- | ----------------------------------------------------------------------------- | | `...rest` | `TrendChipProps` | - | Every `TrendChip` prop: `trend`, `size`, `variant`, and the parts as children | ### KPI.Actions | Prop | Type | Default | Description | | ------------ | ------------- | ------------------ | ----------------------------------------------------------------------------------- | | `children` | `ReactNode` | the ellipsis glyph | The button's content | | `aria-label` | `string` | `'More actions'` | The button's name; set it when the menu is about one metric | | `...rest` | `ButtonProps` | - | Every Button prop. The defaults are `variant="ghost"`, `size="sm"` and `isIconOnly` | ### KPI.Progress | Prop | Type | Default | Description | | ------------ | ------------------------------------ | ------------ | --------------------------------------------------------------- | | `value` | `number` | - | **Required.** How far along, from 0 to 100 | | `status` | `'success' \| 'warning' \| 'danger'` | `'success'` | Colours the bar | | `aria-label` | `string` | `'Progress'` | The bar's name; set it when a card carries more than one number | | `className` | `string` | - | Additional classes | | `...rest` | `ComponentProps<'div'>` | - | Every other `ProgressBar` prop | ### KPI.Chart | Prop | Type | Default | Description | | -------------- | -------------------------------------------- | ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | `data` | `Record[]` | - | **Required.** One object per observation; a missing one is `null`, never `0` | | `dataKey` | `string` | `'value'` | The field each observation is read from | | `color` | `string` | `'currentColor'` | The series line's colour | | `fillColor` | `string` | `color` at 20% | The fill under the line, at its top | | `connectNulls` | `boolean` | `false` | Draws across a `null` instead of breaking the line at it | | `height` | `number` | `80` | Height of the plot | | `strokeWidth` | `number` | `2` | Width of the series line | | `tooltip` | `ReactNode` | - | A `Tooltip`. With one the plot is reachable from the keyboard and the card's title names it; without one it is hidden from assistive technology | | `areaProps` | `Omit ` | - | Passed to the series, winning over everything the card sets on it | | `className` | `string` | - | Additional classes | | `...rest` | `ComponentProps<'div'>` | - | Native ` ` attributes | ### KPI.Header · KPI.Content · KPI.Footer | Prop | Type | Default | Description | | ----------- | ------------------------------------- | ------- | --------------------------------------------------- | | `children` | `ReactNode` | - | The part's content | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered `` with your own element | | `...rest` | `ComponentProps<'div'>` | - | Native `` attributes | ### KPI.Separator | Prop | Type | Default | Description | | --------- | ---------------- | ------- | -------------------- | | `...rest` | `SeparatorProps` | - | Every Separator prop | ### Render Props | Prop | Type | Description | | ------------------------- | ---------------------------------- | ------------------------------------------------------------- | | `children` of `KPI.Value` | `(formatted: string) => ReactNode` | Receives the formatted figure; the result fills `.kpi__value` |# Widget > A card that frames a chart, a table or metrics **Category**: components **URL**: https://peakui.pro/en/docs/react/components/widget **Source**: https://raw.githubusercontent.com/peakui-dev/peakui-pro/refs/heads/main/apps/docs/content/docs/en/react/components/(data-display)/widget.mdx ## Usage ```tsx import {Widget} from "@peakui-pro/react"; ``` ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {Widget} from "@peakui-pro/react"; import {LineChart} from "@peakui-pro/react/line-chart"; import {INPUT, OUTPUT, TOKENS, millions} from "./_data.ts"; /* Each legend item's `color` is the stroke of the series it names. */ export function Basic() { return ( ); } ``` ### Anatomy ```tsx import {Widget} from "@peakui-pro/react"; // The widget ships from the package root: it imports no chart, so framing one needs no charting // library here. Put the chart in `Content`, imported from its own subpath. export default () => ( Tokens Over Time Input Output ); ``` ### Legend colours `color` takes any CSS colour, matching the series the item names. ```tsx Organic Paid ``` ## Examples ### With Bar Chart ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {Widget} from "@peakui-pro/react"; import {BarChart} from "@peakui-pro/react/bar-chart"; import {INPUT, REQUESTS, thousands} from "./_data.ts"; export function WithBarChart() { return (); } ``` ### With Line Chart ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {Widget} from "@peakui-pro/react"; import {LineChart} from "@peakui-pro/react/line-chart"; import {INPUT, REVENUE, thousands} from "./_data.ts"; /* One series needs no legend: the title names it, and the description gives its span. */ export function WithLineChart() { return ( Requests Over Time Requests ); } ``` ### With Pie Chart ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {Widget} from "@peakui-pro/react"; import {PieChart} from "@peakui-pro/react/pie-chart"; import {BROWSERS} from "./_data.ts"; /* A pie has no axes to name its sectors: the legend sits under it, and wraps. */ export function WithPieChart() { return ( Revenue Last 6 months ); } ``` ### With KPIs ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {KPIGroup, TrendChip, Widget} from "@peakui-pro/react"; import {KPI} from "@peakui-pro/react/kpi"; import {LineChart} from "@peakui-pro/react/line-chart"; import {INPUT, REVENUE} from "./_data.ts"; /* `p-0` hands the content's edge to the group, which draws the hairlines between the metrics. */ export function WithKPIs() { return ( Browser Usage {BROWSERS.map((row) => ( ))} {BROWSERS.map((row) => ( {row.name} ))}); } ``` ### With Footer ```tsx import {Widget} from "@peakui-pro/react"; /* The footer sits on the shell, under the content: an action row, or a line of metadata. */ export function WithFooter() { return ( Key Metrics Last 6 months Total Revenue 3.3% last 30d ); } ``` ### Dashboard Grid ```tsx "use client"; // the chart is built from compound parts, which a server file cannot reach import {Widget} from "@peakui-pro/react"; import {BarChart} from "@peakui-pro/react/bar-chart"; import {LineChart} from "@peakui-pro/react/line-chart"; import {INPUT, REQUESTS, REVENUE, thousands} from "./_data.ts"; /* Widgets are grid items: the first spans both columns, the charts share the second row. */ export function DashboardGrid() { return ( Storage 88 of 128 GB 69% used Updated 5 minutes ago ); } ``` ## Customization ### Tailwind CSS ```tsxOverview $228K 1,234 Revenue Requests ``` ### Global CSS ```css @layer components { .widget { --widget-inset: calc(var(--spacing) * 2); --widget-legend-dot-size: calc(var(--spacing) * 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 Widget component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui-pro/blob/main/packages/styles/components/widget.css)): #### Base Classes - `.widget` - The tinted shell #### Element Classes - `.widget__header` - The row above the content; title, description and legend, spread apart - `.widget__title` - The widget's name - `.widget__description` - A quieter line beside the title - `.widget__content` - The raised surface the chart, table or metrics sit on - `.widget__footer` - The row below the content - `.widget__legend` - The set of legend items - `.widget__legend-item` - One series: a dot and its label - `.widget__legend-item-dot` - The coloured dot - `.widget__legend-item-label` - The series name ### Slots - `[data-slot="widget"]` - The root - `[data-slot="widget-header"]` - The header row - `[data-slot="widget-title"]` - The title - `[data-slot="widget-description"]` - The description - `[data-slot="widget-content"]` - The content surface - `[data-slot="widget-footer"]` - The footer row - `[data-slot="widget-legend"]` - The legend - `[data-slot="widget-legend-item"]` - A legend item - `[data-slot="widget-legend-item-dot"]` - The dot - `[data-slot="widget-legend-item-label"]` - The label ### CSS Variables | Variable | Purpose | | -------------------------- | ---------------------------------------------------------- | | `--widget-inset` | The shell's inset around the content | | `--widget-legend-dot-size` | Width and height of the legend dot | | `--widget-legend-dot` | The dot's colour; set on the dot by `LegendItem`'s `color` | ## API Reference ### Widget | Prop | Type | Default | Description | | ----------- | ------------------------------------- | ------- | --------------------------------------------------- | | `children` | `ReactNode` | - | The header, content and footer | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered ` {/* edge to edge */} ` with your own element | | `...rest` | `ComponentProps<'div'>` | - | Native `` attributes | ### Widget.Header | Prop | Type | Default | Description | | ----------- | ----------------------- | ------- | --------------------------------- | | `children` | `ReactNode` | - | The title, description and legend | | `className` | `string` | - | Additional classes | | `...rest` | `ComponentProps<'div'>` | - | Native `` attributes | ### Widget.Title | Prop | Type | Default | Description | | ----------- | ------------------------ | ------- | -------------------------- | | `children` | `ReactNode` | - | The widget's name | | `className` | `string` | - | Additional classes | | `...rest` | `ComponentProps<'span'>` | - | Native `` attributes | ### Widget.Description | Prop | Type | Default | Description | | ----------- | ------------------------ | ------- | ------------------------------- | | `children` | `ReactNode` | - | A quieter line beside the title | | `className` | `string` | - | Additional classes | | `...rest` | `ComponentProps<'span'>` | - | Native `` attributes | ### Widget.Content | Prop | Type | Default | Description | | ----------- | ----------------------- | ------- | -------------------------------------------------------- | | `children` | `ReactNode` | - | The chart, table or metrics | | `className` | `string` | - | Additional classes; `p-0` makes the content edge to edge | | `...rest` | `ComponentProps<'div'>` | - | Native `` attributes | ### Widget.Footer | Prop | Type | Default | Description | | ----------- | ----------------------- | ------- | ------------------------- | | `children` | `ReactNode` | - | Actions or metadata | | `className` | `string` | - | Additional classes | | `...rest` | `ComponentProps<'div'>` | - | Native `` attributes | ### Widget.Legend | Prop | Type | Default | Description | | ----------- | ----------------------- | ------- | ------------------------------- | | `children` | `ReactNode` | - | The `Widget.LegendItem` entries | | `className` | `string` | - | Additional classes | | `...rest` | `ComponentProps<'div'>` | - | Native `` attributes | ### Widget.LegendItem | Prop | Type | Default | Description | | ----------- | ----------------------- | ------- | ------------------------------------------------------------- | | `color` | `string` | - | Required. Any CSS colour for the dot, usually the series' own | | `children` | `ReactNode` | - | The series name | | `className` | `string` | - | Additional classes | | `...rest` | `ComponentProps<'div'>` | - | Native `` attributes |# NumberValue > Locale-aware number with prefix and suffix **Category**: components **URL**: https://peakui.pro/en/docs/react/components/number-value **Source**: https://raw.githubusercontent.com/peakui-dev/peakui-pro/refs/heads/main/apps/docs/content/docs/en/react/components/(feedback)/number-value.mdx ## Usage ```tsx import {NumberValue} from "@peakui-pro/react"; ``` ```tsx import {NumberValue} from "@peakui-pro/react"; export function Basic() { return ; } ``` ### Anatomy Keep parts as direct children: a part inside a fragment or wrapper is not repositioned. ```tsx import {NumberValue} from "@peakui-pro/react"; // Rendered as: prefix, the formatted value, then every other child in the order it was written. // A Prefix inside a fragment or another component is not recognised and renders after the value. export default () => ( ); ``` ## Examples ### Currency `currency` is required when `style` is `"currency"`. ```tsx import {NumberValue} from "@peakui-pro/react"; const FIGURE = "text-2xl font-medium"; export function Currency() { return ( {(["USD", "EUR", "JPY", "GBP"] as const).map((currency) => (); } ``` ### Percent The value is a fraction: `0.033` renders as `3.3%`. ```tsx import {NumberValue} from "@peakui-pro/react"; const FIGURE = "text-2xl font-medium"; export function Percent() { return ())} {[0.033, 0.985, -0.02].map((value) => (); } ``` ### Compact ```tsx import {NumberValue} from "@peakui-pro/react"; const FIGURE = "text-2xl font-medium"; export function Compact() { return ())} {[1234, 45_678, 1_234_567, 9_876_543_210].map((value) => (); } ``` ### Sign Display ```tsx import {NumberValue} from "@peakui-pro/react"; const SIGNS = ["auto", "always", "exceptZero", "never"] as const; export function SignDisplay() { return ())} {SIGNS.map((signDisplay) => (); } ``` ### With Prefix Suffix The prefix precedes the value whatever order the parts are written in. ```tsx import {NumberValue} from "@peakui-pro/react"; const FIGURE = "text-2xl font-medium"; export function WithPrefixSuffix() { return ({signDisplay} {[42, 0, -42].map((value) => ())}))} ); } ``` ### Tabular Nums Stack figures in a column: the digits are tabular, so they stay aligned. ```tsx import {NumberValue} from "@peakui-pro/react"; export function TabularNums() { return (revenue {/* The prefix is written last and still renders first. */} /month sessions ~ {[228_441, 71_887, 156_540, 1234, 98_234].map((value) => (); } ``` ### Format Options `formatOptions` goes straight to `Intl.NumberFormat` and overrides the props above. ```tsx import {NumberValue} from "@peakui-pro/react"; const FIGURE = "text-2xl font-medium"; /* What the convenience props do not reach: a compact currency, and accounting's bracketed loss. */ const COMPACT_CURRENCY: Intl.NumberFormatOptions = { currency: "USD", maximumFractionDigits: 1, notation: "compact", style: "currency", }; const ACCOUNTING: Intl.NumberFormatOptions = { currency: "USD", currencySign: "accounting", style: "currency", }; export function FormatOptions() { return ())} ); } ``` ## Customization ### Tailwind CSS ```tsx``` ### Global CSS ```css @layer components { .number-value { --number-value-suffix-gap: calc(var(--spacing) * 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 NumberValue component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui-pro/blob/main/packages/styles/components/number-value.css)): #### Base Classes - `.number-value` - The root; an inline-flex row on one baseline, with tabular figures #### Element Classes - `.number-value__value` - The formatted number - `.number-value__prefix` - Text before the value; inherits the figure's colour, weight and size - `.number-value__suffix` - Text after the value; muted, regular weight, set off by a margin ### Slots - `[data-slot="number-value"]` - The root element - `[data-slot="number-value-value"]` - The formatted number - `[data-slot="number-value-prefix"]` - The prefix - `[data-slot="number-value-suffix"]` - The suffix ### CSS Variables | Variable | Purpose | | --------------------------- | -------------------------------------- | | `--number-value-suffix-gap` | Space between the value and the suffix | ## API Reference ### NumberValue | Prop | Type | Default | Description | | ----------------------- | ---------------------------------------------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `value` | `number` | - | **Required.** The number to format | | `style` | `'decimal' \| 'currency' \| 'percent' \| 'unit'` | `'decimal'` | The number style — `Intl.NumberFormat`'s option, not inline CSS. The native `style` attribute is not accepted | | `currency` | `string` | - | Currency code such as `'USD'`; required when `style` is `'currency'` | | `unit` | `string` | - | Unit such as `'kilometer'`; required when `style` is `'unit'` | | `notation` | `'standard' \| 'compact' \| 'scientific' \| 'engineering'` | `'standard'` | Notation style | | `signDisplay` | `'auto' \| 'always' \| 'exceptZero' \| 'never'` | - | When the sign is shown | | `minimumFractionDigits` | `number` | - | Fewest fraction digits to show | | `maximumFractionDigits` | `number` | - | Most fraction digits to show | | `locale` | `string` | - | Locale to format in; without it, the nearest `I18nProvider`'s locale, and with no provider the environment's — pin one of the two when a server renders the page, or the server and the browser produce two different strings for the same markup | | `formatOptions` | `Intl.NumberFormatOptions` | - | Options handed to `Intl.NumberFormat`; they override every convenience prop above | | `children` | `ReactNode \| ((formatted: string) => ReactNode)` | - | The parts, and anything else to render beside the figure. As a function it receives the formatted string and its result fills the value element | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'span', undefined>` | - | Replaces the rendered `` with your own element | | `...rest` | `ComponentProps<'span'>` | - | Every other `` attribute, except `style` and `children` | ### NumberValue.Prefix | Prop | Type | Default | Description | | ----------- | --------------------------------- | ------- | ------------------------------------------------------------------------------ | | `children` | `ReactNode` | - | Text before the value | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction ` | - | Replaces the rendered `` with your own element; `E` defaults to `'span'` | | `...rest` | `ComponentProps<'span'>` | - | Native `` attributes | ### NumberValue.Suffix | Prop | Type | Default | Description | | ----------- | --------------------------------- | ------- | ------------------------------------------------------------------------------ | | `children` | `ReactNode` | - | Text after the value | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction ` | - | Replaces the rendered `` with your own element; `E` defaults to `'span'` | | `...rest` | `ComponentProps<'span'>` | - | Native `` attributes | ### Render Props | Prop | Type | Description | | ---------- | ---------------------------------- | ---------------------------------------------------------------------- | | `children` | `(formatted: string) => ReactNode` | Receives the formatted string; the result fills `.number-value__value` | # TrendChip > A chip showing a metric's direction and change **Category**: components **URL**: https://peakui.pro/en/docs/react/components/trend-chip **Source**: https://raw.githubusercontent.com/peakui-dev/peakui-pro/refs/heads/main/apps/docs/content/docs/en/react/components/(feedback)/trend-chip.mdx ## Usage ```tsx import {TrendChip} from "@peakui-pro/react"; ``` ```tsx import {TrendChip} from "@peakui-pro/react"; export function Basic() { return ( ); } ``` ### Anatomy Keep parts as direct children: a part inside a fragment or wrapper is not repositioned. ```tsx import {TrendChip} from "@peakui-pro/react"; // Rendered as: indicator, then prefix, value and suffix — in that order, however they are written. // A part inside a fragment or another component is not recognised and renders after the suffix. // A wrapped Indicator also leaves the default arrow in place: the chip then shows two. export default () => (+3.3% -2.1% 0.0% ); ``` ## Examples ### Variants ```tsx import {TrendChip} from "@peakui-pro/react"; const variants = ["primary", "secondary", "tertiary", "soft"] as const; export function Variants() { return ( 3.3% {variants.map((variant) => (); } ``` ### Sizes ```tsx import {TrendChip} from "@peakui-pro/react"; export function Sizes() { return ({variant}))}+3.3% -2.1% 0.0% ); } ``` ### Custom Indicator `TrendChip.Indicator` takes one icon, or SVG shapes it wraps in its own `+3.3% +3.3% +3.3% # CellColorPicker > Colour picker styled as a settings cell **Category**: components **URL**: https://peakui.pro/en/docs/react/components/cell-color-picker **Source**: https://raw.githubusercontent.com/peakui-dev/peakui-pro/refs/heads/main/apps/docs/content/docs/en/react/components/(forms)/cell-color-picker.mdx ## Usage ```tsx import {CellColorPicker} from "@peakui-pro/react"; ``` ```tsx "use client"; import { ColorArea, ColorField, ColorInputGroup, ColorSlider, ColorSwatch, Label, } from "@peakui/react"; import {CellColorPicker} from "@peakui-pro/react"; export function Basic() { return ( ); } ``` ### Anatomy The ValueDisplay and the Swatch read the picker's state with no consumer wiring. ```tsx import {CellColorPicker} from "@peakui-pro/react"; // Rendered as: the Trigger (aAccent