mirror of
https://github.com/andwati/dokploy.git
synced 2026-12-06 01:28:46 +00:00
fix(ui): code formatting and DialogHeader improvements
- Apply consistent code formatting across dialog components - Add bottom padding to DialogHeader for better visual separation - Clean up DialogHeader usage in swarm settings (remove duplicate padding) - Improve schedule dialog layout and add proper description - Fix indentation and formatting inconsistencies Final cleanup of dialog component formatting and spacing.
This commit is contained in:
@@ -1,16 +1,25 @@
|
||||
import { cn } from "@/lib/utils";
|
||||
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
||||
import { X } from "lucide-react";
|
||||
import * as React from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const DialogContext = React.createContext<{
|
||||
onOpenChange?: (open: boolean) => void;
|
||||
open?: boolean;
|
||||
}>({});
|
||||
|
||||
const Dialog = ({ onOpenChange, open, ...props }: React.ComponentPropsWithoutRef<typeof DialogPrimitive.Root>) => (
|
||||
const Dialog = ({
|
||||
onOpenChange,
|
||||
open,
|
||||
...props
|
||||
}: React.ComponentPropsWithoutRef<typeof DialogPrimitive.Root>) => (
|
||||
<DialogContext.Provider value={{ onOpenChange, open }}>
|
||||
<DialogPrimitive.Root open={open} onOpenChange={onOpenChange} {...props} modal={false}/>
|
||||
<DialogPrimitive.Root
|
||||
open={open}
|
||||
onOpenChange={onOpenChange}
|
||||
{...props}
|
||||
modal={false}
|
||||
/>
|
||||
</DialogContext.Provider>
|
||||
);
|
||||
Dialog.displayName = DialogPrimitive.Root.displayName;
|
||||
@@ -44,18 +53,19 @@ const DialogContent = React.forwardRef<
|
||||
const { onOpenChange, open } = React.useContext(DialogContext);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!open) return;
|
||||
|
||||
const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
|
||||
if (!open) return;
|
||||
|
||||
const scrollbarWidth =
|
||||
window.innerWidth - document.documentElement.clientWidth;
|
||||
const body = document.body;
|
||||
const originalPaddingRight = body.style.paddingRight;
|
||||
const originalOverflow = body.style.overflow;
|
||||
|
||||
body.style.overflow = 'hidden';
|
||||
|
||||
body.style.overflow = "hidden";
|
||||
if (scrollbarWidth > 0) {
|
||||
body.style.paddingRight = `${scrollbarWidth}px`;
|
||||
}
|
||||
|
||||
|
||||
return () => {
|
||||
body.style.overflow = originalOverflow;
|
||||
body.style.paddingRight = originalPaddingRight;
|
||||
@@ -63,23 +73,26 @@ const DialogContent = React.forwardRef<
|
||||
}, [open]);
|
||||
|
||||
// Handle outside interactions properly with Command components
|
||||
const handleInteractOutside = React.useCallback((e: Event) => {
|
||||
if (onOpenChange) {
|
||||
onOpenChange(false);
|
||||
}
|
||||
}, [onOpenChange]);
|
||||
const handleInteractOutside = React.useCallback(
|
||||
(_e: Event) => {
|
||||
if (onOpenChange) {
|
||||
onOpenChange(false);
|
||||
}
|
||||
},
|
||||
[onOpenChange],
|
||||
);
|
||||
|
||||
const hasPaddingOverride = className?.includes("p-0");
|
||||
|
||||
|
||||
// Separate DialogFooter from other children for proper layout
|
||||
const childrenArray = React.Children.toArray(children);
|
||||
const dialogFooter = childrenArray.find((child) =>
|
||||
React.isValidElement(child) && child.type === DialogFooter
|
||||
const dialogFooter = childrenArray.find(
|
||||
(child) => React.isValidElement(child) && child.type === DialogFooter,
|
||||
);
|
||||
const otherChildren = childrenArray.filter((child) =>
|
||||
!(React.isValidElement(child) && child.type === DialogFooter)
|
||||
const otherChildren = childrenArray.filter(
|
||||
(child) => !(React.isValidElement(child) && child.type === DialogFooter),
|
||||
);
|
||||
|
||||
|
||||
return (
|
||||
<DialogPortal>
|
||||
{/* Custom overlay for modal=false - no click handler to avoid Command conflicts */}
|
||||
@@ -94,9 +107,11 @@ const DialogContent = React.forwardRef<
|
||||
onInteractOutside={(e) => {
|
||||
const target = e.target as HTMLElement;
|
||||
// Don't close when clicking inside popovers, dropdowns, or command components
|
||||
if (target.closest('[data-radix-popper-content-wrapper]') ||
|
||||
target.closest('[cmdk-root]') ||
|
||||
target.closest('[data-radix-command-root]')) {
|
||||
if (
|
||||
target.closest("[data-radix-popper-content-wrapper]") ||
|
||||
target.closest("[cmdk-root]") ||
|
||||
target.closest("[data-radix-command-root]")
|
||||
) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
@@ -105,23 +120,23 @@ const DialogContent = React.forwardRef<
|
||||
}}
|
||||
{...props}
|
||||
>
|
||||
<div
|
||||
<div
|
||||
ref={contentRef}
|
||||
className={cn(
|
||||
"overflow-y-auto overflow-x-hidden flex-1 min-h-0 overscroll-contain",
|
||||
!hasPaddingOverride && "p-6"
|
||||
!hasPaddingOverride && "p-6",
|
||||
)}
|
||||
>
|
||||
{otherChildren}
|
||||
</div>
|
||||
|
||||
|
||||
{/* DialogFooter outside scrollable area with proper spacing */}
|
||||
{dialogFooter && (
|
||||
<div className="p-6 pt-0 border-t border-border/50">
|
||||
{dialogFooter}
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
|
||||
<X className="h-4 w-4" />
|
||||
<span className="sr-only">Close</span>
|
||||
@@ -138,7 +153,7 @@ const DialogHeader = ({
|
||||
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-col space-y-1.5 text-center sm:text-left",
|
||||
"flex flex-col space-y-1.5 text-center sm:text-left pb-4",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
@@ -198,4 +213,4 @@ export {
|
||||
DialogFooter,
|
||||
DialogTitle,
|
||||
DialogDescription,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user