Components / DataStable

Panel

A white group for one theme of related rows or tiles, with an optional header that holds a title and one Chip action.

View as Markdown

Playground

Active audits

  • Checkout flow audit28 screens, 17 findings
  • Onboarding audit14 screens, 6 findings

Code

Panel.tsx
import { useId, type MouseEventHandler, type ReactNode } from 'react'
import { Chip } from './Chip'

// Nacre Panel: a white group that holds one theme of related rows or wells, with an optional header (a title and one
// Chip action). React plus Tailwind classes only; needs nacre-theme.css and Chip.tsx. One level of grouping:
// ground, panel, well. Keep a well's content flat: never put a bordered box inside a box inside a panel. No motion.

export type PanelAction = {
  label: string
  href?: string
  onClick?: MouseEventHandler<HTMLElement>
}

export type PanelProps = {
  /** The heading. With a title the panel is a named region. */
  title?: string
  /** One quiet action at the end of the header, drawn as a Chip with a chevron. */
  action?: PanelAction
  /** The heading level, 2 by default. Use 3 or 4 when the panel sits under a screen heading. */
  level?: 2 | 3 | 4
  /** section (default) is a named region when it has a title; div adds no landmark, for a panel in a busy screen. */
  as?: 'section' | 'div'
  children: ReactNode
  className?: string
}

export function Panel({ title, action, level = 2, as: Root = 'section', children, className = '' }: PanelProps) {
  const id = useId()
  const named = Root === 'section' && Boolean(title)
  const Heading = `h${level}` as 'h2'
  return (
    <Root
      data-part="root"
      aria-labelledby={named ? `${id}-title` : undefined}
      className={`flex min-w-0 flex-col rounded-xl bg-surface p-1.5 ring-1 ring-line-subtle ${className}`}
    >
      {(title || action) && (
        <div data-part="header" className="flex min-h-12 items-center justify-between gap-3 ps-3 pe-1.5">
          {title && <Heading id={`${id}-title`} data-part="title" className="min-w-0 text-[1.125rem] leading-6 font-[600] tracking-[-0.015em] text-fg-strong">{title}</Heading>}
          {action && <Chip chevron href={action.href} onClick={action.onClick} className="ms-auto">{action.label}</Chip>}
        </div>
      )}
      {children}
    </Root>
  )
}
Chip.tsx
import type { MouseEventHandler, ReactNode } from 'react'

// Nacre Chip: a small pill that starts one quiet action, such as View all in a panel header. React plus Tailwind
// classes only; needs nacre-theme.css. A link when it has an href, otherwise a button. Motion: colour quick 160 out on
// hover; the press scale comes from the Nacre base (pointer only, motion-safe).

export type ChipProps = {
  children: ReactNode
  /** Shows a chevron after the label, for a chip that goes somewhere. */
  chevron?: boolean
  /** Makes the chip a link. */
  href?: string
  onClick?: MouseEventHandler<HTMLElement>
  disabled?: boolean
  className?: string
}

const base =
  'inline-flex h-9 shrink-0 cursor-pointer items-center gap-1 rounded-full bg-sunken px-3.5 text-body font-[600] whitespace-nowrap text-fg ' +
  'transition-colors duration-(--nx-dur-quick) ease-out hover:bg-[color-mix(in_oklab,var(--nx-fg)_7%,var(--nx-sunken))] hover:text-fg-strong ' +
  'focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus disabled:cursor-not-allowed disabled:text-fg-disabled'

export function Chip({ children, chevron = false, href, onClick, disabled = false, className = '' }: ChipProps) {
  const content = (
    <>
      {children}
      {chevron && (
        <svg data-part="chevron" aria-hidden="true" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" className="-me-1 size-4 rtl:scale-x-[-1]">
          <path d="M6.5 4l4 4-4 4" />
        </svg>
      )}
    </>
  )
  if (href && !disabled) {
    return <a href={href} data-part="root" data-press="" onClick={onClick} className={`${base} ${className}`}>{content}</a>
  }
  return <button type="button" data-part="root" disabled={disabled} onClick={onClick} className={`${base} ${className}`}>{content}</button>
}

Usage

When to use

  • A section of a phone screen: Active audits, This week, with a View all chip.
  • A set of tiles or rows that belong together, so the page behind stays a single quiet ground.

Choose something else when

  • The content is one number or one entry point: use Tile.
  • The group needs columns and sorting: use Table.
  • It would sit inside another panel: use a plain well (a sunken row), not a second panel.

In the Nacre workspace

Active audits

A Panel titled Active audits holds two rows. Its header ends with a View all chip that opens the audit list.

Token categories

A Panel with no header holds a row of two Tiles. The white frame ties them together on the grey page.

Do and don't

  • DoGroup by ground, panel, well: one level of white, one level of grey inside it.

    Don'tNest a bordered box inside a box inside a panel.

  • DoName the panel with a short title.

    Don'tLeave a titled region without a heading; set title so it is a named region.

Anatomy

Active audits

  • Checkout flow audit28 screens, 17 findings
  • Onboarding audit14 screens, 6 findings
  1. Panel. Surface, radius xl (28 px), 6 px padding and a 1 px line-subtle ring. No shadow.
  2. Header. A row at least 48 px high with the title at the start and the Chip at the end.
  3. Title. Text 18/24 at weight 600 in fg-strong, tracking -0.015em.

API

titleType stringDefault -The heading, an h2. With a title the panel is a section named by it.
actionType PanelActionDefault -One header action: label, plus href or onClick. Drawn as a Chip with a chevron at the end of the header.
levelType 2 | 3 | 4Default -The heading level, 2 by default. Use 3 or 4 when the panel sits under a screen heading.
asType 'section' | 'div'Default -section (default) is a named region when it has a title. div adds no landmark, for a panel in a busy screen.
childrenType ReactNodeDefault -The rows, tiles or wells inside.
classNameType stringDefault -Extra classes on the panel.

Motion

NoneProperty none: a static surface. The Chip in the header has its own hoverDuration none 0Easing outKeyboard Same.

Active audits

  • Checkout flow audit28 screens, 17 findings
  • Onboarding audit14 screens, 6 findings

Accessibility

Keyboard

Tab
A panel is not focusable. Focus goes to its Chip and the controls inside it, in reading order.

ARIA and semantics

  • With a title the panel is a section (a named region) labelled by the h2.
  • The h2 keeps heading order: put the panel under a level 1 heading.

Contrast

Title on the panelfg-strong on surfaceLight 19.01:1Dark 16.29:1Needs 4.5:1
Chip labelfg on sunkenLight 13.79:1Dark 13.55:1Needs 4.5:1