@blips/ui 0.0.1 → 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/dist/index.cjs +1347 -146
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +185 -6
- package/dist/index.d.ts +185 -6
- package/dist/index.js +1295 -148
- package/dist/index.js.map +1 -1
- package/package.json +25 -13
- package/src/components/accordion.tsx +12 -12
- package/src/components/alert-dialog.tsx +25 -24
- package/src/components/alert.tsx +11 -11
- package/src/components/aspect-ratio.tsx +3 -3
- package/src/components/avatar.tsx +11 -11
- package/src/components/badge.tsx +6 -6
- package/src/components/breadcrumb.tsx +23 -23
- package/src/components/button-group.tsx +83 -0
- package/src/components/button.tsx +11 -11
- package/src/components/calendar.tsx +21 -24
- package/src/components/card.tsx +15 -22
- package/src/components/carousel.tsx +72 -71
- package/src/components/chart.tsx +368 -0
- package/src/components/checkbox.tsx +7 -7
- package/src/components/collapsible.tsx +6 -6
- package/src/components/command.tsx +27 -26
- package/src/components/context-menu.tsx +33 -33
- package/src/components/dialog.tsx +22 -22
- package/src/components/drawer.tsx +21 -21
- package/src/components/dropdown-menu.tsx +34 -34
- package/src/components/form.tsx +178 -0
- package/src/components/hover-card.tsx +8 -8
- package/src/components/input-group.tsx +175 -0
- package/src/components/input-otp.tsx +16 -16
- package/src/components/input.tsx +6 -6
- package/src/components/kbd.tsx +28 -0
- package/src/components/label.tsx +9 -9
- package/src/components/menubar.tsx +36 -36
- package/src/components/navigation-menu.tsx +21 -21
- package/src/components/pagination.tsx +22 -21
- package/src/components/popover.tsx +8 -8
- package/src/components/progress.tsx +7 -7
- package/src/components/radio-group.tsx +11 -11
- package/src/components/resizable.tsx +14 -14
- package/src/components/scroll-area.tsx +8 -8
- package/src/components/select.tsx +23 -23
- package/src/components/separator.tsx +6 -6
- package/src/components/sheet.tsx +24 -24
- package/src/components/sidebar.tsx +774 -0
- package/src/components/skeleton.tsx +3 -3
- package/src/components/slider.tsx +6 -6
- package/src/components/sonner.tsx +9 -9
- package/src/components/spinner.tsx +16 -0
- package/src/components/switch.tsx +6 -6
- package/src/components/table.tsx +19 -19
- package/src/components/tabs.tsx +11 -11
- package/src/components/textarea.tsx +6 -6
- package/src/components/toggle-group.tsx +15 -14
- package/src/components/toggle.tsx +8 -8
- package/src/components/tooltip.tsx +10 -10
- package/src/globals.css +45 -0
- package/src/hooks/use-mobile.tsx +19 -0
- package/src/index.ts +78 -0
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
"use client"
|
|
1
|
+
"use client"
|
|
2
2
|
|
|
3
|
-
import * as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import * as DialogPrimitive from "@radix-ui/react-dialog"
|
|
5
|
+
import { X } from "lucide-react"
|
|
6
6
|
|
|
7
|
-
import { cn } from "
|
|
7
|
+
import { cn } from "@/lib/utils"
|
|
8
8
|
|
|
9
|
-
const Dialog = DialogPrimitive.Root
|
|
9
|
+
const Dialog = DialogPrimitive.Root
|
|
10
10
|
|
|
11
|
-
const DialogTrigger = DialogPrimitive.Trigger
|
|
11
|
+
const DialogTrigger = DialogPrimitive.Trigger
|
|
12
12
|
|
|
13
|
-
const DialogPortal = DialogPrimitive.Portal
|
|
13
|
+
const DialogPortal = DialogPrimitive.Portal
|
|
14
14
|
|
|
15
|
-
const DialogClose = DialogPrimitive.Close
|
|
15
|
+
const DialogClose = DialogPrimitive.Close
|
|
16
16
|
|
|
17
17
|
const DialogOverlay = React.forwardRef<
|
|
18
18
|
React.ElementRef<typeof DialogPrimitive.Overlay>,
|
|
@@ -26,8 +26,8 @@ const DialogOverlay = React.forwardRef<
|
|
|
26
26
|
)}
|
|
27
27
|
{...props}
|
|
28
28
|
/>
|
|
29
|
-
))
|
|
30
|
-
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName
|
|
29
|
+
))
|
|
30
|
+
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName
|
|
31
31
|
|
|
32
32
|
const DialogContent = React.forwardRef<
|
|
33
33
|
React.ElementRef<typeof DialogPrimitive.Content>,
|
|
@@ -50,8 +50,8 @@ const DialogContent = React.forwardRef<
|
|
|
50
50
|
</DialogPrimitive.Close>
|
|
51
51
|
</DialogPrimitive.Content>
|
|
52
52
|
</DialogPortal>
|
|
53
|
-
))
|
|
54
|
-
DialogContent.displayName = DialogPrimitive.Content.displayName
|
|
53
|
+
))
|
|
54
|
+
DialogContent.displayName = DialogPrimitive.Content.displayName
|
|
55
55
|
|
|
56
56
|
const DialogHeader = ({
|
|
57
57
|
className,
|
|
@@ -64,8 +64,8 @@ const DialogHeader = ({
|
|
|
64
64
|
)}
|
|
65
65
|
{...props}
|
|
66
66
|
/>
|
|
67
|
-
)
|
|
68
|
-
DialogHeader.displayName = "DialogHeader"
|
|
67
|
+
)
|
|
68
|
+
DialogHeader.displayName = "DialogHeader"
|
|
69
69
|
|
|
70
70
|
const DialogFooter = ({
|
|
71
71
|
className,
|
|
@@ -78,8 +78,8 @@ const DialogFooter = ({
|
|
|
78
78
|
)}
|
|
79
79
|
{...props}
|
|
80
80
|
/>
|
|
81
|
-
)
|
|
82
|
-
DialogFooter.displayName = "DialogFooter"
|
|
81
|
+
)
|
|
82
|
+
DialogFooter.displayName = "DialogFooter"
|
|
83
83
|
|
|
84
84
|
const DialogTitle = React.forwardRef<
|
|
85
85
|
React.ElementRef<typeof DialogPrimitive.Title>,
|
|
@@ -93,8 +93,8 @@ const DialogTitle = React.forwardRef<
|
|
|
93
93
|
)}
|
|
94
94
|
{...props}
|
|
95
95
|
/>
|
|
96
|
-
))
|
|
97
|
-
DialogTitle.displayName = DialogPrimitive.Title.displayName
|
|
96
|
+
))
|
|
97
|
+
DialogTitle.displayName = DialogPrimitive.Title.displayName
|
|
98
98
|
|
|
99
99
|
const DialogDescription = React.forwardRef<
|
|
100
100
|
React.ElementRef<typeof DialogPrimitive.Description>,
|
|
@@ -105,8 +105,8 @@ const DialogDescription = React.forwardRef<
|
|
|
105
105
|
className={cn("text-sm text-muted-foreground", className)}
|
|
106
106
|
{...props}
|
|
107
107
|
/>
|
|
108
|
-
))
|
|
109
|
-
DialogDescription.displayName = DialogPrimitive.Description.displayName
|
|
108
|
+
))
|
|
109
|
+
DialogDescription.displayName = DialogPrimitive.Description.displayName
|
|
110
110
|
|
|
111
111
|
export {
|
|
112
112
|
Dialog,
|
|
@@ -119,4 +119,4 @@ export {
|
|
|
119
119
|
DialogFooter,
|
|
120
120
|
DialogTitle,
|
|
121
121
|
DialogDescription,
|
|
122
|
-
}
|
|
122
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as React from "react"
|
|
2
|
-
import { Drawer as DrawerPrimitive } from "vaul"
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { Drawer as DrawerPrimitive } from "vaul"
|
|
3
3
|
|
|
4
|
-
import { cn } from "
|
|
4
|
+
import { cn } from "@/lib/utils"
|
|
5
5
|
|
|
6
6
|
const Drawer = ({
|
|
7
7
|
shouldScaleBackground = true,
|
|
@@ -11,14 +11,14 @@ const Drawer = ({
|
|
|
11
11
|
shouldScaleBackground={shouldScaleBackground}
|
|
12
12
|
{...props}
|
|
13
13
|
/>
|
|
14
|
-
)
|
|
15
|
-
Drawer.displayName = "Drawer"
|
|
14
|
+
)
|
|
15
|
+
Drawer.displayName = "Drawer"
|
|
16
16
|
|
|
17
|
-
const DrawerTrigger = DrawerPrimitive.Trigger
|
|
17
|
+
const DrawerTrigger = DrawerPrimitive.Trigger
|
|
18
18
|
|
|
19
|
-
const DrawerPortal = DrawerPrimitive.Portal
|
|
19
|
+
const DrawerPortal = DrawerPrimitive.Portal
|
|
20
20
|
|
|
21
|
-
const DrawerClose = DrawerPrimitive.Close
|
|
21
|
+
const DrawerClose = DrawerPrimitive.Close
|
|
22
22
|
|
|
23
23
|
const DrawerOverlay = React.forwardRef<
|
|
24
24
|
React.ElementRef<typeof DrawerPrimitive.Overlay>,
|
|
@@ -29,8 +29,8 @@ const DrawerOverlay = React.forwardRef<
|
|
|
29
29
|
className={cn("fixed inset-0 z-50 bg-black/80", className)}
|
|
30
30
|
{...props}
|
|
31
31
|
/>
|
|
32
|
-
))
|
|
33
|
-
DrawerOverlay.displayName = DrawerPrimitive.Overlay.displayName
|
|
32
|
+
))
|
|
33
|
+
DrawerOverlay.displayName = DrawerPrimitive.Overlay.displayName
|
|
34
34
|
|
|
35
35
|
const DrawerContent = React.forwardRef<
|
|
36
36
|
React.ElementRef<typeof DrawerPrimitive.Content>,
|
|
@@ -50,8 +50,8 @@ const DrawerContent = React.forwardRef<
|
|
|
50
50
|
{children}
|
|
51
51
|
</DrawerPrimitive.Content>
|
|
52
52
|
</DrawerPortal>
|
|
53
|
-
))
|
|
54
|
-
DrawerContent.displayName = "DrawerContent"
|
|
53
|
+
))
|
|
54
|
+
DrawerContent.displayName = "DrawerContent"
|
|
55
55
|
|
|
56
56
|
const DrawerHeader = ({
|
|
57
57
|
className,
|
|
@@ -61,8 +61,8 @@ const DrawerHeader = ({
|
|
|
61
61
|
className={cn("grid gap-1.5 p-4 text-center sm:text-left", className)}
|
|
62
62
|
{...props}
|
|
63
63
|
/>
|
|
64
|
-
)
|
|
65
|
-
DrawerHeader.displayName = "DrawerHeader"
|
|
64
|
+
)
|
|
65
|
+
DrawerHeader.displayName = "DrawerHeader"
|
|
66
66
|
|
|
67
67
|
const DrawerFooter = ({
|
|
68
68
|
className,
|
|
@@ -72,8 +72,8 @@ const DrawerFooter = ({
|
|
|
72
72
|
className={cn("mt-auto flex flex-col gap-2 p-4", className)}
|
|
73
73
|
{...props}
|
|
74
74
|
/>
|
|
75
|
-
)
|
|
76
|
-
DrawerFooter.displayName = "DrawerFooter"
|
|
75
|
+
)
|
|
76
|
+
DrawerFooter.displayName = "DrawerFooter"
|
|
77
77
|
|
|
78
78
|
const DrawerTitle = React.forwardRef<
|
|
79
79
|
React.ElementRef<typeof DrawerPrimitive.Title>,
|
|
@@ -87,8 +87,8 @@ const DrawerTitle = React.forwardRef<
|
|
|
87
87
|
)}
|
|
88
88
|
{...props}
|
|
89
89
|
/>
|
|
90
|
-
))
|
|
91
|
-
DrawerTitle.displayName = DrawerPrimitive.Title.displayName
|
|
90
|
+
))
|
|
91
|
+
DrawerTitle.displayName = DrawerPrimitive.Title.displayName
|
|
92
92
|
|
|
93
93
|
const DrawerDescription = React.forwardRef<
|
|
94
94
|
React.ElementRef<typeof DrawerPrimitive.Description>,
|
|
@@ -99,8 +99,8 @@ const DrawerDescription = React.forwardRef<
|
|
|
99
99
|
className={cn("text-sm text-muted-foreground", className)}
|
|
100
100
|
{...props}
|
|
101
101
|
/>
|
|
102
|
-
))
|
|
103
|
-
DrawerDescription.displayName = DrawerPrimitive.Description.displayName
|
|
102
|
+
))
|
|
103
|
+
DrawerDescription.displayName = DrawerPrimitive.Description.displayName
|
|
104
104
|
|
|
105
105
|
export {
|
|
106
106
|
Drawer,
|
|
@@ -113,4 +113,4 @@ export {
|
|
|
113
113
|
DrawerFooter,
|
|
114
114
|
DrawerTitle,
|
|
115
115
|
DrawerDescription,
|
|
116
|
-
}
|
|
116
|
+
}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
"use client"
|
|
1
|
+
"use client"
|
|
2
2
|
|
|
3
|
-
import * as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu"
|
|
5
|
+
import { Check, ChevronRight, Circle } from "lucide-react"
|
|
6
6
|
|
|
7
|
-
import { cn } from "
|
|
7
|
+
import { cn } from "@/lib/utils"
|
|
8
8
|
|
|
9
|
-
const DropdownMenu = DropdownMenuPrimitive.Root
|
|
9
|
+
const DropdownMenu = DropdownMenuPrimitive.Root
|
|
10
10
|
|
|
11
|
-
const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger
|
|
11
|
+
const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger
|
|
12
12
|
|
|
13
|
-
const DropdownMenuGroup = DropdownMenuPrimitive.Group
|
|
13
|
+
const DropdownMenuGroup = DropdownMenuPrimitive.Group
|
|
14
14
|
|
|
15
|
-
const DropdownMenuPortal = DropdownMenuPrimitive.Portal
|
|
15
|
+
const DropdownMenuPortal = DropdownMenuPrimitive.Portal
|
|
16
16
|
|
|
17
|
-
const DropdownMenuSub = DropdownMenuPrimitive.Sub
|
|
17
|
+
const DropdownMenuSub = DropdownMenuPrimitive.Sub
|
|
18
18
|
|
|
19
|
-
const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup
|
|
19
|
+
const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup
|
|
20
20
|
|
|
21
21
|
const DropdownMenuSubTrigger = React.forwardRef<
|
|
22
22
|
React.ElementRef<typeof DropdownMenuPrimitive.SubTrigger>,
|
|
23
23
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger> & {
|
|
24
|
-
inset?: boolean
|
|
24
|
+
inset?: boolean
|
|
25
25
|
}
|
|
26
26
|
>(({ className, inset, children, ...props }, ref) => (
|
|
27
27
|
<DropdownMenuPrimitive.SubTrigger
|
|
@@ -36,9 +36,9 @@ const DropdownMenuSubTrigger = React.forwardRef<
|
|
|
36
36
|
{children}
|
|
37
37
|
<ChevronRight className="ml-auto" />
|
|
38
38
|
</DropdownMenuPrimitive.SubTrigger>
|
|
39
|
-
))
|
|
39
|
+
))
|
|
40
40
|
DropdownMenuSubTrigger.displayName =
|
|
41
|
-
DropdownMenuPrimitive.SubTrigger.displayName
|
|
41
|
+
DropdownMenuPrimitive.SubTrigger.displayName
|
|
42
42
|
|
|
43
43
|
const DropdownMenuSubContent = React.forwardRef<
|
|
44
44
|
React.ElementRef<typeof DropdownMenuPrimitive.SubContent>,
|
|
@@ -52,9 +52,9 @@ const DropdownMenuSubContent = React.forwardRef<
|
|
|
52
52
|
)}
|
|
53
53
|
{...props}
|
|
54
54
|
/>
|
|
55
|
-
))
|
|
55
|
+
))
|
|
56
56
|
DropdownMenuSubContent.displayName =
|
|
57
|
-
DropdownMenuPrimitive.SubContent.displayName
|
|
57
|
+
DropdownMenuPrimitive.SubContent.displayName
|
|
58
58
|
|
|
59
59
|
const DropdownMenuContent = React.forwardRef<
|
|
60
60
|
React.ElementRef<typeof DropdownMenuPrimitive.Content>,
|
|
@@ -71,13 +71,13 @@ const DropdownMenuContent = React.forwardRef<
|
|
|
71
71
|
{...props}
|
|
72
72
|
/>
|
|
73
73
|
</DropdownMenuPrimitive.Portal>
|
|
74
|
-
))
|
|
75
|
-
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName
|
|
74
|
+
))
|
|
75
|
+
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName
|
|
76
76
|
|
|
77
77
|
const DropdownMenuItem = React.forwardRef<
|
|
78
78
|
React.ElementRef<typeof DropdownMenuPrimitive.Item>,
|
|
79
79
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & {
|
|
80
|
-
inset?: boolean
|
|
80
|
+
inset?: boolean
|
|
81
81
|
}
|
|
82
82
|
>(({ className, inset, ...props }, ref) => (
|
|
83
83
|
<DropdownMenuPrimitive.Item
|
|
@@ -89,8 +89,8 @@ const DropdownMenuItem = React.forwardRef<
|
|
|
89
89
|
)}
|
|
90
90
|
{...props}
|
|
91
91
|
/>
|
|
92
|
-
))
|
|
93
|
-
DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName
|
|
92
|
+
))
|
|
93
|
+
DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName
|
|
94
94
|
|
|
95
95
|
const DropdownMenuCheckboxItem = React.forwardRef<
|
|
96
96
|
React.ElementRef<typeof DropdownMenuPrimitive.CheckboxItem>,
|
|
@@ -112,9 +112,9 @@ const DropdownMenuCheckboxItem = React.forwardRef<
|
|
|
112
112
|
</span>
|
|
113
113
|
{children}
|
|
114
114
|
</DropdownMenuPrimitive.CheckboxItem>
|
|
115
|
-
))
|
|
115
|
+
))
|
|
116
116
|
DropdownMenuCheckboxItem.displayName =
|
|
117
|
-
DropdownMenuPrimitive.CheckboxItem.displayName
|
|
117
|
+
DropdownMenuPrimitive.CheckboxItem.displayName
|
|
118
118
|
|
|
119
119
|
const DropdownMenuRadioItem = React.forwardRef<
|
|
120
120
|
React.ElementRef<typeof DropdownMenuPrimitive.RadioItem>,
|
|
@@ -135,13 +135,13 @@ const DropdownMenuRadioItem = React.forwardRef<
|
|
|
135
135
|
</span>
|
|
136
136
|
{children}
|
|
137
137
|
</DropdownMenuPrimitive.RadioItem>
|
|
138
|
-
))
|
|
139
|
-
DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName
|
|
138
|
+
))
|
|
139
|
+
DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName
|
|
140
140
|
|
|
141
141
|
const DropdownMenuLabel = React.forwardRef<
|
|
142
142
|
React.ElementRef<typeof DropdownMenuPrimitive.Label>,
|
|
143
143
|
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Label> & {
|
|
144
|
-
inset?: boolean
|
|
144
|
+
inset?: boolean
|
|
145
145
|
}
|
|
146
146
|
>(({ className, inset, ...props }, ref) => (
|
|
147
147
|
<DropdownMenuPrimitive.Label
|
|
@@ -153,8 +153,8 @@ const DropdownMenuLabel = React.forwardRef<
|
|
|
153
153
|
)}
|
|
154
154
|
{...props}
|
|
155
155
|
/>
|
|
156
|
-
))
|
|
157
|
-
DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName
|
|
156
|
+
))
|
|
157
|
+
DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName
|
|
158
158
|
|
|
159
159
|
const DropdownMenuSeparator = React.forwardRef<
|
|
160
160
|
React.ElementRef<typeof DropdownMenuPrimitive.Separator>,
|
|
@@ -165,8 +165,8 @@ const DropdownMenuSeparator = React.forwardRef<
|
|
|
165
165
|
className={cn("-mx-1 my-1 h-px bg-muted", className)}
|
|
166
166
|
{...props}
|
|
167
167
|
/>
|
|
168
|
-
))
|
|
169
|
-
DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName
|
|
168
|
+
))
|
|
169
|
+
DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName
|
|
170
170
|
|
|
171
171
|
const DropdownMenuShortcut = ({
|
|
172
172
|
className,
|
|
@@ -177,9 +177,9 @@ const DropdownMenuShortcut = ({
|
|
|
177
177
|
className={cn("ml-auto text-xs tracking-widest opacity-60", className)}
|
|
178
178
|
{...props}
|
|
179
179
|
/>
|
|
180
|
-
)
|
|
181
|
-
}
|
|
182
|
-
DropdownMenuShortcut.displayName = "DropdownMenuShortcut"
|
|
180
|
+
)
|
|
181
|
+
}
|
|
182
|
+
DropdownMenuShortcut.displayName = "DropdownMenuShortcut"
|
|
183
183
|
|
|
184
184
|
export {
|
|
185
185
|
DropdownMenu,
|
|
@@ -197,4 +197,4 @@ export {
|
|
|
197
197
|
DropdownMenuSubContent,
|
|
198
198
|
DropdownMenuSubTrigger,
|
|
199
199
|
DropdownMenuRadioGroup,
|
|
200
|
-
}
|
|
200
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import type * 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 "@/components/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 | null>(null)
|
|
28
|
+
|
|
29
|
+
const FormField = <
|
|
30
|
+
TFieldValues extends FieldValues = FieldValues,
|
|
31
|
+
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>
|
|
32
|
+
>({
|
|
33
|
+
...props
|
|
34
|
+
}: ControllerProps<TFieldValues, TName>) => {
|
|
35
|
+
return (
|
|
36
|
+
<FormFieldContext.Provider value={{ name: props.name }}>
|
|
37
|
+
<Controller {...props} />
|
|
38
|
+
</FormFieldContext.Provider>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const useFormField = () => {
|
|
43
|
+
const fieldContext = React.useContext(FormFieldContext)
|
|
44
|
+
const itemContext = React.useContext(FormItemContext)
|
|
45
|
+
const { getFieldState, formState } = useFormContext()
|
|
46
|
+
|
|
47
|
+
if (!fieldContext) {
|
|
48
|
+
throw new Error("useFormField should be used within <FormField>")
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!itemContext) {
|
|
52
|
+
throw new Error("useFormField should be used within <FormItem>")
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const fieldState = getFieldState(fieldContext.name, formState)
|
|
56
|
+
|
|
57
|
+
const { id } = itemContext
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
id,
|
|
61
|
+
name: fieldContext.name,
|
|
62
|
+
formItemId: `${id}-form-item`,
|
|
63
|
+
formDescriptionId: `${id}-form-item-description`,
|
|
64
|
+
formMessageId: `${id}-form-item-message`,
|
|
65
|
+
...fieldState,
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
type FormItemContextValue = {
|
|
70
|
+
id: string
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const FormItemContext = React.createContext<FormItemContextValue | null>(null)
|
|
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-sm 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-sm 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
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import * as HoverCardPrimitive from "@radix-ui/react-hover-card"
|
|
3
3
|
|
|
4
|
-
import { cn } from "
|
|
4
|
+
import { cn } from "@/lib/utils"
|
|
5
5
|
|
|
6
|
-
const HoverCard = HoverCardPrimitive.Root
|
|
6
|
+
const HoverCard = HoverCardPrimitive.Root
|
|
7
7
|
|
|
8
|
-
const HoverCardTrigger = HoverCardPrimitive.Trigger
|
|
8
|
+
const HoverCardTrigger = HoverCardPrimitive.Trigger
|
|
9
9
|
|
|
10
10
|
const HoverCardContent = React.forwardRef<
|
|
11
11
|
React.ElementRef<typeof HoverCardPrimitive.Content>,
|
|
@@ -21,7 +21,7 @@ const HoverCardContent = React.forwardRef<
|
|
|
21
21
|
)}
|
|
22
22
|
{...props}
|
|
23
23
|
/>
|
|
24
|
-
))
|
|
25
|
-
HoverCardContent.displayName = HoverCardPrimitive.Content.displayName
|
|
24
|
+
))
|
|
25
|
+
HoverCardContent.displayName = HoverCardPrimitive.Content.displayName
|
|
26
26
|
|
|
27
|
-
export { HoverCard, HoverCardTrigger, HoverCardContent }
|
|
27
|
+
export { HoverCard, HoverCardTrigger, HoverCardContent }
|