create-ec-app 0.0.6 → 0.0.7

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