@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.
Files changed (168) hide show
  1. package/dist/types/components/Chart/Chart.d.ts +2 -0
  2. package/dist/types/components/Chart/ChartContext.d.ts +2 -0
  3. package/dist/types/components/Chart/components/ChartLegend.d.ts +4 -0
  4. package/dist/types/components/Chart/components/ChartStyle.d.ts +2 -0
  5. package/dist/types/components/Chart/components/ChartTooltip.d.ts +4 -0
  6. package/dist/types/components/Chart/components/index.d.ts +3 -0
  7. package/dist/types/components/Chart/constants.d.ts +22 -0
  8. package/dist/types/components/Chart/helpers.d.ts +11 -0
  9. package/dist/types/components/Chart/hooks/index.d.ts +1 -0
  10. package/dist/types/components/Chart/hooks/useChart/index.d.ts +1 -0
  11. package/dist/types/components/Chart/hooks/useChart/useChart.d.ts +1 -0
  12. package/dist/types/components/Chart/index.d.ts +2 -0
  13. package/dist/types/components/Chart/stories/args/activeShapeArgs.d.ts +2 -0
  14. package/dist/types/components/Chart/stories/args/animationArgs.d.ts +12 -0
  15. package/dist/types/components/Chart/stories/args/areaArgs.d.ts +2 -0
  16. package/dist/types/components/Chart/stories/args/areaChartArgs.d.ts +2 -0
  17. package/dist/types/components/Chart/stories/args/barArgs.d.ts +5 -0
  18. package/dist/types/components/Chart/stories/args/barChartArgs.d.ts +2 -0
  19. package/dist/types/components/Chart/stories/args/cartesianChartArgs.d.ts +2 -0
  20. package/dist/types/components/Chart/stories/args/cartesianSharedArgs.d.ts +11 -0
  21. package/dist/types/components/Chart/stories/args/chartArgs.d.ts +6 -0
  22. package/dist/types/components/Chart/stories/args/dotArgs.d.ts +10 -0
  23. package/dist/types/components/Chart/stories/args/events.d.ts +804 -0
  24. package/dist/types/components/Chart/stories/args/labelListArgs.d.ts +2 -0
  25. package/dist/types/components/Chart/stories/args/legendArgs.d.ts +3 -0
  26. package/dist/types/components/Chart/stories/args/lineArgs.d.ts +2 -0
  27. package/dist/types/components/Chart/stories/args/lineChartArgs.d.ts +2 -0
  28. package/dist/types/components/Chart/stories/args/pieArgs.d.ts +2 -0
  29. package/dist/types/components/Chart/stories/args/pieChartArgs.d.ts +2 -0
  30. package/dist/types/components/Chart/stories/args/polarChartArgs.d.ts +2 -0
  31. package/dist/types/components/Chart/stories/args/polarSharedArgs.d.ts +2 -0
  32. package/dist/types/components/Chart/stories/args/radarArgs.d.ts +2 -0
  33. package/dist/types/components/Chart/stories/args/radarChartArgs.d.ts +2 -0
  34. package/dist/types/components/Chart/stories/args/radialBarArgs.d.ts +2 -0
  35. package/dist/types/components/Chart/stories/args/radialBarChartArgs.d.ts +2 -0
  36. package/dist/types/components/Chart/stories/args/rectangleArgs.d.ts +9 -0
  37. package/dist/types/components/Chart/stories/args/referenceSharedArgs.d.ts +4 -0
  38. package/dist/types/components/Chart/stories/args/sectorArgs.d.ts +7 -0
  39. package/dist/types/components/Chart/stories/args/sharedAxisArgs.d.ts +2 -0
  40. package/dist/types/components/Chart/stories/args/stylesArgs.d.ts +6 -0
  41. package/dist/types/components/Chart/stories/args/textArgs.d.ts +2 -0
  42. package/dist/types/components/Chart/stories/args/tooltipArgs.d.ts +4 -0
  43. package/dist/types/components/Chart/stories/args/types.d.ts +13 -0
  44. package/dist/types/components/Chart/stories/args/xAxisArgs.d.ts +2 -0
  45. package/dist/types/components/Chart/stories/args/yAxisArgs.d.ts +2 -0
  46. package/dist/types/components/Chart/stories/examples/AreaChart.d.ts +16 -0
  47. package/dist/types/components/Chart/stories/examples/BarChart.d.ts +20 -0
  48. package/dist/types/components/Chart/stories/examples/LineChart.d.ts +16 -0
  49. package/dist/types/components/Chart/stories/examples/PieChart.d.ts +19 -0
  50. package/dist/types/components/Chart/stories/examples/RadarChart.d.ts +24 -0
  51. package/dist/types/components/Chart/stories/examples/RadialChart.d.ts +17 -0
  52. package/dist/types/components/Chart/stories/examples/Tooltip.d.ts +15 -0
  53. package/dist/types/components/Chart/stories/helpers/index.d.ts +9 -0
  54. package/dist/types/components/Chart/types.d.ts +37 -0
  55. package/dist/types/components/DragAndDrop/Draggable/Draggable.d.ts +29 -0
  56. package/dist/types/components/DragAndDrop/Draggable/Draggable.example.d.ts +24 -0
  57. package/dist/types/components/DragAndDrop/Draggable/constants.d.ts +9 -0
  58. package/dist/types/components/DragAndDrop/Draggable/index.d.ts +1 -0
  59. package/dist/types/components/DragAndDrop/Draggable/types.d.ts +41 -0
  60. package/dist/types/components/DragAndDrop/Droppable/Droppable.d.ts +2 -0
  61. package/dist/types/components/DragAndDrop/Droppable/Droppable.example.d.ts +10 -0
  62. package/dist/types/components/DragAndDrop/Droppable/constants.d.ts +5 -0
  63. package/dist/types/components/DragAndDrop/Droppable/index.d.ts +1 -0
  64. package/dist/types/components/DragAndDrop/Droppable/types.d.ts +4 -0
  65. package/dist/types/components/DragAndDrop/Sortable/Sortable.d.ts +2 -0
  66. package/dist/types/components/DragAndDrop/Sortable/Sortable.example.d.ts +6 -0
  67. package/dist/types/components/DragAndDrop/Sortable/constants.d.ts +4 -0
  68. package/dist/types/components/DragAndDrop/Sortable/index.d.ts +1 -0
  69. package/dist/types/components/DragAndDrop/Sortable/types.d.ts +7 -0
  70. package/dist/types/components/DragAndDrop/index.d.ts +3 -0
  71. package/dist/types/components/Widget/InternalWidgetsContext.d.ts +2 -0
  72. package/dist/types/components/Widget/Widget.d.ts +2 -0
  73. package/dist/types/components/Widget/Widgets.example.d.ts +1 -0
  74. package/dist/types/components/Widget/WidgetsContext.d.ts +2 -0
  75. package/dist/types/components/Widget/hooks/index.d.ts +2 -0
  76. package/dist/types/components/Widget/hooks/useWidget/index.d.ts +1 -0
  77. package/dist/types/components/Widget/hooks/useWidget/useWidget.d.ts +7 -0
  78. package/dist/types/components/Widget/hooks/useWidgets/index.d.ts +1 -0
  79. package/dist/types/components/Widget/hooks/useWidgets/useWidgets.d.ts +1 -0
  80. package/dist/types/components/Widget/index.d.ts +3 -0
  81. package/dist/types/components/Widget/modifiers/index.d.ts +1 -0
  82. package/dist/types/components/Widget/modifiers/restrictToElement.d.ts +2 -0
  83. package/dist/types/components/Widget/types.d.ts +28 -0
  84. package/package.json +9 -3
  85. package/src/components/Chart/Chart.tsx +26 -0
  86. package/src/components/Chart/ChartContext.tsx +4 -0
  87. package/src/components/Chart/components/ChartLegend.tsx +52 -0
  88. package/src/components/Chart/components/ChartStyle.tsx +32 -0
  89. package/src/components/Chart/components/ChartTooltip.tsx +126 -0
  90. package/src/components/Chart/components/index.ts +3 -0
  91. package/src/components/Chart/constants.ts +78 -0
  92. package/src/components/Chart/helpers.ts +27 -0
  93. package/src/components/Chart/hooks/index.ts +1 -0
  94. package/src/components/Chart/hooks/useChart/index.ts +1 -0
  95. package/src/components/Chart/hooks/useChart/useChart.ts +12 -0
  96. package/src/components/Chart/index.ts +2 -0
  97. package/src/components/Chart/stories/args/activeShapeArgs.ts +34 -0
  98. package/src/components/Chart/stories/args/animationArgs.ts +67 -0
  99. package/src/components/Chart/stories/args/areaArgs.ts +16 -0
  100. package/src/components/Chart/stories/args/areaChartArgs.ts +19 -0
  101. package/src/components/Chart/stories/args/barArgs.ts +123 -0
  102. package/src/components/Chart/stories/args/barChartArgs.ts +65 -0
  103. package/src/components/Chart/stories/args/cartesianChartArgs.ts +42 -0
  104. package/src/components/Chart/stories/args/cartesianSharedArgs.ts +136 -0
  105. package/src/components/Chart/stories/args/chartArgs.ts +244 -0
  106. package/src/components/Chart/stories/args/dotArgs.ts +46 -0
  107. package/src/components/Chart/stories/args/events.ts +343 -0
  108. package/src/components/Chart/stories/args/index.ts +178 -0
  109. package/src/components/Chart/stories/args/labelListArgs.ts +124 -0
  110. package/src/components/Chart/stories/args/legendArgs.ts +205 -0
  111. package/src/components/Chart/stories/args/lineArgs.ts +87 -0
  112. package/src/components/Chart/stories/args/lineChartArgs.ts +17 -0
  113. package/src/components/Chart/stories/args/pieArgs.ts +18 -0
  114. package/src/components/Chart/stories/args/pieChartArgs.ts +7 -0
  115. package/src/components/Chart/stories/args/polarChartArgs.ts +86 -0
  116. package/src/components/Chart/stories/args/polarSharedArgs.ts +42 -0
  117. package/src/components/Chart/stories/args/radarArgs.ts +26 -0
  118. package/src/components/Chart/stories/args/radarChartArgs.ts +26 -0
  119. package/src/components/Chart/stories/args/radialBarArgs.ts +36 -0
  120. package/src/components/Chart/stories/args/radialBarChartArgs.ts +16 -0
  121. package/src/components/Chart/stories/args/rectangleArgs.ts +35 -0
  122. package/src/components/Chart/stories/args/referenceSharedArgs.ts +75 -0
  123. package/src/components/Chart/stories/args/sectorArgs.ts +106 -0
  124. package/src/components/Chart/stories/args/sharedAxisArgs.ts +332 -0
  125. package/src/components/Chart/stories/args/stylesArgs.ts +258 -0
  126. package/src/components/Chart/stories/args/textArgs.ts +97 -0
  127. package/src/components/Chart/stories/args/tooltipArgs.ts +41 -0
  128. package/src/components/Chart/stories/args/types.ts +23 -0
  129. package/src/components/Chart/stories/args/xAxisArgs.ts +109 -0
  130. package/src/components/Chart/stories/args/yAxisArgs.ts +73 -0
  131. package/src/components/Chart/stories/examples/AreaChart.tsx +156 -0
  132. package/src/components/Chart/stories/examples/BarChart.tsx +425 -0
  133. package/src/components/Chart/stories/examples/LineChart.tsx +144 -0
  134. package/src/components/Chart/stories/examples/PieChart.tsx +238 -0
  135. package/src/components/Chart/stories/examples/RadarChart.tsx +261 -0
  136. package/src/components/Chart/stories/examples/RadialChart.tsx +239 -0
  137. package/src/components/Chart/stories/examples/Tooltip.tsx +68 -0
  138. package/src/components/Chart/stories/helpers/index.tsx +75 -0
  139. package/src/components/Chart/types.ts +39 -0
  140. package/src/components/DragAndDrop/Draggable/Draggable.example.tsx +147 -0
  141. package/src/components/DragAndDrop/Draggable/Draggable.tsx +161 -0
  142. package/src/components/DragAndDrop/Draggable/constants.ts +47 -0
  143. package/src/components/DragAndDrop/Draggable/index.ts +1 -0
  144. package/src/components/DragAndDrop/Draggable/types.ts +56 -0
  145. package/src/components/DragAndDrop/Droppable/Droppable.example.tsx +86 -0
  146. package/src/components/DragAndDrop/Droppable/Droppable.tsx +38 -0
  147. package/src/components/DragAndDrop/Droppable/constants.ts +15 -0
  148. package/src/components/DragAndDrop/Droppable/index.ts +1 -0
  149. package/src/components/DragAndDrop/Droppable/types.ts +7 -0
  150. package/src/components/DragAndDrop/Sortable/Sortable.example.tsx +61 -0
  151. package/src/components/DragAndDrop/Sortable/Sortable.tsx +65 -0
  152. package/src/components/DragAndDrop/Sortable/constants.ts +12 -0
  153. package/src/components/DragAndDrop/Sortable/index.ts +1 -0
  154. package/src/components/DragAndDrop/Sortable/types.ts +11 -0
  155. package/src/components/DragAndDrop/index.ts +3 -0
  156. package/src/components/Widget/InternalWidgetsContext.tsx +4 -0
  157. package/src/components/Widget/Widget.tsx +17 -0
  158. package/src/components/Widget/Widgets.example.tsx +118 -0
  159. package/src/components/Widget/WidgetsContext.tsx +97 -0
  160. package/src/components/Widget/hooks/index.ts +2 -0
  161. package/src/components/Widget/hooks/useWidget/index.ts +1 -0
  162. package/src/components/Widget/hooks/useWidget/useWidget.ts +21 -0
  163. package/src/components/Widget/hooks/useWidgets/index.ts +1 -0
  164. package/src/components/Widget/hooks/useWidgets/useWidgets.ts +12 -0
  165. package/src/components/Widget/index.ts +3 -0
  166. package/src/components/Widget/modifiers/index.ts +1 -0
  167. package/src/components/Widget/modifiers/restrictToElement.ts +8 -0
  168. package/src/components/Widget/types.ts +30 -0
