Blocks Design System

Composition

Server-authored and client-authored code

The package root has no client directive. Static components such as Box, Text, Button, Card and Table render on the server and in client components alike. Interactive components (Tabs, Field, Select, Modal, Menu, NavList, AppLayout and the other Base UI parts) are client components that a Server Component can still render.

  • In a Server Component, import compound parts by name: TabsList, FieldLabel, ModalContent. A Server Component can’t read properties of a client component, so Tabs.List there fails.
  • In a 'use client' file, the dot API works too: Tabs.List, Field.Label. Both spellings are the same components, sharing one context.
  • Event handlers, state and refs belong in client-authored code. A plain submit button in a server-rendered form needs none of them.

Installation shows a Server Component page with a heading and Tabs; Field and Select show both styles.

Controlled and uncontrolled

Interactive components take defaultValue, defaultChecked or defaultOpen to manage themselves, or value/checked/open with a change handler when the caller owns the state.

Changing the element

  • as on Box and the components built on it (Stack, Grid, Measure, Card, Text, Heading, Link, Button) renders another element or component and keeps its props typed: <Box as="nav">, <Link as={NextLink}>. A Server Component can pass a server-local component.
  • render on Base UI parts replaces the rendered element while keeping behavior: a trigger rendered as a Button.
Source · foundations/render-composition.tsx
foundations/render-composition.tsx
'use client'

import { Button, Menu, Popover, Stack } from '@blocks/design-system'

// `render` gives a Base UI part another element; here each trigger is a Button.
export default function RenderComposition() {
  return (
    <Stack direction="row" gap="sm">
      <Menu>
        <Menu.Trigger render={<Button type="button" />}>Station actions</Menu.Trigger>
        <Menu.Content>
          <Menu.Item>Resync</Menu.Item>
        </Menu.Content>
      </Menu>
      <Popover>
        <Popover.Trigger render={<Button type="button" variant="ghost" />}>Station notes</Popover.Trigger>
        <Popover.Content>
          <Popover.Title>Notes</Popover.Title>
          <Popover.Description>Pillow replaced in 2024.</Popover.Description>
        </Popover.Content>
      </Popover>
    </Stack>
  )
}
Triggers rendered as Buttons

Refs, ids and ARIA

Every component forwards ref, id, aria-* and native attributes to its element. Base UI parts wire ids between labels, controls and popups for you.

Escape hatches

Components take no className or style. When you need styling outside the tokens, dangerouslySetClassName and dangerouslySetStyle apply after the component’s own, and are easy to search for.

Mount Hood

Source · foundations/escape-hatches.tsx
foundations/escape-hatches.tsx
import { Card, Heading } from '@blocks/design-system'

// No className or style props: escape hatches say so out loud.
export default function EscapeHatches() {
  return (
    <Card dangerouslySetClassName="station-card-print" dangerouslySetStyle={{ breakInside: 'avoid' }}>
      <Heading as="h3" fontSize="md">
        Mount Hood
      </Heading>
    </Card>
  )
}
Escape hatches

Themes and portals

Popups render in a portal at the end of document.body. Inside a subtree with its own data-ds-theme, pass container to SelectContent, ModalContent or a popover, tooltip or menu’s Content so the popup inherits the theme. See Themes.