Cairn

Segmented Bar

Stable

A horizontal share-of-total, split into labelled parts. Grayscale by default; hue is opt-in via scale.

  • scale: mono
  • categorical
  • sequential

Grayscale by default

  • Direct
  • Search
  • Social
  • Referral

Categorical (opt-in, ≤ 4)

  • Idle
  • Queue
  • Processing
  • Error
Show code
import { SegmentedBar } from '@six-vallees/ui-react';

export default function SegmentedBarDemo() {
  // Grayscale by default: the active part is ink, the rest recede to a muted tint (with a keyline).
  const share = [
    { label: 'Direct', value: 42, active: true },
    { label: 'Search', value: 28 },
    { label: 'Social', value: 18 },
    { label: 'Referral', value: 12 },
  ];
  // Categorical is opt-in, for genuinely unordered categories (capped at 4).
  const mix = [
    { label: 'Idle', value: 10 },
    { label: 'Queue', value: 35.5 },
    { label: 'Processing', value: 45, active: true },
    { label: 'Error', value: 9.5 },
  ];
  return (
    <div className="flex w-full max-w-[520px] flex-col gap-8 text-on-surface">
      <div>
        <p className="mb-3 sv-body-sm text-on-surface-variant">Grayscale by default</p>
        <SegmentedBar data={share} />
      </div>
      <div>
        <p className="mb-3 sv-body-sm text-on-surface-variant">Categorical (opt-in, ≤ 4)</p>
        <SegmentedBar data={mix} scale="categorical" />
      </div>
    </div>
  );
}

Installation

npx shadcn@latest add https://cairn.sixvallees.com/r/segmented-bar.json