@keboola/design 4.4.0 → 5.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/AGENTS.md +68 -44
- package/COMPONENT-API.md +35 -6
- package/README.md +1 -1
- package/dist/charts.cjs +268 -0
- package/dist/charts.cjs.map +1 -0
- package/dist/charts.d.cts +181 -0
- package/dist/charts.d.ts +181 -0
- package/dist/charts.js +259 -0
- package/dist/charts.js.map +1 -0
- package/dist/editors.cjs +151 -77
- package/dist/editors.cjs.map +1 -1
- package/dist/editors.js +153 -79
- package/dist/editors.js.map +1 -1
- package/dist/index.cjs +2610 -1537
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +486 -467
- package/dist/index.d.ts +486 -467
- package/dist/index.js +2337 -1273
- package/dist/index.js.map +1 -1
- package/dist/markdown-editor.cjs +155 -119
- package/dist/markdown-editor.cjs.map +1 -1
- package/dist/markdown-editor.js +155 -119
- package/dist/markdown-editor.js.map +1 -1
- package/dist/mermaid.cjs +62 -36
- package/dist/mermaid.cjs.map +1 -1
- package/dist/mermaid.js +63 -37
- package/dist/mermaid.js.map +1 -1
- package/dist/rjsf.cjs +459 -385
- package/dist/rjsf.cjs.map +1 -1
- package/dist/rjsf.js +363 -289
- package/dist/rjsf.js.map +1 -1
- package/dist/styles.css +4 -2
- package/dist/testing.cjs +238 -111
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +6 -0
- package/dist/testing.d.ts +6 -0
- package/dist/testing.js +240 -113
- package/dist/testing.js.map +1 -1
- package/package.json +35 -16
- package/src/styles.css +72 -30
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ComponentProps, ReactElement } from 'react';
|
|
3
|
+
import { Tooltip } from 'recharts';
|
|
4
|
+
|
|
5
|
+
/** A length that recharts' `<ResponsiveContainer>` accepts: px number or `"NN%"`. */
|
|
6
|
+
type ChartDimension = number | `${number}%`;
|
|
7
|
+
type ChartContainerProps = Omit<ComponentProps<'div'>, 'children'> & {
|
|
8
|
+
/**
|
|
9
|
+
* Height as a px number or percentage string. Charts have no intrinsic
|
|
10
|
+
* height, so a container needs one either here or from a sized ancestor.
|
|
11
|
+
* Defaults to 300.
|
|
12
|
+
*/
|
|
13
|
+
height?: ChartDimension;
|
|
14
|
+
/** Width as a px number or percentage. Defaults to `"100%"` (fills parent). */
|
|
15
|
+
width?: ChartDimension;
|
|
16
|
+
/** A single recharts chart element (`<LineChart>`, `<BarChart>`, …). */
|
|
17
|
+
children: ReactElement;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Responsive, brand-themed frame for a chart. Wraps the chart in recharts'
|
|
21
|
+
* `<ResponsiveContainer>` and applies the semantic-token chrome (axis text,
|
|
22
|
+
* grid, cursor) through CSS so every chart inside inherits it. Sizing is
|
|
23
|
+
* intrinsic: give it a `height` (default 300) and it fills the parent width.
|
|
24
|
+
*/
|
|
25
|
+
declare const ChartContainer: ({ height, width, className, children, ...props }: ChartContainerProps) => react_jsx_runtime.JSX.Element;
|
|
26
|
+
|
|
27
|
+
type TooltipPayloadEntry = {
|
|
28
|
+
name?: string | number;
|
|
29
|
+
value?: string | number;
|
|
30
|
+
color?: string;
|
|
31
|
+
dataKey?: string | number;
|
|
32
|
+
};
|
|
33
|
+
type ChartTooltipContentProps = {
|
|
34
|
+
active?: boolean;
|
|
35
|
+
label?: string | number;
|
|
36
|
+
payload?: TooltipPayloadEntry[];
|
|
37
|
+
/** Format a value for display (e.g. currency, percentage). */
|
|
38
|
+
valueFormatter?: (value: string | number, name: string) => string;
|
|
39
|
+
className?: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Brand-themed tooltip body. Surfaces (background, border, text) resolve from
|
|
43
|
+
* semantic tokens, and each series swatch reuses the recharts-provided series
|
|
44
|
+
* `color` (already a `--color-chart-*` token from this package's charts).
|
|
45
|
+
*/
|
|
46
|
+
declare const ChartTooltipContent: ({ active, label, payload, valueFormatter, className, }: ChartTooltipContentProps) => react_jsx_runtime.JSX.Element | null;
|
|
47
|
+
type ChartTooltipProps = ComponentProps<typeof Tooltip> & {
|
|
48
|
+
valueFormatter?: (value: string | number, name: string) => string;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Drop-in recharts `<Tooltip>` pre-wired to render {@link ChartTooltipContent}.
|
|
52
|
+
* Each chart mounts one by default; pass `showTooltip={false}` on the chart to omit.
|
|
53
|
+
*/
|
|
54
|
+
declare const ChartTooltip: ({ valueFormatter, ...props }: ChartTooltipProps) => react_jsx_runtime.JSX.Element;
|
|
55
|
+
|
|
56
|
+
/** Number of the semantic chart token (`1`–`5`) a series maps to. */
|
|
57
|
+
type ChartColorToken = 1 | 2 | 3 | 4 | 5;
|
|
58
|
+
/**
|
|
59
|
+
* The CSS color for a chart token. `index` is 0-based (series position); it
|
|
60
|
+
* wraps around the five-slot palette so any number of series stays on-brand.
|
|
61
|
+
*/
|
|
62
|
+
declare const chartTokenColor: (index: number) => string;
|
|
63
|
+
|
|
64
|
+
/** A single row of chart data — an object keyed by the axis + series keys. */
|
|
65
|
+
type ChartDatum = Record<string, string | number | null | undefined>;
|
|
66
|
+
/**
|
|
67
|
+
* One plotted series (a line, bar, or area). Its color comes from the semantic
|
|
68
|
+
* chart palette: by series order, or pinned to a specific token via `color`.
|
|
69
|
+
*/
|
|
70
|
+
type ChartSeries = {
|
|
71
|
+
/** Key into each datum for this series' value. */
|
|
72
|
+
dataKey: string;
|
|
73
|
+
/** Human label for legend/tooltip. Defaults to `dataKey`. */
|
|
74
|
+
name?: string;
|
|
75
|
+
/** Pin to a specific palette token (1–5). Defaults to the series position. */
|
|
76
|
+
color?: ChartColorToken;
|
|
77
|
+
};
|
|
78
|
+
/** Props shared by the cartesian charts (line / bar / area). */
|
|
79
|
+
type CartesianChartProps = {
|
|
80
|
+
/** The rows to plot. */
|
|
81
|
+
data: ChartDatum[];
|
|
82
|
+
/** Key into each datum for the category (x) axis. */
|
|
83
|
+
xKey: string;
|
|
84
|
+
/** Series to plot. */
|
|
85
|
+
series: ChartSeries[];
|
|
86
|
+
/** Height as a px number or percentage. Defaults to 300. */
|
|
87
|
+
height?: ChartDimension;
|
|
88
|
+
/** Width as a px number or percentage. Defaults to `"100%"`. */
|
|
89
|
+
width?: ChartDimension;
|
|
90
|
+
/** Show the cartesian background grid. Defaults to `true`. */
|
|
91
|
+
showGrid?: boolean;
|
|
92
|
+
/** Show the value (y) axis. Defaults to `true`. */
|
|
93
|
+
showYAxis?: boolean;
|
|
94
|
+
/** Show a legend below the chart. Defaults to `false`. */
|
|
95
|
+
showLegend?: boolean;
|
|
96
|
+
/** Show the hover tooltip. Defaults to `true`. */
|
|
97
|
+
showTooltip?: boolean;
|
|
98
|
+
/** Format a series value for the axis and tooltip. */
|
|
99
|
+
valueFormatter?: (value: number) => string;
|
|
100
|
+
className?: string;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* A themed multi-series line chart. Each series' color comes from the semantic
|
|
105
|
+
* `--color-chart-*` palette (by order, or pinned via `series[].color`), which
|
|
106
|
+
* follows the active color scheme and the active brand's `colors.chart` when it
|
|
107
|
+
* defines one. Wrap-free — mounts its own {@link ChartContainer}.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* <LineChart
|
|
111
|
+
* data={data}
|
|
112
|
+
* xKey="month"
|
|
113
|
+
* series={[{ dataKey: 'revenue', name: 'Revenue' }, { dataKey: 'cost' }]}
|
|
114
|
+
* />
|
|
115
|
+
*/
|
|
116
|
+
declare const LineChart: ({ data, xKey, series, height, width, className, ...chrome }: CartesianChartProps) => react_jsx_runtime.JSX.Element;
|
|
117
|
+
|
|
118
|
+
type BarChartProps = CartesianChartProps & {
|
|
119
|
+
/** Stack the series into a single bar per category. Defaults to grouped. */
|
|
120
|
+
stacked?: boolean;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* A themed multi-series bar chart. Series colors come from the semantic
|
|
124
|
+
* `--color-chart-*` palette (by order, or pinned via `series[].color`), which
|
|
125
|
+
* follows the active color scheme and the active brand's `colors.chart` when it
|
|
126
|
+
* defines one. Pass `stacked` to stack the series instead of grouping them.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* <BarChart data={data} xKey="month" series={[{ dataKey: 'revenue' }]} />
|
|
130
|
+
*/
|
|
131
|
+
declare const BarChart: ({ data, xKey, series, height, width, className, stacked, ...chrome }: BarChartProps) => react_jsx_runtime.JSX.Element;
|
|
132
|
+
|
|
133
|
+
type AreaChartProps = CartesianChartProps & {
|
|
134
|
+
/** Stack the series into a cumulative area. Defaults to overlaid. */
|
|
135
|
+
stacked?: boolean;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* A themed multi-series area chart. Each series is stroked and softly filled
|
|
139
|
+
* from the semantic `--color-chart-*` palette (by order, or pinned via
|
|
140
|
+
* `series[].color`), which follows the active color scheme and the active
|
|
141
|
+
* brand's `colors.chart` when it defines one. Pass `stacked` to stack the
|
|
142
|
+
* series cumulatively.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* <AreaChart data={data} xKey="month" series={[{ dataKey: 'revenue' }]} />
|
|
146
|
+
*/
|
|
147
|
+
declare const AreaChart: ({ data, xKey, series, height, width, className, stacked, ...chrome }: AreaChartProps) => react_jsx_runtime.JSX.Element;
|
|
148
|
+
|
|
149
|
+
type PieChartProps = {
|
|
150
|
+
/** The rows to plot — one sector per row. */
|
|
151
|
+
data: ChartDatum[];
|
|
152
|
+
/** Key into each datum for the sector label. */
|
|
153
|
+
nameKey: string;
|
|
154
|
+
/** Key into each datum for the sector value. */
|
|
155
|
+
dataKey: string;
|
|
156
|
+
/** Render as a donut with a hole of this inner radius (px or %). */
|
|
157
|
+
innerRadius?: ChartDimension;
|
|
158
|
+
/** Height as a px number or percentage. Defaults to 300. */
|
|
159
|
+
height?: ChartDimension;
|
|
160
|
+
/** Width as a px number or percentage. Defaults to `"100%"`. */
|
|
161
|
+
width?: ChartDimension;
|
|
162
|
+
/** Show a legend below the chart. Defaults to `true`. */
|
|
163
|
+
showLegend?: boolean;
|
|
164
|
+
/** Show the hover tooltip. Defaults to `true`. */
|
|
165
|
+
showTooltip?: boolean;
|
|
166
|
+
/** Format a sector value for the tooltip. */
|
|
167
|
+
valueFormatter?: (value: number) => string;
|
|
168
|
+
className?: string;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* A themed pie / donut chart. Each sector cycles through the semantic
|
|
172
|
+
* `--color-chart-*` palette, which follows the active color scheme and the
|
|
173
|
+
* active brand's `colors.chart` when it defines one. Pass `innerRadius` to make
|
|
174
|
+
* a donut.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* <PieChart data={data} nameKey="engine" dataKey="rows" innerRadius="60%" />
|
|
178
|
+
*/
|
|
179
|
+
declare const PieChart: ({ data, nameKey, dataKey, innerRadius, height, width, className, showLegend, showTooltip, valueFormatter, }: PieChartProps) => react_jsx_runtime.JSX.Element;
|
|
180
|
+
|
|
181
|
+
export { AreaChart, type AreaChartProps, BarChart, type BarChartProps, type CartesianChartProps, type ChartColorToken, ChartContainer, type ChartContainerProps, type ChartDatum, type ChartDimension, type ChartSeries, ChartTooltip, ChartTooltipContent, type ChartTooltipProps, LineChart, PieChart, type PieChartProps, chartTokenColor };
|
package/dist/charts.d.ts
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ComponentProps, ReactElement } from 'react';
|
|
3
|
+
import { Tooltip } from 'recharts';
|
|
4
|
+
|
|
5
|
+
/** A length that recharts' `<ResponsiveContainer>` accepts: px number or `"NN%"`. */
|
|
6
|
+
type ChartDimension = number | `${number}%`;
|
|
7
|
+
type ChartContainerProps = Omit<ComponentProps<'div'>, 'children'> & {
|
|
8
|
+
/**
|
|
9
|
+
* Height as a px number or percentage string. Charts have no intrinsic
|
|
10
|
+
* height, so a container needs one either here or from a sized ancestor.
|
|
11
|
+
* Defaults to 300.
|
|
12
|
+
*/
|
|
13
|
+
height?: ChartDimension;
|
|
14
|
+
/** Width as a px number or percentage. Defaults to `"100%"` (fills parent). */
|
|
15
|
+
width?: ChartDimension;
|
|
16
|
+
/** A single recharts chart element (`<LineChart>`, `<BarChart>`, …). */
|
|
17
|
+
children: ReactElement;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Responsive, brand-themed frame for a chart. Wraps the chart in recharts'
|
|
21
|
+
* `<ResponsiveContainer>` and applies the semantic-token chrome (axis text,
|
|
22
|
+
* grid, cursor) through CSS so every chart inside inherits it. Sizing is
|
|
23
|
+
* intrinsic: give it a `height` (default 300) and it fills the parent width.
|
|
24
|
+
*/
|
|
25
|
+
declare const ChartContainer: ({ height, width, className, children, ...props }: ChartContainerProps) => react_jsx_runtime.JSX.Element;
|
|
26
|
+
|
|
27
|
+
type TooltipPayloadEntry = {
|
|
28
|
+
name?: string | number;
|
|
29
|
+
value?: string | number;
|
|
30
|
+
color?: string;
|
|
31
|
+
dataKey?: string | number;
|
|
32
|
+
};
|
|
33
|
+
type ChartTooltipContentProps = {
|
|
34
|
+
active?: boolean;
|
|
35
|
+
label?: string | number;
|
|
36
|
+
payload?: TooltipPayloadEntry[];
|
|
37
|
+
/** Format a value for display (e.g. currency, percentage). */
|
|
38
|
+
valueFormatter?: (value: string | number, name: string) => string;
|
|
39
|
+
className?: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Brand-themed tooltip body. Surfaces (background, border, text) resolve from
|
|
43
|
+
* semantic tokens, and each series swatch reuses the recharts-provided series
|
|
44
|
+
* `color` (already a `--color-chart-*` token from this package's charts).
|
|
45
|
+
*/
|
|
46
|
+
declare const ChartTooltipContent: ({ active, label, payload, valueFormatter, className, }: ChartTooltipContentProps) => react_jsx_runtime.JSX.Element | null;
|
|
47
|
+
type ChartTooltipProps = ComponentProps<typeof Tooltip> & {
|
|
48
|
+
valueFormatter?: (value: string | number, name: string) => string;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Drop-in recharts `<Tooltip>` pre-wired to render {@link ChartTooltipContent}.
|
|
52
|
+
* Each chart mounts one by default; pass `showTooltip={false}` on the chart to omit.
|
|
53
|
+
*/
|
|
54
|
+
declare const ChartTooltip: ({ valueFormatter, ...props }: ChartTooltipProps) => react_jsx_runtime.JSX.Element;
|
|
55
|
+
|
|
56
|
+
/** Number of the semantic chart token (`1`–`5`) a series maps to. */
|
|
57
|
+
type ChartColorToken = 1 | 2 | 3 | 4 | 5;
|
|
58
|
+
/**
|
|
59
|
+
* The CSS color for a chart token. `index` is 0-based (series position); it
|
|
60
|
+
* wraps around the five-slot palette so any number of series stays on-brand.
|
|
61
|
+
*/
|
|
62
|
+
declare const chartTokenColor: (index: number) => string;
|
|
63
|
+
|
|
64
|
+
/** A single row of chart data — an object keyed by the axis + series keys. */
|
|
65
|
+
type ChartDatum = Record<string, string | number | null | undefined>;
|
|
66
|
+
/**
|
|
67
|
+
* One plotted series (a line, bar, or area). Its color comes from the semantic
|
|
68
|
+
* chart palette: by series order, or pinned to a specific token via `color`.
|
|
69
|
+
*/
|
|
70
|
+
type ChartSeries = {
|
|
71
|
+
/** Key into each datum for this series' value. */
|
|
72
|
+
dataKey: string;
|
|
73
|
+
/** Human label for legend/tooltip. Defaults to `dataKey`. */
|
|
74
|
+
name?: string;
|
|
75
|
+
/** Pin to a specific palette token (1–5). Defaults to the series position. */
|
|
76
|
+
color?: ChartColorToken;
|
|
77
|
+
};
|
|
78
|
+
/** Props shared by the cartesian charts (line / bar / area). */
|
|
79
|
+
type CartesianChartProps = {
|
|
80
|
+
/** The rows to plot. */
|
|
81
|
+
data: ChartDatum[];
|
|
82
|
+
/** Key into each datum for the category (x) axis. */
|
|
83
|
+
xKey: string;
|
|
84
|
+
/** Series to plot. */
|
|
85
|
+
series: ChartSeries[];
|
|
86
|
+
/** Height as a px number or percentage. Defaults to 300. */
|
|
87
|
+
height?: ChartDimension;
|
|
88
|
+
/** Width as a px number or percentage. Defaults to `"100%"`. */
|
|
89
|
+
width?: ChartDimension;
|
|
90
|
+
/** Show the cartesian background grid. Defaults to `true`. */
|
|
91
|
+
showGrid?: boolean;
|
|
92
|
+
/** Show the value (y) axis. Defaults to `true`. */
|
|
93
|
+
showYAxis?: boolean;
|
|
94
|
+
/** Show a legend below the chart. Defaults to `false`. */
|
|
95
|
+
showLegend?: boolean;
|
|
96
|
+
/** Show the hover tooltip. Defaults to `true`. */
|
|
97
|
+
showTooltip?: boolean;
|
|
98
|
+
/** Format a series value for the axis and tooltip. */
|
|
99
|
+
valueFormatter?: (value: number) => string;
|
|
100
|
+
className?: string;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* A themed multi-series line chart. Each series' color comes from the semantic
|
|
105
|
+
* `--color-chart-*` palette (by order, or pinned via `series[].color`), which
|
|
106
|
+
* follows the active color scheme and the active brand's `colors.chart` when it
|
|
107
|
+
* defines one. Wrap-free — mounts its own {@link ChartContainer}.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* <LineChart
|
|
111
|
+
* data={data}
|
|
112
|
+
* xKey="month"
|
|
113
|
+
* series={[{ dataKey: 'revenue', name: 'Revenue' }, { dataKey: 'cost' }]}
|
|
114
|
+
* />
|
|
115
|
+
*/
|
|
116
|
+
declare const LineChart: ({ data, xKey, series, height, width, className, ...chrome }: CartesianChartProps) => react_jsx_runtime.JSX.Element;
|
|
117
|
+
|
|
118
|
+
type BarChartProps = CartesianChartProps & {
|
|
119
|
+
/** Stack the series into a single bar per category. Defaults to grouped. */
|
|
120
|
+
stacked?: boolean;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* A themed multi-series bar chart. Series colors come from the semantic
|
|
124
|
+
* `--color-chart-*` palette (by order, or pinned via `series[].color`), which
|
|
125
|
+
* follows the active color scheme and the active brand's `colors.chart` when it
|
|
126
|
+
* defines one. Pass `stacked` to stack the series instead of grouping them.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* <BarChart data={data} xKey="month" series={[{ dataKey: 'revenue' }]} />
|
|
130
|
+
*/
|
|
131
|
+
declare const BarChart: ({ data, xKey, series, height, width, className, stacked, ...chrome }: BarChartProps) => react_jsx_runtime.JSX.Element;
|
|
132
|
+
|
|
133
|
+
type AreaChartProps = CartesianChartProps & {
|
|
134
|
+
/** Stack the series into a cumulative area. Defaults to overlaid. */
|
|
135
|
+
stacked?: boolean;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* A themed multi-series area chart. Each series is stroked and softly filled
|
|
139
|
+
* from the semantic `--color-chart-*` palette (by order, or pinned via
|
|
140
|
+
* `series[].color`), which follows the active color scheme and the active
|
|
141
|
+
* brand's `colors.chart` when it defines one. Pass `stacked` to stack the
|
|
142
|
+
* series cumulatively.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* <AreaChart data={data} xKey="month" series={[{ dataKey: 'revenue' }]} />
|
|
146
|
+
*/
|
|
147
|
+
declare const AreaChart: ({ data, xKey, series, height, width, className, stacked, ...chrome }: AreaChartProps) => react_jsx_runtime.JSX.Element;
|
|
148
|
+
|
|
149
|
+
type PieChartProps = {
|
|
150
|
+
/** The rows to plot — one sector per row. */
|
|
151
|
+
data: ChartDatum[];
|
|
152
|
+
/** Key into each datum for the sector label. */
|
|
153
|
+
nameKey: string;
|
|
154
|
+
/** Key into each datum for the sector value. */
|
|
155
|
+
dataKey: string;
|
|
156
|
+
/** Render as a donut with a hole of this inner radius (px or %). */
|
|
157
|
+
innerRadius?: ChartDimension;
|
|
158
|
+
/** Height as a px number or percentage. Defaults to 300. */
|
|
159
|
+
height?: ChartDimension;
|
|
160
|
+
/** Width as a px number or percentage. Defaults to `"100%"`. */
|
|
161
|
+
width?: ChartDimension;
|
|
162
|
+
/** Show a legend below the chart. Defaults to `true`. */
|
|
163
|
+
showLegend?: boolean;
|
|
164
|
+
/** Show the hover tooltip. Defaults to `true`. */
|
|
165
|
+
showTooltip?: boolean;
|
|
166
|
+
/** Format a sector value for the tooltip. */
|
|
167
|
+
valueFormatter?: (value: number) => string;
|
|
168
|
+
className?: string;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* A themed pie / donut chart. Each sector cycles through the semantic
|
|
172
|
+
* `--color-chart-*` palette, which follows the active color scheme and the
|
|
173
|
+
* active brand's `colors.chart` when it defines one. Pass `innerRadius` to make
|
|
174
|
+
* a donut.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* <PieChart data={data} nameKey="engine" dataKey="rows" innerRadius="60%" />
|
|
178
|
+
*/
|
|
179
|
+
declare const PieChart: ({ data, nameKey, dataKey, innerRadius, height, width, className, showLegend, showTooltip, valueFormatter, }: PieChartProps) => react_jsx_runtime.JSX.Element;
|
|
180
|
+
|
|
181
|
+
export { AreaChart, type AreaChartProps, BarChart, type BarChartProps, type CartesianChartProps, type ChartColorToken, ChartContainer, type ChartContainerProps, type ChartDatum, type ChartDimension, type ChartSeries, ChartTooltip, ChartTooltipContent, type ChartTooltipProps, LineChart, PieChart, type PieChartProps, chartTokenColor };
|
package/dist/charts.js
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { ResponsiveContainer, Tooltip, LineChart as LineChart$1, Line, BarChart as BarChart$1, Bar, AreaChart as AreaChart$1, Area, PieChart as PieChart$1, Legend, Pie, Cell, CartesianGrid, XAxis, YAxis } from 'recharts';
|
|
2
|
+
import { clsx } from 'clsx';
|
|
3
|
+
import { extendTailwindMerge } from 'tailwind-merge';
|
|
4
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
// src/blocks/Charts/ChartContainer.tsx
|
|
7
|
+
var twMerge = extendTailwindMerge({
|
|
8
|
+
prefix: "tw-"
|
|
9
|
+
});
|
|
10
|
+
var cn = (...classes) => twMerge(clsx(...classes));
|
|
11
|
+
var ChartContainer = ({
|
|
12
|
+
height = 300,
|
|
13
|
+
width = "100%",
|
|
14
|
+
className,
|
|
15
|
+
children,
|
|
16
|
+
...props
|
|
17
|
+
}) => /* @__PURE__ */ jsx(
|
|
18
|
+
"div",
|
|
19
|
+
{
|
|
20
|
+
className: cn(
|
|
21
|
+
"tw-text-xs",
|
|
22
|
+
// Axis ticks and labels follow the muted foreground token.
|
|
23
|
+
"[&_.recharts-cartesian-axis-tick_text]:tw-fill-muted-foreground",
|
|
24
|
+
"[&_.recharts-polar-angle-axis-tick_text]:tw-fill-muted-foreground",
|
|
25
|
+
"[&_.recharts-label]:tw-fill-muted-foreground",
|
|
26
|
+
"[&_.recharts-legend-item-text]:!tw-text-muted-foreground",
|
|
27
|
+
// Grid lines, axis lines and the hover cursor follow the border token.
|
|
28
|
+
"[&_.recharts-cartesian-grid_line]:tw-stroke-border/60",
|
|
29
|
+
"[&_.recharts-cartesian-axis-line]:tw-stroke-border",
|
|
30
|
+
"[&_.recharts-cartesian-axis-tick-line]:tw-stroke-border",
|
|
31
|
+
"[&_.recharts-curve.recharts-tooltip-cursor]:tw-stroke-border",
|
|
32
|
+
"[&_.recharts-rectangle.recharts-tooltip-cursor]:tw-fill-muted/60",
|
|
33
|
+
"[&_.recharts-surface]:tw-outline-none",
|
|
34
|
+
className
|
|
35
|
+
),
|
|
36
|
+
...props,
|
|
37
|
+
children: /* @__PURE__ */ jsx(ResponsiveContainer, { width, height, children })
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
var ChartTooltipContent = ({
|
|
41
|
+
active,
|
|
42
|
+
label,
|
|
43
|
+
payload,
|
|
44
|
+
valueFormatter,
|
|
45
|
+
className
|
|
46
|
+
}) => {
|
|
47
|
+
if (!active || !payload?.length) return null;
|
|
48
|
+
return /* @__PURE__ */ jsxs(
|
|
49
|
+
"div",
|
|
50
|
+
{
|
|
51
|
+
className: cn(
|
|
52
|
+
"tw-min-w-32 tw-rounded-md tw-border tw-border-border tw-bg-popover tw-px-2.5 tw-py-1.5 tw-text-xs tw-text-popover-foreground tw-shadow-md",
|
|
53
|
+
className
|
|
54
|
+
),
|
|
55
|
+
children: [
|
|
56
|
+
label != null && /* @__PURE__ */ jsx("div", { className: "tw-mb-1 tw-font-medium", children: label }),
|
|
57
|
+
/* @__PURE__ */ jsx("div", { className: "tw-flex tw-flex-col tw-gap-1", children: payload.map((entry) => {
|
|
58
|
+
const name = String(entry.name ?? entry.dataKey ?? "");
|
|
59
|
+
const value = entry.value;
|
|
60
|
+
const hasNumber = value != null && value !== "" && Number.isFinite(Number(value));
|
|
61
|
+
const display = hasNumber ? valueFormatter ? valueFormatter(Number(value), name) : String(Number(value)) : value ?? "";
|
|
62
|
+
return /* @__PURE__ */ jsxs(
|
|
63
|
+
"div",
|
|
64
|
+
{
|
|
65
|
+
className: "tw-flex tw-items-center tw-justify-between tw-gap-3",
|
|
66
|
+
children: [
|
|
67
|
+
/* @__PURE__ */ jsxs("span", { className: "tw-flex tw-items-center tw-gap-1.5", children: [
|
|
68
|
+
/* @__PURE__ */ jsx(
|
|
69
|
+
"span",
|
|
70
|
+
{
|
|
71
|
+
className: "tw-size-2 tw-shrink-0 tw-rounded-[2px]",
|
|
72
|
+
style: { backgroundColor: entry.color }
|
|
73
|
+
}
|
|
74
|
+
),
|
|
75
|
+
/* @__PURE__ */ jsx("span", { className: "tw-text-muted-foreground", children: name })
|
|
76
|
+
] }),
|
|
77
|
+
/* @__PURE__ */ jsx("span", { className: "tw-font-medium tw-tabular-nums", children: display })
|
|
78
|
+
]
|
|
79
|
+
},
|
|
80
|
+
String(entry.dataKey ?? name)
|
|
81
|
+
);
|
|
82
|
+
}) })
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
var ChartTooltip = ({ valueFormatter, ...props }) => /* @__PURE__ */ jsx(
|
|
88
|
+
Tooltip,
|
|
89
|
+
{
|
|
90
|
+
cursor: { strokeWidth: 1 },
|
|
91
|
+
content: /* @__PURE__ */ jsx(ChartTooltipContent, { valueFormatter }),
|
|
92
|
+
...props
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
// src/blocks/Charts/format.ts
|
|
97
|
+
var formatValue = (value, valueFormatter) => {
|
|
98
|
+
if (value == null || value === "") return "";
|
|
99
|
+
const num = Number(value);
|
|
100
|
+
if (!Number.isFinite(num)) return "";
|
|
101
|
+
return valueFormatter ? valueFormatter(num) : String(num);
|
|
102
|
+
};
|
|
103
|
+
var AXIS_PROPS = {
|
|
104
|
+
tickLine: false,
|
|
105
|
+
axisLine: false,
|
|
106
|
+
tick: { fontSize: 11 }
|
|
107
|
+
};
|
|
108
|
+
var cartesianChrome = ({
|
|
109
|
+
xKey,
|
|
110
|
+
showGrid = true,
|
|
111
|
+
showYAxis = true,
|
|
112
|
+
showLegend = false,
|
|
113
|
+
showTooltip = true,
|
|
114
|
+
valueFormatter
|
|
115
|
+
}) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
116
|
+
showGrid && /* @__PURE__ */ jsx(CartesianGrid, { strokeDasharray: "3 3", vertical: false }),
|
|
117
|
+
/* @__PURE__ */ jsx(XAxis, { dataKey: xKey, ...AXIS_PROPS }),
|
|
118
|
+
showYAxis && /* @__PURE__ */ jsx(
|
|
119
|
+
YAxis,
|
|
120
|
+
{
|
|
121
|
+
width: 48,
|
|
122
|
+
...AXIS_PROPS,
|
|
123
|
+
tickFormatter: valueFormatter ? (value) => formatValue(value, valueFormatter) : void 0
|
|
124
|
+
}
|
|
125
|
+
),
|
|
126
|
+
showTooltip && /* @__PURE__ */ jsx(
|
|
127
|
+
ChartTooltip,
|
|
128
|
+
{
|
|
129
|
+
valueFormatter: valueFormatter ? (value) => formatValue(value, valueFormatter) : void 0
|
|
130
|
+
}
|
|
131
|
+
),
|
|
132
|
+
showLegend && /* @__PURE__ */ jsx(Legend, { wrapperStyle: { fontSize: 11 } })
|
|
133
|
+
] });
|
|
134
|
+
|
|
135
|
+
// src/blocks/Charts/theme.ts
|
|
136
|
+
var CHART_TOKEN_COUNT = 5;
|
|
137
|
+
var chartTokenColor = (index) => {
|
|
138
|
+
const slot = (index % CHART_TOKEN_COUNT + CHART_TOKEN_COUNT) % CHART_TOKEN_COUNT + 1;
|
|
139
|
+
return `rgb(var(--color-chart-${slot}))`;
|
|
140
|
+
};
|
|
141
|
+
var resolveSeriesColor = (index, token) => chartTokenColor(token ? token - 1 : index);
|
|
142
|
+
var LineChart = ({
|
|
143
|
+
data,
|
|
144
|
+
xKey,
|
|
145
|
+
series,
|
|
146
|
+
height,
|
|
147
|
+
width,
|
|
148
|
+
className,
|
|
149
|
+
...chrome
|
|
150
|
+
}) => /* @__PURE__ */ jsx(ChartContainer, { height, width, className, children: /* @__PURE__ */ jsxs(LineChart$1, { data, margin: { top: 8, right: 8, left: 0, bottom: 0 }, children: [
|
|
151
|
+
cartesianChrome({ xKey, ...chrome }),
|
|
152
|
+
series.map((s, index) => {
|
|
153
|
+
const color = resolveSeriesColor(index, s.color);
|
|
154
|
+
return /* @__PURE__ */ jsx(
|
|
155
|
+
Line,
|
|
156
|
+
{
|
|
157
|
+
type: "monotone",
|
|
158
|
+
dataKey: s.dataKey,
|
|
159
|
+
name: s.name ?? s.dataKey,
|
|
160
|
+
stroke: color,
|
|
161
|
+
strokeWidth: 2,
|
|
162
|
+
dot: { r: 3, fill: color, stroke: color },
|
|
163
|
+
activeDot: { r: 4 },
|
|
164
|
+
isAnimationActive: false
|
|
165
|
+
},
|
|
166
|
+
s.dataKey
|
|
167
|
+
);
|
|
168
|
+
})
|
|
169
|
+
] }) });
|
|
170
|
+
var BarChart = ({
|
|
171
|
+
data,
|
|
172
|
+
xKey,
|
|
173
|
+
series,
|
|
174
|
+
height,
|
|
175
|
+
width,
|
|
176
|
+
className,
|
|
177
|
+
stacked = false,
|
|
178
|
+
...chrome
|
|
179
|
+
}) => /* @__PURE__ */ jsx(ChartContainer, { height, width, className, children: /* @__PURE__ */ jsxs(BarChart$1, { data, margin: { top: 8, right: 8, left: 0, bottom: 0 }, children: [
|
|
180
|
+
cartesianChrome({ xKey, ...chrome }),
|
|
181
|
+
series.map((s, index) => /* @__PURE__ */ jsx(
|
|
182
|
+
Bar,
|
|
183
|
+
{
|
|
184
|
+
dataKey: s.dataKey,
|
|
185
|
+
name: s.name ?? s.dataKey,
|
|
186
|
+
fill: resolveSeriesColor(index, s.color),
|
|
187
|
+
radius: stacked ? 0 : [4, 4, 0, 0],
|
|
188
|
+
stackId: stacked ? "stack" : void 0,
|
|
189
|
+
isAnimationActive: false
|
|
190
|
+
},
|
|
191
|
+
s.dataKey
|
|
192
|
+
))
|
|
193
|
+
] }) });
|
|
194
|
+
var AreaChart = ({
|
|
195
|
+
data,
|
|
196
|
+
xKey,
|
|
197
|
+
series,
|
|
198
|
+
height,
|
|
199
|
+
width,
|
|
200
|
+
className,
|
|
201
|
+
stacked = false,
|
|
202
|
+
...chrome
|
|
203
|
+
}) => /* @__PURE__ */ jsx(ChartContainer, { height, width, className, children: /* @__PURE__ */ jsxs(AreaChart$1, { data, margin: { top: 8, right: 8, left: 0, bottom: 0 }, children: [
|
|
204
|
+
cartesianChrome({ xKey, ...chrome }),
|
|
205
|
+
series.map((s, index) => {
|
|
206
|
+
const color = resolveSeriesColor(index, s.color);
|
|
207
|
+
return /* @__PURE__ */ jsx(
|
|
208
|
+
Area,
|
|
209
|
+
{
|
|
210
|
+
type: "monotone",
|
|
211
|
+
dataKey: s.dataKey,
|
|
212
|
+
name: s.name ?? s.dataKey,
|
|
213
|
+
stroke: color,
|
|
214
|
+
fill: color,
|
|
215
|
+
fillOpacity: 0.15,
|
|
216
|
+
strokeWidth: 2,
|
|
217
|
+
stackId: stacked ? "stack" : void 0,
|
|
218
|
+
isAnimationActive: false
|
|
219
|
+
},
|
|
220
|
+
s.dataKey
|
|
221
|
+
);
|
|
222
|
+
})
|
|
223
|
+
] }) });
|
|
224
|
+
var PieChart = ({
|
|
225
|
+
data,
|
|
226
|
+
nameKey,
|
|
227
|
+
dataKey,
|
|
228
|
+
innerRadius = 0,
|
|
229
|
+
height,
|
|
230
|
+
width,
|
|
231
|
+
className,
|
|
232
|
+
showLegend = true,
|
|
233
|
+
showTooltip = true,
|
|
234
|
+
valueFormatter
|
|
235
|
+
}) => /* @__PURE__ */ jsx(ChartContainer, { height, width, className, children: /* @__PURE__ */ jsxs(PieChart$1, { children: [
|
|
236
|
+
showTooltip && /* @__PURE__ */ jsx(
|
|
237
|
+
ChartTooltip,
|
|
238
|
+
{
|
|
239
|
+
valueFormatter: valueFormatter ? (value) => formatValue(value, valueFormatter) : void 0
|
|
240
|
+
}
|
|
241
|
+
),
|
|
242
|
+
showLegend && /* @__PURE__ */ jsx(Legend, { wrapperStyle: { fontSize: 11 } }),
|
|
243
|
+
/* @__PURE__ */ jsx(
|
|
244
|
+
Pie,
|
|
245
|
+
{
|
|
246
|
+
data,
|
|
247
|
+
nameKey,
|
|
248
|
+
dataKey,
|
|
249
|
+
innerRadius,
|
|
250
|
+
stroke: "rgb(var(--color-background))",
|
|
251
|
+
isAnimationActive: false,
|
|
252
|
+
children: data.map((datum, index) => /* @__PURE__ */ jsx(Cell, { fill: chartTokenColor(index) }, String(datum[nameKey] ?? index)))
|
|
253
|
+
}
|
|
254
|
+
)
|
|
255
|
+
] }) });
|
|
256
|
+
|
|
257
|
+
export { AreaChart, BarChart, ChartContainer, ChartTooltip, ChartTooltipContent, LineChart, PieChart, chartTokenColor };
|
|
258
|
+
//# sourceMappingURL=charts.js.map
|
|
259
|
+
//# sourceMappingURL=charts.js.map
|