@traky-app/ui 1.0.0 → 1.1.0

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 (68) hide show
  1. package/README.md +12 -19
  2. package/package.json +48 -3
  3. package/registry/traky/json/command.json +1 -1
  4. package/registry/traky/ui/command.tsx +1 -0
  5. package/src/hooks/use-document-theme.ts +25 -0
  6. package/src/hooks/use-mobile.ts +19 -0
  7. package/src/lib/disable-input-autofill.ts +23 -0
  8. package/src/lib/sidebar-persistence.ts +76 -0
  9. package/src/lib/utils.ts +30 -0
  10. package/src/ui/accordion.tsx +65 -0
  11. package/src/ui/alert-dialog.tsx +163 -0
  12. package/src/ui/alert.tsx +66 -0
  13. package/src/ui/animated-beam.tsx +185 -0
  14. package/src/ui/animated-list.tsx +71 -0
  15. package/src/ui/avatar.tsx +53 -0
  16. package/src/ui/badge.tsx +46 -0
  17. package/src/ui/bento-grid.tsx +109 -0
  18. package/src/ui/breadcrumb.tsx +108 -0
  19. package/src/ui/bubble.tsx +125 -0
  20. package/src/ui/button-group.tsx +83 -0
  21. package/src/ui/button.tsx +64 -0
  22. package/src/ui/calendar.tsx +213 -0
  23. package/src/ui/card.tsx +92 -0
  24. package/src/ui/carousel.tsx +240 -0
  25. package/src/ui/chart.tsx +380 -0
  26. package/src/ui/checkbox.tsx +31 -0
  27. package/src/ui/checkpoint.tsx +94 -0
  28. package/src/ui/code-block.tsx +232 -0
  29. package/src/ui/collapsible.tsx +33 -0
  30. package/src/ui/command.tsx +191 -0
  31. package/src/ui/context-menu.tsx +251 -0
  32. package/src/ui/dialog.tsx +142 -0
  33. package/src/ui/drawer.tsx +135 -0
  34. package/src/ui/dropdown-menu.tsx +256 -0
  35. package/src/ui/empty.tsx +104 -0
  36. package/src/ui/field.tsx +248 -0
  37. package/src/ui/globe.tsx +234 -0
  38. package/src/ui/hover-card.tsx +44 -0
  39. package/src/ui/input-group.tsx +170 -0
  40. package/src/ui/input-otp.tsx +77 -0
  41. package/src/ui/input.tsx +24 -0
  42. package/src/ui/item.tsx +193 -0
  43. package/src/ui/kbd.tsx +28 -0
  44. package/src/ui/label.tsx +24 -0
  45. package/src/ui/map.tsx +2226 -0
  46. package/src/ui/marker.tsx +69 -0
  47. package/src/ui/marquee.tsx +74 -0
  48. package/src/ui/message.tsx +92 -0
  49. package/src/ui/navigation-menu.tsx +169 -0
  50. package/src/ui/number-ticker.tsx +90 -0
  51. package/src/ui/pagination.tsx +122 -0
  52. package/src/ui/popover.tsx +48 -0
  53. package/src/ui/progress.tsx +31 -0
  54. package/src/ui/select.tsx +193 -0
  55. package/src/ui/separator.tsx +28 -0
  56. package/src/ui/sheet.tsx +143 -0
  57. package/src/ui/sidebar.tsx +764 -0
  58. package/src/ui/skeleton.tsx +13 -0
  59. package/src/ui/sonner.tsx +71 -0
  60. package/src/ui/spinner.tsx +15 -0
  61. package/src/ui/switch.tsx +41 -0
  62. package/src/ui/table.tsx +116 -0
  63. package/src/ui/tabs.tsx +66 -0
  64. package/src/ui/textarea.tsx +20 -0
  65. package/src/ui/toggle-group.tsx +83 -0
  66. package/src/ui/toggle.tsx +47 -0
  67. package/src/ui/tooltip.tsx +61 -0
  68. package/src/ui/trace.tsx +165 -0
