# Panel

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

Status: Stable. Group: Data.

## 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.

## When not to use

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

## Scenarios

### 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 avoid

- Do: Group by ground, panel, well: one level of white, one level of grey inside it.
- Avoid: Nest a bordered box inside a box inside a panel.
- Do: Name the panel with a short title.
- Avoid: Leave a titled region without a heading; set title so it is a named region.

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `title` | `string` |  | The heading, an h2. With a title the panel is a section named by it. |
| `action` | `PanelAction` |  | One header action: label, plus href or onClick. Drawn as a Chip with a chevron at the end of the header. |
| `level` | `2 \| 3 \| 4` |  | The heading level, 2 by default. Use 3 or 4 when the panel sits under a screen heading. |
| `as` | `'section' \| 'div'` |  | section (default) is a named region when it has a title. div adds no landmark, for a panel in a busy screen. |
| `children` | `ReactNode` |  | The rows, tiles or wells inside. |
| `className` | `string` |  | Extra classes on the panel. |

## Anatomy

1. Panel (`data-part="root"`): Surface, radius xl (28 px), 6 px padding and a 1 px line-subtle ring. No shadow.
2. Header (`data-part="header"`): A row at least 48 px high with the title at the start and the Chip at the end.
3. Title (`data-part="title"`): Text 18/24 at weight 600 in fg-strong, tracking -0.015em.

## Motion

| Interaction | Property | Duration | Easing | From the keyboard |
| --- | --- | --- | --- | --- |
| None | none: a static surface. The Chip in the header has its own hover | none | out | Same. |

## Accessibility

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

- 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.

## Code

### Panel.tsx

```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

```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>
}
```

## HTML

The default example as plain HTML, for any stack. Needs nacre-theme.css.

```html
<section data-part="root" aria-labelledby="_R_0_-title" class="flex min-w-0 flex-col rounded-xl bg-surface p-1.5 ring-1 ring-line-subtle ">
  <div data-part="header" class="flex min-h-12 items-center justify-between gap-3 ps-3 pe-1.5">
    <h2 id="_R_0_-title" data-part="title" class="min-w-0 text-[1.125rem] leading-6 font-[600] tracking-[-0.015em] text-fg-strong">Active audits</h2>
    <button type="button" data-part="root" class="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 ms-auto">
      View all
      <svg data-part="chevron" aria-hidden="true" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" class="-me-1 size-4 rtl:scale-x-[-1]">
        <path d="M6.5 4l4 4-4 4"></path>
      </svg>
    </button>
  </div>
  <div data-part="root" data-tint="lime" class="relative isolate flex min-h-36 min-w-0 flex-col overflow-hidden rounded-lg p-4 bg-linear-to-b from-tint-lime to-tint-lime-wash text-tint-lime-ink w-44">
    <p data-part="title" class="text-[1.0625rem] leading-6 font-[600] tracking-[-0.015em]">Colour</p>
    <p data-part="caption" class="text-label font-[500]">48 tokens</p>
    <div data-part="art" aria-hidden="true" class="pointer-events-none absolute grid size-28 place-items-center [&amp;&gt;*]:size-full [&amp;&gt;*]:object-contain -end-1 -bottom-1">
      <svg viewBox="0 0 96 96" fill="none" stroke="currentColor" stroke-width="9" stroke-linecap="round">
        <circle cx="48" cy="48" r="32" opacity="0.22"></circle>
        <path d="M48 16a32 32 0 0 1 30.4 41.8"></path>
      </svg>
    </div>
  </div>
</section>
```

## Related

- [Chip](https://enxm.me/services/design-systems/nacre/components/chip)
- [Table](https://enxm.me/services/design-systems/nacre/components/table)
- [Tile](https://enxm.me/services/design-systems/nacre/components/tile)
