@mbao01/common 0.0.43 → 0.0.45

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 (172) 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/DatetimePicker/DatetimeGrid.d.ts +26 -0
  56. package/dist/types/components/DatetimePicker/DatetimePicker.d.ts +13 -0
  57. package/dist/types/components/DatetimePicker/constants.d.ts +15 -0
  58. package/dist/types/components/DatetimePicker/index.d.ts +1 -0
  59. package/dist/types/components/DatetimePicker/types.d.ts +25 -0
  60. package/dist/types/components/Form/DatetimeInput/DatetimeCalendar.d.ts +5 -0
  61. package/dist/types/components/Form/DatetimeInput/DatetimeInput.d.ts +83 -0
  62. package/dist/types/components/Form/DatetimeInput/DatetimeInputContext.d.ts +2 -0
  63. package/dist/types/components/Form/DatetimeInput/NaturalLanguageInput.d.ts +5 -0
  64. package/dist/types/components/Form/DatetimeInput/TimePicker.d.ts +1 -0
  65. package/dist/types/components/Form/DatetimeInput/constants.d.ts +24 -0
  66. package/dist/types/components/Form/DatetimeInput/helpers.d.ts +27 -0
  67. package/dist/types/components/Form/DatetimeInput/hooks/index.d.ts +1 -0
  68. package/dist/types/components/Form/DatetimeInput/hooks/useDateInput/index.d.ts +1 -0
  69. package/dist/types/components/Form/DatetimeInput/hooks/useDateInput/useDateInput.d.ts +1 -0
  70. package/dist/types/components/Form/DatetimeInput/index.d.ts +1 -0
  71. package/dist/types/components/Form/DatetimeInput/types.d.ts +31 -0
  72. package/dist/types/components/Form/MultiSelect/MultiSelect.d.ts +46 -0
  73. package/dist/types/components/Form/MultiSelect/MultiSelectContext.d.ts +2 -0
  74. package/dist/types/components/Form/MultiSelect/constants.d.ts +19 -0
  75. package/dist/types/components/Form/MultiSelect/hooks/index.d.ts +1 -0
  76. package/dist/types/components/Form/MultiSelect/hooks/useMultiSelect/index.d.ts +1 -0
  77. package/dist/types/components/Form/MultiSelect/hooks/useMultiSelect/useMultiSelect.d.ts +1 -0
  78. package/dist/types/components/Form/MultiSelect/index.d.ts +1 -0
  79. package/dist/types/components/Form/MultiSelect/types.d.ts +31 -0
  80. package/dist/types/components/Form/TagsInput/TagsInput.d.ts +13 -0
  81. package/dist/types/components/Form/TagsInput/constants.d.ts +16 -0
  82. package/dist/types/components/Form/TagsInput/index.d.ts +1 -0
  83. package/dist/types/components/Form/TagsInput/types.d.ts +9 -0
  84. package/dist/types/components/Form/index.d.ts +2 -0
  85. package/dist/types/index.d.ts +1 -0
  86. package/package.json +7 -3
  87. package/src/components/Chart/Chart.tsx +26 -0
  88. package/src/components/Chart/ChartContext.tsx +4 -0
  89. package/src/components/Chart/components/ChartLegend.tsx +52 -0
  90. package/src/components/Chart/components/ChartStyle.tsx +32 -0
  91. package/src/components/Chart/components/ChartTooltip.tsx +126 -0
  92. package/src/components/Chart/components/index.ts +3 -0
  93. package/src/components/Chart/constants.ts +78 -0
  94. package/src/components/Chart/helpers.ts +27 -0
  95. package/src/components/Chart/hooks/index.ts +1 -0
  96. package/src/components/Chart/hooks/useChart/index.ts +1 -0
  97. package/src/components/Chart/hooks/useChart/useChart.ts +12 -0
  98. package/src/components/Chart/index.ts +2 -0
  99. package/src/components/Chart/stories/args/activeShapeArgs.ts +34 -0
  100. package/src/components/Chart/stories/args/animationArgs.ts +67 -0
  101. package/src/components/Chart/stories/args/areaArgs.ts +16 -0
  102. package/src/components/Chart/stories/args/areaChartArgs.ts +19 -0
  103. package/src/components/Chart/stories/args/barArgs.ts +123 -0
  104. package/src/components/Chart/stories/args/barChartArgs.ts +65 -0
  105. package/src/components/Chart/stories/args/cartesianChartArgs.ts +42 -0
  106. package/src/components/Chart/stories/args/cartesianSharedArgs.ts +136 -0
  107. package/src/components/Chart/stories/args/chartArgs.ts +244 -0
  108. package/src/components/Chart/stories/args/dotArgs.ts +46 -0
  109. package/src/components/Chart/stories/args/events.ts +343 -0
  110. package/src/components/Chart/stories/args/index.ts +178 -0
  111. package/src/components/Chart/stories/args/labelListArgs.ts +124 -0
  112. package/src/components/Chart/stories/args/legendArgs.ts +205 -0
  113. package/src/components/Chart/stories/args/lineArgs.ts +87 -0
  114. package/src/components/Chart/stories/args/lineChartArgs.ts +17 -0
  115. package/src/components/Chart/stories/args/pieArgs.ts +18 -0
  116. package/src/components/Chart/stories/args/pieChartArgs.ts +7 -0
  117. package/src/components/Chart/stories/args/polarChartArgs.ts +86 -0
  118. package/src/components/Chart/stories/args/polarSharedArgs.ts +42 -0
  119. package/src/components/Chart/stories/args/radarArgs.ts +26 -0
  120. package/src/components/Chart/stories/args/radarChartArgs.ts +26 -0
  121. package/src/components/Chart/stories/args/radialBarArgs.ts +36 -0
  122. package/src/components/Chart/stories/args/radialBarChartArgs.ts +16 -0
  123. package/src/components/Chart/stories/args/rectangleArgs.ts +35 -0
  124. package/src/components/Chart/stories/args/referenceSharedArgs.ts +75 -0
  125. package/src/components/Chart/stories/args/sectorArgs.ts +106 -0
  126. package/src/components/Chart/stories/args/sharedAxisArgs.ts +332 -0
  127. package/src/components/Chart/stories/args/stylesArgs.ts +258 -0
  128. package/src/components/Chart/stories/args/textArgs.ts +97 -0
  129. package/src/components/Chart/stories/args/tooltipArgs.ts +41 -0
  130. package/src/components/Chart/stories/args/types.ts +23 -0
  131. package/src/components/Chart/stories/args/xAxisArgs.ts +109 -0
  132. package/src/components/Chart/stories/args/yAxisArgs.ts +73 -0
  133. package/src/components/Chart/stories/examples/AreaChart.tsx +156 -0
  134. package/src/components/Chart/stories/examples/BarChart.tsx +425 -0
  135. package/src/components/Chart/stories/examples/LineChart.tsx +144 -0
  136. package/src/components/Chart/stories/examples/PieChart.tsx +238 -0
  137. package/src/components/Chart/stories/examples/RadarChart.tsx +261 -0
  138. package/src/components/Chart/stories/examples/RadialChart.tsx +239 -0
  139. package/src/components/Chart/stories/examples/Tooltip.tsx +68 -0
  140. package/src/components/Chart/stories/helpers/index.tsx +75 -0
  141. package/src/components/Chart/types.ts +39 -0
  142. package/src/components/DatetimePicker/DatetimeGrid.tsx +59 -0
  143. package/src/components/DatetimePicker/DatetimePicker.tsx +59 -0
  144. package/src/components/DatetimePicker/constants.ts +102 -0
  145. package/src/components/DatetimePicker/index.ts +1 -0
  146. package/src/components/DatetimePicker/types.ts +36 -0
  147. package/src/components/Form/DatetimeInput/DatetimeCalendar.tsx +68 -0
  148. package/src/components/Form/DatetimeInput/DatetimeInput.tsx +90 -0
  149. package/src/components/Form/DatetimeInput/DatetimeInputContext.tsx +4 -0
  150. package/src/components/Form/DatetimeInput/NaturalLanguageInput.tsx +73 -0
  151. package/src/components/Form/DatetimeInput/TimePicker.tsx +202 -0
  152. package/src/components/Form/DatetimeInput/constants.ts +135 -0
  153. package/src/components/Form/DatetimeInput/helpers.ts +93 -0
  154. package/src/components/Form/DatetimeInput/hooks/index.ts +1 -0
  155. package/src/components/Form/DatetimeInput/hooks/useDateInput/index.ts +1 -0
  156. package/src/components/Form/DatetimeInput/hooks/useDateInput/useDateInput.ts +10 -0
  157. package/src/components/Form/DatetimeInput/index.ts +1 -0
  158. package/src/components/Form/DatetimeInput/types.ts +36 -0
  159. package/src/components/Form/MultiSelect/MultiSelect.tsx +348 -0
  160. package/src/components/Form/MultiSelect/MultiSelectContext.tsx +4 -0
  161. package/src/components/Form/MultiSelect/constants.ts +103 -0
  162. package/src/components/Form/MultiSelect/hooks/index.ts +1 -0
  163. package/src/components/Form/MultiSelect/hooks/useMultiSelect/index.ts +1 -0
  164. package/src/components/Form/MultiSelect/hooks/useMultiSelect/useMultiSelect.ts +10 -0
  165. package/src/components/Form/MultiSelect/index.ts +1 -0
  166. package/src/components/Form/MultiSelect/types.ts +46 -0
  167. package/src/components/Form/TagsInput/TagsInput.tsx +278 -0
  168. package/src/components/Form/TagsInput/constants.ts +87 -0
  169. package/src/components/Form/TagsInput/index.ts +1 -0
  170. package/src/components/Form/TagsInput/types.ts +10 -0
  171. package/src/components/Form/index.ts +2 -0
  172. package/src/index.ts +1 -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,59 @@
