@dreamtree-org/twreact-ui 1.3.1 → 1.3.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/DESIGN.md +2 -2
- package/README.md +80 -1
- package/ai-skills/dreamtree-ui.md +40 -3
- package/charts/package.json +5 -0
- package/dist/_shared/cn-DPPQUJu1.js +138 -0
- package/dist/ai-schema.json +638 -0
- package/dist/charts/index.d.ts +9 -0
- package/dist/charts/index.d.ts.map +1 -0
- package/dist/charts/index.js +769 -0
- package/dist/components/charts/AreaChart.d.ts +4 -0
- package/dist/components/charts/AreaChart.d.ts.map +1 -0
- package/dist/components/charts/BarChart.d.ts +4 -0
- package/dist/components/charts/BarChart.d.ts.map +1 -0
- package/dist/components/charts/CartesianChart.d.ts +5 -0
- package/dist/components/charts/CartesianChart.d.ts.map +1 -0
- package/dist/components/charts/ChartFrame.d.ts +18 -0
- package/dist/components/charts/ChartFrame.d.ts.map +1 -0
- package/dist/components/charts/DonutChart.d.ts +4 -0
- package/dist/components/charts/DonutChart.d.ts.map +1 -0
- package/dist/components/charts/LineChart.d.ts +4 -0
- package/dist/components/charts/LineChart.d.ts.map +1 -0
- package/dist/components/charts/Sparkline.d.ts +5 -0
- package/dist/components/charts/Sparkline.d.ts.map +1 -0
- package/dist/components/charts/chartTheme.d.ts +26 -0
- package/dist/components/charts/chartTheme.d.ts.map +1 -0
- package/dist/components/rich-text/RichTextEditor.d.ts +4 -0
- package/dist/components/rich-text/RichTextEditor.d.ts.map +1 -0
- package/dist/components/rich-text/RichTextToolbar.d.ts +219 -0
- package/dist/components/rich-text/RichTextToolbar.d.ts.map +1 -0
- package/dist/esm/charts/index.js +5 -0
- package/dist/esm/components/charts/AreaChart.js +16 -0
- package/dist/esm/components/charts/BarChart.js +16 -0
- package/dist/esm/components/charts/CartesianChart.js +250 -0
- package/dist/esm/components/charts/ChartFrame.js +170 -0
- package/dist/esm/components/charts/DonutChart.js +119 -0
- package/dist/esm/components/charts/LineChart.js +16 -0
- package/dist/esm/components/charts/Sparkline.js +110 -0
- package/dist/esm/components/charts/chartTheme.js +109 -0
- package/dist/esm/components/rich-text/RichTextEditor.js +244 -0
- package/dist/esm/components/rich-text/RichTextToolbar.js +397 -0
- package/dist/esm/rich-text/index.js +1 -0
- package/dist/index.css +1 -1
- package/dist/index.esm.css +1 -1
- package/dist/index.esm.js +17 -4
- package/dist/index.js +17 -4
- package/dist/rich-text/index.d.ts +5 -0
- package/dist/rich-text/index.d.ts.map +1 -0
- package/dist/rich-text/index.js +654 -0
- package/dist/tokens/brands/studio.css +14 -0
- package/dist/tokens/brands/studio.json +20 -0
- package/dist/types/charts.d.ts +97 -0
- package/dist/types/charts.d.ts.map +1 -0
- package/dist/types/rich-text.d.ts +50 -0
- package/dist/types/rich-text.d.ts.map +1 -0
- package/doc/README.md +13 -0
- package/mcp/catalog.snapshot.json +1009 -3
- package/mcp/server-core.mjs +30 -1
- package/package.json +38 -2
- package/rich-text/package.json +5 -0
- package/tokens/brands/studio.json +20 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { objectWithoutProperties as _objectWithoutProperties, objectSpread2 as _objectSpread2 } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
3
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
4
|
+
import React, { useId } from 'react';
|
|
5
|
+
import { cn } from '../../utils/cn.js';
|
|
6
|
+
|
|
7
|
+
var _excluded = ["className", "title", "description", "defaultTitle", "data", "height", "emptyState", "legend", "accessibleTable", "tableColumns", "children", "aria-label"];
|
|
8
|
+
// The swatch colour arrives as a custom property so a token (`rgb(var(--dt-*))`)
|
|
9
|
+
// and a resolved rgb() string both work.
|
|
10
|
+
var swatch = function swatch(size) {
|
|
11
|
+
return cn("inline-block shrink-0 rounded-full bg-[color:var(--dt-chart-color)]", size);
|
|
12
|
+
};
|
|
13
|
+
var sizeStyle = function sizeStyle(height) {
|
|
14
|
+
return {
|
|
15
|
+
height: typeof height === "number" ? "".concat(height, "px") : height
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
function ChartLegend(_ref) {
|
|
19
|
+
var items = _ref.items;
|
|
20
|
+
return jsx("ul", {
|
|
21
|
+
className: "mt-3 flex flex-wrap items-center justify-center gap-x-4 gap-y-1 text-xs text-gray-600 dark:text-gray-300",
|
|
22
|
+
"data-testid": "chart-legend",
|
|
23
|
+
children: items.map(function (item) {
|
|
24
|
+
return jsxs("li", {
|
|
25
|
+
className: "inline-flex items-center gap-1.5",
|
|
26
|
+
children: [jsx("span", {
|
|
27
|
+
className: swatch("h-2.5 w-2.5"),
|
|
28
|
+
style: {
|
|
29
|
+
"--dt-chart-color": item.color
|
|
30
|
+
},
|
|
31
|
+
"aria-hidden": "true"
|
|
32
|
+
}), jsx("span", {
|
|
33
|
+
children: item.name
|
|
34
|
+
})]
|
|
35
|
+
}, item.name);
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function ChartTooltipContent(_ref2) {
|
|
40
|
+
var active = _ref2.active,
|
|
41
|
+
payload = _ref2.payload,
|
|
42
|
+
label = _ref2.label,
|
|
43
|
+
valueFormatter = _ref2.valueFormatter,
|
|
44
|
+
_ref2$hideLabel = _ref2.hideLabel,
|
|
45
|
+
hideLabel = _ref2$hideLabel === void 0 ? false : _ref2$hideLabel;
|
|
46
|
+
if (!active || !payload || !payload.length) return null;
|
|
47
|
+
return jsxs("div", {
|
|
48
|
+
className: "rounded-md border border-gray-200 bg-white px-3 py-2 text-xs text-gray-900 shadow-md dark:border-gray-700 dark:bg-gray-900 dark:text-gray-100",
|
|
49
|
+
children: [!hideLabel && label != null && label !== "" && jsx("p", {
|
|
50
|
+
className: "mb-1 font-medium",
|
|
51
|
+
children: label
|
|
52
|
+
}), jsx("ul", {
|
|
53
|
+
className: "space-y-0.5",
|
|
54
|
+
children: payload.map(function (entry) {
|
|
55
|
+
var _entry$payload;
|
|
56
|
+
return jsxs("li", {
|
|
57
|
+
className: "flex items-center gap-2",
|
|
58
|
+
children: [jsx("span", {
|
|
59
|
+
className: swatch("h-2 w-2"),
|
|
60
|
+
style: {
|
|
61
|
+
"--dt-chart-color": entry.color || ((_entry$payload = entry.payload) === null || _entry$payload === void 0 ? void 0 : _entry$payload.fill)
|
|
62
|
+
},
|
|
63
|
+
"aria-hidden": "true"
|
|
64
|
+
}), jsx("span", {
|
|
65
|
+
className: "text-gray-600 dark:text-gray-300",
|
|
66
|
+
children: entry.name
|
|
67
|
+
}), jsx("span", {
|
|
68
|
+
className: "ml-auto pl-3 font-medium tabular-nums",
|
|
69
|
+
children: valueFormatter(entry.value)
|
|
70
|
+
})]
|
|
71
|
+
}, "".concat(entry.dataKey, "-").concat(entry.name));
|
|
72
|
+
})
|
|
73
|
+
})]
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function ChartDataTable(_ref3) {
|
|
77
|
+
var caption = _ref3.caption,
|
|
78
|
+
columns = _ref3.columns,
|
|
79
|
+
rows = _ref3.rows;
|
|
80
|
+
return jsxs("table", {
|
|
81
|
+
className: "sr-only",
|
|
82
|
+
"data-testid": "chart-data-table",
|
|
83
|
+
children: [caption && jsx("caption", {
|
|
84
|
+
children: caption
|
|
85
|
+
}), jsx("thead", {
|
|
86
|
+
children: jsx("tr", {
|
|
87
|
+
children: columns.map(function (c) {
|
|
88
|
+
return jsx("th", {
|
|
89
|
+
scope: "col",
|
|
90
|
+
children: c.label
|
|
91
|
+
}, c.key);
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
}), jsx("tbody", {
|
|
95
|
+
children: rows.map(function (row, r) {
|
|
96
|
+
return jsx("tr", {
|
|
97
|
+
children: columns.map(function (c, i) {
|
|
98
|
+
return i === 0 ? jsx("th", {
|
|
99
|
+
scope: "row",
|
|
100
|
+
children: c.format(row[c.key])
|
|
101
|
+
}, c.key) : jsx("td", {
|
|
102
|
+
children: c.format(row[c.key])
|
|
103
|
+
}, c.key);
|
|
104
|
+
})
|
|
105
|
+
}, r);
|
|
106
|
+
})
|
|
107
|
+
})]
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The accessible shell every chart renders: the SVG lives in a `role="img"`
|
|
112
|
+
* region named by `title` and described by `description`; the numbers are
|
|
113
|
+
* repeated in a visually-hidden table (recharts' SVG has no accessible content).
|
|
114
|
+
*/
|
|
115
|
+
var ChartFrame = /*#__PURE__*/React.forwardRef(function ChartFrame(_ref4, ref) {
|
|
116
|
+
var className = _ref4.className,
|
|
117
|
+
title = _ref4.title,
|
|
118
|
+
description = _ref4.description,
|
|
119
|
+
defaultTitle = _ref4.defaultTitle,
|
|
120
|
+
data = _ref4.data,
|
|
121
|
+
height = _ref4.height,
|
|
122
|
+
_ref4$emptyState = _ref4.emptyState,
|
|
123
|
+
emptyState = _ref4$emptyState === void 0 ? "No data to display" : _ref4$emptyState,
|
|
124
|
+
legend = _ref4.legend,
|
|
125
|
+
_ref4$accessibleTable = _ref4.accessibleTable,
|
|
126
|
+
accessibleTable = _ref4$accessibleTable === void 0 ? true : _ref4$accessibleTable,
|
|
127
|
+
tableColumns = _ref4.tableColumns,
|
|
128
|
+
children = _ref4.children,
|
|
129
|
+
ariaLabel = _ref4["aria-label"],
|
|
130
|
+
rest = _objectWithoutProperties(_ref4, _excluded);
|
|
131
|
+
var descriptionId = useId();
|
|
132
|
+
var name = title || ariaLabel || defaultTitle;
|
|
133
|
+
if (!Array.isArray(data) || data.length === 0) {
|
|
134
|
+
return jsx("div", _objectSpread2(_objectSpread2({
|
|
135
|
+
ref: ref,
|
|
136
|
+
className: cn("flex w-full items-center justify-center rounded-md border border-dashed border-gray-300 text-sm text-gray-500 dark:border-gray-700 dark:text-gray-400", className),
|
|
137
|
+
style: sizeStyle(height),
|
|
138
|
+
role: "status",
|
|
139
|
+
"aria-label": name,
|
|
140
|
+
"data-empty": "true"
|
|
141
|
+
}, rest), {}, {
|
|
142
|
+
children: emptyState
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
return jsxs("div", _objectSpread2(_objectSpread2({
|
|
146
|
+
ref: ref,
|
|
147
|
+
className: cn("w-full", className)
|
|
148
|
+
}, rest), {}, {
|
|
149
|
+
children: [jsx("div", {
|
|
150
|
+
role: "img",
|
|
151
|
+
"aria-label": name,
|
|
152
|
+
"aria-describedby": description ? descriptionId : undefined,
|
|
153
|
+
className: "w-full text-gray-500 dark:text-gray-400",
|
|
154
|
+
style: sizeStyle(height),
|
|
155
|
+
children: children
|
|
156
|
+
}), description && jsx("p", {
|
|
157
|
+
id: descriptionId,
|
|
158
|
+
className: "sr-only",
|
|
159
|
+
children: description
|
|
160
|
+
}), legend && legend.length > 0 && jsx(ChartLegend, {
|
|
161
|
+
items: legend
|
|
162
|
+
}), accessibleTable && jsx(ChartDataTable, {
|
|
163
|
+
caption: name,
|
|
164
|
+
columns: tableColumns,
|
|
165
|
+
rows: data
|
|
166
|
+
})]
|
|
167
|
+
}));
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
export { ChartFrame, ChartLegend, ChartTooltipContent };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { objectWithoutProperties as _objectWithoutProperties, objectSpread2 as _objectSpread2 } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
3
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { ResponsiveContainer, PieChart, Tooltip, Pie } from 'recharts';
|
|
6
|
+
import { ChartFrame, ChartTooltipContent } from './ChartFrame.js';
|
|
7
|
+
import { useChartTheme, useReducedMotion, defaultValueFormatter } from './chartTheme.js';
|
|
8
|
+
|
|
9
|
+
var _excluded = ["data", "index", "category", "colors", "valueFormatter", "variant", "innerRadius", "outerRadius", "centerLabel", "height", "showLegend", "showTooltip", "animate", "title", "description", "emptyState", "accessibleTable", "className"];
|
|
10
|
+
var DonutChart = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
11
|
+
var data = _ref.data,
|
|
12
|
+
_ref$index = _ref.index,
|
|
13
|
+
index = _ref$index === void 0 ? "name" : _ref$index,
|
|
14
|
+
_ref$category = _ref.category,
|
|
15
|
+
category = _ref$category === void 0 ? "value" : _ref$category,
|
|
16
|
+
colors = _ref.colors,
|
|
17
|
+
_ref$valueFormatter = _ref.valueFormatter,
|
|
18
|
+
valueFormatter = _ref$valueFormatter === void 0 ? defaultValueFormatter : _ref$valueFormatter,
|
|
19
|
+
_ref$variant = _ref.variant,
|
|
20
|
+
variant = _ref$variant === void 0 ? "donut" : _ref$variant,
|
|
21
|
+
_ref$innerRadius = _ref.innerRadius,
|
|
22
|
+
innerRadius = _ref$innerRadius === void 0 ? "60%" : _ref$innerRadius,
|
|
23
|
+
_ref$outerRadius = _ref.outerRadius,
|
|
24
|
+
outerRadius = _ref$outerRadius === void 0 ? "90%" : _ref$outerRadius,
|
|
25
|
+
centerLabel = _ref.centerLabel,
|
|
26
|
+
_ref$height = _ref.height,
|
|
27
|
+
height = _ref$height === void 0 ? 240 : _ref$height,
|
|
28
|
+
_ref$showLegend = _ref.showLegend,
|
|
29
|
+
showLegend = _ref$showLegend === void 0 ? true : _ref$showLegend,
|
|
30
|
+
_ref$showTooltip = _ref.showTooltip,
|
|
31
|
+
showTooltip = _ref$showTooltip === void 0 ? true : _ref$showTooltip,
|
|
32
|
+
_ref$animate = _ref.animate,
|
|
33
|
+
animate = _ref$animate === void 0 ? true : _ref$animate,
|
|
34
|
+
title = _ref.title,
|
|
35
|
+
description = _ref.description,
|
|
36
|
+
emptyState = _ref.emptyState,
|
|
37
|
+
_ref$accessibleTable = _ref.accessibleTable,
|
|
38
|
+
accessibleTable = _ref$accessibleTable === void 0 ? true : _ref$accessibleTable,
|
|
39
|
+
className = _ref.className,
|
|
40
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
41
|
+
var rows = Array.isArray(data) ? data : [];
|
|
42
|
+
var names = rows.map(function (row) {
|
|
43
|
+
return String(row[index]);
|
|
44
|
+
});
|
|
45
|
+
var _useChartTheme = useChartTheme(names, colors),
|
|
46
|
+
chrome = _useChartTheme.chrome,
|
|
47
|
+
series = _useChartTheme.series;
|
|
48
|
+
var reducedMotion = useReducedMotion();
|
|
49
|
+
var slices = rows.map(function (row, i) {
|
|
50
|
+
return _objectSpread2(_objectSpread2({}, row), {}, {
|
|
51
|
+
fill: series[i]
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
var isDonut = variant !== "pie";
|
|
55
|
+
return jsx(ChartFrame, _objectSpread2(_objectSpread2({
|
|
56
|
+
ref: ref,
|
|
57
|
+
className: className,
|
|
58
|
+
title: title,
|
|
59
|
+
description: description,
|
|
60
|
+
defaultTitle: isDonut ? "Donut chart" : "Pie chart",
|
|
61
|
+
data: data,
|
|
62
|
+
height: height,
|
|
63
|
+
emptyState: emptyState,
|
|
64
|
+
accessibleTable: accessibleTable,
|
|
65
|
+
legend: showLegend ? names.map(function (name, i) {
|
|
66
|
+
return {
|
|
67
|
+
name: name,
|
|
68
|
+
color: series[i]
|
|
69
|
+
};
|
|
70
|
+
}) : null,
|
|
71
|
+
tableColumns: [{
|
|
72
|
+
key: index,
|
|
73
|
+
label: index,
|
|
74
|
+
format: function format(v) {
|
|
75
|
+
return v == null ? "" : String(v);
|
|
76
|
+
}
|
|
77
|
+
}, {
|
|
78
|
+
key: category,
|
|
79
|
+
label: category,
|
|
80
|
+
format: valueFormatter
|
|
81
|
+
}]
|
|
82
|
+
}, rest), {}, {
|
|
83
|
+
children: jsxs("div", {
|
|
84
|
+
className: "relative h-full w-full",
|
|
85
|
+
children: [jsx(ResponsiveContainer, {
|
|
86
|
+
width: "100%",
|
|
87
|
+
height: "100%",
|
|
88
|
+
minWidth: 0,
|
|
89
|
+
children: jsxs(PieChart, {
|
|
90
|
+
accessibilityLayer: false,
|
|
91
|
+
children: [showTooltip && jsx(Tooltip, {
|
|
92
|
+
isAnimationActive: false,
|
|
93
|
+
content: jsx(ChartTooltipContent, {
|
|
94
|
+
valueFormatter: valueFormatter,
|
|
95
|
+
hideLabel: true
|
|
96
|
+
})
|
|
97
|
+
}), jsx(Pie, {
|
|
98
|
+
data: slices,
|
|
99
|
+
dataKey: category,
|
|
100
|
+
nameKey: index,
|
|
101
|
+
innerRadius: isDonut ? innerRadius : 0,
|
|
102
|
+
outerRadius: outerRadius,
|
|
103
|
+
paddingAngle: isDonut && rows.length > 1 ? 1 : 0,
|
|
104
|
+
stroke: chrome.surface,
|
|
105
|
+
strokeWidth: 2,
|
|
106
|
+
isAnimationActive: animate && !reducedMotion
|
|
107
|
+
})]
|
|
108
|
+
})
|
|
109
|
+
}), isDonut && centerLabel != null && jsx("div", {
|
|
110
|
+
className: "pointer-events-none absolute inset-0 flex items-center justify-center text-center text-sm font-semibold text-gray-900 dark:text-gray-100",
|
|
111
|
+
"aria-hidden": "true",
|
|
112
|
+
children: centerLabel
|
|
113
|
+
})]
|
|
114
|
+
})
|
|
115
|
+
}));
|
|
116
|
+
});
|
|
117
|
+
DonutChart.displayName = "DonutChart";
|
|
118
|
+
|
|
119
|
+
export { DonutChart as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { objectSpread2 as _objectSpread2 } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import CartesianChart from './CartesianChart.js';
|
|
6
|
+
|
|
7
|
+
var LineChart = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
8
|
+
return jsx(CartesianChart, _objectSpread2(_objectSpread2({
|
|
9
|
+
ref: ref
|
|
10
|
+
}, props), {}, {
|
|
11
|
+
kind: "line"
|
|
12
|
+
}));
|
|
13
|
+
});
|
|
14
|
+
LineChart.displayName = "LineChart";
|
|
15
|
+
|
|
16
|
+
export { LineChart as default };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { objectWithoutProperties as _objectWithoutProperties, objectSpread2 as _objectSpread2, toConsumableArray as _toConsumableArray } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
3
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { ResponsiveContainer, AreaChart, LineChart, YAxis, Tooltip, Area, Line } from 'recharts';
|
|
6
|
+
import { ChartFrame, ChartTooltipContent } from './ChartFrame.js';
|
|
7
|
+
import { useChartTheme, useReducedMotion, defaultValueFormatter } from './chartTheme.js';
|
|
8
|
+
|
|
9
|
+
var _excluded = ["data", "category", "index", "color", "type", "valueFormatter", "height", "showTooltip", "animate", "title", "description", "emptyState", "accessibleTable", "className"];
|
|
10
|
+
/** A word-sized trend line: no axes, grid or legend — just the shape of the data. */
|
|
11
|
+
var Sparkline = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
12
|
+
var data = _ref.data,
|
|
13
|
+
_ref$category = _ref.category,
|
|
14
|
+
category = _ref$category === void 0 ? "value" : _ref$category,
|
|
15
|
+
index = _ref.index,
|
|
16
|
+
_ref$color = _ref.color,
|
|
17
|
+
color = _ref$color === void 0 ? "primary" : _ref$color,
|
|
18
|
+
_ref$type = _ref.type,
|
|
19
|
+
type = _ref$type === void 0 ? "line" : _ref$type,
|
|
20
|
+
_ref$valueFormatter = _ref.valueFormatter,
|
|
21
|
+
valueFormatter = _ref$valueFormatter === void 0 ? defaultValueFormatter : _ref$valueFormatter,
|
|
22
|
+
_ref$height = _ref.height,
|
|
23
|
+
height = _ref$height === void 0 ? 40 : _ref$height,
|
|
24
|
+
_ref$showTooltip = _ref.showTooltip,
|
|
25
|
+
showTooltip = _ref$showTooltip === void 0 ? false : _ref$showTooltip,
|
|
26
|
+
_ref$animate = _ref.animate,
|
|
27
|
+
animate = _ref$animate === void 0 ? false : _ref$animate,
|
|
28
|
+
title = _ref.title,
|
|
29
|
+
description = _ref.description,
|
|
30
|
+
_ref$emptyState = _ref.emptyState,
|
|
31
|
+
emptyState = _ref$emptyState === void 0 ? "No data" : _ref$emptyState,
|
|
32
|
+
_ref$accessibleTable = _ref.accessibleTable,
|
|
33
|
+
accessibleTable = _ref$accessibleTable === void 0 ? true : _ref$accessibleTable,
|
|
34
|
+
className = _ref.className,
|
|
35
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
36
|
+
var _useChartTheme = useChartTheme([category], [color]),
|
|
37
|
+
series = _useChartTheme.series;
|
|
38
|
+
var reducedMotion = useReducedMotion();
|
|
39
|
+
var stroke = series[0];
|
|
40
|
+
var Root = type === "area" ? AreaChart : LineChart;
|
|
41
|
+
var common = {
|
|
42
|
+
dataKey: category,
|
|
43
|
+
name: category,
|
|
44
|
+
type: "monotone",
|
|
45
|
+
stroke: stroke,
|
|
46
|
+
strokeWidth: 2,
|
|
47
|
+
dot: false,
|
|
48
|
+
activeDot: showTooltip ? {
|
|
49
|
+
r: 3,
|
|
50
|
+
strokeWidth: 0,
|
|
51
|
+
fill: stroke
|
|
52
|
+
} : false,
|
|
53
|
+
isAnimationActive: animate && !reducedMotion
|
|
54
|
+
};
|
|
55
|
+
return jsx(ChartFrame, _objectSpread2(_objectSpread2({
|
|
56
|
+
ref: ref,
|
|
57
|
+
className: className,
|
|
58
|
+
title: title,
|
|
59
|
+
description: description,
|
|
60
|
+
defaultTitle: "Sparkline",
|
|
61
|
+
data: data,
|
|
62
|
+
height: height,
|
|
63
|
+
emptyState: emptyState,
|
|
64
|
+
accessibleTable: accessibleTable,
|
|
65
|
+
tableColumns: [].concat(_toConsumableArray(index ? [{
|
|
66
|
+
key: index,
|
|
67
|
+
label: index,
|
|
68
|
+
format: function format(v) {
|
|
69
|
+
return v == null ? "" : String(v);
|
|
70
|
+
}
|
|
71
|
+
}] : []), [{
|
|
72
|
+
key: category,
|
|
73
|
+
label: category,
|
|
74
|
+
format: valueFormatter
|
|
75
|
+
}])
|
|
76
|
+
}, rest), {}, {
|
|
77
|
+
children: jsx(ResponsiveContainer, {
|
|
78
|
+
width: "100%",
|
|
79
|
+
height: "100%",
|
|
80
|
+
minWidth: 0,
|
|
81
|
+
children: jsxs(Root, {
|
|
82
|
+
data: data,
|
|
83
|
+
margin: {
|
|
84
|
+
top: 2,
|
|
85
|
+
right: 2,
|
|
86
|
+
bottom: 2,
|
|
87
|
+
left: 2
|
|
88
|
+
},
|
|
89
|
+
accessibilityLayer: false,
|
|
90
|
+
children: [jsx(YAxis, {
|
|
91
|
+
hide: true,
|
|
92
|
+
domain: ["dataMin", "dataMax"]
|
|
93
|
+
}), showTooltip && jsx(Tooltip, {
|
|
94
|
+
isAnimationActive: false,
|
|
95
|
+
cursor: false,
|
|
96
|
+
content: jsx(ChartTooltipContent, {
|
|
97
|
+
valueFormatter: valueFormatter,
|
|
98
|
+
hideLabel: !index
|
|
99
|
+
})
|
|
100
|
+
}), type === "area" ? jsx(Area, _objectSpread2(_objectSpread2({}, common), {}, {
|
|
101
|
+
fill: stroke,
|
|
102
|
+
fillOpacity: 0.15
|
|
103
|
+
})) : jsx(Line, _objectSpread2({}, common))]
|
|
104
|
+
})
|
|
105
|
+
})
|
|
106
|
+
}));
|
|
107
|
+
});
|
|
108
|
+
Sparkline.displayName = "Sparkline";
|
|
109
|
+
|
|
110
|
+
export { Sparkline as default };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { slicedToArray as _slicedToArray } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
3
|
+
import { useState, useEffect } from 'react';
|
|
4
|
+
import { prefersReducedMotion } from '../../utils/position.js';
|
|
5
|
+
|
|
6
|
+
var CHART_PALETTES = ["primary", "secondary", "success", "warning", "error", "info", "gray"];
|
|
7
|
+
var DEFAULT_CHART_COLORS = ["primary", "success", "warning", "error", "info", "secondary", "gray"];
|
|
8
|
+
var TOKEN_RE = new RegExp("^(".concat(CHART_PALETTES.join("|"), ")(?:-(50|[1-9]00|950))?$"));
|
|
9
|
+
var CHROME_VARS = {
|
|
10
|
+
grid: "--dt-line",
|
|
11
|
+
axis: "--dt-muted",
|
|
12
|
+
surface: "--dt-surface",
|
|
13
|
+
text: "--dt-foreground"
|
|
14
|
+
};
|
|
15
|
+
/** `"primary"` → `"--dt-primary-500"`, `"error-300"` → `"--dt-error-300"`; null for anything else. */
|
|
16
|
+
function tokenVar(color) {
|
|
17
|
+
var m = TOKEN_RE.exec(String(color || ""));
|
|
18
|
+
return m ? "--dt-".concat(m[1], "-").concat(m[2] || "500") : null;
|
|
19
|
+
}
|
|
20
|
+
function readVar(name) {
|
|
21
|
+
if (typeof window === "undefined" || typeof window.getComputedStyle !== "function") return "";
|
|
22
|
+
return window.getComputedStyle(document.documentElement).getPropertyValue(name).trim();
|
|
23
|
+
}
|
|
24
|
+
// SVG presentation attributes do not resolve var() in every engine, so a token is
|
|
25
|
+
// turned into a concrete rgb() string when the browser can tell us its value. The
|
|
26
|
+
// var() form is the SSR / jsdom fallback.
|
|
27
|
+
function resolveVar(name) {
|
|
28
|
+
var value = readVar(name);
|
|
29
|
+
return value ? "rgb(".concat(value.split(/[\s,]+/).join(" "), ")") : "rgb(var(".concat(name, "))");
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A series colour: a palette token (`primary`, `success-600`, …) resolves to the
|
|
33
|
+
* matching `--dt-*` variable; any other string is treated as a CSS colour supplied
|
|
34
|
+
* by the consumer (e.g. a colour stored with the data).
|
|
35
|
+
*/
|
|
36
|
+
function resolveColor(color) {
|
|
37
|
+
var name = tokenVar(color);
|
|
38
|
+
return name ? resolveVar(name) : color;
|
|
39
|
+
}
|
|
40
|
+
function seriesColors(categories, colors) {
|
|
41
|
+
var palette = colors && colors.length ? colors : DEFAULT_CHART_COLORS;
|
|
42
|
+
return categories.map(function (_, i) {
|
|
43
|
+
return resolveColor(palette[i % palette.length]);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function readChrome() {
|
|
47
|
+
return Object.fromEntries(Object.entries(CHROME_VARS).map(function (_ref) {
|
|
48
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
49
|
+
k = _ref2[0],
|
|
50
|
+
v = _ref2[1];
|
|
51
|
+
return [k, resolveVar(v)];
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Chart chrome + series colours, re-read whenever the theme flips (the `dark`
|
|
56
|
+
* class or `data-theme` on <html>) so axes and series follow dark mode without
|
|
57
|
+
* a remount.
|
|
58
|
+
*/
|
|
59
|
+
function useChartTheme(categories, colors) {
|
|
60
|
+
var _useState = useState(0),
|
|
61
|
+
_useState2 = _slicedToArray(_useState, 2);
|
|
62
|
+
_useState2[0];
|
|
63
|
+
var setVersion = _useState2[1];
|
|
64
|
+
useEffect(function () {
|
|
65
|
+
if (typeof MutationObserver !== "function") return undefined;
|
|
66
|
+
var observer = new MutationObserver(function () {
|
|
67
|
+
return setVersion(function (v) {
|
|
68
|
+
return v + 1;
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
observer.observe(document.documentElement, {
|
|
72
|
+
attributes: true,
|
|
73
|
+
attributeFilter: ["class", "data-theme", "style"]
|
|
74
|
+
});
|
|
75
|
+
return function () {
|
|
76
|
+
return observer.disconnect();
|
|
77
|
+
};
|
|
78
|
+
}, []);
|
|
79
|
+
return {
|
|
80
|
+
chrome: readChrome(),
|
|
81
|
+
series: seriesColors(categories, colors)
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/** `true` while the user asks the OS for reduced motion; follows changes live. */
|
|
85
|
+
function useReducedMotion() {
|
|
86
|
+
var _useState3 = useState(prefersReducedMotion),
|
|
87
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
88
|
+
reduced = _useState4[0],
|
|
89
|
+
setReduced = _useState4[1];
|
|
90
|
+
useEffect(function () {
|
|
91
|
+
var _query$addEventListen;
|
|
92
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") return undefined;
|
|
93
|
+
var query = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
94
|
+
var update = function update() {
|
|
95
|
+
return setReduced(query.matches);
|
|
96
|
+
};
|
|
97
|
+
(_query$addEventListen = query.addEventListener) === null || _query$addEventListen === void 0 || _query$addEventListen.call(query, "change", update);
|
|
98
|
+
return function () {
|
|
99
|
+
var _query$removeEventLis;
|
|
100
|
+
return (_query$removeEventLis = query.removeEventListener) === null || _query$removeEventLis === void 0 ? void 0 : _query$removeEventLis.call(query, "change", update);
|
|
101
|
+
};
|
|
102
|
+
}, []);
|
|
103
|
+
return reduced;
|
|
104
|
+
}
|
|
105
|
+
var defaultValueFormatter = function defaultValueFormatter(value) {
|
|
106
|
+
return typeof value === "number" ? value.toLocaleString() : value == null ? "" : String(value);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export { CHART_PALETTES, DEFAULT_CHART_COLORS, defaultValueFormatter, resolveColor, seriesColors, tokenVar, useChartTheme, useReducedMotion };
|