@mbao01/common 0.9.2 → 0.9.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.
@@ -1,4 +1,4 @@
1
- import { AreaProps, BarProps, LineProps, PieProps, RadarProps, RadialBarProps, XAxisProps, YAxisProps } from 'recharts';
1
+ import { AreaProps, BarProps, LineProps, PieProps, RadarProps, RadialBarProps, ScatterProps, XAxisProps, YAxisProps } from 'recharts';
2
2
  import { ArgTypes } from '@storybook/react-vite';
3
3
  import { CartesianChartProps, PolarChartProps } from 'recharts/types/util/types';
4
4
  import { Flatten, OmitSVGElement } from './types';
@@ -60,4 +60,16 @@ export declare const radarArgKey: {
60
60
  radarChart: "radarChart";
61
61
  };
62
62
  export declare const radarChartArgs: ArgTypes;
63
+ export type ScatterChartProps = {
64
+ scatter: OmitSVGElement<ScatterProps>;
65
+ scatterChart: CartesianChartProps;
66
+ } & AxisProps;
67
+ export type ScatterChartArgs = Partial<Flatten<ScatterChartProps>> & {};
68
+ export declare const scatterArgKey: {
69
+ scatter: "scatter";
70
+ scatterChart: "scatterChart";
71
+ xAxis: "xAxis";
72
+ yAxis: "yAxis";
73
+ };
74
+ export declare const scatterChartArgs: ArgTypes;
63
75
  export {};
@@ -0,0 +1,2 @@
1
+ import { ArgTypes } from '@storybook/react-vite';
2
+ export declare const scatterArgs: ArgTypes;
@@ -0,0 +1,2 @@
1
+ import { ArgTypes } from '@storybook/react-vite';
2
+ export declare const scatterChartArgs: ArgTypes;
@@ -0,0 +1,17 @@
1
+ import { ScatterChartProps } from '../args';
2
+ /**
3
+ * ## Parent
4
+ *
5
+ * The ScatterChart can be used within: `<Chart />`
6
+ *
7
+ * ## Children
8
+ *
9
+ * The ScatterChart can be used with the following child components: `<XAxis />`, `<YAxis />`, `<ZAxis />`,
10
+ * `<ReferenceArea />`, `<ReferenceDot />`, `<ReferenceLine />`, `<CartesianGrid />`,
11
+ * `<ChartLegend />`, `<ChartTooltip />`, `<Scatter />`, `<Customized />` or valid svg elements.
12
+ */
13
+ export declare const ScatterChartExample: (props: ScatterChartProps) => import("react/jsx-runtime").JSX.Element;
14
+ export declare const MultiSeriesScatterChartExample: (props: ScatterChartProps) => import("react/jsx-runtime").JSX.Element;
15
+ export declare const BubbleScatterChartExample: (props: ScatterChartProps) => import("react/jsx-runtime").JSX.Element;
16
+ export declare const WithLineScatterChartExample: (props: ScatterChartProps) => import("react/jsx-runtime").JSX.Element;
17
+ export declare const ShapesScatterChartExample: (props: ScatterChartProps) => import("react/jsx-runtime").JSX.Element;
@@ -84,6 +84,7 @@ export * from './components/Widget';
84
84
  export * from './components/WidgetShell';
85
85
  /** molecules */
86
86
  export * from './components/Banner';
87
+ export * from './components/Drawer';
87
88
  export * from './components/Empty';
88
89
  export * from './components/Sidebar';
89
90
  export * from './components/Stepper';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mbao01/common",
3
3
  "private": false,
4
- "version": "0.9.2",
4
+ "version": "0.9.3",
5
5
  "type": "module",
6
6
  "author": "Ayomide Bakare",
7
7
  "license": "MIT",
@@ -5,6 +5,7 @@ import type {
5
5
  PieProps,
6
6
  RadarProps,
7
7
  RadialBarProps,
8
+ ScatterProps,
8
9
  XAxisProps,
9
10
  YAxisProps,
10
11
  } from "recharts";
