@tapcart/mobile-components 0.1.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/LICENSE.md +26 -0
- package/components/ThemeProvider.tsx +9 -0
- package/components/ThemeToggle.tsx +22 -0
- package/components/ui/accordion.tsx +58 -0
- package/components/ui/alert-dialog.tsx +141 -0
- package/components/ui/aspect-ratio.tsx +7 -0
- package/components/ui/badge.tsx +36 -0
- package/components/ui/button.tsx +69 -0
- package/components/ui/carousel.tsx +262 -0
- package/components/ui/container.tsx +24 -0
- package/components/ui/grid.tsx +38 -0
- package/components/ui/icon.tsx +25 -0
- package/components/ui/input.tsx +25 -0
- package/components/ui/label.tsx +26 -0
- package/components/ui/money.tsx +32 -0
- package/components/ui/scroll-area.tsx +54 -0
- package/components/ui/separator.tsx +31 -0
- package/components/ui/skeleton.tsx +15 -0
- package/components/ui/switch.tsx +29 -0
- package/components/ui/text.tsx +28 -0
- package/components/ui/toast.tsx +129 -0
- package/components/ui/toaster.tsx +35 -0
- package/components/ui/toggle-group.tsx +61 -0
- package/components/ui/toggle.tsx +45 -0
- package/components/ui/use-toast.ts +191 -0
- package/components/ui/video.tsx +27 -0
- package/components.json +14 -0
- package/index.tsx +28 -0
- package/lib/utils.ts +6 -0
- package/package.json +47 -0
- package/postcss.config.js +6 -0
- package/styles/globals.css +146 -0
- package/tailwind.config.js +141 -0
- package/tsconfig.json +13 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Copyright (c) 2017-present Tapcart Inc.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
The rights granted above may only be exercised to develop and distribute
|
|
14
|
+
applications that integrate or interoperate with Tapcart software or services,
|
|
15
|
+
and in the case of external, stand-alone applications that do not embed
|
|
16
|
+
directly inside Tapcart, the rights granted above may only be exercised to
|
|
17
|
+
develop and distribute applications that are dissimilar and visually distinct
|
|
18
|
+
from Tapcart products and services, as determined by Tapcart in its sole discretion.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { ThemeProvider as NextThemesProvider } from "next-themes"
|
|
5
|
+
import { ThemeProviderProps } from "next-themes/dist/types"
|
|
6
|
+
|
|
7
|
+
export function ThemeProvider({ children, ...props }: ThemeProviderProps) {
|
|
8
|
+
return <NextThemesProvider {...props}>{children}</NextThemesProvider>
|
|
9
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { useTheme } from "next-themes"
|
|
5
|
+
|
|
6
|
+
import { Button } from "@/components/ui/button"
|
|
7
|
+
|
|
8
|
+
export function ThemeToggle() {
|
|
9
|
+
const { setTheme, theme } = useTheme()
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<Button
|
|
13
|
+
variant="ghost"
|
|
14
|
+
size="sm"
|
|
15
|
+
onClick={() => setTheme(theme === "light" ? "dark" : "light")}
|
|
16
|
+
>
|
|
17
|
+
<div className="rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
|
|
18
|
+
<div className="absolute rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
|
|
19
|
+
<span className="sr-only">Toggle theme</span>
|
|
20
|
+
</Button>
|
|
21
|
+
)
|
|
22
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import * as AccordionPrimitive from "@radix-ui/react-accordion"
|
|
5
|
+
import { ChevronDown } from "lucide-react"
|
|
6
|
+
|
|
7
|
+
import { cn } from "@/lib/utils"
|
|
8
|
+
|
|
9
|
+
const Accordion = AccordionPrimitive.Root
|
|
10
|
+
|
|
11
|
+
const AccordionItem = React.forwardRef<
|
|
12
|
+
React.ElementRef<typeof AccordionPrimitive.Item>,
|
|
13
|
+
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item>
|
|
14
|
+
>(({ className, ...props }, ref) => (
|
|
15
|
+
<AccordionPrimitive.Item
|
|
16
|
+
ref={ref}
|
|
17
|
+
className={cn("border-b", className)}
|
|
18
|
+
{...props}
|
|
19
|
+
/>
|
|
20
|
+
))
|
|
21
|
+
AccordionItem.displayName = "AccordionItem"
|
|
22
|
+
|
|
23
|
+
const AccordionTrigger = React.forwardRef<
|
|
24
|
+
React.ElementRef<typeof AccordionPrimitive.Trigger>,
|
|
25
|
+
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger>
|
|
26
|
+
>(({ className, children, ...props }, ref) => (
|
|
27
|
+
<AccordionPrimitive.Header className="flex">
|
|
28
|
+
<AccordionPrimitive.Trigger
|
|
29
|
+
ref={ref}
|
|
30
|
+
className={cn(
|
|
31
|
+
"flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180",
|
|
32
|
+
className
|
|
33
|
+
)}
|
|
34
|
+
{...props}
|
|
35
|
+
>
|
|
36
|
+
{children}
|
|
37
|
+
<ChevronDown className="h-4 w-4 shrink-0 transition-transform duration-200" />
|
|
38
|
+
</AccordionPrimitive.Trigger>
|
|
39
|
+
</AccordionPrimitive.Header>
|
|
40
|
+
))
|
|
41
|
+
AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName
|
|
42
|
+
|
|
43
|
+
const AccordionContent = React.forwardRef<
|
|
44
|
+
React.ElementRef<typeof AccordionPrimitive.Content>,
|
|
45
|
+
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Content>
|
|
46
|
+
>(({ className, children, ...props }, ref) => (
|
|
47
|
+
<AccordionPrimitive.Content
|
|
48
|
+
ref={ref}
|
|
49
|
+
className="overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down"
|
|
50
|
+
{...props}
|
|
51
|
+
>
|
|
52
|
+
<div className={cn("pb-4 pt-0", className)}>{children}</div>
|
|
53
|
+
</AccordionPrimitive.Content>
|
|
54
|
+
))
|
|
55
|
+
|
|
56
|
+
AccordionContent.displayName = AccordionPrimitive.Content.displayName
|
|
57
|
+
|
|
58
|
+
export { Accordion, AccordionItem, AccordionTrigger, AccordionContent }
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog"
|
|
5
|
+
|
|
6
|
+
import { cn } from "@/lib/utils"
|
|
7
|
+
import { buttonVariants } from "@/components/ui/button"
|
|
8
|
+
|
|
9
|
+
const AlertDialog = AlertDialogPrimitive.Root
|
|
10
|
+
|
|
11
|
+
const AlertDialogTrigger = AlertDialogPrimitive.Trigger
|
|
12
|
+
|
|
13
|
+
const AlertDialogPortal = AlertDialogPrimitive.Portal
|
|
14
|
+
|
|
15
|
+
const AlertDialogOverlay = React.forwardRef<
|
|
16
|
+
React.ElementRef<typeof AlertDialogPrimitive.Overlay>,
|
|
17
|
+
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay>
|
|
18
|
+
>(({ className, ...props }, ref) => (
|
|
19
|
+
<AlertDialogPrimitive.Overlay
|
|
20
|
+
className={cn(
|
|
21
|
+
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
|
22
|
+
className
|
|
23
|
+
)}
|
|
24
|
+
{...props}
|
|
25
|
+
ref={ref}
|
|
26
|
+
/>
|
|
27
|
+
))
|
|
28
|
+
AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName
|
|
29
|
+
|
|
30
|
+
const AlertDialogContent = React.forwardRef<
|
|
31
|
+
React.ElementRef<typeof AlertDialogPrimitive.Content>,
|
|
32
|
+
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content>
|
|
33
|
+
>(({ className, ...props }, ref) => (
|
|
34
|
+
<AlertDialogPortal>
|
|
35
|
+
<AlertDialogOverlay />
|
|
36
|
+
<AlertDialogPrimitive.Content
|
|
37
|
+
ref={ref}
|
|
38
|
+
className={cn(
|
|
39
|
+
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
|
|
40
|
+
className
|
|
41
|
+
)}
|
|
42
|
+
{...props}
|
|
43
|
+
/>
|
|
44
|
+
</AlertDialogPortal>
|
|
45
|
+
))
|
|
46
|
+
AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName
|
|
47
|
+
|
|
48
|
+
const AlertDialogHeader = ({
|
|
49
|
+
className,
|
|
50
|
+
...props
|
|
51
|
+
}: React.HTMLAttributes<HTMLDivElement>) => (
|
|
52
|
+
<div
|
|
53
|
+
className={cn(
|
|
54
|
+
"flex flex-col space-y-2 text-center sm:text-left",
|
|
55
|
+
className
|
|
56
|
+
)}
|
|
57
|
+
{...props}
|
|
58
|
+
/>
|
|
59
|
+
)
|
|
60
|
+
AlertDialogHeader.displayName = "AlertDialogHeader"
|
|
61
|
+
|
|
62
|
+
const AlertDialogFooter = ({
|
|
63
|
+
className,
|
|
64
|
+
...props
|
|
65
|
+
}: React.HTMLAttributes<HTMLDivElement>) => (
|
|
66
|
+
<div
|
|
67
|
+
className={cn(
|
|
68
|
+
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
|
|
69
|
+
className
|
|
70
|
+
)}
|
|
71
|
+
{...props}
|
|
72
|
+
/>
|
|
73
|
+
)
|
|
74
|
+
AlertDialogFooter.displayName = "AlertDialogFooter"
|
|
75
|
+
|
|
76
|
+
const AlertDialogTitle = React.forwardRef<
|
|
77
|
+
React.ElementRef<typeof AlertDialogPrimitive.Title>,
|
|
78
|
+
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Title>
|
|
79
|
+
>(({ className, ...props }, ref) => (
|
|
80
|
+
<AlertDialogPrimitive.Title
|
|
81
|
+
ref={ref}
|
|
82
|
+
className={cn("text-lg font-semibold", className)}
|
|
83
|
+
{...props}
|
|
84
|
+
/>
|
|
85
|
+
))
|
|
86
|
+
AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName
|
|
87
|
+
|
|
88
|
+
const AlertDialogDescription = React.forwardRef<
|
|
89
|
+
React.ElementRef<typeof AlertDialogPrimitive.Description>,
|
|
90
|
+
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Description>
|
|
91
|
+
>(({ className, ...props }, ref) => (
|
|
92
|
+
<AlertDialogPrimitive.Description
|
|
93
|
+
ref={ref}
|
|
94
|
+
className={cn("text-sm text-muted-foreground", className)}
|
|
95
|
+
{...props}
|
|
96
|
+
/>
|
|
97
|
+
))
|
|
98
|
+
AlertDialogDescription.displayName =
|
|
99
|
+
AlertDialogPrimitive.Description.displayName
|
|
100
|
+
|
|
101
|
+
const AlertDialogAction = React.forwardRef<
|
|
102
|
+
React.ElementRef<typeof AlertDialogPrimitive.Action>,
|
|
103
|
+
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action>
|
|
104
|
+
>(({ className, ...props }, ref) => (
|
|
105
|
+
<AlertDialogPrimitive.Action
|
|
106
|
+
ref={ref}
|
|
107
|
+
className={cn(buttonVariants(), className)}
|
|
108
|
+
{...props}
|
|
109
|
+
/>
|
|
110
|
+
))
|
|
111
|
+
AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName
|
|
112
|
+
|
|
113
|
+
const AlertDialogCancel = React.forwardRef<
|
|
114
|
+
React.ElementRef<typeof AlertDialogPrimitive.Cancel>,
|
|
115
|
+
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel>
|
|
116
|
+
>(({ className, ...props }, ref) => (
|
|
117
|
+
<AlertDialogPrimitive.Cancel
|
|
118
|
+
ref={ref}
|
|
119
|
+
className={cn(
|
|
120
|
+
buttonVariants({ variant: "outline" }),
|
|
121
|
+
"mt-2 sm:mt-0",
|
|
122
|
+
className
|
|
123
|
+
)}
|
|
124
|
+
{...props}
|
|
125
|
+
/>
|
|
126
|
+
))
|
|
127
|
+
AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName
|
|
128
|
+
|
|
129
|
+
export {
|
|
130
|
+
AlertDialog,
|
|
131
|
+
AlertDialogPortal,
|
|
132
|
+
AlertDialogOverlay,
|
|
133
|
+
AlertDialogTrigger,
|
|
134
|
+
AlertDialogContent,
|
|
135
|
+
AlertDialogHeader,
|
|
136
|
+
AlertDialogFooter,
|
|
137
|
+
AlertDialogTitle,
|
|
138
|
+
AlertDialogDescription,
|
|
139
|
+
AlertDialogAction,
|
|
140
|
+
AlertDialogCancel,
|
|
141
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
3
|
+
|
|
4
|
+
import { cn } from "@/lib/utils"
|
|
5
|
+
|
|
6
|
+
const badgeVariants = cva(
|
|
7
|
+
"inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
|
|
8
|
+
{
|
|
9
|
+
variants: {
|
|
10
|
+
variant: {
|
|
11
|
+
default:
|
|
12
|
+
"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",
|
|
13
|
+
secondary:
|
|
14
|
+
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
15
|
+
destructive:
|
|
16
|
+
"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",
|
|
17
|
+
outline: "text-foreground",
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
defaultVariants: {
|
|
21
|
+
variant: "default",
|
|
22
|
+
},
|
|
23
|
+
}
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
export interface BadgeProps
|
|
27
|
+
extends React.HTMLAttributes<HTMLDivElement>,
|
|
28
|
+
VariantProps<typeof badgeVariants> {}
|
|
29
|
+
|
|
30
|
+
function Badge({ className, variant, ...props }: BadgeProps) {
|
|
31
|
+
return (
|
|
32
|
+
<div className={cn(badgeVariants({ variant }), className)} {...props} />
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { Badge, badgeVariants }
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { Slot } from "@radix-ui/react-slot"
|
|
3
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
4
|
+
import { IconLoader2 } from "@tabler/icons-react"
|
|
5
|
+
|
|
6
|
+
import { cn } from "@/lib/utils"
|
|
7
|
+
|
|
8
|
+
const buttonVariants = cva(
|
|
9
|
+
"flex rounded items-center justify-center text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:bg-stateColors-disabled disabled:pointer-events-none ring-offset-background overflow-elipse whitespace-nowrap truncate",
|
|
10
|
+
{
|
|
11
|
+
variants: {
|
|
12
|
+
size: {
|
|
13
|
+
default: "h-10 py-3 px-4",
|
|
14
|
+
sm: "h-9 px-3 rounded-md",
|
|
15
|
+
lg: "h-11 px-8 rounded-md",
|
|
16
|
+
icon: "h-10 w-10",
|
|
17
|
+
content: "h-10 py-3 px-4 w-auto",
|
|
18
|
+
},
|
|
19
|
+
variant: {
|
|
20
|
+
default:
|
|
21
|
+
"bg-buttonColors-primaryFill text-buttonColors-primaryText active:opacity-70",
|
|
22
|
+
destructive:
|
|
23
|
+
"bg-stateColors-error text-coreColors-pageColor active:opacity-70 disabled:bg-stateColors-disabled",
|
|
24
|
+
outline:
|
|
25
|
+
"border border-input hover:bg-accent hover:text-accent-foreground",
|
|
26
|
+
secondary:
|
|
27
|
+
"border bg-buttonColors-secondaryFill text-buttonColors-secondaryText border-buttonColors-secondaryOutline active:opacity-70 disabled:bg-buttonColors-secondaryFill disabled:text-stateColors-disabled disabled:border-stateColors-disabled",
|
|
28
|
+
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
29
|
+
link: "underline-offset-4 hover:underline text-primary",
|
|
30
|
+
quickadd:
|
|
31
|
+
"bg-buttonColors-primaryFill text-buttonColors-primaryText active:opacity-70 w-full rounded-none rounded-b-lg h-8 text-xs",
|
|
32
|
+
applePay: "bg-white text-black border border-black",
|
|
33
|
+
shopPay: "bg-[#612EFF]",
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
defaultVariants: {
|
|
37
|
+
variant: "default",
|
|
38
|
+
size: "default",
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
export interface ButtonProps
|
|
44
|
+
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
45
|
+
VariantProps<typeof buttonVariants> {
|
|
46
|
+
asChild?: boolean
|
|
47
|
+
loading?: boolean
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
51
|
+
({ className, variant, size, asChild = false, loading, ...props }, ref) => {
|
|
52
|
+
const Comp = asChild ? Slot : "button"
|
|
53
|
+
return (
|
|
54
|
+
<Comp
|
|
55
|
+
className={cn(buttonVariants({ variant, size, className }), {
|
|
56
|
+
"pointer-events-none": loading,
|
|
57
|
+
})}
|
|
58
|
+
ref={ref}
|
|
59
|
+
{...props}
|
|
60
|
+
>
|
|
61
|
+
{!loading && props.children}
|
|
62
|
+
{loading && <IconLoader2 className="h-4 w-4 animate-spin" />}
|
|
63
|
+
</Comp>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
Button.displayName = "Button"
|
|
68
|
+
|
|
69
|
+
export { Button, buttonVariants }
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import useEmblaCarousel, {
|
|
5
|
+
type UseEmblaCarouselType,
|
|
6
|
+
} from "embla-carousel-react"
|
|
7
|
+
import { ArrowLeft, ArrowRight } from "lucide-react"
|
|
8
|
+
|
|
9
|
+
import { cn } from "@/lib/utils"
|
|
10
|
+
import { Button } from "@/components/ui/button"
|
|
11
|
+
|
|
12
|
+
type CarouselApi = UseEmblaCarouselType[1]
|
|
13
|
+
type UseCarouselParameters = Parameters<typeof useEmblaCarousel>
|
|
14
|
+
type CarouselOptions = UseCarouselParameters[0]
|
|
15
|
+
type CarouselPlugin = UseCarouselParameters[1]
|
|
16
|
+
|
|
17
|
+
type CarouselProps = {
|
|
18
|
+
opts?: CarouselOptions
|
|
19
|
+
plugins?: CarouselPlugin
|
|
20
|
+
orientation?: "horizontal" | "vertical"
|
|
21
|
+
setApi?: (api: CarouselApi) => void
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type CarouselContextProps = {
|
|
25
|
+
carouselRef: ReturnType<typeof useEmblaCarousel>[0]
|
|
26
|
+
api: ReturnType<typeof useEmblaCarousel>[1]
|
|
27
|
+
scrollPrev: () => void
|
|
28
|
+
scrollNext: () => void
|
|
29
|
+
canScrollPrev: boolean
|
|
30
|
+
canScrollNext: boolean
|
|
31
|
+
} & CarouselProps
|
|
32
|
+
|
|
33
|
+
const CarouselContext = React.createContext<CarouselContextProps | null>(null)
|
|
34
|
+
|
|
35
|
+
function useCarousel() {
|
|
36
|
+
const context = React.useContext(CarouselContext)
|
|
37
|
+
|
|
38
|
+
if (!context) {
|
|
39
|
+
throw new Error("useCarousel must be used within a <Carousel />")
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return context
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const Carousel = React.forwardRef<
|
|
46
|
+
HTMLDivElement,
|
|
47
|
+
React.HTMLAttributes<HTMLDivElement> & CarouselProps
|
|
48
|
+
>(
|
|
49
|
+
(
|
|
50
|
+
{
|
|
51
|
+
orientation = "horizontal",
|
|
52
|
+
opts,
|
|
53
|
+
setApi,
|
|
54
|
+
plugins,
|
|
55
|
+
className,
|
|
56
|
+
children,
|
|
57
|
+
...props
|
|
58
|
+
},
|
|
59
|
+
ref
|
|
60
|
+
) => {
|
|
61
|
+
const [carouselRef, api] = useEmblaCarousel(
|
|
62
|
+
{
|
|
63
|
+
...opts,
|
|
64
|
+
axis: orientation === "horizontal" ? "x" : "y",
|
|
65
|
+
},
|
|
66
|
+
plugins
|
|
67
|
+
)
|
|
68
|
+
const [canScrollPrev, setCanScrollPrev] = React.useState(false)
|
|
69
|
+
const [canScrollNext, setCanScrollNext] = React.useState(false)
|
|
70
|
+
|
|
71
|
+
const onSelect = React.useCallback((api: CarouselApi) => {
|
|
72
|
+
if (!api) {
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
setCanScrollPrev(api.canScrollPrev())
|
|
77
|
+
setCanScrollNext(api.canScrollNext())
|
|
78
|
+
}, [])
|
|
79
|
+
|
|
80
|
+
const scrollPrev = React.useCallback(() => {
|
|
81
|
+
api?.scrollPrev()
|
|
82
|
+
}, [api])
|
|
83
|
+
|
|
84
|
+
const scrollNext = React.useCallback(() => {
|
|
85
|
+
api?.scrollNext()
|
|
86
|
+
}, [api])
|
|
87
|
+
|
|
88
|
+
const handleKeyDown = React.useCallback(
|
|
89
|
+
(event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
90
|
+
if (event.key === "ArrowLeft") {
|
|
91
|
+
event.preventDefault()
|
|
92
|
+
scrollPrev()
|
|
93
|
+
} else if (event.key === "ArrowRight") {
|
|
94
|
+
event.preventDefault()
|
|
95
|
+
scrollNext()
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
[scrollPrev, scrollNext]
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
React.useEffect(() => {
|
|
102
|
+
if (!api || !setApi) {
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
setApi(api)
|
|
107
|
+
}, [api, setApi])
|
|
108
|
+
|
|
109
|
+
React.useEffect(() => {
|
|
110
|
+
if (!api) {
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
onSelect(api)
|
|
115
|
+
api.on("reInit", onSelect)
|
|
116
|
+
api.on("select", onSelect)
|
|
117
|
+
|
|
118
|
+
return () => {
|
|
119
|
+
api?.off("select", onSelect)
|
|
120
|
+
}
|
|
121
|
+
}, [api, onSelect])
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<CarouselContext.Provider
|
|
125
|
+
value={{
|
|
126
|
+
carouselRef,
|
|
127
|
+
api: api,
|
|
128
|
+
opts,
|
|
129
|
+
orientation:
|
|
130
|
+
orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
|
|
131
|
+
scrollPrev,
|
|
132
|
+
scrollNext,
|
|
133
|
+
canScrollPrev,
|
|
134
|
+
canScrollNext,
|
|
135
|
+
}}
|
|
136
|
+
>
|
|
137
|
+
<div
|
|
138
|
+
ref={ref}
|
|
139
|
+
onKeyDownCapture={handleKeyDown}
|
|
140
|
+
className={cn("relative", className)}
|
|
141
|
+
role="region"
|
|
142
|
+
aria-roledescription="carousel"
|
|
143
|
+
{...props}
|
|
144
|
+
>
|
|
145
|
+
{children}
|
|
146
|
+
</div>
|
|
147
|
+
</CarouselContext.Provider>
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
)
|
|
151
|
+
Carousel.displayName = "Carousel"
|
|
152
|
+
|
|
153
|
+
const CarouselContent = React.forwardRef<
|
|
154
|
+
HTMLDivElement,
|
|
155
|
+
React.HTMLAttributes<HTMLDivElement>
|
|
156
|
+
>(({ className, ...props }, ref) => {
|
|
157
|
+
const { carouselRef, orientation } = useCarousel()
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<div ref={carouselRef} className="overflow-hidden">
|
|
161
|
+
<div
|
|
162
|
+
ref={ref}
|
|
163
|
+
className={cn(
|
|
164
|
+
"flex",
|
|
165
|
+
orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col",
|
|
166
|
+
className
|
|
167
|
+
)}
|
|
168
|
+
{...props}
|
|
169
|
+
/>
|
|
170
|
+
</div>
|
|
171
|
+
)
|
|
172
|
+
})
|
|
173
|
+
CarouselContent.displayName = "CarouselContent"
|
|
174
|
+
|
|
175
|
+
const CarouselItem = React.forwardRef<
|
|
176
|
+
HTMLDivElement,
|
|
177
|
+
React.HTMLAttributes<HTMLDivElement>
|
|
178
|
+
>(({ className, ...props }, ref) => {
|
|
179
|
+
const { orientation } = useCarousel()
|
|
180
|
+
|
|
181
|
+
return (
|
|
182
|
+
<div
|
|
183
|
+
ref={ref}
|
|
184
|
+
role="group"
|
|
185
|
+
aria-roledescription="slide"
|
|
186
|
+
className={cn(
|
|
187
|
+
"min-w-0 shrink-0 grow-0 basis-full",
|
|
188
|
+
orientation === "horizontal" ? "pl-4" : "pt-4",
|
|
189
|
+
className
|
|
190
|
+
)}
|
|
191
|
+
{...props}
|
|
192
|
+
/>
|
|
193
|
+
)
|
|
194
|
+
})
|
|
195
|
+
CarouselItem.displayName = "CarouselItem"
|
|
196
|
+
|
|
197
|
+
const CarouselPrevious = React.forwardRef<
|
|
198
|
+
HTMLButtonElement,
|
|
199
|
+
React.ComponentProps<typeof Button>
|
|
200
|
+
>(({ className, variant = "outline", size = "icon", ...props }, ref) => {
|
|
201
|
+
const { orientation, scrollPrev, canScrollPrev } = useCarousel()
|
|
202
|
+
|
|
203
|
+
return (
|
|
204
|
+
<Button
|
|
205
|
+
ref={ref}
|
|
206
|
+
variant={variant}
|
|
207
|
+
size={size}
|
|
208
|
+
className={cn(
|
|
209
|
+
"absolute h-8 w-8 rounded-full",
|
|
210
|
+
orientation === "horizontal"
|
|
211
|
+
? "-left-12 top-1/2 -translate-y-1/2"
|
|
212
|
+
: "-top-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
213
|
+
className
|
|
214
|
+
)}
|
|
215
|
+
disabled={!canScrollPrev}
|
|
216
|
+
onClick={scrollPrev}
|
|
217
|
+
{...props}
|
|
218
|
+
>
|
|
219
|
+
<ArrowLeft className="h-4 w-4" />
|
|
220
|
+
<span className="sr-only">Previous slide</span>
|
|
221
|
+
</Button>
|
|
222
|
+
)
|
|
223
|
+
})
|
|
224
|
+
CarouselPrevious.displayName = "CarouselPrevious"
|
|
225
|
+
|
|
226
|
+
const CarouselNext = React.forwardRef<
|
|
227
|
+
HTMLButtonElement,
|
|
228
|
+
React.ComponentProps<typeof Button>
|
|
229
|
+
>(({ className, variant = "outline", size = "icon", ...props }, ref) => {
|
|
230
|
+
const { orientation, scrollNext, canScrollNext } = useCarousel()
|
|
231
|
+
|
|
232
|
+
return (
|
|
233
|
+
<Button
|
|
234
|
+
ref={ref}
|
|
235
|
+
variant={variant}
|
|
236
|
+
size={size}
|
|
237
|
+
className={cn(
|
|
238
|
+
"absolute h-8 w-8 rounded-full",
|
|
239
|
+
orientation === "horizontal"
|
|
240
|
+
? "-right-12 top-1/2 -translate-y-1/2"
|
|
241
|
+
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
242
|
+
className
|
|
243
|
+
)}
|
|
244
|
+
disabled={!canScrollNext}
|
|
245
|
+
onClick={scrollNext}
|
|
246
|
+
{...props}
|
|
247
|
+
>
|
|
248
|
+
<ArrowRight className="h-4 w-4" />
|
|
249
|
+
<span className="sr-only">Next slide</span>
|
|
250
|
+
</Button>
|
|
251
|
+
)
|
|
252
|
+
})
|
|
253
|
+
CarouselNext.displayName = "CarouselNext"
|
|
254
|
+
|
|
255
|
+
export {
|
|
256
|
+
type CarouselApi,
|
|
257
|
+
Carousel,
|
|
258
|
+
CarouselContent,
|
|
259
|
+
CarouselItem,
|
|
260
|
+
CarouselPrevious,
|
|
261
|
+
CarouselNext,
|
|
262
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
3
|
+
|
|
4
|
+
import { cn } from "@/lib/utils"
|
|
5
|
+
|
|
6
|
+
const containerVariants = cva("container", {
|
|
7
|
+
variants: {
|
|
8
|
+
variant: {
|
|
9
|
+
spaced: "my-3",
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
export interface ContainerProps
|
|
15
|
+
extends React.HTMLAttributes<HTMLDivElement>,
|
|
16
|
+
VariantProps<typeof containerVariants> {}
|
|
17
|
+
|
|
18
|
+
function Container({ className, variant, ...props }: ContainerProps) {
|
|
19
|
+
return (
|
|
20
|
+
<div className={cn(containerVariants({ variant }), className)} {...props} />
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { Container, containerVariants }
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
3
|
+
import { Container } from "./container"
|
|
4
|
+
|
|
5
|
+
import { cn } from "@/lib/utils"
|
|
6
|
+
|
|
7
|
+
interface GridType {
|
|
8
|
+
className: any
|
|
9
|
+
children: React.ReactNode
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const gridVariants = cva("grid", {
|
|
13
|
+
variants: {
|
|
14
|
+
columns: {
|
|
15
|
+
1: "grid-cols-1 gap-y-[7px]",
|
|
16
|
+
2: "grid-cols-2 gap-x-[7px] gap-y-[7px]",
|
|
17
|
+
3: "grid-cols-3 gap-x-[7px] gap-y-[7px]",
|
|
18
|
+
4: "grid-cols-4 gap-x-[7px] gap-y-[7px]",
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
defaultVariants: {
|
|
22
|
+
columns: 2,
|
|
23
|
+
},
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
export interface GridProps
|
|
27
|
+
extends GridType,
|
|
28
|
+
VariantProps<typeof gridVariants> {}
|
|
29
|
+
|
|
30
|
+
function Grid({ className, columns, ...props }: GridProps) {
|
|
31
|
+
return (
|
|
32
|
+
<Container>
|
|
33
|
+
<div className={cn(gridVariants({ columns }), className)} {...props} />
|
|
34
|
+
</Container>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { Grid, gridVariants }
|