@vendure/dashboard 3.3.8-master-202507220240 → 3.3.8-master-202507240240
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/dist/plugin/utils/plugin-discovery.d.ts +1 -1
- package/dist/plugin/utils/plugin-discovery.js +61 -21
- package/dist/plugin/vite-plugin-tailwind-source.js +13 -1
- package/dist/plugin/vite-plugin-vendure-dashboard.d.ts +1 -1
- package/dist/plugin/vite-plugin-vendure-dashboard.js +2 -2
- package/package.json +39 -26
- package/src/app/routes/_authenticated/_facets/components/add-facet-value-dialog.tsx +146 -0
- package/src/app/routes/_authenticated/_facets/components/facet-values-table.tsx +84 -62
- package/src/app/routes/_authenticated/_facets/facets.graphql.ts +9 -0
- package/src/lib/components/data-table/use-generated-columns.tsx +20 -5
- package/src/lib/components/ui/aspect-ratio.tsx +9 -0
- package/src/lib/components/ui/carousel.tsx +241 -0
- package/src/lib/components/ui/chart.tsx +351 -0
- package/src/lib/components/ui/context-menu.tsx +252 -0
- package/src/lib/components/ui/drawer.tsx +133 -0
- package/src/lib/components/ui/input-otp.tsx +77 -0
- package/src/lib/components/ui/menubar.tsx +274 -0
- package/src/lib/components/ui/navigation-menu.tsx +168 -0
- package/src/lib/components/ui/progress.tsx +29 -0
- package/src/lib/components/ui/radio-group.tsx +45 -0
- package/src/lib/components/ui/resizable.tsx +54 -0
- package/src/lib/components/ui/slider.tsx +63 -0
- package/src/lib/components/ui/toggle-group.tsx +73 -0
- package/src/lib/components/ui/toggle.tsx +45 -0
- package/src/lib/index.ts +18 -0
- package/vite/utils/plugin-discovery.ts +67 -18
- package/vite/vite-plugin-tailwind-source.ts +20 -4
- package/vite/vite-plugin-vendure-dashboard.ts +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DisplayComponent } from '@/vdb/framework/component-registry/dynamic-component.js';
|
|
2
|
-
import { FieldInfo, getTypeFieldInfo } from '@/vdb/framework/document-introspection/get-document-structure.js';
|
|
2
|
+
import { FieldInfo, getTypeFieldInfo, getOperationVariablesFields } from '@/vdb/framework/document-introspection/get-document-structure.js';
|
|
3
3
|
import { api } from '@/vdb/graphql/api.js';
|
|
4
4
|
import { Trans, useLingui } from '@/vdb/lib/trans.js';
|
|
5
5
|
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
@@ -250,16 +250,23 @@ function DeleteMutationRowAction({
|
|
|
250
250
|
}>) {
|
|
251
251
|
const { refetchPaginatedList } = usePaginatedList();
|
|
252
252
|
const { i18n } = useLingui();
|
|
253
|
+
|
|
254
|
+
// Inspect the mutation variables to determine if it expects 'id' or 'ids'
|
|
255
|
+
const mutationVariables = getOperationVariablesFields(deleteMutation);
|
|
256
|
+
const hasIdsParameter = mutationVariables.some(field => field.name === 'ids');
|
|
257
|
+
|
|
253
258
|
const { mutate: deleteMutationFn } = useMutation({
|
|
254
259
|
mutationFn: api.mutate(deleteMutation),
|
|
255
|
-
onSuccess: (result: { [key: string]: { result: 'DELETED' | 'NOT_DELETED'; message: string } }) => {
|
|
260
|
+
onSuccess: (result: { [key: string]: { result: 'DELETED' | 'NOT_DELETED'; message: string } | { result: 'DELETED' | 'NOT_DELETED'; message: string }[] }) => {
|
|
256
261
|
const unwrappedResult = Object.values(result)[0];
|
|
257
|
-
|
|
262
|
+
// Handle both single result and array of results
|
|
263
|
+
const resultToCheck = Array.isArray(unwrappedResult) ? unwrappedResult[0] : unwrappedResult;
|
|
264
|
+
if (resultToCheck.result === 'DELETED') {
|
|
258
265
|
refetchPaginatedList();
|
|
259
266
|
toast.success(i18n.t('Deleted successfully'));
|
|
260
267
|
} else {
|
|
261
268
|
toast.error(i18n.t('Failed to delete'), {
|
|
262
|
-
description:
|
|
269
|
+
description: resultToCheck.message,
|
|
263
270
|
});
|
|
264
271
|
}
|
|
265
272
|
},
|
|
@@ -295,7 +302,15 @@ function DeleteMutationRowAction({
|
|
|
295
302
|
<Trans>Cancel</Trans>
|
|
296
303
|
</AlertDialogCancel>
|
|
297
304
|
<AlertDialogAction
|
|
298
|
-
onClick={() =>
|
|
305
|
+
onClick={() => {
|
|
306
|
+
// Pass variables based on what the mutation expects
|
|
307
|
+
if (hasIdsParameter) {
|
|
308
|
+
deleteMutationFn({ ids: [row.original.id] });
|
|
309
|
+
} else {
|
|
310
|
+
// Fallback to single id if we can't determine the format
|
|
311
|
+
deleteMutationFn({ id: row.original.id });
|
|
312
|
+
}
|
|
313
|
+
}}
|
|
299
314
|
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
|
300
315
|
>
|
|
301
316
|
<Trans>Delete</Trans>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as AspectRatioPrimitive from "@radix-ui/react-aspect-ratio"
|
|
2
|
+
|
|
3
|
+
function AspectRatio({
|
|
4
|
+
...props
|
|
5
|
+
}: React.ComponentProps<typeof AspectRatioPrimitive.Root>) {
|
|
6
|
+
return <AspectRatioPrimitive.Root data-slot="aspect-ratio" {...props} />
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { AspectRatio }
|
|
@@ -0,0 +1,241 @@
|
|
|
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 "@/vdb/lib/utils"
|
|
10
|
+
import { Button } from "@/vdb/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
|
+
>
|
|
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
|
+
}
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import * as RechartsPrimitive from "recharts"
|
|
3
|
+
|
|
4
|
+
import { cn } from "@/vdb/lib/utils"
|
|
5
|
+
|
|
6
|
+
// Format: { THEME_NAME: CSS_SELECTOR }
|
|
7
|
+
const THEMES = { light: "", dark: ".dark" } as const
|
|
8
|
+
|
|
9
|
+
export type ChartConfig = {
|
|
10
|
+
[k in string]: {
|
|
11
|
+
label?: React.ReactNode
|
|
12
|
+
icon?: React.ComponentType
|
|
13
|
+
} & (
|
|
14
|
+
| { color?: string; theme?: never }
|
|
15
|
+
| { color?: never; theme: Record<keyof typeof THEMES, string> }
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type ChartContextProps = {
|
|
20
|
+
config: ChartConfig
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const ChartContext = React.createContext<ChartContextProps | null>(null)
|
|
24
|
+
|
|
25
|
+
function useChart() {
|
|
26
|
+
const context = React.useContext(ChartContext)
|
|
27
|
+
|
|
28
|
+
if (!context) {
|
|
29
|
+
throw new Error("useChart must be used within a <ChartContainer />")
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return context
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function ChartContainer({
|
|
36
|
+
id,
|
|
37
|
+
className,
|
|
38
|
+
children,
|
|
39
|
+
config,
|
|
40
|
+
...props
|
|
41
|
+
}: React.ComponentProps<"div"> & {
|
|
42
|
+
config: ChartConfig
|
|
43
|
+
children: React.ComponentProps<
|
|
44
|
+
typeof RechartsPrimitive.ResponsiveContainer
|
|
45
|
+
>["children"]
|
|
46
|
+
}) {
|
|
47
|
+
const uniqueId = React.useId()
|
|
48
|
+
const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<ChartContext.Provider value={{ config }}>
|
|
52
|
+
<div
|
|
53
|
+
data-slot="chart"
|
|
54
|
+
data-chart={chartId}
|
|
55
|
+
className={cn(
|
|
56
|
+
"[&_.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",
|
|
57
|
+
className
|
|
58
|
+
)}
|
|
59
|
+
{...props}
|
|
60
|
+
>
|
|
61
|
+
<ChartStyle id={chartId} config={config} />
|
|
62
|
+
<RechartsPrimitive.ResponsiveContainer>
|
|
63
|
+
{children}
|
|
64
|
+
</RechartsPrimitive.ResponsiveContainer>
|
|
65
|
+
</div>
|
|
66
|
+
</ChartContext.Provider>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
|
|
71
|
+
const colorConfig = Object.entries(config).filter(
|
|
72
|
+
([, config]) => config.theme || config.color
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
if (!colorConfig.length) {
|
|
76
|
+
return null
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<style
|
|
81
|
+
dangerouslySetInnerHTML={{
|
|
82
|
+
__html: Object.entries(THEMES)
|
|
83
|
+
.map(
|
|
84
|
+
([theme, prefix]) => `
|
|
85
|
+
${prefix} [data-chart=${id}] {
|
|
86
|
+
${colorConfig
|
|
87
|
+
.map(([key, itemConfig]) => {
|
|
88
|
+
const color =
|
|
89
|
+
itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ||
|
|
90
|
+
itemConfig.color
|
|
91
|
+
return color ? ` --color-${key}: ${color};` : null
|
|
92
|
+
})
|
|
93
|
+
.join("\n")}
|
|
94
|
+
}
|
|
95
|
+
`
|
|
96
|
+
)
|
|
97
|
+
.join("\n"),
|
|
98
|
+
}}
|
|
99
|
+
/>
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const ChartTooltip = RechartsPrimitive.Tooltip
|
|
104
|
+
|
|
105
|
+
function ChartTooltipContent({
|
|
106
|
+
active,
|
|
107
|
+
payload,
|
|
108
|
+
className,
|
|
109
|
+
indicator = "dot",
|
|
110
|
+
hideLabel = false,
|
|
111
|
+
hideIndicator = false,
|
|
112
|
+
label,
|
|
113
|
+
labelFormatter,
|
|
114
|
+
labelClassName,
|
|
115
|
+
formatter,
|
|
116
|
+
color,
|
|
117
|
+
nameKey,
|
|
118
|
+
labelKey,
|
|
119
|
+
}: React.ComponentProps<typeof RechartsPrimitive.Tooltip> &
|
|
120
|
+
React.ComponentProps<"div"> & {
|
|
121
|
+
hideLabel?: boolean
|
|
122
|
+
hideIndicator?: boolean
|
|
123
|
+
indicator?: "line" | "dot" | "dashed"
|
|
124
|
+
nameKey?: string
|
|
125
|
+
labelKey?: string
|
|
126
|
+
}) {
|
|
127
|
+
const { config } = useChart()
|
|
128
|
+
|
|
129
|
+
const tooltipLabel = React.useMemo(() => {
|
|
130
|
+
if (hideLabel || !payload?.length) {
|
|
131
|
+
return null
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const [item] = payload
|
|
135
|
+
const key = `${labelKey || item?.dataKey || item?.name || "value"}`
|
|
136
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key)
|
|
137
|
+
const value =
|
|
138
|
+
!labelKey && typeof label === "string"
|
|
139
|
+
? config[label as keyof typeof config]?.label || label
|
|
140
|
+
: itemConfig?.label
|
|
141
|
+
|
|
142
|
+
if (labelFormatter) {
|
|
143
|
+
return (
|
|
144
|
+
<div className={cn("font-medium", labelClassName)}>
|
|
145
|
+
{labelFormatter(value, payload)}
|
|
146
|
+
</div>
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (!value) {
|
|
151
|
+
return null
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return <div className={cn("font-medium", labelClassName)}>{value}</div>
|
|
155
|
+
}, [
|
|
156
|
+
label,
|
|
157
|
+
labelFormatter,
|
|
158
|
+
payload,
|
|
159
|
+
hideLabel,
|
|
160
|
+
labelClassName,
|
|
161
|
+
config,
|
|
162
|
+
labelKey,
|
|
163
|
+
])
|
|
164
|
+
|
|
165
|
+
if (!active || !payload?.length) {
|
|
166
|
+
return null
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const nestLabel = payload.length === 1 && indicator !== "dot"
|
|
170
|
+
|
|
171
|
+
return (
|
|
172
|
+
<div
|
|
173
|
+
className={cn(
|
|
174
|
+
"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",
|
|
175
|
+
className
|
|
176
|
+
)}
|
|
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
|
+
>
|
|
193
|
+
{formatter && item?.value !== undefined && item.name ? (
|
|
194
|
+
formatter(item.value, item.name, item, index, item.payload)
|
|
195
|
+
) : (
|
|
196
|
+
<>
|
|
197
|
+
{itemConfig?.icon ? (
|
|
198
|
+
<itemConfig.icon />
|
|
199
|
+
) : (
|
|
200
|
+
!hideIndicator && (
|
|
201
|
+
<div
|
|
202
|
+
className={cn(
|
|
203
|
+
"shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)",
|
|
204
|
+
{
|
|
205
|
+
"h-2.5 w-2.5": indicator === "dot",
|
|
206
|
+
"w-1": indicator === "line",
|
|
207
|
+
"w-0 border-[1.5px] border-dashed bg-transparent":
|
|
208
|
+
indicator === "dashed",
|
|
209
|
+
"my-0.5": nestLabel && indicator === "dashed",
|
|
210
|
+
}
|
|
211
|
+
)}
|
|
212
|
+
style={
|
|
213
|
+
{
|
|
214
|
+
"--color-bg": indicatorColor,
|
|
215
|
+
"--color-border": indicatorColor,
|
|
216
|
+
} as React.CSSProperties
|
|
217
|
+
}
|
|
218
|
+
/>
|
|
219
|
+
)
|
|
220
|
+
)}
|
|
221
|
+
<div
|
|
222
|
+
className={cn(
|
|
223
|
+
"flex flex-1 justify-between leading-none",
|
|
224
|
+
nestLabel ? "items-end" : "items-center"
|
|
225
|
+
)}
|
|
226
|
+
>
|
|
227
|
+
<div className="grid gap-1.5">
|
|
228
|
+
{nestLabel ? tooltipLabel : null}
|
|
229
|
+
<span className="text-muted-foreground">
|
|
230
|
+
{itemConfig?.label || item.name}
|
|
231
|
+
</span>
|
|
232
|
+
</div>
|
|
233
|
+
{item.value && (
|
|
234
|
+
<span className="text-foreground font-mono font-medium tabular-nums">
|
|
235
|
+
{item.value.toLocaleString()}
|
|
236
|
+
</span>
|
|
237
|
+
)}
|
|
238
|
+
</div>
|
|
239
|
+
</>
|
|
240
|
+
)}
|
|
241
|
+
</div>
|
|
242
|
+
)
|
|
243
|
+
})}
|
|
244
|
+
</div>
|
|
245
|
+
</div>
|
|
246
|
+
)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const ChartLegend = RechartsPrimitive.Legend
|
|
250
|
+
|
|
251
|
+
function ChartLegendContent({
|
|
252
|
+
className,
|
|
253
|
+
hideIcon = false,
|
|
254
|
+
payload,
|
|
255
|
+
verticalAlign = "bottom",
|
|
256
|
+
nameKey,
|
|
257
|
+
}: React.ComponentProps<"div"> &
|
|
258
|
+
Pick<RechartsPrimitive.LegendProps, "payload" | "verticalAlign"> & {
|
|
259
|
+
hideIcon?: boolean
|
|
260
|
+
nameKey?: string
|
|
261
|
+
}) {
|
|
262
|
+
const { config } = useChart()
|
|
263
|
+
|
|
264
|
+
if (!payload?.length) {
|
|
265
|
+
return null
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return (
|
|
269
|
+
<div
|
|
270
|
+
className={cn(
|
|
271
|
+
"flex items-center justify-center gap-4",
|
|
272
|
+
verticalAlign === "top" ? "pb-3" : "pt-3",
|
|
273
|
+
className
|
|
274
|
+
)}
|
|
275
|
+
>
|
|
276
|
+
{payload.map((item) => {
|
|
277
|
+
const key = `${nameKey || item.dataKey || "value"}`
|
|
278
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key)
|
|
279
|
+
|
|
280
|
+
return (
|
|
281
|
+
<div
|
|
282
|
+
key={item.value}
|
|
283
|
+
className={cn(
|
|
284
|
+
"[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3"
|
|
285
|
+
)}
|
|
286
|
+
>
|
|
287
|
+
{itemConfig?.icon && !hideIcon ? (
|
|
288
|
+
<itemConfig.icon />
|
|
289
|
+
) : (
|
|
290
|
+
<div
|
|
291
|
+
className="h-2 w-2 shrink-0 rounded-[2px]"
|
|
292
|
+
style={{
|
|
293
|
+
backgroundColor: item.color,
|
|
294
|
+
}}
|
|
295
|
+
/>
|
|
296
|
+
)}
|
|
297
|
+
{itemConfig?.label}
|
|
298
|
+
</div>
|
|
299
|
+
)
|
|
300
|
+
})}
|
|
301
|
+
</div>
|
|
302
|
+
)
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// Helper to extract item config from a payload.
|
|
306
|
+
function getPayloadConfigFromPayload(
|
|
307
|
+
config: ChartConfig,
|
|
308
|
+
payload: unknown,
|
|
309
|
+
key: string
|
|
310
|
+
) {
|
|
311
|
+
if (typeof payload !== "object" || payload === null) {
|
|
312
|
+
return undefined
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const payloadPayload =
|
|
316
|
+
"payload" in payload &&
|
|
317
|
+
typeof payload.payload === "object" &&
|
|
318
|
+
payload.payload !== null
|
|
319
|
+
? payload.payload
|
|
320
|
+
: undefined
|
|
321
|
+
|
|
322
|
+
let configLabelKey: string = key
|
|
323
|
+
|
|
324
|
+
if (
|
|
325
|
+
key in payload &&
|
|
326
|
+
typeof payload[key as keyof typeof payload] === "string"
|
|
327
|
+
) {
|
|
328
|
+
configLabelKey = payload[key as keyof typeof payload] as string
|
|
329
|
+
} else if (
|
|
330
|
+
payloadPayload &&
|
|
331
|
+
key in payloadPayload &&
|
|
332
|
+
typeof payloadPayload[key as keyof typeof payloadPayload] === "string"
|
|
333
|
+
) {
|
|
334
|
+
configLabelKey = payloadPayload[
|
|
335
|
+
key as keyof typeof payloadPayload
|
|
336
|
+
] as string
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return configLabelKey in config
|
|
340
|
+
? config[configLabelKey]
|
|
341
|
+
: config[key as keyof typeof config]
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export {
|
|
345
|
+
ChartContainer,
|
|
346
|
+
ChartTooltip,
|
|
347
|
+
ChartTooltipContent,
|
|
348
|
+
ChartLegend,
|
|
349
|
+
ChartLegendContent,
|
|
350
|
+
ChartStyle,
|
|
351
|
+
}
|