1
+ import { forwardRef, Fragment } from "react";
2
+ import type { DatetimeGridProps } from "./types";
3
+ import { cn } from "../../utilities";
4
+ import { Input } from "../Form";
5
+ import {
6
+ getDatetimeGridClasses,
7
+ getDatetimeInputClasses,
8
+ getDatetimeSeparatorClasses,
9
+ } from "./constants";
10
+
11
+ export const DatetimeGrid = forwardRef<HTMLDivElement, DatetimeGridProps>(
12
+ ({ format, disabled, className, timescape, placeholders, variant, outline, wide, size }, ref) => {
13
+ return (
14
+ <div
15
+ className={cn(
16
+ getDatetimeGridClasses({ size, wide, outline, variant, disabled }),
17
+ className
18
+ )}
19
+ {...timescape.getRootProps()}
20
+ ref={ref}
21
+ >
22
+ {format?.length
23
+ ? format.map((group, i) => (
24
+ <Fragment key={`group-${i}`}>
25
+ {group?.length
26
+ ? group.map((unit, j) => (
27
+ <Fragment key={unit}>
28
+ <Input
29
+ size={size}
30
+ disabled={disabled}
31
+ className={cn(getDatetimeInputClasses({ size, unit }))}
32
+ {...timescape.getInputProps(unit)}
33
+ placeholder={placeholders[unit]}
34
+ />
35
+ {i === 0 && j < group.length - 1 ? (
36
+ // date separator
37
+ <span className={cn(getDatetimeSeparatorClasses())}>/</span>
38
+ ) : (
39
+ j < group.length - 2 && (
40
+ // time separator
41
+ <span className={cn(getDatetimeSeparatorClasses())}>:</span>
42
+ )
43
+ )}
44
+ </Fragment>
45
+ ))
46
+ : null}
47
+ {format[1]?.length && !i ? (
48
+ // date-time separator - only if both date and time are present
49
+ <span className={cn(getDatetimeSeparatorClasses(), "opacity-30 text-xl")}>|</span>
50
+ ) : null}
51
+ </Fragment>
52
+ ))
53
+ : null}
54
+ </div>
55
+ );
56
+ }
57
+ );
58
+
59
+ DatetimeGrid.displayName = "DatetimeGrid";
@@ -0,0 +1,59 @@
1
+ "use client";
2
+
3
+ import { forwardRef, useCallback } from "react";
4
+ import { useTimescape } from "timescape/react";
5
+ import type { DatetimePickerProps } from "./types";
6
+ import { DEFAULTS, INPUT_PLACEHOLDERS } from "./constants";
7
+ import { DatetimeGrid } from "./DatetimeGrid";
8
+
9
+ export const DatetimePicker = forwardRef<HTMLDivElement, DatetimePickerProps>(
10
+ (
11
+ {
12
+ format = DEFAULTS,
13
+ placeholders,
14
+ onChange,
15
+ className,
16
+ date,
17
+ minDate,
18
+ maxDate,
19
+ hour12 = true,
20
+ digits,
21
+ wrapAround,
22
+ snapToStep,
23
+ ...props
24
+ },
25
+ ref
26
+ ) => {
27
+ const handleDateChange = useCallback(
28
+ (date: Date | undefined) => {
29
+ if (onChange) {
30
+ onChange(date);
31
+ }
32
+ },
33
+ [onChange]
34
+ );
35
+ const timescape = useTimescape({
36
+ date,
37
+ onChangeDate: handleDateChange,
38
+ minDate,
39
+ maxDate,
40
+ hour12,
41
+ digits,
42
+ wrapAround,
43
+ snapToStep,
44
+ });
45
+
46
+ return (
47
+ <DatetimeGrid
48
+ format={format}
49
+ className={className}
50
+ timescape={timescape}
51
+ placeholders={placeholders ?? INPUT_PLACEHOLDERS}
52
+ ref={ref}
53
+ {...props}
54
+ />
55
+ );
56
+ }
57
+ );
58
+
59
+ DatetimePicker.displayName = "DatetimePicker";
@@ -0,0 +1,102 @@
1
+ import type { DateFormat, DatetimeFormatDefaults, InputPlaceholders, TimeFormat } from "./types";
2
+ import { cva } from "../../libs";
3
+
4
+ export const DEFAULTS = [
5
+ ["days", "months", "years"],
6
+ ["hours", "minutes", "am/pm"],
7
+ ] as DatetimeFormatDefaults;
8
+
9
+ export const INPUT_PLACEHOLDERS: InputPlaceholders = {
10
+ months: "MM",
11
+ days: "DD",
12
+ years: "YYYY",
13
+ hours: "HH",
14
+ minutes: "MM",
15
+ seconds: "SS",
16
+ "am/pm": "AM/PM",
17
+ };
18
+
19
+ export const getDatetimeGridClasses = cva(
20
+ `flex items-center w-fit p-1 rounded-md transition-all duration-100 gap-1 selection:bg-transparent selection:text-base-content
21
+ [&:has(input:focus)]:duration-100 [&:has(input:focus)]:outline [&:has(input:focus)]:outline-2 [&:has(input:focus)]:outline-offset-2 [&:has(input:focus)]:outline-base-content/20
22
+ [&:has(input:focus-within)]:duration-100 [&:has(input:focus-within)]:outline [&:has(input:focus-within)]:outline-2 [&:has(input:focus-within)]:outline-offset-2 [&:has(input:focus-within)]:outline-base-content/20
23
+ `,
24
+ {
25
+ variants: {
26
+ variant: {
27
+ default: "border-0",
28
+ accent: "border border-accent",
29
+ error: "border border-error",
30
+ ghost: "border border-ghost",
31
+ info: "border border-info",
32
+ primary: "border border-primary",
33
+ secondary: "border border-secondary",
34
+ success: "border border-success",
35
+ warning: "border border-warning",
36
+ },
37
+ outline: {
38
+ true: "border",
39
+ },
40
+ disabled: {
41
+ true: "border-base-300",
42
+ },
43
+ wide: {
44
+ true: "w-full",
45
+ },
46
+ size: {
47
+ xs: "h-6 leading-relaxed px-2 text-xs",
48
+ sm: "h-8 leading-8 px-3 text-sm",
49
+ md: "h-12 leading-loose px-4 text-sm",
50
+ lg: "h-16 leading-loose px-5 text-lg",
51
+ },
52
+ },
53
+ compoundVariants: [
54
+ {
55
+ size: undefined,
56
+ className: "min-h-fit h-10",
57
+ },
58
+ {
59
+ variant: undefined,
60
+ outline: true,
61
+ className: "border-neutral-content",
62
+ },
63
+ {
64
+ variant: "default",
65
+ outline: true,
66
+ className: "border-base-content",
67
+ },
68
+ ],
69
+ }
70
+ );
71
+
72
+ export const getDatetimeSeparatorClasses = cva("text-xs text-gray-400");
73
+
74
+ export const getDatetimeInputClasses = cva(
75
+ "min-w-8 p-1 inline tabular-nums h-fit border-none outline-none select-none content-box caret-transparent rounded-sm min-w-8 text-center focus:outline-none focus:bg-base-content/20 focus-visible:ring-0 focus-visible:outline-none",
76
+ {
77
+ variants: {
78
+ size: {
79
+ xs: "max-h-4",
80
+ sm: "max-h-6",
81
+ md: "",
82
+ lg: "min-w-8",
83
+ },
84
+ unit: {
85
+ years: "min-w-12",
86
+ "am/pm": "bg-base-content/15",
87
+ } as Record<DateFormat | TimeFormat, string>,
88
+ },
89
+ compoundVariants: [
90
+ {
91
+ size: "lg",
92
+ unit: "years",
93
+ className: "min-w-14",
94
+ },
95
+ {
96
+ size: "lg",
97
+ unit: "am/pm",
98
+ className: "min-w-10",
99
+ },
100
+ ],
101
+ }
102
+ );
@@ -0,0 +1 @@
1
+ export { DatetimePicker } from "./DatetimePicker";
@@ -0,0 +1,36 @@
1
+ import type { Options } from "timescape/react";
2
+ import { useTimescape } from "timescape/react";
3
+ import { type VariantProps } from "../../libs";
4
+ import { getDatetimeGridClasses } from "./constants";
5
+
6
+ export type DateFormat = "days" | "months" | "years";
7
+
8
+ export type TimeFormat = "hours" | "minutes" | "seconds" | "am/pm";
9
+
10
+ type TimescapeReturn = ReturnType<typeof useTimescape>;
11
+ type DatetimeArray<T extends DateFormat | TimeFormat> = T[];
12
+
13
+ export type DatetimeFormatDefaults =
14
+ | [DatetimeArray<DateFormat>]
15
+ | [DatetimeArray<TimeFormat>]
16
+ | [DatetimeArray<DateFormat>, DatetimeArray<TimeFormat>]
17
+ | [DatetimeArray<TimeFormat>, DatetimeArray<DateFormat>];
18
+
19
+ export type InputPlaceholders = Record<DateFormat | TimeFormat, string>;
20
+
21
+ type DatetimeGridVariantProps = VariantProps<typeof getDatetimeGridClasses>;
22
+ export type DatetimeGridProps = {
23
+ format: DatetimeFormatDefaults;
24
+ disabled?: boolean;
25
+ className?: string;
26
+ timescape: Pick<TimescapeReturn, "getRootProps" | "getInputProps">;
27
+ placeholders: InputPlaceholders;
28
+ } & DatetimeGridVariantProps;
29
+
30
+ export type DatetimePickerProps = Omit<Options, "onChangeDate"> & {
31
+ format?: DatetimeFormatDefaults;
32
+ disabled?: boolean;
33
+ placeholders?: InputPlaceholders;
34
+ onChange?: Options["onChangeDate"];
35
+ className?: string;
36
+ } & DatetimeGridVariantProps;