@appcorp/shadcn 1.1.8 → 1.1.11

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,19 @@
1
1
  import * as React from "react";
2
2
  interface ChartDataItem {
3
3
  date: string;
4
- desktop: number;
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
+ locale?: string;
16
+ onSelectorChange: (value: string) => void;
16
17
  }
17
- export declare const AreaChartV1: ({ dates, description, title, selectors, }: AreaChartV1Props) => React.JSX.Element;
18
+ export declare const AreaChartV1: ({ dates, description, legends, title, selectors, locale, onSelectorChange, }: AreaChartV1Props) => React.JSX.Element;
18
19
  export {};
@@ -40,71 +40,74 @@ 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
- var chartConfig = {
44
- visitors: {
45
- label: "Visitors",
46
- },
47
- desktop: {
48
- label: "Desktop",
49
- color: "var(--chart-1)",
50
- },
51
- mobile: {
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;
58
- var _b = React.useState("90d"), timeRange = _b[0], setTimeRange = _b[1];
59
- var filteredData = dates.filter(function (item) {
60
- var date = new Date(item.date);
61
- var referenceDate = new Date("2024-06-30");
62
- var daysToSubtract = 90;
63
- if (timeRange === "30d") {
64
- daysToSubtract = 30;
65
- }
66
- else if (timeRange === "7d") {
67
- daysToSubtract = 7;
68
- }
54
+ var dates = _a.dates, description = _a.description, legends = _a.legends, title = _a.title, selectors = _a.selectors, _b = _a.locale, locale = _b === void 0 ? "en-US" : _b, onSelectorChange = _a.onSelectorChange;
55
+ var _c = React.useState("90d"), timeRange = _c[0], setTimeRange = _c[1];
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(startDate.getDate() - daysToSubtract);
71
- return date >= startDate;
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: setTimeRange },
79
- React.createElement(select_1.SelectTrigger, { className: "hidden w-[160px] rounded-lg sm:ml-auto sm:flex", "aria-label": "Select a value" },
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, { onClick: function (f) { return selector.handleSelector(f); }, key: selector.label, value: selector.value }, selector.label)); })))),
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: chartConfig, className: "aspect-auto h-[250px] w-full" },
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
- React.createElement("linearGradient", { id: "fillDesktop", x1: "0", y1: "0", x2: "0", y2: "1" },
87
- React.createElement("stop", { offset: "5%", stopColor: "var(--color-desktop)", stopOpacity: 0.8 }),
88
- React.createElement("stop", { offset: "95%", stopColor: "var(--color-desktop)", stopOpacity: 0.1 })),
89
- React.createElement("linearGradient", { id: "fillMobile", x1: "0", y1: "0", x2: "0", y2: "1" },
90
- React.createElement("stop", { offset: "5%", stopColor: "var(--color-mobile)", stopOpacity: 0.8 }),
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);
95
- return date.toLocaleDateString("en-US", {
96
+ return date.toLocaleDateString(locale, {
96
97
  month: "short",
97
98
  day: "numeric",
98
99
  });
99
100
  } }),
100
101
  React.createElement(chart_1.ChartTooltip, { cursor: false, content: React.createElement(chart_1.ChartTooltipContent, { labelFormatter: function (value) {
101
- return new Date(value).toLocaleDateString("en-US", {
102
+ return new Date(value).toLocaleDateString(locale, {
102
103
  month: "short",
103
104
  day: "numeric",
104
105
  });
105
106
  }, indicator: "dot" }) }),
106
- React.createElement(recharts_1.Area, { dataKey: "mobile", type: "natural", fill: "url(#fillMobile)", stroke: "var(--color-mobile)", stackId: "a" }),
107
- React.createElement(recharts_1.Area, { dataKey: "desktop", type: "natural", fill: "url(#fillDesktop)", stroke: "var(--color-desktop)", stackId: "a" }),
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/shadcn",
3
- "version": "1.1.8",
3
+ "version": "1.1.11",
4
4
  "scripts": {
5
5
  "build:next": "next build",
6
6
  "build:storybook": "storybook build -c .storybook -o .out",