@arch-cadre/ui 0.0.10 → 0.0.15

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 (256) hide show
  1. package/build.config.ts +23 -0
  2. package/dist/components/.gitkeep +0 -0
  3. package/dist/components/accordion.cjs +62 -0
  4. package/dist/components/accordion.d.ts +7 -0
  5. package/dist/components/accordion.mjs +58 -0
  6. package/dist/components/alert-dialog.cjs +127 -0
  7. package/dist/components/alert-dialog.d.ts +14 -0
  8. package/dist/components/alert-dialog.mjs +144 -0
  9. package/dist/components/alert.cjs +58 -0
  10. package/dist/components/alert.d.ts +9 -0
  11. package/dist/components/alert.mjs +62 -0
  12. package/dist/components/aspect-ratio.cjs +19 -0
  13. package/dist/components/aspect-ratio.d.ts +4 -0
  14. package/dist/components/aspect-ratio.mjs +9 -0
  15. package/dist/components/avatar.cjs +44 -0
  16. package/dist/components/avatar.d.ts +6 -0
  17. package/dist/components/avatar.mjs +50 -0
  18. package/dist/components/badge.cjs +41 -0
  19. package/dist/components/badge.d.ts +9 -0
  20. package/dist/components/badge.mjs +37 -0
  21. package/dist/components/breadcrumb.cjs +106 -0
  22. package/dist/components/breadcrumb.d.ts +11 -0
  23. package/dist/components/breadcrumb.mjs +105 -0
  24. package/dist/components/button-group.cjs +65 -0
  25. package/dist/components/button-group.d.ts +12 -0
  26. package/dist/components/button-group.mjs +76 -0
  27. package/dist/components/button.cjs +57 -0
  28. package/dist/components/button.d.ts +10 -0
  29. package/dist/components/button.mjs +51 -0
  30. package/dist/components/calendar.cjs +143 -0
  31. package/dist/components/calendar.d.ts +8 -0
  32. package/dist/components/calendar.mjs +191 -0
  33. package/dist/components/card.cjs +86 -0
  34. package/dist/components/card.d.ts +9 -0
  35. package/dist/components/card.mjs +90 -0
  36. package/dist/components/checkbox.cjs +28 -0
  37. package/dist/components/checkbox.d.ts +4 -0
  38. package/dist/components/checkbox.mjs +30 -0
  39. package/dist/components/collapsible.cjs +37 -0
  40. package/dist/components/collapsible.d.ts +6 -0
  41. package/dist/components/collapsible.mjs +31 -0
  42. package/dist/components/command.cjs +125 -0
  43. package/dist/components/command.d.ts +18 -0
  44. package/dist/components/command.mjs +169 -0
  45. package/dist/components/context-menu.cjs +188 -0
  46. package/dist/components/context-menu.d.ts +25 -0
  47. package/dist/components/context-menu.mjs +218 -0
  48. package/dist/components/dialog.cjs +123 -0
  49. package/dist/components/dialog.d.ts +15 -0
  50. package/dist/components/dialog.mjs +130 -0
  51. package/dist/components/drawer.cjs +118 -0
  52. package/dist/components/drawer.d.ts +13 -0
  53. package/dist/components/drawer.mjs +124 -0
  54. package/dist/components/dropdown-menu.cjs +190 -0
  55. package/dist/components/dropdown-menu.d.ts +25 -0
  56. package/dist/components/dropdown-menu.mjs +226 -0
  57. package/dist/components/empty.cjs +92 -0
  58. package/dist/components/empty.d.ts +12 -0
  59. package/dist/components/empty.mjs +102 -0
  60. package/dist/components/field.cjs +173 -0
  61. package/dist/components/field.d.ts +25 -0
  62. package/dist/components/field.mjs +228 -0
  63. package/dist/components/form.cjs +143 -0
  64. package/dist/components/form.d.ts +23 -0
  65. package/dist/components/form.mjs +123 -0
  66. package/dist/components/hover-card.cjs +46 -0
  67. package/dist/components/hover-card.d.ts +6 -0
  68. package/dist/components/hover-card.mjs +35 -0
  69. package/dist/components/input-group.cjs +130 -0
  70. package/dist/components/input-group.d.ts +16 -0
  71. package/dist/components/input-group.mjs +155 -0
  72. package/dist/components/input-otp.cjs +69 -0
  73. package/dist/components/input-otp.d.ts +11 -0
  74. package/dist/components/input-otp.mjs +59 -0
  75. package/dist/components/input.cjs +22 -0
  76. package/dist/components/input.d.ts +3 -0
  77. package/dist/components/input.mjs +19 -0
  78. package/dist/components/item.cjs +168 -0
  79. package/dist/components/item.d.ts +23 -0
  80. package/dist/components/item.mjs +187 -0
  81. package/dist/components/kbd.cjs +31 -0
  82. package/dist/components/kbd.d.ts +4 -0
  83. package/dist/components/kbd.mjs +28 -0
  84. package/dist/components/label.cjs +22 -0
  85. package/dist/components/label.d.ts +4 -0
  86. package/dist/components/label.mjs +21 -0
  87. package/dist/components/language-switcher.cjs +43 -0
  88. package/dist/components/language-switcher.d.ts +2 -0
  89. package/dist/components/language-switcher.mjs +30 -0
  90. package/dist/components/menubar.cjs +207 -0
  91. package/dist/components/menubar.d.ts +26 -0
  92. package/dist/components/menubar.mjs +246 -0
  93. package/dist/components/navigation-menu.cjs +113 -0
  94. package/dist/components/navigation-menu.d.ts +14 -0
  95. package/dist/components/navigation-menu.mjs +166 -0
  96. package/dist/components/pagination.cjs +106 -0
  97. package/dist/components/pagination.d.ts +15 -0
  98. package/dist/components/pagination.mjs +116 -0
  99. package/dist/components/popover.cjs +53 -0
  100. package/dist/components/popover.d.ts +7 -0
  101. package/dist/components/popover.mjs +40 -0
  102. package/dist/components/progress.cjs +29 -0
  103. package/dist/components/progress.d.ts +4 -0
  104. package/dist/components/progress.mjs +30 -0
  105. package/dist/components/radio-group.cjs +39 -0
  106. package/dist/components/radio-group.d.ts +5 -0
  107. package/dist/components/radio-group.mjs +43 -0
  108. package/dist/components/scroll-area.cjs +45 -0
  109. package/dist/components/scroll-area.d.ts +7 -0
  110. package/dist/components/scroll-area.mjs +59 -0
  111. package/dist/components/select.cjs +140 -0
  112. package/dist/components/select.d.ts +15 -0
  113. package/dist/components/select.mjs +173 -0
  114. package/dist/components/separator.cjs +26 -0
  115. package/dist/components/separator.d.ts +4 -0
  116. package/dist/components/separator.mjs +25 -0
  117. package/dist/components/sheet.cjs +120 -0
  118. package/dist/components/sheet.d.ts +13 -0
  119. package/dist/components/sheet.mjs +119 -0
  120. package/dist/components/sidebar.cjs +508 -0
  121. package/dist/components/sidebar.d.ts +69 -0
  122. package/dist/components/sidebar.mjs +635 -0
  123. package/dist/components/skeleton.cjs +20 -0
  124. package/dist/components/skeleton.d.ts +3 -0
  125. package/dist/components/skeleton.mjs +13 -0
  126. package/dist/components/slider.cjs +43 -0
  127. package/dist/components/slider.d.ts +4 -0
  128. package/dist/components/slider.mjs +59 -0
  129. package/dist/components/sonner.cjs +49 -0
  130. package/dist/components/sonner.d.ts +4 -0
  131. package/dist/components/sonner.mjs +36 -0
  132. package/dist/components/spinner.cjs +22 -0
  133. package/dist/components/spinner.d.ts +3 -0
  134. package/dist/components/spinner.mjs +15 -0
  135. package/dist/components/switch.cjs +25 -0
  136. package/dist/components/switch.d.ts +4 -0
  137. package/dist/components/switch.mjs +30 -0
  138. package/dist/components/table.cjs +101 -0
  139. package/dist/components/table.d.ts +10 -0
  140. package/dist/components/table.mjs +115 -0
  141. package/dist/components/tabs.cjs +55 -0
  142. package/dist/components/tabs.d.ts +7 -0
  143. package/dist/components/tabs.mjs +63 -0
  144. package/dist/components/textarea.cjs +20 -0
  145. package/dist/components/textarea.d.ts +3 -0
  146. package/dist/components/textarea.mjs +16 -0
  147. package/dist/components/toggle-group.cjs +65 -0
  148. package/dist/components/toggle-group.d.ts +9 -0
  149. package/dist/components/toggle-group.mjs +65 -0
  150. package/dist/components/toggle.cjs +47 -0
  151. package/dist/components/toggle.d.ts +9 -0
  152. package/dist/components/toggle.mjs +41 -0
  153. package/dist/components/tooltip.cjs +56 -0
  154. package/dist/components/tooltip.d.ts +7 -0
  155. package/dist/components/tooltip.mjs +49 -0
  156. package/dist/hooks/.gitkeep +0 -0
  157. package/dist/hooks/use-mobile.cjs +23 -0
  158. package/dist/hooks/use-mobile.d.ts +1 -0
  159. package/dist/hooks/use-mobile.mjs +17 -0
  160. package/dist/hooks/use-user.cjs +21 -0
  161. package/dist/hooks/use-user.d.ts +12 -0
  162. package/dist/hooks/use-user.mjs +12 -0
  163. package/dist/index.cjs +155 -0
  164. package/dist/index.d.ts +13 -0
  165. package/dist/index.mjs +13 -0
  166. package/dist/lib/utils.cjs +11 -0
  167. package/dist/lib/utils.d.ts +2 -0
  168. package/dist/lib/utils.mjs +5 -0
  169. package/dist/logo.cjs +49 -0
  170. package/dist/logo.d.ts +15 -0
  171. package/dist/logo.mjs +32 -0
  172. package/dist/postcss.config.cjs +13 -0
  173. package/dist/postcss.config.d.mts +3 -0
  174. package/dist/postcss.config.mjs +6 -0
  175. package/dist/providers/auth-provider.cjs +44 -0
  176. package/dist/providers/auth-provider.d.ts +15 -0
  177. package/dist/providers/auth-provider.mjs +37 -0
  178. package/dist/providers/index.cjs +47 -0
  179. package/dist/providers/index.d.ts +7 -0
  180. package/dist/providers/index.mjs +33 -0
  181. package/dist/shared/access-denied.cjs +38 -0
  182. package/dist/shared/access-denied.d.ts +2 -0
  183. package/dist/shared/access-denied.mjs +12 -0
  184. package/dist/shared/loader.cjs +95 -0
  185. package/dist/shared/loader.d.ts +11 -0
  186. package/dist/shared/loader.mjs +98 -0
  187. package/dist/shared/page-loader.cjs +23 -0
  188. package/dist/shared/page-loader.d.ts +7 -0
  189. package/dist/shared/page-loader.mjs +6 -0
  190. package/dist/shared/scroll-fade-effect.cjs +21 -0
  191. package/dist/shared/scroll-fade-effect.d.ts +4 -0
  192. package/dist/shared/scroll-fade-effect.mjs +20 -0
  193. package/dist/styles/globals.css +1 -0
  194. package/package.json +58 -49
  195. package/scripts/switchToDist.js +55 -0
  196. package/scripts/switchToSrc.js +52 -0
  197. package/src/components/accordion.tsx +2 -2
  198. package/src/components/alert-dialog.tsx +1 -1
  199. package/src/components/alert.tsx +1 -1
  200. package/src/components/aspect-ratio.tsx +2 -1
  201. package/src/components/avatar.tsx +1 -1
  202. package/src/components/badge.tsx +3 -3
  203. package/src/components/breadcrumb.tsx +5 -3
  204. package/src/components/button-group.tsx +4 -2
  205. package/src/components/button.tsx +3 -3
  206. package/src/components/calendar.tsx +2 -2
  207. package/src/components/checkbox.tsx +2 -2
  208. package/src/components/collapsible.tsx +2 -1
  209. package/src/components/command.tsx +1 -1
  210. package/src/components/context-menu.tsx +2 -2
  211. package/src/components/dialog.tsx +2 -2
  212. package/src/components/dropdown-menu.tsx +2 -2
  213. package/src/components/empty.tsx +1 -0
  214. package/src/components/field.tsx +5 -2
  215. package/src/components/form.tsx +9 -7
  216. package/src/components/hover-card.tsx +1 -1
  217. package/src/components/input-group.tsx +1 -1
  218. package/src/components/input-otp.tsx +1 -1
  219. package/src/components/item.tsx +3 -3
  220. package/src/components/kbd.tsx +1 -0
  221. package/src/components/label.tsx +1 -1
  222. package/src/components/language-switcher.tsx +16 -17
  223. package/src/components/menubar.tsx +2 -2
  224. package/src/components/navigation-menu.tsx +2 -2
  225. package/src/components/pagination.tsx +5 -2
  226. package/src/components/popover.tsx +1 -1
  227. package/src/components/progress.tsx +1 -1
  228. package/src/components/radio-group.tsx +2 -2
  229. package/src/components/scroll-area.tsx +1 -1
  230. package/src/components/select.tsx +2 -2
  231. package/src/components/separator.tsx +1 -1
  232. package/src/components/sheet.tsx +2 -2
  233. package/src/components/sidebar.tsx +6 -6
  234. package/src/components/skeleton.tsx +1 -0
  235. package/src/components/slider.tsx +1 -1
  236. package/src/components/sonner.tsx +1 -0
  237. package/src/components/spinner.tsx +1 -0
  238. package/src/components/switch.tsx +1 -1
  239. package/src/components/tabs.tsx +1 -1
  240. package/src/components/toggle-group.tsx +2 -2
  241. package/src/components/toggle.tsx +2 -2
  242. package/src/components/tooltip.tsx +1 -1
  243. package/src/hooks/use-user.ts +2 -2
  244. package/src/index.ts +8 -5
  245. package/src/logo.tsx +1 -0
  246. package/src/providers/auth-provider.tsx +7 -6
  247. package/src/providers/index.tsx +1 -0
  248. package/src/shared/access-denied.tsx +1 -0
  249. package/src/shared/loader.tsx +2 -1
  250. package/src/shared/page-loader.tsx +1 -0
  251. package/src/shared/scroll-fade-effect.tsx +1 -1
  252. package/src/styles/globals.css +258 -244
  253. package/biome.json +0 -38
  254. package/src/components/carousel.tsx +0 -241
  255. package/src/components/chart.tsx +0 -357
  256. package/tsconfig.build.json +0 -16
