studio-ui-patterns

作者: supabase

为 Supabase Studio 设计系统 UI 模式。在构建或更新时使用

npx skills add https://github.com/supabase/supabase --skill studio-ui-patterns

Studio UI Patterns

The Design System docs and demos are the source of truth. Always check the relevant demo file before composing new UI.

Compose the House Stack

Before writing custom markup or styles, search 'ui', 'ui-patterns', apps/studio/components/ui/, and the Design System demos. Compose existing primitives through their documented props and slots rather than cloning them, wrapping them to override built-in behavior, or fighting their internal padding and chrome with structural CSS overrides.

  • Layout geometry: own spacing on the parent container with flex flex-col gap-y-* rather than space-y-* (fragile under prose/margin resets) or ad-hoc margins on child sections.
  • Class merging: always combine classes with cn(...) from 'ui' (never template-literal concatenation); avoid deep structural selectors and conflicting Tailwind utilities.
  • Async buttons: use Button's built-in loading prop directly, and apply loading + disabled states to slow async actions (downloads, exports, mutations) so double-clicks cannot fire parallel requests.

Studio Component Index

NeedUse
Inline link in copyInlineLink (components/ui/InlineLink)
Dynamic/untyped internal/external URLDynamicLink (components/ui/DynamicLink); prefer TanStack <Link> directly for known typed internal routes
Support linkSupportLink (components/interfaces/Support/SupportLink)
External or docs linkDOCS_URL (lib/constants) + target="_blank" rel="noopener noreferrer" (when not using InlineLink)
Disabled control needing explanationButtonTooltip (components/ui/ButtonTooltip) or DropdownMenuItemTooltip (components/ui/DropdownMenuItemTooltip)
Floating button over busy contentFloatingPlate ('ui')
Small fixed filter setFilterPopover (components/ui/FilterPopover) instead of a heavy Command combobox
Empty table search-result rowTableRowNoResults (components/ui/TableRowNoResults)
Expandable rows or sectionsCollapsible ('ui'), never hand-rolled toggle <div>s
Dotted tooltip trigger textTOOLTIP_UNDERLINE_CLASS_NAME (components/ui/tooltip-styles)
Technical identifier in copyPlain <code> (auto-styled by packages/config/inline-code.css; opt out with data-code-style="plain")

Layout

Docs: apps/design-system/content/docs/ui-patterns/layout.mdx

Build pages with PageContainer, PageBreadcrumbs, PageHeader, PageNav, and PageSection (PageLayout has been removed).

