Components / DataStable

Tile

A soft pastel block that names one thing, with a short caption and art in the corner. It opens a screen or shows a headline number.

View as Markdown

Playground

Colour

48 tokens

Code

Tile.tsx
import type { ReactNode } from 'react'

// Nacre Tile: a soft pastel block that names one thing and shows its main number or a piece of art. React plus
// Tailwind classes only; needs nacre-theme.css. The fill is a vertical gradient from the tint to its wash, and the
// text uses the tint's own ink, so it stays readable in both themes. No motion. Put tiles in a Panel, two to a row.

export type TileTint = 'lime' | 'pink' | 'blue' | 'violet'
export type TileSize = 'md' | 'lg'
export type TileArtPlacement = 'corner' | 'bleed' | 'top' | 'top-end'
export type TileArtSize = 'md' | 'sm' | 'lg'

export type TileProps = {
  tint: TileTint
  /** The name or number. Leave it out for a tile that is only art and one action. */
  title?: string
  caption?: string
  /** md is a name (Colour); lg is a headline number (86%). */
  size?: TileSize
  /** Art in the lower end corner: a 3D icon, an illustration, a ring. Decorative, so it is hidden from assistive tech. */
  art?: ReactNode
  /** corner (default) puts the art in the lower end corner, top centres it at the top of the tile. */
  artPlacement?: TileArtPlacement
  /** md is 112 px; sm is 44 px, for a narrow tile where the art must sit inside the padding and clear the text; lg is 128 px, meant to bleed off the corner. */
  artSize?: TileArtSize
  /** Extra content under the caption, such as a button or a short list. */
  children?: ReactNode
  className?: string
}

const tints: Record<TileTint, string> = {
  lime: 'bg-linear-to-b from-tint-lime to-tint-lime-wash text-tint-lime-ink',
  pink: 'bg-linear-to-b from-tint-pink to-tint-pink-wash text-tint-pink-ink',
  blue: 'bg-linear-to-b from-tint-blue to-tint-blue-wash text-tint-blue-ink',
  violet: 'bg-linear-to-b from-tint-violet to-tint-violet-wash text-tint-violet-ink',
}

const titles: Record<TileSize, string> = {
  md: 'text-[1.0625rem] leading-6 font-[600] tracking-[-0.015em]',
  lg: 'text-[1.875rem] leading-[1.15] font-[600] tracking-[-0.025em]',
}

const arts: Record<TileArtPlacement, string> = {
  corner: '-end-1 -bottom-1',
  bleed: '-end-4 -bottom-4',
  top: 'top-1 start-1/2 -translate-x-1/2 rtl:translate-x-1/2',
  'top-end': 'top-2.5 end-3',
}
const artSizes: Record<TileArtSize, string> = { md: 'size-28', sm: 'size-11', lg: 'size-32' }

export function Tile({ tint, title, caption, size = 'md', art, artPlacement = 'corner', artSize = 'md', children, className = '' }: TileProps) {
  return (
    <div data-part="root" data-tint={tint} className={`relative isolate flex min-h-36 min-w-0 flex-col overflow-hidden rounded-lg p-4 ${tints[tint]} ${className}`}>
      {title && <p data-part="title" className={titles[size]}>{title}</p>}
      {caption && <p data-part="caption" className="text-label font-[500]">{caption}</p>}
      {children}
      {art && (
        <div data-part="art" aria-hidden="true" className={`pointer-events-none absolute grid ${artSizes[artSize]} place-items-center [&>*]:size-full [&>*]:object-contain ${arts[artPlacement]}`}>
          {art}
        </div>
      )}
    </div>
  )
}

Usage

When to use

  • Entry points on a home screen: Colour, Spacing, Buttons, each a tile with its count.
  • One headline number: 86% token coverage, 12 open changes.

Choose something else when

  • It lists rows or holds several values: use Panel.
  • It reports a status inline: use Badge.
  • It must stand out as the main call to action: use Button.

In the Nacre workspace

Token categories

A Panel holds a row of two tiles, Colour in lime and Spacing in blue, each with the number of tokens and a glass icon.

Headline metric

A single violet tile reads 12 open changes with a ring in the corner. It is the only tile on the screen, so the number is the first thing seen.

Do and don't

  • DoGive each tint one meaning on a screen: lime for ready, pink for talk.

    Don'tUse all four tints at once with no meaning behind them.

  • DoKeep the title to a few words and the caption to one short line.

    Don'tWrap a paragraph into a tile; link to the page that has it.

Anatomy

Colour

48 tokens

  1. Tile. Radius lg (22 px), 16 px padding, a vertical gradient from the tint to its wash, minimum height 144 px.
  2. Title. Text 17/24 at weight 600 in the tint ink, tracking -0.015em.
  3. Caption. Label 13/16 at weight 500 in the same ink.
  4. Art. 96 px square in the lower end corner, bleeding 4 px past the edge. Decorative.

API

tintType 'lime' | 'pink' | 'blue' | 'violet'Default -Required. Picks the gradient and the ink. The tile never takes any other colour.
titleType stringDefault -Required. The name or the number: Colour, 86%.
captionType stringDefault -A line under the title: 48 tokens.
sizeType 'md' | 'lg'Default -md (default) is a name such as Colour. lg is a headline number such as 86%: 34 px at weight 600.
artType ReactNodeDefault -Art in the lower end corner, 96 px square, hidden from assistive tech. It draws with the ink colour unless it is an image.
artPlacementType 'corner' | 'top' | 'top-end'Default -corner (default) puts the art in the lower end corner. top centres it at the top, for a tile that holds a button below. top-end sits inside the padding at the top end, for a stat tile.
artSizeType 'md' | 'sm'Default 'md'md is 96 px. sm is 44 px, for a narrow tile where the art must clear the text and sit inside the padding.
childrenType ReactNodeDefault -Extra content under the caption, such as a button or a short list.
classNameType stringDefault -Extra classes on the tile, such as a height.

Motion

NoneProperty none: a static surface. A tile that links uses the link-card lift of its parentDuration none 0Easing outKeyboard Same.

Colour

48 tokens

Accessibility

Keyboard

Tab
A tile is not focusable. Wrap it in a link or button, or put a Chip beside it, when it opens something.

ARIA and semantics

  • The art is aria-hidden: it repeats what the title says.
  • The title and caption are plain paragraphs, so a tile inside a link reads as one name.

Contrast

Lime title and caption, top of the gradienttint-lime-ink on tint-limeLight 6.82:1Dark 7.04:1Needs 4.5:1
Lime text, bottom of the gradienttint-lime-ink on tint-lime-washLight 7.76:1Dark 8.10:1Needs 4.5:1
Pink title and captiontint-pink-ink on tint-pinkLight 7.14:1Dark 7.10:1Needs 4.5:1
Pink text, bottom of the gradienttint-pink-ink on tint-pink-washLight 8.30:1Dark 8.62:1Needs 4.5:1
Blue title and captiontint-blue-ink on tint-blueLight 6.21:1Dark 6.07:1Needs 4.5:1
Blue text, bottom of the gradienttint-blue-ink on tint-blue-washLight 8.85:1Dark 8.82:1Needs 4.5:1
Violet title and captiontint-violet-ink on tint-violetLight 8.17:1Dark 7.79:1Needs 4.5:1
Violet text, bottom of the gradienttint-violet-ink on tint-violet-washLight 9.99:1Dark 9.90:1Needs 4.5:1