moi-computer 0.11.0 → 0.11.1-next.1

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 (196) hide show
  1. package/client/AGENTS.md +2 -2
  2. package/client/components/ui/button.tsx +1 -53
  3. package/client/components/ui/collapsible.tsx +1 -15
  4. package/client/components/ui/dialog.tsx +1 -58
  5. package/client/components/ui/dropdown-menu.tsx +1 -254
  6. package/client/components/ui/hover-card.tsx +1 -44
  7. package/client/components/ui/input.tsx +1 -21
  8. package/client/components/ui/popover.tsx +1 -88
  9. package/client/components/ui/resizable.tsx +1 -40
  10. package/client/components/ui/skeleton.tsx +1 -13
  11. package/client/components/ui/slider.tsx +1 -70
  12. package/client/components/ui/spinner.tsx +1 -18
  13. package/client/components/ui/switch.tsx +1 -23
  14. package/client/components/ui/tabs.tsx +1 -0
  15. package/client/components/ui/textarea.tsx +1 -18
  16. package/client/components/ui/tooltip.tsx +1 -51
  17. package/client/features/chat/ChatPanel.tsx +6 -6
  18. package/client/features/chat/ChatPopup.tsx +3 -4
  19. package/client/features/chat/TurnView.tsx +5 -4
  20. package/client/features/chat/api.ts +5 -14
  21. package/client/features/chat/chat-frames.ts +5 -2
  22. package/client/features/chat/composer/ChatComposer.tsx +5 -1
  23. package/client/features/chat/composer/ModelPicker.tsx +4 -3
  24. package/client/features/chat/composer/banners/ErrorBanner.tsx +20 -12
  25. package/client/features/chat/composer/useWorkspaceComposerState.tsx +15 -7
  26. package/client/features/chat/group-turns.ts +11 -0
  27. package/client/features/chat/session-view.ts +53 -0
  28. package/client/features/chat/useChat.ts +5 -1
  29. package/client/features/dev/ChatStatesPage.tsx +3 -1
  30. package/client/features/dev/DevIndexPage.tsx +5 -0
  31. package/client/features/dev/DevRoutes.tsx +2 -0
  32. package/client/features/dev/HarnessDebugPage.tsx +1 -1
  33. package/client/features/dev/UiComponentPreviews.tsx +834 -0
  34. package/client/features/dev/UiComponentsPage.tsx +60 -0
  35. package/client/features/home/WorkspacePreview.tsx +1 -1
  36. package/client/features/home/workspace-setup/DemoDialog.tsx +3 -2
  37. package/client/features/home/workspace-setup/ImportWorkspaceDialog.tsx +5 -8
  38. package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +7 -20
  39. package/client/features/settings/SettingsLayout.tsx +1 -1
  40. package/client/features/settings/WorkspaceSettings.tsx +4 -1
  41. package/client/features/views/ViewManager.tsx +14 -9
  42. package/client/features/widgets/WidgetFrame.tsx +1 -1
  43. package/client/features/widgets/Widgets.tsx +1 -3
  44. package/client/features/workspace/WorkspaceScreen.tsx +5 -1
  45. package/client/features/workspace/WorkspaceSplitLayout.tsx +6 -1
  46. package/client/features/workspace/api.ts +2 -4
  47. package/client/index.css +22 -29
  48. package/dist/{chunk-tny85yt2.js → chunk-4s15axjs.js} +2 -2
  49. package/dist/{chunk-c9pjqx9m.js → chunk-53a7pxcz.js} +1 -1
  50. package/dist/chunk-6664vxpk.css +1 -0
  51. package/dist/{chunk-104m57qw.js → chunk-87thzbtw.js} +2 -2
  52. package/dist/chunk-a6jad1a6.js +1 -0
  53. package/dist/chunk-dghwstd2.js +9 -0
  54. package/dist/chunk-eg120aca.js +1 -0
  55. package/dist/{chunk-v7wr1df4.js → chunk-j3wvxjr7.js} +1 -1
  56. package/dist/chunk-vwjeezeb.js +1 -0
  57. package/dist/chunk-w482ew2c.js +546 -0
  58. package/dist/chunk-yc471zah.js +70 -0
  59. package/dist/index.html +1 -1
  60. package/lib/format.ts +49 -1
  61. package/lib/themes.ts +6 -6
  62. package/lib/types.ts +5 -7
  63. package/package.json +17 -7
  64. package/registry.json +643 -0
  65. package/server/AGENTS.md +1 -0
  66. package/server/agent.ts +1 -1
  67. package/server/api.ts +25 -29
  68. package/server/applets.ts +30 -29
  69. package/server/bundler/applet-css.ts +6 -1
  70. package/server/bundler/build-applet.ts +5 -1
  71. package/server/bundler/build-worker.ts +178 -0
  72. package/server/cli-ui-components.ts +28 -33
  73. package/server/cli.ts +6 -11
  74. package/server/data-dir.ts +1 -1
  75. package/server/harness/README.md +13 -9
  76. package/server/harness/acp/NOTES.md +426 -0
  77. package/server/harness/acp/discovery.ts +27 -30
  78. package/server/harness/acp/model-state.ts +57 -0
  79. package/server/harness/acp/session.ts +18 -6
  80. package/server/harness/claude-code/NOTES.md +47 -12
  81. package/server/harness/claude-code/cli.ts +40 -0
  82. package/server/harness/claude-code/index.ts +11 -5
  83. package/server/harness/claude-code/models.ts +72 -19
  84. package/server/harness/claude-code/session.ts +408 -299
  85. package/server/harness/hermes/NOTES.md +18 -0
  86. package/server/harness/hermes/discovery.ts +20 -0
  87. package/server/harness/hermes/index.ts +9 -0
  88. package/server/harness/hermes/models.ts +28 -8
  89. package/server/harness/types.ts +4 -2
  90. package/server/moi-scaffold.ts +1 -1
  91. package/server/preview.ts +3 -1
  92. package/server/registry.ts +63 -41
  93. package/server/scratchpad-executor.ts +79 -56
  94. package/server/scratchpad-shape-defaults.ts +82 -0
  95. package/server/tldraw-package.d.ts +4 -0
  96. package/server/ui-components.ts +101 -434
  97. package/server/view-builders.ts +2 -1
  98. package/server/web.ts +9 -5
  99. package/server/workspace-env.ts +3 -2
  100. package/tsconfig.json +0 -1
  101. package/ui-components/accordion.tsx +71 -0
  102. package/ui-components/alert-dialog.tsx +165 -0
  103. package/ui-components/alert.tsx +68 -0
  104. package/ui-components/attachment.tsx +195 -0
  105. package/ui-components/avatar.tsx +90 -0
  106. package/ui-components/badge.tsx +49 -0
  107. package/ui-components/button-group.tsx +78 -0
  108. package/ui-components/button.tsx +55 -0
  109. package/ui-components/calendar.tsx +180 -0
  110. package/ui-components/card.tsx +84 -0
  111. package/ui-components/carousel.tsx +235 -0
  112. package/ui-components/chart.tsx +338 -0
  113. package/ui-components/checkbox.tsx +27 -0
  114. package/ui-components/collapsible.tsx +15 -0
  115. package/ui-components/combobox.tsx +265 -0
  116. package/ui-components/context-menu.tsx +244 -0
  117. package/ui-components/dialog.tsx +138 -0
  118. package/ui-components/docs/accordion.md +463 -0
  119. package/ui-components/docs/alert-dialog.md +481 -0
  120. package/ui-components/docs/alert.md +301 -0
  121. package/ui-components/docs/attachment.md +689 -0
  122. package/ui-components/docs/avatar.md +495 -0
  123. package/ui-components/docs/badge.md +258 -0
  124. package/ui-components/docs/button-group.md +879 -0
  125. package/ui-components/docs/button.md +26 -0
  126. package/ui-components/docs/calendar.md +862 -0
  127. package/ui-components/docs/card.md +265 -0
  128. package/ui-components/docs/carousel.md +627 -0
  129. package/ui-components/docs/chart.md +1256 -0
  130. package/ui-components/docs/checkbox.md +477 -0
  131. package/ui-components/docs/collapsible.md +446 -0
  132. package/ui-components/docs/combobox.md +1003 -0
  133. package/ui-components/docs/context-menu.md +860 -0
  134. package/ui-components/docs/data-table.md +1580 -0
  135. package/ui-components/docs/date-picker.md +614 -0
  136. package/ui-components/docs/dialog.md +414 -0
  137. package/ui-components/docs/drawer.md +51 -0
  138. package/ui-components/docs/dropdown-menu.md +1000 -0
  139. package/ui-components/docs/field.md +1192 -0
  140. package/ui-components/docs/hover-card.md +275 -0
  141. package/ui-components/docs/input-group.md +866 -0
  142. package/ui-components/docs/input.md +456 -0
  143. package/ui-components/docs/label.md +295 -0
  144. package/ui-components/docs/pagination.md +416 -0
  145. package/ui-components/docs/popover.md +348 -0
  146. package/ui-components/docs/progress.md +214 -0
  147. package/ui-components/docs/radio-group.md +389 -0
  148. package/ui-components/docs/resizable.md +265 -0
  149. package/ui-components/docs/select.md +616 -0
  150. package/ui-components/docs/separator.md +216 -0
  151. package/ui-components/docs/skeleton.md +205 -0
  152. package/ui-components/docs/slider.md +226 -0
  153. package/ui-components/docs/spinner.md +332 -0
  154. package/ui-components/docs/switch.md +236 -0
  155. package/ui-components/docs/table.md +551 -0
  156. package/ui-components/docs/tabs.md +379 -0
  157. package/ui-components/docs/textarea.md +187 -0
  158. package/ui-components/docs/toggle-group.md +370 -0
  159. package/ui-components/docs/toggle.md +91 -0
  160. package/ui-components/docs/tooltip.md +290 -0
  161. package/ui-components/drawer.tsx +213 -0
  162. package/ui-components/dropdown-menu.tsx +263 -0
  163. package/ui-components/field.tsx +224 -0
  164. package/ui-components/hover-card.tsx +46 -0
  165. package/ui-components/input-group.tsx +146 -0
  166. package/ui-components/input.tsx +20 -0
  167. package/ui-components/label.tsx +17 -0
  168. package/ui-components/pagination.tsx +124 -0
  169. package/ui-components/popover.tsx +81 -0
  170. package/ui-components/progress.tsx +63 -0
  171. package/ui-components/radio-group.tsx +37 -0
  172. package/ui-components/resizable.tsx +40 -0
  173. package/ui-components/scoped-portal.tsx +31 -0
  174. package/ui-components/select.tsx +195 -0
  175. package/ui-components/separator.tsx +18 -0
  176. package/ui-components/skeleton.tsx +15 -0
  177. package/ui-components/slider.tsx +75 -0
  178. package/ui-components/spinner.tsx +20 -0
  179. package/ui-components/switch.tsx +26 -0
  180. package/ui-components/table.tsx +86 -0
  181. package/ui-components/tabs.tsx +75 -0
  182. package/ui-components/textarea.tsx +17 -0
  183. package/ui-components/toggle-group.tsx +85 -0
  184. package/ui-components/toggle.tsx +42 -0
  185. package/ui-components/tooltip.tsx +61 -0
  186. package/ui-components/utils.ts +8 -0
  187. package/workspace/.claude/skills/moi-workspace/SKILL.md +11 -20
  188. package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +4 -3
  189. package/workspace/.claude/skills/moi-workspace/references/UI-COMPONENTS.md +67 -203
  190. package/dist/chunk-59zf0m6n.js +0 -1
  191. package/dist/chunk-bj3akjs2.js +0 -1
  192. package/dist/chunk-j2w2vak4.js +0 -546
  193. package/dist/chunk-k2r9c95m.js +0 -10
  194. package/dist/chunk-kmbxhgwv.js +0 -1
  195. package/dist/chunk-p1yqa71k.js +0 -83
  196. package/dist/chunk-r5xrenjy.css +0 -1