Content typesize
Settings, forms, and focused configuration"small" (or "default")
Lists, tables, and detail pages"default"
Dense horizontal content (logs, editors, wide grid)"full"
  • If filters/search exist on a list page, align table actions with the filters (don't use PageHeaderAside/PageSectionAside for those actions).
  • If no filters exist, place actions in PageHeaderAside or PageSectionAside.

Demos: page-layout-settings.tsx, page-layout-list.tsx, page-layout-list-simple.tsx, page-layout-detail.tsx (all in apps/design-system/registry/default/example/).

Forms

Docs: apps/design-system/content/docs/ui-patterns/forms.mdx

Use FormItemLayout (not manual FormItem/FormLabel/FormMessage/FormDescription) with FormControl wrapping primitives from 'ui'. For schema, subscriptions, dirty state, reset, and submit mechanics, see the react-hook-form skill.

ContextLayoutContainer
Page (settings/config)FormItemLayout layout="flex-row-reverse"Card (CardContent per field; CardFooter for actions)
Side panel — wideFormItemLayout layout="horizontal"SheetSection
Side panel — narrow (size="sm" or below)FormItemLayout layout="vertical"SheetSection

Demos: form-patterns-pagelayout.tsx, form-patterns-sidepanel.tsx.

Tables

Docs: apps/design-system/content/docs/ui-patterns/tables.mdx

PatternUse when
TableSimple, static, semantic display
Data TableTanStack-powered (@tanstack/react-table); sorting, filtering, paging
Data Grid (legacy)Existing table-editor grids only (legacy)
  • For interactive or data tables, use @tanstack/react-table (use plain Table for simple static display); never add new react-data-grid imports.
  • Place search/filters above the table aligned left, and actions above the table aligned right (or in the page actions area if the table is primary content with no filters).
  • Search/filter <Input> fields need staged-Escape handling (see the studio-shortcuts skill).

Demos: table-demo.tsx, data-table-demo.tsx, data-grid-demo.tsx.

Charts

Docs: apps/design-system/content/docs/ui-patterns/charts.mdx

  • Use provided chart building blocks; avoid passing raw Recharts components to ChartContent.
  • Use useChart context flags for loading/disabled states and avoid over-abstraction.

Demos (in apps/design-system/registry/default/block/): chart-composed-demo.tsx, chart-composed-basic.tsx, chart-composed-states.tsx, chart-composed-metrics.tsx, chart-composed-actions.tsx, chart-composed-table.tsx.

Empty States

Docs: apps/design-system/content/docs/ui-patterns/empty-states.mdx

ScenarioPattern
Initial / onboardingPresentational empty state with value prop + clear next action
Data-heavy listsInformational empty state matching the list/table layout
Zero results from searchKeep layout consistent with data state to avoid jarring transitions
Missing routeCentered Admonition

Demos: empty-state-presentational-icon.tsx, empty-state-initial-state-informational.tsx, empty-state-zero-items-table.tsx, data-grid-empty-state.tsx, empty-state-missing-route.tsx.

Navigation

Docs: apps/design-system/content/docs/ui-patterns/navigation.mdx

  • Use NavMenu for a horizontal list of related views within a consistent page layout; activating an item must trigger a URL change (no local-only tab state).
  • For feature-flagged replacements, verify both states: off preserves existing navigation and destinations; on exposes the replacement (intentionally hidden surfaces are explicit exceptions).

Cards, Alerts & Banners

  • Cards: group related information with CardContent for sections and CardFooter for actions. Only add CardHeader/CardTitle when surrounding context doesn't already identify the card (e.g. multiple distinct settings cards).
  • Admonition (ui-patterns/Admonition): use <Admonition title="..."> for short (1–2 sentence) callouts or warnings at the top of a page or section — never as a substitute for Card. Consolidate stacked warnings into a single block.
  • Global banners: mount org/app-wide banners in components/interfaces/App/AppBannerWrapper.tsx, not ProjectLayout.

Dialogs & Sheets (Side Panels)

Use a Sheet when switching pages would break context (e.g. editing a row from a list).

  • Compose with SheetHeader/SheetTitle/SheetSection/SheetFooter (SheetContent size="lg" for horizontal forms) or DialogHeader/DialogTitle/DialogSection/DialogFooter (with a separator between DialogHeader and DialogSection).
  • Respect built-in primitive padding and chrome: rely on DialogSection/SheetSection/header built-in spacing instead of overriding or re-padding inner slots, and use DialogFooter/SheetFooter only when real actions exist (omit footers that only duplicate built-in dismissal).
  • Confirmation modals (ui-patterns/Dialogs/ConfirmationModal and ui-patterns/Dialogs/TextConfirmModal for typed-confirmation destructive actions; never window.confirm): keep description concise (put multi-sentence details in children), reserve variant="destructive" for actual data loss, and compose <Dialog> directly for custom multi-action flows rather than adding one-off props.
  • Reset dialog, sheet, and picker state on close or reopen so previous inputs or rejected selections don't leak.
  • Wire dirty form dismissal in sheets/dialogs with useConfirmOnClose + DiscardChangesConfirmationDialog (Cancel, Escape, and backdrop). Source of truth: apps/design-system/content/docs/ui-patterns/modality.mdx.

Accessibility (Three-Modality Parity)

Every interactive control must work across pointer, keyboard, and screen reader with real semantic elements (<h2>–<h4> for headings, <Button asChild><Link> for navigation, never nested <button>s), visible focus, and zero double announcements. Source of truth: apps/design-system/content/docs/accessibility.mdx (focus-ring, focus-inset, focusableWhenDisabled).

  • Icon-only buttons with <Tooltip>: pair aria-label + <Tooltip> + aria-describedby={undefined} with the exact comment // Tooltip repeats the label; screen readers would read it twice. Use contextual row labels (aria-label={`${item.name} actions`}) instead of generic "More options", and keep aria-label synced with dynamic toggle state.
  • <Switch>: give a static descriptive aria-label (e.g. "Cron job active status"), never a dynamic verb toggling "Enable X" / "Disable X" — screen readers already announce on/off state.
  • Tooltips & disabled controls: default <TooltipContent side="bottom">. <TooltipTrigger asChild> must wrap a focusable interactive element (never a <span>, <div>, or icon). Omit tooltips on enabled buttons with descriptive labels; use ButtonTooltip (sets focusableWhenDisabled) or DropdownMenuItemTooltip for disabled controls needing explanation.
  • Focus & dialog parity: pair group-hover:opacity-100 controls inside non-focusable group rows with group-focus-within:opacity-100 and/or focus-visible:opacity-100 (plus data-[state=open]:opacity-100 for menu/popover triggers; group-focus-visible:opacity-100 only works when the group ancestor itself is focusable, such as a <button> or <Link>); restore focus to the trigger button (or DropdownMenuTrigger) when closing state-controlled dialogs; include DialogTitle/SheetTitle and DialogDescription when descriptive copy exists (never pass aria-describedby={undefined} on DialogContent to silence warnings).
  • Screen-reader & i18n markup: omit redundant sr-only when visible text or aria-label already conveys it; keep sr-only inside a relative ancestor (so position: absolute doesn't break scroll containers) and never inside hidden. Add translate="no" on monetary/cost values.

Copy

Follow the copywriting skill and apps/design-system/content/docs/copywriting.mdx for all UI text (and grep e2e/studio/ when changing visible copy).