@djangocfg/ui-core 1.0.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/README.md +135 -0
- package/package.json +111 -0
- package/src/components/accordion.tsx +56 -0
- package/src/components/alert-dialog.tsx +142 -0
- package/src/components/alert.tsx +59 -0
- package/src/components/aspect-ratio.tsx +7 -0
- package/src/components/avatar.tsx +50 -0
- package/src/components/badge.tsx +36 -0
- package/src/components/button-group.tsx +85 -0
- package/src/components/button.tsx +111 -0
- package/src/components/calendar.tsx +213 -0
- package/src/components/card.tsx +76 -0
- package/src/components/carousel.tsx +261 -0
- package/src/components/chart.tsx +369 -0
- package/src/components/checkbox.tsx +29 -0
- package/src/components/collapsible.tsx +11 -0
- package/src/components/combobox.tsx +182 -0
- package/src/components/command.tsx +170 -0
- package/src/components/context-menu.tsx +200 -0
- package/src/components/copy.tsx +144 -0
- package/src/components/dialog.tsx +122 -0
- package/src/components/drawer.tsx +137 -0
- package/src/components/empty.tsx +104 -0
- package/src/components/field.tsx +244 -0
- package/src/components/form.tsx +178 -0
- package/src/components/hover-card.tsx +29 -0
- package/src/components/image-with-fallback.tsx +170 -0
- package/src/components/index.ts +86 -0
- package/src/components/input-group.tsx +170 -0
- package/src/components/input-otp.tsx +81 -0
- package/src/components/input.tsx +22 -0
- package/src/components/item.tsx +195 -0
- package/src/components/kbd.tsx +28 -0
- package/src/components/label.tsx +26 -0
- package/src/components/multi-select.tsx +222 -0
- package/src/components/og-image.tsx +47 -0
- package/src/components/popover.tsx +33 -0
- package/src/components/portal.tsx +106 -0
- package/src/components/preloader.tsx +250 -0
- package/src/components/progress.tsx +28 -0
- package/src/components/radio-group.tsx +43 -0
- package/src/components/resizable.tsx +111 -0
- package/src/components/scroll-area.tsx +102 -0
- package/src/components/section.tsx +58 -0
- package/src/components/select.tsx +158 -0
- package/src/components/separator.tsx +31 -0
- package/src/components/sheet.tsx +140 -0
- package/src/components/skeleton.tsx +15 -0
- package/src/components/slider.tsx +28 -0
- package/src/components/spinner.tsx +16 -0
- package/src/components/sticky.tsx +117 -0
- package/src/components/switch.tsx +29 -0
- package/src/components/table.tsx +120 -0
- package/src/components/tabs.tsx +238 -0
- package/src/components/textarea.tsx +22 -0
- package/src/components/toast.tsx +129 -0
- package/src/components/toaster.tsx +41 -0
- package/src/components/toggle-group.tsx +61 -0
- package/src/components/toggle.tsx +45 -0
- package/src/components/token-icon.tsx +156 -0
- package/src/components/tooltip-provider-safe.tsx +43 -0
- package/src/components/tooltip.tsx +32 -0
- package/src/hooks/index.ts +15 -0
- package/src/hooks/useCopy.ts +41 -0
- package/src/hooks/useCountdown.ts +73 -0
- package/src/hooks/useDebounce.ts +25 -0
- package/src/hooks/useDebouncedCallback.ts +58 -0
- package/src/hooks/useDebugTools.ts +52 -0
- package/src/hooks/useEventsBus.ts +53 -0
- package/src/hooks/useImageLoader.ts +95 -0
- package/src/hooks/useMediaQuery.ts +40 -0
- package/src/hooks/useMobile.tsx +22 -0
- package/src/hooks/useToast.ts +194 -0
- package/src/index.ts +14 -0
- package/src/lib/index.ts +2 -0
- package/src/lib/og-image.ts +151 -0
- package/src/lib/utils.ts +6 -0
- package/src/styles/base.css +20 -0
- package/src/styles/globals.css +12 -0
- package/src/styles/index.css +25 -0
- package/src/styles/sources.css +11 -0
- package/src/styles/theme/animations.css +65 -0
- package/src/styles/theme/dark.css +49 -0
- package/src/styles/theme/light.css +50 -0
- package/src/styles/theme/tokens.css +134 -0
- package/src/styles/theme.css +22 -0
- package/src/styles/utilities.css +187 -0
- package/src/types/index.ts +0 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { Drawer as DrawerPrimitive } from "vaul"
|
|
5
|
+
|
|
6
|
+
import { cn } from "../lib/utils"
|
|
7
|
+
|
|
8
|
+
const Drawer = ({
|
|
9
|
+
shouldScaleBackground = true,
|
|
10
|
+
direction,
|
|
11
|
+
...props
|
|
12
|
+
}: React.ComponentProps<typeof DrawerPrimitive.Root> & { direction?: 'bottom' | 'right' | 'left' | 'top' }) => (
|
|
13
|
+
<DrawerPrimitive.Root
|
|
14
|
+
shouldScaleBackground={shouldScaleBackground}
|
|
15
|
+
direction={direction}
|
|
16
|
+
{...props}
|
|
17
|
+
/>
|
|
18
|
+
)
|
|
19
|
+
Drawer.displayName = "Drawer"
|
|
20
|
+
|
|
21
|
+
const DrawerTrigger = DrawerPrimitive.Trigger
|
|
22
|
+
|
|
23
|
+
const DrawerPortal = DrawerPrimitive.Portal
|
|
24
|
+
|
|
25
|
+
const DrawerClose = DrawerPrimitive.Close
|
|
26
|
+
|
|
27
|
+
const DrawerOverlay = React.forwardRef<
|
|
28
|
+
React.ElementRef<typeof DrawerPrimitive.Overlay>,
|
|
29
|
+
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Overlay>
|
|
30
|
+
>(({ className, style, ...props }, ref) => (
|
|
31
|
+
<DrawerPrimitive.Overlay
|
|
32
|
+
ref={ref}
|
|
33
|
+
className={cn("fixed inset-0 z-500 transition-opacity duration-200", className)}
|
|
34
|
+
style={{ backgroundColor: 'rgb(0 0 0 / 0.8)', ...style }}
|
|
35
|
+
{...props}
|
|
36
|
+
/>
|
|
37
|
+
))
|
|
38
|
+
DrawerOverlay.displayName = DrawerPrimitive.Overlay.displayName
|
|
39
|
+
|
|
40
|
+
const directionStyles = {
|
|
41
|
+
bottom: "inset-x-0 bottom-0 mt-24 h-auto rounded-t-lg border-t",
|
|
42
|
+
top: "inset-x-0 top-0 mb-24 h-auto rounded-b-lg border-b",
|
|
43
|
+
right: "inset-y-0 right-0 h-full w-[280px] border-l",
|
|
44
|
+
left: "inset-y-0 left-0 h-full w-[280px] border-r",
|
|
45
|
+
} as const;
|
|
46
|
+
|
|
47
|
+
const DrawerContent = React.forwardRef<
|
|
48
|
+
React.ElementRef<typeof DrawerPrimitive.Content>,
|
|
49
|
+
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Content> & { direction?: 'bottom' | 'right' | 'left' | 'top' }
|
|
50
|
+
>(({ className, children, direction = 'bottom', style, ...props }, ref) => {
|
|
51
|
+
const isVertical = direction === 'bottom' || direction === 'top';
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<DrawerPortal>
|
|
55
|
+
<DrawerOverlay />
|
|
56
|
+
<DrawerPrimitive.Content
|
|
57
|
+
ref={ref}
|
|
58
|
+
className={cn(
|
|
59
|
+
"fixed z-500 flex flex-col bg-background",
|
|
60
|
+
directionStyles[direction],
|
|
61
|
+
className
|
|
62
|
+
)}
|
|
63
|
+
style={{
|
|
64
|
+
transition: 'transform 300ms cubic-bezier(0.32, 0.72, 0, 1)',
|
|
65
|
+
...style,
|
|
66
|
+
}}
|
|
67
|
+
{...props}
|
|
68
|
+
>
|
|
69
|
+
{isVertical && <div className="mx-auto mt-4 h-2 w-[100px] rounded-full bg-muted" />}
|
|
70
|
+
{children}
|
|
71
|
+
</DrawerPrimitive.Content>
|
|
72
|
+
</DrawerPortal>
|
|
73
|
+
);
|
|
74
|
+
})
|
|
75
|
+
DrawerContent.displayName = "DrawerContent"
|
|
76
|
+
|
|
77
|
+
const DrawerHeader = ({
|
|
78
|
+
className,
|
|
79
|
+
...props
|
|
80
|
+
}: React.HTMLAttributes<HTMLDivElement>) => (
|
|
81
|
+
<div
|
|
82
|
+
className={cn("grid gap-1.5 p-4 text-center sm:text-left", className)}
|
|
83
|
+
{...props}
|
|
84
|
+
/>
|
|
85
|
+
)
|
|
86
|
+
DrawerHeader.displayName = "DrawerHeader"
|
|
87
|
+
|
|
88
|
+
const DrawerFooter = ({
|
|
89
|
+
className,
|
|
90
|
+
...props
|
|
91
|
+
}: React.HTMLAttributes<HTMLDivElement>) => (
|
|
92
|
+
<div
|
|
93
|
+
className={cn("mt-auto flex flex-col gap-2 p-4", className)}
|
|
94
|
+
{...props}
|
|
95
|
+
/>
|
|
96
|
+
)
|
|
97
|
+
DrawerFooter.displayName = "DrawerFooter"
|
|
98
|
+
|
|
99
|
+
const DrawerTitle = React.forwardRef<
|
|
100
|
+
React.ElementRef<typeof DrawerPrimitive.Title>,
|
|
101
|
+
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Title>
|
|
102
|
+
>(({ className, ...props }, ref) => (
|
|
103
|
+
<DrawerPrimitive.Title
|
|
104
|
+
ref={ref}
|
|
105
|
+
className={cn(
|
|
106
|
+
"text-lg font-semibold leading-none tracking-tight",
|
|
107
|
+
className
|
|
108
|
+
)}
|
|
109
|
+
{...props}
|
|
110
|
+
/>
|
|
111
|
+
))
|
|
112
|
+
DrawerTitle.displayName = DrawerPrimitive.Title.displayName
|
|
113
|
+
|
|
114
|
+
const DrawerDescription = React.forwardRef<
|
|
115
|
+
React.ElementRef<typeof DrawerPrimitive.Description>,
|
|
116
|
+
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Description>
|
|
117
|
+
>(({ className, ...props }, ref) => (
|
|
118
|
+
<DrawerPrimitive.Description
|
|
119
|
+
ref={ref}
|
|
120
|
+
className={cn("text-sm text-muted-foreground", className)}
|
|
121
|
+
{...props}
|
|
122
|
+
/>
|
|
123
|
+
))
|
|
124
|
+
DrawerDescription.displayName = DrawerPrimitive.Description.displayName
|
|
125
|
+
|
|
126
|
+
export {
|
|
127
|
+
Drawer,
|
|
128
|
+
DrawerPortal,
|
|
129
|
+
DrawerOverlay,
|
|
130
|
+
DrawerTrigger,
|
|
131
|
+
DrawerClose,
|
|
132
|
+
DrawerContent,
|
|
133
|
+
DrawerHeader,
|
|
134
|
+
DrawerFooter,
|
|
135
|
+
DrawerTitle,
|
|
136
|
+
DrawerDescription,
|
|
137
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
2
|
+
|
|
3
|
+
import { cn } from "../lib/utils"
|
|
4
|
+
|
|
5
|
+
function Empty({ className, ...props }: React.ComponentProps<"div">) {
|
|
6
|
+
return (
|
|
7
|
+
<div
|
|
8
|
+
data-slot="empty"
|
|
9
|
+
className={cn(
|
|
10
|
+
"flex min-w-0 flex-1 flex-col items-center justify-center gap-6 text-balance rounded-lg border-dashed p-6 text-center md:p-12",
|
|
11
|
+
className
|
|
12
|
+
)}
|
|
13
|
+
{...props}
|
|
14
|
+
/>
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function EmptyHeader({ className, ...props }: React.ComponentProps<"div">) {
|
|
19
|
+
return (
|
|
20
|
+
<div
|
|
21
|
+
data-slot="empty-header"
|
|
22
|
+
className={cn(
|
|
23
|
+
"flex max-w-sm flex-col items-center gap-2 text-center",
|
|
24
|
+
className
|
|
25
|
+
)}
|
|
26
|
+
{...props}
|
|
27
|
+
/>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const emptyMediaVariants = cva(
|
|
32
|
+
"mb-2 flex shrink-0 items-center justify-center [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
|
33
|
+
{
|
|
34
|
+
variants: {
|
|
35
|
+
variant: {
|
|
36
|
+
default: "bg-transparent",
|
|
37
|
+
icon: "bg-muted text-foreground flex size-10 shrink-0 items-center justify-center rounded-lg [&_svg:not([class*='size-'])]:size-6",
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
defaultVariants: {
|
|
41
|
+
variant: "default",
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
function EmptyMedia({
|
|
47
|
+
className,
|
|
48
|
+
variant = "default",
|
|
49
|
+
...props
|
|
50
|
+
}: React.ComponentProps<"div"> & VariantProps<typeof emptyMediaVariants>) {
|
|
51
|
+
return (
|
|
52
|
+
<div
|
|
53
|
+
data-slot="empty-icon"
|
|
54
|
+
data-variant={variant}
|
|
55
|
+
className={cn(emptyMediaVariants({ variant, className }))}
|
|
56
|
+
{...props}
|
|
57
|
+
/>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function EmptyTitle({ className, ...props }: React.ComponentProps<"div">) {
|
|
62
|
+
return (
|
|
63
|
+
<div
|
|
64
|
+
data-slot="empty-title"
|
|
65
|
+
className={cn("text-lg font-medium tracking-tight", className)}
|
|
66
|
+
{...props}
|
|
67
|
+
/>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function EmptyDescription({ className, ...props }: React.ComponentProps<"p">) {
|
|
72
|
+
return (
|
|
73
|
+
<div
|
|
74
|
+
data-slot="empty-description"
|
|
75
|
+
className={cn(
|
|
76
|
+
"text-muted-foreground [&>a:hover]:text-primary text-sm/relaxed [&>a]:underline [&>a]:underline-offset-4",
|
|
77
|
+
className
|
|
78
|
+
)}
|
|
79
|
+
{...props}
|
|
80
|
+
/>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function EmptyContent({ className, ...props }: React.ComponentProps<"div">) {
|
|
85
|
+
return (
|
|
86
|
+
<div
|
|
87
|
+
data-slot="empty-content"
|
|
88
|
+
className={cn(
|
|
89
|
+
"flex w-full min-w-0 max-w-sm flex-col items-center gap-4 text-balance text-sm",
|
|
90
|
+
className
|
|
91
|
+
)}
|
|
92
|
+
{...props}
|
|
93
|
+
/>
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export {
|
|
98
|
+
Empty,
|
|
99
|
+
EmptyHeader,
|
|
100
|
+
EmptyTitle,
|
|
101
|
+
EmptyDescription,
|
|
102
|
+
EmptyContent,
|
|
103
|
+
EmptyMedia,
|
|
104
|
+
}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useMemo } from "react"
|
|
4
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
5
|
+
|
|
6
|
+
import { cn } from "../lib/utils"
|
|
7
|
+
import { Label } from "./label"
|
|
8
|
+
import { Separator } from "./separator"
|
|
9
|
+
|
|
10
|
+
function FieldSet({ className, ...props }: React.ComponentProps<"fieldset">) {
|
|
11
|
+
return (
|
|
12
|
+
<fieldset
|
|
13
|
+
data-slot="field-set"
|
|
14
|
+
className={cn(
|
|
15
|
+
"flex flex-col gap-6",
|
|
16
|
+
"has-[>[data-slot=checkbox-group]]:gap-3 has-[>[data-slot=radio-group]]:gap-3",
|
|
17
|
+
className
|
|
18
|
+
)}
|
|
19
|
+
{...props}
|
|
20
|
+
/>
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function FieldLegend({
|
|
25
|
+
className,
|
|
26
|
+
variant = "legend",
|
|
27
|
+
...props
|
|
28
|
+
}: React.ComponentProps<"legend"> & { variant?: "legend" | "label" }) {
|
|
29
|
+
return (
|
|
30
|
+
<legend
|
|
31
|
+
data-slot="field-legend"
|
|
32
|
+
data-variant={variant}
|
|
33
|
+
className={cn(
|
|
34
|
+
"mb-3 font-medium",
|
|
35
|
+
"data-[variant=legend]:text-base",
|
|
36
|
+
"data-[variant=label]:text-sm",
|
|
37
|
+
className
|
|
38
|
+
)}
|
|
39
|
+
{...props}
|
|
40
|
+
/>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function FieldGroup({ className, ...props }: React.ComponentProps<"div">) {
|
|
45
|
+
return (
|
|
46
|
+
<div
|
|
47
|
+
data-slot="field-group"
|
|
48
|
+
className={cn(
|
|
49
|
+
"group/field-group @container/field-group flex w-full flex-col gap-7 data-[slot=checkbox-group]:gap-3 [&>[data-slot=field-group]]:gap-4",
|
|
50
|
+
className
|
|
51
|
+
)}
|
|
52
|
+
{...props}
|
|
53
|
+
/>
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const fieldVariants = cva(
|
|
58
|
+
"group/field data-[invalid=true]:text-destructive flex w-full gap-3",
|
|
59
|
+
{
|
|
60
|
+
variants: {
|
|
61
|
+
orientation: {
|
|
62
|
+
vertical: ["flex-col [&>*]:w-full [&>.sr-only]:w-auto"],
|
|
63
|
+
horizontal: [
|
|
64
|
+
"flex-row items-center",
|
|
65
|
+
"[&>[data-slot=field-label]]:flex-auto",
|
|
66
|
+
"has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px has-[>[data-slot=field-content]]:items-start",
|
|
67
|
+
],
|
|
68
|
+
responsive: [
|
|
69
|
+
"@md/field-group:flex-row @md/field-group:items-center @md/field-group:[&>*]:w-auto flex-col [&>*]:w-full [&>.sr-only]:w-auto",
|
|
70
|
+
"@md/field-group:[&>[data-slot=field-label]]:flex-auto",
|
|
71
|
+
"@md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px",
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
defaultVariants: {
|
|
76
|
+
orientation: "vertical",
|
|
77
|
+
},
|
|
78
|
+
}
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
function Field({
|
|
82
|
+
className,
|
|
83
|
+
orientation = "vertical",
|
|
84
|
+
...props
|
|
85
|
+
}: React.ComponentProps<"div"> & VariantProps<typeof fieldVariants>) {
|
|
86
|
+
return (
|
|
87
|
+
<div
|
|
88
|
+
role="group"
|
|
89
|
+
data-slot="field"
|
|
90
|
+
data-orientation={orientation}
|
|
91
|
+
className={cn(fieldVariants({ orientation }), className)}
|
|
92
|
+
{...props}
|
|
93
|
+
/>
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function FieldContent({ className, ...props }: React.ComponentProps<"div">) {
|
|
98
|
+
return (
|
|
99
|
+
<div
|
|
100
|
+
data-slot="field-content"
|
|
101
|
+
className={cn(
|
|
102
|
+
"group/field-content flex flex-1 flex-col gap-1.5 leading-snug",
|
|
103
|
+
className
|
|
104
|
+
)}
|
|
105
|
+
{...props}
|
|
106
|
+
/>
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function FieldLabel({
|
|
111
|
+
className,
|
|
112
|
+
...props
|
|
113
|
+
}: React.ComponentProps<typeof Label>) {
|
|
114
|
+
return (
|
|
115
|
+
<Label
|
|
116
|
+
data-slot="field-label"
|
|
117
|
+
className={cn(
|
|
118
|
+
"group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50",
|
|
119
|
+
"has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col has-[>[data-slot=field]]:rounded-md has-[>[data-slot=field]]:border [&>[data-slot=field]]:p-4",
|
|
120
|
+
"has-data-[state=checked]:bg-primary/5 has-data-[state=checked]:border-primary dark:has-data-[state=checked]:bg-primary/10",
|
|
121
|
+
className
|
|
122
|
+
)}
|
|
123
|
+
{...props}
|
|
124
|
+
/>
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function FieldTitle({ className, ...props }: React.ComponentProps<"div">) {
|
|
129
|
+
return (
|
|
130
|
+
<div
|
|
131
|
+
data-slot="field-label"
|
|
132
|
+
className={cn(
|
|
133
|
+
"flex w-fit items-center gap-2 text-sm font-medium leading-snug group-data-[disabled=true]/field:opacity-50",
|
|
134
|
+
className
|
|
135
|
+
)}
|
|
136
|
+
{...props}
|
|
137
|
+
/>
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function FieldDescription({ className, ...props }: React.ComponentProps<"p">) {
|
|
142
|
+
return (
|
|
143
|
+
<p
|
|
144
|
+
data-slot="field-description"
|
|
145
|
+
className={cn(
|
|
146
|
+
"text-muted-foreground text-sm font-normal leading-normal group-has-[[data-orientation=horizontal]]/field:text-balance",
|
|
147
|
+
"nth-last-2:-mt-1 last:mt-0 [[data-variant=legend]+&]:-mt-1.5",
|
|
148
|
+
"[&>a:hover]:text-primary [&>a]:underline [&>a]:underline-offset-4",
|
|
149
|
+
className
|
|
150
|
+
)}
|
|
151
|
+
{...props}
|
|
152
|
+
/>
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function FieldSeparator({
|
|
157
|
+
children,
|
|
158
|
+
className,
|
|
159
|
+
...props
|
|
160
|
+
}: React.ComponentProps<"div"> & {
|
|
161
|
+
children?: React.ReactNode
|
|
162
|
+
}) {
|
|
163
|
+
return (
|
|
164
|
+
<div
|
|
165
|
+
data-slot="field-separator"
|
|
166
|
+
data-content={!!children}
|
|
167
|
+
className={cn(
|
|
168
|
+
"relative -my-2 h-5 text-sm group-data-[variant=outline]/field-group:-mb-2",
|
|
169
|
+
className
|
|
170
|
+
)}
|
|
171
|
+
{...props}
|
|
172
|
+
>
|
|
173
|
+
<Separator className="absolute inset-0 top-1/2" />
|
|
174
|
+
{children && (
|
|
175
|
+
<span
|
|
176
|
+
className="bg-background text-muted-foreground relative mx-auto block w-fit px-2"
|
|
177
|
+
data-slot="field-separator-content"
|
|
178
|
+
>
|
|
179
|
+
{children}
|
|
180
|
+
</span>
|
|
181
|
+
)}
|
|
182
|
+
</div>
|
|
183
|
+
)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function FieldError({
|
|
187
|
+
className,
|
|
188
|
+
children,
|
|
189
|
+
errors,
|
|
190
|
+
...props
|
|
191
|
+
}: React.ComponentProps<"div"> & {
|
|
192
|
+
errors?: Array<{ message?: string } | undefined>
|
|
193
|
+
}) {
|
|
194
|
+
const content = useMemo(() => {
|
|
195
|
+
if (children) {
|
|
196
|
+
return children
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (!errors) {
|
|
200
|
+
return null
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (errors?.length === 1 && errors[0]?.message) {
|
|
204
|
+
return errors[0].message
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return (
|
|
208
|
+
<ul className="ml-4 flex list-disc flex-col gap-1">
|
|
209
|
+
{errors.map(
|
|
210
|
+
(error, index) =>
|
|
211
|
+
error?.message && <li key={index}>{error.message}</li>
|
|
212
|
+
)}
|
|
213
|
+
</ul>
|
|
214
|
+
)
|
|
215
|
+
}, [children, errors])
|
|
216
|
+
|
|
217
|
+
if (!content) {
|
|
218
|
+
return null
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return (
|
|
222
|
+
<div
|
|
223
|
+
role="alert"
|
|
224
|
+
data-slot="field-error"
|
|
225
|
+
className={cn("text-destructive text-sm font-normal", className)}
|
|
226
|
+
{...props}
|
|
227
|
+
>
|
|
228
|
+
{content}
|
|
229
|
+
</div>
|
|
230
|
+
)
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export {
|
|
234
|
+
Field,
|
|
235
|
+
FieldLabel,
|
|
236
|
+
FieldDescription,
|
|
237
|
+
FieldError,
|
|
238
|
+
FieldGroup,
|
|
239
|
+
FieldLegend,
|
|
240
|
+
FieldSeparator,
|
|
241
|
+
FieldSet,
|
|
242
|
+
FieldContent,
|
|
243
|
+
FieldTitle,
|
|
244
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import * as LabelPrimitive from "@radix-ui/react-label"
|
|
5
|
+
import { Slot } from "@radix-ui/react-slot"
|
|
6
|
+
import {
|
|
7
|
+
Controller,
|
|
8
|
+
FormProvider,
|
|
9
|
+
useFormContext,
|
|
10
|
+
type ControllerProps,
|
|
11
|
+
type FieldPath,
|
|
12
|
+
type FieldValues,
|
|
13
|
+
} from "react-hook-form"
|
|
14
|
+
|
|
15
|
+
import { cn } from "../lib/utils"
|
|
16
|
+
import { Label } from "./label"
|
|
17
|
+
|
|
18
|
+
const Form = FormProvider
|
|
19
|
+
|
|
20
|
+
type FormFieldContextValue<
|
|
21
|
+
TFieldValues extends FieldValues = FieldValues,
|
|
22
|
+
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
|
|
23
|
+
> = {
|
|
24
|
+
name: TName
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const FormFieldContext = React.createContext<FormFieldContextValue>(
|
|
28
|
+
{} as FormFieldContextValue
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
const FormField = <
|
|
32
|
+
TFieldValues extends FieldValues = FieldValues,
|
|
33
|
+
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
|
|
34
|
+
>({
|
|
35
|
+
...props
|
|
36
|
+
}: ControllerProps<TFieldValues, TName>) => {
|
|
37
|
+
return (
|
|
38
|
+
<FormFieldContext.Provider value={{ name: props.name }}>
|
|
39
|
+
<Controller {...props} />
|
|
40
|
+
</FormFieldContext.Provider>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const useFormField = () => {
|
|
45
|
+
const fieldContext = React.useContext(FormFieldContext)
|
|
46
|
+
const itemContext = React.useContext(FormItemContext)
|
|
47
|
+
const { getFieldState, formState } = useFormContext()
|
|
48
|
+
|
|
49
|
+
const fieldState = getFieldState(fieldContext.name, formState)
|
|
50
|
+
|
|
51
|
+
if (!fieldContext) {
|
|
52
|
+
throw new Error("useFormField should be used within <FormField>")
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const { id } = itemContext
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
id,
|
|
59
|
+
name: fieldContext.name,
|
|
60
|
+
formItemId: `${id}-form-item`,
|
|
61
|
+
formDescriptionId: `${id}-form-item-description`,
|
|
62
|
+
formMessageId: `${id}-form-item-message`,
|
|
63
|
+
...fieldState,
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
type FormItemContextValue = {
|
|
68
|
+
id: string
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const FormItemContext = React.createContext<FormItemContextValue>(
|
|
72
|
+
{} as FormItemContextValue
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
const FormItem = React.forwardRef<
|
|
76
|
+
HTMLDivElement,
|
|
77
|
+
React.HTMLAttributes<HTMLDivElement>
|
|
78
|
+
>(({ className, ...props }, ref) => {
|
|
79
|
+
const id = React.useId()
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<FormItemContext.Provider value={{ id }}>
|
|
83
|
+
<div ref={ref} className={cn("space-y-2", className)} {...props} />
|
|
84
|
+
</FormItemContext.Provider>
|
|
85
|
+
)
|
|
86
|
+
})
|
|
87
|
+
FormItem.displayName = "FormItem"
|
|
88
|
+
|
|
89
|
+
const FormLabel = React.forwardRef<
|
|
90
|
+
React.ElementRef<typeof LabelPrimitive.Root>,
|
|
91
|
+
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>
|
|
92
|
+
>(({ className, ...props }, ref) => {
|
|
93
|
+
const { error, formItemId } = useFormField()
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<Label
|
|
97
|
+
ref={ref}
|
|
98
|
+
className={cn(error && "text-destructive", className)}
|
|
99
|
+
htmlFor={formItemId}
|
|
100
|
+
{...props}
|
|
101
|
+
/>
|
|
102
|
+
)
|
|
103
|
+
})
|
|
104
|
+
FormLabel.displayName = "FormLabel"
|
|
105
|
+
|
|
106
|
+
const FormControl = React.forwardRef<
|
|
107
|
+
React.ElementRef<typeof Slot>,
|
|
108
|
+
React.ComponentPropsWithoutRef<typeof Slot>
|
|
109
|
+
>(({ ...props }, ref) => {
|
|
110
|
+
const { error, formItemId, formDescriptionId, formMessageId } = useFormField()
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<Slot
|
|
114
|
+
ref={ref}
|
|
115
|
+
id={formItemId}
|
|
116
|
+
aria-describedby={
|
|
117
|
+
!error
|
|
118
|
+
? `${formDescriptionId}`
|
|
119
|
+
: `${formDescriptionId} ${formMessageId}`
|
|
120
|
+
}
|
|
121
|
+
aria-invalid={!!error}
|
|
122
|
+
{...props}
|
|
123
|
+
/>
|
|
124
|
+
)
|
|
125
|
+
})
|
|
126
|
+
FormControl.displayName = "FormControl"
|
|
127
|
+
|
|
128
|
+
const FormDescription = React.forwardRef<
|
|
129
|
+
HTMLParagraphElement,
|
|
130
|
+
React.HTMLAttributes<HTMLParagraphElement>
|
|
131
|
+
>(({ className, ...props }, ref) => {
|
|
132
|
+
const { formDescriptionId } = useFormField()
|
|
133
|
+
|
|
134
|
+
return (
|
|
135
|
+
<p
|
|
136
|
+
ref={ref}
|
|
137
|
+
id={formDescriptionId}
|
|
138
|
+
className={cn("text-[0.8rem] text-muted-foreground", className)}
|
|
139
|
+
{...props}
|
|
140
|
+
/>
|
|
141
|
+
)
|
|
142
|
+
})
|
|
143
|
+
FormDescription.displayName = "FormDescription"
|
|
144
|
+
|
|
145
|
+
const FormMessage = React.forwardRef<
|
|
146
|
+
HTMLParagraphElement,
|
|
147
|
+
React.HTMLAttributes<HTMLParagraphElement>
|
|
148
|
+
>(({ className, children, ...props }, ref) => {
|
|
149
|
+
const { error, formMessageId } = useFormField()
|
|
150
|
+
const body = error ? String(error?.message ?? "") : children
|
|
151
|
+
|
|
152
|
+
if (!body) {
|
|
153
|
+
return null
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<p
|
|
158
|
+
ref={ref}
|
|
159
|
+
id={formMessageId}
|
|
160
|
+
className={cn("text-[0.8rem] font-medium text-destructive", className)}
|
|
161
|
+
{...props}
|
|
162
|
+
>
|
|
163
|
+
{body}
|
|
164
|
+
</p>
|
|
165
|
+
)
|
|
166
|
+
})
|
|
167
|
+
FormMessage.displayName = "FormMessage"
|
|
168
|
+
|
|
169
|
+
export {
|
|
170
|
+
useFormField,
|
|
171
|
+
Form,
|
|
172
|
+
FormItem,
|
|
173
|
+
FormLabel,
|
|
174
|
+
FormControl,
|
|
175
|
+
FormDescription,
|
|
176
|
+
FormMessage,
|
|
177
|
+
FormField,
|
|
178
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import * as HoverCardPrimitive from "@radix-ui/react-hover-card"
|
|
5
|
+
|
|
6
|
+
import { cn } from "../lib/utils"
|
|
7
|
+
|
|
8
|
+
const HoverCard = HoverCardPrimitive.Root
|
|
9
|
+
|
|
10
|
+
const HoverCardTrigger = HoverCardPrimitive.Trigger
|
|
11
|
+
|
|
12
|
+
const HoverCardContent = React.forwardRef<
|
|
13
|
+
React.ElementRef<typeof HoverCardPrimitive.Content>,
|
|
14
|
+
React.ComponentPropsWithoutRef<typeof HoverCardPrimitive.Content>
|
|
15
|
+
>(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
|
|
16
|
+
<HoverCardPrimitive.Content
|
|
17
|
+
ref={ref}
|
|
18
|
+
align={align}
|
|
19
|
+
sideOffset={sideOffset}
|
|
20
|
+
className={cn(
|
|
21
|
+
"z-150 w-64 rounded-sm border bg-popover backdrop-blur-xl p-4 text-popover-foreground shadow-sm outline-none 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-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
|
22
|
+
className
|
|
23
|
+
)}
|
|
24
|
+
{...props}
|
|
25
|
+
/>
|
|
26
|
+
))
|
|
27
|
+
HoverCardContent.displayName = HoverCardPrimitive.Content.displayName
|
|
28
|
+
|
|
29
|
+
export { HoverCard, HoverCardTrigger, HoverCardContent }
|