|
| 1 | +--- |
| 2 | +title: DocumentProgressCard |
| 3 | +description: Generic card visualising a document's lifecycle state — optional percentage, stacked progress bar, and status legend |
| 4 | +--- |
| 5 | + |
| 6 | +# DocumentProgressCard |
| 7 | + |
| 8 | +`DocumentProgressCard` is a generic, presentational card for communicating the lifecycle/fulfilment state of a document in a record detail right rail. It shows an optional completion percentage, a stacked progress bar, and a legend — driven by an arbitrary set of status `segments`. |
| 9 | + |
| 10 | +It is view-only and domain-agnostic: pass the segments and an explicit `percent`. Any domain-specific math — deriving the percentage, or decomposing overlapping buckets into bar segments — lives in the consumer. See [Example: purchase-order fulfilment](#example-purchase-order-fulfilment) for a complete, copyable pattern. |
| 11 | + |
| 12 | +## Import |
| 13 | + |
| 14 | +```tsx |
| 15 | +import { DocumentProgressCard } from "@tailor-platform/app-shell"; |
| 16 | +``` |
| 17 | + |
| 18 | +## Basic Usage |
| 19 | + |
| 20 | +```tsx |
| 21 | +<DocumentProgressCard |
| 22 | + title="Shipment status" |
| 23 | + percent={60} |
| 24 | + segments={[ |
| 25 | + { label: "Shipped", value: 30, color: "green" }, |
| 26 | + { label: "Returned", value: 3, color: "red" }, |
| 27 | + { label: "Pending", value: 17, color: "neutral" }, |
| 28 | + ]} |
| 29 | +/> |
| 30 | +``` |
| 31 | + |
| 32 | +## Props |
| 33 | + |
| 34 | +| Prop | Type | Default | Description | |
| 35 | +| ----------- | --------------------------- | ------------- | --------------------------------------------------------------------------------------------------------- | |
| 36 | +| `segments` | `DocumentProgressSegment[]` | **Required** | Status segments rendered as a stacked bar (and, by default, the legend). | |
| 37 | +| `title` | `React.ReactNode` | - | Optional card title shown top-left. | |
| 38 | +| `percent` | `number` | - | Optional headline percentage (0–100), shown top-right. Explicit — the generic card derives no progress. | |
| 39 | +| `legend` | `DocumentProgressSegment[]` | `segments` | Optional legend rows; override only when the legend should differ from the bar (see [Legend](#legend)). | |
| 40 | +| `total` | `number` | sum of values | Denominator used to size the bar. A value larger than the segment sum leaves an unfilled track remainder. | |
| 41 | +| `className` | `string` | - | Additional CSS classes for the card root. | |
| 42 | + |
| 43 | +### `DocumentProgressSegment` |
| 44 | + |
| 45 | +| Field | Type | Description | |
| 46 | +| ------- | ----------------------- | ------------------------------------------------------ | |
| 47 | +| `label` | `string` | Legend label. | |
| 48 | +| `value` | `number` | Amount — shown in the legend and used to size the bar. | |
| 49 | +| `color` | `DocumentProgressColor` | Bar / marker color (required). | |
| 50 | + |
| 51 | +`DocumentProgressColor` is one of: `"indigo"`, `"pink"`, `"green"`, `"amber"`, `"red"`, `"blue"`, `"neutral"`. |
| 52 | + |
| 53 | +## Progress Bar |
| 54 | + |
| 55 | +The bar tiles `segments` left-to-right, each sized as `value / (total ?? sum of values)`. When `total` exceeds the segment sum, the shortfall renders as an empty `bg-muted` track — useful for a "remaining" portion you don't want as a colored segment. A `"neutral"` segment reads as a muted/track-like fill. |
| 56 | + |
| 57 | +## Legend |
| 58 | + |
| 59 | +By default the legend mirrors `segments`. Pass `legend` to render different rows — for example when buckets overlap and the bar shows a decomposition while the legend shows the raw figures: |
| 60 | + |
| 61 | +```tsx |
| 62 | +<DocumentProgressCard |
| 63 | + percent={30} |
| 64 | + total={40} |
| 65 | + segments={[ |
| 66 | + { label: "Net received", value: 10, color: "indigo" }, |
| 67 | + { label: "Returned", value: 2, color: "pink" }, |
| 68 | + ]} |
| 69 | + legend={[ |
| 70 | + { label: "Received items", value: 12, color: "indigo" }, |
| 71 | + { label: "Returned items", value: 2, color: "pink" }, |
| 72 | + { label: "Yet to receive", value: 28, color: "neutral" }, |
| 73 | + ]} |
| 74 | +/> |
| 75 | +``` |
| 76 | + |
| 77 | +## Example: purchase-order fulfilment |
| 78 | + |
| 79 | +A common use is communicating a purchase order's receiving state — **received**, **returned**, and **yet to receive**. `DocumentProgressCard` stays generic, so derive the percentage and the bar breakdown in your component and pass them in. This recipe reproduces the recommended look (labels, indigo/pink/neutral colors, and a bar that decomposes received into "kept" + "returned" against the ordered total): |
| 80 | + |
| 81 | +```tsx |
| 82 | +function PurchaseOrderFulfilment({ |
| 83 | + received, |
| 84 | + returned, |
| 85 | + yetToReceive, |
| 86 | + // Whether returned items still count as fulfilled. Set false to subtract them. |
| 87 | + returnedCountsAsComplete = true, |
| 88 | +}: { |
| 89 | + received: number; |
| 90 | + returned: number; |
| 91 | + yetToReceive: number; |
| 92 | + returnedCountsAsComplete?: boolean; |
| 93 | +}) { |
| 94 | + // Returned is a subset of received; clamp so the breakdown can't exceed it. |
| 95 | + const effectiveReturned = Math.min(Math.max(returned, 0), Math.max(received, 0)); |
| 96 | + const total = Math.max(received, 0) + Math.max(yetToReceive, 0); // the ordered quantity |
| 97 | + const complete = returnedCountsAsComplete ? received : received - effectiveReturned; |
| 98 | + const percent = total > 0 ? Math.round((complete / total) * 100) : 0; |
| 99 | + |
| 100 | + return ( |
| 101 | + <DocumentProgressCard |
| 102 | + title="Fulfilment rate" |
| 103 | + percent={percent} |
| 104 | + total={total} // ordered quantity — the shortfall renders as the "yet to receive" track |
| 105 | + // Bar: net received (kept) + returned. Yet-to-receive is the unfilled remainder. |
| 106 | + segments={[ |
| 107 | + { label: "Received items", value: received - effectiveReturned, color: "indigo" }, |
| 108 | + { label: "Returned items", value: effectiveReturned, color: "pink" }, |
| 109 | + ]} |
| 110 | + // Legend: the three buckets as-is, so "Received items" shows the full amount. |
| 111 | + legend={[ |
| 112 | + { label: "Received items", value: received, color: "indigo" }, |
| 113 | + { label: "Returned items", value: returned, color: "pink" }, |
| 114 | + { label: "Yet to receive", value: yetToReceive, color: "neutral" }, |
| 115 | + ]} |
| 116 | + /> |
| 117 | + ); |
| 118 | +} |
| 119 | + |
| 120 | +// <PurchaseOrderFulfilment received={12} returned={2} yetToReceive={28} /> → 30% |
| 121 | +``` |
| 122 | + |
| 123 | +Notes for adapting it: |
| 124 | + |
| 125 | +- **Colors:** `indigo` (received), `pink` (returned), `neutral` (yet to receive) is the recommended set; swap any of the seven palette colors to fit your domain. |
| 126 | +- **Bar vs. legend:** the bar uses `received − returned` so the two colored segments don't double-count the returned items, while the `legend` override keeps "Received items" showing the full received figure. |
| 127 | +- **`total`:** pass the ordered quantity so the unfilled portion of the bar represents "yet to receive". Omit it (or use the segment sum) if you want a fully-tiled bar instead. |
| 128 | +- **Percentage policy:** flip `returnedCountsAsComplete` to decide whether returned items count toward completion. |
| 129 | + |
| 130 | +## Input handling |
| 131 | + |
| 132 | +Segment values are expected to be non-negative numbers. Non-finite or negative values are coerced to `0`, and `percent` is rounded and clamped to `[0, 100]`. |
| 133 | + |
| 134 | +## Related |
| 135 | + |
| 136 | +- [MetricCard](metric-card) — Compact KPI summary card. |
| 137 | +- [Card](card) — The underlying card primitive. |
0 commit comments