@mastra/playground-ui
Reusable React components, hooks, domains, and design tokens used by Mastra Studio. It provides the UI building blocks for logs, memory, metrics, traces, and agent management.
Installation
npm install @mastra/playground-ui
Usage
Import the package styles once in your React application.
import '@mastra/playground-ui/style.css';
import { Button } from '@mastra/playground-ui/components/Button';
export function SaveButton() {
return <Button>Save</Button>;
}
With a Tailwind build of your own, compile one sheet instead of style.css: import the components' stylesheet uncompiled, and sources.css so Tailwind emits the classes the compiled components use.
@import 'tailwindcss';
@import '@mastra/playground-ui/components.css';
@import '@mastra/playground-ui/sources.css';
To use Mastra's product fonts, Mona Sans for text and Commit Mono for code, add fonts.css. The font files ship inside the package as woff2, split by script so a page only downloads the characters it renders, and the stylesheet points the font tokens at them. Without it, text uses the system font stacks.
@import '@mastra/playground-ui/fonts.css';
Metadata
Use separate elements for metadata fields. Metadata keeps a compact gap between fields, and Metadata.Item groups an icon with its label. Fields wrap as space narrows.
Rows that must keep one line, such as cards, menu options, and truncated titles, pass singleLine: fields stay on one line and each shrinks with an ellipsis. Give a short field className="shrink-0" to keep it whole while a longer one truncates.
import { Metadata } from '@mastra/playground-ui/components/Metadata';
import { Txt } from '@mastra/playground-ui/components/Txt';
<Metadata>
<Metadata.Item>
<Txt as="span" variant="label">
v8
</Txt>
</Metadata.Item>
<Metadata.Item>
<Txt as="span" variant="caption" tone="muted">
Nov 3, 2026, 10:24 AM
</Txt>
</Metadata.Item>
<Metadata.Item>
<Txt as="span" variant="caption" tone="muted">
(current)
</Txt>
</Metadata.Item>
</Metadata>;
Use normal sentences in tooltips, accessible names, and other plain-text APIs. Parentheses such as (current) and missing-value placeholders remain useful; avoid decorative separators or repeated spaces as a substitute for layout. Browser tab titles set through document.title keep the Page | Product convention.
Data sizes
Import formatBytes from the number utility:
import { formatBytes } from '@mastra/playground-ui/utils/number';
formatBytes(1536);
formatBytes(0.5, { unit: 'GB' });
formatBytes(2048, { unit: 'GB', autoScale: false });
formatBytes(0.5, { unit: 'GB', autoScale: true });
formatBytes(2048, { unit: 'GB', autoScale: true });
These calls return 1.5 KB, 0.5 GB, 2048 GB, 512 MB, and 2 TB, respectively.
With no options, formatBytes(bytes) keeps its existing automatic byte formatting and rounding. With a source unit, the formatter keeps the supplied value and unit unchanged unless autoScale: true. The supported units are B, KB, MB, GB, TB, and PB, also exported as the ByteUnit type.
Conversions use the helper's existing binary convention: each unit is 1024 of the previous unit, despite the legacy KB through PB labels. These are not decimal SI conversions, where each step is 1000. Convert decimal measurements to this convention before passing them in.
Automatic scaling stops at B and PB. It rounds bytes and values of 10 or more to whole numbers, and smaller values in larger units to one decimal place. When rounding reaches 1024, the opt-in mode promotes to the next unit, except at PB. Zero becomes 0 B in automatic mode and keeps its source unit otherwise. Negative, non-finite, null, and undefined measurements return undefined in every mode.
Subtle buttons
Use variant="subtle" for a persistent neutral fill, such as a selected view. It keeps the same dimensions as default, so switching between the two does not move surrounding controls. Set aria-pressed on toggle buttons to expose selection to assistive technology.
<Button variant={selected ? 'subtle' : 'default'} aria-pressed={selected}>
My PRs
</Button>
Loading buttons
Pass loading to the button whose action is in progress. Don't put a Spinner in a button, swap its icon or change its label.
<Button variant="primary" icon={<IconPlusMedium />} loading={createProject.isPending} onClick={create}>
Create project
</Button>
- The loader takes the place of the button's icon (
icon, else iconEnd, else the glyph of an icon-only button), so the button keeps its size. A button without an icon gets the loader on the left. Pass the icon through icon, not as a child, or it stays beside the loader.
- The label stays: "Create project", not "Creating project…". The person sees which action is running, and the button's name doesn't change under a screen reader.
- Clicks and submits do nothing, and the button keeps focus (
aria-disabled and aria-busy instead of disabled). disabled only needs the other reasons the button can't be used.
- The button keeps its own colours and the loader takes the icon's: loading isn't the disabled look, which is too faint to read in a light theme.
- The loader appears after 150ms, so an action that finishes sooner changes nothing on screen.
- Other buttons that must wait (Cancel, the second action) are
disabled, not loading.
- In a
Dialog with pending, DialogAction is loading on its own. With two actions, pass loading to each. AlertDialog.Action closes the dialog when clicked; to keep it open while loading, use Dialog with pending.
Central Icons
Interface icons come from Central Icons, in one style: round, outlined, 2px corners, 2px stroke (@central-icons-react/round-outlined-radius-2-stroke-2). Use them for every interface icon. lucide-react remains only where Central has no matching glyph, such as Unplug or Network. Brand and product icons, such as OpenAIIcon or AgentIcon, stay as their own components.
Each icon is its own module under @mastra/playground-ui/icons/central/. An icon inside a design system component, such as a button or menu item, takes its size from that component. Anywhere else, wrap it in Icon or give it a size-icon-* class. Don't set size, width, height or a size class on an icon: the playground-ui/icon-size-from-parent lint rule reports it. The Icons docs page in Storybook covers the sizes and the optical inset a few edge-to-edge shapes get. Icons are decorative (aria-hidden) unless you pass aria-label. Prefer labelling the button or link that contains them.
import { Icon } from '@mastra/playground-ui/icons/Icon';
import { IconMagnifyingGlass } from '@mastra/playground-ui/icons/central/IconMagnifyingGlass';
<Icon size="sm">
<IconMagnifyingGlass />
</Icon>;
The Icons/All Icons Storybook story shows every icon available.
Adding an icon
The icons are committed to this package, so installing and building need no license key. Adding one requires Mastra's Central Icons license key, from the CENTRAL MASTRA item in 1Password.
-
Find the name in Central's icon list or in the Central Figma library, for example IconArrowRight.
-
From packages/playground-ui, run the generator with the key and the names to add:
CENTRAL_LICENSE_KEY=<key> pnpm icons:central IconArrowRight IconCalendar
It checks the key with Central, installs the pinned package in a temporary directory, writes one TSX module per icon to src/ds/icons/central/, and adds the names to central-icons.json. Running it with no names regenerates the current set, for example after raising version in central-icons.json.
-
Commit src/ds/icons/central/. Don't edit the generated files by hand.
Only add icons from this one style, and only icons a screen uses. The license covers icons inside Mastra's products. It doesn't cover the complete library, or offering the icons on their own as an icon set or download. See CENTRAL-ICONS-LICENSE.md. Never commit the license key.
Tool icons
presentTool from @mastra/playground-ui/components/ai/tool-call gives a tool call its label,
detail, static icon, and animated AgentIndicator pose. Use it wherever a tool call is shown, so a
running call and its finished card look the same.
import { AgentIndicator } from '@mastra/playground-ui/components/AgentIndicator';
import { presentTool } from '@mastra/playground-ui/components/ai/tool-call';
const { pose, label, detail } = presentTool(call.toolName, call.args);
<AgentIndicator state={pose} />;
Always pass the call's arguments. Tools such as knowledge_page take an operation (op or
action), and the icon and label follow it, so deleting a page does not look like editing one.
Workspace prefixes (mastra_workspace_), MCP names (mcp__server__tool), namespace.tool names,
and known aliases resolve to the tool they wrap. Unknown tools and ambiguous names such as
mcp__catalog__search keep the generic tool icon.
The AI / Activity / Tool Icon Families Storybook story shows every family and lets you switch
actions to watch the morph.
Tool approvals
ToolApproval renders a standalone approval request in the shared activity layout: the tool name
with its decision status, the full tool arguments (file previews included), and the Approve and
Decline actions.
import { ToolApproval } from '@mastra/playground-ui/components/ai/tool-approval';
<ToolApproval
toolName="write_file"
args={{ path: 'src/agent.ts', content: 'export const name = "Assistant";' }}
disabled={isSubmitting}
status={decision}
onApprove={approve}
onDecline={decline}
/>;
A tool that already renders its own activity composes the parts instead: ToolApprovalStatus beside
the tool name, ToolApprovalActions in the details while the request is pending.
import { ToolApprovalActions, ToolApprovalStatus } from '@mastra/playground-ui/components/ai/tool-approval';
<>
<ActivityHeadline icon={icon} label={label} badges={<ToolApprovalStatus status={decision} />} />
{!decision && <ToolApprovalActions toolName="write_file" onApprove={approve} onDecline={decline} />}
</>;
The consumer owns submission, error feedback, and the optional approved or declined status.
A decision removes the actions; clearing it restores them for a retry. disabled blocks both
decisions without implying server confirmation. autoFocus focuses Approve on mount. Custom
children replace the default argument preview. Examples live under AI / Tool Approval in Storybook.
Agent questions
Use AskUser to render an agent's ask_user payload with shared answer handling:
import { AskUser } from '@mastra/playground-ui/components/ai/ask-user';
<AskUser
payload={{ question: 'Choose a deployment target', options: [{ label: 'Staging' }] }}
onSubmit={handleAnswerSubmit}
/>;
For custom layouts, compose the controls inside AskUser.Root. The root owns selection, custom text, validation, and submission. AskUser.Question names the group and its inputs for assistive technology.
import * as AskUser from '@mastra/playground-ui/components/ai/ask-user';
<AskUser.Root key={prompt.id} selectionMode="single_select" disabled={isSubmitting} onSubmit={handleAnswerSubmit}>
<AskUser.Body>
<AskUser.Question>Choose a deployment target</AskUser.Question>
<AskUser.Options>
<AskUser.Option value="Staging" description="Validate the release before production.">
Staging
</AskUser.Option>
<AskUser.Option value="Production">Production</AskUser.Option>
<AskUser.CustomAnswer />
</AskUser.Options>
<AskUser.Submit when="custom-answer" className="mt-2" />
</AskUser.Body>
</AskUser.Root>;
Single-select options submit their value immediately. when="custom-answer" shows the submit control only while Other… is selected. For multi-select prompts, use selectionMode="multi_select" and omit when to keep the submit control visible. You can position the submit control anywhere inside the root.
Selecting Other… focuses an inline text field. Empty or whitespace-only text unselects it on blur. Non-empty drafts stay selected, and unchecking Other… excludes its text from submission. Answers remain string for single-select and free-text prompts, and string[] for multi-select prompts.
For a free-text prompt, replace AskUser.Options with AskUser.TextAnswer and omit when from the submit control. Use AskUser.Pending for a submitting message or AskUser.Output with a result to display an answer. Reset the draft by changing the root's key when switching prompts. The payload-based card handles question changes automatically.
Interactive examples live under AI / Ask User in Storybook, including composed layouts with the submit control outside the options.
Tables
Table variant="inset" renders a data table from the native table, thead, tbody, tr, th, and td elements with the same raised surface as DataList. Each part takes its element's props, so colSpan and aria-* work as they do in HTML, and any component can go in a cell.
import { Table } from '@mastra/playground-ui/components/Table';
export function CreditHistory({ credits }: { credits: Credit[] }) {
return (
<Table variant="inset" aria-labelledby="credit-history">
<Table.Header>
<Table.Row>
<Table.Head>Type</Table.Head>
<Table.Head className="w-full">Description</Table.Head>
<Table.Head align="end">Balance</Table.Head>
</Table.Row>
</Table.Header>
<Table.Body>
{credits.map(credit => (
<Table.Row key={credit.id}>
<Table.Cell>
<Table.RowLink href={`/billing/credits/${credit.id}`}>{credit.type}</Table.RowLink>
</Table.Cell>
<Table.Cell>{credit.title}</Table.Cell>
<Table.Cell align="end">{credit.balance}</Table.Cell>
</Table.Row>
))}
</Table.Body>
</Table>
);
}
Table takes variant="inset" for the DataList surface. Omit variant to preserve the existing default appearance and sizing. columnDividers draws lines between columns in inset mode.
Table.Head takes align (start, center, or end).
Table.Cell takes align and tone (ink or muted).
- Every column is the same color. Use
Txt tone="muted" only for secondary text inside a cell, such as a second line, or mute every column except the first.
Table.SortButton goes inside a sortable Table.Head and shows the sort arrow.
Table.RowLink makes the whole row a link. Table.RowButton makes it a button, for opening a drawer or dialog. Pass render={<Link to="…" />} for a router link.
Table.Pagination goes below the table: Previous, numbered pages, and Next. It takes a zero-based page, pageCount, and onPageChange. The caller supplies the current page’s rows, from a local slice or a server query.
- Text is left-aligned; numbers are right-aligned with
align="end" on the head and cells. Negative amounts keep their minus sign and use tone="muted"; never red, since usage isn't an error.
- Rows are at least 36px tall and grow with their content. Cells stay on one line unless you wrap their text in an element with
whitespace-normal.
Use Table for data people read and compare, such as billing history or usage. Use DataList for lists of entities people click into, such as agents or traces, which need row keyboard navigation, sticky or reorderable columns, or virtualization. Search and filters go in an ActionRow above either one. Choose based on the rows rendered at once, not the total dataset size; large server-paginated datasets can use Table.
The full guide, with recipes for column dividers, editable cells, sorting, client-side and server-side pagination, loading, and empty states, is the DataDisplay / Table docs page in Storybook.