@@ -0,0 +1,1256 @@
1
+ ---
2
+ title: Chart
3
+ description: Beautiful charts. Built using Recharts. Copy and paste into your apps.
4
+ base: base
5
+ component: true
6
+ ---
7
+
8
+ <Callout className="mt-4">
9
+
10
+ **Updated:** The `chart` component now uses Recharts v3. If you're upgrading existing chart code, see [Updating to Recharts v3](#updating-to-recharts-v3).
11
+
12
+ </Callout>
13
+
14
+ ```tsx
15
+ 'use client'
16
+
17
+ import * as React from 'react'
18
+ import { Bar, BarChart, CartesianGrid, XAxis } from 'recharts'
19
+
20
+ import {
21
+ Card,
22
+ CardContent,
23
+ CardDescription,
24
+ CardHeader,
25
+ CardTitle
26
+ } from '@/registry/new-york-v4/ui/card'
27
+ import {
28
+ ChartContainer,
29
+ ChartTooltip,
30
+ ChartTooltipContent,
31
+ type ChartConfig
32
+ } from '@/registry/new-york-v4/ui/chart'
33
+
34
+ export const description = 'An interactive bar chart'
35
+
36
+ const chartData = [
37
+ { date: '2024-04-01', desktop: 222, mobile: 150 },
38
+ { date: '2024-04-02', desktop: 97, mobile: 180 },
39
+ { date: '2024-04-03', desktop: 167, mobile: 120 },
40
+ { date: '2024-04-04', desktop: 242, mobile: 260 },
41
+ { date: '2024-04-05', desktop: 373, mobile: 290 },
42
+ { date: '2024-04-06', desktop: 301, mobile: 340 },
43
+ { date: '2024-04-07', desktop: 245, mobile: 180 },
44
+ { date: '2024-04-08', desktop: 409, mobile: 320 },
45
+ { date: '2024-04-09', desktop: 59, mobile: 110 },
46
+ { date: '2024-04-10', desktop: 261, mobile: 190 },
47
+ { date: '2024-04-11', desktop: 327, mobile: 350 },
48
+ { date: '2024-04-12', desktop: 292, mobile: 210 },
49
+ { date: '2024-04-13', desktop: 342, mobile: 380 },
50
+ { date: '2024-04-14', desktop: 137, mobile: 220 },
51
+ { date: '2024-04-15', desktop: 120, mobile: 170 },
52
+ { date: '2024-04-16', desktop: 138, mobile: 190 },
53
+ { date: '2024-04-17', desktop: 446, mobile: 360 },
54
+ { date: '2024-04-18', desktop: 364, mobile: 410 },
55
+ { date: '2024-04-19', desktop: 243, mobile: 180 },
56
+ { date: '2024-04-20', desktop: 89, mobile: 150 },
57
+ { date: '2024-04-21', desktop: 137, mobile: 200 },
58
+ { date: '2024-04-22', desktop: 224, mobile: 170 },
59
+ { date: '2024-04-23', desktop: 138, mobile: 230 },
60
+ { date: '2024-04-24', desktop: 387, mobile: 290 },
61
+ { date: '2024-04-25', desktop: 215, mobile: 250 },
62
+ { date: '2024-04-26', desktop: 75, mobile: 130 },
63
+ { date: '2024-04-27', desktop: 383, mobile: 420 },
64
+ { date: '2024-04-28', desktop: 122, mobile: 180 },
65
+ { date: '2024-04-29', desktop: 315, mobile: 240 },
66
+ { date: '2024-04-30', desktop: 454, mobile: 380 }
67
+ ]
68
+
69
+ const chartConfig = {
70
+ views: {
71
+ label: 'Page Views'
72
+ },
73
+ desktop: {
74
+ label: 'Desktop',
75
+ color: 'var(--chart-2)'
76
+ },
77
+ mobile: {
78
+ label: 'Mobile',
79
+ color: 'var(--chart-1)'
80
+ }
81
+ } satisfies ChartConfig
82
+
83
+ export function ChartDemo() {
84
+ const [activeChart, setActiveChart] = React.useState<keyof typeof chartConfig>('desktop')
85
+
86
+ const total = React.useMemo(
87
+ () => ({
88
+ desktop: chartData.reduce((acc, curr) => acc + curr.desktop, 0),
89
+ mobile: chartData.reduce((acc, curr) => acc + curr.mobile, 0)
90
+ }),
91
+ []
92
+ )
93
+
94
+ return (
95
+ <Card className="py-0 pb-4">
96
+ <CardHeader className="flex flex-col items-stretch border-b p-0! sm:flex-row">
97
+ <div className="flex flex-1 flex-col justify-center gap-1 px-6 pt-4 pb-3 sm:py-0!">
98
+ <CardTitle>Bar Chart - Interactive</CardTitle>
99
+ <CardDescription>Showing total visitors for the last 3 months</CardDescription>
100
+ </div>
101
+ <div className="flex">
102
+ {['desktop', 'mobile'].map(key => {
103
+ const chart = key as keyof typeof chartConfig
104
+ return (
105
+ <button
106
+ key={chart}
107
+ data-active={activeChart === chart}
108
+ className="relative z-30 flex flex-1 flex-col justify-center gap-1 border-t px-6 py-4 text-left even:border-l data-[active=true]:bg-muted/50 sm:border-t-0 sm:border-l sm:px-8 sm:py-6"
109
+ onClick={() => setActiveChart(chart)}
110
+ >
111
+ <span className="text-xs text-muted-foreground">{chartConfig[chart].label}</span>
112
+ <span className="text-lg leading-none font-bold sm:text-3xl">
113
+ {total[key as keyof typeof total].toLocaleString()}
114
+ </span>
115
+ </button>
116
+ )
117
+ })}
118
+ </div>
119
+ </CardHeader>
120
+ <CardContent className="px-2 sm:p-6">
121
+ <ChartContainer config={chartConfig} className="aspect-auto h-[250px] w-full">
122
+ <BarChart
123
+ accessibilityLayer
124
+ data={chartData}
125
+ margin={{
126
+ left: 12,
127
+ right: 12
128
+ }}
129
+ >
130
+ <CartesianGrid vertical={false} />
131
+ <XAxis
132
+ dataKey="date"
133
+ tickLine={false}
134
+ axisLine={false}
135
+ tickMargin={8}
136
+ minTickGap={32}
137
+ tickFormatter={value => {
138
+ const date = new Date(value)
139
+ return date.toLocaleDateString('en-US', {
140
+ month: 'short',
141
+ day: 'numeric'
142
+ })
143
+ }}
144
+ />
145
+ <ChartTooltip
146
+ content={
147
+ <ChartTooltipContent
148
+ className="w-[150px]"
149
+ nameKey="views"
150
+ labelFormatter={value => {
151
+ return new Date(value).toLocaleDateString('en-US', {
152
+ month: 'short',
153
+ day: 'numeric',
154
+ year: 'numeric'
155
+ })
156
+ }}
157
+ />
158
+ }
159
+ />
160
+ <Bar dataKey={activeChart} fill={`var(--color-${activeChart})`} />
161
+ </BarChart>
162
+ </ChartContainer>
163
+ </CardContent>
164
+ </Card>
165
+ )
166
+ }
167
+ ```
168
+
169
+ Introducing **Charts**. A collection of chart components that you can copy and paste into your apps.
170
+
171
+ Charts are designed to look great out of the box. They work well with the other components and are fully customizable to fit your project.
172
+
173
+ [Browse the Charts Library](/charts).
174
+
175
+ ## Component
176
+
177
+ We use [Recharts](https://recharts.org/) under the hood.
178
+
179
+ We designed the `chart` component with composition in mind. **You build your charts using Recharts components and only bring in custom components, such as `ChartTooltip`, when and where you need it**.
180
+
181
+ ```tsx showLineNumbers /ChartContainer/ /ChartTooltipContent/
182
+ import { Bar, BarChart } from 'recharts'
183
+
184
+ import { ChartContainer, ChartTooltipContent } from '@/components/ui/chart'
185
+
186
+ export function MyChart() {
187
+ return (
188
+ <ChartContainer>
189
+ <BarChart data={data}>
190
+ <Bar dataKey="value" />
191
+ <ChartTooltip content={<ChartTooltipContent />} />
192
+ </BarChart>
193
+ </ChartContainer>
194
+ )
195
+ }
196
+ ```
197
+
198
+ We do not wrap Recharts. This means you're not locked into an abstraction. When a new Recharts version is released, you can follow the official upgrade path to upgrade your charts.
199
+
200
+ **The components are yours**.
201
+
202
+ ## Updating to Recharts v3
203
+
204
+ If you're updating older chart code to Recharts v3:
205
+
206
+ - Use `var(--chart-1)` instead of `hsl(var(--chart-1))` when you reference chart tokens from your CSS variables.
207
+ - Use `ChartTooltip.defaultIndex` for initial tooltip state only. Keep persistent active shapes in your own chart state.
208
+ - Remove `layout` from `<Bar>` when the parent `<BarChart>` already defines it.
209
+ - Keep a height, `min-h-*`, or `aspect-*` on `ChartContainer` so `ResponsiveContainer` can measure on first render.
210
+
211
+ ## Installation
212
+
213
+ <CodeTabs>
214
+
215
+ <TabsList>
216
+ <TabsTrigger value="cli">Command</TabsTrigger>
217
+ <TabsTrigger value="manual">Manual</TabsTrigger>
218
+ </TabsList>
219
+ <TabsContent value="cli">
220
+
221
+ ```bash
222
+ moi ui-components add chart
223
+ ```
224
+
225
+ </TabsContent>
226
+
227
+ <TabsContent value="manual">
228
+
229
+ <Steps className="mb-0 pt-2">
230
+
231
+ <Step>Install the following dependencies:</Step>
232
+
233
+ ```bash
234
+ npm install recharts
235
+ ```
236
+
237
+ <Step>Copy and paste the following code into `components/ui/chart.tsx`.</Step>
238
+
239
+ <ComponentSource
240
+ name="chart"
241
+ title="components/ui/chart.tsx"
242
+ styleName="base-nova"
243
+ />
244
+
245
+ <Step>Add the following colors to your CSS file</Step>
246
+
247
+ ```css title="app/globals.css" showLineNumbers
248
+ @layer base {
249
+ :root {
250
+ --chart-1: oklch(0.646 0.222 41.116);
251
+ --chart-2: oklch(0.6 0.118 184.704);
252
+ --chart-3: oklch(0.398 0.07 227.392);
253
+ --chart-4: oklch(0.828 0.189 84.429);
254
+ --chart-5: oklch(0.769 0.188 70.08);
255
+ }
256
+
257
+ .dark {
258
+ --chart-1: oklch(0.488 0.243 264.376);
259
+ --chart-2: oklch(0.696 0.17 162.48);
260
+ --chart-3: oklch(0.769 0.188 70.08);
261
+ --chart-4: oklch(0.627 0.265 303.9);
262
+ --chart-5: oklch(0.645 0.246 16.439);
263
+ }
264
+ }
265
+ ```
266
+
267
+ </Steps>
268
+
269
+ </TabsContent>
270
+
271
+ </CodeTabs>
272
+
273
+ ## Your First Chart
274
+
275
+ Let's build your first chart. We'll build a bar chart, add a grid, axis, tooltip and legend.
276
+
277
+ <Steps>
278
+
279
+ <Step>Start by defining your data</Step>
280
+
281
+ The following data represents the number of desktop and mobile users for each month.
282
+
283
+ <Callout className="mt-4">
284
+
285
+ **Note:** Your data can be in any shape. You are not limited to the shape of the data below. Use the `dataKey` prop to map your data to the chart.
286
+
287
+ </Callout>
288
+
289
+ ```tsx title="components/example-chart.tsx" showLineNumbers
290
+ const chartData = [
291
+ { month: 'January', desktop: 186, mobile: 80 },
292
+ { month: 'February', desktop: 305, mobile: 200 },
293
+ { month: 'March', desktop: 237, mobile: 120 },
294
+ { month: 'April', desktop: 73, mobile: 190 },
295
+ { month: 'May', desktop: 209, mobile: 130 },
296
+ { month: 'June', desktop: 214, mobile: 140 }
297
+ ]
298
+ ```
299
+
300
+ <Step>Define your chart config</Step>
301
+
302
+ The chart config holds configuration for the chart. This is where you place human-readable strings, such as labels, icons and color tokens for theming.
303
+
304
+ ```tsx title="components/example-chart.tsx" showLineNumbers
305
+ import { type ChartConfig } from '@/components/ui/chart'
306
+
307
+ const chartConfig = {
308
+ desktop: {
309
+ label: 'Desktop',
310
+ color: '#2563eb'
311
+ },
312
+ mobile: {
313
+ label: 'Mobile',
314
+ color: '#60a5fa'
315
+ }
316
+ } satisfies ChartConfig
317
+ ```
318
+
319
+ <Step>Build your chart</Step>
320
+
321
+ You can now build your chart using Recharts components.
322
+
323
+ <Callout className="mt-4 bg-amber-50 border-amber-200 dark:bg-amber-950/50 dark:border-amber-950">
324
+
325
+ **Important:** Remember to set a `min-h-[VALUE]` on the `ChartContainer` component. This is required for the chart to be responsive.
326
+
327
+ </Callout>
328
+
329
+ ```tsx
330
+ 'use client'
331
+
332
+ import { Bar, BarChart } from 'recharts'
333
+
334
+ import { ChartContainer, type ChartConfig } from '@/components/ui/chart'
335
+
336
+ const chartData = [
337
+ { month: 'January', desktop: 186, mobile: 80 },
338
+ { month: 'February', desktop: 305, mobile: 200 },
339
+ { month: 'March', desktop: 237, mobile: 120 },
340
+ { month: 'April', desktop: 73, mobile: 190 },
341
+ { month: 'May', desktop: 209, mobile: 130 },
342
+ { month: 'June', desktop: 214, mobile: 140 }
343
+ ]
344
+
345
+ const chartConfig = {
346
+ desktop: {
347
+ label: 'Desktop',
348
+ color: '#2563eb'
349
+ },
350
+ mobile: {
351
+ label: 'Mobile',
352
+ color: '#60a5fa'
353
+ }
354
+ } satisfies ChartConfig
355
+
356
+ export function ChartExample() {
357
+ return (
358
+ <ChartContainer config={chartConfig} className="min-h-[200px] w-full">
359
+ <BarChart accessibilityLayer data={chartData}>
360
+ <Bar dataKey="desktop" fill="var(--color-desktop)" radius={4} />
361
+ <Bar dataKey="mobile" fill="var(--color-mobile)" radius={4} />
362
+ </BarChart>
363
+ </ChartContainer>
364
+ )
365
+ }
366
+ ```
367
+
368
+ </Steps>
369
+
370
+ ### Add a Grid
371
+
372
+ Let's add a grid to the chart.
373
+
374
+ <Steps className="mb-0 pt-2">
375
+
376
+ <Step>Import the `CartesianGrid` component.</Step>
377
+
378
+ ```tsx /CartesianGrid/
379
+ import { Bar, BarChart, CartesianGrid } from 'recharts'
380
+ ```
381
+
382
+ <Step>Add the `CartesianGrid` component to your chart.</Step>
383
+
384
+ ```tsx showLineNumbers {3}
385
+ <ChartContainer config={chartConfig} className="min-h-[200px] w-full">
386
+ <BarChart accessibilityLayer data={chartData}>
387
+ <CartesianGrid vertical={false} />
388
+ <Bar dataKey="desktop" fill="var(--color-desktop)" radius={4} />
389
+ <Bar dataKey="mobile" fill="var(--color-mobile)" radius={4} />
390
+ </BarChart>
391
+ </ChartContainer>
392
+ ```
393
+
394
+ ```tsx
395
+ 'use client'
396
+
397
+ import { Bar, BarChart, CartesianGrid } from 'recharts'
398
+
399
+ import { ChartContainer, type ChartConfig } from '@/components/ui/chart'
400
+
401
+ const chartData = [
402
+ { month: 'January', desktop: 186, mobile: 80 },
403
+ { month: 'February', desktop: 305, mobile: 200 },
404
+ { month: 'March', desktop: 237, mobile: 120 },
405
+ { month: 'April', desktop: 73, mobile: 190 },
406
+ { month: 'May', desktop: 209, mobile: 130 },
407
+ { month: 'June', desktop: 214, mobile: 140 }
408
+ ]
409
+
410
+ const chartConfig = {
411
+ desktop: {
412
+ label: 'Desktop',
413
+ color: '#2563eb'
414
+ },
415
+ mobile: {
416
+ label: 'Mobile',
417
+ color: '#60a5fa'
418
+ }
419
+ } satisfies ChartConfig
420
+
421
+ export function ChartBarDemoGrid() {
422
+ return (
423
+ <ChartContainer config={chartConfig} className="min-h-[200px] w-full">
424
+ <BarChart accessibilityLayer data={chartData}>
425
+ <CartesianGrid vertical={false} />
426
+ <Bar dataKey="desktop" fill="var(--color-desktop)" radius={4} />
427
+ <Bar dataKey="mobile" fill="var(--color-mobile)" radius={4} />
428
+ </BarChart>
429
+ </ChartContainer>
430
+ )
431
+ }
432
+ ```
433
+
434
+ </Steps>
435
+
436
+ ### Add an Axis
437
+
438
+ To add an x-axis to the chart, we'll use the `XAxis` component.
439
+
440
+ <Steps className="mb-0 pt-2">
441
+
442
+ <Step>Import the `XAxis` component.</Step>
443
+
444
+ ```tsx /XAxis/
445
+ import { Bar, BarChart, CartesianGrid, XAxis } from 'recharts'
446
+ ```
447
+
448
+ <Step>Add the `XAxis` component to your chart.</Step>
449
+
450
+ ```tsx showLineNumbers {4-10}
451
+ <ChartContainer config={chartConfig} className="h-[200px] w-full">
452
+ <BarChart accessibilityLayer data={chartData}>
453
+ <CartesianGrid vertical={false} />
454
+ <XAxis
455
+ dataKey="month"
456
+ tickLine={false}
457
+ tickMargin={10}
458
+ axisLine={false}
459
+ tickFormatter={value => value.slice(0, 3)}
460
+ />
461
+ <Bar dataKey="desktop" fill="var(--color-desktop)" radius={4} />
462
+ <Bar dataKey="mobile" fill="var(--color-mobile)" radius={4} />
463
+ </BarChart>
464
+ </ChartContainer>
465
+ ```
466
+
467
+ ```tsx
468
+ 'use client'
469
+
470
+ import { Bar, BarChart, CartesianGrid, XAxis } from 'recharts'
471
+
472
+ import { ChartContainer, type ChartConfig } from '@/components/ui/chart'
473
+
474
+ const chartData = [
475
+ { month: 'January', desktop: 186, mobile: 80 },
476
+ { month: 'February', desktop: 305, mobile: 200 },
477
+ { month: 'March', desktop: 237, mobile: 120 },
478
+ { month: 'April', desktop: 73, mobile: 190 },
479
+ { month: 'May', desktop: 209, mobile: 130 },
480
+ { month: 'June', desktop: 214, mobile: 140 }
481
+ ]
482
+
483
+ const chartConfig = {
484
+ desktop: {
485
+ label: 'Desktop',
486
+ color: '#2563eb'
487
+ },
488
+ mobile: {
489
+ label: 'Mobile',
490
+ color: '#60a5fa'
491
+ }
492
+ } satisfies ChartConfig
493
+
494
+ export function ChartBarDemoAxis() {
495
+ return (
496
+ <ChartContainer config={chartConfig} className="min-h-[200px] w-full">
497
+ <BarChart accessibilityLayer data={chartData}>
498
+ <CartesianGrid vertical={false} />
499
+ <XAxis
500
+ dataKey="month"
501
+ tickLine={false}
502
+ tickMargin={10}
503
+ axisLine={false}
504
+ tickFormatter={value => value.slice(0, 3)}
505
+ />
506
+ <Bar dataKey="desktop" fill="var(--color-desktop)" radius={4} />
507
+ <Bar dataKey="mobile" fill="var(--color-mobile)" radius={4} />
508
+ </BarChart>
509
+ </ChartContainer>
510
+ )
511
+ }
512
+ ```
513
+
514
+ </Steps>
515
+
516
+ ### Add Tooltip
517
+
518
+ So far we've only used components from Recharts. They look great out of the box thanks to some customization in the `chart` component.
519
+
520
+ To add a tooltip, we'll use the custom `ChartTooltip` and `ChartTooltipContent` components from `chart`.
521
+
522
+ <Steps className="mb-0 pt-2">
523
+
524
+ <Step>Import the `ChartTooltip` and `ChartTooltipContent` components.</Step>
525
+
526
+ ```tsx
527
+ import { ChartTooltip, ChartTooltipContent } from '@/components/ui/chart'
528
+ ```
529
+
530
+ <Step>Add the components to your chart.</Step>
531
+
532
+ ```tsx showLineNumbers {11}
533
+ <ChartContainer config={chartConfig} className="h-[200px] w-full">
534
+ <BarChart accessibilityLayer data={chartData}>
535
+ <CartesianGrid vertical={false} />
536
+ <XAxis
537
+ dataKey="month"
538
+ tickLine={false}
539
+ tickMargin={10}
540
+ axisLine={false}
541
+ tickFormatter={value => value.slice(0, 3)}
542
+ />
543
+ <ChartTooltip content={<ChartTooltipContent />} />
544
+ <Bar dataKey="desktop" fill="var(--color-desktop)" radius={4} />
545
+ <Bar dataKey="mobile" fill="var(--color-mobile)" radius={4} />
546
+ </BarChart>
547
+ </ChartContainer>
548
+ ```
549
+
550
+ ```tsx
551
+ 'use client'
552
+
553
+ import { Bar, BarChart, CartesianGrid, XAxis } from 'recharts'
554
+
555
+ import {
556
+ ChartContainer,
557
+ ChartTooltip,
558
+ ChartTooltipContent,
559
+ type ChartConfig
560
+ } from '@/components/ui/chart'
561
+
562
+ const chartData = [
563
+ { month: 'January', desktop: 186, mobile: 80 },
564
+ { month: 'February', desktop: 305, mobile: 200 },
565
+ { month: 'March', desktop: 237, mobile: 120 },
566
+ { month: 'April', desktop: 73, mobile: 190 },
567
+ { month: 'May', desktop: 209, mobile: 130 },
568
+ { month: 'June', desktop: 214, mobile: 140 }
569
+ ]
570
+
571
+ const chartConfig = {
572
+ desktop: {
573
+ label: 'Desktop',
574
+ color: '#2563eb'
575
+ },
576
+ mobile: {
577
+ label: 'Mobile',
578
+ color: '#60a5fa'
579
+ }
580
+ } satisfies ChartConfig
581
+
582
+ export function ChartBarDemoTooltip() {
583
+ return (
584
+ <ChartContainer config={chartConfig} className="min-h-[200px] w-full">
585
+ <BarChart accessibilityLayer data={chartData}>
586
+ <CartesianGrid vertical={false} />
587
+ <XAxis
588
+ dataKey="month"
589
+ tickLine={false}
590
+ tickMargin={10}
591
+ axisLine={false}
592
+ tickFormatter={value => value.slice(0, 3)}
593
+ />
594
+ <ChartTooltip content={<ChartTooltipContent />} />
595
+ <Bar dataKey="desktop" fill="var(--color-desktop)" radius={4} />
596
+ <Bar dataKey="mobile" fill="var(--color-mobile)" radius={4} />
597
+ </BarChart>
598
+ </ChartContainer>
599
+ )
600
+ }
601
+ ```
602
+
603
+ Hover to see the tooltips. Easy, right? Two components, and we've got a beautiful tooltip.
604
+
605
+ </Steps>
606
+
607
+ ### Add Legend
608
+
609
+ We'll do the same for the legend. We'll use the `ChartLegend` and `ChartLegendContent` components from `chart`.
610
+
611
+ <Steps className="mb-0 pt-2">
612
+
613
+ <Step>Import the `ChartLegend` and `ChartLegendContent` components.</Step>
614
+
615
+ ```tsx
616
+ import { ChartLegend, ChartLegendContent } from '@/components/ui/chart'
617
+ ```
618
+
619
+ <Step>Add the components to your chart.</Step>
620
+
621
+ ```tsx showLineNumbers {12}
622
+ <ChartContainer config={chartConfig} className="h-[200px] w-full">
623
+ <BarChart accessibilityLayer data={chartData}>
624
+ <CartesianGrid vertical={false} />
625
+ <XAxis
626
+ dataKey="month"
627
+ tickLine={false}
628
+ tickMargin={10}
629
+ axisLine={false}
630
+ tickFormatter={value => value.slice(0, 3)}
631
+ />
632
+ <ChartTooltip content={<ChartTooltipContent />} />
633
+ <ChartLegend content={<ChartLegendContent />} />
634
+ <Bar dataKey="desktop" fill="var(--color-desktop)" radius={4} />
635
+ <Bar dataKey="mobile" fill="var(--color-mobile)" radius={4} />
636
+ </BarChart>
637
+ </ChartContainer>
638
+ ```
639
+
640
+ ```tsx
641
+ 'use client'
642
+
643
+ import { Bar, BarChart, CartesianGrid, XAxis } from 'recharts'
644
+
645
+ import {
646
+ ChartContainer,
647
+ ChartLegend,
648
+ ChartLegendContent,
649
+ ChartTooltip,
650
+ ChartTooltipContent,
651
+ type ChartConfig
652
+ } from '@/components/ui/chart'
653
+
654
+ const chartData = [
655
+ { month: 'January', desktop: 186, mobile: 80 },
656
+ { month: 'February', desktop: 305, mobile: 200 },
657
+ { month: 'March', desktop: 237, mobile: 120 },
658
+ { month: 'April', desktop: 73, mobile: 190 },
659
+ { month: 'May', desktop: 209, mobile: 130 },
660
+ { month: 'June', desktop: 214, mobile: 140 }
661
+ ]
662
+
663
+ const chartConfig = {
664
+ desktop: {
665
+ label: 'Desktop',
666
+ color: '#2563eb'
667
+ },
668
+ mobile: {
669
+ label: 'Mobile',
670
+ color: '#60a5fa'
671
+ }
672
+ } satisfies ChartConfig
673
+
674
+ export function ChartBarDemoLegend() {
675
+ return (
676
+ <ChartContainer config={chartConfig} className="min-h-[200px] w-full">
677
+ <BarChart accessibilityLayer data={chartData}>
678
+ <CartesianGrid vertical={false} />
679
+ <XAxis
680
+ dataKey="month"
681
+ tickLine={false}
682
+ tickMargin={10}
683
+ axisLine={false}
684
+ tickFormatter={value => value.slice(0, 3)}
685
+ />
686
+ <ChartTooltip content={<ChartTooltipContent />} />
687
+ <ChartLegend content={<ChartLegendContent />} />
688
+ <Bar dataKey="desktop" fill="var(--color-desktop)" radius={4} />
689
+ <Bar dataKey="mobile" fill="var(--color-mobile)" radius={4} />
690
+ </BarChart>
691
+ </ChartContainer>
692
+ )
693
+ }
694
+ ```
695
+
696
+ </Steps>
697
+
698
+ Done. You've built your first chart! What's next?
699
+
700
+ - [Themes and Colors](/docs/components/chart#theming)
701
+ - [Tooltip](/docs/components/chart#tooltip)
702
+ - [Legend](/docs/components/chart#legend)
703
+
704
+ ## Chart Config
705
+
706
+ The chart config is where you define the labels, icons and colors for a chart.
707
+
708
+ It is intentionally decoupled from chart data.
709
+
710
+ This allows you to share config and color tokens between charts. It can also work independently for cases where your data or color tokens live remotely or in a different format.
711
+
712
+ ```tsx showLineNumbers /ChartConfig/
713
+ import { IconDeviceDesktop } from '@tabler/icons-react'
714
+
715
+ import { type ChartConfig } from '@/components/ui/chart'
716
+
717
+ const chartConfig = {
718
+ desktop: {
719
+ label: 'Desktop',
720
+ icon: IconDeviceDesktop,
721
+ // A color like 'hsl(220, 98%, 61%)' or 'var(--color-name)'
722
+ color: '#2563eb',
723
+ // OR a theme object with 'light' and 'dark' keys
724
+ theme: {
725
+ light: '#2563eb',
726
+ dark: '#dc2626'
727
+ }
728
+ }
729
+ } satisfies ChartConfig
730
+ ```
731
+
732
+ ## Theming
733
+
734
+ Charts have built-in support for theming. You can use css variables (recommended) or color values in any color format, such as hex, hsl or oklch.
735
+
736
+ ### CSS Variables
737
+
738
+ <Steps className="mb-0 pt-2">
739
+
740
+ <Step>Define your colors in your css file</Step>
741
+
742
+ ```css title="app/globals.css" showLineNumbers
743
+ @layer base {
744
+ :root {
745
+ --chart-1: oklch(0.646 0.222 41.116);
746
+ --chart-2: oklch(0.6 0.118 184.704);
747
+ }
748
+
749
+ .dark {
750
+ --chart-1: oklch(0.488 0.243 264.376);
751
+ --chart-2: oklch(0.696 0.17 162.48);
752
+ }
753
+ }
754
+ ```
755
+
756
+ <Step>Add the color to your `chartConfig`</Step>
757
+
758
+ ```tsx title="components/example-chart.tsx" showLineNumbers
759
+ const chartConfig = {
760
+ desktop: {
761
+ label: 'Desktop',
762
+ color: 'var(--chart-1)'
763
+ },
764
+ mobile: {
765
+ label: 'Mobile',
766
+ color: 'var(--chart-2)'
767
+ }
768
+ } satisfies ChartConfig
769
+ ```
770
+
771
+ </Steps>
772
+
773
+ ### hex, hsl or oklch
774
+
775
+ You can also define your colors directly in the chart config. Use the color format you prefer.
776
+
777
+ ```tsx title="components/example-chart.tsx" showLineNumbers
778
+ const chartConfig = {
779
+ desktop: {
780
+ label: 'Desktop',
781
+ color: '#2563eb'
782
+ },
783
+ mobile: {
784
+ label: 'Mobile',
785
+ color: 'hsl(220, 98%, 61%)'
786
+ },
787
+ tablet: {
788
+ label: 'Tablet',
789
+ color: 'oklch(0.5 0.2 240)'
790
+ },
791
+ laptop: {
792
+ label: 'Laptop',
793
+ color: 'var(--chart-2)'
794
+ }
795
+ } satisfies ChartConfig
796
+ ```
797
+
798
+ ### Using Colors
799
+
800
+ To use the theme colors in your chart, reference the colors using the format `var(--color-KEY)`.
801
+
802
+ #### Components
803
+
804
+ ```tsx
805
+ <Bar dataKey="desktop" fill="var(--color-desktop)" />
806
+ ```
807
+
808
+ #### Chart Data
809
+
810
+ ```tsx title="components/example-chart.tsx" showLineNumbers
811
+ const chartData = [
812
+ { browser: 'chrome', visitors: 275, fill: 'var(--color-chrome)' },
813
+ { browser: 'safari', visitors: 200, fill: 'var(--color-safari)' }
814
+ ]
815
+ ```
816
+
817
+ #### Tailwind
818
+
819
+ ```tsx title="components/example-chart.tsx"
820
+ <LabelList className="fill-(--color-desktop)" />
821
+ ```
822
+
823
+ ## Tooltip
824
+
825
+ A chart tooltip contains a label, name, indicator and value. You can use a combination of these to customize your tooltip.
826
+
827
+ ```tsx
828
+ 'use client'
829
+
830
+ import * as React from 'react'
831
+ import { cn } from 'cn'
832
+
833
+ export function ChartTooltipDemo() {
834
+ return (
835
+ <div className="grid aspect-video w-full max-w-md justify-center text-foreground md:grid-cols-2 [&>div]:relative [&>div]:flex [&>div]:h-[137px] [&>div]:w-[224px] [&>div]:items-center [&>div]:justify-center [&>div]:p-4">
836
+ <div>
837
+ <div className="absolute top-[45px] left-[-35px] z-10 text-sm font-medium">Label</div>
838
+ <svg
839
+ xmlns="http://www.w3.org/2000/svg"
840
+ viewBox="0 0 193 40"
841
+ width="50"
842
+ height="12"
843
+ fill="none"
844
+ className="absolute top-[50px] left-[5px] z-10"
845
+ >
846
+ <g clipPath="url(#a)">
847
+ <path
848
+ fill="currentColor"
849
+ d="M173.928 21.13C115.811 44.938 58.751 45.773 0 26.141c4.227-4.386 7.82-2.715 10.567-1.88 21.133 5.64 42.9 6.266 64.457 7.101 31.066 1.253 60.441-5.848 89.183-17.335 1.268-.418 2.325-1.253 4.861-2.924-14.582-2.924-29.165 2.089-41.845-3.76.212-.835.212-1.879.423-2.714 9.51-.627 19.231-1.253 28.742-2.089 9.51-.835 18.808-1.88 28.318-2.506 6.974-.418 9.933 2.924 7.397 9.19-3.17 8.145-7.608 15.664-11.623 23.391-.423.836-1.057 1.88-1.902 2.298-2.325.835-4.65 1.044-7.186 1.67-.422-2.088-1.479-4.386-1.268-6.265.423-2.506 1.902-4.595 3.804-9.19Z"
850
+ />
851
+ </g>
852
+ <defs>
853
+ <clipPath id="a">
854
+ <path fill="currentColor" d="M0 0h193v40H0z" />
855
+ </clipPath>
856
+ </defs>
857
+ </svg>
858
+ <TooltipDemo
859
+ label="Page Views"
860
+ payload={[
861
+ { name: 'Desktop', value: 186, fill: 'var(--chart-1)' },
862
+ { name: 'Mobile', value: 80, fill: 'var(--chart-2)' }
863
+ ]}
864
+ className="w-[8rem]"
865
+ />
866
+ </div>
867
+ <div className="items-end">
868
+ <div className="absolute top-[0px] left-[122px] z-10 text-sm font-medium">Name</div>
869
+ <svg
870
+ xmlns="http://www.w3.org/2000/svg"
871
+ width="35"
872
+ height="42"
873
+ fill="none"
874
+ viewBox="0 0 122 148"
875
+ className="absolute top-[10px] left-[85px] z-10 -scale-x-100"
876
+ >
877
+ <g clipPath="url(#ab)">
878
+ <path
879
+ fill="currentColor"
880
+ d="M0 2.65c6.15-4.024 12.299-2.753 17.812-.847a115.56 115.56 0 0 1 21.84 10.59C70.4 32.727 88.849 61.744 96.483 97.54c1.908 9.108 2.544 18.639 3.817 29.017 8.481-4.871 12.934-14.402 21.416-19.909 1.061 4.236-1.06 6.989-2.756 9.319-6.998 9.531-14.207 19.062-21.63 28.382-3.604 4.448-6.36 4.871-10.177 1.059-8.058-7.837-12.935-17.368-14.42-28.382 0-.424.636-1.059 1.485-2.118 9.118 2.33 6.997 13.979 14.843 18.215 3.393-14.614.848-28.593-2.969-42.149-4.029-14.19-9.33-27.746-17.812-39.82-8.27-11.86-18.66-21.392-30.11-30.287C26.93 11.758 14.207 6.039 0 2.65Z"
881
+ />
882
+ </g>
883
+ <defs>
884
+ <clipPath id="ab">
885
+ <path fill="currentColor" d="M0 0h122v148H0z" />
886
+ </clipPath>
887
+ </defs>
888
+ </svg>
889
+ <TooltipDemo
890
+ label="Browser"
891
+ hideLabel
892
+ payload={[
893
+ { name: 'Chrome', value: 1286, fill: 'var(--chart-3)' },
894
+ { name: 'Firefox', value: 1000, fill: 'var(--chart-4)' }
895
+ ]}
896
+ indicator="dashed"
897
+ className="w-[8rem]"
898
+ />
899
+ </div>
900
+ <div className="hidden! md:flex!">
901
+ <TooltipDemo
902
+ label="Page Views"
903
+ payload={[{ name: 'Desktop', value: 12486, fill: 'var(--chart-3)' }]}
904
+ className="w-[9rem]"
905
+ indicator="line"
906
+ />
907
+ </div>
908
+ <div className="items-start! justify-start!">
909
+ <div className="absolute top-[60px] left-[50px] z-10 text-sm font-medium">Indicator</div>
910
+ <TooltipDemo
911
+ label="Browser"
912
+ hideLabel
913
+ payload={[{ name: 'Chrome', value: 1286, fill: 'var(--chart-1)' }]}
914
+ indicator="dot"
915
+ className="w-[8rem]"
916
+ />
917
+ <svg
918
+ xmlns="http://www.w3.org/2000/svg"
919
+ width="15"
920
+ height="34"
921
+ fill="none"
922
+ viewBox="0 0 75 175"
923
+ className="absolute top-[38px] left-[30px] z-10 rotate-[-40deg]"
924
+ >
925
+ <g clipPath="url(#abc)">
926
+ <path
927
+ fill="currentColor"
928
+ d="M20.187 175c-4.439-2.109-7.186-2.531-8.032-4.008-3.17-5.484-6.763-10.968-8.454-17.084-5.073-16.242-4.439-32.694-1.057-49.146 5.707-28.053 18.388-52.942 34.24-76.565 1.692-2.531 3.171-5.063 4.862-7.805 0-.21-.211-.632-.634-1.265-4.65 1.265-9.511 2.53-14.161 3.585-2.537.422-5.496.422-8.032-.421-1.48-.422-3.593-2.742-3.593-4.219 0-1.898 1.48-4.218 2.747-5.906 1.057-1.054 2.96-1.265 4.65-1.687C35.406 7.315 48.088 3.729 60.98.776c10.99-2.53 14.584 1.055 13.95 11.812-.634 11.18-.846 22.358-1.268 33.326-.212 3.375-.846 6.96-1.268 10.757-8.878-4.007-8.878-4.007-12.048-38.177C47.03 33.259 38.153 49.289 29.91 65.741 21.667 82.193 16.17 99.49 13.212 117.84c-2.959 18.984.634 36.912 6.975 57.161Z"
929
+ />
930
+ </g>
931
+ <defs>
932
+ <clipPath id="abc">
933
+ <path fill="currentColor" d="M0 0h75v175H0z" />
934
+ </clipPath>
935
+ </defs>
936
+ </svg>
937
+ </div>
938
+ </div>
939
+ )
940
+ }
941
+
942
+ function TooltipDemo({
943
+ indicator = 'dot',
944
+ label,
945
+ payload,
946
+ hideLabel,
947
+ hideIndicator,
948
+ className
949
+ }: {
950
+ label: string
951
+ hideLabel?: boolean
952
+ hideIndicator?: boolean
953
+ indicator?: 'line' | 'dot' | 'dashed'
954
+ payload: {
955
+ name: string
956
+ value: number
957
+ fill: string
958
+ }[]
959
+ nameKey?: string
960
+ labelKey?: string
961
+ } & React.ComponentProps<'div'>) {
962
+ const tooltipLabel = hideLabel ? null : <div className="font-medium">{label}</div>
963
+
964
+ if (!payload?.length) {
965
+ return null
966
+ }
967
+
968
+ const nestLabel = payload.length === 1 && indicator !== 'dot'
969
+
970
+ return (
971
+ <div
972
+ className={cn(
973
+ 'grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl transition-all ease-in-out hover:-translate-y-0.5',
974
+ className
975
+ )}
976
+ >
977
+ {!nestLabel ? tooltipLabel : null}
978
+ <div className="grid gap-1.5">
979
+ {payload.map((item, index) => {
980
+ const indicatorColor = item.fill
981
+
982
+ return (
983
+ <div
984
+ key={index}
985
+ className={cn(
986
+ 'flex w-full items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground',
987
+ indicator === 'dot' && 'items-center'
988
+ )}
989
+ >
990
+ <>
991
+ {!hideIndicator && (
992
+ <div
993
+ className={cn(
994
+ 'shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)',
995
+ {
996
+ 'h-2.5 w-2.5': indicator === 'dot',
997
+ 'w-1': indicator === 'line',
998
+ 'w-0 border-[1.5px] border-dashed bg-transparent': indicator === 'dashed',
999
+ 'my-0.5': nestLabel && indicator === 'dashed'
1000
+ }
1001
+ )}
1002
+ style={
1003
+ {
1004
+ '--color-bg': indicatorColor,
1005
+ '--color-border': indicatorColor
1006
+ } as React.CSSProperties
1007
+ }
1008
+ />
1009
+ )}
1010
+ <div
1011
+ className={cn(
1012
+ 'flex flex-1 justify-between leading-none',
1013
+ nestLabel ? 'items-end' : 'items-center'
1014
+ )}
1015
+ >
1016
+ <div className="grid gap-1.5">
1017
+ {nestLabel ? tooltipLabel : null}
1018
+ <span className="text-muted-foreground">{item.name}</span>
1019
+ </div>
1020
+ <span className="font-mono font-medium text-foreground tabular-nums">
1021
+ {item.value.toLocaleString()}
1022
+ </span>
1023
+ </div>
1024
+ </>
1025
+ </div>
1026
+ )
1027
+ })}
1028
+ </div>
1029
+ </div>
1030
+ )
1031
+ }
1032
+ ```
1033
+
1034
+ You can turn on/off any of these using the `hideLabel`, `hideIndicator` props and customize the indicator style using the `indicator` prop.
1035
+
1036
+ Use `labelKey` and `nameKey` to use a custom key for the tooltip label and name.
1037
+
1038
+ Chart comes with the `<ChartTooltip>` and `<ChartTooltipContent>` components. You can use these two components to add custom tooltips to your chart.
1039
+
1040
+ ```tsx title="components/example-chart.tsx"
1041
+ import { ChartTooltip, ChartTooltipContent } from '@/components/ui/chart'
1042
+ ```
1043
+
1044
+ ```tsx title="components/example-chart.tsx"
1045
+ <ChartTooltip content={<ChartTooltipContent />} />
1046
+ ```
1047
+
1048
+ ### Props
1049
+
1050
+ Use the following props to customize the tooltip.
1051
+
1052
+ | Prop | Type | Description |
1053
+ | :-------------- | :----------------------- | :------------------------------------------- |
1054
+ | `labelKey` | string | The config or data key to use for the label. |
1055
+ | `nameKey` | string | The config or data key to use for the name. |
1056
+ | `indicator` | `dot` `line` or `dashed` | The indicator style for the tooltip. |
1057
+ | `hideLabel` | boolean | Whether to hide the label. |
1058
+ | `hideIndicator` | boolean | Whether to hide the indicator. |
1059
+
1060
+ ### Colors
1061
+
1062
+ Colors are automatically referenced from the chart config.
1063
+
1064
+ ### Custom
1065
+
1066
+ To use a custom key for tooltip label and names, use the `labelKey` and `nameKey` props.
1067
+
1068
+ ```tsx showLineNumbers /browser/
1069
+ const chartData = [
1070
+ { browser: 'chrome', visitors: 187, fill: 'var(--color-chrome)' },
1071
+ { browser: 'safari', visitors: 200, fill: 'var(--color-safari)' }
1072
+ ]
1073
+
1074
+ const chartConfig = {
1075
+ visitors: {
1076
+ label: 'Total Visitors'
1077
+ },
1078
+ chrome: {
1079
+ label: 'Chrome',
1080
+ color: 'var(--chart-1)'
1081
+ },
1082
+ safari: {
1083
+ label: 'Safari',
1084
+ color: 'var(--chart-2)'
1085
+ }
1086
+ } satisfies ChartConfig
1087
+ ```
1088
+
1089
+ ```tsx title="components/example-chart.tsx"
1090
+ <ChartTooltip content={<ChartTooltipContent labelKey="visitors" nameKey="browser" />} />
1091
+ ```
1092
+
1093
+ This will use `Total Visitors` for label and `Chrome` and `Safari` for the tooltip names.
1094
+
1095
+ ## Legend
1096
+
1097
+ You can use the custom `<ChartLegend>` and `<ChartLegendContent>` components to add a legend to your chart.
1098
+
1099
+ ```tsx title="components/example-chart.tsx"
1100
+ import { ChartLegend, ChartLegendContent } from '@/components/ui/chart'
1101
+ ```
1102
+
1103
+ ```tsx title="components/example-chart.tsx"
1104
+ <ChartLegend content={<ChartLegendContent />} />
1105
+ ```
1106
+
1107
+ ### Colors
1108
+
1109
+ Colors are automatically referenced from the chart config.
1110
+
1111
+ ### Custom
1112
+
1113
+ To use a custom key for legend names, use the `nameKey` prop.
1114
+
1115
+ ```tsx showLineNumbers /browser/
1116
+ const chartData = [
1117
+ { browser: 'chrome', visitors: 187, fill: 'var(--color-chrome)' },
1118
+ { browser: 'safari', visitors: 200, fill: 'var(--color-safari)' }
1119
+ ]
1120
+
1121
+ const chartConfig = {
1122
+ chrome: {
1123
+ label: 'Chrome',
1124
+ color: 'var(--chart-1)'
1125
+ },
1126
+ safari: {
1127
+ label: 'Safari',
1128
+ color: 'var(--chart-2)'
1129
+ }
1130
+ } satisfies ChartConfig
1131
+ ```
1132
+
1133
+ ```tsx title="components/example-chart.tsx"
1134
+ <ChartLegend content={<ChartLegendContent nameKey="browser" />} />
1135
+ ```
1136
+
1137
+ This will use `Chrome` and `Safari` for the legend names.
1138
+
1139
+ ## Accessibility
1140
+
1141
+ You can turn on the `accessibilityLayer` prop to add an accessible layer to your chart.
1142
+
1143
+ This prop adds keyboard access and screen reader support to your charts.
1144
+
1145
+ ```tsx title="components/example-chart.tsx"
1146
+ <LineChart accessibilityLayer />
1147
+ ```
1148
+
1149
+ ## RTL
1150
+
1151
+ ```tsx
1152
+ 'use client'
1153
+
1154
+ import { Bar, BarChart, CartesianGrid, XAxis } from 'recharts'
1155
+
1156
+ import { useTranslation, type Translations } from '@/components/language-selector'
1157
+ import {
1158
+ ChartContainer,
1159
+ ChartLegend,
1160
+ ChartLegendContent,
1161
+ ChartTooltip,
1162
+ ChartTooltipContent,
1163
+ type ChartConfig
1164
+ } from '@/components/ui/chart'
1165
+
1166
+ const translations: Translations = {
1167
+ en: {
1168
+ dir: 'ltr',
1169
+ values: {
1170
+ january: 'January',
1171
+ february: 'February',
1172
+ march: 'March',
1173
+ april: 'April',
1174
+ may: 'May',
1175
+ june: 'June',
1176
+ desktop: 'Desktop',
1177
+ mobile: 'Mobile'
1178
+ }
1179
+ },
1180
+ ar: {
1181
+ dir: 'rtl',
1182
+ values: {
1183
+ january: 'يناير',
1184
+ february: 'فبراير',
1185
+ march: 'مارس',
1186
+ april: 'أبريل',
1187
+ may: 'مايو',
1188
+ june: 'يونيو',
1189
+ desktop: 'سطح المكتب',
1190
+ mobile: 'الجوال'
1191
+ }
1192
+ },
1193
+ he: {
1194
+ dir: 'rtl',
1195
+ values: {
1196
+ january: 'ינואר',
1197
+ february: 'פברואר',
1198
+ march: 'מרץ',
1199
+ april: 'אפריל',
1200
+ may: 'מאי',
1201
+ june: 'יוני',
1202
+ desktop: 'מחשב',
1203
+ mobile: 'נייד'
1204
+ }
1205
+ }
1206
+ }
1207
+
1208
+ const chartData = [
1209
+ { month: 'january', desktop: 186, mobile: 80 },
1210
+ { month: 'february', desktop: 305, mobile: 200 },
1211
+ { month: 'march', desktop: 237, mobile: 120 },
1212
+ { month: 'april', desktop: 73, mobile: 190 },
1213
+ { month: 'may', desktop: 209, mobile: 130 },
1214
+ { month: 'june', desktop: 214, mobile: 140 }
1215
+ ]
1216
+
1217
+ export function ChartRtl() {
1218
+ const { t, dir } = useTranslation(translations, 'ar')
1219
+
1220
+ const chartConfig = {
1221
+ desktop: {
1222
+ label: t.desktop,
1223
+ color: 'var(--chart-2)'
1224
+ },
1225
+ mobile: {
1226
+ label: t.mobile,
1227
+ color: 'var(--chart-1)'
1228
+ }
1229
+ } satisfies ChartConfig
1230
+
1231
+ return (
1232
+ <ChartContainer config={chartConfig} className="min-h-[200px] w-full">
1233
+ <BarChart accessibilityLayer data={chartData}>
1234
+ <CartesianGrid vertical={false} orientation={dir === 'rtl' ? 'right' : 'left'} />
1235
+ <XAxis
1236
+ dataKey="month"
1237
+ tickLine={false}
1238
+ tickMargin={10}
1239
+ axisLine={false}
1240
+ tickFormatter={value => (t[value as keyof typeof t] as string).slice(0, 3)}
1241
+ reversed={dir === 'rtl'}
1242
+ />
1243
+ <ChartTooltip
1244
+ content={
1245
+ <ChartTooltipContent labelFormatter={value => t[value as keyof typeof t] as string} />
1246
+ }
1247
+ labelClassName="w-32"
1248
+ />
1249
+ <ChartLegend content={<ChartLegendContent />} />
1250
+ <Bar dataKey="desktop" fill="var(--color-desktop)" radius={4} />
1251
+ <Bar dataKey="mobile" fill="var(--color-mobile)" radius={4} />
1252
+ </BarChart>
1253
+ </ChartContainer>
1254
+ )
1255
+ }
1256
+ ```