{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pipeline-01",
  "description": "A board with a column for each stage showing its item count, total value and weighted value, and a card for each item that can be moved from its menu or opened beside the board; on a phone, one stage at a time.",
  "registryDependencies": [
    "button",
    "dropdown-menu",
    "https://www.dashboardblocks.com/r/radix/announcements.json",
    "https://www.dashboardblocks.com/r/radix/attempt.json",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/pipeline.json",
    "https://www.dashboardblocks.com/r/radix/tag.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/pipeline/pipeline-01.tsx",
      "content": "'use client'\n\nimport {\n  Announcements,\n  useAnnouncements,\n} from '@/registry/components/dashboardblocks/announcements'\nimport {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateRows,\n  BlockStateText,\n  type BlockStateProps,\n  Skeleton,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  PipelineCard,\n  type PipelineItem,\n  type PipelineStage,\n  PipelineStageHeader,\n  getDaysInStage,\n  getStageColor,\n  getStageSummaries,\n} from '@/registry/components/dashboardblocks/pipeline'\nimport { Tag } from '@/registry/components/dashboardblocks/tag'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { attempt } from '@/registry/lib/dashboardblocks/attempt'\nimport { formatCurrency } from '@/registry/lib/dashboardblocks/format'\nimport { startTransition, useEffect, useId, useMemo, useRef, useState } from 'react'\n\nimport { Button } from '@/components/ui/button'\nimport {\n  DropdownMenu,\n  DropdownMenuContent,\n  DropdownMenuGroup,\n  DropdownMenuLabel,\n  DropdownMenuRadioGroup,\n  DropdownMenuRadioItem,\n  DropdownMenuTrigger,\n} from '@/components/ui/dropdown-menu'\n\nimport { cn } from '@/lib/utils'\n\ninterface Pipeline1Props extends BlockStateProps {\n  /** Defaults to a sentence with the open value and how many items are stuck. */\n  description?: string\n  /** Leave out, or pass none, to show the empty state. */\n  items?: PipelineItem[]\n  now: Date\n  /** Moves an item to another stage. Resolve `{ status: 'error', message }` to refuse: the item goes back and the message shows. */\n  onMove?: (\n    id: string,\n    stage: string,\n  ) => void | Promise<void | { message: string; status: 'error' }>\n  /** An item's own page. With it, each card is a link, so it opens in a new tab with Cmd or Ctrl, and a plain click calls `onOpen`. */\n  getHref?: (id: string) => string\n  /** Opens an item, such as in a panel beside the board. With it, the whole card is a button. */\n  onOpen?: (id: string) => void\n  /** The item open beside the board, drawn muted. */\n  openId?: string\n  stages: PipelineStage[]\n  title: string\n}\n\nconst NOW = Date.UTC(2026, 8, 25, 14, 30)\nconst noItems: PipelineItem[] = []\n\nconst daysAgo = (days: number) => new Date(NOW - days * 86_400_000)\n\nconst exampleProps: Pipeline1Props = {\n  items: [\n    {\n      enteredStageAt: daysAgo(5),\n      id: 'd1',\n      owner: 'Maya Patel',\n      ownerAvatar: '/images/avatar-16.webp',\n      stage: 'qualified',\n      subtitle: 'Fleet analytics rollout',\n      title: 'Northwind Logistics',\n      value: 42_000,\n    },\n    {\n      enteredStageAt: daysAgo(21),\n      id: 'd2',\n      owner: 'Luis Romero',\n      ownerAvatar: '/images/avatar-13.webp',\n      stage: 'qualified',\n      subtitle: 'Patient portal pilot',\n      title: 'Brightline Health',\n      value: 18_500,\n    },\n    {\n      enteredStageAt: daysAgo(3),\n      id: 'd3',\n      owner: 'Aiko Tanaka',\n      ownerAvatar: '/images/avatar-09.webp',\n      stage: 'qualified',\n      subtitle: 'Supplier dashboard',\n      title: 'Orbital Foods',\n      value: 27_000,\n    },\n    {\n      enteredStageAt: daysAgo(8),\n      id: 'd4',\n      owner: 'Jonas Weber',\n      ownerAvatar: '/images/avatar-07.webp',\n      stage: 'discovery',\n      subtitle: 'Risk reporting suite',\n      title: 'Kestrel Bank',\n      value: 96_000,\n    },\n    {\n      enteredStageAt: daysAgo(16),\n      id: 'd5',\n      owner: 'Maya Patel',\n      ownerAvatar: '/images/avatar-16.webp',\n      stage: 'discovery',\n      subtitle: 'District licences',\n      title: 'Pinecrest Schools',\n      value: 31_200,\n    },\n    {\n      enteredStageAt: daysAgo(2),\n      id: 'd6',\n      owner: 'Luis Romero',\n      ownerAvatar: '/images/avatar-13.webp',\n      stage: 'discovery',\n      subtitle: 'Booking insights',\n      title: 'Halcyon Travel',\n      value: 54_000,\n    },\n    {\n      enteredStageAt: daysAgo(6),\n      id: 'd7',\n      owner: 'Aiko Tanaka',\n      ownerAvatar: '/images/avatar-09.webp',\n      stage: 'proposal',\n      subtitle: 'Enterprise plan, 400 seats',\n      title: 'Atlas Freight',\n      value: 128_000,\n    },\n    {\n      enteredStageAt: daysAgo(12),\n      id: 'd8',\n      owner: 'Jonas Weber',\n      ownerAvatar: '/images/avatar-07.webp',\n      stage: 'proposal',\n      subtitle: 'Data warehouse sync',\n      title: 'Meridian Labs',\n      value: 64_500,\n    },\n    {\n      enteredStageAt: daysAgo(4),\n      id: 'd9',\n      owner: 'Maya Patel',\n      ownerAvatar: '/images/avatar-16.webp',\n      stage: 'proposal',\n      subtitle: 'Usage metering',\n      title: 'Solstice Energy',\n      value: 39_900,\n    },\n    {\n      enteredStageAt: daysAgo(3),\n      id: 'd10',\n      owner: 'Jonas Weber',\n      ownerAvatar: '/images/avatar-07.webp',\n      stage: 'negotiation',\n      subtitle: 'Multi-region renewal',\n      title: 'Vantage Retail',\n      value: 212_000,\n    },\n    {\n      enteredStageAt: daysAgo(11),\n      id: 'd11',\n      owner: 'Luis Romero',\n      ownerAvatar: '/images/avatar-13.webp',\n      stage: 'negotiation',\n      subtitle: 'Claims analytics',\n      title: 'Copperleaf Insurance',\n      value: 87_000,\n    },\n  ],\n  now: new Date(NOW),\n  stages: [\n    { expectedDays: 14, id: 'qualified', label: 'Qualified', probability: 0.1 },\n    {\n      expectedDays: 10,\n      id: 'discovery',\n      label: 'Discovery',\n      probability: 0.25,\n    },\n    { expectedDays: 10, id: 'proposal', label: 'Proposal', probability: 0.5 },\n    {\n      expectedDays: 7,\n      id: 'negotiation',\n      label: 'Negotiation',\n      probability: 0.75,\n    },\n  ],\n  title: 'Sales pipeline',\n}\n\nconst compact = (value: number) => formatCurrency(value, { compact: true })\n\nconst Pipeline1 = (props: Pipeline1Props) => {\n  const {\n    items: loadedItems = noItems,\n    now,\n    onMove,\n    getHref,\n    onOpen,\n    openId,\n    stages,\n    errorMessage,\n    status,\n    title,\n  } = props\n  const id = useId()\n  const [moves, setMoves] = useState<{ id: string; key: number; stage: string }[]>([])\n  const [refusal, setRefusal] = useState<string>()\n  const [said, announce] = useAnnouncements()\n  const stageOf = (itemId?: string) =>\n    loadedItems.find((item) => item.id === itemId)?.stage\n  const [pickedStage, setShownStage] = useState(() => stageOf(openId) ?? stages[0]?.id)\n  const [seenOpen, setSeenOpen] = useState(openId)\n  if (openId !== seenOpen) {\n    setSeenOpen(openId)\n    const openStage = stageOf(openId)\n    if (openStage) setShownStage(openStage)\n  }\n  const shownStage = stages.some((stage) => stage.id === pickedStage)\n    ? pickedStage\n    : stages[0]?.id\n  const board = useRef<HTMLDivElement>(null)\n  const shownOpen = useRef<string | undefined>(undefined)\n  const moveCount = useRef(0)\n\n  useEffect(() => {\n    if (openId === shownOpen.current) return\n    const closed = shownOpen.current\n    shownOpen.current = openId\n    if (openId === undefined) {\n      board.current\n        ?.querySelector<HTMLElement>(\n          `[data-item=\"${CSS.escape(closed ?? '')}\"] [data-slot=pipeline-card-trigger]`,\n        )\n        ?.focus({ preventScroll: true })\n      return\n    }\n    board.current\n      ?.querySelector('[data-open]')\n      ?.scrollIntoView({ block: 'nearest', inline: 'nearest' })\n  }, [openId])\n  const state = getBlockState(status, loadedItems)\n  const items = useMemo(\n    () =>\n      moves.reduce((current, moved) => {\n        const item = current.find((other) => other.id === moved.id)\n        if (!item) return current\n        return [\n          { ...item, enteredStageAt: now, stage: moved.stage },\n          ...current.filter((other) => other.id !== moved.id),\n        ]\n      }, loadedItems),\n    [loadedItems, moves, now],\n  )\n  const summaries = getStageSummaries(stages, items, now)\n  const total = summaries.reduce((sum, stage) => sum + stage.value, 0)\n  const stuck = summaries.reduce((sum, stage) => sum + stage.stuck, 0)\n  const {\n    description = `${items.length} open ${items.length === 1 ? 'deal' : 'deals'} worth ${compact(total)}; ${stuck === 0 ? 'none' : stuck} past their stage’s time limit.`,\n  } = props\n\n  const weighted = stages.some((stage) => stage.probability !== undefined)\n\n  const move = async (item: PipelineItem, stage: PipelineStage) => {\n    if (item.stage === stage.id) return\n    moveCount.current += 1\n    const key = moveCount.current\n    setMoves((current) => [...current, { id: item.id, key, stage: stage.id }])\n    setRefusal(undefined)\n    announce(`Moved ${item.title} to ${stage.label}`)\n    if (!onMove) return\n    const result = await attempt(() => onMove(item.id, stage.id))\n    startTransition(() => {\n      setMoves((current) => current.filter((moved) => moved.key !== key))\n      if (result?.status !== 'error') return\n      setRefusal(result.message)\n      announce(`${item.title} wasn’t moved. ${result.message}`)\n    })\n  }\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <section className='@container flex flex-col gap-4'>\n        <header className='flex flex-col gap-0.5'>\n          <h2 className='font-semibold tracking-tight'>{title}</h2>\n          <BlockReady className='text-sm'>\n            <p className='text-muted-foreground text-sm'>{description}</p>\n          </BlockReady>\n        </header>\n        <Announcements said={said} />\n        {refusal && <p className='text-destructive text-sm'>{refusal}</p>}\n        {(state === 'empty' || state === 'error') && (\n          <BlockStateRows className='border-t pt-3' />\n        )}\n        {(state === undefined || state === 'loading') && (\n          <div\n            role='group'\n            aria-label='Show stage'\n            className='flex gap-1 overflow-x-auto p-1 [scrollbar-width:thin] @2xl:hidden'\n          >\n            {summaries.map((stage) => (\n              <Button\n                key={stage.id}\n                aria-pressed={shownStage === stage.id}\n                onClick={() => setShownStage(stage.id)}\n                size='sm'\n                variant={shownStage === stage.id ? 'secondary' : 'ghost'}\n              >\n                {stage.label}\n                {state === undefined && <Tag>{stage.count}</Tag>}\n              </Button>\n            ))}\n          </div>\n        )}\n        {(state === undefined || state === 'loading') && (\n          <div\n            ref={board}\n            role='region'\n            aria-label={`${title} board`}\n            // oxlint-disable-next-line jsx-a11y/no-noninteractive-tabindex -- a scrolling region must be focusable so keyboard users can reach the columns that don't fit\n            tabIndex={0}\n            className='focus-visible:ring-ring/50 relative flex snap-x snap-mandatory gap-4 overflow-x-auto outline-none [scrollbar-width:thin] focus-visible:ring-3'\n          >\n            <BlockStateText className='sr-only' />\n            {summaries.map((stage, index) => {\n              const headingId = `${id}-${stage.id}`\n              const stageItems = items.filter((item) => item.stage === stage.id)\n              return (\n                <section\n                  key={stage.id}\n                  aria-labelledby={headingId}\n                  className={cn(\n                    'w-full shrink-0 snap-start flex-col gap-3 border-t pt-3 @2xl:flex @2xl:w-64 @4xl:w-auto @4xl:min-w-0 @4xl:flex-1',\n                    shownStage === stage.id ? 'flex' : 'hidden',\n                  )}\n                >\n                  <PipelineStageHeader\n                    color={getStageColor(index, stages.length)}\n                    count={state ? undefined : stage.count}\n                    id={headingId}\n                    label={stage.label}\n                    total={\n                      state\n                        ? undefined\n                        : weighted\n                          ? `${compact(stage.value)}, ${compact(stage.weighted)} weighted`\n                          : compact(stage.value)\n                    }\n                  />\n                  {state === 'loading' ? (\n                    <div className='flex flex-col gap-2'>\n                      <Skeleton className='h-24 rounded-xl' />\n                      <Skeleton className='h-24 rounded-xl' />\n                    </div>\n                  ) : stageItems.length > 0 ? (\n                    <ul aria-labelledby={headingId} className='flex flex-col gap-2'>\n                      {stageItems.map((item) => {\n                        const days = getDaysInStage(item.enteredStageAt, now)\n                        return (\n                          <li key={item.id} data-item={item.id}>\n                            <PipelineCard\n                              action={\n                                <MoveMenu\n                                  item={item}\n                                  onMove={(target) => void move(item, target)}\n                                  stages={stages}\n                                />\n                              }\n                              days={days}\n                              expectedDays={stage.expectedDays}\n                              href={getHref?.(item.id)}\n                              onOpen={onOpen && (() => onOpen(item.id))}\n                              open={openId === item.id}\n                              owner={item.owner}\n                              ownerAvatar={item.ownerAvatar}\n                              subtitle={item.subtitle}\n                              title={item.title}\n                              value={\n                                item.value !== undefined ? compact(item.value) : undefined\n                              }\n                            />\n                          </li>\n                        )\n                      })}\n                    </ul>\n                  ) : (\n                    <p className='text-muted-foreground rounded-xl border border-dashed px-3 py-6 text-center text-xs'>\n                      No deals in {stage.label.toLowerCase()}\n                    </p>\n                  )}\n                </section>\n              )\n            })}\n          </div>\n        )}\n      </section>\n    </BlockStateProvider>\n  )\n}\n\nfunction MoveMenu({\n  item,\n  onMove,\n  stages,\n}: {\n  item: PipelineItem\n  onMove: (stage: PipelineStage) => void\n  stages: PipelineStage[]\n}) {\n  return (\n    <DropdownMenu modal={false}>\n      <DropdownMenuTrigger asChild>\n        <Button aria-label={`Move ${item.title}`} size='icon-xs' variant='ghost'>\n          <IconPlaceholder\n            lucide='EllipsisIcon'\n            tabler='IconDots'\n            hugeicons='MoreHorizontalCircle01Icon'\n            phosphor='DotsThreeOutlineIcon'\n            remixicon='RiMoreLine'\n          />\n        </Button>\n      </DropdownMenuTrigger>\n      <DropdownMenuContent align='end' className='w-auto min-w-40'>\n        <DropdownMenuGroup>\n          <DropdownMenuLabel>Move to</DropdownMenuLabel>\n          <DropdownMenuRadioGroup\n            value={item.stage}\n            onValueChange={(value) => {\n              const stage = stages.find((candidate) => candidate.id === value)\n              if (stage) onMove(stage)\n            }}\n          >\n            {stages.map((stage) => (\n              <DropdownMenuRadioItem key={stage.id} value={stage.id}>\n                {stage.label}\n              </DropdownMenuRadioItem>\n            ))}\n          </DropdownMenuRadioGroup>\n        </DropdownMenuGroup>\n      </DropdownMenuContent>\n    </DropdownMenu>\n  )\n}\n\nexport { Pipeline1, exampleProps as pipeline1ExampleProps, type Pipeline1Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/pipeline/pipeline-01.tsx"
    }
  ],
  "meta": {
    "shows": "A board with a column for each stage showing its item count, total value and weighted value, and a card for each item that can be moved from its menu or opened beside the board; on a phone, one stage at a time.",
    "size": "full",
    "usedWith": [
      "pipeline-02",
      "pipeline-03",
      "funnel-01"
    ],
    "component": "Pipeline1",
    "props": "{ description?: string; items?: { enteredStageAt: Date; id: string; owner?: string; ownerAvatar?: string; stage: string; subtitle?: string; title: string; value?: number }[]; now: Date; onMove?: (id: string, stage: string) => void | Promise<void | { message: string; status: \"error\" }>; getHref?: (id: string) => string; onOpen?: (id: string) => void; openId?: string; stages: { expectedDays?: number; id: string; label: string; probability?: number }[]; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
