@six-vallees/ui-react 0.1.0 → 0.1.2
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.
- package/README.md +54 -0
- package/dist/button/button.d.ts +23 -0
- package/dist/button/button.js +10 -0
- package/dist/button/button.js.map +1 -0
- package/dist/charts/area-chart.d.ts +27 -0
- package/dist/charts/area-chart.js +9 -0
- package/dist/charts/area-chart.js.map +1 -0
- package/dist/charts/bar-chart.d.ts +29 -0
- package/dist/charts/bar-chart.js +10 -0
- package/dist/charts/bar-chart.js.map +1 -0
- package/dist/charts/lib/path.d.ts +12 -0
- package/dist/charts/lib/path.js +11 -0
- package/dist/charts/lib/path.js.map +1 -0
- package/dist/charts/lib/series.d.ts +35 -0
- package/dist/charts/lib/series.js +19 -0
- package/dist/charts/lib/series.js.map +1 -0
- package/dist/charts/ring.d.ts +44 -0
- package/dist/charts/ring.js +10 -0
- package/dist/charts/ring.js.map +1 -0
- package/dist/charts/segmented-bar.d.ts +34 -0
- package/dist/charts/segmented-bar.js +9 -0
- package/dist/charts/segmented-bar.js.map +1 -0
- package/dist/charts/sparkline.d.ts +19 -0
- package/dist/charts/sparkline.js +9 -0
- package/dist/charts/sparkline.js.map +1 -0
- package/dist/charts/stat.d.ts +22 -0
- package/dist/charts/stat.js +8 -0
- package/dist/charts/stat.js.map +1 -0
- package/dist/chunk-27MWE4F5.js +24 -0
- package/dist/chunk-27MWE4F5.js.map +1 -0
- package/dist/chunk-5DZPPT7X.js +30 -0
- package/dist/chunk-5DZPPT7X.js.map +1 -0
- package/dist/chunk-DXRY7AS4.js +11 -0
- package/dist/chunk-DXRY7AS4.js.map +1 -0
- package/dist/chunk-HXRF55LD.js +64 -0
- package/dist/chunk-HXRF55LD.js.map +1 -0
- package/dist/chunk-I2PXLL75.js +41 -0
- package/dist/chunk-I2PXLL75.js.map +1 -0
- package/dist/chunk-IAKPFV2O.js +31 -0
- package/dist/chunk-IAKPFV2O.js.map +1 -0
- package/dist/chunk-IVQKYAL6.js +30 -0
- package/dist/chunk-IVQKYAL6.js.map +1 -0
- package/dist/chunk-N5ZJZ7I3.js +18 -0
- package/dist/chunk-N5ZJZ7I3.js.map +1 -0
- package/dist/chunk-OIL3X3BZ.js +98 -0
- package/dist/chunk-OIL3X3BZ.js.map +1 -0
- package/dist/chunk-QZYA5GS2.js +40 -0
- package/dist/chunk-QZYA5GS2.js.map +1 -0
- package/dist/chunk-SN3OYOEU.js +89 -0
- package/dist/chunk-SN3OYOEU.js.map +1 -0
- package/dist/chunk-UNKWUPX2.js +91 -0
- package/dist/chunk-UNKWUPX2.js.map +1 -0
- package/dist/chunk-WBTUZO4N.js +74 -0
- package/dist/chunk-WBTUZO4N.js.map +1 -0
- package/dist/icon/icon.d.ts +30 -0
- package/dist/icon/icon.js +8 -0
- package/dist/icon/icon.js.map +1 -0
- package/dist/index.d.ts +15 -257
- package/dist/index.js +61 -437
- package/dist/index.js.map +1 -1
- package/dist/lib/utils.d.ts +6 -0
- package/dist/lib/utils.js +7 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/logo/logo-mark.d.ts +12 -0
- package/dist/logo/logo-mark.js +7 -0
- package/dist/logo/logo-mark.js.map +1 -0
- package/dist/logo/logo.d.ts +13 -0
- package/dist/logo/logo.js +7 -0
- package/dist/logo/logo.js.map +1 -0
- package/package.json +10 -5
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# @six-vallees/ui-react
|
|
2
|
+
|
|
3
|
+
Cairn React components — the Six Vallées design system UI, driven by the Cairn tokens.
|
|
4
|
+
Neo-grotesque, grayscale-first, WCAG AA, light and dark.
|
|
5
|
+
|
|
6
|
+
> Cairn is Six Vallées' **own** system (Zone C). Client and prospect projects carry their own
|
|
7
|
+
> brand — this package is not meant for them.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @six-vallees/ui-react @six-vallees/tokens
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
`react` and `react-dom` are peers; `@phosphor-icons/react` is an optional peer (only for `Icon`).
|
|
16
|
+
|
|
17
|
+
## Use
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { Button } from '@six-vallees/ui-react';
|
|
21
|
+
|
|
22
|
+
<Button variant="primary" size="md">Save</Button>;
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The components style themselves with Cairn's token utilities (`bg-primary`, `rounded-control`,
|
|
26
|
+
…). Wire them once with the Tailwind preset from `@six-vallees/tokens`, and tell Tailwind to
|
|
27
|
+
scan this package so those classes are generated:
|
|
28
|
+
|
|
29
|
+
```css
|
|
30
|
+
@import "tailwindcss";
|
|
31
|
+
@import "@six-vallees/tokens/theme";
|
|
32
|
+
@source "../node_modules/@six-vallees/ui-react/dist";
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Full setup + a working example: **[Get started](https://cairn.sixvallees.com)**.
|
|
36
|
+
|
|
37
|
+
## Components
|
|
38
|
+
|
|
39
|
+
| | |
|
|
40
|
+
| --- | --- |
|
|
41
|
+
| `Button` | Four variants, three sizes, `asChild`. |
|
|
42
|
+
| `Icon` | Phosphor wrapper, preset sizes, accessible by default. |
|
|
43
|
+
| `Logo` / `LogoMark` | Six Vallées wordmark + symbol, `currentColor`. |
|
|
44
|
+
| `Sparkline` | Compact axis-less trend line. |
|
|
45
|
+
| `AreaChart` · `BarChart` | Line/area and bar, SSR-safe SVG. |
|
|
46
|
+
| `Stat` | Metric with optional delta + trailing sparkline. |
|
|
47
|
+
| `Ring` · `SegmentedBar` | Radial progress and share-of-total, grayscale-first. |
|
|
48
|
+
|
|
49
|
+
Helpers: `categorical`, `sequential`, `chartToken` (data-viz color, `sys.chart.*` tokens).
|
|
50
|
+
|
|
51
|
+
## Notes
|
|
52
|
+
|
|
53
|
+
- Built to ESM + type declarations (tsup); tree-shakeable (`sideEffects: false`).
|
|
54
|
+
- No CSS is shipped — components carry Tailwind class strings; your Tailwind generates them.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { VariantProps } from 'class-variance-authority';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Cairn Button. Consumes the design tokens through the Tailwind bridge
|
|
7
|
+
* (bg-primary, rounded-control, …), install the Cairn theme in the target project.
|
|
8
|
+
*/
|
|
9
|
+
declare const buttonVariants: (props?: ({
|
|
10
|
+
variant?: "primary" | "secondary" | "ghost" | "danger" | null | undefined;
|
|
11
|
+
size?: "sm" | "md" | "lg" | null | undefined;
|
|
12
|
+
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
13
|
+
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
|
|
14
|
+
/** Visual style of the button. */
|
|
15
|
+
variant?: 'primary' | 'secondary' | 'ghost' | 'danger';
|
|
16
|
+
/** Control height and padding. */
|
|
17
|
+
size?: 'sm' | 'md' | 'lg';
|
|
18
|
+
/** Render as the child element (e.g. an `<a>`) instead of a `<button>`. */
|
|
19
|
+
asChild?: boolean;
|
|
20
|
+
}
|
|
21
|
+
declare const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement>>;
|
|
22
|
+
|
|
23
|
+
export { Button, type ButtonProps, buttonVariants };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface AreaChartProps {
|
|
4
|
+
/** Values, or `{ label, value }` points. */
|
|
5
|
+
data: (number | {
|
|
6
|
+
label?: string;
|
|
7
|
+
value: number;
|
|
8
|
+
})[];
|
|
9
|
+
height?: number;
|
|
10
|
+
/** Index of the point to mark with a guideline + callout. */
|
|
11
|
+
markerIndex?: number;
|
|
12
|
+
markerLabel?: string;
|
|
13
|
+
className?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Cairn AreaChart, a smooth line with a flat fill. Colour follows `currentColor`.
|
|
17
|
+
* Zero-dependency SVG: renders server-side (Astro-safe), no client JS. The horizontal
|
|
18
|
+
* axis stretches to the container (non-scaling strokes keep the line crisp); the marker
|
|
19
|
+
* dot + callout are HTML overlays so they never distort. An interactive tier (hover
|
|
20
|
+
* tooltips) belongs to the visx layer, this is the static SSR tier.
|
|
21
|
+
*/
|
|
22
|
+
declare function AreaChart({ data, height, markerIndex, markerLabel, className }: AreaChartProps): React.JSX.Element | null;
|
|
23
|
+
declare namespace AreaChart {
|
|
24
|
+
var displayName: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { AreaChart, type AreaChartProps };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface BarDatum {
|
|
4
|
+
label: string;
|
|
5
|
+
value: number;
|
|
6
|
+
/** Highlight this bar (ink) and show its value by default. */
|
|
7
|
+
active?: boolean;
|
|
8
|
+
}
|
|
9
|
+
interface BarChartProps {
|
|
10
|
+
data: BarDatum[];
|
|
11
|
+
height?: number;
|
|
12
|
+
showValue?: boolean;
|
|
13
|
+
/** Colour of the promoted bar. Defaults to ink; `accent` uses the categorical blue. */
|
|
14
|
+
tone?: 'ink' | 'accent';
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Cairn BarChart, grayscale-first: muted neutral bars, the active bar promoted to ink
|
|
19
|
+
* (or the categorical blue via `tone="accent"`) with a value pill. Interactive: hover any
|
|
20
|
+
* bar to promote it and reveal its value. Colours resolve from `sys.chart.*` tokens (via
|
|
21
|
+
* `chartToken`), so a theme swap recolours the chart for free. The chart carries a text
|
|
22
|
+
* `aria-label` listing every label/value, so the data is never mouse-only (WCAG-safe).
|
|
23
|
+
*/
|
|
24
|
+
declare function BarChart({ data, height, showValue, tone, className }: BarChartProps): React.JSX.Element;
|
|
25
|
+
declare namespace BarChart {
|
|
26
|
+
var displayName: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { BarChart, type BarChartProps, type BarDatum };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Build a smooth path (cubic beziers through midpoints) from points. */
|
|
2
|
+
declare function smooth(pts: readonly (readonly [number, number])[]): string;
|
|
3
|
+
/** Coerce non-finite values (NaN/Infinity) to 0 so a stray value can't poison the geometry. */
|
|
4
|
+
declare function finite(values: readonly number[]): number[];
|
|
5
|
+
/** Min / max / non-zero range of a series (range falls back to 1 when the series is flat). */
|
|
6
|
+
declare function extent(values: readonly number[]): {
|
|
7
|
+
min: number;
|
|
8
|
+
max: number;
|
|
9
|
+
range: number;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { extent, finite, smooth };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cairn data-viz colour, the single place a series gets a colour.
|
|
3
|
+
*
|
|
4
|
+
* Rule: grayscale first. A single series is `ink`; a comparison series is `muted`.
|
|
5
|
+
* Reach for hue only when categories are genuinely unordered (`categorical`, capped
|
|
6
|
+
* at 4) or encode magnitude (`sequential`, single-hue). Never hand-pick a hex, every
|
|
7
|
+
* value here is a `sys.chart.*` token resolved at runtime via its CSS variable, so a
|
|
8
|
+
* theme swap (light↔dark) recolours the charts for free.
|
|
9
|
+
*/
|
|
10
|
+
/** Semantic chart roles → their CSS variable. The single place a chart hue is named;
|
|
11
|
+
* components consume these, never the raw `--sv-sys-chart-*` var. `accent` is the one
|
|
12
|
+
* opt-in hue (categorical blue) a fixed-shape chart may promote a value to. */
|
|
13
|
+
declare const chartToken: {
|
|
14
|
+
readonly ink: "var(--sv-sys-chart-ink)";
|
|
15
|
+
readonly muted: "var(--sv-sys-chart-muted)";
|
|
16
|
+
readonly markEdge: "var(--sv-sys-chart-mark-edge)";
|
|
17
|
+
readonly accent: "var(--sv-sys-chart-categorical-2)";
|
|
18
|
+
readonly grid: "var(--sv-sys-chart-grid)";
|
|
19
|
+
readonly axis: "var(--sv-sys-chart-axis)";
|
|
20
|
+
readonly track: "var(--sv-sys-chart-track)";
|
|
21
|
+
};
|
|
22
|
+
declare const CATEGORICAL_MAX: 4;
|
|
23
|
+
/** Promoted-mark colour for a fixed-shape chart: `ink` by default, categorical blue for `accent`.
|
|
24
|
+
* The single definition of the mono `tone` option, shared by BarChart and Ring. */
|
|
25
|
+
declare function toneFill(tone: 'ink' | 'accent'): string;
|
|
26
|
+
/** Colour for category `i` (0-based). Wraps past the cap, pair with a label/pattern. */
|
|
27
|
+
declare function categorical(i: number): string;
|
|
28
|
+
/** WCAG-AA foreground for text drawn on `categorical(i)`. */
|
|
29
|
+
declare function categoricalOn(i: number): string;
|
|
30
|
+
/** Colour for the `i`-th of `n` steps on the single-hue magnitude ramp. */
|
|
31
|
+
declare function sequential(i: number, n: number): string;
|
|
32
|
+
/** WCAG-AA foreground for text drawn on `sequential(i, n)`. */
|
|
33
|
+
declare function sequentialOn(i: number, n: number): string;
|
|
34
|
+
|
|
35
|
+
export { CATEGORICAL_MAX, categorical, categoricalOn, chartToken, sequential, sequentialOn, toneFill };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CATEGORICAL_MAX,
|
|
3
|
+
categorical,
|
|
4
|
+
categoricalOn,
|
|
5
|
+
chartToken,
|
|
6
|
+
sequential,
|
|
7
|
+
sequentialOn,
|
|
8
|
+
toneFill
|
|
9
|
+
} from "../../chunk-WBTUZO4N.js";
|
|
10
|
+
export {
|
|
11
|
+
CATEGORICAL_MAX,
|
|
12
|
+
categorical,
|
|
13
|
+
categoricalOn,
|
|
14
|
+
chartToken,
|
|
15
|
+
sequential,
|
|
16
|
+
sequentialOn,
|
|
17
|
+
toneFill
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=series.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface RingProps {
|
|
4
|
+
/** Progress, 0-100. */
|
|
5
|
+
value: number;
|
|
6
|
+
/** Outer diameter in px. */
|
|
7
|
+
size?: number;
|
|
8
|
+
/** Ring thickness in px. */
|
|
9
|
+
thickness?: number;
|
|
10
|
+
/** Colour of the filled arc. Defaults to ink; `accent` uses categorical blue. */
|
|
11
|
+
tone?: 'ink' | 'accent';
|
|
12
|
+
/**
|
|
13
|
+
* Explicit arc colour (a token / CSS colour), overrides `tone`. Pass only colours that
|
|
14
|
+
* clear 3:1 against the surface as a thin stroke, ink, blue, or a dark graphite. Acid
|
|
15
|
+
* and mid-gray are fill-only (they fail as a line); see AGENTS.md rule 9.
|
|
16
|
+
*/
|
|
17
|
+
color?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Draw a darker keyline under the arc so a light, low-contrast colour (acid) stays
|
|
20
|
+
* perceptible, the rim carries the 3:1 shape contrast the fill can't (AGENTS.md rule 9).
|
|
21
|
+
* `true` uses ink; pass a colour (e.g. `sys.color.accent-edge`) for a tonal, in-family rim.
|
|
22
|
+
*/
|
|
23
|
+
casing?: boolean | string;
|
|
24
|
+
/** Fill the arc from empty on mount. Honours `prefers-reduced-motion`. */
|
|
25
|
+
animate?: boolean;
|
|
26
|
+
/** Centre content, e.g. the value. Omit for a bare ring. */
|
|
27
|
+
children?: React.ReactNode;
|
|
28
|
+
/** Accessible label; falls back to "<value>%". */
|
|
29
|
+
'aria-label'?: string;
|
|
30
|
+
className?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Cairn Ring, single-value radial progress. Grayscale by default (ink arc on a
|
|
34
|
+
* neutral track); `tone="accent"` opts into the categorical blue, or pass an explicit
|
|
35
|
+
* `color`. The arc fills from empty on mount (rounded cap, 12 o'clock, clockwise).
|
|
36
|
+
* Zero-dependency SVG. A client component (`'use client'`): the mount animation uses state;
|
|
37
|
+
* pass `animate={false}` to render it statically.
|
|
38
|
+
*/
|
|
39
|
+
declare function Ring({ value, size, thickness, tone, color, casing, animate, children, className, 'aria-label': ariaLabel, }: RingProps): React.JSX.Element;
|
|
40
|
+
declare namespace Ring {
|
|
41
|
+
var displayName: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { Ring, type RingProps };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface Segment {
|
|
4
|
+
label: string;
|
|
5
|
+
value: number;
|
|
6
|
+
/** Pull this segment forward (ink) and others recede. */
|
|
7
|
+
active?: boolean;
|
|
8
|
+
}
|
|
9
|
+
interface SegmentedBarProps {
|
|
10
|
+
data: Segment[];
|
|
11
|
+
/** Bar thickness in px. */
|
|
12
|
+
height?: number;
|
|
13
|
+
/**
|
|
14
|
+
* How segments get colour:
|
|
15
|
+
* - `mono` (default): grayscale, active segment is ink, the rest are muted tints.
|
|
16
|
+
* - `categorical`: the capped unordered palette (≤4 meaningful categories).
|
|
17
|
+
* - `sequential`: single-hue magnitude ramp, in data order.
|
|
18
|
+
*/
|
|
19
|
+
scale?: 'mono' | 'categorical' | 'sequential';
|
|
20
|
+
/** Show the label + value row beneath the bar. */
|
|
21
|
+
showLegend?: boolean;
|
|
22
|
+
className?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Cairn SegmentedBar, a single horizontal bar split into labelled parts (a share-of-total
|
|
26
|
+
* / stacked bar). Grayscale by default; hue is opt-in via `scale`. Every segment carries a
|
|
27
|
+
* text label + value, so meaning never rests on colour alone (WCAG-safe). Zero-dependency.
|
|
28
|
+
*/
|
|
29
|
+
declare function SegmentedBar({ data, height, scale, showLegend, className }: SegmentedBarProps): React.JSX.Element;
|
|
30
|
+
declare namespace SegmentedBar {
|
|
31
|
+
var displayName: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { type Segment, SegmentedBar, type SegmentedBarProps };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface SparklineProps {
|
|
4
|
+
/** The series of values. */
|
|
5
|
+
data: number[];
|
|
6
|
+
width?: number;
|
|
7
|
+
height?: number;
|
|
8
|
+
/** `line` or filled `area`. */
|
|
9
|
+
type?: 'line' | 'area';
|
|
10
|
+
strokeWidth?: number;
|
|
11
|
+
className?: string;
|
|
12
|
+
}
|
|
13
|
+
/** Cairn Sparkline, a compact, axis-less trend line. Colour follows currentColor. */
|
|
14
|
+
declare function Sparkline({ data, width, height, type, strokeWidth, className }: SparklineProps): React.JSX.Element | null;
|
|
15
|
+
declare namespace Sparkline {
|
|
16
|
+
var displayName: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { Sparkline, type SparklineProps };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface StatProps {
|
|
4
|
+
/** The metric, pre-formatted (e.g. "3,484" or "118 lbs"). */
|
|
5
|
+
value: string;
|
|
6
|
+
label?: string;
|
|
7
|
+
/** Change indicator. `tone` colours it (success / error / neutral). */
|
|
8
|
+
delta?: {
|
|
9
|
+
value: string;
|
|
10
|
+
tone?: 'success' | 'error' | 'neutral';
|
|
11
|
+
};
|
|
12
|
+
/** Trailing visual, e.g. a `<Sparkline />`. */
|
|
13
|
+
children?: React.ReactNode;
|
|
14
|
+
className?: string;
|
|
15
|
+
}
|
|
16
|
+
/** Cairn Stat, a metric with an optional coloured delta and a trailing sparkline. */
|
|
17
|
+
declare function Stat({ value, label, delta, children, className }: StatProps): React.JSX.Element;
|
|
18
|
+
declare namespace Stat {
|
|
19
|
+
var displayName: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { Stat, type StatProps };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/charts/lib/path.ts
|
|
2
|
+
function smooth(pts) {
|
|
3
|
+
return pts.reduce((acc, [x, y], i, arr) => {
|
|
4
|
+
if (i === 0) return `M ${x},${y}`;
|
|
5
|
+
const [px, py] = arr[i - 1];
|
|
6
|
+
const cx = (px + x) / 2;
|
|
7
|
+
return `${acc} C ${cx},${py} ${cx},${y} ${x},${y}`;
|
|
8
|
+
}, "");
|
|
9
|
+
}
|
|
10
|
+
function finite(values) {
|
|
11
|
+
return values.map((v) => Number.isFinite(v) ? v : 0);
|
|
12
|
+
}
|
|
13
|
+
function extent(values) {
|
|
14
|
+
const min = Math.min(...values);
|
|
15
|
+
const max = Math.max(...values);
|
|
16
|
+
return { min, max, range: max - min || 1 };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
smooth,
|
|
21
|
+
finite,
|
|
22
|
+
extent
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=chunk-27MWE4F5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/charts/lib/path.ts"],"sourcesContent":["/** Build a smooth path (cubic beziers through midpoints) from points. */\nexport function smooth(pts: readonly (readonly [number, number])[]): string {\n return pts.reduce((acc, [x, y], i, arr) => {\n if (i === 0) return `M ${x},${y}`;\n const [px, py] = arr[i - 1];\n const cx = (px + x) / 2;\n return `${acc} C ${cx},${py} ${cx},${y} ${x},${y}`;\n }, '');\n}\n\n/** Coerce non-finite values (NaN/Infinity) to 0 so a stray value can't poison the geometry. */\nexport function finite(values: readonly number[]): number[] {\n return values.map((v) => (Number.isFinite(v) ? v : 0));\n}\n\n/** Min / max / non-zero range of a series (range falls back to 1 when the series is flat). */\nexport function extent(values: readonly number[]): { min: number; max: number; range: number } {\n const min = Math.min(...values);\n const max = Math.max(...values);\n return { min, max, range: max - min || 1 };\n}\n"],"mappings":";AACO,SAAS,OAAO,KAAqD;AAC1E,SAAO,IAAI,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,GAAG,QAAQ;AACzC,QAAI,MAAM,EAAG,QAAO,KAAK,CAAC,IAAI,CAAC;AAC/B,UAAM,CAAC,IAAI,EAAE,IAAI,IAAI,IAAI,CAAC;AAC1B,UAAM,MAAM,KAAK,KAAK;AACtB,WAAO,GAAG,GAAG,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AAAA,EAClD,GAAG,EAAE;AACP;AAGO,SAAS,OAAO,QAAqC;AAC1D,SAAO,OAAO,IAAI,CAAC,MAAO,OAAO,SAAS,CAAC,IAAI,IAAI,CAAE;AACvD;AAGO,SAAS,OAAO,QAAwE;AAC7F,QAAM,MAAM,KAAK,IAAI,GAAG,MAAM;AAC9B,QAAM,MAAM,KAAK,IAAI,GAAG,MAAM;AAC9B,SAAO,EAAE,KAAK,KAAK,OAAO,MAAM,OAAO,EAAE;AAC3C;","names":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
cn
|
|
3
|
+
} from "./chunk-DXRY7AS4.js";
|
|
4
|
+
|
|
5
|
+
// src/charts/stat.tsx
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
function Stat({ value, label, delta, children, className }) {
|
|
8
|
+
const tone = delta?.tone ?? "neutral";
|
|
9
|
+
const toneCls = tone === "success" ? "bg-success-container text-on-success-container" : tone === "error" ? "bg-error-container text-on-error-container" : "bg-surface-muted text-on-surface-variant";
|
|
10
|
+
const arrow = tone === "success" ? "\u2191" : tone === "error" ? "\u2193" : null;
|
|
11
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("rounded-card border border-outline p-5", className), children: [
|
|
12
|
+
label && /* @__PURE__ */ jsx("p", { className: "sv-body-sm text-on-surface-variant", children: label }),
|
|
13
|
+
/* @__PURE__ */ jsxs("div", { className: "mt-2 flex items-end justify-between gap-4", children: [
|
|
14
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
15
|
+
/* @__PURE__ */ jsx("div", { className: "sv-metric tabular-nums text-on-surface", children: value }),
|
|
16
|
+
delta && /* @__PURE__ */ jsx("div", { className: "mt-2", children: /* @__PURE__ */ jsxs("span", { className: cn("inline-flex items-center gap-1 rounded-pill px-2 py-0.5 sv-body-sm font-medium", toneCls), children: [
|
|
17
|
+
arrow && /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: arrow }),
|
|
18
|
+
delta.value
|
|
19
|
+
] }) })
|
|
20
|
+
] }),
|
|
21
|
+
children && /* @__PURE__ */ jsx("div", { className: "shrink-0 text-on-surface-variant", children })
|
|
22
|
+
] })
|
|
23
|
+
] });
|
|
24
|
+
}
|
|
25
|
+
Stat.displayName = "Stat";
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
Stat
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=chunk-5DZPPT7X.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/charts/stat.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cn } from '@/lib/utils';\n\nexport interface StatProps {\n /** The metric, pre-formatted (e.g. \"3,484\" or \"118 lbs\"). */\n value: string;\n label?: string;\n /** Change indicator. `tone` colours it (success / error / neutral). */\n delta?: { value: string; tone?: 'success' | 'error' | 'neutral' };\n /** Trailing visual, e.g. a `<Sparkline />`. */\n children?: React.ReactNode;\n className?: string;\n}\n\n/** Cairn Stat, a metric with an optional coloured delta and a trailing sparkline. */\nexport function Stat({ value, label, delta, children, className }: StatProps) {\n const tone = delta?.tone ?? 'neutral';\n // Message-as-meaning lives in a status container with its paired on-* text (AGENTS.md\n // rule 4), never as bare coloured text — so the delta is a small container pill.\n const toneCls =\n tone === 'success'\n ? 'bg-success-container text-on-success-container'\n : tone === 'error'\n ? 'bg-error-container text-on-error-container'\n : 'bg-surface-muted text-on-surface-variant';\n // A directional glyph so the up/down meaning never rests on hue alone (rule 4).\n const arrow = tone === 'success' ? '↑' : tone === 'error' ? '↓' : null;\n return (\n <div className={cn('rounded-card border border-outline p-5', className)}>\n {label && <p className=\"sv-body-sm text-on-surface-variant\">{label}</p>}\n <div className=\"mt-2 flex items-end justify-between gap-4\">\n <div>\n <div className=\"sv-metric tabular-nums text-on-surface\">{value}</div>\n {delta && (\n <div className=\"mt-2\">\n <span className={cn('inline-flex items-center gap-1 rounded-pill px-2 py-0.5 sv-body-sm font-medium', toneCls)}>\n {arrow && <span aria-hidden=\"true\">{arrow}</span>}\n {delta.value}\n </span>\n </div>\n )}\n </div>\n {children && <div className=\"shrink-0 text-on-surface-variant\">{children}</div>}\n </div>\n </div>\n );\n}\nStat.displayName = 'Stat';\n"],"mappings":";;;;;AA6BgB,cAMF,YANE;AAdT,SAAS,KAAK,EAAE,OAAO,OAAO,OAAO,UAAU,UAAU,GAAc;AAC5E,QAAM,OAAO,OAAO,QAAQ;AAG5B,QAAM,UACJ,SAAS,YACL,mDACA,SAAS,UACP,+CACA;AAER,QAAM,QAAQ,SAAS,YAAY,WAAM,SAAS,UAAU,WAAM;AAClE,SACE,qBAAC,SAAI,WAAW,GAAG,0CAA0C,SAAS,GACnE;AAAA,aAAS,oBAAC,OAAE,WAAU,sCAAsC,iBAAM;AAAA,IACnE,qBAAC,SAAI,WAAU,6CACb;AAAA,2BAAC,SACC;AAAA,4BAAC,SAAI,WAAU,0CAA0C,iBAAM;AAAA,QAC9D,SACC,oBAAC,SAAI,WAAU,QACb,+BAAC,UAAK,WAAW,GAAG,kFAAkF,OAAO,GAC1G;AAAA,mBAAS,oBAAC,UAAK,eAAY,QAAQ,iBAAM;AAAA,UACzC,MAAM;AAAA,WACT,GACF;AAAA,SAEJ;AAAA,MACC,YAAY,oBAAC,SAAI,WAAU,oCAAoC,UAAS;AAAA,OAC3E;AAAA,KACF;AAEJ;AACA,KAAK,cAAc;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/utils.ts"],"sourcesContent":["import { clsx, type ClassValue } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\n/** Merge class names, resolving Tailwind conflicts (last wins). */\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n"],"mappings":";AAAA,SAAS,YAA6B;AACtC,SAAS,eAAe;AAGjB,SAAS,MAAM,QAAsB;AAC1C,SAAO,QAAQ,KAAK,MAAM,CAAC;AAC7B;","names":[]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
categorical,
|
|
3
|
+
categoricalOn,
|
|
4
|
+
chartToken,
|
|
5
|
+
sequential,
|
|
6
|
+
sequentialOn
|
|
7
|
+
} from "./chunk-WBTUZO4N.js";
|
|
8
|
+
import {
|
|
9
|
+
cn
|
|
10
|
+
} from "./chunk-DXRY7AS4.js";
|
|
11
|
+
|
|
12
|
+
// src/charts/segmented-bar.tsx
|
|
13
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
14
|
+
function SegmentedBar({ data, height = 40, scale = "mono", showLegend = true, className }) {
|
|
15
|
+
const safe = (v) => Number.isFinite(v) && v > 0 ? v : 0;
|
|
16
|
+
const total = data.reduce((s, d) => s + safe(d.value), 0) || 1;
|
|
17
|
+
const hasActive = data.some((d) => d.active);
|
|
18
|
+
const fill = (d, i) => {
|
|
19
|
+
if (scale === "categorical") return categorical(i);
|
|
20
|
+
if (scale === "sequential") return sequential(i, data.length);
|
|
21
|
+
if (!hasActive) return chartToken.ink;
|
|
22
|
+
return d.active ? chartToken.ink : chartToken.muted;
|
|
23
|
+
};
|
|
24
|
+
const onFill = (d, i) => {
|
|
25
|
+
if (scale === "categorical") return categoricalOn(i);
|
|
26
|
+
if (scale === "sequential") return sequentialOn(i, data.length);
|
|
27
|
+
if (!hasActive) return "var(--sv-sys-color-on-primary)";
|
|
28
|
+
return d.active ? "var(--sv-sys-color-on-primary)" : "var(--sv-sys-color-on-surface)";
|
|
29
|
+
};
|
|
30
|
+
const needsEdge = scale === "mono" && hasActive;
|
|
31
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("w-full", className), children: [
|
|
32
|
+
/* @__PURE__ */ jsx(
|
|
33
|
+
"div",
|
|
34
|
+
{
|
|
35
|
+
className: "flex w-full overflow-hidden rounded-control",
|
|
36
|
+
style: {
|
|
37
|
+
height,
|
|
38
|
+
...needsEdge ? { outline: `1px solid ${chartToken.markEdge}`, outlineOffset: "-1px" } : {}
|
|
39
|
+
},
|
|
40
|
+
role: "img",
|
|
41
|
+
"aria-label": data.map((d) => `${d.label} ${d.value}`).join(", "),
|
|
42
|
+
children: data.map((d, i) => /* @__PURE__ */ jsx(
|
|
43
|
+
"div",
|
|
44
|
+
{
|
|
45
|
+
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) },
|
|
47
|
+
children: /* @__PURE__ */ jsx("span", { className: "truncate sv-body-xs font-medium tabular-nums", style: { color: onFill(d, i) }, children: d.value })
|
|
48
|
+
},
|
|
49
|
+
d.label
|
|
50
|
+
))
|
|
51
|
+
}
|
|
52
|
+
),
|
|
53
|
+
showLegend && /* @__PURE__ */ jsx("ul", { className: "mt-3 flex flex-wrap gap-x-4 gap-y-1", children: data.map((d, i) => /* @__PURE__ */ jsxs("li", { className: cn("flex items-center gap-1.5 sv-body-sm", d.active ? "text-on-surface" : "text-on-surface-variant"), children: [
|
|
54
|
+
/* @__PURE__ */ jsx("span", { className: "size-2 shrink-0 rounded-[2px]", style: { background: fill(d, i) }, "aria-hidden": "true" }),
|
|
55
|
+
d.label
|
|
56
|
+
] }, d.label)) })
|
|
57
|
+
] });
|
|
58
|
+
}
|
|
59
|
+
SegmentedBar.displayName = "SegmentedBar";
|
|
60
|
+
|
|
61
|
+
export {
|
|
62
|
+
SegmentedBar
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=chunk-HXRF55LD.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 // 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-[2px]\" 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,CAAC,GAAY,MAAsB;AAChD,QAAI,UAAU,cAAe,QAAO,cAAc,CAAC;AACnD,QAAI,UAAU,aAAc,QAAO,aAAa,GAAG,KAAK,MAAM;AAE9D,QAAI,CAAC,UAAW,QAAO;AACvB,WAAO,EAAE,SAAS,mCAAmC;AAAA,EACvD;AAIA,QAAM,YAAY,UAAU,UAAU;AAEtC,SACE,qBAAC,SAAI,WAAW,GAAG,UAAU,SAAS,GACpC;AAAA;AAAA,MAAC;AAAA;AAAA,QACC,WAAU;AAAA,QACV,OAAO;AAAA,UACL;AAAA,UACA,GAAI,YAAY,EAAE,SAAS,aAAa,WAAW,QAAQ,IAAI,eAAe,OAAO,IAAI,CAAC;AAAA,QAC5F;AAAA,QACA,MAAK;AAAA,QACL,cAAY,KAAK,IAAI,CAAC,MAAM,GAAG,EAAE,KAAK,IAAI,EAAE,KAAK,EAAE,EAAE,KAAK,IAAI;AAAA,QAE7D,eAAK,IAAI,CAAC,GAAG,MACZ;AAAA,UAAC;AAAA;AAAA,YAEC,WAAU;AAAA,YACV,OAAO,EAAE,OAAO,GAAI,KAAK,EAAE,KAAK,IAAI,QAAS,GAAG,KAAK,YAAY,KAAK,GAAG,CAAC,EAAE;AAAA,YAE5E,8BAAC,UAAK,WAAU,gDAA+C,OAAO,EAAE,OAAO,OAAO,GAAG,CAAC,EAAE,GAAI,YAAE,OAAM;AAAA;AAAA,UAJnG,EAAE;AAAA,QAKT,CACD;AAAA;AAAA,IACH;AAAA,IACC,cACC,oBAAC,QAAG,WAAU,uCACX,eAAK,IAAI,CAAC,GAAG,MACZ,qBAAC,QAAiB,WAAW,GAAG,wCAAwC,EAAE,SAAS,oBAAoB,yBAAyB,GAC9H;AAAA,0BAAC,UAAK,WAAU,iCAAgC,OAAO,EAAE,YAAY,KAAK,GAAG,CAAC,EAAE,GAAG,eAAY,QAAO;AAAA,MACrG,EAAE;AAAA,SAFI,EAAE,KAGX,CACD,GACH;AAAA,KAEJ;AAEJ;AACA,aAAa,cAAc;","names":[]}
|