@appcorp/shadcn 1.1.8 → 1.1.9
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.
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
interface ChartDataItem {
|
|
3
3
|
date: string;
|
|
4
|
-
|
|
5
|
-
mobile: number;
|
|
4
|
+
[key: string]: number | string;
|
|
6
5
|
}
|
|
7
6
|
export interface AreaChartV1Props {
|
|
8
7
|
dates: ChartDataItem[];
|
|
9
8
|
description: string;
|
|
9
|
+
legends: string[];
|
|
10
10
|
title: string;
|
|
11
11
|
selectors: {
|
|
12
12
|
label: string;
|
|
13
13
|
value: string;
|
|
14
|
-
handleSelector: (f: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
|
|
15
14
|
}[];
|
|
15
|
+
onSelectorChange: (value: string) => void;
|
|
16
16
|
}
|
|
17
|
-
export declare const AreaChartV1: ({ dates, description, title, selectors, }: AreaChartV1Props) => React.JSX.Element;
|
|
17
|
+
export declare const AreaChartV1: ({ dates, description, legends, title, selectors, onSelectorChange, }: AreaChartV1Props) => React.JSX.Element;
|
|
18
18
|
export {};
|
|
@@ -40,55 +40,56 @@ var recharts_1 = require("recharts");
|
|
|
40
40
|
var card_1 = require("../../components/ui/card");
|
|
41
41
|
var chart_1 = require("../../components/ui/chart");
|
|
42
42
|
var select_1 = require("../../components/ui/select");
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
label: "Mobile",
|
|
53
|
-
color: "var(--chart-2)",
|
|
54
|
-
},
|
|
43
|
+
// Utility function to create ChartConfig from legends array
|
|
44
|
+
var createChartConfig = function (legends) {
|
|
45
|
+
return legends.reduce(function (acc, legend, index) {
|
|
46
|
+
acc[legend.toLowerCase()] = {
|
|
47
|
+
label: legend,
|
|
48
|
+
color: "var(--chart-".concat(index + 1, ")"),
|
|
49
|
+
};
|
|
50
|
+
return acc;
|
|
51
|
+
}, {});
|
|
55
52
|
};
|
|
56
53
|
var AreaChartV1 = function (_a) {
|
|
57
|
-
var dates = _a.dates, description = _a.description, title = _a.title, selectors = _a.selectors;
|
|
54
|
+
var dates = _a.dates, description = _a.description, legends = _a.legends, title = _a.title, selectors = _a.selectors, onSelectorChange = _a.onSelectorChange;
|
|
58
55
|
var _b = React.useState("90d"), timeRange = _b[0], setTimeRange = _b[1];
|
|
59
|
-
var
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
56
|
+
var dynamicChartConfig = createChartConfig(legends);
|
|
57
|
+
var handleValueChange = function (value) {
|
|
58
|
+
setTimeRange(value);
|
|
59
|
+
onSelectorChange(value);
|
|
60
|
+
};
|
|
61
|
+
var filteredData = React.useMemo(function () {
|
|
62
|
+
var _a;
|
|
63
|
+
var daysMap = {
|
|
64
|
+
"7d": 7,
|
|
65
|
+
"30d": 30,
|
|
66
|
+
"90d": 90,
|
|
67
|
+
};
|
|
68
|
+
var daysToSubtract = (_a = daysMap[timeRange]) !== null && _a !== void 0 ? _a : 90;
|
|
69
|
+
var referenceDate = new Date(dates[dates.length - 1].date);
|
|
69
70
|
var startDate = new Date(referenceDate);
|
|
70
|
-
startDate.setDate(
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
startDate.setDate(referenceDate.getDate() - daysToSubtract);
|
|
72
|
+
var startTime = startDate.getTime();
|
|
73
|
+
return dates.filter(function (item) { return new Date(item.date).getTime() >= startTime; });
|
|
74
|
+
}, [dates, timeRange]);
|
|
73
75
|
return (React.createElement(card_1.Card, { className: "pt-0" },
|
|
74
76
|
React.createElement(card_1.CardHeader, { className: "flex items-center gap-2 space-y-0 border-b py-5 sm:flex-row" },
|
|
75
77
|
React.createElement("div", { className: "grid flex-1 gap-1" },
|
|
76
78
|
React.createElement(card_1.CardTitle, null, title),
|
|
77
79
|
React.createElement(card_1.CardDescription, null, description)),
|
|
78
|
-
React.createElement(select_1.Select, { value: timeRange, onValueChange:
|
|
79
|
-
React.createElement(select_1.SelectTrigger, { className: "hidden w-
|
|
80
|
+
React.createElement(select_1.Select, { value: timeRange, onValueChange: handleValueChange },
|
|
81
|
+
React.createElement(select_1.SelectTrigger, { className: "hidden w-40 rounded-lg sm:ml-auto sm:flex", "aria-label": "Select a value" },
|
|
80
82
|
React.createElement(select_1.SelectValue, { placeholder: "Last 3 months" })),
|
|
81
|
-
React.createElement(select_1.SelectContent, { className: "rounded-xl" }, selectors.map(function (selector) { return (React.createElement(select_1.SelectItem, {
|
|
83
|
+
React.createElement(select_1.SelectContent, { className: "rounded-xl" }, selectors.map(function (selector) { return (React.createElement(select_1.SelectItem, { key: selector.label, value: selector.value }, selector.label)); })))),
|
|
82
84
|
React.createElement(card_1.CardContent, { className: "px-2 pt-4 sm:px-6 sm:pt-6" },
|
|
83
|
-
React.createElement(chart_1.ChartContainer, { config:
|
|
85
|
+
React.createElement(chart_1.ChartContainer, { config: dynamicChartConfig, className: "aspect-auto h-[250px] w-full" },
|
|
84
86
|
React.createElement(recharts_1.AreaChart, { data: filteredData },
|
|
85
|
-
React.createElement("defs", null,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
React.createElement("stop", { offset: "
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
React.createElement("stop", { offset: "95%", stopColor: "var(--color-mobile)", stopOpacity: 0.1 }))),
|
|
87
|
+
React.createElement("defs", null, legends.map(function (legend) {
|
|
88
|
+
var key = legend.toLowerCase();
|
|
89
|
+
return (React.createElement("linearGradient", { key: key, id: "fill".concat(legend), x1: "0", y1: "0", x2: "0", y2: "1" },
|
|
90
|
+
React.createElement("stop", { offset: "5%", stopColor: "var(--color-".concat(key, ")"), stopOpacity: 0.8 }),
|
|
91
|
+
React.createElement("stop", { offset: "95%", stopColor: "var(--color-".concat(key, ")"), stopOpacity: 0.1 })));
|
|
92
|
+
})),
|
|
92
93
|
React.createElement(recharts_1.CartesianGrid, { vertical: false }),
|
|
93
94
|
React.createElement(recharts_1.XAxis, { dataKey: "date", tickLine: false, axisLine: false, tickMargin: 8, minTickGap: 32, tickFormatter: function (value) {
|
|
94
95
|
var date = new Date(value);
|
|
@@ -103,8 +104,10 @@ var AreaChartV1 = function (_a) {
|
|
|
103
104
|
day: "numeric",
|
|
104
105
|
});
|
|
105
106
|
}, indicator: "dot" }) }),
|
|
106
|
-
|
|
107
|
-
|
|
107
|
+
legends.map(function (legend) {
|
|
108
|
+
var key = legend.toLowerCase();
|
|
109
|
+
return (React.createElement(recharts_1.Area, { key: key, dataKey: key, type: "natural", fill: "url(#fill".concat(legend, ")"), stroke: "var(--color-".concat(key, ")"), stackId: "a" }));
|
|
110
|
+
}),
|
|
108
111
|
React.createElement(chart_1.ChartLegend, { content: React.createElement(chart_1.ChartLegendContent, null) }))))));
|
|
109
112
|
};
|
|
110
113
|
exports.AreaChartV1 = AreaChartV1;
|