@squadbase/vantage 0.6.1-dev2.5f947f1 → 0.6.2-dev1.1c9e8bc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. package/dist/add-4GHF2TX2.js +6 -0
  2. package/dist/add-4GHF2TX2.js.map +1 -0
  3. package/dist/{build-O5TVNH4E.js → build-X5NVCQKT.js} +9 -9
  4. package/dist/{build-O5TVNH4E.js.map → build-X5NVCQKT.js.map} +1 -1
  5. package/dist/{check-WFBEDHDR.js → check-ZBIH422T.js} +7 -7
  6. package/dist/{check-WFBEDHDR.js.map → check-ZBIH422T.js.map} +1 -1
  7. package/dist/chunk-2ICNHUG6.js +1820 -0
  8. package/dist/chunk-2ICNHUG6.js.map +1 -0
  9. package/dist/{chunk-5ZOP4SQR.js → chunk-2N72FKLB.js} +12 -7
  10. package/dist/chunk-2N72FKLB.js.map +1 -0
  11. package/dist/{chunk-BCE22JSM.js → chunk-7DZGJQ3P.js} +33 -14
  12. package/dist/chunk-7DZGJQ3P.js.map +1 -0
  13. package/dist/{chunk-RPZAALCX.js → chunk-7S52M2SL.js} +256 -165
  14. package/dist/chunk-7S52M2SL.js.map +1 -0
  15. package/dist/{chunk-QDZA5JSL.js → chunk-AABMKHEU.js} +4 -4
  16. package/dist/{chunk-QDZA5JSL.js.map → chunk-AABMKHEU.js.map} +1 -1
  17. package/dist/{chunk-KLEIVDUV.js → chunk-CEXAQQ5W.js} +150 -11
  18. package/dist/chunk-CEXAQQ5W.js.map +1 -0
  19. package/dist/{chunk-3G43C6OL.js → chunk-GNXCX4WE.js} +46 -3
  20. package/dist/chunk-GNXCX4WE.js.map +1 -0
  21. package/dist/chunk-IUPSBD6W.js +7914 -0
  22. package/dist/chunk-IUPSBD6W.js.map +1 -0
  23. package/dist/{chunk-JGRMRXXZ.js → chunk-JKLLFVEU.js} +3 -3
  24. package/dist/{chunk-JGRMRXXZ.js.map → chunk-JKLLFVEU.js.map} +1 -1
  25. package/dist/{chunk-PXRX5PEC.js → chunk-PDOBHMUQ.js} +3 -3
  26. package/dist/chunk-PDOBHMUQ.js.map +1 -0
  27. package/dist/{chunk-ZVANIULZ.js → chunk-RNTDBX6S.js} +4 -4
  28. package/dist/{chunk-ZVANIULZ.js.map → chunk-RNTDBX6S.js.map} +1 -1
  29. package/dist/{chunk-A2UUGASH.js → chunk-U736PVHY.js} +2 -2
  30. package/dist/chunk-U736PVHY.js.map +1 -0
  31. package/dist/{chunk-PVTHHV7X.js → chunk-V3LF7BE7.js} +27 -5
  32. package/dist/chunk-V3LF7BE7.js.map +1 -0
  33. package/dist/{chunk-EP6JHXSR.js → chunk-WAMZWZJB.js} +54 -9
  34. package/dist/chunk-WAMZWZJB.js.map +1 -0
  35. package/dist/{chunk-DTDVSFRY.js → chunk-XQUSGIDG.js} +17 -3
  36. package/dist/chunk-XQUSGIDG.js.map +1 -0
  37. package/dist/cli.js +15 -11
  38. package/dist/cli.js.map +1 -1
  39. package/dist/client/index.d.ts +32 -3
  40. package/dist/client/index.js +205 -12
  41. package/dist/client/index.js.map +1 -1
  42. package/dist/components/index.d.ts +1983 -29
  43. package/dist/components/index.js +4 -4
  44. package/dist/{dev-NZRLOQCL.js → dev-4XEDTELV.js} +24 -13
  45. package/dist/dev-4XEDTELV.js.map +1 -0
  46. package/dist/doc/index.js +4 -2
  47. package/dist/doc/index.js.map +1 -1
  48. package/dist/{docs-ZGDJUHJI.js → docs-JVP4RPKT.js} +3 -3
  49. package/dist/{docs-ZGDJUHJI.js.map → docs-JVP4RPKT.js.map} +1 -1
  50. package/dist/{doctor-VFKEMR54.js → doctor-5E2VEZPK.js} +8 -8
  51. package/dist/doctor-5E2VEZPK.js.map +1 -0
  52. package/dist/markdown/index.js +1 -1
  53. package/dist/markdown/index.js.map +1 -1
  54. package/dist/{preview-QDCIVVSR.js → preview-T6CLSQVX.js} +12 -4
  55. package/dist/preview-T6CLSQVX.js.map +1 -0
  56. package/dist/query/index.d.ts +0 -11
  57. package/dist/query/index.js +2 -2
  58. package/dist/{routes-RHP5FVGD.js → routes-3SGAFDMC.js} +6 -6
  59. package/dist/{routes-RHP5FVGD.js.map → routes-3SGAFDMC.js.map} +1 -1
  60. package/dist/{search-RFBELGY7.js → search-5LC4XPB5.js} +3 -3
  61. package/dist/{search-RFBELGY7.js.map → search-5LC4XPB5.js.map} +1 -1
  62. package/dist/slide/index.js +63 -17
  63. package/dist/slide/index.js.map +1 -1
  64. package/dist/table/index.js +11 -10
  65. package/dist/table/index.js.map +1 -1
  66. package/dist/ui/index.d.ts +148 -12
  67. package/dist/ui/index.js +1340 -88
  68. package/dist/ui/index.js.map +1 -1
  69. package/dist/{upgrade-GF2P67M6.js → upgrade-JHXZBGQS.js} +7 -7
  70. package/dist/{upgrade-GF2P67M6.js.map → upgrade-JHXZBGQS.js.map} +1 -1
  71. package/dist/vite/index.d.ts +10 -0
  72. package/dist/vite/index.js +4 -4
  73. package/docs/en/changelog.md +24 -0
  74. package/docs/en/cli-reference.md +30 -0
  75. package/docs/en/components.md +29 -15
  76. package/docs/en/parts/data-table.md +22 -0
  77. package/docs/en/parts/delta.md +50 -0
  78. package/docs/en/parts/format.md +43 -0
  79. package/docs/en/parts/kpi-card.md +57 -0
  80. package/docs/en/parts/metric-value.md +3 -2
  81. package/docs/en/parts/page-shell.md +1 -1
  82. package/docs/en/parts/sparkline.md +1 -1
  83. package/docs/en/parts/trend-indicator.md +17 -1
  84. package/docs/en/ui-and-theming.md +1 -1
  85. package/docs/index.json +366 -76
  86. package/docs/ja/changelog.md +55 -0
  87. package/docs/ja/cli-reference.md +29 -0
  88. package/docs/ja/components.md +57 -101
  89. package/docs/ja/page-types/csv.md +83 -0
  90. package/docs/ja/page-types/doc.md +83 -0
  91. package/docs/ja/page-types/excel.md +82 -0
  92. package/docs/ja/page-types/slide.md +132 -0
  93. package/docs/ja/page-types.md +47 -0
  94. package/docs/ja/parts/area-chart.md +61 -0
  95. package/docs/ja/parts/bar-chart.md +69 -0
  96. package/docs/ja/parts/bar-list.md +35 -0
  97. package/docs/ja/parts/category-bar.md +36 -0
  98. package/docs/ja/parts/data-table.md +22 -0
  99. package/docs/ja/parts/delta.md +50 -0
  100. package/docs/ja/parts/donut-chart.md +47 -0
  101. package/docs/ja/parts/echart.md +3 -0
  102. package/docs/ja/parts/format.md +44 -0
  103. package/docs/ja/parts/kpi-card.md +55 -0
  104. package/docs/ja/parts/line-chart.md +58 -0
  105. package/docs/ja/parts/metric-value.md +3 -2
  106. package/docs/ja/parts/page-shell.md +1 -1
  107. package/docs/ja/parts/progress-circle.md +34 -0
  108. package/docs/ja/parts/sparkline.md +2 -2
  109. package/docs/ja/parts/tracker.md +32 -0
  110. package/docs/ja/parts/trend-indicator.md +17 -1
  111. package/docs/ja/routing.md +8 -86
  112. package/docs/ja/ui/alert-dialog.md +41 -0
  113. package/docs/ja/ui/avatar.md +31 -0
  114. package/docs/ja/ui/combobox.md +74 -0
  115. package/docs/ja/ui/drawer.md +41 -0
  116. package/docs/ja/ui/field.md +42 -0
  117. package/docs/ja/ui/hover-card.md +21 -0
  118. package/docs/ja/ui/kbd.md +16 -0
  119. package/docs/ja/ui/pagination.md +36 -0
  120. package/docs/ja/ui/radio-group.md +21 -0
  121. package/docs/ja/ui/toast.md +46 -0
  122. package/docs/ja/ui-and-theming.md +14 -7
  123. package/package.json +43 -29
  124. package/registry/ui/accordion.tsx +76 -0
  125. package/registry/ui/alert-dialog.tsx +189 -0
  126. package/registry/ui/alert.tsx +80 -0
  127. package/registry/ui/app-shell.tsx +287 -0
  128. package/registry/ui/area-chart.tsx +3701 -0
  129. package/registry/ui/attention-list.tsx +303 -0
  130. package/registry/ui/avatar.tsx +110 -0
  131. package/registry/ui/badge.tsx +56 -0
  132. package/registry/ui/bar-chart.tsx +3698 -0
  133. package/registry/ui/bar-list.tsx +3743 -0
  134. package/registry/ui/box-plot-chart.tsx +3906 -0
  135. package/registry/ui/breadcrumb.tsx +128 -0
  136. package/registry/ui/button.tsx +62 -0
  137. package/registry/ui/calendar.tsx +223 -0
  138. package/registry/ui/card.tsx +107 -0
  139. package/registry/ui/category-bar.tsx +1290 -0
  140. package/registry/ui/chart-frame.tsx +1393 -0
  141. package/registry/ui/checkbox.tsx +30 -0
  142. package/registry/ui/collapsible.tsx +23 -0
  143. package/registry/ui/combobox.tsx +310 -0
  144. package/registry/ui/command.tsx +198 -0
  145. package/registry/ui/dashboard-card.tsx +217 -0
  146. package/registry/ui/data-table.tsx +693 -146
  147. package/registry/ui/date-range-picker.tsx +390 -0
  148. package/registry/ui/delta.tsx +188 -0
  149. package/registry/ui/dialog.tsx +161 -0
  150. package/registry/ui/donut-chart.tsx +3751 -0
  151. package/registry/ui/drawer.tsx +229 -0
  152. package/registry/ui/dropdown-menu.tsx +274 -0
  153. package/registry/ui/echart.tsx +918 -0
  154. package/registry/ui/field.tsx +240 -0
  155. package/registry/ui/filter-bar.tsx +392 -0
  156. package/registry/ui/funnel-steps.tsx +3569 -0
  157. package/registry/ui/heatmap.tsx +1786 -0
  158. package/registry/ui/histogram-chart.tsx +3986 -0
  159. package/registry/ui/hover-card.tsx +52 -0
  160. package/registry/ui/input-group.tsx +160 -0
  161. package/registry/ui/input.tsx +24 -0
  162. package/registry/ui/kbd.tsx +30 -0
  163. package/registry/ui/kpi-card.tsx +699 -0
  164. package/registry/ui/label.tsx +22 -0
  165. package/registry/ui/legend.tsx +3563 -0
  166. package/registry/ui/line-chart.tsx +3699 -0
  167. package/registry/ui/metric-value.tsx +62 -0
  168. package/registry/ui/multi-select.tsx +232 -0
  169. package/registry/ui/page-shell.tsx +282 -0
  170. package/registry/ui/pagination.tsx +140 -0
  171. package/registry/ui/paired-chart.tsx +3827 -0
  172. package/registry/ui/placeholder.tsx +36 -0
  173. package/registry/ui/popover.tsx +92 -0
  174. package/registry/ui/progress-circle.tsx +867 -0
  175. package/registry/ui/progress.tsx +85 -0
  176. package/registry/ui/radio-group.tsx +39 -0
  177. package/registry/ui/sample-data.tsx +86 -0
  178. package/registry/ui/scatter-chart.tsx +4212 -0
  179. package/registry/ui/scroll-area.tsx +56 -0
  180. package/registry/ui/searchable-select.tsx +214 -0
  181. package/registry/ui/section-header.tsx +43 -0
  182. package/registry/ui/segmented-control.tsx +76 -0
  183. package/registry/ui/select.tsx +255 -0
  184. package/registry/ui/separator.tsx +27 -0
  185. package/registry/ui/sheet.tsx +139 -0
  186. package/registry/ui/sidebar.tsx +725 -0
  187. package/registry/ui/skeleton.tsx +17 -0
  188. package/registry/ui/slider.tsx +56 -0
  189. package/registry/ui/sparkline.tsx +230 -0
  190. package/registry/ui/spinner.tsx +14 -0
  191. package/registry/ui/states.tsx +90 -0
  192. package/registry/ui/status-badge.tsx +121 -0
  193. package/registry/ui/switch.tsx +34 -0
  194. package/registry/ui/table.tsx +118 -0
  195. package/registry/ui/tabs.tsx +84 -0
  196. package/registry/ui/textarea.tsx +22 -0
  197. package/registry/ui/toast.tsx +250 -0
  198. package/registry/ui/toggle-group.tsx +91 -0
  199. package/registry/ui/toggle.tsx +47 -0
  200. package/registry/ui/tooltip.tsx +72 -0
  201. package/registry/ui/tracker.tsx +849 -0
  202. package/registry/ui/trend-indicator.tsx +74 -0
  203. package/registry/ui/updated-at.tsx +122 -0
  204. package/registry/ui/waterfall-chart.tsx +4248 -0
  205. package/skills/vantage-add-feature/SKILL.md +9 -7
  206. package/skills/vantage-design/SKILL.md +12 -2
  207. package/skills/vantage-design/references/format.md +1 -1
  208. package/skills/vantage-pitfalls/SKILL.md +5 -1
  209. package/skills/vantage-slide/SKILL.md +17 -0
  210. package/templates/AGENTS.md +22 -1
  211. package/templates/agents/api.md +29 -0
  212. package/templates/agents/csv.md +2 -1
  213. package/templates/agents/doc.md +4 -3
  214. package/templates/agents/page.md +32 -8
  215. package/templates/agents/slide.md +13 -1
  216. package/templates/agents/xlsx.md +2 -1
  217. package/theme.css +252 -132
  218. package/dist/add-EISGSZAH.js +0 -6
  219. package/dist/add-EISGSZAH.js.map +0 -1
  220. package/dist/chunk-3G43C6OL.js.map +0 -1
  221. package/dist/chunk-5ZOP4SQR.js.map +0 -1
  222. package/dist/chunk-A2UUGASH.js.map +0 -1
  223. package/dist/chunk-BCE22JSM.js.map +0 -1
  224. package/dist/chunk-DTDVSFRY.js.map +0 -1
  225. package/dist/chunk-EP6JHXSR.js.map +0 -1
  226. package/dist/chunk-KLEIVDUV.js.map +0 -1
  227. package/dist/chunk-LSRMRIXA.js +0 -2227
  228. package/dist/chunk-LSRMRIXA.js.map +0 -1
  229. package/dist/chunk-PVTHHV7X.js.map +0 -1
  230. package/dist/chunk-PXRX5PEC.js.map +0 -1
  231. package/dist/chunk-RPZAALCX.js.map +0 -1
  232. package/dist/chunk-T3FLAGI6.js +0 -316
  233. package/dist/chunk-T3FLAGI6.js.map +0 -1
  234. package/dist/dev-NZRLOQCL.js.map +0 -1
  235. package/dist/doctor-VFKEMR54.js.map +0 -1
  236. package/dist/preview-QDCIVVSR.js.map +0 -1