@@ -1,241 +0,0 @@
1
- "use client";
2
-
3
- import * as React from "react";
4
- import useEmblaCarousel, {
5
- type UseEmblaCarouselType,
6
- } from "embla-carousel-react";
7
- import { ArrowLeft, ArrowRight } from "lucide-react";
8
-
9
- import { cn } from "../lib/utils";
10
- import { Button } from "./button";
11
-
12
- type CarouselApi = UseEmblaCarouselType[1];
13
- type UseCarouselParameters = Parameters<typeof useEmblaCarousel>;
14
- type CarouselOptions = UseCarouselParameters[0];
15
- type CarouselPlugin = UseCarouselParameters[1];
16
-
17
- type CarouselProps = {
18
- opts?: CarouselOptions;
19
- plugins?: CarouselPlugin;
20
- orientation?: "horizontal" | "vertical";
21
- setApi?: (api: CarouselApi) => void;
22
- };
23
-
24
- type CarouselContextProps = {
25
- carouselRef: ReturnType<typeof useEmblaCarousel>[0];
26
- api: ReturnType<typeof useEmblaCarousel>[1];
27
- scrollPrev: () => void;
28
- scrollNext: () => void;
29
- canScrollPrev: boolean;
30
- canScrollNext: boolean;
31
- } & CarouselProps;
32
-
33
- const CarouselContext = React.createContext<CarouselContextProps | null>(null);
34
-
35
- function useCarousel() {
36
- const context = React.useContext(CarouselContext);
37
-
38
- if (!context) {
39
- throw new Error("useCarousel must be used within a <Carousel />");
40
- }
41
-
42
- return context;
43
- }
44
-
45
- function Carousel({
46
- orientation = "horizontal",
47
- opts,
48
- setApi,
49
- plugins,
50
- className,
51
- children,
52
- ...props
53
- }: React.ComponentProps<"div"> & CarouselProps) {
54
- const [carouselRef, api] = useEmblaCarousel(
55
- {
56
- ...opts,
57
- axis: orientation === "horizontal" ? "x" : "y",
58
- },
59
- plugins,
60
- );
61
- const [canScrollPrev, setCanScrollPrev] = React.useState(false);
62
- const [canScrollNext, setCanScrollNext] = React.useState(false);
63
-
64
- const onSelect = React.useCallback((api: CarouselApi) => {
65
- if (!api) return;
66
- setCanScrollPrev(api.canScrollPrev());
67
- setCanScrollNext(api.canScrollNext());
68
- }, []);
69
-
70
- const scrollPrev = React.useCallback(() => {
71
- api?.scrollPrev();
72
- }, [api]);
73
-
74
- const scrollNext = React.useCallback(() => {
75
- api?.scrollNext();
76
- }, [api]);
77
-
78
- const handleKeyDown = React.useCallback(
79
- (event: React.KeyboardEvent<HTMLDivElement>) => {
80
- if (event.key === "ArrowLeft") {
81
- event.preventDefault();
82
- scrollPrev();
83
- } else if (event.key === "ArrowRight") {
84
- event.preventDefault();
85
- scrollNext();
86
- }
87
- },
88
- [scrollPrev, scrollNext],
89
- );
90
-
91
- React.useEffect(() => {
92
- if (!api || !setApi) return;
93
- setApi(api);
94
- }, [api, setApi]);
95
-
96
- React.useEffect(() => {
97
- if (!api) return;
98
- onSelect(api);
99
- api.on("reInit", onSelect);
100
- api.on("select", onSelect);
101
-
102
- return () => {
103
- api?.off("select", onSelect);
104
- };
105
- }, [api, onSelect]);
106
-
107
- return (
108
- <CarouselContext.Provider
109
- value={{
110
- carouselRef,
111
- api: api,
112
- opts,
113
- orientation:
114
- orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
115
- scrollPrev,
116
- scrollNext,
117
- canScrollPrev,
118
- canScrollNext,
119
- }}
120
- >
121
- <div
122
- onKeyDownCapture={handleKeyDown}
123
- className={cn("relative", className)}
124
- role="region"
125
- aria-roledescription="carousel"
126
- data-slot="carousel"
127
- {...props}
128
- >
129
- {children}
130
- </div>
131
- </CarouselContext.Provider>
132
- );
133
- }
134
-
135
- function CarouselContent({ className, ...props }: React.ComponentProps<"div">) {
136
- const { carouselRef, orientation } = useCarousel();
137
-
138
- return (
139
- <div
140
- ref={carouselRef}
141
- className="overflow-hidden"
142
- data-slot="carousel-content"
143
- >
144
- <div
145
- className={cn(
146
- "flex",
147
- orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col",
148
- className,
149
- )}
150
- {...props}
151
- />
152
- </div>
153
- );
154
- }
155
-
156
- function CarouselItem({ className, ...props }: React.ComponentProps<"div">) {
157
- const { orientation } = useCarousel();
158
-
159
- return (
160
- <div
161
- role="group"
162
- aria-roledescription="slide"
163
- data-slot="carousel-item"
164
- className={cn(
165
- "min-w-0 shrink-0 grow-0 basis-full",
166
- orientation === "horizontal" ? "pl-4" : "pt-4",
167
- className,
168
- )}
169
- {...props}
170
- />
171
- );
172
- }
173
-
174
- function CarouselPrevious({
175
- className,
176
- variant = "outline",
177
- size = "icon",
178
- ...props
179
- }: React.ComponentProps<typeof Button>) {
180
- const { orientation, scrollPrev, canScrollPrev } = useCarousel();
181
-
182
- return (
183
- <Button
184
- data-slot="carousel-previous"
185
- variant={variant}
186
- size={size}
187
- className={cn(
188
- "absolute size-8 rounded-full",
189
- orientation === "horizontal"
190
- ? "top-1/2 -left-12 -translate-y-1/2"
191
- : "-top-12 left-1/2 -translate-x-1/2 rotate-90",
192
- className,
193
- )}
194
- disabled={!canScrollPrev}
195
- onClick={scrollPrev}
196
- {...props}
197
- >
198
- <ArrowLeft />
199
- <span className="sr-only">Previous slide</span>
200
- </Button>
201
- );
202
- }
203
-
204
- function CarouselNext({
205
- className,
206
- variant = "outline",
207
- size = "icon",
208
- ...props
209
- }: React.ComponentProps<typeof Button>) {
210
- const { orientation, scrollNext, canScrollNext } = useCarousel();
211
-
212
- return (
213
- <Button
214
- data-slot="carousel-next"
215
- variant={variant}
216
- size={size}
217
- className={cn(
218
- "absolute size-8 rounded-full",
219
- orientation === "horizontal"
220
- ? "top-1/2 -right-12 -translate-y-1/2"
221
- : "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
222
- className,
223
- )}
224
- disabled={!canScrollNext}
225
- onClick={scrollNext}
226
- {...props}
227
- >
228
- <ArrowRight />
229
- <span className="sr-only">Next slide</span>
230
- </Button>
231
- );
232
- }
233
-
234
- export {
235
- type CarouselApi,
236
- Carousel,
237
- CarouselContent,
238
- CarouselItem,
239
- CarouselPrevious,
240
- CarouselNext,
241
- };
@@ -1,357 +0,0 @@
1
- "use client";
2
-
3
- import * as React from "react";
4
- import * as RechartsPrimitive from "recharts";
5
-
6
- import { cn } from "../lib/utils";
7
-
8
- // Format: { THEME_NAME: CSS_SELECTOR }
9
- const THEMES = { light: "", dark: ".dark" } as const;
10
-
11
- export type ChartConfig = {
12
- [k in string]: {
13
- label?: React.ReactNode;
14
- icon?: React.ComponentType;
15
- } & (
16
- | { color?: string; theme?: never }
17
- | { color?: never; theme: Record<keyof typeof THEMES, string> }
18
- );
19
- };
20
-
21
- type ChartContextProps = {
22
- config: ChartConfig;
23
- };
24
-
25
- const ChartContext = React.createContext<ChartContextProps | null>(null);
26
-
27
- function useChart() {
28
- const context = React.useContext(ChartContext);
29
-
30
- if (!context) {
31
- throw new Error("useChart must be used within a <ChartContainer />");
32
- }
33
-
34
- return context;
35
- }
36
-
37
- function ChartContainer({
38
- id,
39
- className,
40
- children,
41
- config,
42
- ...props
43
- }: React.ComponentProps<"div"> & {
44
- config: ChartConfig;
45
- children: React.ComponentProps<
46
- typeof RechartsPrimitive.ResponsiveContainer
47
- >["children"];
48
- }) {
49
- const uniqueId = React.useId();
50
- const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`;
51
-
52
- return (
53
- <ChartContext.Provider value={{ config }}>
54
- <div
55
- data-slot="chart"
56
- data-chart={chartId}
57
- className={cn(
58
- "[&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border flex aspect-video justify-center text-xs [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden",
59
- className,
60
- )}
61
- {...props}
62
- >
63
- <ChartStyle id={chartId} config={config} />
64
- <RechartsPrimitive.ResponsiveContainer>
65
- {children}
66
- </RechartsPrimitive.ResponsiveContainer>
67
- </div>
68
- </ChartContext.Provider>
69
- );
70
- }
71
-
72
- const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
73
- const colorConfig = Object.entries(config).filter(
74
- ([, config]) => config.theme || config.color,
75
- );
76
-
77
- if (!colorConfig.length) {
78
- return null;
79
- }
80
-
81
- return (
82
- <style
83
- dangerouslySetInnerHTML={{
84
- __html: Object.entries(THEMES)
85
- .map(
86
- ([theme, prefix]) => `
87
- ${prefix} [data-chart=${id}] {
88
- ${colorConfig
89
- .map(([key, itemConfig]) => {
90
- const color =
91
- itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ||
92
- itemConfig.color;
93
- return color ? ` --color-${key}: ${color};` : null;
94
- })
95
- .join("\n")}
96
- }
97
- `,
98
- )
99
- .join("\n"),
100
- }}
101
- />
102
- );
103
- };
104
-
105
- const ChartTooltip = RechartsPrimitive.Tooltip;
106
-
107
- function ChartTooltipContent({
108
- active,
109
- payload,
110
- className,
111
- indicator = "dot",
112
- hideLabel = false,
113
- hideIndicator = false,
114
- label,
115
- labelFormatter,
116
- labelClassName,
117
- formatter,
118
- color,
119
- nameKey,
120
- labelKey,
121
- }: React.ComponentProps<typeof RechartsPrimitive.Tooltip> &
122
- React.ComponentProps<"div"> & {
123
- hideLabel?: boolean;
124
- hideIndicator?: boolean;
125
- indicator?: "line" | "dot" | "dashed";
126
- nameKey?: string;
127
- labelKey?: string;
128
- }) {
129
- const { config } = useChart();
130
-
131
- const tooltipLabel = React.useMemo(() => {
132
- if (hideLabel || !payload?.length) {
133
- return null;
134
- }
135
-
136
- const [item] = payload;
137
- const key = `${labelKey || item?.dataKey || item?.name || "value"}`;
138
- const itemConfig = getPayloadConfigFromPayload(config, item, key);
139
- const value =
140
- !labelKey && typeof label === "string"
141
- ? config[label as keyof typeof config]?.label || label
142
- : itemConfig?.label;
143
-
144
- if (labelFormatter) {
145
- return (
146
- <div className={cn("font-medium", labelClassName)}>
147
- {labelFormatter(value, payload)}
148
- </div>
149
- );
150
- }
151
-
152
- if (!value) {
153
- return null;
154
- }
155
-
156
- return <div className={cn("font-medium", labelClassName)}>{value}</div>;
157
- }, [
158
- label,
159
- labelFormatter,
160
- payload,
161
- hideLabel,
162
- labelClassName,
163
- config,
164
- labelKey,
165
- ]);
166
-
167
- if (!active || !payload?.length) {
168
- return null;
169
- }
170
-
171
- const nestLabel = payload.length === 1 && indicator !== "dot";
172
-
173
- return (
174
- <div
175
- className={cn(
176
- "border-border/50 bg-background grid min-w-[8rem] items-start gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs shadow-xl",
177
- className,
178
- )}
179
- >
180
- {!nestLabel ? tooltipLabel : null}
181
- <div className="grid gap-1.5">
182
- {payload
183
- .filter((item) => item.type !== "none")
184
- .map((item, index) => {
185
- const key = `${nameKey || item.name || item.dataKey || "value"}`;
186
- const itemConfig = getPayloadConfigFromPayload(config, item, key);
187
- const indicatorColor = color || item.payload.fill || item.color;
188
-
189
- return (
190
- <div
191
- key={item.dataKey}
192
- className={cn(
193
- "[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5",
194
- indicator === "dot" && "items-center",
195
- )}
196
- >
197
- {formatter && item?.value !== undefined && item.name ? (
198
- formatter(item.value, item.name, item, index, item.payload)
199
- ) : (
200
- <>
201
- {itemConfig?.icon ? (
202
- <itemConfig.icon />
203
- ) : (
204
- !hideIndicator && (
205
- <div
206
- className={cn(
207
- "shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)",
208
- {
209
- "h-2.5 w-2.5": indicator === "dot",
210
- "w-1": indicator === "line",
211
- "w-0 border-[1.5px] border-dashed bg-transparent":
212
- indicator === "dashed",
213
- "my-0.5": nestLabel && indicator === "dashed",
214
- },
215
- )}
216
- style={
217
- {
218
- "--color-bg": indicatorColor,
219
- "--color-border": indicatorColor,
220
- } as React.CSSProperties
221
- }
222
- />
223
- )
224
- )}
225
- <div
226
- className={cn(
227
- "flex flex-1 justify-between leading-none",
228
- nestLabel ? "items-end" : "items-center",
229
- )}
230
- >
231
- <div className="grid gap-1.5">
232
- {nestLabel ? tooltipLabel : null}
233
- <span className="text-muted-foreground">
234
- {itemConfig?.label || item.name}
235
- </span>
236
- </div>
237
- {item.value && (
238
- <span className="text-foreground font-mono font-medium tabular-nums">
239
- {item.value.toLocaleString()}
240
- </span>
241
- )}
242
- </div>
243
- </>
244
- )}
245
- </div>
246
- );
247
- })}
248
- </div>
249
- </div>
250
- );
251
- }
252
-
253
- const ChartLegend = RechartsPrimitive.Legend;
254
-
255
- function ChartLegendContent({
256
- className,
257
- hideIcon = false,
258
- payload,
259
- verticalAlign = "bottom",
260
- nameKey,
261
- }: React.ComponentProps<"div"> &
262
- Pick<RechartsPrimitive.LegendProps, "payload" | "verticalAlign"> & {
263
- hideIcon?: boolean;
264
- nameKey?: string;
265
- }) {
266
- const { config } = useChart();
267
-
268
- if (!payload?.length) {
269
- return null;
270
- }
271
-
272
- return (
273
- <div
274
- className={cn(
275
- "flex items-center justify-center gap-4",
276
- verticalAlign === "top" ? "pb-3" : "pt-3",
277
- className,
278
- )}
279
- >
280
- {payload
281
- .filter((item) => item.type !== "none")
282
- .map((item) => {
283
- const key = `${nameKey || item.dataKey || "value"}`;
284
- const itemConfig = getPayloadConfigFromPayload(config, item, key);
285
-
286
- return (
287
- <div
288
- key={item.value}
289
- className={cn(
290
- "[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3",
291
- )}
292
- >
293
- {itemConfig?.icon && !hideIcon ? (
294
- <itemConfig.icon />
295
- ) : (
296
- <div
297
- className="h-2 w-2 shrink-0 rounded-[2px]"
298
- style={{
299
- backgroundColor: item.color,
300
- }}
301
- />
302
- )}
303
- {itemConfig?.label}
304
- </div>
305
- );
306
- })}
307
- </div>
308
- );
309
- }
310
-
311
- // Helper to extract item config from a payload.
312
- function getPayloadConfigFromPayload(
313
- config: ChartConfig,
314
- payload: unknown,
315
- key: string,
316
- ) {
317
- if (typeof payload !== "object" || payload === null) {
318
- return undefined;
319
- }
320
-
321
- const payloadPayload =
322
- "payload" in payload &&
323
- typeof payload.payload === "object" &&
324
- payload.payload !== null
325
- ? payload.payload
326
- : undefined;
327
-
328
- let configLabelKey: string = key;
329
-
330
- if (
331
- key in payload &&
332
- typeof payload[key as keyof typeof payload] === "string"
333
- ) {
334
- configLabelKey = payload[key as keyof typeof payload] as string;
335
- } else if (
336
- payloadPayload &&
337
- key in payloadPayload &&
338
- typeof payloadPayload[key as keyof typeof payloadPayload] === "string"
339
- ) {
340
- configLabelKey = payloadPayload[
341
- key as keyof typeof payloadPayload
342
- ] as string;
343
- }
344
-
345
- return configLabelKey in config
346
- ? config[configLabelKey]
347
- : config[key as keyof typeof config];
348
- }
349
-
350
- export {
351
- ChartContainer,
352
- ChartTooltip,
353
- ChartTooltipContent,
354
- ChartLegend,
355
- ChartLegendContent,
356
- ChartStyle,
357
- };
@@ -1,16 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "noEmit": false,
5
- "declaration": true,
6
- "emitDeclarationOnly": false,
7
- "outDir": "dist",
8
- "module": "CommonJS",
9
- "target": "ES2022",
10
- "jsx": "react-jsx",
11
- "moduleResolution": "node",
12
- "isolatedModules": false
13
- },
14
- "include": ["src/**/*"],
15
- "exclude": ["node_modules", "dist", "**/*.test.*"]
16
- }