UI Components
This guide explains how to build custom widgets using the UI component library provided by @openuidev/react-ui.
The package was previously named @crayonai/react-ui. Both names refer to the same project, but the rename introduced some breaking changes. When upgrading an older widget, review the Widgets FAQ for migration guidance.
Component index
The following table lists the available components by category.
| Group | Components |
|---|---|
| Layout | Card, CardHeader, Separator |
| Actions | Button, Buttons, IconButton |
| Text | TextContent, MarkDownRenderer, TextCallout, Callout, CodeBlock |
| Tags | Tag, TagBlock |
| Lists | ListBlock, ListItem, FollowUpBlock, FollowUpItem |
| Steps | Steps, StepsItem |
| Disclosure | Accordion, AccordionItem, AccordionTrigger, AccordionContent, Tabs, TabsList, TabsTrigger, TabsContent |
| Media | Image, ImageBlock, ImageGallery, Carousel, CarouselContent, CarouselItem, CarouselPrevious, CarouselNext |
| Table | Table, ScrollableTable, TableHeader, TableBody, TableFooter, TableRow, TableHead, TableCell |
| Form inputs | FormControl, Label, Hint, Input, TextArea, Select, SelectTrigger, SelectValue, SelectContent, SelectGroup, SelectLabel, SelectItem, SelectSeparator |
| Choices | CheckBoxGroup, CheckBoxItem, RadioGroup, RadioItem, SwitchGroup, SwitchItem |
| Range | Slider, SliderBlock |
| Dates | Calendar, DatePicker |
| Charts | LineChart, BarChart, AreaChart, ScrollableLineChart, ScrollableBarChart, ScrollableAreaChart, HorizontalBarChart, PieChart, RadialChart, SingleStackedBar, RadarChart, ScatterChart, MiniLineChart, MiniBarChart, MiniAreaChart |
Shared prop vocabulary:
varianton containers (Card,Accordion,CheckBoxGroup,RadioGroup,SwitchGroup,TextContent,MarkDownRenderer):"card"(bordered surface),"sunk"(recessed fill) or"clear"(no chrome).- Status
variant(Tag,TextCallout,Callout):"neutral" | "info" | "success" | "warning" | "danger". - Most components also accept
classNameandstyle.CardHeader,Image,InputandTagtakestylesinstead.
Layout
UI.Card — the standard surface. It accepts every <div> attribute.
| Prop | Type | Default |
|---|---|---|
variant | "card" \| "sunk" \| "clear" | "card" |
width | "standard" \| "full" | "standard" |
UI.CardHeader — title row for a card.
| Prop | Type | Notes |
|---|---|---|
title | node | |
subtitle | node | |
icon | node | e.g. <Icons.User size={16} /> |
actions | Button / IconButton element or array | right-aligned |
styles | CSS object | note: styles, not style |
UI.Separator — horizontal rule (Radix Separator). Pass
orientation="vertical" inside a flex row.
Example Code
function ProfileCard(props) {
const { name, role, bio } = props;
return (
<UI.Card variant="card" width="standard">
<UI.CardHeader
icon={<Icons.User size={16} />}
title={name}
subtitle={role}
actions={<UI.IconButton icon={<Icons.MoreHorizontal size={14} />} variant="tertiary" size="small" aria-label="More" />}
/>
<UI.Separator />
<p style={{ margin: "12px 0 0", color: "var(--foreground, #111827)" }}>{bio}</p>
</UI.Card>
);
}
module.exports.default = ProfileCard;
Example Data
{ "name": "Priya Shah", "role": "Account manager", "bio": "Looks after enterprise renewals in APAC." }
Actions
UI.Button — accepts every <button> attribute.
| Prop | Type | Default |
|---|---|---|
variant | "primary" \| "secondary" \| "tertiary" | "primary" |
size | "extra-small" \| "small" \| "medium" \| "large" | "medium" |
buttonType | "normal" \| "destructive" | "normal" |
iconLeft / iconRight | node |
UI.Buttons — lays out a group of Button/IconButton children.
variant: "horizontal" (default) or "vertical".
UI.IconButton — square or round icon-only button. Give it an aria-label.
| Prop | Type | Default |
|---|---|---|
icon | node (required) | |
variant | "primary" \| "secondary" \| "tertiary" | "primary" |
size | "3-extra-small" \| "2-extra-small" \| "extra-small" \| "small" \| "medium" \| "large" | "medium" |
shape | "square" \| "circle" | "square" |
appearance | "normal" \| "destructive" | "normal" |
Use the submit prop to send the user's choice back to the agent:
Example Code
function ConfirmOrder(props) {
const { orderId, submit } = props;
const send = (message) => submit && submit({ title: "Order " + orderId, message: message });
return (
<UI.Card variant="card">
<UI.CardHeader title={"Confirm order " + orderId + "?"} />
<UI.Buttons variant="horizontal">
<UI.Button variant="primary" iconLeft={<Icons.Check size={14} />} onClick={() => send("Confirm order " + orderId)}>
Confirm
</UI.Button>
<UI.Button variant="secondary" onClick={() => send("Change order " + orderId)}>Change</UI.Button>
<UI.Button variant="tertiary" buttonType="destructive" onClick={() => send("Cancel order " + orderId)}>
Cancel
</UI.Button>
</UI.Buttons>
</UI.Card>
);
}
module.exports.default = ConfirmOrder;
Example Data
{ "orderId": "A-1042" }
Text
UI.TextContent — a block of body text. variant: "clear" | "card" | "sunk".
UI.MarkDownRenderer — renders a markdown string.
| Prop | Type | Notes |
|---|---|---|
textMarkdown | string (required) | |
variant | "clear" \| "card" \| "sunk" | |
options | react-markdown Options | advanced |
The MarkdownText global is the app's own markdown renderer (the one chat
uses). Use it when the text should match the surrounding chat messages.
UI.TextCallout / UI.Callout — highlighted message boxes.
TextCallout is the compact inline form.
| Prop | Type |
|---|---|
variant | "neutral" \| "info" \| "success" \| "warning" \| "danger" |
title | node |
description | node |
UI.CodeBlock — syntax-highlighted code.
| Prop | Type |
|---|---|
language | string (required), e.g. "json", "python" |
codeString | string (required) |
Example Code
function ReleaseNote(props) {
const { version, summary, notes, snippet } = props;
return (
<UI.Card variant="card">
<UI.CardHeader title={"Release " + version} />
<UI.TextContent variant="clear">{summary}</UI.TextContent>
<UI.MarkDownRenderer variant="sunk" textMarkdown={notes} />
<UI.TextCallout variant="warning" title="Heads up" description="Tokens issued before this release expire in 7 days." />
<UI.Callout variant="success" title="No downtime" description="The rollout is incremental." />
<UI.CodeBlock language="json" codeString={snippet} />
</UI.Card>
);
}
module.exports.default = ReleaseNote;
Example Data
{
"version": "2.4.0",
"summary": "Faster sync and a new export format.",
"notes": "- **Sync** is 2x faster\n- New `csv` export",
"snippet": "{\n \"export\": \"csv\"\n}"
}
Tags
UI.Tag — a small pill.
| Prop | Type | Default |
|---|---|---|
text | node (required) | |
variant | "neutral" \| "info" \| "success" \| "warning" \| "danger" | "neutral" |
size | "sm" \| "md" \| "lg" | "md" |
icon | node | |
styles | CSS object |
UI.TagBlock — wraps a row of Tags.
Example Code
function TicketTags(props) {
const { status, labels } = props;
const statusVariant = status === "Open" ? "warning" : status === "Resolved" ? "success" : "neutral";
return (
<UI.TagBlock>
<UI.Tag text={status} variant={statusVariant} icon={<Icons.Circle size={10} />} />
{(labels || []).map((l) => <UI.Tag key={l} text={l} size="sm" />)}
</UI.TagBlock>
);
}
module.exports.default = TicketTags;
Example Data
{ "status": "Open", "labels": ["billing", "priority"] }
Lists
UI.ListBlock — a list of ListItems. It numbers the items and passes
variant down to every item.
| Prop | Type | Default |
|---|---|---|
variant | "number" \| "icon" \| "image" | "number" |
UI.ListItem
| Prop | Type | Notes |
|---|---|---|
title | node | |
subtitle | node | |
icon | node | shown when the block variant="icon" |
image | { src, alt } | shown when the block variant="image" |
actionLabel / actionIcon | node | trailing affordance |
onClick | () => void | makes the row clickable |
UI.FollowUpBlock / UI.FollowUpItem — suggested next questions.
FollowUpItem takes text (required) and icon, plus button attributes such
as onClick.
Example Code
function TopArticles(props) {
const { articles, suggestions, submit } = props;
return (
<UI.Card variant="card">
<UI.CardHeader title="Top articles" />
<UI.ListBlock variant="icon">
{articles.map((a) => (
<UI.ListItem
key={a.title}
title={a.title}
subtitle={a.views + " views"}
icon={<Icons.FileText size={14} />}
actionIcon={<Icons.ChevronRight size={14} />}
onClick={() => submit && submit({ message: "Open article: " + a.title })}
/>
))}
</UI.ListBlock>
<UI.FollowUpBlock>
{suggestions.map((s) => (
<UI.FollowUpItem key={s} text={s} onClick={() => submit && submit({ message: s })} />
))}
</UI.FollowUpBlock>
</UI.Card>
);
}
module.exports.default = TopArticles;
Example Data
{
"articles": [
{ "title": "Reset your password", "views": 1240 },
{ "title": "Set up SSO", "views": 860 }
],
"suggestions": ["Show more articles", "Which ones are outdated?"]
}
Steps
UI.Steps numbers its StepsItem children automatically.
UI.StepsItem takes title and details (both required), plus an optional
number that overrides the automatic number.
Example Code
function SetupGuide(props) {
const { steps } = props;
return (
<UI.Steps>
{steps.map((s) => <UI.StepsItem key={s.title} title={s.title} details={s.details} />)}
</UI.Steps>
);
}
module.exports.default = SetupGuide;
Example Data
{
"steps": [
{ "title": "Create an API key", "details": "Settings → API keys → New key." },
{ "title": "Add the webhook", "details": "Paste the URL into your CRM." },
{ "title": "Send a test event", "details": "Use the Test button to verify." }
]
}
Disclosure
Accordion (Radix Accordion): UI.Accordion → UI.AccordionItem →
UI.AccordionTrigger + UI.AccordionContent.
| Component | Props |
|---|---|
Accordion | type: "single" | "multiple" (required); collapsible (single only); defaultValue; variant: "card" \| "sunk" \| "clear" |
AccordionItem | value (required, unique) |
AccordionTrigger | text (required), icon |
AccordionContent | children |
Tabs (Radix Tabs): UI.Tabs → UI.TabsList with UI.TabsTriggers, then
one UI.TabsContent per tab.
| Component | Props |
|---|---|
Tabs | defaultValue or value + onValueChange; variant: "clear" only |
TabsList | variant: "title" | "iconTitle" | "iconTitleSubtext" | "imageTitle" | "imageTitleSubtext" |
TabsTrigger | value and text (required); icon, subtext, image (URL) |
TabsContent | value (required) |
Example Code
function PlanDetails(props) {
const { faqs, monthly, yearly } = props;
return (
<UI.Card variant="card">
<UI.Tabs defaultValue="monthly">
<UI.TabsList variant="iconTitle">
<UI.TabsTrigger value="monthly" text="Monthly" icon={<Icons.Calendar size={14} />} />
<UI.TabsTrigger value="yearly" text="Yearly" icon={<Icons.CalendarRange size={14} />} />
</UI.TabsList>
<UI.TabsContent value="monthly"><UI.TextContent>{monthly}</UI.TextContent></UI.TabsContent>
<UI.TabsContent value="yearly"><UI.TextContent>{yearly}</UI.TextContent></UI.TabsContent>
</UI.Tabs>
<UI.Accordion type="single" collapsible variant="clear">
{faqs.map((f, i) => (
<UI.AccordionItem key={i} value={"faq-" + i}>
<UI.AccordionTrigger text={f.q} icon={<Icons.HelpCircle size={14} />} />
<UI.AccordionContent>{f.a}</UI.AccordionContent>
</UI.AccordionItem>
))}
</UI.Accordion>
</UI.Card>
);
}
module.exports.default = PlanDetails;
Example Data
{
"monthly": "$29 / month, cancel anytime.",
"yearly": "$290 / year — two months free.",
"faqs": [
{ "q": "Can I switch plans later?", "a": "Yes, changes apply on the next billing cycle." },
{ "q": "Is there a free trial?", "a": "14 days, no card required." }
]
}
Media
UI.Image — accepts every <img> attribute.
| Prop | Type | Notes |
|---|---|---|
src | string (required) | |
alt | string | |
aspectRatio | "1:1" \| "3:2" \| "3:4" \| "4:3" \| "16:9" | |
scale | "fit" \| "fill" | |
styles | CSS object |
UI.ImageBlock — a single image with a loading state: src (required),
alt, imageLoading.
UI.ImageGallery — a thumbnail grid that opens a full-screen viewer.
images: [{ src, alt?, details? }].
Carousel — UI.Carousel → UI.CarouselContent → UI.CarouselItems,
followed by UI.CarouselPrevious / UI.CarouselNext. The prev/next buttons
render only when there is room to scroll, and each needs an icon.
| Component | Props |
|---|---|
Carousel | variant: "card" \| "sunk"; itemsToScroll (default 1); showButtons (default true); noSnap |
CarouselPrevious / CarouselNext | icon (required), plus IconButton props |
Example Code
function ProductShowcase(props) {
const { products, gallery } = props;
return (
<UI.Card variant="card" width="full">
<UI.Carousel variant="card" itemsToScroll={1}>
<UI.CarouselContent>
{products.map((p) => (
<UI.CarouselItem key={p.name}>
<UI.Image src={p.image} alt={p.name} aspectRatio="4:3" scale="fill" />
<div style={{ fontWeight: 600, marginTop: 8 }}>{p.name}</div>
<div style={{ color: "var(--muted-foreground, #6b7280)" }}>{p.price}</div>
</UI.CarouselItem>
))}
</UI.CarouselContent>
<UI.CarouselPrevious icon={<Icons.ChevronLeft size={14} />} />
<UI.CarouselNext icon={<Icons.ChevronRight size={14} />} />
</UI.Carousel>
<UI.ImageBlock src={products[0].image} alt={products[0].name} />
<UI.ImageGallery images={gallery} />
</UI.Card>
);
}
module.exports.default = ProductShowcase;
Example Data
{
"products": [
{ "name": "Desk lamp", "price": "$39", "image": "https://picsum.photos/seed/lamp/400/300" },
{ "name": "Chair", "price": "$149", "image": "https://picsum.photos/seed/chair/400/300" },
{ "name": "Monitor arm", "price": "$89", "image": "https://picsum.photos/seed/arm/400/300" }
],
"gallery": [
{ "src": "https://picsum.photos/seed/g1/600/400", "alt": "Front", "details": "Front view" },
{ "src": "https://picsum.photos/seed/g2/600/400", "alt": "Side" }
]
}
Table
The parts mirror HTML tables: UI.Table → UI.TableHeader / UI.TableBody /
UI.TableFooter → UI.TableRow → UI.TableHead (header cell) or
UI.TableCell.
| Component | Extra props |
|---|---|
Table | containerClassName, containerStyle (the wrapper scrolls horizontally) |
ScrollableTable | the same; use it for wide tables in narrow chat columns |
TableHead | icon, align: "left" \| "center" \| "right" |
TableCell | align: "left" \| "center" \| "right" (right-align numbers) |
Example Code
function InvoiceTable(props) {
const { rows, total } = props;
return (
<UI.Table>
<UI.TableHeader>
<UI.TableRow>
<UI.TableHead>Item</UI.TableHead>
<UI.TableHead align="right">Qty</UI.TableHead>
<UI.TableHead align="right">Amount</UI.TableHead>
</UI.TableRow>
</UI.TableHeader>
<UI.TableBody>
{rows.map((r) => (
<UI.TableRow key={r.item}>
<UI.TableCell>{r.item}</UI.TableCell>
<UI.TableCell align="right">{r.qty}</UI.TableCell>
<UI.TableCell align="right">{r.amount}</UI.TableCell>
</UI.TableRow>
))}
</UI.TableBody>
<UI.TableFooter>
<UI.TableRow>
<UI.TableCell colSpan={2}>Total</UI.TableCell>
<UI.TableCell align="right">{total}</UI.TableCell>
</UI.TableRow>
</UI.TableFooter>
</UI.Table>
);
}
module.exports.default = InvoiceTable;
Example Data
{
"rows": [
{ "item": "Pro seats", "qty": 12, "amount": "$348" },
{ "item": "Voice minutes", "qty": 3000, "amount": "$90" }
],
"total": "$438"
}
Form inputs
Widget inputs keep local state. Nothing reaches the agent until you call
submit(...).
| Component | Props |
|---|---|
FormControl | groups label + control + hint; hasError turns the hint red |
Label | children (required), required, disabled, htmlFor |
Hint | helper or error text; inherits hasError from FormControl |
Input | every <input> attribute; size: "small" \| "medium" \| "large"; hasError |
TextArea | every <textarea> attribute; rows; hasError |
Select | Radix Select root: value / defaultValue, onValueChange; size: "sm" \| "md" \| "lg" |
SelectTrigger | wraps SelectValue; size, hideDropdownIcon |
SelectValue | placeholder |
SelectContent | the dropdown (portalled; it follows the theme automatically) |
SelectGroup / SelectLabel / SelectSeparator | grouping |
SelectItem | value (required), children, showTick |
Example Code
function CallbackForm(props) {
const { topics, submit } = props;
const [phone, setPhone] = useState("");
const [topic, setTopic] = useState("");
const [note, setNote] = useState("");
const phoneError = phone.length > 0 && phone.replace(/\D/g, "").length < 10;
const send = () =>
submit && submit({ title: "Callback request", message: "Call me at " + phone + " about " + topic + ". " + note });
return (
<UI.Card variant="card">
<UI.CardHeader title="Request a callback" />
<UI.FormControl hasError={phoneError}>
<UI.Label htmlFor="cb-phone" required>Phone</UI.Label>
<UI.Input id="cb-phone" placeholder="+1 555 010 0000" value={phone} onChange={(e) => setPhone(e.target.value)} hasError={phoneError} />
<UI.Hint>{phoneError ? "Enter at least 10 digits" : "We call within one business day"}</UI.Hint>
</UI.FormControl>
<UI.FormControl>
<UI.Label>Topic</UI.Label>
<UI.Select value={topic} onValueChange={setTopic}>
<UI.SelectTrigger>
<UI.SelectValue placeholder="Choose a topic" />
</UI.SelectTrigger>
<UI.SelectContent>
<UI.SelectGroup>
<UI.SelectLabel>Topics</UI.SelectLabel>
{topics.map((t) => <UI.SelectItem key={t} value={t}>{t}</UI.SelectItem>)}
</UI.SelectGroup>
</UI.SelectContent>
</UI.Select>
</UI.FormControl>
<UI.FormControl>
<UI.Label>Notes</UI.Label>
<UI.TextArea rows={3} value={note} onChange={(e) => setNote(e.target.value)} placeholder="Anything we should know?" />
</UI.FormControl>
<UI.Button disabled={!phone || phoneError || !topic} onClick={send}>Request callback</UI.Button>
</UI.Card>
);
}
module.exports.default = CallbackForm;
Example Data
{ "topics": ["Billing", "Technical issue", "Sales"] }
Choices
| Component | Props |
|---|---|
CheckBoxGroup | variant: "card" \| "sunk" \| "clear"; children are CheckBoxItems |
CheckBoxItem | label, description, checked / defaultChecked, onChange(checked: boolean), name, value, disabled |
RadioGroup | Radix RadioGroup: value / defaultValue, onValueChange(value), variant |
RadioItem | value (required), label, description, disabled |
SwitchGroup | variant; children are SwitchItems |
SwitchItem | label, description, checked / defaultChecked, onChange(checked: boolean), disabled |
Note: CheckBoxItem and SwitchItem call onChange with a boolean, not a
DOM event.
Example Code
function NotificationPrefs(props) {
const { channels, submit } = props;
const [selected, setSelected] = useState([]);
const [frequency, setFrequency] = useState("daily");
const [muted, setMuted] = useState(false);
const toggle = (c, on) => setSelected((prev) => (on ? prev.concat(c) : prev.filter((x) => x !== c)));
const save = () =>
submit && submit({ message: "Notify me via " + (selected.join(", ") || "nothing") + ", " + frequency + (muted ? ", muted on weekends" : "") });
return (
<UI.Card variant="card">
<UI.CardHeader title="Notification preferences" />
<UI.CheckBoxGroup variant="clear">
{channels.map((c) => (
<UI.CheckBoxItem key={c} label={c} checked={selected.includes(c)} onChange={(on) => toggle(c, on)} />
))}
</UI.CheckBoxGroup>
<UI.RadioGroup value={frequency} onValueChange={setFrequency} variant="clear">
<UI.RadioItem value="instant" label="Instant" />
<UI.RadioItem value="daily" label="Daily digest" description="One email at 9am" />
</UI.RadioGroup>
<UI.SwitchGroup variant="clear">
<UI.SwitchItem label="Mute on weekends" checked={muted} onChange={setMuted} />
</UI.SwitchGroup>
<UI.Button onClick={save}>Save</UI.Button>
</UI.Card>
);
}
module.exports.default = NotificationPrefs;
Example Data
{ "channels": ["Email", "SMS", "Slack"] }
Slider, SliderBlock
UI.Slider — the bare track (Radix Slider). Values are always arrays:
one number for a single thumb, two for a range.
| Prop | Type | Notes |
|---|---|---|
variant | "continuous" \| "discrete" (required) | discrete shows step dots |
min, max | number (required) | |
step | number | |
value / defaultValue | number[] | |
onValueChange / onValueCommit | (value: number[]) => void | |
leftContent / rightContent | node | e.g. icons |
UI.SliderBlock — a labelled slider with editable number inputs. It takes
the same props plus label (required) and manages its own value. Listen
with onValueCommit.
Example Code
function BudgetPicker(props) {
const { min, max, submit } = props;
const [seats, setSeats] = useState([10]);
return (
<UI.Card variant="card">
<UI.CardHeader title={"Seats: " + seats[0]} />
<UI.Slider
variant="continuous"
min={1}
max={100}
step={1}
value={seats}
onValueChange={setSeats}
leftContent={<Icons.User size={12} />}
rightContent={<Icons.Users size={12} />}
/>
<UI.SliderBlock
label="Budget range ($)"
variant="continuous"
min={min}
max={max}
step={100}
defaultValue={[min, max]}
onValueCommit={(v) => submit && submit({ message: "Budget between $" + v[0] + " and $" + v[1] })}
/>
</UI.Card>
);
}
module.exports.default = BudgetPicker;
Example Data
{ "min": 500, "max": 5000 }
Dates
UI.Calendar — an inline calendar built on react-day-picker v9. It takes
all DayPicker props, most importantly:
| Prop | Notes |
|---|---|
mode | "single" \| "multiple" \| "range" |
selected | Date, Date[] or { from, to }, matching mode |
onSelect | called with the new selection |
disabled | matcher, e.g. { before: new Date() } |
Props arrive as JSON, so dates are strings. Convert them with
new Date(str) before passing them in.
UI.DatePicker — a calendar with a dropdown header, single or range.
| Prop | Type |
|---|---|
mode | "single" \| "range" |
selectedSingleDate / setSelectedSingleDate | Date and its setter (single mode) |
selectedRangeDates / setSelectedRangeDates | { from, to } and its setter (range mode) |
Example Code
function BookingDates(props) {
const { busyDays, submit } = props;
const [day, setDay] = useState();
const [range, setRange] = useState();
const busy = (busyDays || []).map((d) => new Date(d));
return (
<UI.Card variant="card">
<UI.CardHeader title="Pick a day" subtitle="Highlighted days are fully booked" />
<UI.Calendar mode="multiple" selected={busy} />
<UI.DatePicker mode="single" selectedSingleDate={day} setSelectedSingleDate={setDay} />
<UI.DatePicker mode="range" selectedRangeDates={range} setSelectedRangeDates={setRange} />
<UI.Button
disabled={!day}
onClick={() => submit && submit({ message: "Book " + day.toDateString() })}
>
Book
</UI.Button>
</UI.Card>
);
}
module.exports.default = BookingDates;
Example Data
{ "busyDays": ["2026-11-03", "2026-11-04", "2026-11-10"] }
Charts
Charts use a flat rows data contract. It is not Chart.js: there is no
labels,datasetsoroptions, and those props are silently ignored, so you get empty axes.
Which chart
| Component | Use for | Data contract |
|---|---|---|
LineChart, BarChart, AreaChart | trends and comparisons over categories; they fit the container width | rows + categoryKey |
ScrollableLineChart, ScrollableBarChart, ScrollableAreaChart | long series (dozens of points); they scroll horizontally instead of squeezing | rows + categoryKey |
HorizontalBarChart | ranked lists with long labels | rows + categoryKey |
PieChart | part-to-whole (variant="donut" for a donut) | rows + categoryKey + dataKey |
RadialChart | part-to-whole as rings or a gauge | rows + categoryKey + dataKey |
SingleStackedBar | part-to-whole as one horizontal bar | rows + categoryKey + dataKey |
RadarChart | comparing several metrics per category | rows + categoryKey |
ScatterChart | correlation between two numeric values | datasets of {x, y} points |
MiniLineChart, MiniBarChart, MiniAreaChart | sparklines inside KPI tiles | number[] or [{ value, label? }] |
There is no DonutChart, Histogram or PieChartCondensed.
2D charts
datais a flat array of row objects, one per x-axis point:[{ month: "Jan", sales: 100, profit: 40 }, ...].categoryKeynames the x-axis field, and every row must contain it.- Every other numeric key is a series. Two series means two numeric keys per row, not two arrays. The legend shows the key name.
- Always pass
height(e.g.height={240}), otherwise the chart can collapse to zero height.
| Prop | Type | Applies to |
|---|---|---|
data | rows (required) | all |
categoryKey | string (required) | all |
height, width | number | all |
customPalette | string[] (hex); see how it is applied | all |
theme | "ocean" \| "orchid" \| "emerald" \| "spectrum" \| "sunset" \| "vivid" | all |
grid, legend, showYAxis | boolean | all |
xAxisLabel, yAxisLabel | node | all |
isAnimationActive | boolean | all |
variant | "linear" \| "natural" \| "step" | Line, Area |
variant | "grouped" \| "stacked" | Bar |
strokeWidth | number | Line |
radius, maxBarWidth | number | Bar |
tickVariant | "singleLine" \| "angled" | condensed (non-scrollable) charts |
How customPalette is applied
The palette is not read in order. Every chart picks the colours for n
series outward from the middle of the array:
| Series | Colours used from a palette p of length L (mid = floor(L / 2)) |
|---|---|
| 1 | p[mid] |
| 2 | p[mid - 1], p[mid + 1] |
| 3 or more | n consecutive colours centred on mid, wrapping around the ends |
In practice:
- 1 series:
customPalette={["#3b82f6"]}. - 2 series: put a spacer in the middle:
customPalette={[first, "#CBD5E1", second]}. A two-colour palette makes the second series black, becausep[2]doesn't exist. - 3 series: three colours, in order.
- 4 or more: pass exactly
ncolours and accept that the order rotates, or leavecustomPaletteout and usetheme("ocean","orchid","emerald","spectrum","sunset","vivid").
The same rule applies to PieChart, RadialChart and SingleStackedBar (one
colour per slice). The mini charts take a single lineColor / barColor /
areaColor instead.
Example Code
function SalesTrend(props) {
const { title, rows } = props;
return (
<UI.Card variant="card">
<UI.CardHeader title={title} />
<UI.LineChart data={rows} categoryKey="month" variant="natural" grid legend showYAxis height={220} />
{/* 2 series → colours 1 and 3 of the palette are used (see "How customPalette is applied") */}
<UI.BarChart data={rows} categoryKey="month" variant="grouped" customPalette={["#6366F1", "#CBD5E1", "#14B8A6"]} legend height={220} />
<UI.AreaChart data={rows} categoryKey="month" variant="linear" legend height={220} />
<UI.ScrollableLineChart data={rows} categoryKey="month" grid height={220} />
</UI.Card>
);
}
module.exports.default = SalesTrend;
Example Data
{
"title": "Sales vs profit",
"rows": [
{ "month": "Jan", "sales": 120, "profit": 40 },
{ "month": "Feb", "sales": 180, "profit": 65 },
{ "month": "Mar", "sales": 150, "profit": 50 },
{ "month": "Apr", "sales": 210, "profit": 90 }
]
}
HorizontalBarChart
Same contract as BarChart. It uses showXAxis (not showYAxis), and
variant is "grouped" | "stacked".
Example Code
function TopAgents(props) {
const { rows } = props;
return <UI.HorizontalBarChart data={rows} categoryKey="agent" customPalette={["#10b981"]} grid showXAxis height={220} />;
}
module.exports.default = TopAgents;
Example Data
{ "rows": [{ "agent": "Support bot", "calls": 412 }, { "agent": "Sales bot", "calls": 290 }, { "agent": "HR bot", "calls": 95 }] }
Part-to-whole (PieChart, RadialChart, SingleStackedBar)
All three need both categoryKey (the slice name) and dataKey (the
slice size). With {label, value} rows and no keys, nothing plots.
| Prop | PieChart | RadialChart | SingleStackedBar |
|---|---|---|---|
variant | "pie" (default) | "donut" | "circular" (default) | "semicircle" | — |
format | "percentage" | "number" | same | — |
legend, legendVariant ("default" \| "stacked") | ✓ | ✓ | ✓ |
customPalette, theme | ✓ | ✓ | ✓ |
height, width | number or string | number or string | use style |
cornerRadius / paddingAngle | ✓ / ✓ | ✓ / — | — |
Example Code
function SpendBreakdown(props) {
const { data } = props;
return (
<UI.Card variant="card">
<UI.CardHeader title="Spend by category" />
<div style={{ display: "grid", gap: 24 }}>
<UI.PieChart data={data} categoryKey="category" dataKey="amount" variant="donut" format="percentage" legend />
<UI.RadialChart data={data} categoryKey="category" dataKey="amount" variant="semicircle" legend />
<UI.SingleStackedBar data={data} categoryKey="category" dataKey="amount" legend />
</div>
</UI.Card>
);
}
module.exports.default = SpendBreakdown;
Example Data
{ "data": [{ "category": "Compute", "amount": 540 }, { "category": "Storage", "amount": 210 }, { "category": "Network", "amount": 90 }] }
RadarChart and ScatterChart
UI.RadarChart — rows + categoryKey, where each other numeric key is a
series. variant: "line" | "area", plus areaOpacity, strokeWidth, grid
and legend.
UI.ScatterChart — data is a list of datasets:
[{ name, data: [{ x, y, z? }] }]. Other props: xAxisDataKey / yAxisDataKey
(default "x" / "y"), shape ("circle" | "square"), xAxisLabel,
yAxisLabel, grid, legend and height.
Example Code
function ModelComparison(props) {
const { skills, runs } = props;
return (
<UI.Card variant="card">
<UI.RadarChart data={skills} categoryKey="skill" variant="area" legend height={240} />
<UI.ScatterChart data={runs} xAxisLabel="Latency (ms)" yAxisLabel="Accuracy" grid legend height={240} />
</UI.Card>
);
}
module.exports.default = ModelComparison;
Example Data
{
"skills": [
{ "skill": "Reasoning", "modelA": 82, "modelB": 74 },
{ "skill": "Coding", "modelA": 77, "modelB": 81 },
{ "skill": "Recall", "modelA": 69, "modelB": 72 }
],
"runs": [
{ "name": "Model A", "data": [{ "x": 120, "y": 0.82 }, { "x": 180, "y": 0.86 }] },
{ "name": "Model B", "data": [{ "x": 90, "y": 0.74 }, { "x": 140, "y": 0.79 }] }
]
}
Sparklines with no axes. data is number[] or [{ value, label? }]. Use
size (a number or CSS size) for the height, and lineColor / barColor /
areaColor for a single colour. MiniAreaChart also takes useGradient and
opacity.
Example Code
function KpiTiles(props) {
const { kpis } = props;
const tile = { flex: 1, minWidth: 140, padding: 12, border: "1px solid var(--border, #e5e7eb)", borderRadius: 10 };
return (
<div style={{ display: "flex", gap: 12, flexWrap: "wrap" }}>
{kpis.map((k) => (
<div key={k.label} style={tile}>
<div style={{ fontSize: 12, opacity: 0.7 }}>{k.label}</div>
<div style={{ fontSize: 20, fontWeight: 700 }}>{k.value}</div>
{k.kind === "bar" ? <UI.MiniBarChart data={k.trend} size={40} barColor="#6366F1" />
: k.kind === "area" ? <UI.MiniAreaChart data={k.trend} size={40} areaColor="#14B8A6" useGradient />
: <UI.MiniLineChart data={k.trend} size={40} lineColor="#EC4899" />}
</div>
))}
</div>
);
}
module.exports.default = KpiTiles;
Example Data
{
"kpis": [
{ "label": "Revenue", "value": "$48k", "kind": "line", "trend": [12, 18, 15, 22, 28] },
{ "label": "Orders", "value": "1,204", "kind": "bar", "trend": [80, 95, 70, 120, 110] },
{ "label": "Users", "value": "9.8k", "kind": "area", "trend": [{ "value": 7 }, { "value": 8 }, { "value": 9.8 }] }
]
}