@@ -24,6 +25,8 @@ import { radarArgs } from "./radarArgs";
24
25
  import { radarChartArgs as radarChartComponentArgs } from "./radarChartArgs";
25
26
  import { radialBarArgs } from "./radialBarArgs";
26
27
  import { radialBarChartArgs as radialBarChartComponentArgs } from "./radialBarChartArgs";
28
+ import { scatterArgs } from "./scatterArgs";
29
+ import { scatterChartArgs as scatterChartComponentArgs } from "./scatterChartArgs";
27
30
  import { OmitSVGElement } from "./types";
28
31
  import { xAxisArgs } from "./xAxisArgs";
29
32
  import { yAxisArgs } from "./yAxisArgs";
@@ -177,3 +180,29 @@ export const radarChartArgs: ArgTypes = {
177
180
  ...categorizeArgs(radarChartComponentArgs, radarArgKey.radarChart),
178
181
  ...categorizeArgs(radarArgs, radarArgKey.radar),
179
182
  };
183
+
184
+ /**
185
+ * Scatter chart
186
+ */
187
+ type ScatterArgKey = "scatter" | "scatterChart" | "xAxis" | "yAxis";
188
+
189
+ export type ScatterChartProps = {
190
+ scatter: OmitSVGElement<ScatterProps>;
191
+ scatterChart: CartesianChartProps;
192
+ } & AxisProps;
193
+
194
+ export type ScatterChartArgs = Partial<Flatten<ScatterChartProps>> & {};
195
+
196
+ export const scatterArgKey = {
197
+ scatter: "scatter",
198
+ scatterChart: "scatterChart",
199
+ xAxis: "xAxis",
200
+ yAxis: "yAxis",
201
+ } satisfies Record<string, ScatterArgKey>;
202
+
203
+ export const scatterChartArgs: ArgTypes = {
204
+ ...categorizeArgs(scatterChartComponentArgs, scatterArgKey.scatterChart),
205
+ ...categorizeArgs(xAxisArgs, scatterArgKey.xAxis),
206
+ ...categorizeArgs(yAxisArgs, scatterArgKey.yAxis),
207
+ ...categorizeArgs(scatterArgs, scatterArgKey.scatter),
208
+ };
@@ -0,0 +1,79 @@
1
+ import { type ArgTypes } from "@storybook/react-vite";
2
+ import { generalStyleArgs, hide, labelDescription, labelSummary } from "./stylesArgs";
3
+ import { animationArgs } from "./animationArgs";
4
+ import { dataKey, zAxisId } from "./cartesianSharedArgs";
5
+
6
+ export const scatterArgs: ArgTypes = {
7
+ ...generalStyleArgs,
8
+ ...animationArgs,
9
+ dataKey,
10
+ zAxisId,
11
+ hide,
12
+ name: {
13
+ description: `The name of data. This option will be used in tooltip and legend to represent a scatter.
14
+ If no value was set to this option, the value of dataKey will be used alternatively.`,
15
+ table: {
16
+ type: {
17
+ summary: "string | number",
18
+ },
19
+ category: "General",
20
+ },
21
+ control: "text",
22
+ },
23
+ shape: {
24
+ description:
25
+ "If a string set, specified symbol will be used to show scatter item. If ReactElement, the element will be cloned to render scatter item. If a function, it will be called to render scatter item.",
26
+ table: {
27
+ type: {
28
+ summary: "'circle' | 'cross' | 'diamond' | 'square' | 'star' | 'triangle' | 'wye' | ReactElement | Function",
29
+ },
30
+ defaultValue: {
31
+ summary: "'circle'",
32
+ },
33
+ category: "Style",
34
+ },
35
+ control: "select",
36
+ options: ["circle", "cross", "diamond", "square", "star", "triangle", "wye"],
37
+ },
38
+ line: {
39
+ description:
40
+ "If false set, line will not be drawn. If true set, line will be drawn which have the props calculated internally. If object set, line will be drawn which have the props merged by the internal calculated props and the option.",
41
+ table: {
42
+ type: {
43
+ summary: "boolean | Object | ReactElement | Function",
44
+ },
45
+ defaultValue: {
46
+ summary: "false",
47
+ },
48
+ category: "Style",
49
+ },
50
+ control: "boolean",
51
+ },
52
+ lineType: {
53
+ description: "The type of line in the scatter chart, 'joint' connects adjacent points, 'fitting' uses a fitting line.",
54
+ table: {
55
+ type: {
56
+ summary: "'joint' | 'fitting'",
57
+ },
58
+ defaultValue: {
59
+ summary: "'joint'",
60
+ },
61
+ category: "Style",
62
+ },
63
+ control: "radio",
64
+ options: ["joint", "fitting"],
65
+ },
66
+ label: {
67
+ description: labelDescription,
68
+ table: {
69
+ type: {
70
+ summary: labelSummary,
71
+ },
72
+ defaultValue: {
73
+ summary: "false",
74
+ },
75
+ category: "Style",
76
+ },
77
+ control: "boolean",
78
+ },
79
+ };
@@ -0,0 +1,6 @@
1
+ import { type ArgTypes } from "@storybook/react-vite";
2
+ import { categoricalChartArgs } from "./chartArgs";
3
+
4
+ export const scatterChartArgs: ArgTypes = {
5
+ ...categoricalChartArgs,
6
+ };
@@ -0,0 +1,263 @@
1
+ import { CartesianGrid, Scatter, ScatterChart, XAxis, YAxis, ZAxis } from "recharts";
2
+ import { Chart } from "../../Chart";
3
+ import {
4
+ ChartLegend,
5
+ ChartLegendContent,
6
+ ChartTooltip,
7
+ ChartTooltipContent,
8
+ } from "../../components";
9
+ import { type ChartConfig } from "../../types";
10
+ import { ScatterChartProps } from "../args";
11
+
12
+ const chartConfig = {
13
+ desktop: {
14
+ label: "Desktop",
15
+ color: "hsl(var(--chart-1))",
16
+ },
17
+ mobile: {
18
+ label: "Mobile",
19
+ color: "hsl(var(--chart-2))",
20
+ },
21
+ } satisfies ChartConfig;
22
+
23
+ /**
24
+ * ## Parent
25
+ *
26
+ * The ScatterChart can be used within: `<Chart />`
27
+ *
28
+ * ## Children
29
+ *
30
+ * The ScatterChart can be used with the following child components: `<XAxis />`, `<YAxis />`, `<ZAxis />`,
31
+ * `<ReferenceArea />`, `<ReferenceDot />`, `<ReferenceLine />`, `<CartesianGrid />`,
32
+ * `<ChartLegend />`, `<ChartTooltip />`, `<Scatter />`, `<Customized />` or valid svg elements.
33
+ */
34
+ export const ScatterChartExample = (props: ScatterChartProps) => {
35
+ return (
36
+ <Chart config={chartConfig} className="h-[300px] w-full">
37
+ <ScatterChart {...props.scatterChart}>
38
+ <CartesianGrid strokeDasharray="3 3" />
39
+ <XAxis {...props.xAxis} />
40
+ <YAxis {...props.yAxis} />
41
+ <ChartTooltip cursor={{ strokeDasharray: "3 3" }} content={<ChartTooltipContent />} />
42
+ <Scatter {...props.scatter} />
43
+ </ScatterChart>
44
+ </Chart>
45
+ );
46
+ };
47
+
48
+ export const MultiSeriesScatterChartExample = (props: ScatterChartProps) => {
49
+ const desktopData = [
50
+ { x: 100, y: 200 },
51
+ { x: 120, y: 100 },
52
+ { x: 170, y: 300 },
53
+ { x: 140, y: 250 },
54
+ { x: 150, y: 400 },
55
+ { x: 110, y: 280 },
56
+ ];
57
+
58
+ const mobileData = [
59
+ { x: 200, y: 260 },
60
+ { x: 240, y: 290 },
61
+ { x: 190, y: 340 },
62
+ { x: 198, y: 250 },
63
+ { x: 180, y: 280 },
64
+ { x: 210, y: 220 },
65
+ ];
66
+
67
+ return (
68
+ <Chart config={chartConfig} className="h-[300px] w-full">
69
+ <ScatterChart {...props.scatterChart}>
70
+ <CartesianGrid strokeDasharray="3 3" />
71
+ <XAxis {...props.xAxis} />
72
+ <YAxis {...props.yAxis} />
73
+ <ChartTooltip cursor={{ strokeDasharray: "3 3" }} content={<ChartTooltipContent />} />
74
+ <Scatter
75
+ {...props.scatter}
76
+ name="Desktop"
77
+ data={desktopData}
78
+ fill="var(--color-desktop)"
79
+ />
80
+ <Scatter
81
+ {...props.scatter}
82
+ name="Mobile"
83
+ data={mobileData}
84
+ fill="var(--color-mobile)"
85
+ />
86
+ <ChartLegend content={<ChartLegendContent />} />
87
+ </ScatterChart>
88
+ </Chart>
89
+ );
90
+ };
91
+
92
+ export const BubbleScatterChartExample = (props: ScatterChartProps) => {
93
+ const chartConfig = {
94
+ visitors: {
95
+ label: "Visitors",
96
+ color: "hsl(var(--chart-1))",
97
+ },
98
+ } satisfies ChartConfig;
99
+
100
+ return (
101
+ <Chart config={chartConfig} className="h-[300px] w-full">
102
+ <ScatterChart {...props.scatterChart}>
103
+ <CartesianGrid strokeDasharray="3 3" />
104
+ <XAxis
105
+ dataKey="hours"
106
+ name="Hours Spent"
107
+ type="number"
108
+ tickLine={false}
109
+ axisLine={false}
110
+ tickMargin={8}
111
+ {...props.xAxis}
112
+ />
113
+ <YAxis
114
+ dataKey="score"
115
+ name="Test Score"
116
+ type="number"
117
+ tickLine={false}
118
+ axisLine={false}
119
+ tickMargin={8}
120
+ {...props.yAxis}
121
+ />
122
+ <ZAxis dataKey="students" range={[60, 400]} name="Students" />
123
+ <ChartTooltip cursor={{ strokeDasharray: "3 3" }} content={<ChartTooltipContent />} />
124
+ <Scatter
125
+ name="Visitors"
126
+ fill="var(--color-visitors)"
127
+ {...props.scatter}
128
+ />
129
+ </ScatterChart>
130
+ </Chart>
131
+ );
132
+ };
133
+
134
+ export const WithLineScatterChartExample = (props: ScatterChartProps) => {
135
+ const chartConfig = {
136
+ performance: {
137
+ label: "Performance",
138
+ color: "hsl(var(--chart-1))",
139
+ },
140
+ } satisfies ChartConfig;
141
+
142
+ return (
143
+ <Chart config={chartConfig} className="h-[300px] w-full">
144
+ <ScatterChart {...props.scatterChart}>
145
+ <CartesianGrid strokeDasharray="3 3" />
146
+ <XAxis
147
+ dataKey="x"
148
+ name="Experience (years)"
149
+ type="number"
150
+ tickLine={false}
151
+ axisLine={false}
152
+ tickMargin={8}
153
+ {...props.xAxis}
154
+ />
155
+ <YAxis
156
+ dataKey="y"
157
+ name="Salary ($k)"
158
+ type="number"
159
+ tickLine={false}
160
+ axisLine={false}
161
+ tickMargin={8}
162
+ {...props.yAxis}
163
+ />
164
+ <ChartTooltip cursor={{ strokeDasharray: "3 3" }} content={<ChartTooltipContent />} />
165
+ <Scatter
166
+ name="Performance"
167
+ fill="var(--color-performance)"
168
+ line={{ stroke: "var(--color-performance)", strokeWidth: 2 }}
169
+ lineType="fitting"
170
+ {...props.scatter}
171
+ />
172
+ </ScatterChart>
173
+ </Chart>
174
+ );
175
+ };
176
+
177
+ export const ShapesScatterChartExample = (props: ScatterChartProps) => {
178
+ const chartConfig = {
179
+ series1: {
180
+ label: "Series A",
181
+ color: "hsl(var(--chart-1))",
182
+ },
183
+ series2: {
184
+ label: "Series B",
185
+ color: "hsl(var(--chart-2))",
186
+ },
187
+ series3: {
188
+ label: "Series C",
189
+ color: "hsl(var(--chart-3))",
190
+ },
191
+ } satisfies ChartConfig;
192
+
193
+ const series1Data = [
194
+ { x: 10, y: 30 },
195
+ { x: 30, y: 50 },
196
+ { x: 50, y: 70 },
197
+ { x: 70, y: 40 },
198
+ { x: 90, y: 60 },
199
+ ];
200
+
201
+ const series2Data = [
202
+ { x: 20, y: 80 },
203
+ { x: 40, y: 20 },
204
+ { x: 60, y: 50 },
205
+ { x: 80, y: 90 },
206
+ { x: 100, y: 30 },
207
+ ];
208
+
209
+ const series3Data = [
210
+ { x: 15, y: 45 },
211
+ { x: 35, y: 65 },
212
+ { x: 55, y: 25 },
213
+ { x: 75, y: 85 },
214
+ { x: 95, y: 55 },
215
+ ];
216
+
217
+ return (
218
+ <Chart config={chartConfig} className="h-[300px] w-full">
219
+ <ScatterChart {...props.scatterChart}>
220
+ <CartesianGrid strokeDasharray="3 3" />
221
+ <XAxis
222
+ dataKey="x"
223
+ type="number"
224
+ tickLine={false}
225
+ axisLine={false}
226
+ tickMargin={8}
227
+ {...props.xAxis}
228
+ />
229
+ <YAxis
230
+ dataKey="y"
231
+ type="number"
232
+ tickLine={false}
233
+ axisLine={false}
234
+ tickMargin={8}
235
+ {...props.yAxis}
236
+ />
237
+ <ChartTooltip cursor={{ strokeDasharray: "3 3" }} content={<ChartTooltipContent />} />
238
+ <Scatter
239
+ name="Series A"
240
+ data={series1Data}
241
+ fill="var(--color-series1)"
242
+ shape="circle"
243
+ {...props.scatter}
244
+ />
245
+ <Scatter
246
+ name="Series B"
247
+ data={series2Data}
248
+ fill="var(--color-series2)"
249
+ shape="diamond"
250
+ {...props.scatter}
251
+ />
252
+ <Scatter
253
+ name="Series C"
254
+ data={series3Data}
255
+ fill="var(--color-series3)"
256
+ shape="triangle"
257
+ {...props.scatter}
258
+ />
259
+ <ChartLegend content={<ChartLegendContent />} />
260
+ </ScatterChart>
261
+ </Chart>
262
+ );
263
+ };
package/src/index.ts CHANGED
@@ -92,6 +92,7 @@ export * from "./components/WidgetShell";
92
92
 
93
93
  /** molecules */
94
94
  export * from "./components/Banner";
95
+ export * from "./components/Drawer";
95
96
  export * from "./components/Empty";
96
97
  export * from "./components/Sidebar";
97
98
  export * from "./components/Stepper";