@dreamtree-org/twreact-ui 1.3.1 → 1.3.3
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 +90 -5
- package/ai-skills/dreamtree-ui.md +43 -4
- package/bin/cli.mjs +72 -4
- package/charts/package.json +5 -0
- package/dist/_shared/cn-DPPQUJu1.js +138 -0
- package/dist/ai-schema.json +639 -1
- package/dist/charts/index.d.ts +9 -0
- package/dist/charts/index.d.ts.map +1 -0
- package/dist/charts/index.js +797 -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 +36 -0
- package/dist/components/charts/chartTheme.d.ts.map +1 -0
- package/dist/components/core/Table/MobileCard.d.ts.map +1 -1
- package/dist/components/core/Table/MobileFilters.d.ts.map +1 -1
- package/dist/components/core/Table/Table.d.ts.map +1 -1
- 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/components/utility/Stepper.d.ts.map +1 -1
- package/dist/esm/charts/index.js +5 -0
- package/dist/esm/components/blocks/StatCard.js +1 -1
- 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 +255 -0
- package/dist/esm/components/charts/ChartFrame.js +170 -0
- package/dist/esm/components/charts/DonutChart.js +122 -0
- package/dist/esm/components/charts/LineChart.js +16 -0
- package/dist/esm/components/charts/Sparkline.js +113 -0
- package/dist/esm/components/charts/chartTheme.js +126 -0
- package/dist/esm/components/core/Select.js +2 -2
- package/dist/esm/components/core/Table/MobileCard.js +5 -2
- package/dist/esm/components/core/Table/MobileFilters.js +10 -3
- package/dist/esm/components/core/Table/Table.js +10 -7
- package/dist/esm/components/rich-text/RichTextEditor.js +244 -0
- package/dist/esm/components/rich-text/RichTextToolbar.js +397 -0
- package/dist/esm/components/utility/Stepper.js +6 -4
- 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 +50 -22
- package/dist/index.js +50 -22
- 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/practicepro.json +1 -0
- package/dist/tokens/brands/studio.css +14 -0
- package/dist/tokens/brands/studio.json +21 -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 +1016 -10
- package/mcp/server-core.mjs +30 -1
- package/package.json +39 -2
- package/rich-text/package.json +5 -0
- package/tokens/brand.schema.json +612 -0
- package/tokens/brands/practicepro.json +1 -0
- package/tokens/brands/studio.json +21 -0
- package/tokens/lib.cjs +131 -7
|
@@ -0,0 +1,255 @@
|
|
|
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, BarChart, LineChart, CartesianGrid, XAxis, YAxis, Tooltip, Bar, Area, Line } from 'recharts';
|
|
6
|
+
import { ChartFrame, ChartTooltipContent } from './ChartFrame.js';
|
|
7
|
+
import { useChartTheme, useReducedMotion, useChartId, defaultValueFormatter } from './chartTheme.js';
|
|
8
|
+
|
|
9
|
+
var _excluded = ["kind", "data", "index", "categories", "colors", "valueFormatter", "xAxisFormatter", "height", "showLegend", "showTooltip", "showXAxis", "showYAxis", "showGrid", "yAxisWidth", "curveType", "stacked", "horizontal", "showDots", "connectNulls", "animate", "title", "description", "emptyState", "accessibleTable", "className"];
|
|
10
|
+
var ROOTS = {
|
|
11
|
+
line: LineChart,
|
|
12
|
+
bar: BarChart,
|
|
13
|
+
area: AreaChart
|
|
14
|
+
};
|
|
15
|
+
var TITLES = {
|
|
16
|
+
line: "Line chart",
|
|
17
|
+
bar: "Bar chart",
|
|
18
|
+
area: "Area chart"
|
|
19
|
+
};
|
|
20
|
+
var CURVES = {
|
|
21
|
+
linear: "linear",
|
|
22
|
+
monotone: "monotone",
|
|
23
|
+
step: "step",
|
|
24
|
+
natural: "natural"
|
|
25
|
+
};
|
|
26
|
+
function renderSeries(kind, _ref) {
|
|
27
|
+
var id = _ref.id,
|
|
28
|
+
category = _ref.category,
|
|
29
|
+
color = _ref.color,
|
|
30
|
+
curve = _ref.curve,
|
|
31
|
+
stacked = _ref.stacked,
|
|
32
|
+
showDots = _ref.showDots,
|
|
33
|
+
connectNulls = _ref.connectNulls,
|
|
34
|
+
animate = _ref.animate,
|
|
35
|
+
horizontal = _ref.horizontal,
|
|
36
|
+
barRadius = _ref.barRadius;
|
|
37
|
+
var common = {
|
|
38
|
+
id: id,
|
|
39
|
+
dataKey: category,
|
|
40
|
+
name: category,
|
|
41
|
+
isAnimationActive: animate
|
|
42
|
+
};
|
|
43
|
+
if (kind === "bar") {
|
|
44
|
+
var radius = horizontal ? [0, barRadius, barRadius, 0] : [barRadius, barRadius, 0, 0];
|
|
45
|
+
return jsx(Bar, _objectSpread2(_objectSpread2({}, common), {}, {
|
|
46
|
+
fill: color,
|
|
47
|
+
stackId: stacked ? "stack" : undefined,
|
|
48
|
+
radius: stacked ? 0 : radius,
|
|
49
|
+
maxBarSize: 48
|
|
50
|
+
}), category);
|
|
51
|
+
}
|
|
52
|
+
if (kind === "area") {
|
|
53
|
+
return jsx(Area, _objectSpread2(_objectSpread2({}, common), {}, {
|
|
54
|
+
type: curve,
|
|
55
|
+
stroke: color,
|
|
56
|
+
fill: color,
|
|
57
|
+
fillOpacity: stacked ? 0.4 : 0.15,
|
|
58
|
+
strokeWidth: 2,
|
|
59
|
+
stackId: stacked ? "stack" : undefined,
|
|
60
|
+
dot: showDots ? {
|
|
61
|
+
r: 3,
|
|
62
|
+
fill: color,
|
|
63
|
+
strokeWidth: 0
|
|
64
|
+
} : false,
|
|
65
|
+
activeDot: {
|
|
66
|
+
r: 4,
|
|
67
|
+
strokeWidth: 0,
|
|
68
|
+
fill: color
|
|
69
|
+
},
|
|
70
|
+
connectNulls: connectNulls
|
|
71
|
+
}), category);
|
|
72
|
+
}
|
|
73
|
+
return jsx(Line, _objectSpread2(_objectSpread2({}, common), {}, {
|
|
74
|
+
type: curve,
|
|
75
|
+
stroke: color,
|
|
76
|
+
strokeWidth: 2,
|
|
77
|
+
dot: showDots ? {
|
|
78
|
+
r: 3,
|
|
79
|
+
fill: color,
|
|
80
|
+
strokeWidth: 0
|
|
81
|
+
} : false,
|
|
82
|
+
activeDot: {
|
|
83
|
+
r: 4,
|
|
84
|
+
strokeWidth: 0,
|
|
85
|
+
fill: color
|
|
86
|
+
},
|
|
87
|
+
connectNulls: connectNulls
|
|
88
|
+
}), category);
|
|
89
|
+
}
|
|
90
|
+
/** Shared implementation of LineChart / BarChart / AreaChart. */
|
|
91
|
+
var CartesianChart = /*#__PURE__*/React.forwardRef(function CartesianChart(_ref2, ref) {
|
|
92
|
+
var kind = _ref2.kind,
|
|
93
|
+
data = _ref2.data,
|
|
94
|
+
index = _ref2.index,
|
|
95
|
+
_ref2$categories = _ref2.categories,
|
|
96
|
+
categories = _ref2$categories === void 0 ? [] : _ref2$categories,
|
|
97
|
+
colors = _ref2.colors,
|
|
98
|
+
_ref2$valueFormatter = _ref2.valueFormatter,
|
|
99
|
+
valueFormatter = _ref2$valueFormatter === void 0 ? defaultValueFormatter : _ref2$valueFormatter,
|
|
100
|
+
xAxisFormatter = _ref2.xAxisFormatter,
|
|
101
|
+
_ref2$height = _ref2.height,
|
|
102
|
+
height = _ref2$height === void 0 ? 300 : _ref2$height,
|
|
103
|
+
_ref2$showLegend = _ref2.showLegend,
|
|
104
|
+
showLegend = _ref2$showLegend === void 0 ? true : _ref2$showLegend,
|
|
105
|
+
_ref2$showTooltip = _ref2.showTooltip,
|
|
106
|
+
showTooltip = _ref2$showTooltip === void 0 ? true : _ref2$showTooltip,
|
|
107
|
+
_ref2$showXAxis = _ref2.showXAxis,
|
|
108
|
+
showXAxis = _ref2$showXAxis === void 0 ? true : _ref2$showXAxis,
|
|
109
|
+
_ref2$showYAxis = _ref2.showYAxis,
|
|
110
|
+
showYAxis = _ref2$showYAxis === void 0 ? true : _ref2$showYAxis,
|
|
111
|
+
_ref2$showGrid = _ref2.showGrid,
|
|
112
|
+
showGrid = _ref2$showGrid === void 0 ? true : _ref2$showGrid,
|
|
113
|
+
_ref2$yAxisWidth = _ref2.yAxisWidth,
|
|
114
|
+
yAxisWidth = _ref2$yAxisWidth === void 0 ? 48 : _ref2$yAxisWidth,
|
|
115
|
+
_ref2$curveType = _ref2.curveType,
|
|
116
|
+
curveType = _ref2$curveType === void 0 ? "monotone" : _ref2$curveType,
|
|
117
|
+
_ref2$stacked = _ref2.stacked,
|
|
118
|
+
stacked = _ref2$stacked === void 0 ? false : _ref2$stacked,
|
|
119
|
+
_ref2$horizontal = _ref2.horizontal,
|
|
120
|
+
horizontal = _ref2$horizontal === void 0 ? false : _ref2$horizontal,
|
|
121
|
+
_ref2$showDots = _ref2.showDots,
|
|
122
|
+
showDots = _ref2$showDots === void 0 ? false : _ref2$showDots,
|
|
123
|
+
_ref2$connectNulls = _ref2.connectNulls,
|
|
124
|
+
connectNulls = _ref2$connectNulls === void 0 ? false : _ref2$connectNulls,
|
|
125
|
+
_ref2$animate = _ref2.animate,
|
|
126
|
+
animate = _ref2$animate === void 0 ? true : _ref2$animate,
|
|
127
|
+
title = _ref2.title,
|
|
128
|
+
description = _ref2.description,
|
|
129
|
+
emptyState = _ref2.emptyState,
|
|
130
|
+
_ref2$accessibleTable = _ref2.accessibleTable,
|
|
131
|
+
accessibleTable = _ref2$accessibleTable === void 0 ? true : _ref2$accessibleTable,
|
|
132
|
+
className = _ref2.className,
|
|
133
|
+
rest = _objectWithoutProperties(_ref2, _excluded);
|
|
134
|
+
var _useChartTheme = useChartTheme(categories, colors),
|
|
135
|
+
chrome = _useChartTheme.chrome,
|
|
136
|
+
series = _useChartTheme.series;
|
|
137
|
+
var reducedMotion = useReducedMotion();
|
|
138
|
+
var chartId = useChartId();
|
|
139
|
+
var Root = ROOTS[kind];
|
|
140
|
+
var isHorizontalBars = kind === "bar" && horizontal;
|
|
141
|
+
var curve = CURVES[curveType] || "monotone";
|
|
142
|
+
var tick = {
|
|
143
|
+
fill: chrome.axis,
|
|
144
|
+
fontSize: 12
|
|
145
|
+
};
|
|
146
|
+
var formatIndex = xAxisFormatter || function (v) {
|
|
147
|
+
return v == null ? "" : String(v);
|
|
148
|
+
};
|
|
149
|
+
var categoryAxis = {
|
|
150
|
+
dataKey: index,
|
|
151
|
+
tick: tick,
|
|
152
|
+
tickLine: false,
|
|
153
|
+
axisLine: false,
|
|
154
|
+
tickFormatter: xAxisFormatter,
|
|
155
|
+
hide: !showXAxis,
|
|
156
|
+
minTickGap: 8
|
|
157
|
+
};
|
|
158
|
+
var valueAxis = {
|
|
159
|
+
tick: tick,
|
|
160
|
+
tickLine: false,
|
|
161
|
+
axisLine: false,
|
|
162
|
+
tickFormatter: valueFormatter,
|
|
163
|
+
hide: !showYAxis,
|
|
164
|
+
width: yAxisWidth
|
|
165
|
+
};
|
|
166
|
+
return jsx(ChartFrame, _objectSpread2(_objectSpread2({
|
|
167
|
+
ref: ref,
|
|
168
|
+
className: className,
|
|
169
|
+
title: title,
|
|
170
|
+
description: description,
|
|
171
|
+
defaultTitle: TITLES[kind],
|
|
172
|
+
data: data,
|
|
173
|
+
height: height,
|
|
174
|
+
emptyState: emptyState,
|
|
175
|
+
accessibleTable: accessibleTable,
|
|
176
|
+
legend: showLegend ? categories.map(function (c, i) {
|
|
177
|
+
return {
|
|
178
|
+
name: c,
|
|
179
|
+
color: series[i]
|
|
180
|
+
};
|
|
181
|
+
}) : null,
|
|
182
|
+
tableColumns: [{
|
|
183
|
+
key: index,
|
|
184
|
+
label: index,
|
|
185
|
+
format: formatIndex
|
|
186
|
+
}].concat(_toConsumableArray(categories.map(function (c) {
|
|
187
|
+
return {
|
|
188
|
+
key: c,
|
|
189
|
+
label: c,
|
|
190
|
+
format: valueFormatter
|
|
191
|
+
};
|
|
192
|
+
})))
|
|
193
|
+
}, rest), {}, {
|
|
194
|
+
children: jsx(ResponsiveContainer, {
|
|
195
|
+
width: "100%",
|
|
196
|
+
height: "100%",
|
|
197
|
+
minWidth: 0,
|
|
198
|
+
children: jsxs(Root, {
|
|
199
|
+
id: chartId,
|
|
200
|
+
data: data,
|
|
201
|
+
layout: isHorizontalBars ? "vertical" : "horizontal",
|
|
202
|
+
margin: {
|
|
203
|
+
top: 8,
|
|
204
|
+
right: 8,
|
|
205
|
+
bottom: 0,
|
|
206
|
+
left: 0
|
|
207
|
+
},
|
|
208
|
+
accessibilityLayer: false,
|
|
209
|
+
children: [showGrid && jsx(CartesianGrid, {
|
|
210
|
+
stroke: chrome.grid,
|
|
211
|
+
strokeDasharray: "3 3",
|
|
212
|
+
vertical: isHorizontalBars,
|
|
213
|
+
horizontal: !isHorizontalBars
|
|
214
|
+
}), isHorizontalBars ? jsx(XAxis, _objectSpread2(_objectSpread2({
|
|
215
|
+
type: "number"
|
|
216
|
+
}, valueAxis), {}, {
|
|
217
|
+
hide: !showXAxis,
|
|
218
|
+
width: undefined
|
|
219
|
+
})) : jsx(XAxis, _objectSpread2({}, categoryAxis)), isHorizontalBars ? jsx(YAxis, _objectSpread2(_objectSpread2({
|
|
220
|
+
type: "category"
|
|
221
|
+
}, categoryAxis), {}, {
|
|
222
|
+
hide: !showYAxis,
|
|
223
|
+
width: yAxisWidth,
|
|
224
|
+
interval: 0
|
|
225
|
+
})) : jsx(YAxis, _objectSpread2({}, valueAxis)), showTooltip && jsx(Tooltip, {
|
|
226
|
+
cursor: kind === "bar" ? {
|
|
227
|
+
fill: chrome.grid,
|
|
228
|
+
fillOpacity: 0.4
|
|
229
|
+
} : {
|
|
230
|
+
stroke: chrome.grid
|
|
231
|
+
},
|
|
232
|
+
isAnimationActive: false,
|
|
233
|
+
content: jsx(ChartTooltipContent, {
|
|
234
|
+
valueFormatter: valueFormatter
|
|
235
|
+
})
|
|
236
|
+
}), categories.map(function (category, i) {
|
|
237
|
+
return renderSeries(kind, {
|
|
238
|
+
id: "".concat(chartId, "-").concat(i),
|
|
239
|
+
category: category,
|
|
240
|
+
color: series[i],
|
|
241
|
+
curve: curve,
|
|
242
|
+
stacked: stacked,
|
|
243
|
+
showDots: showDots,
|
|
244
|
+
connectNulls: connectNulls,
|
|
245
|
+
animate: animate && !reducedMotion,
|
|
246
|
+
horizontal: isHorizontalBars,
|
|
247
|
+
barRadius: 4
|
|
248
|
+
});
|
|
249
|
+
})]
|
|
250
|
+
})
|
|
251
|
+
})
|
|
252
|
+
}));
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
export { CartesianChart as default };
|
|
@@ -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,122 @@
|
|
|
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, useChartId, 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 chartId = useChartId();
|
|
50
|
+
var slices = rows.map(function (row, i) {
|
|
51
|
+
return _objectSpread2(_objectSpread2({}, row), {}, {
|
|
52
|
+
fill: series[i]
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
var isDonut = variant !== "pie";
|
|
56
|
+
return jsx(ChartFrame, _objectSpread2(_objectSpread2({
|
|
57
|
+
ref: ref,
|
|
58
|
+
className: className,
|
|
59
|
+
title: title,
|
|
60
|
+
description: description,
|
|
61
|
+
defaultTitle: isDonut ? "Donut chart" : "Pie chart",
|
|
62
|
+
data: data,
|
|
63
|
+
height: height,
|
|
64
|
+
emptyState: emptyState,
|
|
65
|
+
accessibleTable: accessibleTable,
|
|
66
|
+
legend: showLegend ? names.map(function (name, i) {
|
|
67
|
+
return {
|
|
68
|
+
name: name,
|
|
69
|
+
color: series[i]
|
|
70
|
+
};
|
|
71
|
+
}) : null,
|
|
72
|
+
tableColumns: [{
|
|
73
|
+
key: index,
|
|
74
|
+
label: index,
|
|
75
|
+
format: function format(v) {
|
|
76
|
+
return v == null ? "" : String(v);
|
|
77
|
+
}
|
|
78
|
+
}, {
|
|
79
|
+
key: category,
|
|
80
|
+
label: category,
|
|
81
|
+
format: valueFormatter
|
|
82
|
+
}]
|
|
83
|
+
}, rest), {}, {
|
|
84
|
+
children: jsxs("div", {
|
|
85
|
+
className: "relative h-full w-full",
|
|
86
|
+
children: [jsx(ResponsiveContainer, {
|
|
87
|
+
width: "100%",
|
|
88
|
+
height: "100%",
|
|
89
|
+
minWidth: 0,
|
|
90
|
+
children: jsxs(PieChart, {
|
|
91
|
+
id: chartId,
|
|
92
|
+
accessibilityLayer: false,
|
|
93
|
+
children: [showTooltip && jsx(Tooltip, {
|
|
94
|
+
isAnimationActive: false,
|
|
95
|
+
content: jsx(ChartTooltipContent, {
|
|
96
|
+
valueFormatter: valueFormatter,
|
|
97
|
+
hideLabel: true
|
|
98
|
+
})
|
|
99
|
+
}), jsx(Pie, {
|
|
100
|
+
id: "".concat(chartId, "-0"),
|
|
101
|
+
data: slices,
|
|
102
|
+
dataKey: category,
|
|
103
|
+
nameKey: index,
|
|
104
|
+
innerRadius: isDonut ? innerRadius : 0,
|
|
105
|
+
outerRadius: outerRadius,
|
|
106
|
+
paddingAngle: isDonut && rows.length > 1 ? 1 : 0,
|
|
107
|
+
stroke: chrome.surface,
|
|
108
|
+
strokeWidth: 2,
|
|
109
|
+
isAnimationActive: animate && !reducedMotion
|
|
110
|
+
})]
|
|
111
|
+
})
|
|
112
|
+
}), isDonut && centerLabel != null && jsx("div", {
|
|
113
|
+
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",
|
|
114
|
+
"aria-hidden": "true",
|
|
115
|
+
children: centerLabel
|
|
116
|
+
})]
|
|
117
|
+
})
|
|
118
|
+
}));
|
|
119
|
+
});
|
|
120
|
+
DonutChart.displayName = "DonutChart";
|
|
121
|
+
|
|
122
|
+
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,113 @@
|
|
|
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, useChartId, 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 chartId = useChartId();
|
|
40
|
+
var stroke = series[0];
|
|
41
|
+
var Root = type === "area" ? AreaChart : LineChart;
|
|
42
|
+
var common = {
|
|
43
|
+
id: "".concat(chartId, "-0"),
|
|
44
|
+
dataKey: category,
|
|
45
|
+
name: category,
|
|
46
|
+
type: "monotone",
|
|
47
|
+
stroke: stroke,
|
|
48
|
+
strokeWidth: 2,
|
|
49
|
+
dot: false,
|
|
50
|
+
activeDot: showTooltip ? {
|
|
51
|
+
r: 3,
|
|
52
|
+
strokeWidth: 0,
|
|
53
|
+
fill: stroke
|
|
54
|
+
} : false,
|
|
55
|
+
isAnimationActive: animate && !reducedMotion
|
|
56
|
+
};
|
|
57
|
+
return jsx(ChartFrame, _objectSpread2(_objectSpread2({
|
|
58
|
+
ref: ref,
|
|
59
|
+
className: className,
|
|
60
|
+
title: title,
|
|
61
|
+
description: description,
|
|
62
|
+
defaultTitle: "Sparkline",
|
|
63
|
+
data: data,
|
|
64
|
+
height: height,
|
|
65
|
+
emptyState: emptyState,
|
|
66
|
+
accessibleTable: accessibleTable,
|
|
67
|
+
tableColumns: [].concat(_toConsumableArray(index ? [{
|
|
68
|
+
key: index,
|
|
69
|
+
label: index,
|
|
70
|
+
format: function format(v) {
|
|
71
|
+
return v == null ? "" : String(v);
|
|
72
|
+
}
|
|
73
|
+
}] : []), [{
|
|
74
|
+
key: category,
|
|
75
|
+
label: category,
|
|
76
|
+
format: valueFormatter
|
|
77
|
+
}])
|
|
78
|
+
}, rest), {}, {
|
|
79
|
+
children: jsx(ResponsiveContainer, {
|
|
80
|
+
width: "100%",
|
|
81
|
+
height: "100%",
|
|
82
|
+
minWidth: 0,
|
|
83
|
+
children: jsxs(Root, {
|
|
84
|
+
id: chartId,
|
|
85
|
+
data: data,
|
|
86
|
+
margin: {
|
|
87
|
+
top: 2,
|
|
88
|
+
right: 2,
|
|
89
|
+
bottom: 2,
|
|
90
|
+
left: 2
|
|
91
|
+
},
|
|
92
|
+
accessibilityLayer: false,
|
|
93
|
+
children: [jsx(YAxis, {
|
|
94
|
+
hide: true,
|
|
95
|
+
domain: ["dataMin", "dataMax"]
|
|
96
|
+
}), showTooltip && jsx(Tooltip, {
|
|
97
|
+
isAnimationActive: false,
|
|
98
|
+
cursor: false,
|
|
99
|
+
content: jsx(ChartTooltipContent, {
|
|
100
|
+
valueFormatter: valueFormatter,
|
|
101
|
+
hideLabel: !index
|
|
102
|
+
})
|
|
103
|
+
}), type === "area" ? jsx(Area, _objectSpread2(_objectSpread2({}, common), {}, {
|
|
104
|
+
fill: stroke,
|
|
105
|
+
fillOpacity: 0.15
|
|
106
|
+
})) : jsx(Line, _objectSpread2({}, common))]
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
}));
|
|
110
|
+
});
|
|
111
|
+
Sparkline.displayName = "Sparkline";
|
|
112
|
+
|
|
113
|
+
export { Sparkline as default };
|