@tioelvis/next-template 2.4.7 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -42
- package/package.json +44 -92
- package/src/actions/configure-package-json.js +32 -0
- package/src/actions/init-project.js +40 -0
- package/src/actions/init-shadcn-ui.js +48 -0
- package/src/actions/init-theme.js +28 -0
- package/src/actions/init-tioelvis-components.js +42 -0
- package/src/actions/install-main-packages.js +51 -0
- package/src/constants.js +234 -97
- package/src/lib/exception.js +9 -0
- package/src/lib/utils.js +55 -0
- package/src/main.js +158 -229
- package/src/template/eslint.config.mjs +15 -13
- package/src/template/postcss.config.mjs +3 -1
- package/src/template/src/app/globals.css +0 -122
- package/src/template/src/app/layout.tsx +7 -15
- package/src/template/src/app/page.tsx +6 -2
- package/src/template/tsconfig.json +9 -2
- package/src/themes/blue.css +141 -0
- package/src/themes/default.css +141 -0
- package/src/themes/green.css +141 -0
- package/src/themes/orange.css +141 -0
- package/src/themes/red.css +141 -0
- package/src/themes/rose.css +141 -0
- package/src/themes/violet.css +141 -0
- package/src/themes/yellow.css +141 -0
- package/src/tioelvis-components/max-width-wrapper.tsx +21 -0
- package/src/app/components/ui/accordion.json +0 -6
- package/src/app/components/ui/accordion.tsx +0 -64
- package/src/app/components/ui/alert-dialog.json +0 -6
- package/src/app/components/ui/alert-dialog.tsx +0 -157
- package/src/app/components/ui/alert.json +0 -6
- package/src/app/components/ui/alert.tsx +0 -66
- package/src/app/components/ui/aspect-ratio.json +0 -6
- package/src/app/components/ui/aspect-ratio.tsx +0 -11
- package/src/app/components/ui/avatar.json +0 -6
- package/src/app/components/ui/avatar.tsx +0 -53
- package/src/app/components/ui/badge.json +0 -6
- package/src/app/components/ui/badge.tsx +0 -46
- package/src/app/components/ui/breadcrumb.json +0 -6
- package/src/app/components/ui/breadcrumb.tsx +0 -107
- package/src/app/components/ui/button.json +0 -6
- package/src/app/components/ui/button.tsx +0 -58
- package/src/app/components/ui/calendar.json +0 -6
- package/src/app/components/ui/calendar.tsx +0 -213
- package/src/app/components/ui/card.json +0 -6
- package/src/app/components/ui/card.tsx +0 -92
- package/src/app/components/ui/carousel.json +0 -6
- package/src/app/components/ui/carousel.tsx +0 -236
- package/src/app/components/ui/chart.json +0 -6
- package/src/app/components/ui/chart.tsx +0 -347
- package/src/app/components/ui/checkbox.json +0 -6
- package/src/app/components/ui/checkbox.tsx +0 -30
- package/src/app/components/ui/collapsible.json +0 -6
- package/src/app/components/ui/collapsible.tsx +0 -33
- package/src/app/components/ui/command.json +0 -6
- package/src/app/components/ui/command.tsx +0 -182
- package/src/app/components/ui/context-menu.json +0 -6
- package/src/app/components/ui/context-menu.tsx +0 -249
- package/src/app/components/ui/dialog.json +0 -6
- package/src/app/components/ui/dialog.tsx +0 -141
- package/src/app/components/ui/drawer.json +0 -6
- package/src/app/components/ui/drawer.tsx +0 -134
- package/src/app/components/ui/dropdown-menu.json +0 -6
- package/src/app/components/ui/dropdown-menu.tsx +0 -256
- package/src/app/components/ui/form.json +0 -12
- package/src/app/components/ui/form.tsx +0 -167
- package/src/app/components/ui/hover-card.json +0 -6
- package/src/app/components/ui/hover-card.tsx +0 -49
- package/src/app/components/ui/input-otp.json +0 -6
- package/src/app/components/ui/input-otp.tsx +0 -76
- package/src/app/components/ui/input.json +0 -6
- package/src/app/components/ui/input.tsx +0 -21
- package/src/app/components/ui/label.json +0 -6
- package/src/app/components/ui/label.tsx +0 -24
- package/src/app/components/ui/menubar.json +0 -6
- package/src/app/components/ui/menubar.tsx +0 -273
- package/src/app/components/ui/navigation-menu.json +0 -6
- package/src/app/components/ui/navigation-menu.tsx +0 -164
- package/src/app/components/ui/pagination.json +0 -6
- package/src/app/components/ui/pagination.tsx +0 -124
- package/src/app/components/ui/popover.json +0 -6
- package/src/app/components/ui/popover.tsx +0 -55
- package/src/app/components/ui/progress.json +0 -6
- package/src/app/components/ui/progress.tsx +0 -30
- package/src/app/components/ui/radio-group.json +0 -6
- package/src/app/components/ui/radio-group.tsx +0 -43
- package/src/app/components/ui/resizable.json +0 -6
- package/src/app/components/ui/resizable.tsx +0 -55
- package/src/app/components/ui/scroll-area.json +0 -6
- package/src/app/components/ui/scroll-area.tsx +0 -55
- package/src/app/components/ui/select.json +0 -6
- package/src/app/components/ui/select.tsx +0 -179
- package/src/app/components/ui/separator.json +0 -6
- package/src/app/components/ui/separator.tsx +0 -28
- package/src/app/components/ui/sheet.json +0 -6
- package/src/app/components/ui/sheet.tsx +0 -145
- package/src/app/components/ui/sidebar.json +0 -6
- package/src/app/components/ui/sidebar.tsx +0 -718
- package/src/app/components/ui/skeleton.json +0 -6
- package/src/app/components/ui/skeleton.tsx +0 -13
- package/src/app/components/ui/slider.json +0 -6
- package/src/app/components/ui/slider.tsx +0 -61
- package/src/app/components/ui/sonner.json +0 -6
- package/src/app/components/ui/sonner.tsx +0 -25
- package/src/app/components/ui/switch.json +0 -6
- package/src/app/components/ui/switch.tsx +0 -30
- package/src/app/components/ui/table.json +0 -6
- package/src/app/components/ui/table.tsx +0 -115
- package/src/app/components/ui/tabs.json +0 -6
- package/src/app/components/ui/tabs.tsx +0 -66
- package/src/app/components/ui/textarea.json +0 -6
- package/src/app/components/ui/textarea.tsx +0 -18
- package/src/app/components/ui/toggle-group.json +0 -6
- package/src/app/components/ui/toggle-group.tsx +0 -71
- package/src/app/components/ui/toggle.json +0 -6
- package/src/app/components/ui/toggle.tsx +0 -47
- package/src/app/components/ui/tooltip.json +0 -6
- package/src/app/components/ui/tooltip.tsx +0 -60
- package/src/app/hooks/use-mobile.ts +0 -21
- package/src/app/lib/utils.ts +0 -6
- package/src/app/tsconfig.json +0 -27
- package/src/template/components.json +0 -21
- package/src/template/next-env.d.ts +0 -5
- package/src/template/public/.gitkeep +0 -0
- package/src/template/src/lib/constants.ts +0 -1
- package/src/template/src/lib/custom-axios-error.ts +0 -29
- package/src/template/src/lib/request.ts +0 -10
- package/src/template/src/lib/utils.ts +0 -6
- package/src/template/src/providers/query.provider.tsx +0 -12
- package/src/template/src/providers/theme.provider.tsx +0 -8
- package/src/utils.js +0 -113
- /package/src/template/{src/app → public}/favicon.ico +0 -0
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
|
|
3
|
-
import { cn } from "@/lib/utils";
|
|
4
|
-
|
|
5
|
-
function Card({ className, ...props }: React.ComponentProps<"div">) {
|
|
6
|
-
return (
|
|
7
|
-
<div
|
|
8
|
-
data-slot="card"
|
|
9
|
-
className={cn(
|
|
10
|
-
"bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",
|
|
11
|
-
className
|
|
12
|
-
)}
|
|
13
|
-
{...props}
|
|
14
|
-
/>
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
|
19
|
-
return (
|
|
20
|
-
<div
|
|
21
|
-
data-slot="card-header"
|
|
22
|
-
className={cn(
|
|
23
|
-
"@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",
|
|
24
|
-
className
|
|
25
|
-
)}
|
|
26
|
-
{...props}
|
|
27
|
-
/>
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
|
|
32
|
-
return (
|
|
33
|
-
<div
|
|
34
|
-
data-slot="card-title"
|
|
35
|
-
className={cn("leading-none font-semibold", className)}
|
|
36
|
-
{...props}
|
|
37
|
-
/>
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
|
|
42
|
-
return (
|
|
43
|
-
<div
|
|
44
|
-
data-slot="card-description"
|
|
45
|
-
className={cn("text-muted-foreground text-sm", className)}
|
|
46
|
-
{...props}
|
|
47
|
-
/>
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
|
|
52
|
-
return (
|
|
53
|
-
<div
|
|
54
|
-
data-slot="card-action"
|
|
55
|
-
className={cn(
|
|
56
|
-
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
|
|
57
|
-
className
|
|
58
|
-
)}
|
|
59
|
-
{...props}
|
|
60
|
-
/>
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
|
65
|
-
return (
|
|
66
|
-
<div
|
|
67
|
-
data-slot="card-content"
|
|
68
|
-
className={cn("px-6", className)}
|
|
69
|
-
{...props}
|
|
70
|
-
/>
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
|
75
|
-
return (
|
|
76
|
-
<div
|
|
77
|
-
data-slot="card-footer"
|
|
78
|
-
className={cn("flex items-center px-6 [.border-t]:pt-6", className)}
|
|
79
|
-
{...props}
|
|
80
|
-
/>
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export {
|
|
85
|
-
Card,
|
|
86
|
-
CardHeader,
|
|
87
|
-
CardFooter,
|
|
88
|
-
CardTitle,
|
|
89
|
-
CardAction,
|
|
90
|
-
CardDescription,
|
|
91
|
-
CardContent,
|
|
92
|
-
};
|
|
@@ -1,236 +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 "@/components/ui/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
|
-
<div
|
|
121
|
-
onKeyDownCapture={handleKeyDown}
|
|
122
|
-
className={cn("relative", className)}
|
|
123
|
-
role="region"
|
|
124
|
-
aria-roledescription="carousel"
|
|
125
|
-
data-slot="carousel"
|
|
126
|
-
{...props}>
|
|
127
|
-
{children}
|
|
128
|
-
</div>
|
|
129
|
-
</CarouselContext.Provider>
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function CarouselContent({ className, ...props }: React.ComponentProps<"div">) {
|
|
134
|
-
const { carouselRef, orientation } = useCarousel();
|
|
135
|
-
|
|
136
|
-
return (
|
|
137
|
-
<div
|
|
138
|
-
ref={carouselRef}
|
|
139
|
-
className="overflow-hidden"
|
|
140
|
-
data-slot="carousel-content">
|
|
141
|
-
<div
|
|
142
|
-
className={cn(
|
|
143
|
-
"flex",
|
|
144
|
-
orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col",
|
|
145
|
-
className
|
|
146
|
-
)}
|
|
147
|
-
{...props}
|
|
148
|
-
/>
|
|
149
|
-
</div>
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function CarouselItem({ className, ...props }: React.ComponentProps<"div">) {
|
|
154
|
-
const { orientation } = useCarousel();
|
|
155
|
-
|
|
156
|
-
return (
|
|
157
|
-
<div
|
|
158
|
-
role="group"
|
|
159
|
-
aria-roledescription="slide"
|
|
160
|
-
data-slot="carousel-item"
|
|
161
|
-
className={cn(
|
|
162
|
-
"min-w-0 shrink-0 grow-0 basis-full",
|
|
163
|
-
orientation === "horizontal" ? "pl-4" : "pt-4",
|
|
164
|
-
className
|
|
165
|
-
)}
|
|
166
|
-
{...props}
|
|
167
|
-
/>
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function CarouselPrevious({
|
|
172
|
-
className,
|
|
173
|
-
variant = "outline",
|
|
174
|
-
size = "icon",
|
|
175
|
-
...props
|
|
176
|
-
}: React.ComponentProps<typeof Button>) {
|
|
177
|
-
const { orientation, scrollPrev, canScrollPrev } = useCarousel();
|
|
178
|
-
|
|
179
|
-
return (
|
|
180
|
-
<Button
|
|
181
|
-
data-slot="carousel-previous"
|
|
182
|
-
variant={variant}
|
|
183
|
-
size={size}
|
|
184
|
-
className={cn(
|
|
185
|
-
"absolute size-8 rounded-full",
|
|
186
|
-
orientation === "horizontal"
|
|
187
|
-
? "top-1/2 -left-12 -translate-y-1/2"
|
|
188
|
-
: "-top-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
189
|
-
className
|
|
190
|
-
)}
|
|
191
|
-
disabled={!canScrollPrev}
|
|
192
|
-
onClick={scrollPrev}
|
|
193
|
-
{...props}>
|
|
194
|
-
<ArrowLeft />
|
|
195
|
-
<span className="sr-only">Previous slide</span>
|
|
196
|
-
</Button>
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function CarouselNext({
|
|
201
|
-
className,
|
|
202
|
-
variant = "outline",
|
|
203
|
-
size = "icon",
|
|
204
|
-
...props
|
|
205
|
-
}: React.ComponentProps<typeof Button>) {
|
|
206
|
-
const { orientation, scrollNext, canScrollNext } = useCarousel();
|
|
207
|
-
|
|
208
|
-
return (
|
|
209
|
-
<Button
|
|
210
|
-
data-slot="carousel-next"
|
|
211
|
-
variant={variant}
|
|
212
|
-
size={size}
|
|
213
|
-
className={cn(
|
|
214
|
-
"absolute size-8 rounded-full",
|
|
215
|
-
orientation === "horizontal"
|
|
216
|
-
? "top-1/2 -right-12 -translate-y-1/2"
|
|
217
|
-
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
218
|
-
className
|
|
219
|
-
)}
|
|
220
|
-
disabled={!canScrollNext}
|
|
221
|
-
onClick={scrollNext}
|
|
222
|
-
{...props}>
|
|
223
|
-
<ArrowRight />
|
|
224
|
-
<span className="sr-only">Next slide</span>
|
|
225
|
-
</Button>
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export {
|
|
230
|
-
type CarouselApi,
|
|
231
|
-
Carousel,
|
|
232
|
-
CarouselContent,
|
|
233
|
-
CarouselItem,
|
|
234
|
-
CarouselPrevious,
|
|
235
|
-
CarouselNext,
|
|
236
|
-
};
|
|
@@ -1,347 +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
|
-
<ChartStyle id={chartId} config={config} />
|
|
63
|
-
<RechartsPrimitive.ResponsiveContainer>
|
|
64
|
-
{children}
|
|
65
|
-
</RechartsPrimitive.ResponsiveContainer>
|
|
66
|
-
</div>
|
|
67
|
-
</ChartContext.Provider>
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
|
|
72
|
-
const colorConfig = Object.entries(config).filter(
|
|
73
|
-
([, config]) => config.theme || config.color
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
if (!colorConfig.length) {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return (
|
|
81
|
-
<style
|
|
82
|
-
dangerouslySetInnerHTML={{
|
|
83
|
-
__html: Object.entries(THEMES)
|
|
84
|
-
.map(
|
|
85
|
-
([theme, prefix]) => `
|
|
86
|
-
${prefix} [data-chart=${id}] {
|
|
87
|
-
${colorConfig
|
|
88
|
-
.map(([key, itemConfig]) => {
|
|
89
|
-
const color =
|
|
90
|
-
itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ||
|
|
91
|
-
itemConfig.color;
|
|
92
|
-
return color ? ` --color-${key}: ${color};` : null;
|
|
93
|
-
})
|
|
94
|
-
.join("\n")}
|
|
95
|
-
}
|
|
96
|
-
`
|
|
97
|
-
)
|
|
98
|
-
.join("\n"),
|
|
99
|
-
}}
|
|
100
|
-
/>
|
|
101
|
-
);
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const ChartTooltip = RechartsPrimitive.Tooltip;
|
|
105
|
-
|
|
106
|
-
function ChartTooltipContent({
|
|
107
|
-
active,
|
|
108
|
-
payload,
|
|
109
|
-
className,
|
|
110
|
-
indicator = "dot",
|
|
111
|
-
hideLabel = false,
|
|
112
|
-
hideIndicator = false,
|
|
113
|
-
label,
|
|
114
|
-
labelFormatter,
|
|
115
|
-
labelClassName,
|
|
116
|
-
formatter,
|
|
117
|
-
color,
|
|
118
|
-
nameKey,
|
|
119
|
-
labelKey,
|
|
120
|
-
}: React.ComponentProps<typeof RechartsPrimitive.Tooltip> &
|
|
121
|
-
React.ComponentProps<"div"> & {
|
|
122
|
-
hideLabel?: boolean;
|
|
123
|
-
hideIndicator?: boolean;
|
|
124
|
-
indicator?: "line" | "dot" | "dashed";
|
|
125
|
-
nameKey?: string;
|
|
126
|
-
labelKey?: string;
|
|
127
|
-
}) {
|
|
128
|
-
const { config } = useChart();
|
|
129
|
-
|
|
130
|
-
const tooltipLabel = React.useMemo(() => {
|
|
131
|
-
if (hideLabel || !payload?.length) {
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const [item] = payload;
|
|
136
|
-
const key = `${labelKey || item?.dataKey || item?.name || "value"}`;
|
|
137
|
-
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
138
|
-
const value =
|
|
139
|
-
!labelKey && typeof label === "string"
|
|
140
|
-
? config[label as keyof typeof config]?.label || label
|
|
141
|
-
: itemConfig?.label;
|
|
142
|
-
|
|
143
|
-
if (labelFormatter) {
|
|
144
|
-
return (
|
|
145
|
-
<div className={cn("font-medium", labelClassName)}>
|
|
146
|
-
{labelFormatter(value, payload)}
|
|
147
|
-
</div>
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (!value) {
|
|
152
|
-
return null;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return <div className={cn("font-medium", labelClassName)}>{value}</div>;
|
|
156
|
-
}, [
|
|
157
|
-
label,
|
|
158
|
-
labelFormatter,
|
|
159
|
-
payload,
|
|
160
|
-
hideLabel,
|
|
161
|
-
labelClassName,
|
|
162
|
-
config,
|
|
163
|
-
labelKey,
|
|
164
|
-
]);
|
|
165
|
-
|
|
166
|
-
if (!active || !payload?.length) {
|
|
167
|
-
return null;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const nestLabel = payload.length === 1 && indicator !== "dot";
|
|
171
|
-
|
|
172
|
-
return (
|
|
173
|
-
<div
|
|
174
|
-
className={cn(
|
|
175
|
-
"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",
|
|
176
|
-
className
|
|
177
|
-
)}>
|
|
178
|
-
{!nestLabel ? tooltipLabel : null}
|
|
179
|
-
<div className="grid gap-1.5">
|
|
180
|
-
{payload.map((item, index) => {
|
|
181
|
-
const key = `${nameKey || item.name || item.dataKey || "value"}`;
|
|
182
|
-
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
183
|
-
const indicatorColor = color || item.payload.fill || item.color;
|
|
184
|
-
|
|
185
|
-
return (
|
|
186
|
-
<div
|
|
187
|
-
key={item.dataKey}
|
|
188
|
-
className={cn(
|
|
189
|
-
"[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5",
|
|
190
|
-
indicator === "dot" && "items-center"
|
|
191
|
-
)}>
|
|
192
|
-
{formatter && item?.value !== undefined && item.name ? (
|
|
193
|
-
formatter(item.value, item.name, item, index, item.payload)
|
|
194
|
-
) : (
|
|
195
|
-
<>
|
|
196
|
-
{itemConfig?.icon ? (
|
|
197
|
-
<itemConfig.icon />
|
|
198
|
-
) : (
|
|
199
|
-
!hideIndicator && (
|
|
200
|
-
<div
|
|
201
|
-
className={cn(
|
|
202
|
-
"shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)",
|
|
203
|
-
{
|
|
204
|
-
"h-2.5 w-2.5": indicator === "dot",
|
|
205
|
-
"w-1": indicator === "line",
|
|
206
|
-
"w-0 border-[1.5px] border-dashed bg-transparent":
|
|
207
|
-
indicator === "dashed",
|
|
208
|
-
"my-0.5": nestLabel && indicator === "dashed",
|
|
209
|
-
}
|
|
210
|
-
)}
|
|
211
|
-
style={
|
|
212
|
-
{
|
|
213
|
-
"--color-bg": indicatorColor,
|
|
214
|
-
"--color-border": indicatorColor,
|
|
215
|
-
} as React.CSSProperties
|
|
216
|
-
}
|
|
217
|
-
/>
|
|
218
|
-
)
|
|
219
|
-
)}
|
|
220
|
-
<div
|
|
221
|
-
className={cn(
|
|
222
|
-
"flex flex-1 justify-between leading-none",
|
|
223
|
-
nestLabel ? "items-end" : "items-center"
|
|
224
|
-
)}>
|
|
225
|
-
<div className="grid gap-1.5">
|
|
226
|
-
{nestLabel ? tooltipLabel : null}
|
|
227
|
-
<span className="text-muted-foreground">
|
|
228
|
-
{itemConfig?.label || item.name}
|
|
229
|
-
</span>
|
|
230
|
-
</div>
|
|
231
|
-
{item.value && (
|
|
232
|
-
<span className="text-foreground font-mono font-medium tabular-nums">
|
|
233
|
-
{item.value.toLocaleString()}
|
|
234
|
-
</span>
|
|
235
|
-
)}
|
|
236
|
-
</div>
|
|
237
|
-
</>
|
|
238
|
-
)}
|
|
239
|
-
</div>
|
|
240
|
-
);
|
|
241
|
-
})}
|
|
242
|
-
</div>
|
|
243
|
-
</div>
|
|
244
|
-
);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
const ChartLegend = RechartsPrimitive.Legend;
|
|
248
|
-
|
|
249
|
-
function ChartLegendContent({
|
|
250
|
-
className,
|
|
251
|
-
hideIcon = false,
|
|
252
|
-
payload,
|
|
253
|
-
verticalAlign = "bottom",
|
|
254
|
-
nameKey,
|
|
255
|
-
}: React.ComponentProps<"div"> &
|
|
256
|
-
Pick<RechartsPrimitive.LegendProps, "payload" | "verticalAlign"> & {
|
|
257
|
-
hideIcon?: boolean;
|
|
258
|
-
nameKey?: string;
|
|
259
|
-
}) {
|
|
260
|
-
const { config } = useChart();
|
|
261
|
-
|
|
262
|
-
if (!payload?.length) {
|
|
263
|
-
return null;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
return (
|
|
267
|
-
<div
|
|
268
|
-
className={cn(
|
|
269
|
-
"flex items-center justify-center gap-4",
|
|
270
|
-
verticalAlign === "top" ? "pb-3" : "pt-3",
|
|
271
|
-
className
|
|
272
|
-
)}>
|
|
273
|
-
{payload.map((item) => {
|
|
274
|
-
const key = `${nameKey || item.dataKey || "value"}`;
|
|
275
|
-
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
276
|
-
|
|
277
|
-
return (
|
|
278
|
-
<div
|
|
279
|
-
key={item.value}
|
|
280
|
-
className={cn(
|
|
281
|
-
"[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3"
|
|
282
|
-
)}>
|
|
283
|
-
{itemConfig?.icon && !hideIcon ? (
|
|
284
|
-
<itemConfig.icon />
|
|
285
|
-
) : (
|
|
286
|
-
<div
|
|
287
|
-
className="h-2 w-2 shrink-0 rounded-[2px]"
|
|
288
|
-
style={{
|
|
289
|
-
backgroundColor: item.color,
|
|
290
|
-
}}
|
|
291
|
-
/>
|
|
292
|
-
)}
|
|
293
|
-
{itemConfig?.label}
|
|
294
|
-
</div>
|
|
295
|
-
);
|
|
296
|
-
})}
|
|
297
|
-
</div>
|
|
298
|
-
);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
// Helper to extract item config from a payload.
|
|
302
|
-
function getPayloadConfigFromPayload(
|
|
303
|
-
config: ChartConfig,
|
|
304
|
-
payload: unknown,
|
|
305
|
-
key: string
|
|
306
|
-
) {
|
|
307
|
-
if (typeof payload !== "object" || payload === null) {
|
|
308
|
-
return undefined;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
const payloadPayload =
|
|
312
|
-
"payload" in payload &&
|
|
313
|
-
typeof payload.payload === "object" &&
|
|
314
|
-
payload.payload !== null
|
|
315
|
-
? payload.payload
|
|
316
|
-
: undefined;
|
|
317
|
-
|
|
318
|
-
let configLabelKey: string = key;
|
|
319
|
-
|
|
320
|
-
if (
|
|
321
|
-
key in payload &&
|
|
322
|
-
typeof payload[key as keyof typeof payload] === "string"
|
|
323
|
-
) {
|
|
324
|
-
configLabelKey = payload[key as keyof typeof payload] as string;
|
|
325
|
-
} else if (
|
|
326
|
-
payloadPayload &&
|
|
327
|
-
key in payloadPayload &&
|
|
328
|
-
typeof payloadPayload[key as keyof typeof payloadPayload] === "string"
|
|
329
|
-
) {
|
|
330
|
-
configLabelKey = payloadPayload[
|
|
331
|
-
key as keyof typeof payloadPayload
|
|
332
|
-
] as string;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
return configLabelKey in config
|
|
336
|
-
? config[configLabelKey]
|
|
337
|
-
: config[key as keyof typeof config];
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
export {
|
|
341
|
-
ChartContainer,
|
|
342
|
-
ChartTooltip,
|
|
343
|
-
ChartTooltipContent,
|
|
344
|
-
ChartLegend,
|
|
345
|
-
ChartLegendContent,
|
|
346
|
-
ChartStyle,
|
|
347
|
-
};
|