@@ -0,0 +1,83 @@
1
+ import { cva, type VariantProps } from "class-variance-authority"
2
+ import { Slot } from "radix-ui"
3
+
4
+ import { cn } from "../lib/utils"
5
+ import { Separator } from "./separator"
6
+
7
+ const buttonGroupVariants = cva(
8
+ "flex w-fit items-stretch has-[>[data-slot=button-group]]:gap-2 [&>*]:focus-visible:relative [&>*]:focus-visible:z-10 has-[select[aria-hidden=true]:last-child]:[&>[data-slot=select-trigger]:last-of-type]:rounded-r-md [&>[data-slot=select-trigger]:not([class*='w-'])]:w-fit [&>input]:flex-1",
9
+ {
10
+ variants: {
11
+ orientation: {
12
+ horizontal:
13
+ "[&>*:not(:first-child)]:rounded-l-none [&>*:not(:first-child)]:border-l-0 [&>*:not(:last-child)]:rounded-r-none",
14
+ vertical:
15
+ "flex-col [&>*:not(:first-child)]:rounded-t-none [&>*:not(:first-child)]:border-t-0 [&>*:not(:last-child)]:rounded-b-none",
16
+ },
17
+ },
18
+ defaultVariants: {
19
+ orientation: "horizontal",
20
+ },
21
+ }
22
+ )
23
+
24
+ function ButtonGroup({
25
+ className,
26
+ orientation,
27
+ ...props
28
+ }: React.ComponentProps<"div"> & VariantProps<typeof buttonGroupVariants>) {
29
+ return (
30
+ <div
31
+ role="group"
32
+ data-slot="button-group"
33
+ data-orientation={orientation}
34
+ className={cn(buttonGroupVariants({ orientation }), className)}
35
+ {...props}
36
+ />
37
+ )
38
+ }
39
+
40
+ function ButtonGroupText({
41
+ className,
42
+ asChild = false,
43
+ ...props
44
+ }: React.ComponentProps<"div"> & {
45
+ asChild?: boolean
46
+ }) {
47
+ const Comp = asChild ? Slot.Root : "div"
48
+
49
+ return (
50
+ <Comp
51
+ className={cn(
52
+ "flex items-center gap-2 rounded-md border bg-muted px-4 text-sm font-medium shadow-xs [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4",
53
+ className
54
+ )}
55
+ {...props}
56
+ />
57
+ )
58
+ }
59
+
60
+ function ButtonGroupSeparator({
61
+ className,
62
+ orientation = "vertical",
63
+ ...props
64
+ }: React.ComponentProps<typeof Separator>) {
65
+ return (
66
+ <Separator
67
+ data-slot="button-group-separator"
68
+ orientation={orientation}
69
+ className={cn(
70
+ "relative m-0! self-stretch bg-input data-[orientation=vertical]:h-auto",
71
+ className
72
+ )}
73
+ {...props}
74
+ />
75
+ )
76
+ }
77
+
78
+ export {
79
+ ButtonGroup,
80
+ ButtonGroupSeparator,
81
+ ButtonGroupText,
82
+ buttonGroupVariants,
83
+ }
@@ -0,0 +1,64 @@
1
+ import * as React from "react"
2
+ import { cva, type VariantProps } from "class-variance-authority"
3
+ import { Slot } from "radix-ui"
4
+
5
+ import { cn } from "../lib/utils"
6
+
7
+ const buttonVariants = cva(
8
+ "inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
9
+ {
10
+ variants: {
11
+ variant: {
12
+ default: "bg-primary text-primary-foreground hover:bg-primary/90",
13
+ destructive:
14
+ "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40",
15
+ outline:
16
+ "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
17
+ secondary:
18
+ "bg-secondary text-secondary-foreground hover:bg-secondary/80",
19
+ ghost:
20
+ "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
21
+ link: "text-primary underline-offset-4 hover:underline",
22
+ },
23
+ size: {
24
+ default: "h-9 px-4 py-2 has-[>svg]:px-3",
25
+ xs: "h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3",
26
+ sm: "h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5",
27
+ lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
28
+ icon: "size-9",
29
+ "icon-xs": "size-6 rounded-md [&_svg:not([class*='size-'])]:size-3",
30
+ "icon-sm": "size-8",
31
+ "icon-lg": "size-10",
32
+ },
33
+ },
34
+ defaultVariants: {
35
+ variant: "default",
36
+ size: "default",
37
+ },
38
+ }
39
+ )
40
+
41
+ function Button({
42
+ className,
43
+ variant = "default",
44
+ size = "default",
45
+ asChild = false,
46
+ ...props
47
+ }: React.ComponentProps<"button"> &
48
+ VariantProps<typeof buttonVariants> & {
49
+ asChild?: boolean
50
+ }) {
51
+ const Comp = asChild ? Slot.Root : "button"
52
+
53
+ return (
54
+ <Comp
55
+ data-slot="button"
56
+ data-variant={variant}
57
+ data-size={size}
58
+ className={cn(buttonVariants({ variant, size, className }))}
59
+ {...props}
60
+ />
61
+ )
62
+ }
63
+
64
+ export { Button, buttonVariants }
@@ -0,0 +1,213 @@
1
+ "use client"
2
+
3
+ import { IconChevronDown, IconChevronLeft, IconChevronRight } from "@tabler/icons-react";
4
+ import * as React from "react"
5
+ import { DayButton, DayPicker, getDefaultClassNames } from "react-day-picker"
6
+
7
+ import { cn } from "../lib/utils"
8
+ import { Button, buttonVariants } from "./button"
9
+
10
+ function Calendar({
11
+ className,
12
+ classNames,
13
+ showOutsideDays = true,
14
+ captionLayout = "label",
15
+ buttonVariant = "ghost",
16
+ formatters,
17
+ components,
18
+ ...props
19
+ }: React.ComponentProps<typeof DayPicker> & {
20
+ buttonVariant?: React.ComponentProps<typeof Button>["variant"]
21
+ }) {
22
+ const defaultClassNames = getDefaultClassNames()
23
+
24
+ return (
25
+ <DayPicker
26
+ showOutsideDays={showOutsideDays}
27
+ className={cn(
28
+ "bg-background group/calendar p-3 [--cell-size:--spacing(8)] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent",
29
+ String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,
30
+ String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,
31
+ className
32
+ )}
33
+ captionLayout={captionLayout}
34
+ formatters={{
35
+ formatMonthDropdown: (date) =>
36
+ date.toLocaleString("default", { month: "short" }),
37
+ ...formatters,
38
+ }}
39
+ classNames={{
40
+ root: cn("w-fit", defaultClassNames.root),
41
+ months: cn(
42
+ "flex gap-4 flex-col md:flex-row relative",
43
+ defaultClassNames.months
44
+ ),
45
+ month: cn("flex flex-col w-full gap-4", defaultClassNames.month),
46
+ nav: cn(
47
+ "flex items-center gap-1 w-full absolute top-0 inset-x-0 justify-between",
48
+ defaultClassNames.nav
49
+ ),
50
+ button_previous: cn(
51
+ buttonVariants({ variant: buttonVariant }),
52
+ "size-(--cell-size) aria-disabled:opacity-50 p-0 select-none",
53
+ defaultClassNames.button_previous
54
+ ),
55
+ button_next: cn(
56
+ buttonVariants({ variant: buttonVariant }),
57
+ "size-(--cell-size) aria-disabled:opacity-50 p-0 select-none",
58
+ defaultClassNames.button_next
59
+ ),
60
+ month_caption: cn(
61
+ "flex items-center justify-center h-(--cell-size) w-full px-(--cell-size)",
62
+ defaultClassNames.month_caption
63
+ ),
64
+ dropdowns: cn(
65
+ "w-full flex items-center text-sm font-medium justify-center h-(--cell-size) gap-1.5",
66
+ defaultClassNames.dropdowns
67
+ ),
68
+ dropdown_root: cn(
69
+ "relative has-focus:border-ring border border-input shadow-xs has-focus:ring-ring/50 has-focus:ring-[3px] rounded-md",
70
+ defaultClassNames.dropdown_root
71
+ ),
72
+ dropdown: cn(
73
+ "absolute bg-popover inset-0 opacity-0",
74
+ defaultClassNames.dropdown
75
+ ),
76
+ caption_label: cn(
77
+ "select-none font-medium",
78
+ captionLayout === "label"
79
+ ? "text-sm"
80
+ : "rounded-md pl-2 pr-1 flex items-center gap-1 text-sm h-8 [&>svg]:text-muted-foreground [&>svg]:size-3.5",
81
+ defaultClassNames.caption_label
82
+ ),
83
+ // react-day-picker v10: `table` sigue en runtime; tipos desactualizados
84
+ table: "w-full border-collapse" as string,
85
+ weekdays: cn("flex", defaultClassNames.weekdays),
86
+ weekday: cn(
87
+ "text-muted-foreground rounded-md flex-1 font-normal text-[0.8rem] select-none",
88
+ defaultClassNames.weekday
89
+ ),
90
+ week: cn("flex w-full mt-2", defaultClassNames.week),
91
+ week_number_header: cn(
92
+ "select-none w-(--cell-size)",
93
+ defaultClassNames.week_number_header
94
+ ),
95
+ week_number: cn(
96
+ "text-[0.8rem] select-none text-muted-foreground",
97
+ defaultClassNames.week_number
98
+ ),
99
+ day: cn(
100
+ "relative w-full h-full p-0 text-center [&:last-child[data-selected=true]_button]:rounded-r-md group/day aspect-square select-none",
101
+ props.showWeekNumber
102
+ ? "[&:nth-child(2)[data-selected=true]_button]:rounded-l-md"
103
+ : "[&:first-child[data-selected=true]_button]:rounded-l-md",
104
+ defaultClassNames.day
105
+ ),
106
+ range_start: cn(
107
+ "rounded-l-md bg-accent",
108
+ defaultClassNames.range_start
109
+ ),
110
+ range_middle: cn("rounded-none", defaultClassNames.range_middle),
111
+ range_end: cn("rounded-r-md bg-accent", defaultClassNames.range_end),
112
+ today: cn(
113
+ "bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none",
114
+ defaultClassNames.today
115
+ ),
116
+ outside: cn(
117
+ "text-muted-foreground aria-selected:text-muted-foreground",
118
+ defaultClassNames.outside
119
+ ),
120
+ disabled: cn(
121
+ "text-muted-foreground opacity-50",
122
+ defaultClassNames.disabled
123
+ ),
124
+ hidden: cn("invisible", defaultClassNames.hidden),
125
+ ...classNames,
126
+ } as React.ComponentProps<typeof DayPicker>["classNames"]}
127
+ components={{
128
+ Root: ({ className, rootRef, ...props }) => {
129
+ return (
130
+ <div
131
+ data-slot="calendar"
132
+ ref={rootRef}
133
+ className={cn(className)}
134
+ {...props}
135
+ />
136
+ )
137
+ },
138
+ Chevron: ({ className, orientation, ...props }) => {
139
+ if (orientation === "left") {
140
+ return (
141
+ <IconChevronLeft className={cn("size-4", className)} {...props} />
142
+ )
143
+ }
144
+
145
+ if (orientation === "right") {
146
+ return (
147
+ <IconChevronRight
148
+ className={cn("size-4", className)}
149
+ {...props}
150
+ />
151
+ )
152
+ }
153
+
154
+ return (
155
+ <IconChevronDown className={cn("size-4", className)} {...props} />
156
+ )
157
+ },
158
+ DayButton: CalendarDayButton,
159
+ WeekNumber: ({ children, ...props }) => {
160
+ return (
161
+ <td {...props}>
162
+ <div className="flex size-(--cell-size) items-center justify-center text-center">
163
+ {children}
164
+ </div>
165
+ </td>
166
+ )
167
+ },
168
+ ...components,
169
+ }}
170
+ {...props}
171
+ />
172
+ )
173
+ }
174
+
175
+ function CalendarDayButton({
176
+ className,
177
+ day,
178
+ modifiers,
179
+ ...props
180
+ }: React.ComponentProps<typeof DayButton>) {
181
+ const defaultClassNames = getDefaultClassNames()
182
+
183
+ const ref = React.useRef<HTMLButtonElement>(null)
184
+ React.useEffect(() => {
185
+ if (modifiers.focused) ref.current?.focus()
186
+ }, [modifiers.focused])
187
+
188
+ return (
189
+ <Button
190
+ ref={ref}
191
+ variant="ghost"
192
+ size="icon"
193
+ data-day={day.date.toLocaleDateString()}
194
+ data-selected-single={
195
+ modifiers.selected &&
196
+ !modifiers.range_start &&
197
+ !modifiers.range_end &&
198
+ !modifiers.range_middle
199
+ }
200
+ data-range-start={modifiers.range_start}
201
+ data-range-end={modifiers.range_end}
202
+ data-range-middle={modifiers.range_middle}
203
+ className={cn(
204
+ "data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground data-[range-middle=true]:bg-accent data-[range-middle=true]:text-accent-foreground data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-ring/50 dark:hover:text-accent-foreground flex aspect-square size-auto w-full min-w-(--cell-size) flex-col gap-1 leading-none font-normal group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:ring-[3px] data-[range-end=true]:rounded-md data-[range-end=true]:rounded-r-md data-[range-middle=true]:rounded-none data-[range-start=true]:rounded-md data-[range-start=true]:rounded-l-md [&>span]:text-xs [&>span]:opacity-70",
205
+ defaultClassNames.day,
206
+ className
207
+ )}
208
+ {...props}
209
+ />
210
+ )
211
+ }
212
+
213
+ export { Calendar, CalendarDayButton }
@@ -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,240 @@
1
+ "use client"
2
+
3
+ import { IconArrowLeft, IconArrowRight } from "@tabler/icons-react";
4
+ import * as React from "react"
5
+ import useEmblaCarousel, {
6
+ type UseEmblaCarouselType,
7
+ } from "embla-carousel-react"
8
+ import { cn } from "../lib/utils"
9
+ import { Button } from "./button"
10
+
11
+ type CarouselApi = UseEmblaCarouselType[1]
12
+ type UseCarouselParameters = Parameters<typeof useEmblaCarousel>
13
+ type CarouselOptions = UseCarouselParameters[0]
14
+ type CarouselPlugin = UseCarouselParameters[1]
15
+
16
+ type CarouselProps = {
17
+ opts?: CarouselOptions
18
+ plugins?: CarouselPlugin
19
+ orientation?: "horizontal" | "vertical"
20
+ setApi?: (api: CarouselApi) => void
21
+ }
22
+
23
+ type CarouselContextProps = {
24
+ carouselRef: ReturnType<typeof useEmblaCarousel>[0]
25
+ api: ReturnType<typeof useEmblaCarousel>[1]
26
+ scrollPrev: () => void
27
+ scrollNext: () => void
28
+ canScrollPrev: boolean
29
+ canScrollNext: boolean
30
+ } & CarouselProps
31
+
32
+ const CarouselContext = React.createContext<CarouselContextProps | null>(null)
33
+
34
+ function useCarousel() {
35
+ const context = React.useContext(CarouselContext)
36
+
37
+ if (!context) {
38
+ throw new Error("useCarousel must be used within a <Carousel />")
39
+ }
40
+
41
+ return context
42
+ }
43
+
44
+ function Carousel({
45
+ orientation = "horizontal",
46
+ opts,
47
+ setApi,
48
+ plugins,
49
+ className,
50
+ children,
51
+ ...props
52
+ }: React.ComponentProps<"div"> & CarouselProps) {
53
+ const [carouselRef, api] = useEmblaCarousel(
54
+ {
55
+ ...opts,
56
+ axis: orientation === "horizontal" ? "x" : "y",
57
+ },
58
+ plugins
59
+ )
60
+ const [canScrollPrev, setCanScrollPrev] = React.useState(false)
61
+ const [canScrollNext, setCanScrollNext] = React.useState(false)
62
+
63
+ const onSelect = React.useCallback((api: CarouselApi) => {
64
+ if (!api) return
65
+ setCanScrollPrev(api.canScrollPrev())
66
+ setCanScrollNext(api.canScrollNext())
67
+ }, [])
68
+
69
+ const scrollPrev = React.useCallback(() => {
70
+ api?.scrollPrev()
71
+ }, [api])
72
+
73
+ const scrollNext = React.useCallback(() => {
74
+ api?.scrollNext()
75
+ }, [api])
76
+
77
+ const handleKeyDown = React.useCallback(
78
+ (event: React.KeyboardEvent<HTMLDivElement>) => {
79
+ if (event.key === "IconArrowLeft") {
80
+ event.preventDefault()
81
+ scrollPrev()
82
+ } else if (event.key === "IconArrowRight") {
83
+ event.preventDefault()
84
+ scrollNext()
85
+ }
86
+ },
87
+ [scrollPrev, scrollNext]
88
+ )
89
+
90
+ React.useEffect(() => {
91
+ if (!api || !setApi) return
92
+ setApi(api)
93
+ }, [api, setApi])
94
+
95
+ React.useEffect(() => {
96
+ if (!api) return
97
+ onSelect(api)
98
+ api.on("reInit", onSelect)
99
+ api.on("select", onSelect)
100
+
101
+ return () => {
102
+ api?.off("select", onSelect)
103
+ }
104
+ }, [api, onSelect])
105
+
106
+ return (
107
+ <CarouselContext.Provider
108
+ value={{
109
+ carouselRef,
110
+ api: api,
111
+ opts,
112
+ orientation:
113
+ orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
114
+ scrollPrev,
115
+ scrollNext,
116
+ canScrollPrev,
117
+ canScrollNext,
118
+ }}
119
+ >
120
+ <div
121
+ onKeyDownCapture={handleKeyDown}
122
+ className={cn("relative", className)}
123
+ role="region"
124
+ aria-roledescription="carousel"
125
+ data-slot="carousel"
126
+ {...props}
127
+ >
128
+ {children}
129
+ </div>
130
+ </CarouselContext.Provider>
131
+ )
132
+ }
133
+
134
+ function CarouselContent({ className, ...props }: React.ComponentProps<"div">) {
135
+ const { carouselRef, orientation } = useCarousel()
136
+
137
+ return (
138
+ <div
139
+ ref={carouselRef}
140
+ className="overflow-hidden"
141
+ data-slot="carousel-content"
142
+ >
143
+ <div
144
+ className={cn(
145
+ "flex",
146
+ orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col",
147
+ className
148
+ )}
149
+ {...props}
150
+ />
151
+ </div>
152
+ )
153
+ }
154
+
155
+ function CarouselItem({ className, ...props }: React.ComponentProps<"div">) {
156
+ const { orientation } = useCarousel()
157
+
158
+ return (
159
+ <div
160
+ role="group"
161
+ aria-roledescription="slide"
162
+ data-slot="carousel-item"
163
+ className={cn(
164
+ "min-w-0 shrink-0 grow-0 basis-full",
165
+ orientation === "horizontal" ? "pl-4" : "pt-4",
166
+ className
167
+ )}
168
+ {...props}
169
+ />
170
+ )
171
+ }
172
+
173
+ function CarouselPrevious({
174
+ className,
175
+ variant = "outline",
176
+ size = "icon",
177
+ ...props
178
+ }: React.ComponentProps<typeof Button>) {
179
+ const { orientation, scrollPrev, canScrollPrev } = useCarousel()
180
+
181
+ return (
182
+ <Button
183
+ data-slot="carousel-previous"
184
+ variant={variant}
185
+ size={size}
186
+ className={cn(
187
+ "absolute size-8 rounded-full",
188
+ orientation === "horizontal"
189
+ ? "top-1/2 -left-12 -translate-y-1/2"
190
+ : "-top-12 left-1/2 -translate-x-1/2 rotate-90",
191
+ className
192
+ )}
193
+ disabled={!canScrollPrev}
194
+ onClick={scrollPrev}
195
+ {...props}
196
+ >
197
+ <IconArrowLeft />
198
+ <span className="sr-only">Previous slide</span>
199
+ </Button>
200
+ )
201
+ }
202
+
203
+ function CarouselNext({
204
+ className,
205
+ variant = "outline",
206
+ size = "icon",
207
+ ...props
208
+ }: React.ComponentProps<typeof Button>) {
209
+ const { orientation, scrollNext, canScrollNext } = useCarousel()
210
+
211
+ return (
212
+ <Button
213
+ data-slot="carousel-next"
214
+ variant={variant}
215
+ size={size}
216
+ className={cn(
217
+ "absolute size-8 rounded-full",
218
+ orientation === "horizontal"
219
+ ? "top-1/2 -right-12 -translate-y-1/2"
220
+ : "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
221
+ className
222
+ )}
223
+ disabled={!canScrollNext}
224
+ onClick={scrollNext}
225
+ {...props}
226
+ >
227
+ <IconArrowRight />
228
+ <span className="sr-only">Next slide</span>
229
+ </Button>
230
+ )
231
+ }
232
+
233
+ export {
234
+ type CarouselApi,
235
+ Carousel,
236
+ CarouselContent,
237
+ CarouselItem,
238
+ CarouselPrevious,
239
+ CarouselNext,
240
+ }