@catalystsoftware/ui 1.0.4 → 1.0.5
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/data/tailwind.config.js +261 -3821
- package/dist/components/catalyst-ui/buttons/burger.tsx +207 -0
- package/dist/components/catalyst-ui/core/data-display/timeline.tsx +210 -0
- package/dist/components/catalyst-ui/core/feedback/alert.tsx +491 -0
- package/dist/components/catalyst-ui/core/feedback/spinner-1.tsx +65 -0
- package/dist/components/catalyst-ui/core/feedback/toast.tsx +1857 -0
- package/dist/components/catalyst-ui/core/navigation/menu.tsx +164 -0
- package/dist/components/catalyst-ui/forms/toggle-class.tsx +176 -0
- package/dist/components/catalyst-ui/hooks/use-copy-to-clipboard.tsx +419 -0
- package/dist/components/catalyst-ui/hooks/use-counter.tsx +13 -0
- package/dist/components/catalyst-ui/hooks/use-event-listener.tsx +23 -0
- package/dist/components/catalyst-ui/hooks/use-export-markdown.tsx +47 -0
- package/dist/components/catalyst-ui/hooks/use-focus.tsx +17 -0
- package/dist/components/catalyst-ui/hooks/use-interval.tsx +23 -0
- package/dist/components/catalyst-ui/hooks/use-is-client.tsx +16 -0
- package/dist/components/catalyst-ui/hooks/use-media-query.tsx +19 -0
- package/dist/components/catalyst-ui/hooks/use-mobile.tsx +19 -0
- package/dist/components/catalyst-ui/hooks/use-resize-observer.tsx +81 -0
- package/dist/components/catalyst-ui/hooks/use-timeout.tsx +21 -0
- package/dist/components/catalyst-ui/hooks/use-timer.tsx +209 -0
- package/dist/components/catalyst-ui/hooks/use-toggle.tsx +12 -0
- package/dist/components/catalyst-ui/media/image.tsx +13 -0
- package/dist/components/catalyst-ui/overlays/dual-sidebar.tsx +4142 -0
- package/dist/components/catalyst-ui/overlays/sidebar-original.tsx +726 -0
- package/dist/components/catalyst-ui/primitives/accordion.tsx +250 -0
- package/dist/components/catalyst-ui/primitives/alert-dialog.tsx +126 -0
- package/dist/components/catalyst-ui/primitives/aspect-ratio.tsx +9 -0
- package/dist/components/catalyst-ui/primitives/avatar.tsx +296 -0
- package/dist/components/catalyst-ui/primitives/badge.tsx +57 -0
- package/dist/components/catalyst-ui/primitives/breadcrumb.tsx +101 -0
- package/dist/components/catalyst-ui/primitives/button.tsx +265 -0
- package/dist/components/catalyst-ui/primitives/calendar-v4.tsx +208 -0
- package/dist/components/catalyst-ui/primitives/calendar.tsx +295 -0
- package/dist/components/catalyst-ui/primitives/card.tsx +618 -0
- package/dist/components/catalyst-ui/primitives/carousel.tsx +238 -0
- package/dist/components/catalyst-ui/primitives/chart.tsx +347 -0
- package/dist/components/catalyst-ui/primitives/checkbox.tsx +225 -0
- package/dist/components/catalyst-ui/primitives/collapsible.tsx +212 -0
- package/dist/components/catalyst-ui/primitives/command.tsx +393 -0
- package/dist/components/catalyst-ui/primitives/context-menu.tsx +236 -0
- package/dist/components/catalyst-ui/primitives/dialog.tsx +471 -0
- package/dist/components/catalyst-ui/primitives/drawer.tsx +761 -0
- package/dist/components/catalyst-ui/primitives/dropdown-menu.tsx +290 -0
- package/dist/components/catalyst-ui/primitives/empty.tsx +104 -0
- package/dist/components/catalyst-ui/primitives/field.tsx +244 -0
- package/dist/components/catalyst-ui/primitives/hover-card.tsx +124 -0
- package/dist/components/catalyst-ui/primitives/input-otp.tsx +76 -0
- package/dist/components/catalyst-ui/primitives/input.tsx +64 -0
- package/dist/components/catalyst-ui/primitives/item.tsx +196 -0
- package/dist/components/catalyst-ui/primitives/kbd.tsx +75 -0
- package/dist/components/catalyst-ui/primitives/label.tsx +24 -0
- package/dist/components/catalyst-ui/primitives/navigation-menu.tsx +150 -0
- package/dist/components/catalyst-ui/primitives/pagination.tsx +198 -0
- package/dist/components/catalyst-ui/primitives/popover.tsx +232 -0
- package/dist/components/catalyst-ui/primitives/progress.tsx +34 -0
- package/dist/components/catalyst-ui/primitives/radio-group.tsx +43 -0
- package/dist/components/catalyst-ui/primitives/resizable.tsx +56 -0
- package/dist/components/catalyst-ui/primitives/select.tsx +155 -0
- package/dist/components/catalyst-ui/primitives/separator.tsx +74 -0
- package/dist/components/catalyst-ui/primitives/sheet.tsx +126 -0
- package/dist/components/catalyst-ui/primitives/skeleton.tsx +15 -0
- package/dist/components/catalyst-ui/primitives/slider.tsx +27 -0
- package/dist/components/catalyst-ui/primitives/switch.tsx +187 -0
- package/dist/components/catalyst-ui/primitives/tabs.tsx +335 -0
- package/dist/components/catalyst-ui/primitives/textarea.tsx +24 -0
- package/dist/components/catalyst-ui/primitives/toggle-group.tsx +55 -0
- package/dist/components/catalyst-ui/primitives/toggle.tsx +42 -0
- package/dist/components/catalyst-ui/primitives/tooltip.tsx +116 -0
- package/dist/components/catalyst-ui/utils/basic-auth.tsx +40 -0
- package/dist/components/catalyst-ui/utils/context-storage.tsx +19 -0
- package/dist/components/catalyst-ui/utils/cors-middleware.tsx +71 -0
- package/dist/components/catalyst-ui/utils/deferred-content.tsx +595 -0
- package/dist/components/catalyst-ui/utils/honeypot-middleware.tsx +38 -0
- package/dist/components/catalyst-ui/utils/incId.tsx +75 -0
- package/dist/components/catalyst-ui/utils/jwk-auth.tsx +36 -0
- package/dist/components/catalyst-ui/utils/request-id.tsx +14 -0
- package/dist/components/catalyst-ui/utils/secure-headers.tsx +37 -0
- package/dist/components/catalyst-ui/utils/server-timing.tsx +23 -0
- package/dist/components/catalyst-ui/utils/utils.ts +43 -0
- package/dist/components/catalyst-ui/utils/with-cookie.tsx +43 -0
- package/dist/components/catalyst-ui/x/accordian-x.tsx +428 -0
- package/dist/components/catalyst-ui/x/alert-x.tsx +413 -0
- package/dist/components/catalyst-ui/x/animated-text-x.tsx +2242 -0
- package/dist/components/catalyst-ui/x/avatar-x.tsx +515 -0
- package/dist/components/catalyst-ui/x/badge-x.tsx +670 -0
- package/dist/components/catalyst-ui/x/button-X.tsx +2857 -0
- package/dist/components/catalyst-ui/x/button-group-x.tsx +847 -0
- package/dist/components/catalyst-ui/x/calendar-x.tsx +1910 -0
- package/dist/components/catalyst-ui/x/card-x.tsx +2597 -0
- package/dist/components/catalyst-ui/x/checkbox-x.tsx +656 -0
- package/dist/components/catalyst-ui/x/collapsible-x.tsx +1360 -0
- package/dist/components/catalyst-ui/x/combobox-x.tsx +911 -0
- package/dist/components/catalyst-ui/x/data-table-x.tsx +1753 -0
- package/dist/components/catalyst-ui/x/date-picker-x.tsx +648 -0
- package/dist/components/catalyst-ui/x/dialog-x.tsx +659 -0
- package/dist/components/catalyst-ui/x/dropdown-menu-x.tsx +612 -0
- package/dist/components/catalyst-ui/x/hover-card-x.tsx +375 -0
- package/dist/components/catalyst-ui/x/icon-x.tsx +840 -0
- package/dist/components/catalyst-ui/x/input-mask-x.tsx +981 -0
- package/dist/components/catalyst-ui/x/input-otp-x.tsx +659 -0
- package/dist/components/catalyst-ui/x/loader-x.tsx +1757 -0
- package/dist/components/catalyst-ui/x/pagination-x.tsx +622 -0
- package/dist/components/catalyst-ui/x/popover-x.tsx +744 -0
- package/dist/components/catalyst-ui/x/radio-group-x.tsx +499 -0
- package/dist/components/catalyst-ui/x/select-x.tsx +1127 -0
- package/dist/components/catalyst-ui/x/sheet-x.tsx +668 -0
- package/dist/components/catalyst-ui/x/switch-x.tsx +681 -0
- package/dist/components/catalyst-ui/x/table-x.tsx +574 -0
- package/dist/components/catalyst-ui/x/tabs-x.tsx +839 -0
- package/dist/components/catalyst-ui/x/textarea-x.tsx +1263 -0
- package/dist/components/catalyst-ui/x/tooltip-x.tsx +396 -0
- package/dist/components/catalyst-ui/x/tracker-x.tsx +560 -0
- package/dist/data/bg-data.tsx +901 -0
- package/dist/data/buttons-data.tsx +2327 -0
- package/dist/data/charts-data.tsx +102 -0
- package/dist/data/chat-data.tsx +83 -0
- package/dist/data/code-data.tsx +1040 -0
- package/dist/data/comboboxes-data.tsx +1843 -0
- package/dist/data/command-data.tsx +1381 -0
- package/dist/data/core-data.tsx +15953 -0
- package/dist/data/crm-data.tsx +47 -0
- package/dist/data/data.tsx +159 -0
- package/dist/data/date-and-time-data.tsx +554 -0
- package/dist/data/dependencies.tsx +7 -0
- package/dist/data/ecommerce-data.tsx +1387 -0
- package/dist/data/forms-data.tsx +7890 -0
- package/dist/data/hooks-data.tsx +5487 -0
- package/dist/data/index.ts +34 -0
- package/dist/data/inputs-data.tsx +557 -0
- package/dist/data/interactive-data.tsx +5394 -0
- package/dist/data/lofi-data.tsx +18295 -0
- package/dist/data/marketing-data.tsx +2546 -0
- package/dist/data/media-data.tsx +1510 -0
- package/dist/data/motion-data.tsx +5801 -0
- package/dist/data/overlay-data.tsx +4136 -0
- package/dist/data/pdf-data.tsx +124 -0
- package/dist/data/pos-data.tsx +213 -0
- package/dist/data/postcss.config.js +6 -0
- package/dist/data/primitive-data.tsx +5170 -0
- package/dist/data/prompt-data.tsx +1226 -0
- package/dist/data/requiredLibs.ts +4 -0
- package/dist/data/sandbox-data.tsx +1 -0
- package/dist/data/sidebars-data.tsx +5421 -0
- package/dist/data/stacks-data.tsx +32 -0
- package/dist/data/table-data.tsx +706 -0
- package/dist/data/tailwind.config.js +270 -0
- package/dist/data/tailwind.config.ngin.js +3830 -0
- package/dist/data/tailwind.css +431 -0
- package/dist/data/tools-data.tsx +6910 -0
- package/dist/data/typography-data.tsx +2050 -0
- package/dist/data/utils-data.tsx +6500 -0
- package/dist/data/x-data.tsx +1171 -0
- package/dist/data.tsx +159 -0
- package/package.json +1 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -362
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import useCarousel, { type UseCarouselType, } from "embla-carousel-react"
|
|
3
|
+
import { ArrowLeft, ArrowRight, } from "lucide-react";
|
|
4
|
+
import { cn, } from "~/components/catalyst-ui/utils";
|
|
5
|
+
import { Button, } from "~/components/catalyst-ui";
|
|
6
|
+
|
|
7
|
+
// @dev app/components/catalyst-ui/data/primitive-data.tsx:815
|
|
8
|
+
|
|
9
|
+
type CarouselApi = UseEmblaCarouselType[1]
|
|
10
|
+
type UseCarouselParameters = Parameters<typeof useEmblaCarousel>
|
|
11
|
+
type CarouselOptions = UseCarouselParameters[0]
|
|
12
|
+
type CarouselPlugin = UseCarouselParameters[1]
|
|
13
|
+
|
|
14
|
+
type CarouselProps = {
|
|
15
|
+
opts?: CarouselOptions
|
|
16
|
+
plugins?: CarouselPlugin
|
|
17
|
+
orientation?: "horizontal" | "vertical"
|
|
18
|
+
setApi?: (api: CarouselApi) => void
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type CarouselContextProps = {
|
|
22
|
+
carouselRef: ReturnType<typeof useEmblaCarousel>[0]
|
|
23
|
+
api: ReturnType<typeof useEmblaCarousel>[1]
|
|
24
|
+
scrollPrev: () => void
|
|
25
|
+
scrollNext: () => void
|
|
26
|
+
canScrollPrev: boolean
|
|
27
|
+
canScrollNext: boolean
|
|
28
|
+
} & CarouselProps
|
|
29
|
+
|
|
30
|
+
const CarouselContext = React.createContext<CarouselContextProps | null>(null)
|
|
31
|
+
|
|
32
|
+
function useEmblaCarousel() {
|
|
33
|
+
const context = React.useContext(CarouselContext)
|
|
34
|
+
|
|
35
|
+
if (!context) {
|
|
36
|
+
throw new Error("useEmblaCarousel must be used within a <EmblaCarousel />")
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return context
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function EmblaCarousel({
|
|
43
|
+
orientation = "horizontal",
|
|
44
|
+
opts,
|
|
45
|
+
setApi,
|
|
46
|
+
plugins,
|
|
47
|
+
className,
|
|
48
|
+
children,
|
|
49
|
+
...props
|
|
50
|
+
}: React.ComponentProps<"div"> & CarouselProps) {
|
|
51
|
+
const [carouselRef, api] = useEmblaCarousel(
|
|
52
|
+
{
|
|
53
|
+
...opts,
|
|
54
|
+
axis: orientation === "horizontal" ? "x" : "y",
|
|
55
|
+
},
|
|
56
|
+
plugins
|
|
57
|
+
)
|
|
58
|
+
const [canScrollPrev, setCanScrollPrev] = React.useState(false)
|
|
59
|
+
const [canScrollNext, setCanScrollNext] = React.useState(false)
|
|
60
|
+
|
|
61
|
+
const onSelect = React.useCallback((api: CarouselApi) => {
|
|
62
|
+
if (!api) return
|
|
63
|
+
setCanScrollPrev(api.canScrollPrev())
|
|
64
|
+
setCanScrollNext(api.canScrollNext())
|
|
65
|
+
}, [])
|
|
66
|
+
|
|
67
|
+
const scrollPrev = React.useCallback(() => {
|
|
68
|
+
api?.scrollPrev()
|
|
69
|
+
}, [api])
|
|
70
|
+
|
|
71
|
+
const scrollNext = React.useCallback(() => {
|
|
72
|
+
api?.scrollNext()
|
|
73
|
+
}, [api])
|
|
74
|
+
|
|
75
|
+
const handleKeyDown = React.useCallback(
|
|
76
|
+
(event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
77
|
+
if (event.key === "ArrowLeft") {
|
|
78
|
+
event.preventDefault()
|
|
79
|
+
scrollPrev()
|
|
80
|
+
} else if (event.key === "ArrowRight") {
|
|
81
|
+
event.preventDefault()
|
|
82
|
+
scrollNext()
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
[scrollPrev, scrollNext]
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
React.useEffect(() => {
|
|
89
|
+
if (!api || !setApi) return
|
|
90
|
+
setApi(api)
|
|
91
|
+
}, [api, setApi])
|
|
92
|
+
|
|
93
|
+
React.useEffect(() => {
|
|
94
|
+
if (!api) return
|
|
95
|
+
onSelect(api)
|
|
96
|
+
api.on("reInit", onSelect)
|
|
97
|
+
api.on("select", onSelect)
|
|
98
|
+
|
|
99
|
+
return () => {
|
|
100
|
+
api?.off("select", onSelect)
|
|
101
|
+
}
|
|
102
|
+
}, [api, onSelect])
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<CarouselContext.Provider
|
|
106
|
+
value={{
|
|
107
|
+
carouselRef,
|
|
108
|
+
api: api,
|
|
109
|
+
opts,
|
|
110
|
+
orientation:
|
|
111
|
+
orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
|
|
112
|
+
scrollPrev,
|
|
113
|
+
scrollNext,
|
|
114
|
+
canScrollPrev,
|
|
115
|
+
canScrollNext,
|
|
116
|
+
}}
|
|
117
|
+
>
|
|
118
|
+
<div
|
|
119
|
+
onKeyDownCapture={handleKeyDown}
|
|
120
|
+
className={cn("relative", className)}
|
|
121
|
+
role="region"
|
|
122
|
+
aria-roledescription="carousel"
|
|
123
|
+
data-slot="carousel"
|
|
124
|
+
{...props}
|
|
125
|
+
>
|
|
126
|
+
{children}
|
|
127
|
+
</div>
|
|
128
|
+
</CarouselContext.Provider>
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function EmblaCarouselContent({ className, ...props }: React.ComponentProps<"div">) {
|
|
133
|
+
const { carouselRef, orientation } = useEmblaCarousel()
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<div
|
|
137
|
+
ref={carouselRef}
|
|
138
|
+
className="overflow-hidden"
|
|
139
|
+
data-slot="carousel-content"
|
|
140
|
+
>
|
|
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 EmblaCarouselItem({ className, ...props }: React.ComponentProps<"div">) {
|
|
154
|
+
const { orientation } = useEmblaCarousel()
|
|
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 EmblaCarouselPrevious({
|
|
172
|
+
className,
|
|
173
|
+
variant = "outline",
|
|
174
|
+
size = "icon",
|
|
175
|
+
...props
|
|
176
|
+
}: React.ComponentProps<typeof Button>) {
|
|
177
|
+
const { orientation, scrollPrev, canScrollPrev } = useEmblaCarousel()
|
|
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
|
+
>
|
|
195
|
+
<ArrowLeft />
|
|
196
|
+
<span className="sr-only">Previous slide</span>
|
|
197
|
+
</Button>
|
|
198
|
+
)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function EmblaCarouselNext({
|
|
202
|
+
className,
|
|
203
|
+
variant = "outline",
|
|
204
|
+
size = "icon",
|
|
205
|
+
...props
|
|
206
|
+
}: React.ComponentProps<typeof Button>) {
|
|
207
|
+
const { orientation, scrollNext, canScrollNext } = useEmblaCarousel()
|
|
208
|
+
|
|
209
|
+
return (
|
|
210
|
+
<Button
|
|
211
|
+
data-slot="carousel-next"
|
|
212
|
+
variant={variant}
|
|
213
|
+
size={size}
|
|
214
|
+
className={cn(
|
|
215
|
+
"absolute size-8 rounded-full",
|
|
216
|
+
orientation === "horizontal"
|
|
217
|
+
? "top-1/2 -right-12 -translate-y-1/2"
|
|
218
|
+
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
219
|
+
className
|
|
220
|
+
)}
|
|
221
|
+
disabled={!canScrollNext}
|
|
222
|
+
onClick={scrollNext}
|
|
223
|
+
{...props}
|
|
224
|
+
>
|
|
225
|
+
<ArrowRight />
|
|
226
|
+
<span className="sr-only">Next slide</span>
|
|
227
|
+
</Button>
|
|
228
|
+
)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export {
|
|
232
|
+
type CarouselApi,
|
|
233
|
+
EmblaCarousel,
|
|
234
|
+
EmblaCarouselContent,
|
|
235
|
+
EmblaCarouselItem,
|
|
236
|
+
EmblaCarouselPrevious,
|
|
237
|
+
EmblaCarouselNext,
|
|
238
|
+
}
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import * as RechartsPrimitive from "recharts"
|
|
3
|
+
import { cn } from "~/components/catalyst-ui"
|
|
4
|
+
|
|
5
|
+
// @dev app/components/catalyst-ui/data/primitive-data.tsx:681
|
|
6
|
+
|
|
7
|
+
// Format: { THEME_NAME: CSS_SELECTOR }
|
|
8
|
+
const THEMES = { light: "", dark: ".dark" } as const
|
|
9
|
+
|
|
10
|
+
export type ChartConfig = {
|
|
11
|
+
[k in string]: {
|
|
12
|
+
label?: React.ReactNode
|
|
13
|
+
icon?: React.ComponentType
|
|
14
|
+
} & (
|
|
15
|
+
| { color?: string; theme?: never }
|
|
16
|
+
| { color?: never; theme: Record<keyof typeof THEMES, string> }
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type ChartContextProps = {
|
|
21
|
+
config: ChartConfig
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const ChartContext = React.createContext<ChartContextProps | null>(null)
|
|
25
|
+
|
|
26
|
+
function useChart() {
|
|
27
|
+
const context = React.useContext(ChartContext)
|
|
28
|
+
|
|
29
|
+
if (!context) {
|
|
30
|
+
throw new Error("useChart must be used within a <ChartContainer />")
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return context
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function ChartContainer({
|
|
37
|
+
id,
|
|
38
|
+
className,
|
|
39
|
+
children,
|
|
40
|
+
config,
|
|
41
|
+
...props
|
|
42
|
+
}: React.ComponentProps<"div"> & {
|
|
43
|
+
config: ChartConfig
|
|
44
|
+
children: React.ComponentProps<
|
|
45
|
+
typeof RechartsPrimitive.ResponsiveContainer
|
|
46
|
+
>["children"]
|
|
47
|
+
}) {
|
|
48
|
+
const uniqueId = React.useId()
|
|
49
|
+
const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<ChartContext.Provider value={{ config }}>
|
|
53
|
+
<div
|
|
54
|
+
data-slot="chart"
|
|
55
|
+
data-chart={chartId}
|
|
56
|
+
className={cn(
|
|
57
|
+
"[&_.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",
|
|
58
|
+
className
|
|
59
|
+
)}
|
|
60
|
+
{...props}
|
|
61
|
+
>
|
|
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
|
+
>
|
|
179
|
+
{!nestLabel ? tooltipLabel : null}
|
|
180
|
+
<div className="grid gap-1.5">
|
|
181
|
+
{payload.map((item, index) => {
|
|
182
|
+
const key = `${nameKey || item.name || item.dataKey || "value"}`
|
|
183
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key)
|
|
184
|
+
const indicatorColor = color || item.payload.fill || item.color
|
|
185
|
+
|
|
186
|
+
return (
|
|
187
|
+
<div
|
|
188
|
+
key={item.dataKey}
|
|
189
|
+
className={cn(
|
|
190
|
+
"[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5",
|
|
191
|
+
indicator === "dot" && "items-center"
|
|
192
|
+
)}
|
|
193
|
+
>
|
|
194
|
+
{formatter && item?.value !== undefined && item.name ? (
|
|
195
|
+
formatter(item.value, item.name, item, index, item.payload)
|
|
196
|
+
) : (
|
|
197
|
+
<>
|
|
198
|
+
{itemConfig?.icon ? (
|
|
199
|
+
<itemConfig.icon />
|
|
200
|
+
) : (
|
|
201
|
+
!hideIndicator && (
|
|
202
|
+
<div
|
|
203
|
+
className={cn(
|
|
204
|
+
"shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)",
|
|
205
|
+
{
|
|
206
|
+
"h-2.5 w-2.5": indicator === "dot",
|
|
207
|
+
"w-1": indicator === "line",
|
|
208
|
+
"w-0 border-[1.5px] border-dashed bg-transparent":
|
|
209
|
+
indicator === "dashed",
|
|
210
|
+
"my-0.5": nestLabel && indicator === "dashed",
|
|
211
|
+
}
|
|
212
|
+
)}
|
|
213
|
+
style={
|
|
214
|
+
{
|
|
215
|
+
"--color-bg": indicatorColor,
|
|
216
|
+
"--color-border": indicatorColor,
|
|
217
|
+
} as React.CSSProperties
|
|
218
|
+
}
|
|
219
|
+
/>
|
|
220
|
+
)
|
|
221
|
+
)}
|
|
222
|
+
<div
|
|
223
|
+
className={cn(
|
|
224
|
+
"flex flex-1 justify-between leading-none",
|
|
225
|
+
nestLabel ? "items-end" : "items-center"
|
|
226
|
+
)}
|
|
227
|
+
>
|
|
228
|
+
<div className="grid gap-1.5">
|
|
229
|
+
{nestLabel ? tooltipLabel : null}
|
|
230
|
+
<span className="text-muted-foreground">
|
|
231
|
+
{itemConfig?.label || item.name}
|
|
232
|
+
</span>
|
|
233
|
+
</div>
|
|
234
|
+
{item.value && (
|
|
235
|
+
<span className="text-foreground font-mono font-medium tabular-nums">
|
|
236
|
+
{item.value.toLocaleString()}
|
|
237
|
+
</span>
|
|
238
|
+
)}
|
|
239
|
+
</div>
|
|
240
|
+
</>
|
|
241
|
+
)}
|
|
242
|
+
</div>
|
|
243
|
+
)
|
|
244
|
+
})}
|
|
245
|
+
</div>
|
|
246
|
+
</div>
|
|
247
|
+
)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const ChartLegend = RechartsPrimitive.Legend
|
|
251
|
+
|
|
252
|
+
function ChartLegendContent({
|
|
253
|
+
className,
|
|
254
|
+
hideIcon = false,
|
|
255
|
+
payload,
|
|
256
|
+
verticalAlign = "bottom",
|
|
257
|
+
nameKey,
|
|
258
|
+
}: React.ComponentProps<"div"> &
|
|
259
|
+
Pick<RechartsPrimitive.LegendProps, "payload" | "verticalAlign"> & {
|
|
260
|
+
hideIcon?: boolean
|
|
261
|
+
nameKey?: string
|
|
262
|
+
}) {
|
|
263
|
+
const { config } = useChart()
|
|
264
|
+
|
|
265
|
+
if (!payload?.length) {
|
|
266
|
+
return null
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return (
|
|
270
|
+
<div
|
|
271
|
+
className={cn(
|
|
272
|
+
"flex items-center justify-center gap-4",
|
|
273
|
+
verticalAlign === "top" ? "pb-3" : "pt-3",
|
|
274
|
+
className
|
|
275
|
+
)}
|
|
276
|
+
>
|
|
277
|
+
{payload.map((item) => {
|
|
278
|
+
const key = `${nameKey || item.dataKey || "value"}`
|
|
279
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key)
|
|
280
|
+
|
|
281
|
+
return (
|
|
282
|
+
<div
|
|
283
|
+
key={item.value}
|
|
284
|
+
className={cn(
|
|
285
|
+
"[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3"
|
|
286
|
+
)}
|
|
287
|
+
>
|
|
288
|
+
{itemConfig?.icon && !hideIcon ? (
|
|
289
|
+
<itemConfig.icon />
|
|
290
|
+
) : (
|
|
291
|
+
<div
|
|
292
|
+
className="h-2 w-2 shrink-0 rounded-[2px]"
|
|
293
|
+
style={{
|
|
294
|
+
backgroundColor: item.color,
|
|
295
|
+
}}
|
|
296
|
+
/>
|
|
297
|
+
)}
|
|
298
|
+
{itemConfig?.label}
|
|
299
|
+
</div>
|
|
300
|
+
)
|
|
301
|
+
})}
|
|
302
|
+
</div>
|
|
303
|
+
)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// Helper to extract item config from a payload.
|
|
307
|
+
function getPayloadConfigFromPayload(
|
|
308
|
+
config: ChartConfig,
|
|
309
|
+
payload: unknown,
|
|
310
|
+
key: string
|
|
311
|
+
) {
|
|
312
|
+
if (typeof payload !== "object" || payload === null) {
|
|
313
|
+
return undefined
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const payloadPayload =
|
|
317
|
+
"payload" in payload &&
|
|
318
|
+
typeof payload.payload === "object" &&
|
|
319
|
+
payload.payload !== null
|
|
320
|
+
? payload.payload
|
|
321
|
+
: undefined
|
|
322
|
+
|
|
323
|
+
let configLabelKey: string = key
|
|
324
|
+
|
|
325
|
+
if (
|
|
326
|
+
key in payload &&
|
|
327
|
+
typeof payload[key as keyof typeof payload] === "string"
|
|
328
|
+
) {
|
|
329
|
+
configLabelKey = payload[key as keyof typeof payload] as string
|
|
330
|
+
} else if (
|
|
331
|
+
payloadPayload &&
|
|
332
|
+
key in payloadPayload &&
|
|
333
|
+
typeof payloadPayload[key as keyof typeof payloadPayload] === "string"
|
|
334
|
+
) {
|
|
335
|
+
configLabelKey = payloadPayload[
|
|
336
|
+
key as keyof typeof payloadPayload
|
|
337
|
+
] as string
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
return configLabelKey in config
|
|
341
|
+
? config[configLabelKey]
|
|
342
|
+
: config[key as keyof typeof config]
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export {
|
|
346
|
+
ChartContainer, ChartTooltip, ChartTooltipContent, ChartLegend, ChartLegendContent, ChartStyle
|
|
347
|
+
}
|