@graftwork/ui 0.0.0-stage → 1.0.0
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/CHANGELOG.md +15 -0
- package/LICENSE +48 -0
- package/dist/components/bar-chart.d.ts +27 -0
- package/dist/components/bar-chart.js +45 -0
- package/dist/components/button.d.ts +16 -0
- package/dist/components/button.js +35 -0
- package/dist/components/card.d.ts +11 -0
- package/dist/components/card.js +26 -0
- package/dist/components/chart.d.ts +43 -0
- package/dist/components/chart.js +137 -0
- package/dist/components/field.d.ts +9 -0
- package/dist/components/field.js +25 -0
- package/dist/components/input.d.ts +14 -0
- package/dist/components/input.js +8 -0
- package/dist/components/select.d.ts +18 -0
- package/dist/components/select.js +12 -0
- package/dist/components/table.d.ts +20 -0
- package/dist/components/table.js +29 -0
- package/dist/components/theme-toggle.d.ts +21 -0
- package/dist/components/theme-toggle.js +66 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/lib/utils.d.ts +1 -0
- package/dist/lib/utils.js +1 -0
- package/dist/styles.css +108 -0
- package/package.json +74 -3
- package/README.md +0 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @graftwork/ui
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#3](https://github.com/graftwork-studio/design-system/pull/3) [`c403dbd`](https://github.com/graftwork-studio/design-system/commit/c403dbd160b5ff037a4754a3265a4651df00547b) Thanks [@david-kenny](https://github.com/david-kenny)! - First release of the Graftwork design system.
|
|
8
|
+
|
|
9
|
+
- `@graftwork/tokens`: design tokens in DTCG format for light, dark and high-contrast themes, built into CSS variables, a Tailwind v4 theme and JS constants. Every text and non-text colour pair is checked for contrast when the tokens build.
|
|
10
|
+
- `@graftwork/ui`: Button, Input, Select, Card, Table, BarChart and ThemeToggle, built on shadcn/ui with React Aria, plus the stylesheet apps import.
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [[`c403dbd`](https://github.com/graftwork-studio/design-system/commit/c403dbd160b5ff037a4754a3265a4651df00547b)]:
|
|
15
|
+
- @graftwork/tokens@1.0.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 graftwork-studio
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
-------------------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
Portions of this package are adapted from shadcn/ui
|
|
26
|
+
(https://github.com/shadcn-ui/ui), used under the following licence:
|
|
27
|
+
|
|
28
|
+
MIT License
|
|
29
|
+
|
|
30
|
+
Copyright (c) 2023 shadcn
|
|
31
|
+
|
|
32
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
33
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
34
|
+
in the Software without restriction, including without limitation the rights
|
|
35
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
36
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
37
|
+
furnished to do so, subject to the following conditions:
|
|
38
|
+
|
|
39
|
+
The above copyright notice and this permission notice shall be included in all
|
|
40
|
+
copies or substantial portions of the Software.
|
|
41
|
+
|
|
42
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
43
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
44
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
45
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
46
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
47
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
48
|
+
SOFTWARE.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export type BarChartSeries = {
|
|
3
|
+
/** Key in each data row. */
|
|
4
|
+
key: string;
|
|
5
|
+
/** Human-readable name, used in the legend and table header. */
|
|
6
|
+
label: string;
|
|
7
|
+
};
|
|
8
|
+
export type BarChartView = "chart" | "table";
|
|
9
|
+
export type BarChartProps = {
|
|
10
|
+
/** Chart heading. */
|
|
11
|
+
title: string;
|
|
12
|
+
/** One or two sentences saying what the chart shows. Required. */
|
|
13
|
+
summary: string;
|
|
14
|
+
data: ReadonlyArray<Record<string, string | number>>;
|
|
15
|
+
/** Key in each data row for the category axis. */
|
|
16
|
+
categoryKey: string;
|
|
17
|
+
/** Up to four series. */
|
|
18
|
+
series: readonly BarChartSeries[];
|
|
19
|
+
/** Formats values in labels, tooltips and the table. */
|
|
20
|
+
formatValue?: (value: number) => string;
|
|
21
|
+
/** Which view shows first. Defaults to chart. */
|
|
22
|
+
defaultView?: BarChartView;
|
|
23
|
+
/** Heading level for the title. Defaults to 2. */
|
|
24
|
+
headingLevel?: 2 | 3 | 4;
|
|
25
|
+
className?: string;
|
|
26
|
+
};
|
|
27
|
+
export declare function BarChart({ title, summary, data, categoryKey, series, formatValue, defaultView, headingLevel, className, }: BarChartProps): React.JSX.Element;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { ChartColumnIcon, TableIcon } from "lucide-react";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { Bar, BarChart as RechartsBarChart, CartesianGrid, LabelList, XAxis, YAxis } from "recharts";
|
|
6
|
+
import { cn } from "../lib/utils.js";
|
|
7
|
+
import { Button } from "./button.js";
|
|
8
|
+
import { ChartContainer, ChartTooltip, ChartTooltipContent } from "./chart.js";
|
|
9
|
+
import { Table, TableBody, TableCell, TableColumn, TableHeader, TableRow } from "./table.js";
|
|
10
|
+
const SERIES_COLOURS = [
|
|
11
|
+
"var(--gw-color-chart-series-1)",
|
|
12
|
+
"var(--gw-color-chart-series-2)",
|
|
13
|
+
"var(--gw-color-chart-series-3)",
|
|
14
|
+
"var(--gw-color-chart-series-4)",
|
|
15
|
+
];
|
|
16
|
+
/** One pattern per series: solid, diagonal stripes, dots, cross-hatch. */
|
|
17
|
+
function SeriesPattern({ id, index, colour }) {
|
|
18
|
+
const mark = "var(--gw-color-surface-raised)";
|
|
19
|
+
return (_jsxs("pattern", { id: id, width: "8", height: "8", patternUnits: "userSpaceOnUse", children: [_jsx("rect", { width: "8", height: "8", fill: colour }), index === 1 ? _jsx("path", { d: "M-2,2 l4,-4 M0,8 l8,-8 M6,10 l4,-4", stroke: mark, strokeWidth: "1.5" }) : null, index === 2 ? _jsx("circle", { cx: "4", cy: "4", r: "1.5", fill: mark }) : null, index === 3 ? _jsx("path", { d: "M0,4 h8 M4,0 v8", stroke: mark, strokeWidth: "1.5" }) : null] }));
|
|
20
|
+
}
|
|
21
|
+
function Swatch({ patternId }) {
|
|
22
|
+
return (_jsx("svg", { "aria-hidden": true, width: "16", height: "16", className: "shrink-0 rounded-sm", children: _jsx("rect", { width: "16", height: "16", fill: `url(#${patternId})` }) }));
|
|
23
|
+
}
|
|
24
|
+
export function BarChart({ title, summary, data, categoryKey, series, formatValue = (value) => value.toLocaleString(), defaultView = "chart", headingLevel = 2, className, }) {
|
|
25
|
+
const [view, setView] = React.useState(defaultView);
|
|
26
|
+
const uid = React.useId().replace(/:/g, "");
|
|
27
|
+
if (series.length > SERIES_COLOURS.length) {
|
|
28
|
+
throw new Error(`BarChart supports up to ${SERIES_COLOURS.length} series.`);
|
|
29
|
+
}
|
|
30
|
+
const Heading = `h${headingLevel}`;
|
|
31
|
+
const titleId = `${uid}-title`;
|
|
32
|
+
const summaryId = `${uid}-summary`;
|
|
33
|
+
const regionId = `${uid}-region`;
|
|
34
|
+
const patternId = (index) => `${uid}-pattern-${index}`;
|
|
35
|
+
const config = Object.fromEntries(series.map((s, i) => [s.key, { label: s.label, color: SERIES_COLOURS[i] }]));
|
|
36
|
+
return (_jsxs("figure", { "data-slot": "bar-chart", "data-view": view, "aria-labelledby": titleId, "aria-describedby": summaryId, className: cn("flex min-w-0 flex-col gap-3", className), children: [_jsxs("div", { className: "flex flex-wrap items-start justify-between gap-3", children: [_jsxs("div", { className: "flex min-w-0 flex-col gap-1", children: [_jsx(Heading, { id: titleId, className: "text-lg leading-heading font-semibold text-text-default", children: title }), _jsx("p", { id: summaryId, className: "max-w-[80ch] text-sm text-text-secondary", children: summary })] }), _jsxs(Button, { variant: "secondary", size: "sm", "aria-controls": regionId, onPress: () => setView(view === "chart" ? "table" : "chart"), children: [view === "chart" ? _jsx(TableIcon, { "aria-hidden": true }) : _jsx(ChartColumnIcon, { "aria-hidden": true }), view === "chart" ? "View as table" : "View as chart"] })] }), _jsx("svg", { "aria-hidden": true, width: "0", height: "0", className: "absolute", children: _jsx("defs", { children: series.map((s, i) => (_jsx(SeriesPattern, { id: patternId(i), index: i, colour: SERIES_COLOURS[i] ?? SERIES_COLOURS[0] }, s.key))) }) }), _jsx("div", { id: regionId, children: view === "chart" ? (_jsxs("div", { className: "flex flex-col gap-3", children: [_jsx("ul", { "aria-hidden": true, className: "flex flex-wrap gap-x-4 gap-y-1 text-sm text-text-default", children: series.map((s, i) => (_jsxs("li", { className: "flex items-center gap-1", children: [_jsx(Swatch, { patternId: patternId(i) }), s.label] }, s.key))) }), _jsx(ChartContainer, { config: config, "aria-hidden": true, className: "aspect-auto h-72 w-full min-w-0", children: _jsxs(RechartsBarChart, { data: [...data], accessibilityLayer: false, margin: { top: 24, right: 8, left: 8 }, children: [_jsx(CartesianGrid, { vertical: false }), _jsx(XAxis, { dataKey: categoryKey, tickLine: false, axisLine: false, tickMargin: 8 }), _jsx(YAxis, { tickLine: false, axisLine: false, width: 48, tickFormatter: (v) => formatValue(v) }), _jsx(ChartTooltip, { cursor: false, content: _jsx(ChartTooltipContent, {}) }), series.map((s, i) => (_jsx(Bar, { dataKey: s.key, name: s.label, fill: `url(#${patternId(i)})`, stroke: SERIES_COLOURS[i], radius: [4, 4, 0, 0], isAnimationActive: false, children: _jsx(LabelList, { dataKey: s.key, position: "top", className: "fill-text-secondary text-xs", formatter: (v) => (typeof v === "number" ? formatValue(v) : String(v ?? "")) }) }, s.key)))] }) })] })) : (_jsxs(Table, { "aria-labelledby": titleId, children: [_jsxs(TableHeader, { children: [_jsx(TableColumn, { isRowHeader: true, children: categoryKey === "" ? "Category" : labelFor(categoryKey) }), series.map((s) => (_jsx(TableColumn, { className: "text-right", children: s.label }, s.key)))] }), _jsx(TableBody, { children: data.map((row, rowIndex) => (_jsxs(TableRow, { children: [_jsx(TableCell, { children: String(row[categoryKey]) }), series.map((s) => {
|
|
37
|
+
const value = row[s.key];
|
|
38
|
+
return (_jsx(TableCell, { className: "text-right tabular-nums", children: typeof value === "number" ? formatValue(value) : String(value ?? "") }, s.key));
|
|
39
|
+
})] }, `${String(row[categoryKey])}-${rowIndex}`))) })] })) })] }));
|
|
40
|
+
}
|
|
41
|
+
/** "monthName" → "Month name" for the category column header. */
|
|
42
|
+
function labelFor(key) {
|
|
43
|
+
const words = key.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").toLowerCase();
|
|
44
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
45
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
import { type ButtonProps as ButtonPrimitiveProps } from "react-aria-components";
|
|
3
|
+
export declare const buttonVariants: (props?: ({
|
|
4
|
+
variant?: "primary" | "secondary" | "ghost" | "destructive" | null | undefined;
|
|
5
|
+
size?: "sm" | "md" | "lg" | null | undefined;
|
|
6
|
+
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
7
|
+
export type ButtonVariant = "primary" | "secondary" | "ghost" | "destructive";
|
|
8
|
+
export type ButtonSize = "sm" | "md" | "lg";
|
|
9
|
+
export type ButtonProps = Omit<ButtonPrimitiveProps, "className" | "style"> & React.RefAttributes<HTMLButtonElement> & {
|
|
10
|
+
/** Visual style. Defaults to primary. */
|
|
11
|
+
variant?: ButtonVariant;
|
|
12
|
+
/** Visual size. Every size keeps a hit area of at least 44 × 44px. Defaults to md. */
|
|
13
|
+
size?: ButtonSize;
|
|
14
|
+
className?: string;
|
|
15
|
+
};
|
|
16
|
+
export declare function Button({ className, variant, size, children, ...props }: ButtonProps): React.JSX.Element;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { cva } from "class-variance-authority";
|
|
4
|
+
import { Button as ButtonPrimitive, composeRenderProps, } from "react-aria-components";
|
|
5
|
+
import { cn } from "../lib/utils.js";
|
|
6
|
+
/*
|
|
7
|
+
* Adapted from shadcn/ui (aria-nova). Copyright (c) 2023 shadcn. MIT licence.
|
|
8
|
+
*
|
|
9
|
+
* Figma contract: Button { variant: primary | secondary | ghost | destructive; size: sm | md | lg }
|
|
10
|
+
*/
|
|
11
|
+
export const buttonVariants = cva([
|
|
12
|
+
"focus-ring hit-area inline-flex shrink-0 cursor-pointer items-center justify-center gap-2",
|
|
13
|
+
"rounded-md border border-transparent font-medium whitespace-nowrap select-none",
|
|
14
|
+
"transition-colors duration-(--gw-motion-duration-fast)",
|
|
15
|
+
"disabled:cursor-not-allowed disabled:opacity-50",
|
|
16
|
+
"[&_svg]:pointer-events-none [&_svg]:shrink-0",
|
|
17
|
+
], {
|
|
18
|
+
variants: {
|
|
19
|
+
variant: {
|
|
20
|
+
primary: "bg-action-primary-bg text-text-on-primary hover:bg-action-primary-bg-hover data-pressed:bg-action-primary-bg-hover",
|
|
21
|
+
secondary: "border-border-input bg-action-secondary-bg text-text-default hover:bg-action-secondary-bg-hover data-pressed:bg-action-secondary-bg-hover",
|
|
22
|
+
ghost: "bg-transparent text-text-default hover:bg-action-ghost-bg-hover data-pressed:bg-action-ghost-bg-hover",
|
|
23
|
+
destructive: "bg-action-destructive-bg text-text-on-destructive hover:bg-action-destructive-bg-hover data-pressed:bg-action-destructive-bg-hover",
|
|
24
|
+
},
|
|
25
|
+
size: {
|
|
26
|
+
sm: "h-8 px-3 text-sm [&_svg]:size-4",
|
|
27
|
+
md: "h-10 px-4 text-md [&_svg]:size-4",
|
|
28
|
+
lg: "h-11 px-6 text-lg [&_svg]:size-5",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
defaultVariants: { variant: "primary", size: "md" },
|
|
32
|
+
});
|
|
33
|
+
export function Button({ className, variant = "primary", size = "md", children, ...props }) {
|
|
34
|
+
return (_jsx(ButtonPrimitive, { "data-slot": "button", "data-variant": variant, "data-size": size, className: cn(buttonVariants({ variant, size }), className), ...props, children: composeRenderProps(children, (c) => c) }));
|
|
35
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
export declare function Card({ className, ...props }: React.ComponentProps<"div">): React.JSX.Element;
|
|
3
|
+
export declare function CardHeader({ className, ...props }: React.ComponentProps<"div">): React.JSX.Element;
|
|
4
|
+
export type CardTitleProps = React.ComponentProps<"h2"> & {
|
|
5
|
+
/** Heading level, so the card fits the page outline. Defaults to 2. */
|
|
6
|
+
level?: 2 | 3 | 4;
|
|
7
|
+
};
|
|
8
|
+
export declare function CardTitle({ className, level, ...props }: CardTitleProps): React.JSX.Element;
|
|
9
|
+
export declare function CardDescription({ className, ...props }: React.ComponentProps<"p">): React.JSX.Element;
|
|
10
|
+
export declare function CardContent({ className, ...props }: React.ComponentProps<"div">): React.JSX.Element;
|
|
11
|
+
export declare function CardFooter({ className, ...props }: React.ComponentProps<"div">): React.JSX.Element;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from "../lib/utils.js";
|
|
3
|
+
/*
|
|
4
|
+
* Adapted from shadcn/ui (aria-nova). Copyright (c) 2023 shadcn. MIT licence.
|
|
5
|
+
*
|
|
6
|
+
* Figma contract: Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter
|
|
7
|
+
*/
|
|
8
|
+
export function Card({ className, ...props }) {
|
|
9
|
+
return (_jsx("div", { "data-slot": "card", className: cn("flex flex-col gap-4 rounded-lg border border-border-default bg-surface-raised py-6 text-md text-text-default", className), ...props }));
|
|
10
|
+
}
|
|
11
|
+
export function CardHeader({ className, ...props }) {
|
|
12
|
+
return _jsx("div", { "data-slot": "card-header", className: cn("flex flex-col gap-1 px-6", className), ...props });
|
|
13
|
+
}
|
|
14
|
+
export function CardTitle({ className, level = 2, ...props }) {
|
|
15
|
+
const Heading = `h${level}`;
|
|
16
|
+
return (_jsx(Heading, { "data-slot": "card-title", className: cn("text-xl leading-heading font-semibold text-text-default", className), ...props }));
|
|
17
|
+
}
|
|
18
|
+
export function CardDescription({ className, ...props }) {
|
|
19
|
+
return _jsx("p", { "data-slot": "card-description", className: cn("text-sm text-text-secondary", className), ...props });
|
|
20
|
+
}
|
|
21
|
+
export function CardContent({ className, ...props }) {
|
|
22
|
+
return _jsx("div", { "data-slot": "card-content", className: cn("px-6", className), ...props });
|
|
23
|
+
}
|
|
24
|
+
export function CardFooter({ className, ...props }) {
|
|
25
|
+
return (_jsx("div", { "data-slot": "card-footer", className: cn("flex flex-wrap items-center gap-2 px-6", className), ...props }));
|
|
26
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import * as RechartsPrimitive from "recharts";
|
|
3
|
+
import type { TooltipValueType } from "recharts";
|
|
4
|
+
declare const THEMES: {
|
|
5
|
+
readonly light: "";
|
|
6
|
+
};
|
|
7
|
+
type TooltipNameType = number | string;
|
|
8
|
+
type ChartConfig = Record<string, {
|
|
9
|
+
label?: React.ReactNode;
|
|
10
|
+
icon?: React.ComponentType;
|
|
11
|
+
} & ({
|
|
12
|
+
color?: string;
|
|
13
|
+
theme?: never;
|
|
14
|
+
} | {
|
|
15
|
+
color?: never;
|
|
16
|
+
theme: Record<keyof typeof THEMES, string>;
|
|
17
|
+
})>;
|
|
18
|
+
declare function ChartContainer({ id, className, children, config, initialDimension, ...props }: React.ComponentProps<"div"> & {
|
|
19
|
+
config: ChartConfig;
|
|
20
|
+
children: React.ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>["children"];
|
|
21
|
+
initialDimension?: {
|
|
22
|
+
width: number;
|
|
23
|
+
height: number;
|
|
24
|
+
};
|
|
25
|
+
}): React.JSX.Element;
|
|
26
|
+
declare const ChartStyle: ({ id, config }: {
|
|
27
|
+
id: string;
|
|
28
|
+
config: ChartConfig;
|
|
29
|
+
}) => React.JSX.Element | null;
|
|
30
|
+
declare const ChartTooltip: typeof RechartsPrimitive.Tooltip;
|
|
31
|
+
declare function ChartTooltipContent({ active, payload, className, indicator, hideLabel, hideIndicator, label, labelFormatter, labelClassName, formatter, color, nameKey, labelKey, }: React.ComponentProps<typeof RechartsPrimitive.Tooltip> & React.ComponentProps<"div"> & {
|
|
32
|
+
hideLabel?: boolean;
|
|
33
|
+
hideIndicator?: boolean;
|
|
34
|
+
indicator?: "line" | "dot" | "dashed";
|
|
35
|
+
nameKey?: string;
|
|
36
|
+
labelKey?: string;
|
|
37
|
+
} & Omit<RechartsPrimitive.DefaultTooltipContentProps<TooltipValueType, TooltipNameType>, "accessibilityLayer">): React.JSX.Element | null;
|
|
38
|
+
declare const ChartLegend: React.MemoExoticComponent<(outsideProps: RechartsPrimitive.LegendProps) => React.ReactPortal | null>;
|
|
39
|
+
declare function ChartLegendContent({ className, hideIcon, payload, verticalAlign, nameKey, }: React.ComponentProps<"div"> & {
|
|
40
|
+
hideIcon?: boolean;
|
|
41
|
+
nameKey?: string;
|
|
42
|
+
} & RechartsPrimitive.DefaultLegendContentProps): React.JSX.Element | null;
|
|
43
|
+
export { type ChartConfig, ChartContainer, ChartTooltip, ChartTooltipContent, ChartLegend, ChartLegendContent, ChartStyle, };
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
/*
|
|
4
|
+
* shadcn/ui chart primitives (aria-nova), restyled with Graftwork tokens.
|
|
5
|
+
* Copyright (c) 2023 shadcn. MIT licence.
|
|
6
|
+
*/
|
|
7
|
+
import * as React from "react";
|
|
8
|
+
import { cn } from "../lib/utils.js";
|
|
9
|
+
import * as RechartsPrimitive from "recharts";
|
|
10
|
+
// Format: { THEME_NAME: CSS_SELECTOR }
|
|
11
|
+
// Graftwork colours are CSS variables that already switch with the theme.
|
|
12
|
+
const THEMES = { light: "" };
|
|
13
|
+
const INITIAL_DIMENSION = { width: 320, height: 200 };
|
|
14
|
+
const ChartContext = React.createContext(null);
|
|
15
|
+
function useChart() {
|
|
16
|
+
const context = React.useContext(ChartContext);
|
|
17
|
+
if (!context) {
|
|
18
|
+
throw new Error("useChart must be used within a <ChartContainer />");
|
|
19
|
+
}
|
|
20
|
+
return context;
|
|
21
|
+
}
|
|
22
|
+
function ChartContainer({ id, className, children, config, initialDimension = INITIAL_DIMENSION, ...props }) {
|
|
23
|
+
const uniqueId = React.useId();
|
|
24
|
+
const chartId = `chart-${id ?? uniqueId.replace(/:/g, "")}`;
|
|
25
|
+
return (_jsx(ChartContext.Provider, { value: { config }, children: _jsxs("div", { "data-slot": "chart", "data-chart": chartId, className: cn("flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-text-secondary [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-chart-grid [&_.recharts-curve.recharts-tooltip-cursor]:stroke-chart-grid [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-chart-grid [&_.recharts-radial-bar-background-sector]:fill-surface-subtle [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-surface-subtle [&_.recharts-reference-line_[stroke='#ccc']]:stroke-chart-grid [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden", className), ...props, children: [_jsx(ChartStyle, { id: chartId, config: config }), _jsx(RechartsPrimitive.ResponsiveContainer, { initialDimension: initialDimension, children: children })] }) }));
|
|
26
|
+
}
|
|
27
|
+
const ChartStyle = ({ id, config }) => {
|
|
28
|
+
const colorConfig = Object.entries(config).filter(([, config]) => config.theme ?? config.color);
|
|
29
|
+
if (!colorConfig.length) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return (_jsx("style", { dangerouslySetInnerHTML: {
|
|
33
|
+
__html: Object.entries(THEMES)
|
|
34
|
+
.map(([theme, prefix]) => `
|
|
35
|
+
${prefix} [data-chart=${id}] {
|
|
36
|
+
${colorConfig
|
|
37
|
+
.map(([key, itemConfig]) => {
|
|
38
|
+
const color = itemConfig.theme?.[theme] ??
|
|
39
|
+
itemConfig.color;
|
|
40
|
+
return color ? ` --color-${key}: ${color};` : null;
|
|
41
|
+
})
|
|
42
|
+
.join("\n")}
|
|
43
|
+
}
|
|
44
|
+
`)
|
|
45
|
+
.join("\n"),
|
|
46
|
+
} }));
|
|
47
|
+
};
|
|
48
|
+
const ChartTooltip = RechartsPrimitive.Tooltip;
|
|
49
|
+
function ChartTooltipContent({ active, payload, className, indicator = "dot", hideLabel = false, hideIndicator = false, label, labelFormatter, labelClassName, formatter, color, nameKey, labelKey, }) {
|
|
50
|
+
const { config } = useChart();
|
|
51
|
+
const tooltipLabel = React.useMemo(() => {
|
|
52
|
+
if (hideLabel || !payload?.length) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const [item] = payload;
|
|
56
|
+
const key = `${labelKey ?? item?.dataKey ?? item?.name ?? "value"}`;
|
|
57
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
58
|
+
const value = !labelKey && typeof label === "string"
|
|
59
|
+
? (config[label]?.label ?? label)
|
|
60
|
+
: itemConfig?.label;
|
|
61
|
+
if (labelFormatter) {
|
|
62
|
+
return (_jsx("div", { className: cn("font-medium", labelClassName), children: labelFormatter(value, payload) }));
|
|
63
|
+
}
|
|
64
|
+
if (!value) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
return _jsx("div", { className: cn("font-medium", labelClassName), children: value });
|
|
68
|
+
}, [
|
|
69
|
+
label,
|
|
70
|
+
labelFormatter,
|
|
71
|
+
payload,
|
|
72
|
+
hideLabel,
|
|
73
|
+
labelClassName,
|
|
74
|
+
config,
|
|
75
|
+
labelKey,
|
|
76
|
+
]);
|
|
77
|
+
if (!active || !payload?.length) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
const nestLabel = payload.length === 1 && indicator !== "dot";
|
|
81
|
+
return (_jsxs("div", { className: cn("grid min-w-32 items-start gap-1.5 rounded-lg border border-border-default bg-surface-overlay px-2.5 py-1.5 text-xs shadow-xl", className), children: [!nestLabel ? tooltipLabel : null, _jsx("div", { className: "grid gap-1.5", children: payload
|
|
82
|
+
.filter((item) => item.type !== "none")
|
|
83
|
+
.map((item, index) => {
|
|
84
|
+
const key = `${nameKey ?? item.name ?? item.dataKey ?? "value"}`;
|
|
85
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
86
|
+
const indicatorColor = color ?? item.payload?.fill ?? item.color;
|
|
87
|
+
return (_jsx("div", { className: cn("flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-text-secondary", indicator === "dot" && "items-center"), children: formatter && item?.value !== undefined && item.name ? (formatter(item.value, item.name, item, index, item.payload)) : (_jsxs(_Fragment, { children: [itemConfig?.icon ? (_jsx(itemConfig.icon, {})) : (!hideIndicator && (_jsx("div", { className: cn("shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)", {
|
|
88
|
+
"h-2.5 w-2.5": indicator === "dot",
|
|
89
|
+
"w-1": indicator === "line",
|
|
90
|
+
"w-0 border-[1.5px] border-dashed bg-transparent": indicator === "dashed",
|
|
91
|
+
"my-0.5": nestLabel && indicator === "dashed",
|
|
92
|
+
}), style: {
|
|
93
|
+
"--color-bg": indicatorColor,
|
|
94
|
+
"--color-border": indicatorColor,
|
|
95
|
+
} }))), _jsxs("div", { className: cn("flex flex-1 justify-between leading-none", nestLabel ? "items-end" : "items-center"), children: [_jsxs("div", { className: "grid gap-1.5", children: [nestLabel ? tooltipLabel : null, _jsx("span", { className: "text-text-secondary", children: itemConfig?.label ?? item.name })] }), item.value != null && (_jsx("span", { className: "font-mono font-medium text-text-default tabular-nums", children: typeof item.value === "number"
|
|
96
|
+
? item.value.toLocaleString()
|
|
97
|
+
: String(item.value) }))] })] })) }, index));
|
|
98
|
+
}) })] }));
|
|
99
|
+
}
|
|
100
|
+
const ChartLegend = RechartsPrimitive.Legend;
|
|
101
|
+
function ChartLegendContent({ className, hideIcon = false, payload, verticalAlign = "bottom", nameKey, }) {
|
|
102
|
+
const { config } = useChart();
|
|
103
|
+
if (!payload?.length) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
return (_jsx("div", { className: cn("flex items-center justify-center gap-4", verticalAlign === "top" ? "pb-3" : "pt-3", className), children: payload
|
|
107
|
+
.filter((item) => item.type !== "none")
|
|
108
|
+
.map((item, index) => {
|
|
109
|
+
const key = `${nameKey ?? item.dataKey ?? "value"}`;
|
|
110
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
111
|
+
return (_jsxs("div", { className: cn("flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-text-secondary"), children: [itemConfig?.icon && !hideIcon ? (_jsx(itemConfig.icon, {})) : (_jsx("div", { className: "h-2 w-2 shrink-0 rounded-[2px]", style: {
|
|
112
|
+
backgroundColor: item.color,
|
|
113
|
+
} })), itemConfig?.label] }, index));
|
|
114
|
+
}) }));
|
|
115
|
+
}
|
|
116
|
+
function getPayloadConfigFromPayload(config, payload, key) {
|
|
117
|
+
if (typeof payload !== "object" || payload === null) {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
const payloadPayload = "payload" in payload &&
|
|
121
|
+
typeof payload.payload === "object" &&
|
|
122
|
+
payload.payload !== null
|
|
123
|
+
? payload.payload
|
|
124
|
+
: undefined;
|
|
125
|
+
let configLabelKey = key;
|
|
126
|
+
if (key in payload &&
|
|
127
|
+
typeof payload[key] === "string") {
|
|
128
|
+
configLabelKey = payload[key];
|
|
129
|
+
}
|
|
130
|
+
else if (payloadPayload &&
|
|
131
|
+
key in payloadPayload &&
|
|
132
|
+
typeof payloadPayload[key] === "string") {
|
|
133
|
+
configLabelKey = payloadPayload[key];
|
|
134
|
+
}
|
|
135
|
+
return configLabelKey in config ? config[configLabelKey] : config[key];
|
|
136
|
+
}
|
|
137
|
+
export { ChartContainer, ChartTooltip, ChartTooltipContent, ChartLegend, ChartLegendContent, ChartStyle, };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
import { Label as LabelPrimitive, Text } from "react-aria-components";
|
|
3
|
+
export declare function FieldLabel({ className, ...props }: React.ComponentProps<typeof LabelPrimitive>): React.JSX.Element;
|
|
4
|
+
export declare function FieldDescription({ className, ...props }: Omit<React.ComponentProps<typeof Text>, "slot">): React.JSX.Element;
|
|
5
|
+
export declare function FieldErrorText({ children, className }: {
|
|
6
|
+
children?: React.ReactNode;
|
|
7
|
+
className?: string;
|
|
8
|
+
}): React.JSX.Element;
|
|
9
|
+
export declare const fieldControl: string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { CircleAlertIcon } from "lucide-react";
|
|
4
|
+
import { FieldError as FieldErrorPrimitive, Label as LabelPrimitive, Text } from "react-aria-components";
|
|
5
|
+
import { cn } from "../lib/utils.js";
|
|
6
|
+
/*
|
|
7
|
+
* Shared parts for form fields. Labels are always visible. Errors are shown as
|
|
8
|
+
* text, with an icon so colour is never the only cue, and React Aria links both
|
|
9
|
+
* the description and the error to the field with aria-describedby.
|
|
10
|
+
*/
|
|
11
|
+
export function FieldLabel({ className, ...props }) {
|
|
12
|
+
return (_jsx(LabelPrimitive, { "data-slot": "field-label", className: cn("text-sm font-medium text-text-default", className), ...props }));
|
|
13
|
+
}
|
|
14
|
+
export function FieldDescription({ className, ...props }) {
|
|
15
|
+
return (_jsx(Text, { slot: "description", "data-slot": "field-description", className: cn("text-sm text-text-secondary", className), ...props }));
|
|
16
|
+
}
|
|
17
|
+
export function FieldErrorText({ children, className }) {
|
|
18
|
+
return (_jsx(FieldErrorPrimitive, { "data-slot": "field-error", className: cn("flex items-start gap-1 text-sm text-text-error", className), children: (validation) => (_jsxs(_Fragment, { children: [_jsx(CircleAlertIcon, { "aria-hidden": true, className: "mt-0.5 size-4 shrink-0" }), _jsx("span", { children: children ?? validation.validationErrors.join(" ") })] })) }));
|
|
19
|
+
}
|
|
20
|
+
export const fieldControl = [
|
|
21
|
+
"w-full min-w-0 rounded-md border border-border-input bg-surface-default px-3 text-md text-text-default",
|
|
22
|
+
"min-h-target-min transition-colors duration-(--gw-motion-duration-fast)",
|
|
23
|
+
"data-invalid:border-2 data-invalid:border-border-input-invalid",
|
|
24
|
+
"data-disabled:cursor-not-allowed data-disabled:opacity-50",
|
|
25
|
+
].join(" ");
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
import { type TextFieldProps } from "react-aria-components";
|
|
3
|
+
export type InputProps = Omit<TextFieldProps, "className" | "style" | "children"> & {
|
|
4
|
+
/** Visible label. Required: placeholders never replace labels. */
|
|
5
|
+
label: string;
|
|
6
|
+
/** Help text under the label, linked to the input. */
|
|
7
|
+
description?: string;
|
|
8
|
+
/** Shown as text under the input when isInvalid is true, and linked to it. */
|
|
9
|
+
errorMessage?: string;
|
|
10
|
+
placeholder?: string;
|
|
11
|
+
className?: string;
|
|
12
|
+
inputRef?: React.Ref<HTMLInputElement>;
|
|
13
|
+
};
|
|
14
|
+
export declare function Input({ label, description, errorMessage, placeholder, className, inputRef, ...props }: InputProps): React.JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Input as InputPrimitive, TextField, } from "react-aria-components";
|
|
4
|
+
import { cn } from "../lib/utils.js";
|
|
5
|
+
import { FieldDescription, FieldErrorText, FieldLabel, fieldControl } from "./field.js";
|
|
6
|
+
export function Input({ label, description, errorMessage, placeholder, className, inputRef, ...props }) {
|
|
7
|
+
return (_jsxs(TextField, { "data-slot": "input-field", className: cn("flex flex-col gap-1", className), ...props, children: [_jsxs(FieldLabel, { children: [label, props.isRequired ? _jsx("span", { className: "text-text-secondary", children: " (required)" }) : null] }), description ? _jsx(FieldDescription, { children: description }) : null, _jsx(InputPrimitive, { ref: inputRef, "data-slot": "input", placeholder: placeholder, className: cn(fieldControl, "focus-ring placeholder:text-text-placeholder") }), _jsx(FieldErrorText, { children: errorMessage })] }));
|
|
8
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
import { type ListBoxItemProps, type SelectProps as SelectPrimitiveProps } from "react-aria-components";
|
|
3
|
+
export type SelectProps<T extends object> = Omit<SelectPrimitiveProps<T, "single">, "className" | "style" | "children" | "selectionMode"> & {
|
|
4
|
+
/** Visible label. Required. */
|
|
5
|
+
label: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
errorMessage?: string;
|
|
8
|
+
placeholder?: string;
|
|
9
|
+
className?: string;
|
|
10
|
+
/** SelectItem elements, or a render function when `items` is given. */
|
|
11
|
+
children: React.ReactNode | ((item: T) => React.ReactNode);
|
|
12
|
+
items?: Iterable<T>;
|
|
13
|
+
};
|
|
14
|
+
export declare function Select<T extends object>({ label, description, errorMessage, placeholder, className, children, items, ...props }: SelectProps<T>): React.JSX.Element;
|
|
15
|
+
export type SelectItemProps = Omit<ListBoxItemProps, "className" | "style"> & {
|
|
16
|
+
className?: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function SelectItem({ className, children, ...props }: SelectItemProps): React.JSX.Element;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { CheckIcon, ChevronDownIcon } from "lucide-react";
|
|
4
|
+
import { Button as ButtonPrimitive, composeRenderProps, ListBox, ListBoxItem, Popover, Select as SelectPrimitive, SelectValue, } from "react-aria-components";
|
|
5
|
+
import { cn } from "../lib/utils.js";
|
|
6
|
+
import { FieldDescription, FieldErrorText, FieldLabel, fieldControl } from "./field.js";
|
|
7
|
+
export function Select({ label, description, errorMessage, placeholder = "Choose an option", className, children, items, ...props }) {
|
|
8
|
+
return (_jsxs(SelectPrimitive, { "data-slot": "select", placeholder: placeholder, className: cn("group/select flex flex-col gap-1", className), ...props, children: [_jsxs(FieldLabel, { children: [label, props.isRequired ? _jsx("span", { className: "text-text-secondary", children: " (required)" }) : null] }), description ? _jsx(FieldDescription, { children: description }) : null, _jsxs(ButtonPrimitive, { "data-slot": "select-trigger", className: cn(fieldControl, "focus-ring flex cursor-pointer items-center justify-between gap-2 text-left", "hover:bg-action-secondary-bg-hover", "group-data-invalid/select:border-2 group-data-invalid/select:border-border-input-invalid"), children: [_jsx(SelectValue, { className: "truncate data-placeholder:text-text-placeholder" }), _jsx(ChevronDownIcon, { "aria-hidden": true, className: "size-4 shrink-0 text-icon-default" })] }), _jsx(FieldErrorText, { children: errorMessage }), _jsx(Popover, { "data-slot": "select-popover", offset: 4, className: cn("w-(--trigger-width) min-w-40 overflow-auto rounded-md border border-border-default bg-surface-overlay shadow-md", "transition-opacity duration-(--gw-motion-duration-fade) data-entering:opacity-0 data-exiting:opacity-0"), children: _jsx(ListBox, { "data-slot": "select-list", items: items, className: "max-h-72 p-1 outline-none data-focus-visible:outline-2 data-focus-visible:outline-solid data-focus-visible:-outline-offset-2 data-focus-visible:outline-focus-ring", children: children }) })] }));
|
|
9
|
+
}
|
|
10
|
+
export function SelectItem({ className, children, ...props }) {
|
|
11
|
+
return (_jsx(ListBoxItem, { "data-slot": "select-item", textValue: typeof children === "string" ? children : props.textValue, className: cn("flex min-h-target-min cursor-pointer items-center justify-between gap-2 rounded-sm px-3 text-md text-text-default outline-none", "data-focused:bg-action-ghost-bg-hover data-focus-visible:outline-2 data-focus-visible:outline-solid data-focus-visible:-outline-offset-2 data-focus-visible:outline-focus-ring", "data-disabled:cursor-not-allowed data-disabled:opacity-50", className), ...props, children: composeRenderProps(children, (content, { isSelected }) => (_jsxs(_Fragment, { children: [_jsx("span", { className: "truncate", children: content }), isSelected ? _jsx(CheckIcon, { "aria-hidden": true, className: "size-4 shrink-0 text-icon-brand" }) : null] }))) }));
|
|
12
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type CellProps, type ColumnProps, type RowProps, type TableBodyProps, type TableHeaderProps, type TableProps as TablePrimitiveProps } from "react-aria-components";
|
|
3
|
+
export type TableDensity = "comfortable" | "compact";
|
|
4
|
+
export type TableProps = Omit<TablePrimitiveProps, "className" | "style"> & {
|
|
5
|
+
/** Row spacing. Compact rows are for dense data grids. Defaults to comfortable. */
|
|
6
|
+
density?: TableDensity;
|
|
7
|
+
className?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function Table({ className, density, ...props }: TableProps): React.JSX.Element;
|
|
10
|
+
export declare function TableHeader<T extends object>({ className, ...props }: TableHeaderProps<T>): React.JSX.Element;
|
|
11
|
+
export declare function TableColumn({ className, ...props }: Omit<ColumnProps, "className"> & {
|
|
12
|
+
className?: string;
|
|
13
|
+
}): React.JSX.Element;
|
|
14
|
+
export declare function TableBody<T extends object>({ className, ...props }: TableBodyProps<T>): React.JSX.Element;
|
|
15
|
+
export declare function TableRow<T extends object>({ className, ...props }: Omit<RowProps<T>, "className"> & {
|
|
16
|
+
className?: string;
|
|
17
|
+
}): React.JSX.Element;
|
|
18
|
+
export declare function TableCell({ className, ...props }: Omit<CellProps, "className"> & {
|
|
19
|
+
className?: string;
|
|
20
|
+
}): React.JSX.Element;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Cell as CellPrimitive, Column as ColumnPrimitive, Row as RowPrimitive, Table as TablePrimitive, TableBody as TableBodyPrimitive, TableHeader as TableHeaderPrimitive, } from "react-aria-components";
|
|
5
|
+
import { cn } from "../lib/utils.js";
|
|
6
|
+
const DensityContext = React.createContext("comfortable");
|
|
7
|
+
export function Table({ className, density = "comfortable", ...props }) {
|
|
8
|
+
return (_jsx(DensityContext.Provider, { value: density, children: _jsx("div", { "data-slot": "table-container", className: "w-full overflow-x-auto rounded-md border border-border-default", children: _jsx(TablePrimitive, { "data-slot": "table", "data-density": density, className: cn("w-full border-collapse text-left text-md text-text-default", className), ...props }) }) }));
|
|
9
|
+
}
|
|
10
|
+
export function TableHeader({ className, ...props }) {
|
|
11
|
+
return (_jsx(TableHeaderPrimitive, { "data-slot": "table-header", className: cn("border-b border-border-default bg-surface-subtle", className), ...props }));
|
|
12
|
+
}
|
|
13
|
+
function cellPadding(density) {
|
|
14
|
+
return density === "compact" ? "px-2 py-1 text-sm" : "px-3 py-3";
|
|
15
|
+
}
|
|
16
|
+
export function TableColumn({ className, ...props }) {
|
|
17
|
+
const density = React.useContext(DensityContext);
|
|
18
|
+
return (_jsx(ColumnPrimitive, { "data-slot": "table-column", className: cn("text-sm font-semibold outline-none whitespace-nowrap text-text-default", "data-focus-visible:outline-2 data-focus-visible:outline-solid data-focus-visible:-outline-offset-2 data-focus-visible:outline-focus-ring", cellPadding(density), className), ...props }));
|
|
19
|
+
}
|
|
20
|
+
export function TableBody({ className, ...props }) {
|
|
21
|
+
return _jsx(TableBodyPrimitive, { "data-slot": "table-body", className: cn(className), ...props });
|
|
22
|
+
}
|
|
23
|
+
export function TableRow({ className, ...props }) {
|
|
24
|
+
return (_jsx(RowPrimitive, { "data-slot": "table-row", className: cn("border-b border-border-default last:border-b-0 hover:bg-surface-subtle", "outline-none data-focus-visible:outline-2 data-focus-visible:outline-solid data-focus-visible:-outline-offset-2 data-focus-visible:outline-focus-ring", className), ...props }));
|
|
25
|
+
}
|
|
26
|
+
export function TableCell({ className, ...props }) {
|
|
27
|
+
const density = React.useContext(DensityContext);
|
|
28
|
+
return (_jsx(CellPrimitive, { "data-slot": "table-cell", className: cn("align-middle outline-none", "data-focus-visible:outline-2 data-focus-visible:outline-solid data-focus-visible:-outline-offset-2 data-focus-visible:outline-focus-ring", cellPadding(density), className), ...props }));
|
|
29
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export type ThemeChoice = "system" | "light" | "dark" | "high-contrast";
|
|
3
|
+
export declare const THEME_STORAGE_KEY = "graftwork-theme";
|
|
4
|
+
/** Applies a theme choice to the document. */
|
|
5
|
+
export declare function applyTheme(choice: ThemeChoice, root?: HTMLElement): void;
|
|
6
|
+
/**
|
|
7
|
+
* An inline script for the document head that applies the stored theme before
|
|
8
|
+
* first paint, so the page never flashes the wrong theme.
|
|
9
|
+
*/
|
|
10
|
+
export declare const themeScript: string;
|
|
11
|
+
export type ThemeToggleProps = {
|
|
12
|
+
/** Controlled value. */
|
|
13
|
+
value?: ThemeChoice;
|
|
14
|
+
/** Uncontrolled starting value. Defaults to the stored choice, or system. */
|
|
15
|
+
defaultValue?: ThemeChoice;
|
|
16
|
+
onChange?: (value: ThemeChoice) => void;
|
|
17
|
+
/** Visible label. Defaults to "Theme". */
|
|
18
|
+
label?: string;
|
|
19
|
+
className?: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function ThemeToggle({ value, defaultValue, onChange, label, className }: ThemeToggleProps): React.JSX.Element;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { ContrastIcon, MonitorIcon, MoonIcon, SunIcon } from "lucide-react";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { Label, Radio, RadioGroup } from "react-aria-components";
|
|
6
|
+
import { cn } from "../lib/utils.js";
|
|
7
|
+
export const THEME_STORAGE_KEY = "graftwork-theme";
|
|
8
|
+
const OPTIONS = [
|
|
9
|
+
{ value: "system", label: "System", Icon: MonitorIcon },
|
|
10
|
+
{ value: "light", label: "Light", Icon: SunIcon },
|
|
11
|
+
{ value: "dark", label: "Dark", Icon: MoonIcon },
|
|
12
|
+
{ value: "high-contrast", label: "High contrast", Icon: ContrastIcon },
|
|
13
|
+
];
|
|
14
|
+
function isThemeChoice(value) {
|
|
15
|
+
return OPTIONS.some((o) => o.value === value);
|
|
16
|
+
}
|
|
17
|
+
/** Applies a theme choice to the document. */
|
|
18
|
+
export function applyTheme(choice, root = document.documentElement) {
|
|
19
|
+
if (choice === "system")
|
|
20
|
+
root.removeAttribute("data-theme");
|
|
21
|
+
else
|
|
22
|
+
root.setAttribute("data-theme", choice);
|
|
23
|
+
}
|
|
24
|
+
function readStored() {
|
|
25
|
+
try {
|
|
26
|
+
const stored = window.localStorage.getItem(THEME_STORAGE_KEY);
|
|
27
|
+
return isThemeChoice(stored) ? stored : "system";
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return "system";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* An inline script for the document head that applies the stored theme before
|
|
35
|
+
* first paint, so the page never flashes the wrong theme.
|
|
36
|
+
*/
|
|
37
|
+
export const themeScript = `(function(){try{var t=localStorage.getItem(${JSON.stringify(THEME_STORAGE_KEY)});if(t==="light"||t==="dark"||t==="high-contrast")document.documentElement.setAttribute("data-theme",t)}catch(e){}})();`;
|
|
38
|
+
/** Keeps every ThemeToggle on the page, and other tabs, in step with the stored choice. */
|
|
39
|
+
function subscribe(onChange) {
|
|
40
|
+
window.addEventListener("storage", onChange);
|
|
41
|
+
return () => window.removeEventListener("storage", onChange);
|
|
42
|
+
}
|
|
43
|
+
export function ThemeToggle({ value, defaultValue, onChange, label = "Theme", className }) {
|
|
44
|
+
// The server renders "system"; the browser then reads the stored choice without a mismatch.
|
|
45
|
+
const stored = React.useSyncExternalStore(subscribe, readStored, () => "system");
|
|
46
|
+
const [chosen, setChosen] = React.useState(undefined);
|
|
47
|
+
const current = value ?? chosen ?? defaultValue ?? stored;
|
|
48
|
+
const choose = (next) => {
|
|
49
|
+
if (!isThemeChoice(next))
|
|
50
|
+
return;
|
|
51
|
+
if (value === undefined)
|
|
52
|
+
setChosen(next);
|
|
53
|
+
applyTheme(next);
|
|
54
|
+
try {
|
|
55
|
+
if (next === "system")
|
|
56
|
+
window.localStorage.removeItem(THEME_STORAGE_KEY);
|
|
57
|
+
else
|
|
58
|
+
window.localStorage.setItem(THEME_STORAGE_KEY, next);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
// Storage can be unavailable (private browsing). The choice still applies for this page.
|
|
62
|
+
}
|
|
63
|
+
onChange?.(next);
|
|
64
|
+
};
|
|
65
|
+
return (_jsxs(RadioGroup, { "data-slot": "theme-toggle", value: current, onChange: choose, orientation: "horizontal", className: cn("flex flex-col gap-1", className), children: [_jsx(Label, { className: "text-sm font-medium text-text-default", children: label }), _jsx("div", { className: "flex flex-wrap gap-1 rounded-md border border-border-input bg-surface-default p-1", children: OPTIONS.map(({ value: optionValue, label: optionLabel, Icon }) => (_jsxs(Radio, { value: optionValue, className: cn("flex min-h-target-min cursor-pointer items-center gap-1 rounded-sm px-3 text-sm text-text-default", "transition-colors duration-(--gw-motion-duration-fast) hover:bg-action-ghost-bg-hover", "data-selected:bg-action-primary-bg data-selected:text-text-on-primary", "data-focus-visible:outline-2 data-focus-visible:outline-solid data-focus-visible:outline-offset-2 data-focus-visible:outline-focus-ring"), children: [_jsx(Icon, { "aria-hidden": true, className: "size-4 shrink-0" }), optionLabel] }, optionValue))) })] }));
|
|
66
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { BarChart, type BarChartProps, type BarChartSeries, type BarChartView } from "./components/bar-chart.js";
|
|
2
|
+
export { Button, type ButtonProps, type ButtonSize, type ButtonVariant, buttonVariants } from "./components/button.js";
|
|
3
|
+
export { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, type CardTitleProps, } from "./components/card.js";
|
|
4
|
+
export { Input, type InputProps } from "./components/input.js";
|
|
5
|
+
export { Select, SelectItem, type SelectItemProps, type SelectProps } from "./components/select.js";
|
|
6
|
+
export { Table, TableBody, TableCell, TableColumn, type TableDensity, TableHeader, type TableProps, TableRow, } from "./components/table.js";
|
|
7
|
+
export { applyTheme, THEME_STORAGE_KEY, type ThemeChoice, ThemeToggle, type ThemeToggleProps, themeScript, } from "./components/theme-toggle.js";
|
|
8
|
+
export { cn } from "./lib/utils.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { BarChart } from "./components/bar-chart.js";
|
|
2
|
+
export { Button, buttonVariants } from "./components/button.js";
|
|
3
|
+
export { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "./components/card.js";
|
|
4
|
+
export { Input } from "./components/input.js";
|
|
5
|
+
export { Select, SelectItem } from "./components/select.js";
|
|
6
|
+
export { Table, TableBody, TableCell, TableColumn, TableHeader, TableRow, } from "./components/table.js";
|
|
7
|
+
export { applyTheme, THEME_STORAGE_KEY, ThemeToggle, themeScript, } from "./components/theme-toggle.js";
|
|
8
|
+
export { cn } from "./lib/utils.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { cn } from "cn";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { cn } from "cn";
|
package/dist/styles.css
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @graftwork/ui stylesheet. Apps import it after Tailwind:
|
|
3
|
+
*
|
|
4
|
+
* @import "tailwindcss";
|
|
5
|
+
* @import "@graftwork/ui/styles.css";
|
|
6
|
+
* @source "../node_modules/@graftwork/ui/dist";
|
|
7
|
+
*/
|
|
8
|
+
@import "@fontsource-variable/noto-sans";
|
|
9
|
+
@import "@graftwork/tokens/css";
|
|
10
|
+
@import "@graftwork/tokens/tailwind.css";
|
|
11
|
+
|
|
12
|
+
/* WCAG 2.4.13: 2px ring, 2px offset, on :focus-visible. */
|
|
13
|
+
@utility focus-ring {
|
|
14
|
+
&:focus-visible {
|
|
15
|
+
outline: var(--gw-focus-ring-width) solid var(--gw-color-focus-ring);
|
|
16
|
+
outline-offset: var(--gw-focus-ring-offset);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/* The same ring, for a wrapper whose child receives keyboard focus. */
|
|
21
|
+
@utility focus-ring-within {
|
|
22
|
+
&:has(:focus-visible) {
|
|
23
|
+
outline: var(--gw-focus-ring-width) solid var(--gw-color-focus-ring);
|
|
24
|
+
outline-offset: var(--gw-focus-ring-offset);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* WCAG 2.5.5: extends the hit area to at least 44 × 44px without changing the look. */
|
|
29
|
+
@utility hit-area {
|
|
30
|
+
position: relative;
|
|
31
|
+
|
|
32
|
+
&::before {
|
|
33
|
+
position: absolute;
|
|
34
|
+
top: 50%;
|
|
35
|
+
left: 50%;
|
|
36
|
+
width: max(100%, var(--gw-target-min));
|
|
37
|
+
height: max(100%, var(--gw-target-min));
|
|
38
|
+
content: "";
|
|
39
|
+
transform: translate(-50%, -50%);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/* Dense data grids in compact density only: 24 × 24px. */
|
|
44
|
+
@utility hit-area-compact {
|
|
45
|
+
position: relative;
|
|
46
|
+
|
|
47
|
+
&::before {
|
|
48
|
+
position: absolute;
|
|
49
|
+
top: 50%;
|
|
50
|
+
left: 50%;
|
|
51
|
+
width: max(100%, var(--gw-target-compact));
|
|
52
|
+
height: max(100%, var(--gw-target-compact));
|
|
53
|
+
content: "";
|
|
54
|
+
transform: translate(-50%, -50%);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/* WCAG 1.4.8: readable prose. 80ch measure, 1.5 line height, wide paragraph spacing. */
|
|
59
|
+
@utility prose {
|
|
60
|
+
max-width: 80ch;
|
|
61
|
+
line-height: var(--gw-font-line-height-body);
|
|
62
|
+
|
|
63
|
+
& p {
|
|
64
|
+
margin-block: 0 var(--gw-paragraph-spacing-body);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@layer base {
|
|
69
|
+
html {
|
|
70
|
+
/* WCAG 2.4.12: sticky headers and footers never cover focused elements. */
|
|
71
|
+
scroll-padding-top: var(--gw-scroll-padding-top);
|
|
72
|
+
scroll-padding-bottom: var(--gw-scroll-padding-bottom);
|
|
73
|
+
background-color: var(--gw-color-surface-default);
|
|
74
|
+
color: var(--gw-color-text-default);
|
|
75
|
+
font-family: var(--gw-font-family-sans);
|
|
76
|
+
font-size: 100%;
|
|
77
|
+
line-height: var(--gw-font-line-height-body);
|
|
78
|
+
text-size-adjust: 100%;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
body {
|
|
82
|
+
min-width: 20rem;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* Every focusable element gets a visible ring unless a component draws its own. */
|
|
86
|
+
:where(:focus-visible) {
|
|
87
|
+
outline: var(--gw-focus-ring-width) solid var(--gw-color-focus-ring);
|
|
88
|
+
outline-offset: var(--gw-focus-ring-offset);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/* Links are underlined, never identified by colour alone. */
|
|
92
|
+
a {
|
|
93
|
+
color: var(--gw-color-text-link);
|
|
94
|
+
text-decoration-line: underline;
|
|
95
|
+
text-underline-offset: 0.15em;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/* WCAG 2.3.3: only opacity fades remain under reduced motion. */
|
|
99
|
+
@media (prefers-reduced-motion: reduce) {
|
|
100
|
+
*,
|
|
101
|
+
*::before,
|
|
102
|
+
*::after {
|
|
103
|
+
scroll-behavior: auto;
|
|
104
|
+
animation-duration: 0ms;
|
|
105
|
+
animation-iteration-count: 1;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,77 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graftwork/ui",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Graftwork React components, built on shadcn/ui with React Aria",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://graftwork-studio.github.io/design-system/",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/graftwork-studio/design-system/issues"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"react",
|
|
12
|
+
"react-aria",
|
|
13
|
+
"shadcn",
|
|
14
|
+
"tailwindcss",
|
|
15
|
+
"accessibility",
|
|
16
|
+
"design-system"
|
|
17
|
+
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/graftwork-studio/design-system.git",
|
|
22
|
+
"directory": "packages/ui"
|
|
23
|
+
},
|
|
24
|
+
"sideEffects": [
|
|
25
|
+
"**/*.css"
|
|
26
|
+
],
|
|
27
|
+
"files": [
|
|
28
|
+
"CHANGELOG.md",
|
|
29
|
+
"LICENSE",
|
|
30
|
+
"dist"
|
|
31
|
+
],
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"default": "./dist/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./styles.css": {
|
|
38
|
+
"style": "./dist/styles.css",
|
|
39
|
+
"default": "./dist/styles.css"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@fontsource-variable/noto-sans": "5.3.0",
|
|
44
|
+
"@graftwork/tokens": "^1.0.0",
|
|
45
|
+
"class-variance-authority": "0.7.1",
|
|
46
|
+
"cn": "0.5.2",
|
|
47
|
+
"lucide-react": "1.74.0",
|
|
48
|
+
"react-aria-components": "1.22.1",
|
|
49
|
+
"react-is": "19.3.1",
|
|
50
|
+
"recharts": "3.11.0"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"react": "^19.0.0",
|
|
54
|
+
"react-dom": "^19.0.0"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/node": "26.6.6",
|
|
58
|
+
"@types/react": "19.3.0",
|
|
59
|
+
"@types/react-dom": "19.3.0",
|
|
60
|
+
"@vitest/browser-playwright": "5.1.1",
|
|
61
|
+
"playwright": "1.65.1",
|
|
62
|
+
"react": "19.3.1",
|
|
63
|
+
"react-dom": "19.3.1",
|
|
64
|
+
"typescript": "6.0.3",
|
|
65
|
+
"vitest": "5.1.1",
|
|
66
|
+
"vitest-browser-react": "2.3.0"
|
|
67
|
+
},
|
|
68
|
+
"publishConfig": {
|
|
69
|
+
"access": "public",
|
|
70
|
+
"provenance": true
|
|
71
|
+
},
|
|
72
|
+
"scripts": {
|
|
73
|
+
"build": "tsc -p tsconfig.build.json && node scripts/copy-css.ts",
|
|
74
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
75
|
+
"test": "vitest run"
|
|
76
|
+
}
|
|
6
77
|
}
|
package/README.md
DELETED