@six-vallees/ui-react 0.3.0 → 0.3.1

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  SegmentedBar
3
- } from "../chunk-OY6MO6QQ.js";
3
+ } from "../chunk-AZMOEG5R.js";
4
4
  import "../chunk-AOULEGMT.js";
5
5
  import "../chunk-DXRY7AS4.js";
6
6
  export {
@@ -27,23 +27,23 @@ function SegmentedBar({ data, height = 40, scale = "mono", showLegend = true, cl
27
27
  if (!hasActive) return "var(--sv-sys-color-on-primary)";
28
28
  return d.active ? "var(--sv-sys-color-on-primary)" : "var(--sv-sys-color-on-surface)";
29
29
  };
30
- const needsEdge = scale === "mono" && hasActive;
31
30
  return /* @__PURE__ */ jsxs("div", { className: cn("w-full", className), children: [
32
31
  /* @__PURE__ */ jsx(
33
32
  "div",
34
33
  {
35
- className: "flex w-full overflow-hidden rounded-control",
36
- style: {
37
- height,
38
- ...needsEdge ? { outline: `1px solid ${chartToken.markEdge}`, outlineOffset: "-1px" } : {}
39
- },
34
+ className: "flex w-full",
35
+ style: { height, gap: 2 },
40
36
  role: "img",
41
37
  "aria-label": data.map((d) => `${d.label} ${d.value}`).join(", "),
42
38
  children: data.map((d, i) => /* @__PURE__ */ jsx(
43
39
  "div",
44
40
  {
45
41
  className: "flex items-center justify-end px-2 first:rounded-l-control last:rounded-r-control",
46
- style: { width: `${safe(d.value) / total * 100}%`, background: fill(d, i) },
42
+ style: {
43
+ width: `${safe(d.value) / total * 100}%`,
44
+ background: fill(d, i),
45
+ boxShadow: `inset 0 0 0 1px ${chartToken.markEdge}`
46
+ },
47
47
  children: /* @__PURE__ */ jsx("span", { className: "truncate sv-body-xs font-medium tabular-nums", style: { color: onFill(d, i) }, children: d.value })
48
48
  },
49
49
  d.label
@@ -61,4 +61,4 @@ SegmentedBar.displayName = "SegmentedBar";
61
61
  export {
62
62
  SegmentedBar
63
63
  };
64
- //# sourceMappingURL=chunk-OY6MO6QQ.js.map
64
+ //# sourceMappingURL=chunk-AZMOEG5R.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/charts/segmented-bar.tsx"],"sourcesContent":["import { cn } from '@/lib/utils';\nimport { categorical, categoricalOn, sequential, sequentialOn, chartToken } from './lib/series';\n\nexport interface Segment {\n label: string;\n value: number;\n /** Pull this segment forward (ink) and others recede. */\n active?: boolean;\n}\n\nexport interface SegmentedBarProps {\n data: Segment[];\n /** Bar thickness in px. */\n height?: number;\n /**\n * How segments get colour:\n * - `mono` (default): grayscale, active segment is ink, the rest are muted tints.\n * - `categorical`: the capped unordered palette (≤4 meaningful categories).\n * - `sequential`: single-hue magnitude ramp, in data order.\n */\n scale?: 'mono' | 'categorical' | 'sequential';\n /** Show the label + value row beneath the bar. */\n showLegend?: boolean;\n className?: string;\n}\n\n/**\n * Cairn SegmentedBar, a single horizontal bar split into labelled parts (a share-of-total\n * / stacked bar). Grayscale by default; hue is opt-in via `scale`. Every segment carries a\n * text label + value, so meaning never rests on colour alone (WCAG-safe). Zero-dependency.\n */\nexport function SegmentedBar({ data, height = 40, scale = 'mono', showLegend = true, className }: SegmentedBarProps) {\n // Negative / non-finite segment values would produce invalid or overflowing widths; clamp to 0.\n const safe = (v: number) => (Number.isFinite(v) && v > 0 ? v : 0);\n const total = data.reduce((s, d) => s + safe(d.value), 0) || 1;\n const hasActive = data.some((d) => d.active);\n\n const fill = (d: Segment, i: number): string => {\n if (scale === 'categorical') return categorical(i);\n if (scale === 'sequential') return sequential(i, data.length);\n // mono: ink for the active (or all, when none is active), muted tints otherwise.\n if (!hasActive) return chartToken.ink;\n return d.active ? chartToken.ink : chartToken.muted;\n };\n\n // Accessible foreground paired to each fill, WCAG AA, never a blend mode that guesses.\n const onFill = (d: Segment, i: number): string => {\n if (scale === 'categorical') return categoricalOn(i);\n if (scale === 'sequential') return sequentialOn(i, data.length);\n // mono: white on ink fills, ink on the light muted tint.\n if (!hasActive) return 'var(--sv-sys-color-on-primary)';\n return d.active ? 'var(--sv-sys-color-on-primary)' : 'var(--sv-sys-color-on-surface)';\n };\n\n return (\n <div className={cn('w-full', className)}>\n {/* Each segment is a bounded tile: a thin gap keeps same-coloured (muted) parts distinct,\n and an inset mark-edge keyline gives every fill a crisp edge and the 3:1 shape contrast a\n pale fill can't carry on its own (AGENTS.md rule 9). */}\n <div\n className=\"flex w-full\"\n style={{ height, gap: 2 }}\n role=\"img\"\n aria-label={data.map((d) => `${d.label} ${d.value}`).join(', ')}\n >\n {data.map((d, i) => (\n <div\n key={d.label}\n className=\"flex items-center justify-end px-2 first:rounded-l-control last:rounded-r-control\"\n style={{\n width: `${(safe(d.value) / total) * 100}%`,\n background: fill(d, i),\n boxShadow: `inset 0 0 0 1px ${chartToken.markEdge}`,\n }}\n >\n <span className=\"truncate sv-body-xs font-medium tabular-nums\" style={{ color: onFill(d, i) }}>{d.value}</span>\n </div>\n ))}\n </div>\n {showLegend && (\n <ul className=\"mt-3 flex flex-wrap gap-x-4 gap-y-1\">\n {data.map((d, i) => (\n <li key={d.label} className={cn('flex items-center gap-1.5 sv-body-sm', d.active ? 'text-on-surface' : 'text-on-surface-variant')}>\n <span className=\"size-2 shrink-0 rounded-swatch\" style={{ background: fill(d, i) }} aria-hidden=\"true\" />\n {d.label}\n </li>\n ))}\n </ul>\n )}\n </div>\n );\n}\nSegmentedBar.displayName = 'SegmentedBar';\n"],"mappings":";;;;;;;;;;;;AA2EY,cAOA,YAPA;AA5CL,SAAS,aAAa,EAAE,MAAM,SAAS,IAAI,QAAQ,QAAQ,aAAa,MAAM,UAAU,GAAsB;AAEnH,QAAM,OAAO,CAAC,MAAe,OAAO,SAAS,CAAC,KAAK,IAAI,IAAI,IAAI;AAC/D,QAAM,QAAQ,KAAK,OAAO,CAAC,GAAG,MAAM,IAAI,KAAK,EAAE,KAAK,GAAG,CAAC,KAAK;AAC7D,QAAM,YAAY,KAAK,KAAK,CAAC,MAAM,EAAE,MAAM;AAE3C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AA,0BAAC,UAAK,WAAU,kCAAiC,OAAO,EAAE,YAAY,KAAK,GAAG,CAAC,EAAE,GAAG,eAAY,QAAO;AAAA,MACtG,EAAE;AAAA,SAFI,EAAE,KAGX,CACD,GACH;AAAA,KAEJ;AAEJ;AACA,aAAa,cAAc;","names":[]}
package/dist/index.js CHANGED
@@ -11,14 +11,6 @@ import {
11
11
  Button,
12
12
  buttonVariants
13
13
  } from "./chunk-KUKSVVDZ.js";
14
- import {
15
- Card,
16
- CardContent,
17
- CardDescription,
18
- CardFooter,
19
- CardHeader,
20
- CardTitle
21
- } from "./chunk-7GXL7U5X.js";
22
14
  import {
23
15
  BarChart
24
16
  } from "./chunk-PJRCDPG5.js";
@@ -31,7 +23,7 @@ import {
31
23
  } from "./chunk-X3LG535W.js";
32
24
  import {
33
25
  SegmentedBar
34
- } from "./chunk-OY6MO6QQ.js";
26
+ } from "./chunk-AZMOEG5R.js";
35
27
  import {
36
28
  CATEGORICAL_MAX,
37
29
  categorical,
@@ -45,6 +37,14 @@ import {
45
37
  import {
46
38
  Stat
47
39
  } from "./chunk-XGYKA3GE.js";
40
+ import {
41
+ Card,
42
+ CardContent,
43
+ CardDescription,
44
+ CardFooter,
45
+ CardHeader,
46
+ CardTitle
47
+ } from "./chunk-7GXL7U5X.js";
48
48
  import "./chunk-DXRY7AS4.js";
49
49
  export {
50
50
  BarChart,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@six-vallees/ui-react",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "type": "module",
5
5
  "description": "Cairn React components — the Six Vallées design system UI, driven by the Cairn tokens.",
6
6
  "license": "UNLICENSED",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/charts/segmented-bar.tsx"],"sourcesContent":["import { cn } from '@/lib/utils';\nimport { categorical, categoricalOn, sequential, sequentialOn, chartToken } from './lib/series';\n\nexport interface Segment {\n label: string;\n value: number;\n /** Pull this segment forward (ink) and others recede. */\n active?: boolean;\n}\n\nexport interface SegmentedBarProps {\n data: Segment[];\n /** Bar thickness in px. */\n height?: number;\n /**\n * How segments get colour:\n * - `mono` (default): grayscale, active segment is ink, the rest are muted tints.\n * - `categorical`: the capped unordered palette (≤4 meaningful categories).\n * - `sequential`: single-hue magnitude ramp, in data order.\n */\n scale?: 'mono' | 'categorical' | 'sequential';\n /** Show the label + value row beneath the bar. */\n showLegend?: boolean;\n className?: string;\n}\n\n/**\n * Cairn SegmentedBar, a single horizontal bar split into labelled parts (a share-of-total\n * / stacked bar). Grayscale by default; hue is opt-in via `scale`. Every segment carries a\n * text label + value, so meaning never rests on colour alone (WCAG-safe). Zero-dependency.\n */\nexport function SegmentedBar({ data, height = 40, scale = 'mono', showLegend = true, className }: SegmentedBarProps) {\n // Negative / non-finite segment values would produce invalid or overflowing widths; clamp to 0.\n const safe = (v: number) => (Number.isFinite(v) && v > 0 ? v : 0);\n const total = data.reduce((s, d) => s + safe(d.value), 0) || 1;\n const hasActive = data.some((d) => d.active);\n\n const fill = (d: Segment, i: number): string => {\n if (scale === 'categorical') return categorical(i);\n if (scale === 'sequential') return sequential(i, data.length);\n // mono: ink for the active (or all, when none is active), muted tints otherwise.\n if (!hasActive) return chartToken.ink;\n return d.active ? chartToken.ink : chartToken.muted;\n };\n\n // Accessible foreground paired to each fill, WCAG AA, never a blend mode that guesses.\n const onFill = (d: Segment, i: number): string => {\n if (scale === 'categorical') return categoricalOn(i);\n if (scale === 'sequential') return sequentialOn(i, data.length);\n // mono: white on ink fills, ink on the light muted tint.\n if (!hasActive) return 'var(--sv-sys-color-on-primary)';\n return d.active ? 'var(--sv-sys-color-on-primary)' : 'var(--sv-sys-color-on-surface)';\n };\n\n // A pale muted segment is < 3:1 vs the surface; a keyline round the bar carries its shape\n // contrast (AGENTS.md rule 9). Only needed in mono when some segment recedes to the muted tint.\n const needsEdge = scale === 'mono' && hasActive;\n\n return (\n <div className={cn('w-full', className)}>\n <div\n className=\"flex w-full overflow-hidden rounded-control\"\n style={{\n height,\n ...(needsEdge ? { outline: `1px solid ${chartToken.markEdge}`, outlineOffset: '-1px' } : {}),\n }}\n role=\"img\"\n aria-label={data.map((d) => `${d.label} ${d.value}`).join(', ')}\n >\n {data.map((d, i) => (\n <div\n key={d.label}\n className=\"flex items-center justify-end px-2 first:rounded-l-control last:rounded-r-control\"\n style={{ width: `${(safe(d.value) / total) * 100}%`, background: fill(d, i) }}\n >\n <span className=\"truncate sv-body-xs font-medium tabular-nums\" style={{ color: onFill(d, i) }}>{d.value}</span>\n </div>\n ))}\n </div>\n {showLegend && (\n <ul className=\"mt-3 flex flex-wrap gap-x-4 gap-y-1\">\n {data.map((d, i) => (\n <li key={d.label} className={cn('flex items-center gap-1.5 sv-body-sm', d.active ? 'text-on-surface' : 'text-on-surface-variant')}>\n <span className=\"size-2 shrink-0 rounded-swatch\" style={{ background: fill(d, i) }} aria-hidden=\"true\" />\n {d.label}\n </li>\n ))}\n </ul>\n )}\n </div>\n );\n}\nSegmentedBar.displayName = 'SegmentedBar';\n"],"mappings":";;;;;;;;;;;;AA2EY,cAOA,YAPA;AA5CL,SAAS,aAAa,EAAE,MAAM,SAAS,IAAI,QAAQ,QAAQ,aAAa,MAAM,UAAU,GAAsB;AAEnH,QAAM,OAAO,CAAC,MAAe,OAAO,SAAS,CAAC,KAAK,IAAI,IAAI,IAAI;AAC/D,QAAM,QAAQ,KAAK,OAAO,CAAC,GAAG,MAAM,IAAI,KAAK,EAAE,KAAK,GAAG,CAAC,KAAK;AAC7D,QAAM,YAAY,KAAK,KAAK,CAAC,MAAM,EAAE,MAAM;AAE3C,QAAM,OAAO,CAAC,GAAY,MAAsB;AAC9C,QAAI,UAAU,cAAe,QAAO,YAAY,CAAC;AACjD,QAAI,UAAU,aAAc,QAAO,WAAW,GAAG,KAAK,MAAM;AAE5D,QAAI,CAAC,UAAW,QAAO,WAAW;AAClC,WAAO,EAAE,SAAS,WAAW,MAAM,WAAW;AAAA,EAChD;AAGA,QAAM,SAAS,CA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