@shipfox/react-ui 0.16.0 → 0.18.0
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/components/card/card.d.ts +24 -0
- package/dist/components/card/card.js +56 -0
- package/dist/components/card/card.stories.js +216 -0
- package/dist/components/card/index.d.ts +2 -0
- package/dist/components/card/index.js +3 -0
- package/dist/components/count-up/count-up.d.ts +14 -0
- package/dist/components/count-up/count-up.js +98 -0
- package/dist/components/count-up/count-up.stories.js +568 -0
- package/dist/components/count-up/index.d.ts +2 -0
- package/dist/components/count-up/index.js +3 -0
- package/dist/components/dashboard/components/charts/bar-chart.d.ts +8 -17
- package/dist/components/dashboard/components/charts/bar-chart.js +127 -81
- package/dist/components/dashboard/components/charts/bar-chart.stories.js +287 -0
- package/dist/components/dashboard/components/charts/chart-tooltip.js +13 -12
- package/dist/components/dashboard/components/charts/colors.d.ts +3 -2
- package/dist/components/dashboard/components/charts/colors.js +5 -2
- package/dist/components/dashboard/components/charts/index.d.ts +1 -0
- package/dist/components/dashboard/components/charts/index.js +1 -0
- package/dist/components/dashboard/components/charts/line-chart.d.ts +7 -16
- package/dist/components/dashboard/components/charts/line-chart.js +132 -108
- package/dist/components/dashboard/components/charts/line-chart.stories.js +257 -0
- package/dist/components/dashboard/components/charts/utils.d.ts +13 -0
- package/dist/components/dashboard/components/charts/utils.js +18 -0
- package/dist/components/dashboard/components/kpi-card.d.ts +8 -9
- package/dist/components/dashboard/components/kpi-card.js +26 -44
- package/dist/components/dashboard/index.d.ts +2 -7
- package/dist/components/dashboard/index.js +0 -11
- package/dist/components/dashboard/pages/analytics-page.d.ts +0 -18
- package/dist/components/dashboard/pages/analytics-page.js +83 -37
- package/dist/components/dashboard/pages/jobs-page.d.ts +0 -18
- package/dist/components/dashboard/pages/jobs-page.js +27 -24
- package/dist/components/dashboard/table/table-wrapper.d.ts +21 -24
- package/dist/components/dashboard/table/table-wrapper.js +38 -51
- package/dist/components/empty-state/empty-state.d.ts +10 -0
- package/dist/components/empty-state/empty-state.js +40 -0
- package/dist/components/empty-state/empty-state.stories.js +74 -0
- package/dist/components/empty-state/index.d.ts +2 -0
- package/dist/components/empty-state/index.js +3 -0
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.js +4 -0
- package/dist/components/item/item.stories.js +3 -3
- package/dist/components/table/data-table.d.ts +12 -1
- package/dist/components/table/data-table.js +84 -71
- package/dist/components/table/table-column-header.d.ts +14 -1
- package/dist/components/table/table-column-header.js +12 -5
- package/dist/components/table/table-pagination.d.ts +14 -1
- package/dist/components/table/table-pagination.js +6 -2
- package/dist/components/table/table.js +3 -3
- package/dist/components/table/table.stories.components.js +6 -28
- package/dist/styles.css +1 -1
- package/package.json +3 -3
|
@@ -1,101 +1,147 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Card, CardContent, CardHeader, CardTitle } from '../../../../components/card/index.js';
|
|
3
|
+
import { EmptyState } from '../../../../components/empty-state/index.js';
|
|
4
|
+
import { Text } from '../../../../components/typography/index.js';
|
|
2
5
|
import { useState } from 'react';
|
|
3
6
|
import { Bar, CartesianGrid, BarChart as RechartsBarChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts';
|
|
4
|
-
import { cn } from '../../../../utils/cn.js';
|
|
5
7
|
import { ChartTooltipContent } from './chart-tooltip.js';
|
|
6
|
-
import {
|
|
8
|
+
import { getChartColor, getHoverOpacity, normalizeTooltipPayload } from './utils.js';
|
|
7
9
|
export function BarChart({ data, bars, height = 200, xAxis, yAxis, grid, tooltip, className, title, barRadius = [
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
0,
|
|
11
|
+
0,
|
|
10
12
|
0,
|
|
11
13
|
0
|
|
12
14
|
], maxBarSize = 8 }) {
|
|
13
15
|
const [hoveredDataKey, setHoveredDataKey] = useState(undefined);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
const visibleBars = bars.filter((bar)=>!bar.hide);
|
|
17
|
+
const hasData = data && data.length > 0 && visibleBars.length > 0;
|
|
18
|
+
const hasNonZeroData = hasData && data.some((item)=>visibleBars.some((bar)=>{
|
|
19
|
+
const value = item[bar.dataKey];
|
|
20
|
+
return value !== undefined && value !== null && Number(value) !== 0;
|
|
21
|
+
}));
|
|
22
|
+
const isEmpty = !hasData || !hasNonZeroData;
|
|
23
|
+
return /*#__PURE__*/ _jsxs(Card, {
|
|
24
|
+
className: className,
|
|
16
25
|
children: [
|
|
17
|
-
title && /*#__PURE__*/ _jsx(
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
title && /*#__PURE__*/ _jsx(CardHeader, {
|
|
27
|
+
children: /*#__PURE__*/ _jsx(CardTitle, {
|
|
28
|
+
variant: "h4",
|
|
29
|
+
children: title
|
|
30
|
+
})
|
|
20
31
|
}),
|
|
21
|
-
/*#__PURE__*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
width: "100%",
|
|
27
|
-
height: "100%",
|
|
28
|
-
children: /*#__PURE__*/ _jsxs(RechartsBarChart, {
|
|
29
|
-
data: data,
|
|
30
|
-
margin: {
|
|
31
|
-
top: 8,
|
|
32
|
-
right: 8,
|
|
33
|
-
left: -20,
|
|
34
|
-
bottom: 0
|
|
32
|
+
/*#__PURE__*/ _jsxs(CardContent, {
|
|
33
|
+
children: [
|
|
34
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
35
|
+
style: {
|
|
36
|
+
height
|
|
35
37
|
},
|
|
38
|
+
className: "relative",
|
|
36
39
|
children: [
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
40
|
+
/*#__PURE__*/ _jsx(ResponsiveContainer, {
|
|
41
|
+
width: "100%",
|
|
42
|
+
height: "100%",
|
|
43
|
+
children: /*#__PURE__*/ _jsxs(RechartsBarChart, {
|
|
44
|
+
data: isEmpty ? [] : data,
|
|
45
|
+
margin: {
|
|
46
|
+
top: 8,
|
|
47
|
+
right: 8,
|
|
48
|
+
left: -20,
|
|
49
|
+
bottom: 0
|
|
50
|
+
},
|
|
51
|
+
children: [
|
|
52
|
+
!xAxis?.hide && /*#__PURE__*/ _jsx(XAxis, {
|
|
53
|
+
dataKey: xAxis?.dataKey ?? 'label',
|
|
54
|
+
axisLine: false,
|
|
55
|
+
tickLine: false,
|
|
56
|
+
tick: {
|
|
57
|
+
fill: 'var(--foreground-neutral-muted)',
|
|
58
|
+
fontSize: 12
|
|
59
|
+
},
|
|
60
|
+
tickFormatter: xAxis?.tickFormatter,
|
|
61
|
+
interval: xAxis?.interval ?? 'preserveStartEnd'
|
|
62
|
+
}),
|
|
63
|
+
!yAxis?.hide && /*#__PURE__*/ _jsx(YAxis, {
|
|
64
|
+
axisLine: false,
|
|
65
|
+
tickLine: false,
|
|
66
|
+
tick: {
|
|
67
|
+
fill: 'var(--foreground-neutral-muted)',
|
|
68
|
+
fontSize: 12
|
|
69
|
+
},
|
|
70
|
+
domain: yAxis?.domain,
|
|
71
|
+
ticks: yAxis?.ticks,
|
|
72
|
+
tickFormatter: yAxis?.tickFormatter
|
|
73
|
+
}),
|
|
74
|
+
/*#__PURE__*/ _jsx(CartesianGrid, {
|
|
75
|
+
strokeDasharray: "3 3",
|
|
76
|
+
stroke: "var(--border-neutral-base)",
|
|
77
|
+
vertical: grid?.vertical ?? false,
|
|
78
|
+
horizontal: grid?.horizontal ?? true
|
|
79
|
+
}),
|
|
80
|
+
/*#__PURE__*/ _jsx(Tooltip, {
|
|
81
|
+
cursor: {
|
|
82
|
+
fill: 'var(--background-neutral-hover)'
|
|
83
|
+
},
|
|
84
|
+
content: (props)=>{
|
|
85
|
+
if (!props.active) return null;
|
|
86
|
+
return /*#__PURE__*/ _jsx(ChartTooltipContent, {
|
|
87
|
+
active: props.active,
|
|
88
|
+
label: props.label,
|
|
89
|
+
payload: normalizeTooltipPayload(props.payload, tooltip?.formatter),
|
|
90
|
+
hoveredDataKey: hoveredDataKey,
|
|
91
|
+
labelFormatter: tooltip?.labelFormatter
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}),
|
|
95
|
+
visibleBars.map((bar, index)=>{
|
|
96
|
+
const color = getChartColor(bar.color, index);
|
|
97
|
+
const fillOpacity = getHoverOpacity(hoveredDataKey, bar.dataKey);
|
|
98
|
+
return /*#__PURE__*/ _jsx(Bar, {
|
|
99
|
+
dataKey: bar.dataKey,
|
|
100
|
+
name: bar.name ?? bar.dataKey,
|
|
101
|
+
fill: color,
|
|
102
|
+
fillOpacity: fillOpacity,
|
|
103
|
+
radius: barRadius,
|
|
104
|
+
maxBarSize: maxBarSize,
|
|
105
|
+
onMouseEnter: ()=>setHoveredDataKey(bar.dataKey),
|
|
106
|
+
onMouseLeave: ()=>setHoveredDataKey(undefined),
|
|
107
|
+
isAnimationActive: false,
|
|
108
|
+
stackId: bar.stackId
|
|
109
|
+
}, bar.dataKey);
|
|
110
|
+
})
|
|
111
|
+
]
|
|
112
|
+
})
|
|
57
113
|
}),
|
|
58
|
-
/*#__PURE__*/ _jsx(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}),
|
|
64
|
-
/*#__PURE__*/ _jsx(Tooltip, {
|
|
65
|
-
cursor: {
|
|
66
|
-
fill: 'var(--background-neutral-hover)'
|
|
67
|
-
},
|
|
68
|
-
content: (props)=>{
|
|
69
|
-
if (!props.active) return null;
|
|
70
|
-
return /*#__PURE__*/ _jsx(ChartTooltipContent, {
|
|
71
|
-
active: props.active,
|
|
72
|
-
label: props.label,
|
|
73
|
-
payload: props.payload,
|
|
74
|
-
hoveredDataKey: hoveredDataKey,
|
|
75
|
-
labelFormatter: tooltip?.labelFormatter
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}),
|
|
79
|
-
bars.map((bar, index)=>{
|
|
80
|
-
const defaultColor = bar.color ? chartColors[bar.color] : chartColorsList[index % chartColorsList.length];
|
|
81
|
-
const fillOpacity = hoveredDataKey ? hoveredDataKey === bar.dataKey ? 1 : 0.25 : 1;
|
|
82
|
-
const { dataKey, name, ...restBar } = bar;
|
|
83
|
-
return /*#__PURE__*/ _jsx(Bar, {
|
|
84
|
-
dataKey: dataKey,
|
|
85
|
-
name: name ?? dataKey,
|
|
86
|
-
fill: defaultColor,
|
|
87
|
-
fillOpacity: fillOpacity,
|
|
88
|
-
radius: barRadius,
|
|
89
|
-
maxBarSize: maxBarSize,
|
|
90
|
-
onMouseEnter: ()=>setHoveredDataKey(dataKey),
|
|
91
|
-
onMouseLeave: ()=>setHoveredDataKey(undefined),
|
|
92
|
-
isAnimationActive: false,
|
|
93
|
-
...restBar
|
|
94
|
-
}, dataKey);
|
|
114
|
+
isEmpty && /*#__PURE__*/ _jsx(EmptyState, {
|
|
115
|
+
icon: "barChartBoxLine",
|
|
116
|
+
title: "Nothing here yet.",
|
|
117
|
+
variant: "compact",
|
|
118
|
+
className: "absolute inset-0 z-10"
|
|
95
119
|
})
|
|
96
120
|
]
|
|
121
|
+
}),
|
|
122
|
+
!isEmpty && visibleBars.length > 0 && /*#__PURE__*/ _jsx("div", {
|
|
123
|
+
className: "flex items-center justify-center flex-wrap gap-16",
|
|
124
|
+
children: visibleBars.map((bar, index)=>{
|
|
125
|
+
const color = getChartColor(bar.color, index);
|
|
126
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
127
|
+
className: "flex items-center gap-6",
|
|
128
|
+
children: [
|
|
129
|
+
/*#__PURE__*/ _jsx("span", {
|
|
130
|
+
className: "size-8 rounded-full",
|
|
131
|
+
style: {
|
|
132
|
+
backgroundColor: color
|
|
133
|
+
}
|
|
134
|
+
}),
|
|
135
|
+
/*#__PURE__*/ _jsx(Text, {
|
|
136
|
+
size: "xs",
|
|
137
|
+
className: "text-foreground-neutral-subtle",
|
|
138
|
+
children: bar.name ?? bar.dataKey
|
|
139
|
+
})
|
|
140
|
+
]
|
|
141
|
+
}, bar.dataKey);
|
|
142
|
+
})
|
|
97
143
|
})
|
|
98
|
-
|
|
144
|
+
]
|
|
99
145
|
})
|
|
100
146
|
]
|
|
101
147
|
});
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { BarChart } from './bar-chart.js';
|
|
3
|
+
const meta = {
|
|
4
|
+
title: 'Components/Charts/BarChart',
|
|
5
|
+
component: BarChart,
|
|
6
|
+
tags: [
|
|
7
|
+
'autodocs'
|
|
8
|
+
],
|
|
9
|
+
parameters: {
|
|
10
|
+
layout: 'centered'
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
export default meta;
|
|
14
|
+
const sampleData = [
|
|
15
|
+
{
|
|
16
|
+
label: 'Jan',
|
|
17
|
+
value1: 100,
|
|
18
|
+
value2: 80,
|
|
19
|
+
value3: 120
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
label: 'Feb',
|
|
23
|
+
value1: 150,
|
|
24
|
+
value2: 130,
|
|
25
|
+
value3: 140
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
label: 'Mar',
|
|
29
|
+
value1: 200,
|
|
30
|
+
value2: 180,
|
|
31
|
+
value3: 160
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
label: 'Apr',
|
|
35
|
+
value1: 180,
|
|
36
|
+
value2: 200,
|
|
37
|
+
value3: 180
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
label: 'May',
|
|
41
|
+
value1: 250,
|
|
42
|
+
value2: 220,
|
|
43
|
+
value3: 200
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
label: 'Jun',
|
|
47
|
+
value1: 300,
|
|
48
|
+
value2: 280,
|
|
49
|
+
value3: 240
|
|
50
|
+
}
|
|
51
|
+
];
|
|
52
|
+
export const Default = {
|
|
53
|
+
render: (args)=>/*#__PURE__*/ _jsx("div", {
|
|
54
|
+
className: "w-400",
|
|
55
|
+
children: /*#__PURE__*/ _jsx(BarChart, {
|
|
56
|
+
...args
|
|
57
|
+
})
|
|
58
|
+
}),
|
|
59
|
+
args: {
|
|
60
|
+
data: sampleData,
|
|
61
|
+
bars: [
|
|
62
|
+
{
|
|
63
|
+
dataKey: 'value1',
|
|
64
|
+
name: 'Series 1'
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
dataKey: 'value2',
|
|
68
|
+
name: 'Series 2'
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
dataKey: 'value3',
|
|
72
|
+
name: 'Series 3'
|
|
73
|
+
}
|
|
74
|
+
],
|
|
75
|
+
height: 200
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
export const WithTitle = {
|
|
79
|
+
render: (args)=>/*#__PURE__*/ _jsx("div", {
|
|
80
|
+
className: "w-400",
|
|
81
|
+
children: /*#__PURE__*/ _jsx(BarChart, {
|
|
82
|
+
...args
|
|
83
|
+
})
|
|
84
|
+
}),
|
|
85
|
+
args: {
|
|
86
|
+
data: sampleData,
|
|
87
|
+
bars: [
|
|
88
|
+
{
|
|
89
|
+
dataKey: 'value1',
|
|
90
|
+
name: 'Revenue'
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
dataKey: 'value2',
|
|
94
|
+
name: 'Expenses'
|
|
95
|
+
}
|
|
96
|
+
],
|
|
97
|
+
height: 200,
|
|
98
|
+
title: 'Monthly Comparison'
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
export const SingleBar = {
|
|
102
|
+
render: (args)=>/*#__PURE__*/ _jsx("div", {
|
|
103
|
+
className: "w-400",
|
|
104
|
+
children: /*#__PURE__*/ _jsx(BarChart, {
|
|
105
|
+
...args
|
|
106
|
+
})
|
|
107
|
+
}),
|
|
108
|
+
args: {
|
|
109
|
+
data: sampleData,
|
|
110
|
+
bars: [
|
|
111
|
+
{
|
|
112
|
+
dataKey: 'value1',
|
|
113
|
+
name: 'Total Sales'
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
height: 200,
|
|
117
|
+
title: 'Sales Over Time'
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
export const CustomColors = {
|
|
121
|
+
render: (args)=>/*#__PURE__*/ _jsx("div", {
|
|
122
|
+
className: "w-400",
|
|
123
|
+
children: /*#__PURE__*/ _jsx(BarChart, {
|
|
124
|
+
...args
|
|
125
|
+
})
|
|
126
|
+
}),
|
|
127
|
+
args: {
|
|
128
|
+
data: sampleData,
|
|
129
|
+
bars: [
|
|
130
|
+
{
|
|
131
|
+
dataKey: 'value1',
|
|
132
|
+
name: 'Blue Series',
|
|
133
|
+
color: 'blue'
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
dataKey: 'value2',
|
|
137
|
+
name: 'Green Series',
|
|
138
|
+
color: 'green'
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
dataKey: 'value3',
|
|
142
|
+
name: 'Orange Series',
|
|
143
|
+
color: 'orange'
|
|
144
|
+
}
|
|
145
|
+
],
|
|
146
|
+
height: 200,
|
|
147
|
+
title: 'Custom Colored Bars'
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
export const StackedBars = {
|
|
151
|
+
render: (args)=>/*#__PURE__*/ _jsx("div", {
|
|
152
|
+
className: "w-400",
|
|
153
|
+
children: /*#__PURE__*/ _jsx(BarChart, {
|
|
154
|
+
...args
|
|
155
|
+
})
|
|
156
|
+
}),
|
|
157
|
+
args: {
|
|
158
|
+
data: sampleData,
|
|
159
|
+
bars: [
|
|
160
|
+
{
|
|
161
|
+
dataKey: 'value1',
|
|
162
|
+
name: 'Series 1',
|
|
163
|
+
stackId: 'stack'
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
dataKey: 'value2',
|
|
167
|
+
name: 'Series 2',
|
|
168
|
+
stackId: 'stack'
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
dataKey: 'value3',
|
|
172
|
+
name: 'Series 3',
|
|
173
|
+
stackId: 'stack'
|
|
174
|
+
}
|
|
175
|
+
],
|
|
176
|
+
height: 200,
|
|
177
|
+
title: 'Stacked Bars'
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
export const RoundedBars = {
|
|
181
|
+
render: (args)=>/*#__PURE__*/ _jsx("div", {
|
|
182
|
+
className: "w-400",
|
|
183
|
+
children: /*#__PURE__*/ _jsx(BarChart, {
|
|
184
|
+
...args
|
|
185
|
+
})
|
|
186
|
+
}),
|
|
187
|
+
args: {
|
|
188
|
+
data: sampleData,
|
|
189
|
+
bars: [
|
|
190
|
+
{
|
|
191
|
+
dataKey: 'value1',
|
|
192
|
+
name: 'Series 1'
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
dataKey: 'value2',
|
|
196
|
+
name: 'Series 2'
|
|
197
|
+
}
|
|
198
|
+
],
|
|
199
|
+
height: 200,
|
|
200
|
+
barRadius: [
|
|
201
|
+
4,
|
|
202
|
+
4,
|
|
203
|
+
0,
|
|
204
|
+
0
|
|
205
|
+
],
|
|
206
|
+
title: 'Rounded Top Corners'
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
export const HiddenBars = {
|
|
210
|
+
render: (args)=>/*#__PURE__*/ _jsx("div", {
|
|
211
|
+
className: "w-400",
|
|
212
|
+
children: /*#__PURE__*/ _jsx(BarChart, {
|
|
213
|
+
...args
|
|
214
|
+
})
|
|
215
|
+
}),
|
|
216
|
+
args: {
|
|
217
|
+
data: sampleData,
|
|
218
|
+
bars: [
|
|
219
|
+
{
|
|
220
|
+
dataKey: 'value1',
|
|
221
|
+
name: 'Visible Series'
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
dataKey: 'value2',
|
|
225
|
+
name: 'Hidden Series',
|
|
226
|
+
hide: true
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
dataKey: 'value3',
|
|
230
|
+
name: 'Another Visible Series'
|
|
231
|
+
}
|
|
232
|
+
],
|
|
233
|
+
height: 200,
|
|
234
|
+
title: 'With Hidden Bars'
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
export const CustomFormatter = {
|
|
238
|
+
render: (args)=>/*#__PURE__*/ _jsx("div", {
|
|
239
|
+
className: "w-400",
|
|
240
|
+
children: /*#__PURE__*/ _jsx(BarChart, {
|
|
241
|
+
...args
|
|
242
|
+
})
|
|
243
|
+
}),
|
|
244
|
+
args: {
|
|
245
|
+
data: sampleData,
|
|
246
|
+
bars: [
|
|
247
|
+
{
|
|
248
|
+
dataKey: 'value1',
|
|
249
|
+
name: 'Sales'
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
dataKey: 'value2',
|
|
253
|
+
name: 'Profit'
|
|
254
|
+
}
|
|
255
|
+
],
|
|
256
|
+
height: 200,
|
|
257
|
+
tooltip: {
|
|
258
|
+
formatter: (value)=>`$${value.toLocaleString()}`,
|
|
259
|
+
labelFormatter: (label)=>`Month: ${label}`
|
|
260
|
+
},
|
|
261
|
+
yAxis: {
|
|
262
|
+
tickFormatter: (value)=>`$${value}`
|
|
263
|
+
},
|
|
264
|
+
title: 'Formatted Values'
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
export const EmptyState = {
|
|
268
|
+
render: (args)=>/*#__PURE__*/ _jsx("div", {
|
|
269
|
+
className: "w-400",
|
|
270
|
+
children: /*#__PURE__*/ _jsx(BarChart, {
|
|
271
|
+
...args
|
|
272
|
+
})
|
|
273
|
+
}),
|
|
274
|
+
args: {
|
|
275
|
+
data: [],
|
|
276
|
+
bars: [
|
|
277
|
+
{
|
|
278
|
+
dataKey: 'value1',
|
|
279
|
+
name: 'Series 1'
|
|
280
|
+
}
|
|
281
|
+
],
|
|
282
|
+
height: 200,
|
|
283
|
+
title: 'Duration distribution'
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
//# sourceMappingURL=bar-chart.stories.js.map
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Text } from '../../../../components/typography/index.js';
|
|
2
3
|
import { cn } from '../../../../utils/cn.js';
|
|
3
4
|
export function ChartTooltipContent({ active, label, payload, hoveredDataKey, labelFormatter }) {
|
|
4
5
|
const isVisible = active && payload && payload.length;
|
|
5
6
|
if (!isVisible) return null;
|
|
6
7
|
return /*#__PURE__*/ _jsxs("div", {
|
|
7
|
-
className:
|
|
8
|
+
className: "flex flex-col gap-4 rounded-8 p-12 bg-background-neutral-overlay border border-border-neutral-base shadow-lg",
|
|
8
9
|
children: [
|
|
9
|
-
/*#__PURE__*/ _jsx(
|
|
10
|
-
|
|
10
|
+
/*#__PURE__*/ _jsx(Text, {
|
|
11
|
+
size: "xs",
|
|
12
|
+
className: "text-foreground-neutral-muted",
|
|
11
13
|
children: labelFormatter ? labelFormatter(String(label)) : label
|
|
12
14
|
}),
|
|
13
15
|
/*#__PURE__*/ _jsx("div", {
|
|
@@ -16,23 +18,22 @@ export function ChartTooltipContent({ active, label, payload, hoveredDataKey, la
|
|
|
16
18
|
/*#__PURE__*/ _jsx("div", {
|
|
17
19
|
className: "flex flex-col gap-4",
|
|
18
20
|
children: payload.map((item, index)=>/*#__PURE__*/ _jsxs("div", {
|
|
19
|
-
className:
|
|
20
|
-
style: {
|
|
21
|
-
opacity: hoveredDataKey ? item.dataKey === hoveredDataKey ? 1 : 0.5 : 1
|
|
22
|
-
},
|
|
21
|
+
className: cn('flex items-center gap-8', hoveredDataKey && item.dataKey !== hoveredDataKey && 'opacity-50'),
|
|
23
22
|
children: [
|
|
24
23
|
/*#__PURE__*/ _jsx("span", {
|
|
25
|
-
className: "size-8 rounded-full
|
|
24
|
+
className: "size-8 shrink-0 rounded-full",
|
|
26
25
|
style: {
|
|
27
26
|
backgroundColor: item.color
|
|
28
27
|
}
|
|
29
28
|
}),
|
|
30
|
-
item.name && /*#__PURE__*/ _jsx(
|
|
31
|
-
|
|
29
|
+
item.name && /*#__PURE__*/ _jsx(Text, {
|
|
30
|
+
size: "xs",
|
|
31
|
+
className: "text-foreground-neutral-subtle",
|
|
32
32
|
children: item.name
|
|
33
33
|
}),
|
|
34
|
-
/*#__PURE__*/ _jsx(
|
|
35
|
-
|
|
34
|
+
/*#__PURE__*/ _jsx(Text, {
|
|
35
|
+
size: "xs",
|
|
36
|
+
className: "text-foreground-neutral-base font-medium ml-auto tabular-nums",
|
|
36
37
|
children: item.value
|
|
37
38
|
})
|
|
38
39
|
]
|
|
@@ -4,8 +4,9 @@ export declare const chartColors: {
|
|
|
4
4
|
readonly orange: "var(--color-orange-500)";
|
|
5
5
|
readonly purple: "var(--color-purple-500)";
|
|
6
6
|
readonly red: "var(--color-red-500)";
|
|
7
|
-
readonly
|
|
7
|
+
readonly amber: "var(--color-amber-500)";
|
|
8
|
+
readonly neutral: "var(--color-neutral-500)";
|
|
8
9
|
};
|
|
9
10
|
export type ChartColor = keyof typeof chartColors;
|
|
10
|
-
export declare const chartColorsList: ("var(--color-blue-500)" | "var(--color-green-500)" | "var(--color-orange-500)" | "var(--color-purple-500)" | "var(--color-red-500)")[];
|
|
11
|
+
export declare const chartColorsList: ("var(--color-blue-500)" | "var(--color-green-500)" | "var(--color-orange-500)" | "var(--color-purple-500)" | "var(--color-red-500)" | "var(--color-amber-500)" | "var(--color-neutral-500)")[];
|
|
11
12
|
//# sourceMappingURL=colors.d.ts.map
|
|
@@ -4,14 +4,17 @@ export const chartColors = {
|
|
|
4
4
|
orange: 'var(--color-orange-500)',
|
|
5
5
|
purple: 'var(--color-purple-500)',
|
|
6
6
|
red: 'var(--color-red-500)',
|
|
7
|
-
|
|
7
|
+
amber: 'var(--color-amber-500)',
|
|
8
|
+
neutral: 'var(--color-neutral-500)'
|
|
8
9
|
};
|
|
9
10
|
export const chartColorsList = [
|
|
10
11
|
chartColors.blue,
|
|
11
12
|
chartColors.green,
|
|
12
13
|
chartColors.orange,
|
|
13
14
|
chartColors.purple,
|
|
14
|
-
chartColors.red
|
|
15
|
+
chartColors.red,
|
|
16
|
+
chartColors.amber,
|
|
17
|
+
chartColors.neutral
|
|
15
18
|
];
|
|
16
19
|
|
|
17
20
|
//# sourceMappingURL=colors.js.map
|
|
@@ -1,34 +1,25 @@
|
|
|
1
1
|
import type { ComponentProps } from 'react';
|
|
2
|
-
import { type LineProps, LineChart as RechartsLineChart } from 'recharts';
|
|
3
|
-
import {
|
|
2
|
+
import { type CartesianGridProps, type LineProps, LineChart as RechartsLineChart, type XAxisProps, type YAxisProps } from 'recharts';
|
|
3
|
+
import type { ChartColor } from './colors';
|
|
4
4
|
export type RechartsLineChartProps = ComponentProps<typeof RechartsLineChart>;
|
|
5
5
|
export interface LineChartLine extends Omit<LineProps, 'dataKey' | 'strokeWidth'> {
|
|
6
6
|
dataKey: string;
|
|
7
7
|
name?: string;
|
|
8
8
|
strokeWidth?: number;
|
|
9
9
|
color?: ChartColor;
|
|
10
|
+
hide?: boolean;
|
|
10
11
|
}
|
|
11
12
|
export interface LineChartProps {
|
|
12
13
|
data: RechartsLineChartProps['data'];
|
|
13
14
|
lines: LineChartLine[];
|
|
14
15
|
syncId?: RechartsLineChartProps['syncId'];
|
|
15
16
|
height?: number;
|
|
16
|
-
xAxis?:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
hide?: boolean;
|
|
20
|
-
};
|
|
21
|
-
yAxis?: {
|
|
22
|
-
domain?: [number, number];
|
|
23
|
-
ticks?: number[];
|
|
24
|
-
hide?: boolean;
|
|
25
|
-
};
|
|
26
|
-
grid?: {
|
|
27
|
-
vertical?: boolean;
|
|
28
|
-
horizontal?: boolean;
|
|
29
|
-
};
|
|
17
|
+
xAxis?: Pick<XAxisProps, 'dataKey' | 'tickFormatter' | 'hide'>;
|
|
18
|
+
yAxis?: Pick<YAxisProps, 'domain' | 'ticks' | 'hide' | 'tickFormatter'>;
|
|
19
|
+
grid?: Pick<CartesianGridProps, 'vertical' | 'horizontal'>;
|
|
30
20
|
tooltip?: {
|
|
31
21
|
labelFormatter?: (label: string) => string;
|
|
22
|
+
formatter?: (value: number) => string;
|
|
32
23
|
};
|
|
33
24
|
className?: string;
|
|
34
25
|
title?: string;
|