@@ -0,0 +1,699 @@
1
+ // Copied by `vantage add ui kpi-card`. This file is yours to edit.
2
+ // Generated from @squadbase/squadkit registry/components/kpi-card.tsx by `pnpm run registry` (in Vantage, edit packages/squadkit, not registry/).
3
+ "use client"
4
+
5
+ /**
6
+ * KpiCard — one metric in five tiers, following shadcn dashboard-01 SectionCards:
7
+ *
8
+ * 1. label (CardDescription, muted)
9
+ * 2. value (CardTitle, tabular-nums; text-4xl once the card is ≥ 320px wide (a comparison label is ~180px, so narrower cards would overlap the value))
10
+ * 3. delta (CardAction: arrow + sign + colour + comparison label — `Delta`)
11
+ * 4. previous actual ("前月 ¥4,290万"; on by default, `showPrevious={false}` hides it)
12
+ * 5. conclusion (`summary`: a *template* whose placeholders the card fills)
13
+ *
14
+ * with optional extras: a target bar under the value (a 6px straight bar — actual
15
+ * in `--chart-1`, the pace projection in `--chart-1/30` (`/45` in dark: 1.33:1 → 1.6:1 against the track, as light has), a 1px tick at the target —
16
+ * and one line "目標の 49%・このペースなら 98%"), then in the footer a record badge
17
+ * from `history`, the data source footnote, the last update time and, with ≥ 6
18
+ * points of `history`, an axis-less sparkline (`showHistory={false}` hides it).
19
+ *
20
+ * Everything derivable is computed here — direction, rate, colour, remaining,
21
+ * achievement, projection, record — so no two props can disagree. Pass enums and
22
+ * numbers only. `history` is the series ending at the current period: its last
23
+ * point should equal `value`.
24
+ *
25
+ * - **Cards in a row line up by subgrid, not by fixed heights.** The card spans two rows of its
26
+ * parent grid (`row-span-2` + `grid-template-rows: subgrid`): row 1 is the body (label, value,
27
+ * delta, previous actual, target bar), row 2 the footer. Cards placed directly in one grid
28
+ * (`grid grid-cols-2 lg:grid-cols-4 gap-4`) therefore share the value baseline and the footer's
29
+ * top edge, and the sparkline sits at the footer's bottom. Outside such a grid the card is a
30
+ * plain grid of the same two rows. The label is one line (truncated, full text in `title`).
31
+ * When the card is narrower than 250px the delta moves from the right of the value to
32
+ * under it (container query, no prop).
33
+ * - **Nothing empty is drawn.** A card with no summary, record badge, target line, source,
34
+ * update time or sparkline has no footer in the DOM; there is no placeholder for the target
35
+ * bar either. No `h-*` / `min-h-*` is used to line cards up.
36
+ * - **`size="sm"`** is for two cards side by side in a narrow place (a Sheet): one step smaller
37
+ * value and padding, and no sparkline.
38
+ * - **`source` is at most two lines** (`line-clamp-2`, full text in `title`).
39
+ * - **Labels follow the grain.** The grain is `comparison.grain`, else
40
+ * `historyGrain`, else inferred from `period`; a monthly card reads "前月比" /
41
+ * "前年同月比" and projects to "月末". Without any of them it reads "前期比".
42
+ * Any other baseline is `vs: "custom"` with a `label` ("昨日比"); the previous
43
+ * line takes its name from it ("昨日 617"), the same way a `label` on any `vs` does.
44
+ * - **Two or more comparisons sit under the value**, not beside it, so the value
45
+ * keeps its place and its width whatever the card holds.
46
+ * - **Polarity drives everything.** With `polarity="lower-is-better"` the target
47
+ * is met at or below it, and the record badge marks the lowest value.
48
+ * - **Rates change in points.** With a `percent` format the delta and
49
+ * `{difference}` are in percentage points ("-0.5pt"); `change="relative"` opts
50
+ * back into the change rate. The target line follows: "目標 95% まであと 2.8pt"
51
+ * instead of a ratio of rates ("97.1% 達成"); `targetDisplay="achievement"` opts back.
52
+ * - **The value has a fixed size.** It never shrinks to fit: a long value wraps its
53
+ * 速報 badge instead of truncating, so neighbouring cards keep one baseline.
54
+ * - **A summary longer than 2 lines is clamped** (full text in `title`), so keep it to one fact.
55
+ *
56
+ * Summary placeholders: `{value}` `{delta}` `{difference}` `{previous}` `{label}`
57
+ * `{target}` `{achievement}` `{remaining}`. Unknown placeholders are left as-is.
58
+ * If a placeholder's value is missing (e.g. no previous period), the whole
59
+ * sentence is replaced with "前月の実績がないため、比較できません。" — or dropped
60
+ * when there is no comparison — so "—" never lands inside a sentence. Write the
61
+ * sentence around them and never put numbers in the template itself.
62
+ *
63
+ * The summary says one fact *beyond* the comparison — composition, target, record,
64
+ * rate. A template made only of `{delta}` / `{difference}` repeats what the badge
65
+ * and the previous actual already say, so it logs a dev warning (once).
66
+ *
67
+ * @example
68
+ * import { KpiCard } from "@/components/kpi-card"
69
+ * // Vantage: import { KpiCard } from "@squadbase/vantage/components"
70
+ *
71
+ * <KpiCard
72
+ * label="売上(今月)"
73
+ * value={48_200_000}
74
+ * format="currency"
75
+ * comparison={{ previous: 42_900_000, vs: "prior-period" }}
76
+ * summary="{label}は前月から {difference}({delta})伸びています。"
77
+ * target={60_000_000}
78
+ * period={{ start: "2026-10-01", end: "2026-11-01" }}
79
+ * />
80
+ */
81
+ import type { ComponentProps } from "react"
82
+
83
+ import { cn } from "@squadbase/vantage/ui"
84
+ import {
85
+ comparisonBaseline,
86
+ computeComparison,
87
+ defaultChangeDisplay,
88
+ formatChange,
89
+ type ChangeDisplay,
90
+ type Comparison,
91
+ type PeriodGrain,
92
+ type Polarity,
93
+ } from "@squadbase/vantage/components"
94
+ import { DEFAULT_LOCALE, EMPTY_VALUE, formatDate, formatDatesInText, formatDelta, formatKind, formatPoints, formatValue, type ValueFormat } from "@squadbase/vantage/components"
95
+ import { computeTargetProgress, detectRecord, inferPeriodGrain, type KpiPeriod } from "@squadbase/vantage/components"
96
+ import { formatRelativeTime } from "@squadbase/vantage/components"
97
+ import { Sparkline } from "@squadbase/vantage/components"
98
+ import { Badge } from "@squadbase/vantage/ui"
99
+ import { Card, CardAction, CardDescription, CardFooter, CardHeader, CardTitle } from "@squadbase/vantage/ui"
100
+ import { Skeleton } from "@squadbase/vantage/ui"
101
+ import { Delta } from "@squadbase/vantage/components"
102
+ import { SampleBadge, useSampleMark } from "@squadbase/vantage/components"
103
+
104
+ export interface KpiCardSource {
105
+ /** Period the data covers (e.g. "2023-04 以降"). ISO year-months / dates in it are written by the card ("2023年4月 以降"). */
106
+ period?: string
107
+ /** Number of rows aggregated; formatted by the card ("48,210件から集計"). */
108
+ count?: number
109
+ /**
110
+ * 集計から除いた行数。出典の脚注に「12件を除外」と添える(ja 以外は「12 excluded」)。0 や負の値は出さない。
111
+ * 除外の理由(テスト用アカウント、欠損など)は `note` に書く。
112
+ * @example source={{ count: 48_210, excluded: 12, note: "テスト用アカウントを除外" }}
113
+ */
114
+ excluded?: number
115
+ /** Data source name (e.g. "Snowflake"). */
116
+ name?: string
117
+ /** 換算・税抜などの脚注。フッターに出す。例: `note: "税抜、1 ドル=150 円で換算"`。数字を使う説明は summary ではなくここへ。 */
118
+ note?: string
119
+ }
120
+
121
+ export interface KpiCardProps extends Omit<ComponentProps<"div">, "children"> {
122
+ /** Metric name (tier 1). */
123
+ label: string
124
+ /** Current value (tier 2). null / undefined renders "—". */
125
+ value: number | null | undefined
126
+ /**
127
+ * Value format, also used for previous / target / remaining. Default `"compact"`.
128
+ * `"currency"` is JPY in 万・億; `"percent"` takes a ratio (0.021 → 2.1%) and
129
+ * switches the delta to points. See `formatValue` for the full table.
130
+ */
131
+ format?: ValueFormat
132
+ /** Default `"ja-JP"`. */
133
+ locale?: string
134
+ /**
135
+ * What the value is compared against; drives the delta (tier 3) and previous line (tier 4).
136
+ * 前期・前年・目標以外は `vs: "custom"` + `label`(バッジの呼び名。末尾の「比」を外した語が前期実績行の呼び名になる)。
137
+ * @example comparison={{ previous: 617, vs: "custom", label: "昨日比" }}
138
+ */
139
+ comparison?: Comparison
140
+ /**
141
+ * 前年比と前月比など、複数の比較を併記する。先頭だけが前期実績行と summary に使われ、2 つ目以降は Delta 行のみ。`comparison` も渡したらそれが先頭。バッジは値の下に並ぶ。
142
+ * @example comparisons={[{ previous: 4_290, vs: "prior-period", grain: "month" }, { previous: 3_900, vs: "prior-year", grain: "month" }]} / comparisons={[{ previous: 617, vs: "custom", label: "昨日比" }, { previous: 590, vs: "custom", label: "先週の同じ曜日比" }]}
143
+ */
144
+ comparisons?: Comparison[]
145
+ /**
146
+ * 確定前の値。値の隣に「速報」バッジを出し、目標の「達成」を言い切らず、最高記録の判定も出さない。
147
+ * @example provisional / provisional={{ label: "暫定" }}
148
+ */
149
+ provisional?: boolean | { label?: string }
150
+ /** Whether a rise is good. Default `"higher-is-better"`. `"neutral"` never colours the change and skips the target and record logic. */
151
+ polarity?: Polarity
152
+ /** `"relative"` ("+12.4%"), `"points"` ("-0.5pt") or `"difference"` ("+¥530万", in `format`). Default: points for a `percent` format, else relative. */
153
+ change?: ChangeDisplay
154
+ /** Absolute ratio below which the change reads as flat. Default 0.01. */
155
+ neutralBand?: number
156
+ /** Show the previous actual ("前月 400"). Default true; needs `comparison`. */
157
+ showPrevious?: boolean
158
+ /** Conclusion sentence template (tier 5); see the placeholders above. */
159
+ summary?: string
160
+ /**
161
+ * Target for the current period. Under the value it adds a 6px bar (actual, the pace
162
+ * projection, a tick at the target) and one line "目標の 49%・このペースなら 98%"
163
+ * (the projection only while `period` is in progress). With `polarity="lower-is-better"`
164
+ * or a rate target (points) there is no bar: "目標 … まであと …" in the footer.
165
+ */
166
+ target?: number
167
+ /**
168
+ * 目標行・見込み行での目標の呼び名。既定「目標」。予算・計画・ノルマなど業務の言葉に合わせる。
169
+ * @example targetLabel="予算" // 予算まであと ¥2,934万(98.1% 達成)
170
+ */
171
+ targetLabel?: string
172
+ /**
173
+ * 目標に対する進み具合の出し方。`"achievement"` は達成率(現在値 ÷ 目標。「98.1% 達成」)、`"points"` は目標との差(「あと 2.8pt」)。
174
+ * 既定は `format` から決まる: `percent`(率)は `"points"`(率を率で割った達成度は読めない)、それ以外は `"achievement"`。
175
+ * `"points"` のとき `{achievement}` は目標との符号付きの差("-2.8pt")になり、見込み行は出ない。
176
+ */
177
+ targetDisplay?: "achievement" | "points"
178
+ /** Current period; with `target`, adds a pace projection while the period is in progress. */
179
+ period?: KpiPeriod
180
+ /** Series ending at the current period (last point = `value`); adds a record badge. */
181
+ history?: ReadonlyArray<number | null | undefined>
182
+ /** Grain of `history` (and of the comparison labels). Default: inferred from `period`, else `"month"` for the record. */
183
+ historyGrain?: PeriodGrain
184
+ /**
185
+ * `history` が 6 点以上あるとき、フッター末尾に軸なしのスパークライン(高さ 32px・`--chart-1`・最新点だけドット)を出す。既定 true。
186
+ * 推移を出したくないカードは `showHistory={false}`(記録バッジは `history` があれば出る)。
187
+ * @example showHistory={false}
188
+ */
189
+ showHistory?: boolean
190
+ /** Data source footnote. */
191
+ source?: KpiCardSource
192
+ /** When the data was last refreshed: "3 分前に更新". 出し方は `updatedAtDisplay`。 */
193
+ updatedAt?: Date | string | number
194
+ /**
195
+ * `updatedAt` の出し方。`"relative"`(既定)は「3 分前に更新」、`"absolute"` は「2026/10/20 14:30 に更新」、
196
+ * `"both"` は「2026/10/20 14:30 に更新(3 分前)」。絶対時刻は実行環境のタイムゾーンで出す(`timeZone` で固定できる)。
197
+ * 画面を印刷・スクリーンショットで残すなら、時間が経っても読める `"absolute"` か `"both"`。
198
+ * @example updatedAtDisplay="absolute"
199
+ */
200
+ updatedAtDisplay?: "relative" | "absolute" | "both"
201
+ /**
202
+ * `updatedAt` の絶対時刻(`updatedAtDisplay` が `"absolute"` / `"both"`)を出すタイムゾーン(IANA 名。例 `"Asia/Tokyo"`)。
203
+ * 既定は実行環境(ブラウザ)のタイムゾーン。サーバーとブラウザで表示が食い違う(SSR)なら固定する。「3 分前」には影響しない。
204
+ * @example updatedAtDisplay="absolute" timeZone="Asia/Tokyo"
205
+ */
206
+ timeZone?: string
207
+ /** Reference time for the projection and relative time (for deterministic rendering). */
208
+ now?: Date | number
209
+ /** Render a skeleton with the final shape instead of the values. */
210
+ isLoading?: boolean
211
+ /**
212
+ * `"sm"` は Sheet の中など狭い場所で 2 枚を横に並べるときの小さいサイズ。値の文字と余白が一段小さくなり、スパークラインは出さない。既定 `"default"`。
213
+ * @example size="sm"
214
+ */
215
+ size?: "default" | "sm"
216
+ }
217
+
218
+ /** Points of `history` from which the footer shows a sparkline (the same bar as the record badge). */
219
+ const SPARKLINE_MIN_POINTS = 6
220
+
221
+ /** Height of the footer sparkline, in px. */
222
+ const SPARKLINE_HEIGHT = 32
223
+
224
+ /**
225
+ * The delta sits right of the value once the card is ≥ 320px wide (a comparison label is ~180px, so narrower cards would overlap the value) (the shadcn
226
+ * `CardAction` slot) and drops under the value below that — a container query,
227
+ * so a narrow card needs no prop.
228
+ */
229
+ const DELTA_PLACEMENT =
230
+ "col-start-1 row-span-1 row-start-3 justify-self-start @[288px]/card:col-start-2 @[288px]/card:row-span-2 @[288px]/card:row-start-1 @[288px]/card:justify-self-end"
231
+
232
+ /**
233
+ * The header is the size container (`@container/card`), not the card: a container sets layout containment, which turns the
234
+ * card's `grid-rows-subgrid` into a plain grid and the rows stop lining up. Its content box is the card minus both paddings
235
+ * (32px; 24px for `sm`), so 218px / 288px here are the 250px / 320px card widths. It also owns the gap above the footer.
236
+ */
237
+ const HEADER_CLASS = "@container/card pb-(--card-spacing)"
238
+ /** A value this long (a huge standard-notation currency) may wrap between digit groups, and its delta then moves under it so the number gets the full row. Ordinary values stay on one line beside the delta. */
239
+ const LONG_VALUE_CHARS = 10
240
+ const DELTA_UNDER_PLACEMENT = "col-start-1 row-span-1 row-start-3 justify-self-start"
241
+ // No grey footer band: value, comparison and notes share one surface, 8px apart (the footer only keeps its subgrid row).
242
+ const KPI_FOOTER_CLASS = "flex-col items-start gap-2 rounded-none border-t-0 bg-transparent pt-0 text-sm"
243
+
244
+ const PLACEHOLDER = /\{(\w+)\}/g
245
+
246
+ const isJapanese = (locale: string) => locale.toLowerCase().startsWith("ja")
247
+
248
+ const isMissing = (v: string | null | undefined) => v === null || v === undefined || v === ""
249
+
250
+ /**
251
+ * Fill `{name}` placeholders from `values`. Unknown names stay as written.
252
+ *
253
+ * Without `fallback`, a known name whose value is null / undefined / empty
254
+ * becomes "—". With `fallback`, any such missing value replaces the whole
255
+ * sentence with `fallback` (which may be null to drop it).
256
+ */
257
+ export function fillKpiTemplate(template: string, values: Readonly<Record<string, string | null | undefined>>): string
258
+ export function fillKpiTemplate(
259
+ template: string,
260
+ values: Readonly<Record<string, string | null | undefined>>,
261
+ fallback: string | null,
262
+ ): string | null
263
+ export function fillKpiTemplate(
264
+ template: string,
265
+ values: Readonly<Record<string, string | null | undefined>>,
266
+ fallback?: string | null,
267
+ ): string | null {
268
+ let missing = false
269
+ const filled = template.replace(PLACEHOLDER, (match, name: string) => {
270
+ if (!Object.prototype.hasOwnProperty.call(values, name)) return match
271
+ const v = values[name]
272
+ if (isMissing(v)) {
273
+ missing = true
274
+ return EMPTY_VALUE
275
+ }
276
+ return v as string
277
+ })
278
+ return missing && fallback !== undefined ? fallback : filled
279
+ }
280
+
281
+ const SHALLOW_SUMMARY_PLACEHOLDERS = new Set(["delta", "difference"])
282
+
283
+ let shallowSummaryWarned = false
284
+
285
+ /** @internal Lets tests observe the once-only dev warning again. */
286
+ export function resetKpiSummaryWarning() {
287
+ shallowSummaryWarned = false
288
+ }
289
+
290
+ /** True when every placeholder is `{delta}` / `{difference}` — the template only restates the badge. */
291
+ function isShallowSummary(template: string): boolean {
292
+ const names = Array.from(template.matchAll(PLACEHOLDER), (m) => m[1] as string)
293
+ return names.length > 0 && names.every((n) => SHALLOW_SUMMARY_PLACEHOLDERS.has(n))
294
+ }
295
+
296
+ // Bundlers replace `process.env.NODE_ENV` textually; a browser without that define has no `process`.
297
+ declare const process: { env: { NODE_ENV?: string } }
298
+
299
+ function isProduction(): boolean {
300
+ try {
301
+ return process.env.NODE_ENV === "production"
302
+ } catch {
303
+ return true
304
+ }
305
+ }
306
+
307
+ function warnShallowSummary(template: string) {
308
+ if (shallowSummaryWarned || isProduction() || !isShallowSummary(template)) return
309
+ shallowSummaryWarned = true
310
+ console.warn(
311
+ `[KpiCard] summary="${template}" only repeats the delta badge and the previous actual. Say one fact beyond the comparison — composition, target, record or rate (e.g. "{label}は目標の {achievement} まで来ています。").`,
312
+ )
313
+ }
314
+
315
+ /** Splits formatted text after each thousands separator so a huge standard-notation value wraps between digit groups instead of clipping. The text itself is unchanged. */
316
+ function digitGroups(text: string): string[] {
317
+ return text.match(/[^,,]*[,,]|[^,,]+$/g) ?? [text]
318
+ }
319
+
320
+ export function KpiCard({
321
+ label,
322
+ value,
323
+ format,
324
+ locale = DEFAULT_LOCALE,
325
+ comparison: comparisonProp,
326
+ comparisons,
327
+ provisional,
328
+ polarity,
329
+ change,
330
+ neutralBand,
331
+ showPrevious = true,
332
+ summary,
333
+ target,
334
+ targetLabel = "目標",
335
+ targetDisplay,
336
+ period,
337
+ history,
338
+ historyGrain,
339
+ showHistory = true,
340
+ source,
341
+ updatedAt,
342
+ updatedAtDisplay = "relative",
343
+ timeZone,
344
+ now,
345
+ isLoading = false,
346
+ size = "default",
347
+ className,
348
+ ...props
349
+ }: KpiCardProps) {
350
+ const allComparisons = [...(comparisonProp ? [comparisonProp] : []), ...(comparisons ?? [])]
351
+ const comparison = allComparisons[0]
352
+ const isProvisional = provisional !== undefined && provisional !== false
353
+ const provisionalLabel = typeof provisional === "object" && provisional.label ? provisional.label : "速報"
354
+ const sample = useSampleMark()
355
+ const neutral = polarity === "neutral"
356
+ const hasPrevious = comparison !== undefined && showPrevious
357
+ // Two or more badges would squeeze the value from the right; they get their own row under it instead.
358
+ const stacked = allComparisons.length > 1
359
+ const hasTarget = target !== undefined
360
+ const grain = comparison?.grain ?? historyGrain ?? inferPeriodGrain(period)
361
+ const record = isProvisional || neutral ? null : detectRecord(history, historyGrain ?? grain, polarity)
362
+ const sourceParts = source
363
+ ? [
364
+ source.period !== undefined ? formatDatesInText(source.period, locale) : undefined,
365
+ source.count !== undefined ? `${formatValue(source.count, "number", locale)}件から集計` : undefined,
366
+ source.excluded !== undefined && Number.isFinite(source.excluded) && source.excluded > 0
367
+ ? isJapanese(locale)
368
+ ? `${formatValue(source.excluded, "number", locale)}件を除外`
369
+ : `${formatValue(source.excluded, "number", locale)} excluded`
370
+ : undefined,
371
+ source.name,
372
+ source.note,
373
+ ].filter((p): p is string => typeof p === "string" && p !== "")
374
+ : []
375
+ const hasUpdated = updatedAt !== undefined
376
+ const historyPoints = (history ?? []).filter((v): v is number => typeof v === "number" && Number.isFinite(v))
377
+ const small = size === "sm"
378
+ const showSparkline = !small && showHistory && historyPoints.length >= SPARKLINE_MIN_POINTS
379
+ const isRate = formatKind(format) === "percent"
380
+ const byPoints = (targetDisplay ?? (isRate ? "points" : "achievement")) === "points"
381
+ const lower = polarity === "lower-is-better"
382
+ // The bar reads "how far toward the target"; a rate (points) or a lower-is-better target has no such fill.
383
+ const targetBar = hasTarget && !neutral && !byPoints && !lower
384
+ if (summary !== undefined) warnShallowSummary(summary)
385
+ // Two rows of the parent grid (body, footer), shared by subgrid; a plain two-row grid when standalone.
386
+ const cardClass = cn("row-span-2 grid content-start gap-y-0 grid-rows-subgrid", className)
387
+ const valueSize = small ? "text-xl @[218px]/card:text-2xl" : "text-2xl @[218px]/card:text-4xl"
388
+
389
+ if (isLoading) {
390
+ return (
391
+ <Card
392
+ data-slot="kpi-card"
393
+ data-loading=""
394
+ aria-busy="true"
395
+ size={size}
396
+ className={cardClass}
397
+ {...props}
398
+ >
399
+ <CardHeader className={HEADER_CLASS}>
400
+ <CardDescription className="col-start-1">
401
+ <span className="sr-only">{label}</span>
402
+ <Skeleton aria-hidden="true" className="h-5 w-24" />
403
+ </CardDescription>
404
+ <CardTitle className="col-start-1 flex items-center gap-2">
405
+ <Skeleton aria-hidden="true" className={small ? "h-7 w-28 @[218px]/card:h-8" : "h-8 w-32 @[218px]/card:h-9"} />
406
+ {/* The mark stays while loading, so the header does not shift when the values arrive. */}
407
+ {sample && <SampleBadge label={sample.label} />}
408
+ </CardTitle>
409
+ {comparison &&
410
+ (stacked ? (
411
+ <div className="flex flex-wrap gap-1">
412
+ {allComparisons.map((_, i) => (
413
+ <Skeleton key={i} aria-hidden="true" className="h-5 w-24 rounded-4xl" />
414
+ ))}
415
+ </div>
416
+ ) : (
417
+ <CardAction className={DELTA_PLACEMENT}>
418
+ <Skeleton aria-hidden="true" className="h-5 w-24 rounded-4xl" />
419
+ </CardAction>
420
+ ))}
421
+ {hasPrevious && <Skeleton aria-hidden="true" className="h-5 w-16" />}
422
+ {targetBar ? (
423
+ <div className="col-span-full mt-1 flex flex-col gap-1.5">
424
+ <Skeleton aria-hidden="true" className="h-2 w-full rounded-full" />
425
+ <Skeleton aria-hidden="true" className="h-5 w-3/5" />
426
+ </div>
427
+ ) : null}
428
+ </CardHeader>
429
+ {(summary || record || (hasTarget && !targetBar) || sourceParts.length > 0 || hasUpdated || showSparkline) && (
430
+ <CardFooter className={KPI_FOOTER_CLASS}>
431
+ {summary && <Skeleton aria-hidden="true" className="h-5 w-4/5" />}
432
+ {record && <Skeleton aria-hidden="true" className="h-5 w-28 rounded-4xl" />}
433
+ {hasTarget && !targetBar && <Skeleton aria-hidden="true" className="h-5 w-3/5" />}
434
+ {sourceParts.length > 0 && <Skeleton aria-hidden="true" className="h-4 w-3/4" />}
435
+ {hasUpdated && <Skeleton aria-hidden="true" className="h-4 w-20" />}
436
+ {showSparkline && <Skeleton aria-hidden="true" className="mt-auto h-8 w-full" />}
437
+ </CardFooter>
438
+ )}
439
+ </Card>
440
+ )
441
+ }
442
+
443
+ const fmt = (v: number | null | undefined) => formatValue(v, format, locale)
444
+ /** An unsigned distance in the metric's unit — points for a rate. */
445
+ const fmtDistance = (v: number) => (isRate ? formatPoints(v, locale, { signDisplay: "never" }) : fmt(v))
446
+ const pct = (v: number) => formatValue(v, { type: "percent", digits: 0 }, locale)
447
+ const tl = targetLabel
448
+ const display = change ?? defaultChangeDisplay(format)
449
+ // Value digits only carry over to a change in points; a relative change keeps its own fixed digits.
450
+ const digits =
451
+ display === "points" && typeof format === "object" && format !== null && "digits" in format ? format.digits : undefined
452
+ const graded = comparison ? { ...comparison, grain } : undefined
453
+ const result = graded ? computeComparison(value, graded, { polarity, neutralBand }) : null
454
+ const baseline = graded ? comparisonBaseline(graded.vs, grain, graded.label, graded.toDate) : null
455
+ const progress = hasTarget && !neutral ? computeTargetProgress(value, target, { period, now, polarity }) : null
456
+ // A linear pace only makes sense for an accumulating total, not for a rate.
457
+ const projectedValue =
458
+ !isRate && !byPoints && progress?.projected != null && progress.elapsed ? (value as number) / progress.elapsed : null
459
+
460
+ const summaryText = summary
461
+ ? fillKpiTemplate(
462
+ summary,
463
+ {
464
+ value: fmt(value),
465
+ label,
466
+ delta: result ? formatChange(result, display, locale, format, digits) : null,
467
+ difference:
468
+ result?.difference != null
469
+ ? isRate
470
+ ? formatPoints(result.difference, locale)
471
+ : formatDelta(result.difference, format, locale)
472
+ : null,
473
+ previous: result?.previous != null ? fmt(result.previous) : null,
474
+ target: hasTarget ? fmt(target) : null,
475
+ achievement: progress
476
+ ? byPoints
477
+ ? formatPoints((value as number) - (target as number), locale)
478
+ : pct(progress.achievement)
479
+ : null,
480
+ remaining: progress ? fmtDistance(progress.remaining) : null,
481
+ },
482
+ result && result.direction === "none" && baseline ? `${baseline}の実績がないため、比較できません。` : null,
483
+ )
484
+ : null
485
+
486
+ // Target bar: actual, the pace projection and a tick at the target on one scale.
487
+ const bar = targetBar && progress ? progressBar() : null
488
+
489
+ function progressBar() {
490
+ const actual = Math.max(value as number, 0)
491
+ const projected = projectedValue !== null && projectedValue > actual ? projectedValue : actual
492
+ const scale = Math.max(target as number, actual, projected)
493
+ const at = (v: number) => (scale > 0 ? (v / scale) * 100 : 0)
494
+ const parts = [`${tl}の ${pct(progress!.achievement)}`]
495
+ if (projectedValue !== null && progress!.projected != null)
496
+ parts.push(`このペースなら ${formatValue(progress!.projected, { type: "percent", digits: 0 }, locale)}`)
497
+ return {
498
+ actualAt: at(actual),
499
+ projectedAt: at(projected),
500
+ targetAt: at(target as number),
501
+ lead: parts[0] as string,
502
+ pace: parts[1] ?? null,
503
+ }
504
+ }
505
+
506
+ let targetText: string | null = null
507
+ if (hasTarget && !bar) {
508
+ if (!progress) targetText = `${tl} ${fmt(target)}`
509
+ else if (isProvisional)
510
+ targetText = progress.achieved
511
+ ? byPoints
512
+ ? `${tl} ${fmt(target)} に到達(確定前)`
513
+ : `${tl} ${fmt(target)} に対して現時点 ${pct(progress.achievement)}(確定前)`
514
+ : byPoints
515
+ ? `${tl} ${fmt(target)} まであと ${fmtDistance(progress.remaining)}(確定前)`
516
+ : `${tl}まであと ${fmtDistance(progress.remaining)}(現時点 ${pct(progress.achievement)}・確定前)`
517
+ else if (lower)
518
+ targetText = progress.achieved
519
+ ? `${tl} ${fmt(target)} を達成`
520
+ : `${tl} ${fmt(target)} まであと ${fmtDistance(progress.remaining)}`
521
+ else if (byPoints)
522
+ targetText = progress.achieved
523
+ ? `${tl} ${fmt(target)} に到達`
524
+ : `${tl} ${fmt(target)} まであと ${fmtDistance(progress.remaining)}`
525
+ else
526
+ targetText = progress.achieved
527
+ ? `${tl} ${fmt(target)} に到達(${pct(progress.achievement)} 達成)`
528
+ : `${tl}まであと ${fmtDistance(progress.remaining)}(${pct(progress.achievement)} 達成)`
529
+ }
530
+
531
+ const hasFooter =
532
+ Boolean(summaryText) || record !== null || Boolean(targetText) || sourceParts.length > 0 || hasUpdated || showSparkline
533
+
534
+ const deltas = allComparisons.map((c, i) => (
535
+ <Delta
536
+ key={i}
537
+ value={value}
538
+ comparison={i === 0 ? (graded ?? c) : { ...c, grain: c.grain ?? grain }}
539
+ polarity={polarity}
540
+ neutralBand={neutralBand}
541
+ format={format}
542
+ change={display}
543
+ digits={digits}
544
+ locale={locale}
545
+ />
546
+ ))
547
+
548
+ const valueText = fmt(value)
549
+ const longValue = valueText.length > LONG_VALUE_CHARS
550
+
551
+ return (
552
+ <Card data-slot="kpi-card" size={size} className={cardClass} {...props}>
553
+ <CardHeader className={HEADER_CLASS}>
554
+ <CardDescription data-slot="kpi-card-label" title={label} className="col-start-1 min-w-0 truncate text-[13px] leading-snug font-medium text-muted-foreground">
555
+ {label}
556
+ </CardDescription>
557
+ <CardTitle
558
+ data-slot="kpi-card-value"
559
+ title={valueText}
560
+ className={cn(
561
+ "col-start-1 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 leading-none font-semibold tracking-tight tabular-nums",
562
+ // Fixed size: the step follows the card width only, never the length of the value.
563
+ valueSize,
564
+ )}
565
+ >
566
+ <span data-slot="kpi-card-value-text" className={longValue ? "min-w-0 break-words" : "whitespace-nowrap"}>
567
+ {longValue
568
+ ? digitGroups(valueText).map((group, i) => (
569
+ <span key={i} className="whitespace-nowrap">
570
+ {group}
571
+ <wbr />
572
+ </span>
573
+ ))
574
+ : valueText}
575
+ </span>
576
+ {isProvisional && (
577
+ <Badge data-slot="kpi-card-provisional" variant="outline" className="align-middle">
578
+ {provisionalLabel}
579
+ </Badge>
580
+ )}
581
+ {sample && <SampleBadge label={sample.label} />}
582
+ </CardTitle>
583
+ {comparison &&
584
+ (stacked ? (
585
+ <div data-slot="kpi-card-comparisons" className="flex flex-wrap items-center gap-1">
586
+ {deltas}
587
+ </div>
588
+ ) : (
589
+ <CardAction className={longValue ? DELTA_UNDER_PLACEMENT : DELTA_PLACEMENT}>{deltas}</CardAction>
590
+ ))}
591
+ {hasPrevious && comparison && (
592
+ <div data-slot="kpi-card-previous" className="col-span-full text-sm text-muted-foreground tabular-nums">
593
+ {result?.previous != null ? `${baseline} ${fmt(result.previous)}` : `${baseline}の実績なし`}
594
+ </div>
595
+ )}
596
+ {bar && progress && (
597
+ <div data-slot="kpi-card-target-progress" className="col-span-full mt-1 flex min-w-0 flex-col gap-1.5">
598
+ <div
599
+ data-slot="kpi-card-target-bar"
600
+ role="progressbar"
601
+ aria-label={`${tl}に対する進捗`}
602
+ aria-valuemin={0}
603
+ aria-valuemax={target}
604
+ aria-valuenow={Math.min(Math.max(value as number, 0), target as number)}
605
+ aria-valuetext={`${tl} ${fmt(target)} に対して ${fmt(value)}(${pct(progress.achievement)})`}
606
+ className="relative h-2 w-full overflow-hidden rounded-full bg-muted"
607
+ >
608
+ <div className="absolute inset-y-0 left-0 bg-chart-1" style={{ width: `${bar.actualAt}%` }} />
609
+ {bar.projectedAt > bar.actualAt && (
610
+ <div
611
+ data-slot="kpi-card-target-bar-projection"
612
+ className="absolute inset-y-0 bg-chart-1/30 dark:bg-chart-1/45"
613
+ style={{ left: `${bar.actualAt}%`, width: `${bar.projectedAt - bar.actualAt}%` }}
614
+ />
615
+ )}
616
+ <div
617
+ data-slot="kpi-card-target-bar-tick"
618
+ className="absolute inset-y-0 w-px bg-foreground"
619
+ style={{ left: `${bar.targetAt}%`, transform: bar.targetAt >= 100 ? "translateX(-1px)" : undefined }}
620
+ />
621
+ </div>
622
+ <p
623
+ data-slot="kpi-card-target"
624
+ title={[bar.lead, bar.pace].filter(Boolean).join("・")}
625
+ className="truncate text-sm text-muted-foreground tabular-nums"
626
+ >
627
+ {bar.lead}
628
+ {bar.pace && (
629
+ <>
630
+ ・<span data-slot="kpi-card-projection" data-estimate="">{bar.pace}</span>
631
+ </>
632
+ )}
633
+ {isProvisional && "(確定前)"}
634
+ </p>
635
+ </div>
636
+ )}
637
+ </CardHeader>
638
+ {hasFooter && (
639
+ <CardFooter className={KPI_FOOTER_CLASS}>
640
+ {summaryText && (
641
+ <p data-slot="kpi-card-summary" title={summaryText} className="line-clamp-2 text-sm leading-relaxed text-muted-foreground tabular-nums">
642
+ {summaryText}
643
+ </p>
644
+ )}
645
+ {record && (
646
+ <Badge data-slot="kpi-card-record" variant="outline">
647
+ {record.label}
648
+ </Badge>
649
+ )}
650
+ {targetText && (
651
+ <p data-slot="kpi-card-target" className="text-muted-foreground tabular-nums">
652
+ {targetText}
653
+ </p>
654
+ )}
655
+ {sourceParts.length > 0 && (
656
+ <p
657
+ data-slot="kpi-card-source"
658
+ title={sourceParts.join("・")}
659
+ className="line-clamp-2 w-full text-xs leading-normal text-muted-foreground tabular-nums"
660
+ >
661
+ {sourceParts.join("・")}
662
+ </p>
663
+ )}
664
+ {hasUpdated && (
665
+ <p data-slot="kpi-card-updated" className="text-xs leading-normal text-muted-foreground">
666
+ {updatedAtText(updatedAt, updatedAtDisplay, locale, now, timeZone)}
667
+ </p>
668
+ )}
669
+ {showSparkline && (
670
+ // mt-auto: the footers of a row are as tall as the tallest, so the sparklines share one bottom edge.
671
+ <div data-slot="kpi-card-history" className="mt-auto w-full pt-2 text-chart-1">
672
+ <Sparkline
673
+ data={historyPoints.map((v) => ({ value: v }))}
674
+ height={SPARKLINE_HEIGHT}
675
+ color="text-chart-1"
676
+ highlight="latest"
677
+ aria-label={`${label}の推移(直近 ${historyPoints.length} 点)`}
678
+ />
679
+ </div>
680
+ )}
681
+ </CardFooter>
682
+ )}
683
+ </Card>
684
+ )
685
+ }
686
+
687
+ /** 「3 分前に更新」「2026/10/20 14:30 に更新」「2026/10/20 14:30 に更新(3 分前)」。 */
688
+ function updatedAtText(
689
+ updatedAt: Date | string | number,
690
+ display: "relative" | "absolute" | "both",
691
+ locale: string,
692
+ now: Date | number | undefined,
693
+ timeZone?: string,
694
+ ): string {
695
+ const relative = formatRelativeTime(updatedAt, { now, locale })
696
+ if (display === "relative") return `${relative}に更新`
697
+ const absolute = formatDate(updatedAt, "datetime", locale, { timeZone })
698
+ return display === "absolute" ? `${absolute} に更新` : `${absolute} に更新(${relative})`
699
+ }