Skip to content

LLM inference in C/C++

C++ ggml

ui: Update Dialog component styling (#27743)

Aleksander Grygier0379a19f0949
diff --git a/tools/ui/src/lib/components/app/dialogs/DialogMermaidPreview.svelte b/tools/ui/src/lib/components/app/dialogs/DialogMermaidPreview.svelte
index 09e53442ac..e741373497 100644
--- a/tools/ui/src/lib/components/app/dialogs/DialogMermaidPreview.svelte
+++ b/tools/ui/src/lib/components/app/dialogs/DialogMermaidPreview.svelte
@@ -14,6 +14,7 @@
<Dialog.Root bind:open {onOpenChange}>
<Dialog.Content
class="z-999999 grid max-h-full max-w-full! grid-rows-[1fr_auto] overflow-hidden p-0 md:h-[90vh] md:max-w-[90vw]!"
+ showCloseButton
>
<MermaidPreview {svgHtml} />
</Dialog.Content>
diff --git a/tools/ui/src/lib/components/ui/dialog/dialog-close.svelte b/tools/ui/src/lib/components/ui/dialog/dialog-close.svelte
index e8a96a7731..cd957a9bf8 100644
--- a/tools/ui/src/lib/components/ui/dialog/dialog-close.svelte
+++ b/tools/ui/src/lib/components/ui/dialog/dialog-close.svelte
@@ -5,3 +5,9 @@
</script>
<DialogPrimitive.Close bind:ref data-slot="dialog-close" {...restProps} />
+
+<style>
+ :global([data-dialog-close]) {
+ z-index: 999;
+ }
+</style>
diff --git a/tools/ui/src/lib/components/ui/dialog/dialog-content.svelte b/tools/ui/src/lib/components/ui/dialog/dialog-content.svelte
index e6b2a641d5..8a1a5909d5 100644
--- a/tools/ui/src/lib/components/ui/dialog/dialog-content.svelte
+++ b/tools/ui/src/lib/components/ui/dialog/dialog-content.svelte
@@ -10,7 +10,7 @@
class: className,
portalProps,
ref = $bindable(null),
- showCloseButton = true,
+ showCloseButton = false,
...restProps
}: WithoutChildrenOrChild<DialogPrimitive.ContentProps> & {
portalProps?: DialogPrimitive.PortalProps;
@@ -25,7 +25,8 @@
<DialogPrimitive.Content
bind:ref
class={cn(
- `fixed top-[50%] left-[50%] z-50 grid max-h-[100dvh] w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 overflow-y-auto rounded-lg border border-border/30 bg-background p-6 shadow-lg duration-200 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:fill-mode-forwards data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg md:max-h-[100vh]`,
+ `fixed top-[50%] left-[50%] z-50 grid translate-x-[-50%] translate-y-[-50%] gap-4 overflow-y-auto rounded-lg border border-border/30 bg-background p-6 shadow-lg duration-200 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:fill-mode-forwards data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,
+ 'max-h-[100dvh] max-w-full size-auto sm:max-w-lg md:w-auto md:size-auto md:max-w-[calc(100%-2rem)]',
className
)}
data-slot="dialog-content"
diff --git a/tools/ui/src/lib/components/ui/dialog/dialog-header.svelte b/tools/ui/src/lib/components/ui/dialog/dialog-header.svelte
index f562694145..fd590e1860 100644
--- a/tools/ui/src/lib/components/ui/dialog/dialog-header.svelte
+++ b/tools/ui/src/lib/components/ui/dialog/dialog-header.svelte
@@ -1,20 +1,43 @@
<script lang="ts">
+ import XIcon from '@lucide/svelte/icons/x';
import { cn, type WithElementRef } from '$lib/components/ui/utils';
+ import { Dialog as DialogPrimitive } from 'bits-ui';
import type { HTMLAttributes } from 'svelte/elements';
let {
children,
class: className,
ref = $bindable(null),
+ showCloseButton = true,
...restProps
- }: WithElementRef<HTMLAttributes<HTMLDivElement>> = $props();
+ }: WithElementRef<HTMLAttributes<HTMLDivElement>> & {
+ showCloseButton?: boolean;
+ } = $props();
</script>
+<!--
+ Header is `sticky`, so it stays at the top while the dialog body scrolls. The close
+ button lives here (not in the body) so it sticks together with the title. `sticky`
+ makes it the containing block, so the close can be absolutely placed at its corner.
+-->
<div
bind:this={ref}
- class={cn('flex flex-col gap-2 text-center sm:text-left', className)}
+ class={cn(
+ 'flex flex-col gap-2 text-center sm:text-left sticky top-0 z-50 bg-background md:bg-transparent',
+ className
+ )}
data-slot="dialog-header"
{...restProps}
>
{@render children?.()}
+
+ {#if showCloseButton}
+ <DialogPrimitive.Close
+ class="absolute top-0 right-0 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"
+ >
+ <XIcon />
+
+ <span class="sr-only">Close</span>
+ </DialogPrimitive.Close>
+ {/if}
</div>