@mbao01/common 0.0.44 → 0.0.46
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/dist/types/components/Chart/Chart.d.ts +2 -0
- package/dist/types/components/Chart/ChartContext.d.ts +2 -0
- package/dist/types/components/Chart/components/ChartLegend.d.ts +4 -0
- package/dist/types/components/Chart/components/ChartStyle.d.ts +2 -0
- package/dist/types/components/Chart/components/ChartTooltip.d.ts +4 -0
- package/dist/types/components/Chart/components/index.d.ts +3 -0
- package/dist/types/components/Chart/constants.d.ts +22 -0
- package/dist/types/components/Chart/helpers.d.ts +11 -0
- package/dist/types/components/Chart/hooks/index.d.ts +1 -0
- package/dist/types/components/Chart/hooks/useChart/index.d.ts +1 -0
- package/dist/types/components/Chart/hooks/useChart/useChart.d.ts +1 -0
- package/dist/types/components/Chart/index.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/activeShapeArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/animationArgs.d.ts +12 -0
- package/dist/types/components/Chart/stories/args/areaArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/areaChartArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/barArgs.d.ts +5 -0
- package/dist/types/components/Chart/stories/args/barChartArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/cartesianChartArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/cartesianSharedArgs.d.ts +11 -0
- package/dist/types/components/Chart/stories/args/chartArgs.d.ts +6 -0
- package/dist/types/components/Chart/stories/args/dotArgs.d.ts +10 -0
- package/dist/types/components/Chart/stories/args/events.d.ts +804 -0
- package/dist/types/components/Chart/stories/args/labelListArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/legendArgs.d.ts +3 -0
- package/dist/types/components/Chart/stories/args/lineArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/lineChartArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/pieArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/pieChartArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/polarChartArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/polarSharedArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/radarArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/radarChartArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/radialBarArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/radialBarChartArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/rectangleArgs.d.ts +9 -0
- package/dist/types/components/Chart/stories/args/referenceSharedArgs.d.ts +4 -0
- package/dist/types/components/Chart/stories/args/sectorArgs.d.ts +7 -0
- package/dist/types/components/Chart/stories/args/sharedAxisArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/stylesArgs.d.ts +6 -0
- package/dist/types/components/Chart/stories/args/textArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/tooltipArgs.d.ts +4 -0
- package/dist/types/components/Chart/stories/args/types.d.ts +13 -0
- package/dist/types/components/Chart/stories/args/xAxisArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/args/yAxisArgs.d.ts +2 -0
- package/dist/types/components/Chart/stories/examples/AreaChart.d.ts +16 -0
- package/dist/types/components/Chart/stories/examples/BarChart.d.ts +20 -0
- package/dist/types/components/Chart/stories/examples/LineChart.d.ts +16 -0
- package/dist/types/components/Chart/stories/examples/PieChart.d.ts +19 -0
- package/dist/types/components/Chart/stories/examples/RadarChart.d.ts +24 -0
- package/dist/types/components/Chart/stories/examples/RadialChart.d.ts +17 -0
- package/dist/types/components/Chart/stories/examples/Tooltip.d.ts +15 -0
- package/dist/types/components/Chart/stories/helpers/index.d.ts +9 -0
- package/dist/types/components/Chart/types.d.ts +37 -0
- package/dist/types/components/DragAndDrop/Draggable/Draggable.d.ts +29 -0
- package/dist/types/components/DragAndDrop/Draggable/Draggable.example.d.ts +24 -0
- package/dist/types/components/DragAndDrop/Draggable/constants.d.ts +9 -0
- package/dist/types/components/DragAndDrop/Draggable/index.d.ts +1 -0
- package/dist/types/components/DragAndDrop/Draggable/types.d.ts +41 -0
- package/dist/types/components/DragAndDrop/Droppable/Droppable.d.ts +2 -0
- package/dist/types/components/DragAndDrop/Droppable/Droppable.example.d.ts +10 -0
- package/dist/types/components/DragAndDrop/Droppable/constants.d.ts +5 -0
- package/dist/types/components/DragAndDrop/Droppable/index.d.ts +1 -0
- package/dist/types/components/DragAndDrop/Droppable/types.d.ts +4 -0
- package/dist/types/components/DragAndDrop/Sortable/Sortable.d.ts +2 -0
- package/dist/types/components/DragAndDrop/Sortable/Sortable.example.d.ts +6 -0
- package/dist/types/components/DragAndDrop/Sortable/constants.d.ts +4 -0
- package/dist/types/components/DragAndDrop/Sortable/index.d.ts +1 -0
- package/dist/types/components/DragAndDrop/Sortable/types.d.ts +7 -0
- package/dist/types/components/DragAndDrop/index.d.ts +3 -0
- package/dist/types/components/Widget/InternalWidgetsContext.d.ts +2 -0
- package/dist/types/components/Widget/Widget.d.ts +2 -0
- package/dist/types/components/Widget/Widgets.example.d.ts +1 -0
- package/dist/types/components/Widget/WidgetsContext.d.ts +2 -0
- package/dist/types/components/Widget/hooks/index.d.ts +2 -0
- package/dist/types/components/Widget/hooks/useWidget/index.d.ts +1 -0
- package/dist/types/components/Widget/hooks/useWidget/useWidget.d.ts +7 -0
- package/dist/types/components/Widget/hooks/useWidgets/index.d.ts +1 -0
- package/dist/types/components/Widget/hooks/useWidgets/useWidgets.d.ts +1 -0
- package/dist/types/components/Widget/index.d.ts +3 -0
- package/dist/types/components/Widget/modifiers/index.d.ts +1 -0
- package/dist/types/components/Widget/modifiers/restrictToElement.d.ts +2 -0
- package/dist/types/components/Widget/types.d.ts +28 -0
- package/package.json +9 -3
- package/src/components/Chart/Chart.tsx +26 -0
- package/src/components/Chart/ChartContext.tsx +4 -0
- package/src/components/Chart/components/ChartLegend.tsx +52 -0
- package/src/components/Chart/components/ChartStyle.tsx +32 -0
- package/src/components/Chart/components/ChartTooltip.tsx +126 -0
- package/src/components/Chart/components/index.ts +3 -0
- package/src/components/Chart/constants.ts +78 -0
- package/src/components/Chart/helpers.ts +27 -0
- package/src/components/Chart/hooks/index.ts +1 -0
- package/src/components/Chart/hooks/useChart/index.ts +1 -0
- package/src/components/Chart/hooks/useChart/useChart.ts +12 -0
- package/src/components/Chart/index.ts +2 -0
- package/src/components/Chart/stories/args/activeShapeArgs.ts +34 -0
- package/src/components/Chart/stories/args/animationArgs.ts +67 -0
- package/src/components/Chart/stories/args/areaArgs.ts +16 -0
- package/src/components/Chart/stories/args/areaChartArgs.ts +19 -0
- package/src/components/Chart/stories/args/barArgs.ts +123 -0
- package/src/components/Chart/stories/args/barChartArgs.ts +65 -0
- package/src/components/Chart/stories/args/cartesianChartArgs.ts +42 -0
- package/src/components/Chart/stories/args/cartesianSharedArgs.ts +136 -0
- package/src/components/Chart/stories/args/chartArgs.ts +244 -0
- package/src/components/Chart/stories/args/dotArgs.ts +46 -0
- package/src/components/Chart/stories/args/events.ts +343 -0
- package/src/components/Chart/stories/args/index.ts +178 -0
- package/src/components/Chart/stories/args/labelListArgs.ts +124 -0
- package/src/components/Chart/stories/args/legendArgs.ts +205 -0
- package/src/components/Chart/stories/args/lineArgs.ts +87 -0
- package/src/components/Chart/stories/args/lineChartArgs.ts +17 -0
- package/src/components/Chart/stories/args/pieArgs.ts +18 -0
- package/src/components/Chart/stories/args/pieChartArgs.ts +7 -0
- package/src/components/Chart/stories/args/polarChartArgs.ts +86 -0
- package/src/components/Chart/stories/args/polarSharedArgs.ts +42 -0
- package/src/components/Chart/stories/args/radarArgs.ts +26 -0
- package/src/components/Chart/stories/args/radarChartArgs.ts +26 -0
- package/src/components/Chart/stories/args/radialBarArgs.ts +36 -0
- package/src/components/Chart/stories/args/radialBarChartArgs.ts +16 -0
- package/src/components/Chart/stories/args/rectangleArgs.ts +35 -0
- package/src/components/Chart/stories/args/referenceSharedArgs.ts +75 -0
- package/src/components/Chart/stories/args/sectorArgs.ts +106 -0
- package/src/components/Chart/stories/args/sharedAxisArgs.ts +332 -0
- package/src/components/Chart/stories/args/stylesArgs.ts +258 -0
- package/src/components/Chart/stories/args/textArgs.ts +97 -0
- package/src/components/Chart/stories/args/tooltipArgs.ts +41 -0
- package/src/components/Chart/stories/args/types.ts +23 -0
- package/src/components/Chart/stories/args/xAxisArgs.ts +109 -0
- package/src/components/Chart/stories/args/yAxisArgs.ts +73 -0
- package/src/components/Chart/stories/examples/AreaChart.tsx +156 -0
- package/src/components/Chart/stories/examples/BarChart.tsx +425 -0
- package/src/components/Chart/stories/examples/LineChart.tsx +144 -0
- package/src/components/Chart/stories/examples/PieChart.tsx +238 -0
- package/src/components/Chart/stories/examples/RadarChart.tsx +261 -0
- package/src/components/Chart/stories/examples/RadialChart.tsx +239 -0
- package/src/components/Chart/stories/examples/Tooltip.tsx +68 -0
- package/src/components/Chart/stories/helpers/index.tsx +75 -0
- package/src/components/Chart/types.ts +39 -0
- package/src/components/DragAndDrop/Draggable/Draggable.example.tsx +147 -0
- package/src/components/DragAndDrop/Draggable/Draggable.tsx +161 -0
- package/src/components/DragAndDrop/Draggable/constants.ts +47 -0
- package/src/components/DragAndDrop/Draggable/index.ts +1 -0
- package/src/components/DragAndDrop/Draggable/types.ts +56 -0
- package/src/components/DragAndDrop/Droppable/Droppable.example.tsx +86 -0
- package/src/components/DragAndDrop/Droppable/Droppable.tsx +38 -0
- package/src/components/DragAndDrop/Droppable/constants.ts +15 -0
- package/src/components/DragAndDrop/Droppable/index.ts +1 -0
- package/src/components/DragAndDrop/Droppable/types.ts +7 -0
- package/src/components/DragAndDrop/Sortable/Sortable.example.tsx +61 -0
- package/src/components/DragAndDrop/Sortable/Sortable.tsx +65 -0
- package/src/components/DragAndDrop/Sortable/constants.ts +12 -0
- package/src/components/DragAndDrop/Sortable/index.ts +1 -0
- package/src/components/DragAndDrop/Sortable/types.ts +11 -0
- package/src/components/DragAndDrop/index.ts +3 -0
- package/src/components/Widget/InternalWidgetsContext.tsx +4 -0
- package/src/components/Widget/Widget.tsx +17 -0
- package/src/components/Widget/Widgets.example.tsx +118 -0
- package/src/components/Widget/WidgetsContext.tsx +97 -0
- package/src/components/Widget/hooks/index.ts +2 -0
- package/src/components/Widget/hooks/useWidget/index.ts +1 -0
- package/src/components/Widget/hooks/useWidget/useWidget.ts +21 -0
- package/src/components/Widget/hooks/useWidgets/index.ts +1 -0
- package/src/components/Widget/hooks/useWidgets/useWidgets.ts +12 -0
- package/src/components/Widget/index.ts +3 -0
- package/src/components/Widget/modifiers/index.ts +1 -0
- package/src/components/Widget/modifiers/restrictToElement.ts +8 -0
- package/src/components/Widget/types.ts +30 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mbao01/common",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.46",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Ayomide Bakare",
|
|
7
7
|
"license": "MIT",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"dev": "storybook dev -p 6006",
|
|
54
54
|
"build": "tsc && vite build",
|
|
55
55
|
"build-storybook": "storybook build -o ../../docs/storybook/common",
|
|
56
|
-
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings
|
|
56
|
+
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 30",
|
|
57
57
|
"prettier": "prettier --check \"**/*.{ts,tsx}\"",
|
|
58
58
|
"prettier:write": "prettier --write \"**/*.{ts,tsx}\"",
|
|
59
59
|
"preview": "vite preview",
|
|
@@ -68,6 +68,10 @@
|
|
|
68
68
|
"test:watch": "vitest"
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
+
"@dnd-kit/core": "^6.1.0",
|
|
72
|
+
"@dnd-kit/modifiers": "^7.0.0",
|
|
73
|
+
"@dnd-kit/sortable": "^8.0.0",
|
|
74
|
+
"@dnd-kit/utilities": "^3.2.2",
|
|
71
75
|
"@radix-ui/react-accordion": "^1.2.0",
|
|
72
76
|
"@radix-ui/react-alert-dialog": "^1.1.1",
|
|
73
77
|
"@radix-ui/react-avatar": "^1.1.0",
|
|
@@ -102,6 +106,7 @@
|
|
|
102
106
|
"react-dropzone": "^14.2.3",
|
|
103
107
|
"react-international-phone": "^4.3.0",
|
|
104
108
|
"react-otp-input": "^3.1.1",
|
|
109
|
+
"recharts": "^2.12.7",
|
|
105
110
|
"sonner": "^1.5.0",
|
|
106
111
|
"tailwind-merge": "^2.5.2",
|
|
107
112
|
"tailwindcss-animate": "^1.0.7",
|
|
@@ -116,6 +121,7 @@
|
|
|
116
121
|
"@storybook/addon-interactions": "^8.3.4",
|
|
117
122
|
"@storybook/addon-links": "^8.3.4",
|
|
118
123
|
"@storybook/addon-onboarding": "^8.3.4",
|
|
124
|
+
"@storybook/addon-storysource": "^8.3.4",
|
|
119
125
|
"@storybook/addon-themes": "^8.3.4",
|
|
120
126
|
"@storybook/addon-viewport": "^8.3.4",
|
|
121
127
|
"@storybook/blocks": "^8.3.4",
|
|
@@ -165,5 +171,5 @@
|
|
|
165
171
|
"react-dom": "^18.2.0",
|
|
166
172
|
"typescript": "^5.2.2"
|
|
167
173
|
},
|
|
168
|
-
"gitHead": "
|
|
174
|
+
"gitHead": "541e3f7084b5e39d30b3ce90140ede22d75e1889"
|
|
169
175
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { forwardRef, useId } from "react";
|
|
4
|
+
import { ResponsiveContainer } from "recharts";
|
|
5
|
+
import { cn } from "../../utilities";
|
|
6
|
+
import { ChartContext } from "./ChartContext";
|
|
7
|
+
import { ChartStyle } from "./components";
|
|
8
|
+
import { getChartClasses } from "./constants";
|
|
9
|
+
import { type ChartProps } from "./types";
|
|
10
|
+
|
|
11
|
+
export const Chart = forwardRef<HTMLDivElement, ChartProps>(
|
|
12
|
+
({ id, className, children, config, ...props }, ref) => {
|
|
13
|
+
const uniqueId = useId();
|
|
14
|
+
const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`;
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<ChartContext.Provider value={{ config }}>
|
|
18
|
+
<div ref={ref} data-chart={chartId} className={cn(getChartClasses(), className)} {...props}>
|
|
19
|
+
<ChartStyle id={chartId} config={config} />
|
|
20
|
+
<ResponsiveContainer>{children}</ResponsiveContainer>
|
|
21
|
+
</div>
|
|
22
|
+
</ChartContext.Provider>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
Chart.displayName = "Chart";
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { forwardRef } from "react";
|
|
4
|
+
import { Legend } from "recharts";
|
|
5
|
+
import type { ChartLegendContentProps } from "../types";
|
|
6
|
+
import { cn } from "../../../utilities";
|
|
7
|
+
import {
|
|
8
|
+
getChartLegendContainerClasses,
|
|
9
|
+
getChartLegendItemClasses,
|
|
10
|
+
getChartLegendMarkerClasses,
|
|
11
|
+
} from "../constants";
|
|
12
|
+
import { getPayloadConfigFromPayload } from "../helpers";
|
|
13
|
+
import { useChart } from "../hooks";
|
|
14
|
+
|
|
15
|
+
export const ChartLegend = Legend;
|
|
16
|
+
ChartLegend.displayName = "ChartLegend";
|
|
17
|
+
|
|
18
|
+
export const ChartLegendContent = forwardRef<HTMLDivElement, ChartLegendContentProps>(
|
|
19
|
+
({ className, hideIcon = false, payload, verticalAlign = "bottom", nameKey }, ref) => {
|
|
20
|
+
const { config } = useChart();
|
|
21
|
+
|
|
22
|
+
if (!payload?.length) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<div ref={ref} className={cn(getChartLegendContainerClasses({ verticalAlign }), className)}>
|
|
28
|
+
{payload.map((item) => {
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
30
|
+
const key = `${nameKey || item.dataKey || "value"}`;
|
|
31
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
35
|
+
<div key={item.value} className={getChartLegendItemClasses()}>
|
|
36
|
+
{itemConfig?.icon && !hideIcon ? (
|
|
37
|
+
<itemConfig.icon />
|
|
38
|
+
) : (
|
|
39
|
+
<div
|
|
40
|
+
style={{ backgroundColor: item.color }}
|
|
41
|
+
className={getChartLegendMarkerClasses()}
|
|
42
|
+
/>
|
|
43
|
+
)}
|
|
44
|
+
{itemConfig?.label}
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
})}
|
|
48
|
+
</div>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
ChartLegendContent.displayName = "ChartLegendContent";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type Theme } from "../../../utilities";
|
|
2
|
+
import { THEMES } from "../constants";
|
|
3
|
+
import { type ChartStyleProps } from "../types";
|
|
4
|
+
|
|
5
|
+
export const ChartStyle = ({ id, config }: ChartStyleProps) => {
|
|
6
|
+
const colorConfig = Object.entries(config).filter(([, config]) => config.theme || config.color);
|
|
7
|
+
|
|
8
|
+
if (!colorConfig.length) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<style
|
|
14
|
+
dangerouslySetInnerHTML={{
|
|
15
|
+
__html: Object.entries(THEMES)
|
|
16
|
+
.map(
|
|
17
|
+
([theme, prefix]) => `
|
|
18
|
+
${prefix} [data-chart=${id}] {
|
|
19
|
+
${colorConfig
|
|
20
|
+
.map(([key, itemConfig]) => {
|
|
21
|
+
const color = itemConfig.theme?.[theme as Theme] || itemConfig.color;
|
|
22
|
+
return color ? ` --color-${key}: ${color};` : null;
|
|
23
|
+
})
|
|
24
|
+
.join("\n")}
|
|
25
|
+
}
|
|
26
|
+
`
|
|
27
|
+
)
|
|
28
|
+
.join("\n"),
|
|
29
|
+
}}
|
|
30
|
+
/>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { forwardRef, useMemo } from "react";
|
|
4
|
+
import { Tooltip } from "recharts";
|
|
5
|
+
import type { ChartTooltipContentProps } from "../types";
|
|
6
|
+
import { cn } from "../../../utilities";
|
|
7
|
+
import {
|
|
8
|
+
getChartTooltipContainerClasses,
|
|
9
|
+
getChartTooltipItemClasses,
|
|
10
|
+
getChartTooltipItemIndicatorClasses,
|
|
11
|
+
getChartTooltipItemLabelClasses,
|
|
12
|
+
getChartTooltipItemValueClasses,
|
|
13
|
+
} from "../constants";
|
|
14
|
+
import { getPayloadConfigFromPayload } from "../helpers";
|
|
15
|
+
import { useChart } from "../hooks";
|
|
16
|
+
|
|
17
|
+
export const ChartTooltip = Tooltip;
|
|
18
|
+
ChartTooltip.displayName = "ChartTooltip";
|
|
19
|
+
|
|
20
|
+
export const ChartTooltipContent = forwardRef<HTMLDivElement, ChartTooltipContentProps>(
|
|
21
|
+
(
|
|
22
|
+
{
|
|
23
|
+
active,
|
|
24
|
+
payload,
|
|
25
|
+
className,
|
|
26
|
+
indicator = "dot",
|
|
27
|
+
hideLabel = false,
|
|
28
|
+
hideIndicator = false,
|
|
29
|
+
label,
|
|
30
|
+
labelFormatter,
|
|
31
|
+
labelClassName,
|
|
32
|
+
formatter,
|
|
33
|
+
color,
|
|
34
|
+
nameKey,
|
|
35
|
+
labelKey,
|
|
36
|
+
},
|
|
37
|
+
ref
|
|
38
|
+
) => {
|
|
39
|
+
const { config } = useChart();
|
|
40
|
+
|
|
41
|
+
const tooltipLabel = useMemo(() => {
|
|
42
|
+
if (hideLabel || !payload?.length) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const [item] = payload;
|
|
47
|
+
const key = `${labelKey || item.dataKey || item.name || "value"}`;
|
|
48
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
49
|
+
const value =
|
|
50
|
+
!labelKey && typeof label === "string" ? config[label]?.label || label : itemConfig?.label;
|
|
51
|
+
|
|
52
|
+
if (labelFormatter) {
|
|
53
|
+
return (
|
|
54
|
+
<div className={cn("font-medium", labelClassName)}>{labelFormatter(value, payload)}</div>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (!value) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return <div className={cn("font-medium", labelClassName)}>{value}</div>;
|
|
63
|
+
}, [label, labelFormatter, payload, hideLabel, labelClassName, config, labelKey]);
|
|
64
|
+
|
|
65
|
+
if (!active || !payload?.length) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const nestLabel = payload.length === 1 && indicator !== "dot";
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<div ref={ref} className={cn(getChartTooltipContainerClasses(), className)}>
|
|
73
|
+
{!nestLabel ? tooltipLabel : null}
|
|
74
|
+
<div className="grid gap-1.5">
|
|
75
|
+
{payload.map((item, index) => {
|
|
76
|
+
const key = `${nameKey || item.name || item.dataKey || "value"}`;
|
|
77
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
78
|
+
const indicatorColor =
|
|
79
|
+
color ||
|
|
80
|
+
(item.payload as { fill: string }).fill ||
|
|
81
|
+
item.color ||
|
|
82
|
+
(item as { fill: string }).fill;
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<div key={item.dataKey} className={getChartTooltipItemClasses({ indicator })}>
|
|
86
|
+
{formatter && item?.value !== undefined && item.name ? (
|
|
87
|
+
formatter(item.value, item.name, item, index, payload)
|
|
88
|
+
) : (
|
|
89
|
+
<>
|
|
90
|
+
{itemConfig?.icon ? (
|
|
91
|
+
<itemConfig.icon />
|
|
92
|
+
) : (
|
|
93
|
+
!hideIndicator && (
|
|
94
|
+
<div
|
|
95
|
+
className={getChartTooltipItemIndicatorClasses({ indicator, nestLabel })}
|
|
96
|
+
style={
|
|
97
|
+
{
|
|
98
|
+
"--color-bg": indicatorColor,
|
|
99
|
+
"--color-border": indicatorColor,
|
|
100
|
+
} as React.CSSProperties
|
|
101
|
+
}
|
|
102
|
+
/>
|
|
103
|
+
)
|
|
104
|
+
)}
|
|
105
|
+
<div className={getChartTooltipItemLabelClasses({ nestLabel })}>
|
|
106
|
+
<div className="grid gap-1.5">
|
|
107
|
+
{nestLabel ? tooltipLabel : null}
|
|
108
|
+
<span>{itemConfig?.label || item.name}</span>
|
|
109
|
+
</div>
|
|
110
|
+
{item.value && (
|
|
111
|
+
<span className={getChartTooltipItemValueClasses()}>
|
|
112
|
+
{item.value.toLocaleString()}
|
|
113
|
+
</span>
|
|
114
|
+
)}
|
|
115
|
+
</div>
|
|
116
|
+
</>
|
|
117
|
+
)}
|
|
118
|
+
</div>
|
|
119
|
+
);
|
|
120
|
+
})}
|
|
121
|
+
</div>
|
|
122
|
+
</div>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
);
|
|
126
|
+
ChartTooltipContent.displayName = "ChartTooltipContent";
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { Theme } from "../../utilities";
|
|
2
|
+
import { cva } from "../../libs";
|
|
3
|
+
|
|
4
|
+
export const THEMES = {
|
|
5
|
+
light: "",
|
|
6
|
+
dark: ".dark",
|
|
7
|
+
} satisfies Record<Theme, string>;
|
|
8
|
+
|
|
9
|
+
export const getChartClasses = cva(
|
|
10
|
+
"flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-base-content [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-base-content/20 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-base-content/20 [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-none [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-base-content/20 [&_.recharts-radial-bar-background-sector]:fill-base-200 [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-base-200 [&_.recharts-reference-line_[stroke='#ccc']]:stroke-base-content/20 [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-sector]:outline-none [&_.recharts-surface]:outline-none"
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
export const getChartLegendContainerClasses = cva("flex items-center justify-center gap-4", {
|
|
14
|
+
variants: {
|
|
15
|
+
verticalAlign: {
|
|
16
|
+
top: "pb-3",
|
|
17
|
+
bottom: "pt-3",
|
|
18
|
+
middle: "",
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export const getChartLegendItemClasses = cva("flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3");
|
|
24
|
+
|
|
25
|
+
export const getChartLegendMarkerClasses = cva("h-2 w-2 shrink-0 rounded-[2px]");
|
|
26
|
+
|
|
27
|
+
export const getChartTooltipContainerClasses = cva(
|
|
28
|
+
"grid min-w-[8rem] items-start gap-1.5 rounded-md border border-border/50 bg-base-100 px-2.5 py-1.5 text-xs shadow-xl"
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
export const getChartTooltipItemClasses = cva(
|
|
32
|
+
"flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-base-content",
|
|
33
|
+
{
|
|
34
|
+
variants: {
|
|
35
|
+
indicator: {
|
|
36
|
+
dot: "items-center",
|
|
37
|
+
line: "",
|
|
38
|
+
dashed: "",
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
export const getChartTooltipItemLabelClasses = cva(
|
|
45
|
+
"flex flex-1 justify-between leading-none items-center",
|
|
46
|
+
{
|
|
47
|
+
variants: {
|
|
48
|
+
nestLabel: {
|
|
49
|
+
true: "items-end",
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
export const getChartTooltipItemValueClasses = cva("font-mono font-medium tabular-nums");
|
|
56
|
+
|
|
57
|
+
export const getChartTooltipItemIndicatorClasses = cva(
|
|
58
|
+
"shrink-0 rounded-[2px] border-[--color-border] bg-[--color-bg]",
|
|
59
|
+
{
|
|
60
|
+
variants: {
|
|
61
|
+
indicator: {
|
|
62
|
+
dot: "h-2.5 w-2.5",
|
|
63
|
+
line: "w-1",
|
|
64
|
+
dashed: "w-0 border-[1.5px] border-dashed bg-transparent",
|
|
65
|
+
},
|
|
66
|
+
nestLabel: {
|
|
67
|
+
true: "",
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
compoundVariants: [
|
|
71
|
+
{
|
|
72
|
+
indicator: "dashed",
|
|
73
|
+
nestLabel: true,
|
|
74
|
+
className: "my-0.5",
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
}
|
|
78
|
+
);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ChartConfig } from "./types";
|
|
2
|
+
|
|
3
|
+
// Helper to extract item config from a payload.
|
|
4
|
+
export const getPayloadConfigFromPayload = (config: ChartConfig, payload: unknown, key: string) => {
|
|
5
|
+
if (typeof payload !== "object" || payload === null) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const payloadPayload =
|
|
10
|
+
"payload" in payload && typeof payload.payload === "object" && payload.payload !== null
|
|
11
|
+
? payload.payload
|
|
12
|
+
: undefined;
|
|
13
|
+
|
|
14
|
+
let configLabelKey: string = key;
|
|
15
|
+
|
|
16
|
+
if (key in payload && typeof payload[key as keyof typeof payload] === "string") {
|
|
17
|
+
configLabelKey = payload[key as keyof typeof payload] as string;
|
|
18
|
+
} else if (
|
|
19
|
+
payloadPayload &&
|
|
20
|
+
key in payloadPayload &&
|
|
21
|
+
typeof payloadPayload[key as keyof typeof payloadPayload] === "string"
|
|
22
|
+
) {
|
|
23
|
+
configLabelKey = payloadPayload[key as keyof typeof payloadPayload] as string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return configLabelKey in config ? config[configLabelKey] : config[key];
|
|
27
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useChart } from "./useChart";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useChart } from "./useChart";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { ChartContext } from "../../ChartContext";
|
|
3
|
+
|
|
4
|
+
export const useChart = () => {
|
|
5
|
+
const context = useContext(ChartContext);
|
|
6
|
+
|
|
7
|
+
if (!context) {
|
|
8
|
+
throw new Error("useChart must be used within a <Chart />");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return context;
|
|
12
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ArgTypes } from "@storybook/react";
|
|
2
|
+
|
|
3
|
+
export const activeShapeArgs: ArgTypes = {
|
|
4
|
+
activeIndex: {
|
|
5
|
+
description:
|
|
6
|
+
"The index of the individual shapes of the graph element to be marked as active, and render props.activeShape",
|
|
7
|
+
table: {
|
|
8
|
+
category: "General",
|
|
9
|
+
},
|
|
10
|
+
control: "number",
|
|
11
|
+
},
|
|
12
|
+
shape: {
|
|
13
|
+
description: "The customized shape to be rendered.",
|
|
14
|
+
table: {
|
|
15
|
+
type: {
|
|
16
|
+
summary: "Function | boolean | ReactElement | object",
|
|
17
|
+
},
|
|
18
|
+
defaultValue: undefined,
|
|
19
|
+
category: "General",
|
|
20
|
+
},
|
|
21
|
+
control: "object",
|
|
22
|
+
},
|
|
23
|
+
activeShape: {
|
|
24
|
+
description: "The customized shape to be rendered if activeIndex or activeTooltipIndex match",
|
|
25
|
+
table: {
|
|
26
|
+
type: {
|
|
27
|
+
summary: "Function | boolean | ReactElement | object",
|
|
28
|
+
},
|
|
29
|
+
defaultValue: undefined,
|
|
30
|
+
category: "General",
|
|
31
|
+
},
|
|
32
|
+
control: "object",
|
|
33
|
+
},
|
|
34
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file both exports the documentation of shared props separately, to be reused in places where only single props
|
|
3
|
+
* are documented, as well as grouped in case a whole group is needed.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { type ArgTypes } from "@storybook/react";
|
|
7
|
+
|
|
8
|
+
export const animateNewValues: ArgTypes[0] = { table: { category: "Animation" } };
|
|
9
|
+
export const animationBegin: ArgTypes[0] = {
|
|
10
|
+
description: "Specifies when the animation should begin, the unit of this option is ms.",
|
|
11
|
+
type: { name: "number" },
|
|
12
|
+
table: {
|
|
13
|
+
defaultValue: {
|
|
14
|
+
summary: "0",
|
|
15
|
+
},
|
|
16
|
+
category: "Animation",
|
|
17
|
+
},
|
|
18
|
+
control: "number",
|
|
19
|
+
};
|
|
20
|
+
export const animationDuration: ArgTypes[0] = {
|
|
21
|
+
description: "Specifies the duration of animation, the unit of this option is ms.",
|
|
22
|
+
table: {
|
|
23
|
+
type: {
|
|
24
|
+
summary: "number",
|
|
25
|
+
},
|
|
26
|
+
category: "Animation",
|
|
27
|
+
},
|
|
28
|
+
control: "number",
|
|
29
|
+
};
|
|
30
|
+
export const animationEasing: ArgTypes[0] = {
|
|
31
|
+
description: "The type of easing function.",
|
|
32
|
+
table: {
|
|
33
|
+
type: {
|
|
34
|
+
summary: "'ease' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'linear'",
|
|
35
|
+
},
|
|
36
|
+
category: "Animation",
|
|
37
|
+
},
|
|
38
|
+
control: "select",
|
|
39
|
+
options: ["ease", "ease-in", "ease-out", "ease-in-out", "linear"],
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const isAnimationActive: ArgTypes[0] = {
|
|
43
|
+
description:
|
|
44
|
+
"If set false, animation of component will be disabled. This is `true` in CSR, and `false` in SSR",
|
|
45
|
+
table: {
|
|
46
|
+
type: {
|
|
47
|
+
summary: "boolean",
|
|
48
|
+
},
|
|
49
|
+
defaultValue: {
|
|
50
|
+
detail: "true in CSR, and false in SSR",
|
|
51
|
+
},
|
|
52
|
+
category: "Animation",
|
|
53
|
+
},
|
|
54
|
+
control: "boolean",
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Caveat: If any prop is added here, it would falsely be add to the documentation of the component where this group
|
|
59
|
+
* is used. If the group is to be extended, then only single props should be imported by each component that does not
|
|
60
|
+
* use all of them.
|
|
61
|
+
* */
|
|
62
|
+
export const animationArgs: ArgTypes = {
|
|
63
|
+
animationBegin,
|
|
64
|
+
animationEasing,
|
|
65
|
+
animationDuration,
|
|
66
|
+
isAnimationActive,
|
|
67
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Args } from "@storybook/react";
|
|
2
|
+
import { lineArgs } from "./lineArgs";
|
|
3
|
+
|
|
4
|
+
export const areaArgs: Args = {
|
|
5
|
+
...lineArgs,
|
|
6
|
+
fillOpacity: {
|
|
7
|
+
description: "The opacity of the fill.",
|
|
8
|
+
table: {
|
|
9
|
+
type: {
|
|
10
|
+
summary: "number",
|
|
11
|
+
},
|
|
12
|
+
category: "Style",
|
|
13
|
+
},
|
|
14
|
+
control: "number",
|
|
15
|
+
},
|
|
16
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type ArgTypes } from "@storybook/react";
|
|
2
|
+
import { cartesianChartArgs } from "./cartesianChartArgs";
|
|
3
|
+
|
|
4
|
+
export const areaChartArgs: ArgTypes = {
|
|
5
|
+
...cartesianChartArgs,
|
|
6
|
+
baseValue: {
|
|
7
|
+
description: "The base value of area.",
|
|
8
|
+
table: {
|
|
9
|
+
type: {
|
|
10
|
+
summary: "number | 'dataMin' | 'dataMax' | 'auto'",
|
|
11
|
+
},
|
|
12
|
+
defaultValue: {
|
|
13
|
+
summary: "'auto'",
|
|
14
|
+
},
|
|
15
|
+
category: "Area",
|
|
16
|
+
},
|
|
17
|
+
control: "text",
|
|
18
|
+
},
|
|
19
|
+
};
|