hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 1 | import { Dialog as DialogPrimitive } from "@kobalte/core/dialog"; |
| 2 | import type { ComponentProps, ParentProps, ValidComponent } from "solid-js"; |
| 3 | import { splitProps } from "solid-js"; |
| 4 | import { IconX } from "@/components/ui/icons"; |
| 5 | import { cn } from "@/lib/cn"; |
| 6 | |
| 7 | export const Dialog = DialogPrimitive; |
| 8 | export const DialogTrigger = DialogPrimitive.Trigger; |
| 9 | export const DialogClose = DialogPrimitive.CloseButton; |
| 10 | |
| 11 | export function DialogContent<T extends ValidComponent = "div">( |
| 12 | props: ComponentProps<typeof DialogPrimitive.Content<T>> & { dismissable?: boolean }, |
| 13 | ) { |
| 14 | const [local, rest] = splitProps(props as ComponentProps<typeof DialogPrimitive.Content> & { dismissable?: boolean }, [ |
| 15 | "class", |
| 16 | "children", |
| 17 | "dismissable", |
| 18 | ]); |
| 19 | return ( |
| 20 | <DialogPrimitive.Portal> |
| 21 | {/* z-[70]: above the mobile nav sheet (z-60) and tab bar (z-40). */} |
| 22 | <DialogPrimitive.Overlay class="fixed inset-0 z-[70] bg-[rgba(13,15,23,0.55)] transition-opacity duration-200" /> |
| 23 | {/* flex center — animate-fade-up must not own transform positioning */} |
| 24 | {/* The centring box is inset by the system bars, so a tall dialog is |
| 25 | never clipped by the status bar or the gesture bar. */} |
| 26 | <div class="pointer-events-none fixed inset-0 z-[70] flex items-center justify-center p-3 pb-[calc(0.75rem+max(env(safe-area-inset-bottom),var(--android-nav-inset,0px)))] pt-[calc(0.75rem+env(safe-area-inset-top))] sm:p-4"> |
| 27 | <DialogPrimitive.Content |
| 28 | // Explicit: with any AlertDialog in the tree, Kobalte hands plain |
| 29 | // dialogs its "alertdialog" role too. |
| 30 | role="dialog" |
| 31 | class={cn( |
| 32 | "pointer-events-auto relative flex max-h-[min(100%,48rem)] w-full max-w-[480px] flex-col overflow-hidden border border-border-line bg-surface-base text-foreground shadow-[0_16px_40px_rgba(0,0,0,0.16)] outline-hidden animate-fade-up sm:rounded-2xl", |
| 33 | local.class, |
| 34 | )} |
| 35 | // Standard dialogs dismiss outside/ESC; pass false only when losing |
| 36 | // unsaved state would be unsafe. |
| 37 | onPointerDownOutside={local.dismissable === false ? (e) => e.preventDefault() : undefined} |
| 38 | onInteractOutside={local.dismissable === false ? (e) => e.preventDefault() : undefined} |
| 39 | onEscapeKeyDown={local.dismissable === false ? (e) => e.preventDefault() : undefined} |
| 40 | {...rest} |
| 41 | > |
| 42 | <DialogPrimitive.CloseButton |
| 43 | type="button" |
| 44 | class="absolute right-4 top-4 z-10 inline-flex h-8 w-8 items-center justify-center rounded-sm text-muted-foreground transition-all hover:bg-accent hover:text-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2" |
| 45 | aria-label="Close" |
| 46 | > |
| 47 | <IconX class="h-4 w-4" /> |
| 48 | </DialogPrimitive.CloseButton> |
| 49 | {local.children} |
| 50 | </DialogPrimitive.Content> |
| 51 | </div> |
| 52 | </DialogPrimitive.Portal> |
| 53 | ); |
| 54 | } |
| 55 | |
| 56 | export function DialogHeader(props: ParentProps<{ class?: string }>) { |
| 57 | return <div class={cn("flex flex-col space-y-1.5 border-b border-border-hairline px-5 py-5 pr-14 text-center sm:px-7 sm:text-left", props.class)}>{props.children}</div>; |
| 58 | } |
| 59 | |
| 60 | export function DialogBody(props: ParentProps<{ class?: string }>) { |
| 61 | return <div class={cn("overflow-y-auto overscroll-contain px-5 py-5 sm:px-7", props.class)}>{props.children}</div>; |
| 62 | } |
| 63 | |
| 64 | export function DialogTitle<T extends ValidComponent = "h2">( |
| 65 | props: ComponentProps<typeof DialogPrimitive.Title<T>>, |
| 66 | ) { |
| 67 | const [local, rest] = splitProps(props as ComponentProps<typeof DialogPrimitive.Title>, ["class"]); |
| 68 | return ( |
| 69 | <DialogPrimitive.Title |
| 70 | class={cn("text-lg font-semibold leading-none tracking-tight", local.class)} |
| 71 | {...rest} |
| 72 | /> |
| 73 | ); |
| 74 | } |
| 75 | |
| 76 | export function DialogDescription<T extends ValidComponent = "p">( |
| 77 | props: ComponentProps<typeof DialogPrimitive.Description<T>>, |
| 78 | ) { |
| 79 | const [local, rest] = splitProps(props as ComponentProps<typeof DialogPrimitive.Description>, ["class"]); |
| 80 | return ( |
| 81 | <DialogPrimitive.Description |
| 82 | class={cn("mt-1.5 text-sm text-muted-foreground", local.class)} |
| 83 | {...rest} |
| 84 | /> |
| 85 | ); |
| 86 | } |