@tanstack/cta-ui 0.15.2 → 0.15.4
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/dist/assets/index-BLGJkAxX.css +1 -0
- package/dist/assets/index-DPjMQkKx.js +208 -0
- package/dist/assets/index-DPjMQkKx.js.map +1 -0
- package/dist/index.html +3 -2
- package/index.html +1 -0
- package/lib/engine-handling/create-app-wrapper.ts +3 -4
- package/lib/engine-handling/generate-initial-payload.ts +12 -20
- package/lib/engine-handling/server-environment.ts +2 -2
- package/lib/index.ts +33 -15
- package/lib-dist/engine-handling/create-app-wrapper.js +3 -2
- package/lib-dist/engine-handling/generate-initial-payload.d.ts +8 -6
- package/lib-dist/engine-handling/generate-initial-payload.js +9 -14
- package/lib-dist/engine-handling/server-environment.d.ts +3 -3
- package/lib-dist/index.d.ts +1 -0
- package/lib-dist/index.js +29 -11
- package/package.json +3 -32
- package/src/index.tsx +2 -42
- package/src/main.tsx +0 -1
- package/src/styles.css +2 -0
- package/src/types.d.ts +13 -8
- package/dist/assets/index-BktnQA5a.js +0 -213
- package/dist/assets/index-BktnQA5a.js.map +0 -1
- package/dist/assets/index-CpoUtYXp.css +0 -1
- package/dist/logo-color-100w.png +0 -0
- package/dist/logo192.png +0 -0
- package/dist/logo512.png +0 -0
- package/dist/tailwind.svg +0 -1
- package/dist/tanstack.png +0 -0
- package/dist/typescript.svg +0 -1
- package/lib/engine-handling/framework-registration.ts +0 -11
- package/lib-dist/engine-handling/framework-registration.d.ts +0 -1
- package/lib-dist/engine-handling/framework-registration.js +0 -10
- package/public/logo-color-100w.png +0 -0
- package/public/logo192.png +0 -0
- package/public/logo512.png +0 -0
- package/public/tailwind.svg +0 -1
- package/public/tanstack.png +0 -0
- package/public/typescript.svg +0 -1
- package/src/components/StatusList.tsx +0 -22
- package/src/components/add-on-info-dialog.tsx +0 -39
- package/src/components/background-animation.tsx +0 -229
- package/src/components/cta-sidebar.tsx +0 -50
- package/src/components/custom-add-on-dialog.tsx +0 -79
- package/src/components/file-navigator.tsx +0 -203
- package/src/components/file-tree.tsx +0 -35
- package/src/components/file-viewer.tsx +0 -67
- package/src/components/header.tsx +0 -31
- package/src/components/sidebar-items/add-ons.tsx +0 -94
- package/src/components/sidebar-items/mode-selector.tsx +0 -57
- package/src/components/sidebar-items/project-name.tsx +0 -28
- package/src/components/sidebar-items/run-add-ons.tsx +0 -71
- package/src/components/sidebar-items/run-create-app.tsx +0 -82
- package/src/components/sidebar-items/starter.tsx +0 -123
- package/src/components/sidebar-items/typescript-switch.tsx +0 -52
- package/src/components/starters-carousel.tsx +0 -45
- package/src/components/startup-dialog.tsx +0 -71
- package/src/components/toaster.tsx +0 -29
- package/src/components/ui/button.tsx +0 -61
- package/src/components/ui/carousel.tsx +0 -239
- package/src/components/ui/checkbox.tsx +0 -30
- package/src/components/ui/dialog.tsx +0 -138
- package/src/components/ui/dropdown-menu.tsx +0 -255
- package/src/components/ui/input.tsx +0 -21
- package/src/components/ui/label.tsx +0 -22
- package/src/components/ui/popover.tsx +0 -46
- package/src/components/ui/separator.tsx +0 -28
- package/src/components/ui/sheet.tsx +0 -137
- package/src/components/ui/sidebar.tsx +0 -726
- package/src/components/ui/skeleton.tsx +0 -13
- package/src/components/ui/sonner.tsx +0 -23
- package/src/components/ui/switch.tsx +0 -29
- package/src/components/ui/table.tsx +0 -114
- package/src/components/ui/tabs.tsx +0 -64
- package/src/components/ui/toggle-group.tsx +0 -71
- package/src/components/ui/toggle.tsx +0 -49
- package/src/components/ui/tooltip.tsx +0 -61
- package/src/components/ui/tree-view.tsx +0 -497
- package/src/file-classes.ts +0 -54
- package/src/hooks/use-mobile.ts +0 -19
- package/src/hooks/use-mounted.ts +0 -9
- package/src/hooks/use-preferred-reduced-motion.ts +0 -27
- package/src/hooks/use-streaming-status.ts +0 -70
- package/src/lib/api.ts +0 -92
- package/src/lib/utils.ts +0 -6
- package/src/store/add-ons.ts +0 -81
- package/src/store/project.ts +0 -347
- package/tests/store/add-ons.test.ts +0 -222
- package/vitest.config.ts +0 -6
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react'
|
|
2
|
-
import { FileBoxIcon, TrashIcon } from 'lucide-react'
|
|
3
|
-
|
|
4
|
-
import { toast } from 'sonner'
|
|
5
|
-
|
|
6
|
-
import { Button } from '@/components/ui/button'
|
|
7
|
-
import { Input } from '@/components/ui/input'
|
|
8
|
-
import {
|
|
9
|
-
Dialog,
|
|
10
|
-
DialogContent,
|
|
11
|
-
DialogFooter,
|
|
12
|
-
DialogHeader,
|
|
13
|
-
DialogTitle,
|
|
14
|
-
} from '@/components/ui/dialog'
|
|
15
|
-
import {
|
|
16
|
-
setProjectStarter,
|
|
17
|
-
useApplicationMode,
|
|
18
|
-
useProjectStarter,
|
|
19
|
-
useRegistry,
|
|
20
|
-
} from '@/store/project'
|
|
21
|
-
import { loadRemoteStarter } from '@/lib/api'
|
|
22
|
-
import { StartersCarousel } from '@/components/starters-carousel'
|
|
23
|
-
|
|
24
|
-
export default function Starter() {
|
|
25
|
-
const [url, setUrl] = useState('')
|
|
26
|
-
const [open, setOpen] = useState(false)
|
|
27
|
-
|
|
28
|
-
const mode = useApplicationMode()
|
|
29
|
-
|
|
30
|
-
const { projectStarter } = useProjectStarter()
|
|
31
|
-
|
|
32
|
-
if (mode !== 'setup') {
|
|
33
|
-
return null
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async function onImport(registryUrl?: string) {
|
|
37
|
-
const data = await loadRemoteStarter(registryUrl || url)
|
|
38
|
-
|
|
39
|
-
if ('error' in data) {
|
|
40
|
-
toast.error('Failed to load starter', {
|
|
41
|
-
description: data.error,
|
|
42
|
-
})
|
|
43
|
-
} else {
|
|
44
|
-
setProjectStarter(data)
|
|
45
|
-
setOpen(false)
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const registry = useRegistry()
|
|
50
|
-
|
|
51
|
-
return (
|
|
52
|
-
<>
|
|
53
|
-
{projectStarter?.banner && (
|
|
54
|
-
<div className="flex justify-center mb-4">
|
|
55
|
-
<div className="p-2 bg-gray-300 rounded-lg shadow-xl shadow-gray-800">
|
|
56
|
-
<img
|
|
57
|
-
src={projectStarter.banner}
|
|
58
|
-
alt="Starter Banner"
|
|
59
|
-
className="w-40 max-w-full"
|
|
60
|
-
/>
|
|
61
|
-
</div>
|
|
62
|
-
</div>
|
|
63
|
-
)}
|
|
64
|
-
{projectStarter?.name && (
|
|
65
|
-
<div className="text-md mb-4">
|
|
66
|
-
<Button
|
|
67
|
-
variant="outline"
|
|
68
|
-
size="sm"
|
|
69
|
-
className="mr-2"
|
|
70
|
-
onClick={() => {
|
|
71
|
-
setProjectStarter(undefined)
|
|
72
|
-
}}
|
|
73
|
-
>
|
|
74
|
-
<TrashIcon className="w-4 h-4" />
|
|
75
|
-
</Button>
|
|
76
|
-
<span className="font-bold">Starter: </span>
|
|
77
|
-
{projectStarter.name}
|
|
78
|
-
</div>
|
|
79
|
-
)}
|
|
80
|
-
<div>
|
|
81
|
-
<Button
|
|
82
|
-
variant="secondary"
|
|
83
|
-
className="w-full"
|
|
84
|
-
onClick={() => {
|
|
85
|
-
setUrl('')
|
|
86
|
-
setOpen(true)
|
|
87
|
-
}}
|
|
88
|
-
>
|
|
89
|
-
<FileBoxIcon className="w-4 h-4" />
|
|
90
|
-
Set Project Starter
|
|
91
|
-
</Button>
|
|
92
|
-
<Dialog modal open={open} onOpenChange={setOpen}>
|
|
93
|
-
<DialogContent className="sm:min-w-[425px] sm:max-w-fit">
|
|
94
|
-
<DialogHeader>
|
|
95
|
-
<DialogTitle>Project Starter URL</DialogTitle>
|
|
96
|
-
</DialogHeader>
|
|
97
|
-
{registry?.starters && (
|
|
98
|
-
<div>
|
|
99
|
-
<StartersCarousel onImport={(url) => onImport(url)} />
|
|
100
|
-
</div>
|
|
101
|
-
)}
|
|
102
|
-
<div>
|
|
103
|
-
<Input
|
|
104
|
-
value={url}
|
|
105
|
-
onChange={(e) => setUrl(e.target.value)}
|
|
106
|
-
placeholder="https://github.com/myorg/myproject/starter.json"
|
|
107
|
-
className="min-w-lg w-full"
|
|
108
|
-
onKeyDown={(e) => {
|
|
109
|
-
if (e.key === 'Enter') {
|
|
110
|
-
onImport()
|
|
111
|
-
}
|
|
112
|
-
}}
|
|
113
|
-
/>
|
|
114
|
-
</div>
|
|
115
|
-
<DialogFooter>
|
|
116
|
-
<Button onClick={() => onImport()}>Load</Button>
|
|
117
|
-
</DialogFooter>
|
|
118
|
-
</DialogContent>
|
|
119
|
-
</Dialog>
|
|
120
|
-
</div>
|
|
121
|
-
</>
|
|
122
|
-
)
|
|
123
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { Label } from '@/components/ui/label'
|
|
2
|
-
import { Switch } from '@/components/ui/switch'
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
setTailwind,
|
|
6
|
-
setTypeScript,
|
|
7
|
-
useApplicationMode,
|
|
8
|
-
useProjectOptions,
|
|
9
|
-
useTailwindEditable,
|
|
10
|
-
useTypeScriptEditable,
|
|
11
|
-
} from '@/store/project'
|
|
12
|
-
|
|
13
|
-
export default function TypescriptSwitch() {
|
|
14
|
-
const typescript = useProjectOptions((state) => state.typescript)
|
|
15
|
-
const tailwind = useProjectOptions((state) => state.tailwind)
|
|
16
|
-
const mode = useApplicationMode()
|
|
17
|
-
const enableTailwind = useTailwindEditable()
|
|
18
|
-
const enableTypeScript = useTypeScriptEditable()
|
|
19
|
-
|
|
20
|
-
if (mode !== 'setup') {
|
|
21
|
-
return null
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
<div className="flex">
|
|
26
|
-
<div className="w-1/2 flex flex-row items-center justify-center">
|
|
27
|
-
<Switch
|
|
28
|
-
id="typescript-switch"
|
|
29
|
-
checked={typescript}
|
|
30
|
-
onCheckedChange={(checked) => setTypeScript(checked)}
|
|
31
|
-
disabled={!enableTypeScript}
|
|
32
|
-
/>
|
|
33
|
-
<Label htmlFor="typescript-switch" className="ml-2">
|
|
34
|
-
<img src="/typescript.svg" className="w-5" />
|
|
35
|
-
TypeScript
|
|
36
|
-
</Label>
|
|
37
|
-
</div>
|
|
38
|
-
<div className="w-1/2 flex flex-row items-center justify-center">
|
|
39
|
-
<Switch
|
|
40
|
-
id="tailwind-switch"
|
|
41
|
-
checked={tailwind}
|
|
42
|
-
onCheckedChange={(checked) => setTailwind(checked)}
|
|
43
|
-
disabled={!enableTailwind}
|
|
44
|
-
/>
|
|
45
|
-
<Label htmlFor="tailwind-switch" className="ml-2">
|
|
46
|
-
<img src="/tailwind.svg" className="w-5" />
|
|
47
|
-
Tailwind
|
|
48
|
-
</Label>
|
|
49
|
-
</div>
|
|
50
|
-
</div>
|
|
51
|
-
)
|
|
52
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Carousel,
|
|
3
|
-
CarouselContent,
|
|
4
|
-
CarouselItem,
|
|
5
|
-
} from '@/components/ui/carousel'
|
|
6
|
-
|
|
7
|
-
import { useRegistry } from '@/store/project'
|
|
8
|
-
|
|
9
|
-
export function StartersCarousel({
|
|
10
|
-
onImport,
|
|
11
|
-
}: {
|
|
12
|
-
onImport: (url: string) => void
|
|
13
|
-
}) {
|
|
14
|
-
const registry = useRegistry()
|
|
15
|
-
|
|
16
|
-
if (!registry) {
|
|
17
|
-
return null
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
<div>
|
|
22
|
-
<Carousel>
|
|
23
|
-
<CarouselContent>
|
|
24
|
-
{registry.starters.map((starter) => (
|
|
25
|
-
<CarouselItem className="basis-1/3" key={starter.url}>
|
|
26
|
-
<div
|
|
27
|
-
className="p-2 flex flex-col items-center hover:cursor-pointer hover:bg-gray-700/50 hover:text-white rounded-lg"
|
|
28
|
-
onClick={() => {
|
|
29
|
-
onImport(starter.url)
|
|
30
|
-
}}
|
|
31
|
-
>
|
|
32
|
-
<img
|
|
33
|
-
src={starter.banner}
|
|
34
|
-
alt={starter.name}
|
|
35
|
-
className="w-100 max-w-full"
|
|
36
|
-
/>
|
|
37
|
-
<div className="text-md font-bold">{starter.name}</div>
|
|
38
|
-
</div>
|
|
39
|
-
</CarouselItem>
|
|
40
|
-
))}
|
|
41
|
-
</CarouselContent>
|
|
42
|
-
</Carousel>
|
|
43
|
-
</div>
|
|
44
|
-
)
|
|
45
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { toast } from 'sonner'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
Dialog,
|
|
5
|
-
DialogContent,
|
|
6
|
-
DialogFooter,
|
|
7
|
-
DialogHeader,
|
|
8
|
-
DialogTitle,
|
|
9
|
-
} from '@/components/ui/dialog'
|
|
10
|
-
import { StartersCarousel } from '@/components/starters-carousel'
|
|
11
|
-
import { Button } from '@/components/ui/button'
|
|
12
|
-
import { Switch } from '@/components/ui/switch'
|
|
13
|
-
import { Label } from '@/components/ui/label'
|
|
14
|
-
import {
|
|
15
|
-
setProjectStarter,
|
|
16
|
-
useApplicationMode,
|
|
17
|
-
useRegistry,
|
|
18
|
-
useStartupDialog,
|
|
19
|
-
} from '@/store/project'
|
|
20
|
-
import { loadRemoteStarter } from '@/lib/api'
|
|
21
|
-
|
|
22
|
-
export default function StartupDialog() {
|
|
23
|
-
const mode = useApplicationMode()
|
|
24
|
-
const registry = useRegistry()
|
|
25
|
-
const { open, setOpen, dontShowAgain, setDontShowAgain } = useStartupDialog()
|
|
26
|
-
|
|
27
|
-
if (mode !== 'setup' || !registry || registry?.starters?.length === 0) {
|
|
28
|
-
return null
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async function onImport(registryUrl: string) {
|
|
32
|
-
const data = await loadRemoteStarter(registryUrl)
|
|
33
|
-
|
|
34
|
-
if ('error' in data) {
|
|
35
|
-
toast.error('Failed to load starter', {
|
|
36
|
-
description: data.error,
|
|
37
|
-
})
|
|
38
|
-
} else {
|
|
39
|
-
setProjectStarter(data)
|
|
40
|
-
setOpen(false)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<Dialog modal open={open} onOpenChange={setOpen}>
|
|
46
|
-
<DialogContent className="sm:min-w-[425px] sm:max-w-fit">
|
|
47
|
-
<DialogHeader>
|
|
48
|
-
<DialogTitle className="text-center text-2xl font-bold">
|
|
49
|
-
Would you like to use a starter project?
|
|
50
|
-
</DialogTitle>
|
|
51
|
-
</DialogHeader>
|
|
52
|
-
<div>
|
|
53
|
-
<StartersCarousel onImport={onImport} />
|
|
54
|
-
</div>
|
|
55
|
-
<DialogFooter className="flex sm:justify-between w-full">
|
|
56
|
-
<div className="flex items-center gap-2">
|
|
57
|
-
<Switch
|
|
58
|
-
id="show-startup-dialog"
|
|
59
|
-
checked={dontShowAgain}
|
|
60
|
-
onCheckedChange={setDontShowAgain}
|
|
61
|
-
/>
|
|
62
|
-
<Label htmlFor="show-startup-dialog">Don't show this again</Label>
|
|
63
|
-
</div>
|
|
64
|
-
<Button onClick={() => setOpen(false)}>
|
|
65
|
-
No, I want to start from scratch
|
|
66
|
-
</Button>
|
|
67
|
-
</DialogFooter>
|
|
68
|
-
</DialogContent>
|
|
69
|
-
</Dialog>
|
|
70
|
-
)
|
|
71
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { useTheme } from 'next-themes'
|
|
2
|
-
import { Toaster as Sonner } from 'sonner'
|
|
3
|
-
|
|
4
|
-
type ToasterProps = React.ComponentProps<typeof Sonner>
|
|
5
|
-
|
|
6
|
-
const Toaster = ({ ...props }: ToasterProps) => {
|
|
7
|
-
const { theme = 'system' } = useTheme()
|
|
8
|
-
|
|
9
|
-
return (
|
|
10
|
-
<Sonner
|
|
11
|
-
theme={theme as ToasterProps['theme']}
|
|
12
|
-
className="toaster group"
|
|
13
|
-
toastOptions={{
|
|
14
|
-
classNames: {
|
|
15
|
-
toast:
|
|
16
|
-
'group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg',
|
|
17
|
-
description: 'group-[.toast]:text-muted-foreground',
|
|
18
|
-
actionButton:
|
|
19
|
-
'group-[.toast]:bg-primary group-[.toast]:text-primary-foreground',
|
|
20
|
-
cancelButton:
|
|
21
|
-
'group-[.toast]:bg-muted group-[.toast]:text-muted-foreground',
|
|
22
|
-
},
|
|
23
|
-
}}
|
|
24
|
-
{...props}
|
|
25
|
-
/>
|
|
26
|
-
)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { Toaster }
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import * as React from 'react'
|
|
2
|
-
import { Slot } from '@radix-ui/react-slot'
|
|
3
|
-
import { cva } from 'class-variance-authority'
|
|
4
|
-
|
|
5
|
-
import type { VariantProps } from 'class-variance-authority'
|
|
6
|
-
|
|
7
|
-
import { cn } from '@/lib/utils'
|
|
8
|
-
|
|
9
|
-
const buttonVariants = cva(
|
|
10
|
-
"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",
|
|
11
|
-
{
|
|
12
|
-
variants: {
|
|
13
|
-
variant: {
|
|
14
|
-
default:
|
|
15
|
-
'bg-primary text-primary-foreground shadow-xs hover:bg-primary/90',
|
|
16
|
-
destructive:
|
|
17
|
-
'bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60',
|
|
18
|
-
outline:
|
|
19
|
-
'border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50',
|
|
20
|
-
secondary:
|
|
21
|
-
'bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80',
|
|
22
|
-
ghost:
|
|
23
|
-
'hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50',
|
|
24
|
-
link: 'text-primary underline-offset-4 hover:underline',
|
|
25
|
-
},
|
|
26
|
-
size: {
|
|
27
|
-
default: 'h-9 px-4 py-2 has-[>svg]:px-3',
|
|
28
|
-
sm: 'h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5',
|
|
29
|
-
lg: 'h-10 rounded-md px-6 has-[>svg]:px-4',
|
|
30
|
-
icon: 'size-9',
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
defaultVariants: {
|
|
34
|
-
variant: 'default',
|
|
35
|
-
size: 'default',
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
function Button({
|
|
41
|
-
className,
|
|
42
|
-
variant,
|
|
43
|
-
size,
|
|
44
|
-
asChild = false,
|
|
45
|
-
...props
|
|
46
|
-
}: React.ComponentProps<'button'> &
|
|
47
|
-
VariantProps<typeof buttonVariants> & {
|
|
48
|
-
asChild?: boolean
|
|
49
|
-
}) {
|
|
50
|
-
const Comp = asChild ? Slot : 'button'
|
|
51
|
-
|
|
52
|
-
return (
|
|
53
|
-
<Comp
|
|
54
|
-
data-slot="button"
|
|
55
|
-
className={cn(buttonVariants({ variant, size, className }))}
|
|
56
|
-
{...props}
|
|
57
|
-
/>
|
|
58
|
-
)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export { Button, buttonVariants }
|
|
@@ -1,239 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import * as React from "react"
|
|
2
|
-
import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
|
|
3
|
-
import { CheckIcon } from "lucide-react"
|
|
4
|
-
|
|
5
|
-
import { cn } from "@/lib/utils"
|
|
6
|
-
|
|
7
|
-
function Checkbox({
|
|
8
|
-
className,
|
|
9
|
-
...props
|
|
10
|
-
}: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
|
|
11
|
-
return (
|
|
12
|
-
<CheckboxPrimitive.Root
|
|
13
|
-
data-slot="checkbox"
|
|
14
|
-
className={cn(
|
|
15
|
-
"peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
|
|
16
|
-
className
|
|
17
|
-
)}
|
|
18
|
-
{...props}
|
|
19
|
-
>
|
|
20
|
-
<CheckboxPrimitive.Indicator
|
|
21
|
-
data-slot="checkbox-indicator"
|
|
22
|
-
className="flex items-center justify-center text-current transition-none"
|
|
23
|
-
>
|
|
24
|
-
<CheckIcon className="size-3.5" />
|
|
25
|
-
</CheckboxPrimitive.Indicator>
|
|
26
|
-
</CheckboxPrimitive.Root>
|
|
27
|
-
)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export { Checkbox }
|