@@ -0,0 +1,239 @@
1
+ import { Label, LabelList, PolarGrid, PolarRadiusAxis, RadialBar, RadialBarChart } from "recharts";
2
+ import { Chart } from "../../Chart";
3
+ import { ChartTooltip, ChartTooltipContent } from "../../components";
4
+ import { type ChartConfig } from "../../types";
5
+ import { RadialBarChartProps } from "../args";
6
+
7
+ const chartConfig = {
8
+ visitors: {
9
+ label: "Visitors",
10
+ },
11
+ chrome: {
12
+ label: "Chrome",
13
+ color: "hsl(var(--chart-1))",
14
+ },
15
+ safari: {
16
+ label: "Safari",
17
+ color: "hsl(var(--chart-2))",
18
+ },
19
+ firefox: {
20
+ label: "Firefox",
21
+ color: "hsl(var(--chart-3))",
22
+ },
23
+ edge: {
24
+ label: "Edge",
25
+ color: "hsl(var(--chart-4))",
26
+ },
27
+ other: {
28
+ label: "Other",
29
+ color: "hsl(var(--chart-5))",
30
+ },
31
+ } satisfies ChartConfig;
32
+
33
+ /**
34
+ * ## Parent
35
+ *
36
+ * The RadialBarChart can be used within: `<Chart />`
37
+ *
38
+ * ## Children
39
+ *
40
+ * The RadialBarChart can be used with the following child components: `<PolarAngleAxis />`, `<PolarRadiusAxis />`,
41
+ * `<PolarGrid />`, `<ChartLegend />`, `<ChartTooltip />`, `<RadialBar />`, `<Customized />`
42
+ */
43
+ export const RadialChartExample = (props: Partial<RadialBarChartProps>) => {
44
+ return (
45
+ <Chart config={chartConfig} className="mx-auto aspect-square h-[250px]">
46
+ <RadialBarChart {...props.radialBarChart}>
47
+ <ChartTooltip
48
+ cursor={false}
49
+ content={<ChartTooltipContent hideLabel nameKey="browser" />}
50
+ />
51
+ <RadialBar dataKey="visitors" {...props.radialBar} />
52
+ </RadialBarChart>
53
+ </Chart>
54
+ );
55
+ };
56
+
57
+ export const LabeledRadialChartExample = (props: Partial<RadialBarChartProps>) => {
58
+ return (
59
+ <Chart config={chartConfig} className="mx-auto aspect-square h-[250px]">
60
+ <RadialBarChart {...props.radialBarChart}>
61
+ <ChartTooltip
62
+ cursor={false}
63
+ content={<ChartTooltipContent hideLabel nameKey="browser" />}
64
+ />
65
+ <RadialBar dataKey="visitors" {...props.radialBar}>
66
+ <LabelList
67
+ position="insideStart"
68
+ dataKey="browser"
69
+ className="fill-white capitalize mix-blend-luminosity"
70
+ fontSize={11}
71
+ />
72
+ </RadialBar>
73
+ </RadialBarChart>
74
+ </Chart>
75
+ );
76
+ };
77
+
78
+ export const GridRadialChartExample = (props: Partial<RadialBarChartProps>) => {
79
+ return (
80
+ <Chart config={chartConfig} className="mx-auto aspect-square h-[250px]">
81
+ <RadialBarChart {...props.radialBarChart}>
82
+ <ChartTooltip
83
+ cursor={false}
84
+ content={<ChartTooltipContent hideLabel nameKey="browser" />}
85
+ />
86
+ <PolarGrid gridType="circle" />
87
+ <RadialBar dataKey="visitors" {...props.radialBar} />
88
+ </RadialBarChart>
89
+ </Chart>
90
+ );
91
+ };
92
+
93
+ export const TextRadialChartExample = (props: Partial<RadialBarChartProps>) => {
94
+ const chartData = [{ browser: "safari", visitors: 200, fill: "var(--color-safari)" }];
95
+ const chartConfig = {
96
+ visitors: {
97
+ label: "Visitors",
98
+ },
99
+ safari: {
100
+ label: "Safari",
101
+ color: "hsl(var(--chart-2))",
102
+ },
103
+ } satisfies ChartConfig;
104
+
105
+ return (
106
+ <Chart config={chartConfig} className="mx-auto aspect-square h-[250px]">
107
+ <RadialBarChart {...props.radialBarChart}>
108
+ <PolarGrid
109
+ gridType="circle"
110
+ radialLines={false}
111
+ stroke="none"
112
+ className="first:fill-base-200 last:fill-base-100"
113
+ polarRadius={[86, 74]}
114
+ />
115
+ <RadialBar dataKey="visitors" {...props.radialBar} />
116
+ <PolarRadiusAxis tick={false} tickLine={false} axisLine={false}>
117
+ <Label
118
+ content={({ viewBox }) => {
119
+ if (viewBox && "cx" in viewBox && "cy" in viewBox) {
120
+ return (
121
+ <text x={viewBox.cx} y={viewBox.cy} textAnchor="middle" dominantBaseline="middle">
122
+ <tspan
123
+ x={viewBox.cx}
124
+ y={viewBox.cy}
125
+ className="fill-foreground text-4xl font-bold"
126
+ >
127
+ {chartData[0].visitors.toLocaleString()}
128
+ </tspan>
129
+ <tspan x={viewBox.cx} y={(viewBox.cy || 0) + 24} className="fill-base-content">
130
+ Visitors
131
+ </tspan>
132
+ </text>
133
+ );
134
+ }
135
+ }}
136
+ />
137
+ </PolarRadiusAxis>
138
+ </RadialBarChart>
139
+ </Chart>
140
+ );
141
+ };
142
+
143
+ export const ShapeRadialChartExample = (props: Partial<RadialBarChartProps>) => {
144
+ const chartData = [{ browser: "safari", visitors: 1260, fill: "var(--color-safari)" }];
145
+ const chartConfig = {
146
+ visitors: {
147
+ label: "Visitors",
148
+ },
149
+ safari: {
150
+ label: "Safari",
151
+ color: "hsl(var(--chart-2))",
152
+ },
153
+ } satisfies ChartConfig;
154
+
155
+ return (
156
+ <Chart config={chartConfig} className="mx-auto aspect-square h-[250px]">
157
+ <RadialBarChart {...props.radialBarChart}>
158
+ <PolarGrid
159
+ gridType="circle"
160
+ radialLines={false}
161
+ stroke="none"
162
+ className="first:fill-base-200 last:fill-base-100"
163
+ polarRadius={[86, 74]}
164
+ />
165
+ <RadialBar dataKey="visitors" {...props.radialBar} />
166
+ <PolarRadiusAxis tick={false} tickLine={false} axisLine={false}>
167
+ <Label
168
+ content={({ viewBox }) => {
169
+ if (viewBox && "cx" in viewBox && "cy" in viewBox) {
170
+ return (
171
+ <text x={viewBox.cx} y={viewBox.cy} textAnchor="middle" dominantBaseline="middle">
172
+ <tspan
173
+ x={viewBox.cx}
174
+ y={viewBox.cy}
175
+ className="fill-base-content text-4xl font-bold"
176
+ >
177
+ {chartData[0].visitors.toLocaleString()}
178
+ </tspan>
179
+ <tspan x={viewBox.cx} y={(viewBox.cy || 0) + 24} className="fill-base-content">
180
+ Visitors
181
+ </tspan>
182
+ </text>
183
+ );
184
+ }
185
+ }}
186
+ />
187
+ </PolarRadiusAxis>
188
+ </RadialBarChart>
189
+ </Chart>
190
+ );
191
+ };
192
+
193
+ export const StackedRadialChartExample = (props: Partial<RadialBarChartProps>) => {
194
+ const chartData = [{ month: "january", desktop: 1260, mobile: 570 }];
195
+ const chartConfig = {
196
+ desktop: {
197
+ label: "Desktop",
198
+ color: "hsl(var(--chart-1))",
199
+ },
200
+ mobile: {
201
+ label: "Mobile",
202
+ color: "hsl(var(--chart-2))",
203
+ },
204
+ } satisfies ChartConfig;
205
+
206
+ const totalVisitors = chartData[0].desktop + chartData[0].mobile;
207
+
208
+ return (
209
+ <Chart config={chartConfig} className="mx-auto aspect-square h-[250px]">
210
+ <RadialBarChart {...props.radialBarChart}>
211
+ <ChartTooltip cursor={false} content={<ChartTooltipContent hideLabel />} />
212
+ <PolarRadiusAxis tick={false} tickLine={false} axisLine={false}>
213
+ <Label
214
+ content={({ viewBox }) => {
215
+ if (viewBox && "cx" in viewBox && "cy" in viewBox) {
216
+ return (
217
+ <text x={viewBox.cx} y={viewBox.cy} textAnchor="middle">
218
+ <tspan
219
+ x={viewBox.cx}
220
+ y={(viewBox.cy || 0) - 16}
221
+ className="fill-foreground text-2xl font-bold"
222
+ >
223
+ {totalVisitors.toLocaleString()}
224
+ </tspan>
225
+ <tspan x={viewBox.cx} y={(viewBox.cy || 0) + 4} className="fill-base-content">
226
+ Visitors
227
+ </tspan>
228
+ </text>
229
+ );
230
+ }
231
+ }}
232
+ />
233
+ </PolarRadiusAxis>
234
+ <RadialBar dataKey="desktop" fill="var(--color-desktop)" {...props.radialBar} />
235
+ <RadialBar dataKey="mobile" fill="var(--color-mobile)" {...props.radialBar} />
236
+ </RadialBarChart>
237
+ </Chart>
238
+ );
239
+ };
@@ -0,0 +1,68 @@
1
+ import { Bar, BarChart, XAxis } from "recharts";
2
+ import type { ChartConfig } from "../../types";
3
+ import { Chart } from "../../Chart";
4
+ import { ChartTooltip, ChartTooltipContent } from "../../components";
5
+ import { type ChartTooltipContentProps } from "../../types";
6
+
7
+ const chartData = [
8
+ { date: "2024-07-15", running: 450, swimming: 300 },
9
+ { date: "2024-07-16", running: 380, swimming: 420 },
10
+ { date: "2024-07-17", running: 520, swimming: 120 },
11
+ { date: "2024-07-18", running: 140, swimming: 550 },
12
+ { date: "2024-07-19", running: 600, swimming: 350 },
13
+ { date: "2024-07-20", running: 480, swimming: 400 },
14
+ ];
15
+ export const tooltipChartConfig = {
16
+ activities: {
17
+ label: "Activities",
18
+ },
19
+ running: {
20
+ label: "Running",
21
+ color: "hsl(var(--chart-3))",
22
+ },
23
+ swimming: {
24
+ label: "Swimming",
25
+ color: "hsl(var(--chart-2))",
26
+ },
27
+ } satisfies ChartConfig;
28
+
29
+ export const BarChartExample = (props: ChartTooltipContentProps) => {
30
+ return (
31
+ <Chart config={tooltipChartConfig} className="h-[250px] w-full">
32
+ <BarChart accessibilityLayer data={chartData}>
33
+ <XAxis
34
+ dataKey="date"
35
+ tickLine={false}
36
+ tickMargin={10}
37
+ axisLine={false}
38
+ tickFormatter={(value: string) => {
39
+ return new Date(value).toLocaleDateString("en-US", {
40
+ weekday: "short",
41
+ });
42
+ }}
43
+ />
44
+ <Bar
45
+ isAnimationActive={false}
46
+ dataKey="running"
47
+ stackId="a"
48
+ fill="var(--color-running)"
49
+ radius={[0, 0, 4, 4]}
50
+ />
51
+ <Bar
52
+ isAnimationActive={false}
53
+ dataKey="swimming"
54
+ stackId="a"
55
+ fill="var(--color-swimming)"
56
+ radius={[4, 4, 0, 0]}
57
+ />
58
+
59
+ <ChartTooltip
60
+ content={<ChartTooltipContent {...props} />}
61
+ isAnimationActive={false}
62
+ cursor={false}
63
+ defaultIndex={1}
64
+ />
65
+ </BarChart>
66
+ </Chart>
67
+ );
68
+ };
@@ -0,0 +1,75 @@
1
+ import type { ArgTypes, StoryContext, StoryFn } from "@storybook/react";
2
+ import type { ComponentProps, ElementType } from "react";
3
+
4
+ export const categorizeArgs = (args: ArgTypes, category: string) => {
5
+ return Object.entries(args).reduce((acc, [name, arg]) => {
6
+ const categoryName = `${category} ${name}`;
7
+ acc[categoryName] = {
8
+ ...arg,
9
+ name,
10
+ table: {
11
+ ...arg.table,
12
+ category,
13
+ },
14
+ };
15
+ return acc;
16
+ }, {} as ArgTypes);
17
+ };
18
+
19
+ const getCategorizedArgs = <T,>(args: ArgTypes<T>) => {
20
+ return Object.entries(args).reduce((acc, [categoryName, value]) => {
21
+ const [category, name] = categoryName.split(" ");
22
+ acc[category] = {
23
+ ...acc[category],
24
+ [name]: value,
25
+ };
26
+ return acc;
27
+ }, {} as ArgTypes);
28
+ };
29
+
30
+ export const withArgs = <T extends object>(Component: StoryFn, context: StoryContext<T>) => {
31
+ context.args = getCategorizedArgs(context.args) as T;
32
+
33
+ return <Component />;
34
+ };
35
+
36
+ const convertStringToJSON = (str: string) => {
37
+ let newStr = str.replace(/'/g, '"');
38
+ newStr = newStr.replace(/(\w+)\s*:/g, '"$1":');
39
+
40
+ try {
41
+ return JSON.parse(newStr) as Record<string, unknown>;
42
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
43
+ } catch (e) {
44
+ return str;
45
+ }
46
+ };
47
+
48
+ // A helper function to generate Args for a story based on ArgsTypes objects
49
+ export const getArgsFromArgTypes = <T extends ArgTypes>(argsTypes: T) => {
50
+ const args = (Object.keys(argsTypes) as (keyof T)[]).reduce(
51
+ (acc, key) => {
52
+ const defaultValue =
53
+ (argsTypes[key].defaultValue as string) ?? argsTypes[key].table?.defaultValue?.summary;
54
+ if (defaultValue) {
55
+ try {
56
+ acc[key] = convertStringToJSON(String(defaultValue));
57
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
58
+ } catch (_e) {
59
+ acc[key] = defaultValue;
60
+ }
61
+ }
62
+ return acc;
63
+ },
64
+ {} as Record<keyof T, unknown>
65
+ );
66
+
67
+ return args;
68
+ };
69
+
70
+ export const renderer = <T extends ElementType>(Component: T) => {
71
+ const component = <G,>(props: G) => <Component {...(props as ComponentProps<T>)} />;
72
+ component.displayName =
73
+ (Component as React.FC<unknown>).displayName || (Component as React.FC<unknown>).name;
74
+ return component;
75
+ };
@@ -0,0 +1,39 @@
1
+ import type { ComponentProps, ComponentType, ReactNode } from "react";
2
+ import { LegendProps, ResponsiveContainer, Tooltip } from "recharts";
3
+ import { type Theme } from "../../utilities";
4
+
5
+ export type ChartConfig = {
6
+ [k in string]: {
7
+ label?: ReactNode;
8
+ icon?: ComponentType;
9
+ } & ({ color?: string; theme?: never } | { color?: never; theme: Record<Theme, string> });
10
+ };
11
+
12
+ export type ChartContextProps = {
13
+ config: ChartConfig;
14
+ };
15
+
16
+ export type ChartProps = ComponentProps<"div"> & {
17
+ config: ChartConfig;
18
+ children: ComponentProps<typeof ResponsiveContainer>["children"];
19
+ };
20
+
21
+ export type ChartStyleProps = {
22
+ id: string;
23
+ config: ChartConfig;
24
+ };
25
+
26
+ export type ChartTooltipContentProps = ComponentProps<typeof Tooltip> &
27
+ ComponentProps<"div"> & {
28
+ hideLabel?: boolean;
29
+ hideIndicator?: boolean;
30
+ indicator?: "line" | "dot" | "dashed";
31
+ nameKey?: string;
32
+ labelKey?: string;
33
+ };
34
+
35
+ export type ChartLegendContentProps = ComponentProps<"div"> &
36
+ Pick<LegendProps, "payload" | "verticalAlign"> & {
37
+ hideIcon?: boolean;
38
+ nameKey?: string;
39
+ };
@@ -0,0 +1,147 @@
1
+ import type { DropAnimation, Modifiers, PointerActivationConstraint } from "@dnd-kit/core";
2
+ import type { Coordinates } from "@dnd-kit/utilities";
3
+ import type { CSSProperties } from "react";
4
+ import { useMemo, useState } from "react";
5
+ import {
6
+ DndContext,
7
+ KeyboardSensor,
8
+ MouseSensor,
9
+ TouchSensor,
10
+ useSensor,
11
+ useSensors,
12
+ } from "@dnd-kit/core";
13
+ import { createSnapModifier } from "@dnd-kit/modifiers";
14
+ import type { DraggableAxis } from "./types";
15
+ import { Draggable } from "./Draggable";
16
+ import { type DraggableHandleElement } from "./types";
17
+
18
+ type DraggableExampleProps = Partial<{
19
+ activationConstraint: PointerActivationConstraint;
20
+ axis: DraggableAxis;
21
+ handle: DraggableHandleElement;
22
+ modifiers: Modifiers;
23
+ buttonStyle: CSSProperties;
24
+ label: string;
25
+ }>;
26
+
27
+ export const DraggableExample = ({
28
+ activationConstraint,
29
+ axis,
30
+ handle,
31
+ modifiers,
32
+ label = "Go ahead, drag me.",
33
+ }: DraggableExampleProps) => {
34
+ const [{ x, y }, setCoordinates] = useState<Coordinates>({ x: 0, y: 0 });
35
+ const mouseSensor = useSensor(MouseSensor, {
36
+ activationConstraint,
37
+ });
38
+ const touchSensor = useSensor(TouchSensor, {
39
+ activationConstraint,
40
+ });
41
+ const keyboardSensor = useSensor(KeyboardSensor, {});
42
+ const sensors = useSensors(mouseSensor, touchSensor, keyboardSensor);
43
+
44
+ return (
45
+ <DndContext
46
+ sensors={sensors}
47
+ onDragEnd={({ delta }) => {
48
+ setCoordinates(({ x, y }) => {
49
+ return {
50
+ x: x + delta.x,
51
+ y: y + delta.y,
52
+ };
53
+ });
54
+ }}
55
+ modifiers={modifiers}
56
+ >
57
+ <Draggable
58
+ id="my-draggable"
59
+ axis={axis}
60
+ handle={handle}
61
+ style={{ top: y, left: x }}
62
+ className="w-fit border border-base-content rounded-md p-2 flex items-center gap-2"
63
+ >
64
+ {label}
65
+ </Draggable>
66
+ </DndContext>
67
+ );
68
+ };
69
+
70
+ export const DraggableSnapToGridExample = () => {
71
+ const [gridSize] = useState(30);
72
+ const buttonStyle = {
73
+ marginLeft: gridSize - 20 + 1,
74
+ marginTop: gridSize - 20 + 1,
75
+ width: gridSize * 8 - 1,
76
+ height: gridSize * 2 - 1,
77
+ };
78
+ const snapToGrid = useMemo(() => createSnapModifier(gridSize), [gridSize]);
79
+
80
+ return (
81
+ <>
82
+ <DraggableExample
83
+ label={`Snapping to ${gridSize}px increments`}
84
+ modifiers={[snapToGrid]}
85
+ buttonStyle={buttonStyle}
86
+ key={gridSize}
87
+ />
88
+ <div
89
+ className="fixed top-0 left-0 w-full h-full -z-10 pointer-events-none"
90
+ style={
91
+ {
92
+ "--grid-size": `${gridSize}px`,
93
+ backgroundSize: "var(--grid-size) var(--grid-size)",
94
+ backgroundImage: `repeating-linear-gradient(
95
+ 0deg,
96
+ transparent,
97
+ transparent calc(var(--grid-size) - 1px),
98
+ #9999991a calc(var(--grid-size) - 1px),
99
+ #9999991a var(--grid-size)
100
+ ),
101
+ repeating-linear-gradient(
102
+ -90deg,
103
+ transparent,
104
+ transparent calc(var(--grid-size) - 1px),
105
+ #9999991a calc(var(--grid-size) - 1px),
106
+ #9999991a var(--grid-size)
107
+ )`,
108
+ } as React.CSSProperties
109
+ }
110
+ />
111
+ </>
112
+ );
113
+ };
114
+
115
+ type DraggableOverlayExampleProps = Partial<{
116
+ activationConstraint: PointerActivationConstraint;
117
+ axis: DraggableAxis;
118
+ handle: DraggableHandleElement;
119
+ modifiers: Modifiers;
120
+ label: string;
121
+ dragOverlayModifiers: Modifiers;
122
+ dropAnimation: DropAnimation | null;
123
+ }>;
124
+
125
+ export const DraggableOverlayExample = ({
126
+ axis,
127
+ dropAnimation,
128
+ handle,
129
+ label = "Drag me to see the <Draggable.Overlay>",
130
+ modifiers,
131
+ }: DraggableOverlayExampleProps) => {
132
+ return (
133
+ <DndContext modifiers={modifiers}>
134
+ <div>
135
+ <Draggable
136
+ id="my-draggable"
137
+ axis={axis}
138
+ handle={handle}
139
+ className="w-fit border border-base-content rounded-md p-2 flex items-center gap-2 data-[draggable-active]:opacity-0"
140
+ >
141
+ {label}
142
+ </Draggable>
143
+ </div>
144
+ <Draggable.Overlay axis={axis} dropAnimation={dropAnimation} />
145
+ </DndContext>
146
+ );
147
+ };