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.
- package/client/AGENTS.md +2 -2
- package/client/components/ui/button.tsx +1 -53
- package/client/components/ui/collapsible.tsx +1 -15
- package/client/components/ui/dialog.tsx +1 -58
- package/client/components/ui/dropdown-menu.tsx +1 -254
- package/client/components/ui/hover-card.tsx +1 -44
- package/client/components/ui/input.tsx +1 -21
- package/client/components/ui/popover.tsx +1 -88
- package/client/components/ui/resizable.tsx +1 -40
- package/client/components/ui/skeleton.tsx +1 -13
- package/client/components/ui/slider.tsx +1 -70
- package/client/components/ui/spinner.tsx +1 -18
- package/client/components/ui/switch.tsx +1 -23
- package/client/components/ui/tabs.tsx +1 -0
- package/client/components/ui/textarea.tsx +1 -18
- package/client/components/ui/tooltip.tsx +1 -51
- package/client/features/chat/ChatPanel.tsx +6 -6
- package/client/features/chat/ChatPopup.tsx +3 -4
- package/client/features/chat/TurnView.tsx +5 -4
- package/client/features/chat/api.ts +5 -14
- package/client/features/chat/chat-frames.ts +5 -2
- package/client/features/chat/composer/ChatComposer.tsx +5 -1
- package/client/features/chat/composer/ModelPicker.tsx +4 -3
- package/client/features/chat/composer/banners/ErrorBanner.tsx +20 -12
- package/client/features/chat/composer/useWorkspaceComposerState.tsx +15 -7
- package/client/features/chat/group-turns.ts +11 -0
- package/client/features/chat/session-view.ts +53 -0
- package/client/features/chat/useChat.ts +5 -1
- package/client/features/dev/ChatStatesPage.tsx +3 -1
- package/client/features/dev/DevIndexPage.tsx +5 -0
- package/client/features/dev/DevRoutes.tsx +2 -0
- package/client/features/dev/HarnessDebugPage.tsx +1 -1
- package/client/features/dev/UiComponentPreviews.tsx +834 -0
- package/client/features/dev/UiComponentsPage.tsx +60 -0
- package/client/features/home/WorkspacePreview.tsx +1 -1
- package/client/features/home/workspace-setup/DemoDialog.tsx +3 -2
- package/client/features/home/workspace-setup/ImportWorkspaceDialog.tsx +5 -8
- package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +7 -20
- package/client/features/settings/SettingsLayout.tsx +1 -1
- package/client/features/settings/WorkspaceSettings.tsx +4 -1
- package/client/features/views/ViewManager.tsx +14 -9
- package/client/features/widgets/WidgetFrame.tsx +1 -1
- package/client/features/widgets/Widgets.tsx +1 -3
- package/client/features/workspace/WorkspaceScreen.tsx +5 -1
- package/client/features/workspace/WorkspaceSplitLayout.tsx +6 -1
- package/client/features/workspace/api.ts +2 -4
- package/client/index.css +22 -29
- package/dist/{chunk-tny85yt2.js → chunk-4s15axjs.js} +2 -2
- package/dist/{chunk-c9pjqx9m.js → chunk-53a7pxcz.js} +1 -1
- package/dist/chunk-6664vxpk.css +1 -0
- package/dist/{chunk-104m57qw.js → chunk-87thzbtw.js} +2 -2
- package/dist/chunk-a6jad1a6.js +1 -0
- package/dist/chunk-dghwstd2.js +9 -0
- package/dist/chunk-eg120aca.js +1 -0
- package/dist/{chunk-v7wr1df4.js → chunk-j3wvxjr7.js} +1 -1
- package/dist/chunk-vwjeezeb.js +1 -0
- package/dist/chunk-w482ew2c.js +546 -0
- package/dist/chunk-yc471zah.js +70 -0
- package/dist/index.html +1 -1
- package/lib/format.ts +49 -1
- package/lib/themes.ts +6 -6
- package/lib/types.ts +5 -7
- package/package.json +17 -7
- package/registry.json +643 -0
- package/server/AGENTS.md +1 -0
- package/server/agent.ts +1 -1
- package/server/api.ts +25 -29
- package/server/applets.ts +30 -29
- package/server/bundler/applet-css.ts +6 -1
- package/server/bundler/build-applet.ts +5 -1
- package/server/bundler/build-worker.ts +178 -0
- package/server/cli-ui-components.ts +28 -33
- package/server/cli.ts +6 -11
- package/server/data-dir.ts +1 -1
- package/server/harness/README.md +13 -9
- package/server/harness/acp/NOTES.md +426 -0
- package/server/harness/acp/discovery.ts +27 -30
- package/server/harness/acp/model-state.ts +57 -0
- package/server/harness/acp/session.ts +18 -6
- package/server/harness/claude-code/NOTES.md +47 -12
- package/server/harness/claude-code/cli.ts +40 -0
- package/server/harness/claude-code/index.ts +11 -5
- package/server/harness/claude-code/models.ts +72 -19
- package/server/harness/claude-code/session.ts +408 -299
- package/server/harness/hermes/NOTES.md +18 -0
- package/server/harness/hermes/discovery.ts +20 -0
- package/server/harness/hermes/index.ts +9 -0
- package/server/harness/hermes/models.ts +28 -8
- package/server/harness/types.ts +4 -2
- package/server/moi-scaffold.ts +1 -1
- package/server/preview.ts +3 -1
- package/server/registry.ts +63 -41
- package/server/scratchpad-executor.ts +79 -56
- package/server/scratchpad-shape-defaults.ts +82 -0
- package/server/tldraw-package.d.ts +4 -0
- package/server/ui-components.ts +101 -434
- package/server/view-builders.ts +2 -1
- package/server/web.ts +9 -5
- package/server/workspace-env.ts +3 -2
- package/tsconfig.json +0 -1
- package/ui-components/accordion.tsx +71 -0
- package/ui-components/alert-dialog.tsx +165 -0
- package/ui-components/alert.tsx +68 -0
- package/ui-components/attachment.tsx +195 -0
- package/ui-components/avatar.tsx +90 -0
- package/ui-components/badge.tsx +49 -0
- package/ui-components/button-group.tsx +78 -0
- package/ui-components/button.tsx +55 -0
- package/ui-components/calendar.tsx +180 -0
- package/ui-components/card.tsx +84 -0
- package/ui-components/carousel.tsx +235 -0
- package/ui-components/chart.tsx +338 -0
- package/ui-components/checkbox.tsx +27 -0
- package/ui-components/collapsible.tsx +15 -0
- package/ui-components/combobox.tsx +265 -0
- package/ui-components/context-menu.tsx +244 -0
- package/ui-components/dialog.tsx +138 -0
- package/ui-components/docs/accordion.md +463 -0
- package/ui-components/docs/alert-dialog.md +481 -0
- package/ui-components/docs/alert.md +301 -0
- package/ui-components/docs/attachment.md +689 -0
- package/ui-components/docs/avatar.md +495 -0
- package/ui-components/docs/badge.md +258 -0
- package/ui-components/docs/button-group.md +879 -0
- package/ui-components/docs/button.md +26 -0
- package/ui-components/docs/calendar.md +862 -0
- package/ui-components/docs/card.md +265 -0
- package/ui-components/docs/carousel.md +627 -0
- package/ui-components/docs/chart.md +1256 -0
- package/ui-components/docs/checkbox.md +477 -0
- package/ui-components/docs/collapsible.md +446 -0
- package/ui-components/docs/combobox.md +1003 -0
- package/ui-components/docs/context-menu.md +860 -0
- package/ui-components/docs/data-table.md +1580 -0
- package/ui-components/docs/date-picker.md +614 -0
- package/ui-components/docs/dialog.md +414 -0
- package/ui-components/docs/drawer.md +51 -0
- package/ui-components/docs/dropdown-menu.md +1000 -0
- package/ui-components/docs/field.md +1192 -0
- package/ui-components/docs/hover-card.md +275 -0
- package/ui-components/docs/input-group.md +866 -0
- package/ui-components/docs/input.md +456 -0
- package/ui-components/docs/label.md +295 -0
- package/ui-components/docs/pagination.md +416 -0
- package/ui-components/docs/popover.md +348 -0
- package/ui-components/docs/progress.md +214 -0
- package/ui-components/docs/radio-group.md +389 -0
- package/ui-components/docs/resizable.md +265 -0
- package/ui-components/docs/select.md +616 -0
- package/ui-components/docs/separator.md +216 -0
- package/ui-components/docs/skeleton.md +205 -0
- package/ui-components/docs/slider.md +226 -0
- package/ui-components/docs/spinner.md +332 -0
- package/ui-components/docs/switch.md +236 -0
- package/ui-components/docs/table.md +551 -0
- package/ui-components/docs/tabs.md +379 -0
- package/ui-components/docs/textarea.md +187 -0
- package/ui-components/docs/toggle-group.md +370 -0
- package/ui-components/docs/toggle.md +91 -0
- package/ui-components/docs/tooltip.md +290 -0
- package/ui-components/drawer.tsx +213 -0
- package/ui-components/dropdown-menu.tsx +263 -0
- package/ui-components/field.tsx +224 -0
- package/ui-components/hover-card.tsx +46 -0
- package/ui-components/input-group.tsx +146 -0
- package/ui-components/input.tsx +20 -0
- package/ui-components/label.tsx +17 -0
- package/ui-components/pagination.tsx +124 -0
- package/ui-components/popover.tsx +81 -0
- package/ui-components/progress.tsx +63 -0
- package/ui-components/radio-group.tsx +37 -0
- package/ui-components/resizable.tsx +40 -0
- package/ui-components/scoped-portal.tsx +31 -0
- package/ui-components/select.tsx +195 -0
- package/ui-components/separator.tsx +18 -0
- package/ui-components/skeleton.tsx +15 -0
- package/ui-components/slider.tsx +75 -0
- package/ui-components/spinner.tsx +20 -0
- package/ui-components/switch.tsx +26 -0
- package/ui-components/table.tsx +86 -0
- package/ui-components/tabs.tsx +75 -0
- package/ui-components/textarea.tsx +17 -0
- package/ui-components/toggle-group.tsx +85 -0
- package/ui-components/toggle.tsx +42 -0
- package/ui-components/tooltip.tsx +61 -0
- package/ui-components/utils.ts +8 -0
- package/workspace/.claude/skills/moi-workspace/SKILL.md +11 -20
- package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +4 -3
- package/workspace/.claude/skills/moi-workspace/references/UI-COMPONENTS.md +67 -203
- package/dist/chunk-59zf0m6n.js +0 -1
- package/dist/chunk-bj3akjs2.js +0 -1
- package/dist/chunk-j2w2vak4.js +0 -546
- package/dist/chunk-k2r9c95m.js +0 -10
- package/dist/chunk-kmbxhgwv.js +0 -1
- package/dist/chunk-p1yqa71k.js +0 -83
- package/dist/chunk-r5xrenjy.css +0 -1
|
@@ -0,0 +1,627 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Carousel
|
|
3
|
+
description: A carousel with motion and swipe built using Embla.
|
|
4
|
+
base: base
|
|
5
|
+
component: true
|
|
6
|
+
links:
|
|
7
|
+
doc: https://www.embla-carousel.com/get-started/react
|
|
8
|
+
api: https://www.embla-carousel.com/api
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import * as React from 'react'
|
|
13
|
+
|
|
14
|
+
import { Card, CardContent } from '@/components/ui/card'
|
|
15
|
+
import {
|
|
16
|
+
Carousel,
|
|
17
|
+
CarouselContent,
|
|
18
|
+
CarouselItem,
|
|
19
|
+
CarouselNext,
|
|
20
|
+
CarouselPrevious
|
|
21
|
+
} from '@/components/ui/carousel'
|
|
22
|
+
|
|
23
|
+
export function CarouselDemo() {
|
|
24
|
+
return (
|
|
25
|
+
<Carousel className="w-full max-w-[12rem] sm:max-w-xs">
|
|
26
|
+
<CarouselContent>
|
|
27
|
+
{Array.from({ length: 5 }).map((_, index) => (
|
|
28
|
+
<CarouselItem key={index}>
|
|
29
|
+
<div className="p-1">
|
|
30
|
+
<Card>
|
|
31
|
+
<CardContent className="flex aspect-square items-center justify-center p-6">
|
|
32
|
+
<span className="text-4xl font-semibold">{index + 1}</span>
|
|
33
|
+
</CardContent>
|
|
34
|
+
</Card>
|
|
35
|
+
</div>
|
|
36
|
+
</CarouselItem>
|
|
37
|
+
))}
|
|
38
|
+
</CarouselContent>
|
|
39
|
+
<CarouselPrevious />
|
|
40
|
+
<CarouselNext />
|
|
41
|
+
</Carousel>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## About
|
|
47
|
+
|
|
48
|
+
The carousel component is built using the [Embla Carousel](https://www.embla-carousel.com/) library.
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
<CodeTabs>
|
|
53
|
+
|
|
54
|
+
<TabsList>
|
|
55
|
+
<TabsTrigger value="cli">Command</TabsTrigger>
|
|
56
|
+
<TabsTrigger value="manual">Manual</TabsTrigger>
|
|
57
|
+
</TabsList>
|
|
58
|
+
|
|
59
|
+
<TabsContent value="cli">
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
moi ui-components add carousel
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
</TabsContent>
|
|
66
|
+
|
|
67
|
+
<TabsContent value="manual">
|
|
68
|
+
|
|
69
|
+
<Steps className="mb-0 pt-2">
|
|
70
|
+
|
|
71
|
+
<Step>Install the following dependencies:</Step>
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
npm install embla-carousel-react
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
<Step>Copy and paste the following code into your project.</Step>
|
|
78
|
+
|
|
79
|
+
<ComponentSource
|
|
80
|
+
name="carousel"
|
|
81
|
+
title="components/ui/carousel.tsx"
|
|
82
|
+
styleName="base-nova"
|
|
83
|
+
/>
|
|
84
|
+
|
|
85
|
+
<Step>Update the import paths to match your project setup.</Step>
|
|
86
|
+
|
|
87
|
+
</Steps>
|
|
88
|
+
|
|
89
|
+
</TabsContent>
|
|
90
|
+
|
|
91
|
+
</CodeTabs>
|
|
92
|
+
|
|
93
|
+
## Usage
|
|
94
|
+
|
|
95
|
+
```tsx showLineNumbers
|
|
96
|
+
import {
|
|
97
|
+
Carousel,
|
|
98
|
+
CarouselContent,
|
|
99
|
+
CarouselItem,
|
|
100
|
+
CarouselNext,
|
|
101
|
+
CarouselPrevious
|
|
102
|
+
} from '@/components/ui/carousel'
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
```tsx showLineNumbers
|
|
106
|
+
<Carousel>
|
|
107
|
+
<CarouselContent>
|
|
108
|
+
<CarouselItem>...</CarouselItem>
|
|
109
|
+
<CarouselItem>...</CarouselItem>
|
|
110
|
+
<CarouselItem>...</CarouselItem>
|
|
111
|
+
</CarouselContent>
|
|
112
|
+
<CarouselPrevious />
|
|
113
|
+
<CarouselNext />
|
|
114
|
+
</Carousel>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Composition
|
|
118
|
+
|
|
119
|
+
Use the following composition to build a `Carousel`:
|
|
120
|
+
|
|
121
|
+
```text
|
|
122
|
+
Carousel
|
|
123
|
+
├── CarouselContent
|
|
124
|
+
│ ├── CarouselItem
|
|
125
|
+
│ └── CarouselItem
|
|
126
|
+
├── CarouselPrevious
|
|
127
|
+
└── CarouselNext
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Sizes
|
|
131
|
+
|
|
132
|
+
To set the size of the items, you can use the `basis` utility class on the `<CarouselItem />`.
|
|
133
|
+
|
|
134
|
+
```tsx
|
|
135
|
+
import * as React from 'react'
|
|
136
|
+
|
|
137
|
+
import { Card, CardContent } from '@/components/ui/card'
|
|
138
|
+
import {
|
|
139
|
+
Carousel,
|
|
140
|
+
CarouselContent,
|
|
141
|
+
CarouselItem,
|
|
142
|
+
CarouselNext,
|
|
143
|
+
CarouselPrevious
|
|
144
|
+
} from '@/components/ui/carousel'
|
|
145
|
+
|
|
146
|
+
export function CarouselSize() {
|
|
147
|
+
return (
|
|
148
|
+
<Carousel
|
|
149
|
+
opts={{
|
|
150
|
+
align: 'start'
|
|
151
|
+
}}
|
|
152
|
+
className="w-full max-w-[12rem] sm:max-w-xs md:max-w-sm"
|
|
153
|
+
>
|
|
154
|
+
<CarouselContent>
|
|
155
|
+
{Array.from({ length: 5 }).map((_, index) => (
|
|
156
|
+
<CarouselItem key={index} className="basis-1/2 lg:basis-1/3">
|
|
157
|
+
<div className="p-1">
|
|
158
|
+
<Card>
|
|
159
|
+
<CardContent className="flex aspect-square items-center justify-center p-6">
|
|
160
|
+
<span className="text-3xl font-semibold">{index + 1}</span>
|
|
161
|
+
</CardContent>
|
|
162
|
+
</Card>
|
|
163
|
+
</div>
|
|
164
|
+
</CarouselItem>
|
|
165
|
+
))}
|
|
166
|
+
</CarouselContent>
|
|
167
|
+
<CarouselPrevious />
|
|
168
|
+
<CarouselNext />
|
|
169
|
+
</Carousel>
|
|
170
|
+
)
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
```tsx showLineNumbers {4-6}
|
|
175
|
+
// 33% of the carousel width.
|
|
176
|
+
<Carousel>
|
|
177
|
+
<CarouselContent>
|
|
178
|
+
<CarouselItem className="basis-1/3">...</CarouselItem>
|
|
179
|
+
<CarouselItem className="basis-1/3">...</CarouselItem>
|
|
180
|
+
<CarouselItem className="basis-1/3">...</CarouselItem>
|
|
181
|
+
</CarouselContent>
|
|
182
|
+
</Carousel>
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
```tsx showLineNumbers {4-6}
|
|
186
|
+
// 50% on small screens and 33% on larger screens.
|
|
187
|
+
<Carousel>
|
|
188
|
+
<CarouselContent>
|
|
189
|
+
<CarouselItem className="md:basis-1/2 lg:basis-1/3">...</CarouselItem>
|
|
190
|
+
<CarouselItem className="md:basis-1/2 lg:basis-1/3">...</CarouselItem>
|
|
191
|
+
<CarouselItem className="md:basis-1/2 lg:basis-1/3">...</CarouselItem>
|
|
192
|
+
</CarouselContent>
|
|
193
|
+
</Carousel>
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Spacing
|
|
197
|
+
|
|
198
|
+
To set the spacing between the items, we use a `pl-[VALUE]` utility on the `<CarouselItem />` and a negative `-ml-[VALUE]` on the `<CarouselContent />`.
|
|
199
|
+
|
|
200
|
+
```tsx
|
|
201
|
+
import * as React from 'react'
|
|
202
|
+
|
|
203
|
+
import { Card, CardContent } from '@/components/ui/card'
|
|
204
|
+
import {
|
|
205
|
+
Carousel,
|
|
206
|
+
CarouselContent,
|
|
207
|
+
CarouselItem,
|
|
208
|
+
CarouselNext,
|
|
209
|
+
CarouselPrevious
|
|
210
|
+
} from '@/components/ui/carousel'
|
|
211
|
+
|
|
212
|
+
export function CarouselSpacing() {
|
|
213
|
+
return (
|
|
214
|
+
<Carousel className="w-full max-w-[12rem] sm:max-w-xs md:max-w-sm">
|
|
215
|
+
<CarouselContent className="-ml-1">
|
|
216
|
+
{Array.from({ length: 5 }).map((_, index) => (
|
|
217
|
+
<CarouselItem key={index} className="basis-1/2 pl-1 lg:basis-1/3">
|
|
218
|
+
<div className="p-1">
|
|
219
|
+
<Card>
|
|
220
|
+
<CardContent className="flex aspect-square items-center justify-center p-6">
|
|
221
|
+
<span className="text-2xl font-semibold">{index + 1}</span>
|
|
222
|
+
</CardContent>
|
|
223
|
+
</Card>
|
|
224
|
+
</div>
|
|
225
|
+
</CarouselItem>
|
|
226
|
+
))}
|
|
227
|
+
</CarouselContent>
|
|
228
|
+
<CarouselPrevious />
|
|
229
|
+
<CarouselNext />
|
|
230
|
+
</Carousel>
|
|
231
|
+
)
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
```tsx showLineNumbers /-ml-4/ /pl-4/
|
|
236
|
+
<Carousel>
|
|
237
|
+
<CarouselContent className="-ml-4">
|
|
238
|
+
<CarouselItem className="pl-4">...</CarouselItem>
|
|
239
|
+
<CarouselItem className="pl-4">...</CarouselItem>
|
|
240
|
+
<CarouselItem className="pl-4">...</CarouselItem>
|
|
241
|
+
</CarouselContent>
|
|
242
|
+
</Carousel>
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
```tsx showLineNumbers /-ml-2/ /pl-2/ /md:-ml-4/ /md:pl-4/
|
|
246
|
+
<Carousel>
|
|
247
|
+
<CarouselContent className="-ml-2 md:-ml-4">
|
|
248
|
+
<CarouselItem className="pl-2 md:pl-4">...</CarouselItem>
|
|
249
|
+
<CarouselItem className="pl-2 md:pl-4">...</CarouselItem>
|
|
250
|
+
<CarouselItem className="pl-2 md:pl-4">...</CarouselItem>
|
|
251
|
+
</CarouselContent>
|
|
252
|
+
</Carousel>
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## Orientation
|
|
256
|
+
|
|
257
|
+
Use the `orientation` prop to set the orientation of the carousel.
|
|
258
|
+
|
|
259
|
+
```tsx
|
|
260
|
+
import * as React from 'react'
|
|
261
|
+
|
|
262
|
+
import { Card, CardContent } from '@/components/ui/card'
|
|
263
|
+
import {
|
|
264
|
+
Carousel,
|
|
265
|
+
CarouselContent,
|
|
266
|
+
CarouselItem,
|
|
267
|
+
CarouselNext,
|
|
268
|
+
CarouselPrevious
|
|
269
|
+
} from '@/components/ui/carousel'
|
|
270
|
+
|
|
271
|
+
export function CarouselOrientation() {
|
|
272
|
+
return (
|
|
273
|
+
<Carousel
|
|
274
|
+
opts={{
|
|
275
|
+
align: 'start'
|
|
276
|
+
}}
|
|
277
|
+
orientation="vertical"
|
|
278
|
+
className="w-full max-w-xs"
|
|
279
|
+
>
|
|
280
|
+
<CarouselContent className="-mt-1 h-[270px]">
|
|
281
|
+
{Array.from({ length: 5 }).map((_, index) => (
|
|
282
|
+
<CarouselItem key={index} className="basis-1/2 pt-1">
|
|
283
|
+
<div className="p-1">
|
|
284
|
+
<Card>
|
|
285
|
+
<CardContent className="flex items-center justify-center p-6">
|
|
286
|
+
<span className="text-3xl font-semibold">{index + 1}</span>
|
|
287
|
+
</CardContent>
|
|
288
|
+
</Card>
|
|
289
|
+
</div>
|
|
290
|
+
</CarouselItem>
|
|
291
|
+
))}
|
|
292
|
+
</CarouselContent>
|
|
293
|
+
<CarouselPrevious />
|
|
294
|
+
<CarouselNext />
|
|
295
|
+
</Carousel>
|
|
296
|
+
)
|
|
297
|
+
}
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
```tsx showLineNumbers /vertical | horizontal/
|
|
301
|
+
<Carousel orientation="vertical | horizontal">
|
|
302
|
+
<CarouselContent>
|
|
303
|
+
<CarouselItem>...</CarouselItem>
|
|
304
|
+
<CarouselItem>...</CarouselItem>
|
|
305
|
+
<CarouselItem>...</CarouselItem>
|
|
306
|
+
</CarouselContent>
|
|
307
|
+
</Carousel>
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
## Options
|
|
311
|
+
|
|
312
|
+
You can pass options to the carousel using the `opts` prop. See the [Embla Carousel docs](https://www.embla-carousel.com/api/options/) for more information.
|
|
313
|
+
|
|
314
|
+
```tsx showLineNumbers {2-5}
|
|
315
|
+
<Carousel
|
|
316
|
+
opts={{
|
|
317
|
+
align: 'start',
|
|
318
|
+
loop: true
|
|
319
|
+
}}
|
|
320
|
+
>
|
|
321
|
+
<CarouselContent>
|
|
322
|
+
<CarouselItem>...</CarouselItem>
|
|
323
|
+
<CarouselItem>...</CarouselItem>
|
|
324
|
+
<CarouselItem>...</CarouselItem>
|
|
325
|
+
</CarouselContent>
|
|
326
|
+
</Carousel>
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
## API
|
|
330
|
+
|
|
331
|
+
Use a state and the `setApi` prop to get an instance of the carousel API.
|
|
332
|
+
|
|
333
|
+
```tsx
|
|
334
|
+
'use client'
|
|
335
|
+
|
|
336
|
+
import * as React from 'react'
|
|
337
|
+
|
|
338
|
+
import { Card, CardContent } from '@/components/ui/card'
|
|
339
|
+
import {
|
|
340
|
+
Carousel,
|
|
341
|
+
CarouselContent,
|
|
342
|
+
CarouselItem,
|
|
343
|
+
CarouselNext,
|
|
344
|
+
CarouselPrevious,
|
|
345
|
+
type CarouselApi
|
|
346
|
+
} from '@/components/ui/carousel'
|
|
347
|
+
|
|
348
|
+
export function CarouselDApiDemo() {
|
|
349
|
+
const [api, setApi] = React.useState<CarouselApi>()
|
|
350
|
+
const [current, setCurrent] = React.useState(0)
|
|
351
|
+
const [count, setCount] = React.useState(0)
|
|
352
|
+
|
|
353
|
+
React.useEffect(() => {
|
|
354
|
+
if (!api) {
|
|
355
|
+
return
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
setCount(api.scrollSnapList().length)
|
|
359
|
+
setCurrent(api.selectedScrollSnap() + 1)
|
|
360
|
+
|
|
361
|
+
api.on('select', () => {
|
|
362
|
+
setCurrent(api.selectedScrollSnap() + 1)
|
|
363
|
+
})
|
|
364
|
+
}, [api])
|
|
365
|
+
|
|
366
|
+
return (
|
|
367
|
+
<div className="mx-auto max-w-[10rem] sm:max-w-xs">
|
|
368
|
+
<Carousel setApi={setApi} className="w-full max-w-xs">
|
|
369
|
+
<CarouselContent>
|
|
370
|
+
{Array.from({ length: 5 }).map((_, index) => (
|
|
371
|
+
<CarouselItem key={index}>
|
|
372
|
+
<Card className="m-px">
|
|
373
|
+
<CardContent className="flex aspect-square items-center justify-center p-6">
|
|
374
|
+
<span className="text-4xl font-semibold">{index + 1}</span>
|
|
375
|
+
</CardContent>
|
|
376
|
+
</Card>
|
|
377
|
+
</CarouselItem>
|
|
378
|
+
))}
|
|
379
|
+
</CarouselContent>
|
|
380
|
+
<CarouselPrevious />
|
|
381
|
+
<CarouselNext />
|
|
382
|
+
</Carousel>
|
|
383
|
+
<div className="py-2 text-center text-sm text-muted-foreground">
|
|
384
|
+
Slide {current} of {count}
|
|
385
|
+
</div>
|
|
386
|
+
</div>
|
|
387
|
+
)
|
|
388
|
+
}
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
```tsx showLineNumbers {1,4,22}
|
|
392
|
+
import { type CarouselApi } from '@/components/ui/carousel'
|
|
393
|
+
|
|
394
|
+
export function Example() {
|
|
395
|
+
const [api, setApi] = React.useState<CarouselApi>()
|
|
396
|
+
const [current, setCurrent] = React.useState(0)
|
|
397
|
+
const [count, setCount] = React.useState(0)
|
|
398
|
+
|
|
399
|
+
React.useEffect(() => {
|
|
400
|
+
if (!api) {
|
|
401
|
+
return
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
setCount(api.scrollSnapList().length)
|
|
405
|
+
setCurrent(api.selectedScrollSnap() + 1)
|
|
406
|
+
|
|
407
|
+
api.on('select', () => {
|
|
408
|
+
setCurrent(api.selectedScrollSnap() + 1)
|
|
409
|
+
})
|
|
410
|
+
}, [api])
|
|
411
|
+
|
|
412
|
+
return (
|
|
413
|
+
<Carousel setApi={setApi}>
|
|
414
|
+
<CarouselContent>
|
|
415
|
+
<CarouselItem>...</CarouselItem>
|
|
416
|
+
<CarouselItem>...</CarouselItem>
|
|
417
|
+
<CarouselItem>...</CarouselItem>
|
|
418
|
+
</CarouselContent>
|
|
419
|
+
</Carousel>
|
|
420
|
+
)
|
|
421
|
+
}
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
## Events
|
|
425
|
+
|
|
426
|
+
You can listen to events using the api instance from `setApi`.
|
|
427
|
+
|
|
428
|
+
```tsx showLineNumbers {1,4-14,16}
|
|
429
|
+
import { type CarouselApi } from '@/components/ui/carousel'
|
|
430
|
+
|
|
431
|
+
export function Example() {
|
|
432
|
+
const [api, setApi] = React.useState<CarouselApi>()
|
|
433
|
+
|
|
434
|
+
React.useEffect(() => {
|
|
435
|
+
if (!api) {
|
|
436
|
+
return
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
api.on('select', () => {
|
|
440
|
+
// Do something on select.
|
|
441
|
+
})
|
|
442
|
+
}, [api])
|
|
443
|
+
|
|
444
|
+
return (
|
|
445
|
+
<Carousel setApi={setApi}>
|
|
446
|
+
<CarouselContent>
|
|
447
|
+
<CarouselItem>...</CarouselItem>
|
|
448
|
+
<CarouselItem>...</CarouselItem>
|
|
449
|
+
<CarouselItem>...</CarouselItem>
|
|
450
|
+
</CarouselContent>
|
|
451
|
+
</Carousel>
|
|
452
|
+
)
|
|
453
|
+
}
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
See the [Embla Carousel docs](https://www.embla-carousel.com/api/events/) for more information on using events.
|
|
457
|
+
|
|
458
|
+
## Plugins
|
|
459
|
+
|
|
460
|
+
You can use the `plugins` prop to add plugins to the carousel.
|
|
461
|
+
|
|
462
|
+
```ts showLineNumbers {1,6-10}
|
|
463
|
+
import Autoplay from "embla-carousel-autoplay"
|
|
464
|
+
|
|
465
|
+
export function Example() {
|
|
466
|
+
return (
|
|
467
|
+
<Carousel
|
|
468
|
+
plugins={[
|
|
469
|
+
Autoplay({
|
|
470
|
+
delay: 2000,
|
|
471
|
+
}),
|
|
472
|
+
]}
|
|
473
|
+
>
|
|
474
|
+
// ...
|
|
475
|
+
</Carousel>
|
|
476
|
+
)
|
|
477
|
+
}
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
```tsx
|
|
481
|
+
'use client'
|
|
482
|
+
|
|
483
|
+
import * as React from 'react'
|
|
484
|
+
import Autoplay from 'embla-carousel-autoplay'
|
|
485
|
+
|
|
486
|
+
import { Card, CardContent } from '@/components/ui/card'
|
|
487
|
+
import {
|
|
488
|
+
Carousel,
|
|
489
|
+
CarouselContent,
|
|
490
|
+
CarouselItem,
|
|
491
|
+
CarouselNext,
|
|
492
|
+
CarouselPrevious
|
|
493
|
+
} from '@/components/ui/carousel'
|
|
494
|
+
|
|
495
|
+
export function CarouselPlugin() {
|
|
496
|
+
const plugin = React.useRef(Autoplay({ delay: 2000, stopOnInteraction: true }))
|
|
497
|
+
|
|
498
|
+
return (
|
|
499
|
+
<Carousel
|
|
500
|
+
plugins={[plugin.current]}
|
|
501
|
+
className="w-full max-w-[10rem] sm:max-w-xs"
|
|
502
|
+
onMouseEnter={plugin.current.stop}
|
|
503
|
+
onMouseLeave={plugin.current.reset}
|
|
504
|
+
>
|
|
505
|
+
<CarouselContent>
|
|
506
|
+
{Array.from({ length: 5 }).map((_, index) => (
|
|
507
|
+
<CarouselItem key={index}>
|
|
508
|
+
<div className="p-1">
|
|
509
|
+
<Card>
|
|
510
|
+
<CardContent className="flex aspect-square items-center justify-center p-6">
|
|
511
|
+
<span className="text-4xl font-semibold">{index + 1}</span>
|
|
512
|
+
</CardContent>
|
|
513
|
+
</Card>
|
|
514
|
+
</div>
|
|
515
|
+
</CarouselItem>
|
|
516
|
+
))}
|
|
517
|
+
</CarouselContent>
|
|
518
|
+
<CarouselPrevious />
|
|
519
|
+
<CarouselNext />
|
|
520
|
+
</Carousel>
|
|
521
|
+
)
|
|
522
|
+
}
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
## RTL
|
|
526
|
+
|
|
527
|
+
```tsx
|
|
528
|
+
'use client'
|
|
529
|
+
|
|
530
|
+
import * as React from 'react'
|
|
531
|
+
|
|
532
|
+
import { useTranslation, type Translations } from '@/components/language-selector'
|
|
533
|
+
import { Card, CardContent } from '@/components/ui/card'
|
|
534
|
+
import {
|
|
535
|
+
Carousel,
|
|
536
|
+
CarouselContent,
|
|
537
|
+
CarouselItem,
|
|
538
|
+
CarouselNext,
|
|
539
|
+
CarouselPrevious
|
|
540
|
+
} from '@/components/ui/carousel'
|
|
541
|
+
|
|
542
|
+
const translations: Translations = {
|
|
543
|
+
en: {
|
|
544
|
+
dir: 'ltr',
|
|
545
|
+
values: {}
|
|
546
|
+
},
|
|
547
|
+
ar: {
|
|
548
|
+
dir: 'rtl',
|
|
549
|
+
values: {}
|
|
550
|
+
},
|
|
551
|
+
he: {
|
|
552
|
+
dir: 'rtl',
|
|
553
|
+
values: {}
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
function toArabicNumerals(num: number): string {
|
|
558
|
+
const arabicNumerals = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩']
|
|
559
|
+
return num
|
|
560
|
+
.toString()
|
|
561
|
+
.split('')
|
|
562
|
+
.map(digit => arabicNumerals[parseInt(digit, 10)])
|
|
563
|
+
.join('')
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
export function CarouselRtl() {
|
|
567
|
+
const { dir, language } = useTranslation(translations, 'ar')
|
|
568
|
+
|
|
569
|
+
const formatNumber = (num: number): string => {
|
|
570
|
+
if (language === 'ar') {
|
|
571
|
+
return toArabicNumerals(num)
|
|
572
|
+
}
|
|
573
|
+
return num.toString()
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
return (
|
|
577
|
+
<Carousel
|
|
578
|
+
dir={dir}
|
|
579
|
+
className="w-full max-w-[12rem] sm:max-w-xs"
|
|
580
|
+
opts={{
|
|
581
|
+
direction: dir
|
|
582
|
+
}}
|
|
583
|
+
>
|
|
584
|
+
<CarouselContent>
|
|
585
|
+
{Array.from({ length: 5 }).map((_, index) => (
|
|
586
|
+
<CarouselItem key={index}>
|
|
587
|
+
<div className="p-1">
|
|
588
|
+
<Card>
|
|
589
|
+
<CardContent className="flex aspect-square items-center justify-center p-6">
|
|
590
|
+
<span className="text-4xl font-semibold">{formatNumber(index + 1)}</span>
|
|
591
|
+
</CardContent>
|
|
592
|
+
</Card>
|
|
593
|
+
</div>
|
|
594
|
+
</CarouselItem>
|
|
595
|
+
))}
|
|
596
|
+
</CarouselContent>
|
|
597
|
+
<CarouselPrevious />
|
|
598
|
+
<CarouselNext />
|
|
599
|
+
</Carousel>
|
|
600
|
+
)
|
|
601
|
+
}
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
When localizing the carousel for RTL languages, you need to set the `direction` option in the `opts` prop to match the text direction. This ensures the carousel scrolls in the correct direction.
|
|
605
|
+
|
|
606
|
+
```tsx showLineNumbers {2-5}
|
|
607
|
+
<Carousel
|
|
608
|
+
dir={dir}
|
|
609
|
+
opts={{
|
|
610
|
+
direction: dir
|
|
611
|
+
}}
|
|
612
|
+
>
|
|
613
|
+
<CarouselContent>
|
|
614
|
+
<CarouselItem>...</CarouselItem>
|
|
615
|
+
<CarouselItem>...</CarouselItem>
|
|
616
|
+
<CarouselItem>...</CarouselItem>
|
|
617
|
+
</CarouselContent>
|
|
618
|
+
<CarouselPrevious className="rtl:rotate-180" />
|
|
619
|
+
<CarouselNext className="rtl:rotate-180" />
|
|
620
|
+
</Carousel>
|
|
621
|
+
```
|
|
622
|
+
|
|
623
|
+
The `direction` option accepts `"ltr"` or `"rtl"` and should match the `dir` prop value. You may also want to rotate the navigation buttons using the `rtl:rotate-180` class to ensure they point in the correct direction.
|
|
624
|
+
|
|
625
|
+
## API Reference
|
|
626
|
+
|
|
627
|
+
See the [Embla Carousel docs](https://www.embla-carousel.com/api/) for more information on props and plugins.
|