@motor-hero/ui-kit 0.11.0 → 0.12.0
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/components/form-dialog.d.ts +33 -1
- package/dist/components/form-dialog.d.ts.map +1 -1
- package/dist/index.cjs +97 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +101 -22
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/src/components/form-dialog.tsx +121 -0
- package/src/index.ts +2 -1
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import * as Dialog from "@radix-ui/react-dialog"
|
|
2
|
+
import { X } from "lucide-react"
|
|
3
|
+
import * as React from "react"
|
|
1
4
|
import type { ReactNode } from "react"
|
|
2
5
|
|
|
6
|
+
import { cn } from "../lib/utils"
|
|
7
|
+
|
|
3
8
|
interface FormDialogLayoutProps {
|
|
4
9
|
title: string
|
|
5
10
|
children: ReactNode
|
|
@@ -46,3 +51,119 @@ export function FormDialogLayout({
|
|
|
46
51
|
</form>
|
|
47
52
|
)
|
|
48
53
|
}
|
|
54
|
+
|
|
55
|
+
const sizeClasses = {
|
|
56
|
+
sm: "sm:max-w-sm",
|
|
57
|
+
md: "sm:max-w-md",
|
|
58
|
+
lg: "sm:max-w-lg",
|
|
59
|
+
xl: "sm:max-w-xl",
|
|
60
|
+
"2xl": "sm:max-w-2xl",
|
|
61
|
+
} as const
|
|
62
|
+
|
|
63
|
+
export type FormDialogSize = keyof typeof sizeClasses
|
|
64
|
+
|
|
65
|
+
interface FormDialogProps {
|
|
66
|
+
open: boolean
|
|
67
|
+
onOpenChange: (open: boolean) => void
|
|
68
|
+
title: string
|
|
69
|
+
description?: ReactNode
|
|
70
|
+
children: ReactNode
|
|
71
|
+
footer?: ReactNode
|
|
72
|
+
/** When provided, the dialog renders a <form> wrapping body + footer. */
|
|
73
|
+
onSubmit?: (e: React.FormEvent<HTMLFormElement>) => void
|
|
74
|
+
size?: FormDialogSize
|
|
75
|
+
className?: string
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Standardized, responsive modal:
|
|
80
|
+
* - mobile: bottom sheet (full width, up to 92vh tall)
|
|
81
|
+
* - desktop: centered dialog (up to 90vh tall)
|
|
82
|
+
* Header and footer stay fixed; only the body scrolls.
|
|
83
|
+
*
|
|
84
|
+
* Also fixes the known Radix bug where `body { pointer-events: none }`
|
|
85
|
+
* can persist after closing a dialog that contained a Select/Popover,
|
|
86
|
+
* which would otherwise make the rest of the page unclickable.
|
|
87
|
+
*/
|
|
88
|
+
export function FormDialog({
|
|
89
|
+
open,
|
|
90
|
+
onOpenChange,
|
|
91
|
+
title,
|
|
92
|
+
description,
|
|
93
|
+
children,
|
|
94
|
+
footer,
|
|
95
|
+
onSubmit,
|
|
96
|
+
size = "lg",
|
|
97
|
+
className,
|
|
98
|
+
}: FormDialogProps) {
|
|
99
|
+
React.useEffect(() => {
|
|
100
|
+
if (open) return
|
|
101
|
+
const id = window.setTimeout(() => {
|
|
102
|
+
if (document.body.style.pointerEvents === "none") {
|
|
103
|
+
document.body.style.pointerEvents = ""
|
|
104
|
+
}
|
|
105
|
+
}, 0)
|
|
106
|
+
return () => window.clearTimeout(id)
|
|
107
|
+
}, [open])
|
|
108
|
+
|
|
109
|
+
const body = (
|
|
110
|
+
<>
|
|
111
|
+
<div className="flex shrink-0 items-start justify-between gap-4 border-b px-6 py-4">
|
|
112
|
+
<div className="min-w-0 space-y-1">
|
|
113
|
+
<Dialog.Title className="text-lg font-semibold leading-none tracking-tight">
|
|
114
|
+
{title}
|
|
115
|
+
</Dialog.Title>
|
|
116
|
+
{description && (
|
|
117
|
+
<Dialog.Description className="text-sm text-muted-foreground">
|
|
118
|
+
{description}
|
|
119
|
+
</Dialog.Description>
|
|
120
|
+
)}
|
|
121
|
+
</div>
|
|
122
|
+
<Dialog.Close
|
|
123
|
+
className="-mr-1 shrink-0 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
|
124
|
+
aria-label="Fechar"
|
|
125
|
+
>
|
|
126
|
+
<X className="h-5 w-5" />
|
|
127
|
+
</Dialog.Close>
|
|
128
|
+
</div>
|
|
129
|
+
<div className="min-h-0 flex-1 overflow-y-auto px-6 py-4">{children}</div>
|
|
130
|
+
{footer && (
|
|
131
|
+
<div className="flex shrink-0 flex-col-reverse gap-2 border-t px-6 py-4 sm:flex-row sm:justify-end">
|
|
132
|
+
{footer}
|
|
133
|
+
</div>
|
|
134
|
+
)}
|
|
135
|
+
</>
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
return (
|
|
139
|
+
<Dialog.Root open={open} onOpenChange={onOpenChange}>
|
|
140
|
+
<Dialog.Portal>
|
|
141
|
+
<Dialog.Overlay className="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" />
|
|
142
|
+
<Dialog.Content
|
|
143
|
+
onCloseAutoFocus={() => {
|
|
144
|
+
document.body.style.pointerEvents = ""
|
|
145
|
+
}}
|
|
146
|
+
className={cn(
|
|
147
|
+
"fixed z-50 flex max-h-[92vh] flex-col bg-background shadow-lg outline-none",
|
|
148
|
+
"inset-x-0 bottom-0 rounded-t-2xl",
|
|
149
|
+
"sm:inset-x-auto sm:bottom-auto sm:left-1/2 sm:top-1/2 sm:max-h-[90vh] sm:w-full sm:-translate-x-1/2 sm:-translate-y-1/2 sm:rounded-lg",
|
|
150
|
+
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
|
151
|
+
sizeClasses[size],
|
|
152
|
+
className,
|
|
153
|
+
)}
|
|
154
|
+
>
|
|
155
|
+
{onSubmit ? (
|
|
156
|
+
<form
|
|
157
|
+
onSubmit={onSubmit}
|
|
158
|
+
className="flex min-h-0 flex-1 flex-col"
|
|
159
|
+
>
|
|
160
|
+
{body}
|
|
161
|
+
</form>
|
|
162
|
+
) : (
|
|
163
|
+
body
|
|
164
|
+
)}
|
|
165
|
+
</Dialog.Content>
|
|
166
|
+
</Dialog.Portal>
|
|
167
|
+
</Dialog.Root>
|
|
168
|
+
)
|
|
169
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -12,7 +12,8 @@ export { StatusBadge } from "./components/status-badge"
|
|
|
12
12
|
export type { StatusBadgeVariant } from "./components/status-badge"
|
|
13
13
|
export { ProgressBar } from "./components/progress-bar"
|
|
14
14
|
export { FormField } from "./components/form-field"
|
|
15
|
-
export { FormDialogLayout } from "./components/form-dialog"
|
|
15
|
+
export { FormDialogLayout, FormDialog } from "./components/form-dialog"
|
|
16
|
+
export type { FormDialogSize } from "./components/form-dialog"
|
|
16
17
|
export { AuthCard } from "./components/auth-card"
|
|
17
18
|
export { Pagination } from "./components/pagination"
|
|
18
19
|
export { TableSkeleton } from "./components/table-skeleton"
|