@coze-arch/cli 0.0.1-alpha.035e0e

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 (156) hide show
  1. package/README.md +142 -0
  2. package/bin/main +2 -0
  3. package/lib/__templates__/expo/.coze +12 -0
  4. package/lib/__templates__/expo/.cozeproj/scripts/dev_build.sh +46 -0
  5. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +220 -0
  6. package/lib/__templates__/expo/.cozeproj/scripts/prod_build.sh +47 -0
  7. package/lib/__templates__/expo/.cozeproj/scripts/prod_run.sh +34 -0
  8. package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +45 -0
  9. package/lib/__templates__/expo/README.md +72 -0
  10. package/lib/__templates__/expo/_gitignore +11 -0
  11. package/lib/__templates__/expo/_npmrc +20 -0
  12. package/lib/__templates__/expo/client/app/_layout.tsx +33 -0
  13. package/lib/__templates__/expo/client/app/demo.tsx +1 -0
  14. package/lib/__templates__/expo/client/app/index.tsx +1 -0
  15. package/lib/__templates__/expo/client/app.config.ts +75 -0
  16. package/lib/__templates__/expo/client/assets/fonts/SpaceMono-Regular.ttf +0 -0
  17. package/lib/__templates__/expo/client/assets/images/adaptive-icon.png +0 -0
  18. package/lib/__templates__/expo/client/assets/images/default-avatar.png +0 -0
  19. package/lib/__templates__/expo/client/assets/images/favicon.png +0 -0
  20. package/lib/__templates__/expo/client/assets/images/icon.png +0 -0
  21. package/lib/__templates__/expo/client/assets/images/partial-react-logo.png +0 -0
  22. package/lib/__templates__/expo/client/assets/images/react-logo.png +0 -0
  23. package/lib/__templates__/expo/client/assets/images/react-logo@2x.png +0 -0
  24. package/lib/__templates__/expo/client/assets/images/react-logo@3x.png +0 -0
  25. package/lib/__templates__/expo/client/assets/images/splash-icon.png +0 -0
  26. package/lib/__templates__/expo/client/components/Screen.tsx +330 -0
  27. package/lib/__templates__/expo/client/components/SmartDateInput.tsx +238 -0
  28. package/lib/__templates__/expo/client/components/ThemedText.tsx +33 -0
  29. package/lib/__templates__/expo/client/components/ThemedView.tsx +38 -0
  30. package/lib/__templates__/expo/client/constants/theme.ts +854 -0
  31. package/lib/__templates__/expo/client/contexts/AuthContext.tsx +49 -0
  32. package/lib/__templates__/expo/client/declarations.d.ts +5 -0
  33. package/lib/__templates__/expo/client/eslint-formatter-simple.mjs +49 -0
  34. package/lib/__templates__/expo/client/eslint.config.mjs +98 -0
  35. package/lib/__templates__/expo/client/hooks/useColorScheme.ts +34 -0
  36. package/lib/__templates__/expo/client/hooks/useTheme.ts +13 -0
  37. package/lib/__templates__/expo/client/metro.config.js +121 -0
  38. package/lib/__templates__/expo/client/package.json +93 -0
  39. package/lib/__templates__/expo/client/screens/demo/index.tsx +25 -0
  40. package/lib/__templates__/expo/client/screens/demo/styles.ts +28 -0
  41. package/lib/__templates__/expo/client/scripts/install-missing-deps.js +104 -0
  42. package/lib/__templates__/expo/client/tsconfig.json +24 -0
  43. package/lib/__templates__/expo/client/utils/index.ts +54 -0
  44. package/lib/__templates__/expo/package.json +22 -0
  45. package/lib/__templates__/expo/pnpm-lock.yaml +13975 -0
  46. package/lib/__templates__/expo/pnpm-workspace.yaml +3 -0
  47. package/lib/__templates__/expo/server/package.json +32 -0
  48. package/lib/__templates__/expo/server/src/index.ts +18 -0
  49. package/lib/__templates__/expo/server/tsconfig.json +24 -0
  50. package/lib/__templates__/expo/template.config.js +50 -0
  51. package/lib/__templates__/expo/tsconfig.json +1 -0
  52. package/lib/__templates__/nextjs/.coze +12 -0
  53. package/lib/__templates__/nextjs/README.md +358 -0
  54. package/lib/__templates__/nextjs/_gitignore +99 -0
  55. package/lib/__templates__/nextjs/_npmrc +23 -0
  56. package/lib/__templates__/nextjs/components.json +21 -0
  57. package/lib/__templates__/nextjs/eslint.config.mjs +18 -0
  58. package/lib/__templates__/nextjs/next-env.d.ts +6 -0
  59. package/lib/__templates__/nextjs/next.config.ts +19 -0
  60. package/lib/__templates__/nextjs/package.json +86 -0
  61. package/lib/__templates__/nextjs/pnpm-lock.yaml +10493 -0
  62. package/lib/__templates__/nextjs/postcss.config.mjs +7 -0
  63. package/lib/__templates__/nextjs/public/file.svg +1 -0
  64. package/lib/__templates__/nextjs/public/globe.svg +1 -0
  65. package/lib/__templates__/nextjs/public/next.svg +1 -0
  66. package/lib/__templates__/nextjs/public/vercel.svg +1 -0
  67. package/lib/__templates__/nextjs/public/window.svg +1 -0
  68. package/lib/__templates__/nextjs/scripts/build.sh +14 -0
  69. package/lib/__templates__/nextjs/scripts/dev.sh +33 -0
  70. package/lib/__templates__/nextjs/scripts/prepare.sh +9 -0
  71. package/lib/__templates__/nextjs/scripts/start.sh +15 -0
  72. package/lib/__templates__/nextjs/src/app/favicon.ico +0 -0
  73. package/lib/__templates__/nextjs/src/app/globals.css +137 -0
  74. package/lib/__templates__/nextjs/src/app/layout.tsx +72 -0
  75. package/lib/__templates__/nextjs/src/app/page.tsx +78 -0
  76. package/lib/__templates__/nextjs/src/app/robots.ts +11 -0
  77. package/lib/__templates__/nextjs/src/components/ui/accordion.tsx +66 -0
  78. package/lib/__templates__/nextjs/src/components/ui/alert-dialog.tsx +157 -0
  79. package/lib/__templates__/nextjs/src/components/ui/alert.tsx +66 -0
  80. package/lib/__templates__/nextjs/src/components/ui/aspect-ratio.tsx +11 -0
  81. package/lib/__templates__/nextjs/src/components/ui/avatar.tsx +53 -0
  82. package/lib/__templates__/nextjs/src/components/ui/badge.tsx +46 -0
  83. package/lib/__templates__/nextjs/src/components/ui/breadcrumb.tsx +109 -0
  84. package/lib/__templates__/nextjs/src/components/ui/button-group.tsx +83 -0
  85. package/lib/__templates__/nextjs/src/components/ui/button.tsx +62 -0
  86. package/lib/__templates__/nextjs/src/components/ui/calendar.tsx +220 -0
  87. package/lib/__templates__/nextjs/src/components/ui/card.tsx +92 -0
  88. package/lib/__templates__/nextjs/src/components/ui/carousel.tsx +241 -0
  89. package/lib/__templates__/nextjs/src/components/ui/chart.tsx +357 -0
  90. package/lib/__templates__/nextjs/src/components/ui/checkbox.tsx +32 -0
  91. package/lib/__templates__/nextjs/src/components/ui/collapsible.tsx +33 -0
  92. package/lib/__templates__/nextjs/src/components/ui/command.tsx +184 -0
  93. package/lib/__templates__/nextjs/src/components/ui/context-menu.tsx +252 -0
  94. package/lib/__templates__/nextjs/src/components/ui/dialog.tsx +143 -0
  95. package/lib/__templates__/nextjs/src/components/ui/drawer.tsx +135 -0
  96. package/lib/__templates__/nextjs/src/components/ui/dropdown-menu.tsx +257 -0
  97. package/lib/__templates__/nextjs/src/components/ui/empty.tsx +104 -0
  98. package/lib/__templates__/nextjs/src/components/ui/field.tsx +248 -0
  99. package/lib/__templates__/nextjs/src/components/ui/form.tsx +167 -0
  100. package/lib/__templates__/nextjs/src/components/ui/hover-card.tsx +44 -0
  101. package/lib/__templates__/nextjs/src/components/ui/input-group.tsx +170 -0
  102. package/lib/__templates__/nextjs/src/components/ui/input-otp.tsx +77 -0
  103. package/lib/__templates__/nextjs/src/components/ui/input.tsx +21 -0
  104. package/lib/__templates__/nextjs/src/components/ui/item.tsx +193 -0
  105. package/lib/__templates__/nextjs/src/components/ui/kbd.tsx +28 -0
  106. package/lib/__templates__/nextjs/src/components/ui/label.tsx +24 -0
  107. package/lib/__templates__/nextjs/src/components/ui/menubar.tsx +276 -0
  108. package/lib/__templates__/nextjs/src/components/ui/navigation-menu.tsx +168 -0
  109. package/lib/__templates__/nextjs/src/components/ui/pagination.tsx +127 -0
  110. package/lib/__templates__/nextjs/src/components/ui/popover.tsx +48 -0
  111. package/lib/__templates__/nextjs/src/components/ui/progress.tsx +31 -0
  112. package/lib/__templates__/nextjs/src/components/ui/radio-group.tsx +45 -0
  113. package/lib/__templates__/nextjs/src/components/ui/resizable.tsx +63 -0
  114. package/lib/__templates__/nextjs/src/components/ui/scroll-area.tsx +58 -0
  115. package/lib/__templates__/nextjs/src/components/ui/select.tsx +190 -0
  116. package/lib/__templates__/nextjs/src/components/ui/separator.tsx +28 -0
  117. package/lib/__templates__/nextjs/src/components/ui/sheet.tsx +139 -0
  118. package/lib/__templates__/nextjs/src/components/ui/sidebar.tsx +724 -0
  119. package/lib/__templates__/nextjs/src/components/ui/skeleton.tsx +13 -0
  120. package/lib/__templates__/nextjs/src/components/ui/slider.tsx +63 -0
  121. package/lib/__templates__/nextjs/src/components/ui/sonner.tsx +40 -0
  122. package/lib/__templates__/nextjs/src/components/ui/spinner.tsx +16 -0
  123. package/lib/__templates__/nextjs/src/components/ui/switch.tsx +31 -0
  124. package/lib/__templates__/nextjs/src/components/ui/table.tsx +116 -0
  125. package/lib/__templates__/nextjs/src/components/ui/tabs.tsx +66 -0
  126. package/lib/__templates__/nextjs/src/components/ui/textarea.tsx +18 -0
  127. package/lib/__templates__/nextjs/src/components/ui/toggle-group.tsx +83 -0
  128. package/lib/__templates__/nextjs/src/components/ui/toggle.tsx +47 -0
  129. package/lib/__templates__/nextjs/src/components/ui/tooltip.tsx +61 -0
  130. package/lib/__templates__/nextjs/src/hooks/use-mobile.ts +19 -0
  131. package/lib/__templates__/nextjs/src/lib/utils.ts +6 -0
  132. package/lib/__templates__/nextjs/template.config.js +85 -0
  133. package/lib/__templates__/nextjs/tsconfig.json +34 -0
  134. package/lib/__templates__/templates.json +87 -0
  135. package/lib/__templates__/vite/.coze +12 -0
  136. package/lib/__templates__/vite/README.md +239 -0
  137. package/lib/__templates__/vite/_gitignore +66 -0
  138. package/lib/__templates__/vite/_npmrc +23 -0
  139. package/lib/__templates__/vite/eslint.config.mjs +9 -0
  140. package/lib/__templates__/vite/index.html +13 -0
  141. package/lib/__templates__/vite/package.json +28 -0
  142. package/lib/__templates__/vite/pnpm-lock.yaml +4716 -0
  143. package/lib/__templates__/vite/postcss.config.js +6 -0
  144. package/lib/__templates__/vite/scripts/build.sh +14 -0
  145. package/lib/__templates__/vite/scripts/dev.sh +32 -0
  146. package/lib/__templates__/vite/scripts/prepare.sh +9 -0
  147. package/lib/__templates__/vite/scripts/start.sh +15 -0
  148. package/lib/__templates__/vite/src/index.css +21 -0
  149. package/lib/__templates__/vite/src/index.ts +5 -0
  150. package/lib/__templates__/vite/src/main.ts +64 -0
  151. package/lib/__templates__/vite/tailwind.config.js +9 -0
  152. package/lib/__templates__/vite/template.config.js +90 -0
  153. package/lib/__templates__/vite/tsconfig.json +16 -0
  154. package/lib/__templates__/vite/vite.config.ts +15 -0
  155. package/lib/cli.js +1916 -0
  156. package/package.json +77 -0
@@ -0,0 +1,92 @@
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-2 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
+ }
@@ -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 "@/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
+ >
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,357 @@
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
+ }