Kit Dialog
UI8Kit 3 Dialog primitive (unstyled), from @ui8kit/registry
Install
npx ui8kit add kit-dialogPulls in: utils
Preview
No static preview for this item: it needs content or a parent that this page cannot supply. The code is below.
Code
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework svelte --dir src --registry-url https://registry.buildy.tw/svelte --strict-cdnnpx ui8kit add kit-dialog<!-- Code generated by @ui8kit/codegen. DO NOT EDIT. -->
<!--
Dialog renders a native dialog element.
-->
<script lang="ts" module>
import type { Snippet } from "svelte";
export type DialogProps = {
open?: boolean;
class?: string;
children?: Snippet;
[key: string]: unknown;
};
</script>
<script lang="ts">
import { dialogClasses } from "./dialog.shared";
import { safeRest } from "../../utils/expr";
let {
open,
class: className,
children,
...rawRest
}: DialogProps = $props();
const rest = $derived(safeRest(rawRest, { blank: ["id", "aria-labelledby", "aria-describedby", "aria-label"] }));
const cls = $derived(dialogClasses({ className }));
</script>
<dialog {...(cls ? { class: cls } : {})} open={open || undefined} {...rest}>
{@render children?.()}
</dialog>
// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.dialog — shared TypeScript contract (types + classes helpers)
import { cn } from "../../utils";
/** Dialog renders a native dialog element. */
export type DialogBaseProps = {
open?: boolean;
};
export type DialogClassesInput = {
className?: string;
};
/** Compose Dialog classes without rendering — the cross-runtime `asChild` substitute. */
export function dialogClasses(input: DialogClassesInput = {}): string {
return cn(input.className);
}
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework react --dir src --registry-url https://registry.buildy.tw/react --strict-cdnnpx ui8kit add kit-dialog// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.dialog — shared TypeScript contract (types + classes helpers)
import { cn } from "../../utils";
/** Dialog renders a native dialog element. */
export type DialogBaseProps = {
open?: boolean;
};
export type DialogClassesInput = {
className?: string;
};
/** Compose Dialog classes without rendering — the cross-runtime `asChild` substitute. */
export function dialogClasses(input: DialogClassesInput = {}): string {
return cn(input.className);
}
// Code generated by @ui8kit/codegen. DO NOT EDIT.
/**
* Dialog is the native <dialog>. Opening/closing (showModal) is the consumer's.
*/
import { forwardRef, type ReactNode, type DialogHTMLAttributes } from "react";
import { dialogClasses } from "./dialog.shared";
import { safeRest } from "../../utils/expr";
/**
* Dialog renders a native dialog element.
*/
export type DialogProps = Omit<DialogHTMLAttributes<HTMLDialogElement>, "className" | "children" | "open"> & {
open?: boolean;
className?: string;
children?: ReactNode;
};
export const Dialog = forwardRef<HTMLDialogElement, DialogProps>(function Dialog(
{ open, className, children, ...rawRest },
ref
) {
const rest = safeRest(rawRest, { blank: ["id", "aria-labelledby", "aria-describedby", "aria-label"] });
const cls = dialogClasses({ className });
return (
<dialog ref={ref} className={cls || undefined} open={open} {...rest}>
{children}
</dialog>
);
});
Dialog.displayName = "Dialog";
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework vue --dir src --registry-url https://registry.buildy.tw/vue --strict-cdnnpx ui8kit add kit-dialog<!-- Code generated by @ui8kit/codegen. DO NOT EDIT. -->
<!--
Dialog renders a native dialog element.
-->
<script setup lang="ts">
import { computed, useAttrs } from "vue";
import { dialogClasses } from "./dialog.shared";
import { safeRest } from "../../utils/expr";
defineOptions({ name: "Dialog", inheritAttrs: false });
const props = defineProps<{
open?: boolean;
}>();
const attrs = useAttrs();
const callerClass = computed(() => attrs.class as string | undefined);
const restAttrs = computed(() => {
const { class: _class, ...restEntries } = attrs;
return safeRest(restEntries, { blank: ["id", "aria-labelledby", "aria-describedby", "aria-label"] });
});
const cls = computed(() => dialogClasses({ className: callerClass.value }));
</script>
<template>
<dialog :class="cls || undefined" :open="props.open || undefined" v-bind="restAttrs">
<slot />
</dialog>
</template>
// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.dialog — shared TypeScript contract (types + classes helpers)
import { cn } from "../../utils";
/** Dialog renders a native dialog element. */
export type DialogBaseProps = {
open?: boolean;
};
export type DialogClassesInput = {
className?: string;
};
/** Compose Dialog classes without rendering — the cross-runtime `asChild` substitute. */
export function dialogClasses(input: DialogClassesInput = {}): string {
return cn(input.className);
}
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework solid --dir src --registry-url https://registry.buildy.tw/solid --strict-cdnnpx ui8kit add kit-dialog// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.dialog — shared TypeScript contract (types + classes helpers)
import { cn } from "../../utils";
/** Dialog renders a native dialog element. */
export type DialogBaseProps = {
open?: boolean;
};
export type DialogClassesInput = {
className?: string;
};
/** Compose Dialog classes without rendering — the cross-runtime `asChild` substitute. */
export function dialogClasses(input: DialogClassesInput = {}): string {
return cn(input.className);
}
// Code generated by @ui8kit/codegen. DO NOT EDIT.
/**
* Dialog is the native <dialog>. Opening/closing (showModal) is the consumer's.
*/
import { splitProps, type JSX, type Component } from "solid-js";
import { dialogClasses } from "./dialog.shared";
import { safeRest } from "../../utils/expr";
/**
* Dialog renders a native dialog element.
*/
export type DialogProps = Omit<JSX.DialogHtmlAttributes<HTMLDialogElement>, "class" | "className" | "children" | "open"> & {
open?: boolean;
class?: string;
className?: string;
children?: JSX.Element;
};
export const Dialog: Component<DialogProps> = (props) => {
const [local, rest] = splitProps(props, ["open", "class", "className", "children"]);
const cls = () => dialogClasses({ className: local.class ?? local.className });
return (
<dialog {...(cls() ? { class: cls() } : {})} open={local.open || undefined} {...safeRest(rest, { blank: ["id", "aria-labelledby", "aria-describedby", "aria-label"] })}>
{local.children}
</dialog>
);
};
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework templ --dir src --registry-url https://registry.buildy.tw/templ --strict-cdnnpx ui8kit add kit-dialog// Code generated by @ui8kit/codegen. DO NOT EDIT.
/*
Dialog is the native <dialog>. Opening/closing (showModal) is the consumer's.
*/
package dialog
import (
uiutils "github.com/ui8kit/codegen/generated/templ/utils"
)
// DialogProps configures Dialog.
type DialogProps struct {
// Class — token class names supplied by the consumer
Class string
ID string
// Open — initial open state
Open bool
AriaLabelledBy string
AriaDescribedBy string
AriaLabel string
Attrs templ.Attributes
}
// DialogClasses composes Dialog classes without rendering —
// the server-composition escape hatch for custom root elements (no asChild in templ).
func DialogClasses(p DialogProps) string {
return uiutils.Cn(p.Class)
}
// Dialog renders the Dialog contract.
templ Dialog(p DialogProps) {
<dialog
if DialogClasses(p) != "" {
class={ DialogClasses(p) }
}
if !uiutils.HasAttr(p.Attrs, "id") {
if uiutils.IsSetStr(p.ID) {
id={ p.ID }
}
}
if !uiutils.HasAttr(p.Attrs, "open") {
open?={ p.Open }
}
if !uiutils.HasAttr(p.Attrs, "aria-labelledby") {
if uiutils.IsSetStr(p.AriaLabelledBy) {
aria-labelledby={ p.AriaLabelledBy }
}
}
if !uiutils.HasAttr(p.Attrs, "aria-describedby") {
if uiutils.IsSetStr(p.AriaDescribedBy) {
aria-describedby={ p.AriaDescribedBy }
}
}
if !uiutils.HasAttr(p.Attrs, "aria-label") {
if uiutils.IsSetStr(p.AriaLabel) {
aria-label={ p.AriaLabel }
}
}
{ uiutils.RestAttrs(p.Attrs, false, "id", "aria-labelledby", "aria-describedby", "aria-label")... }
>
{ children... }
</dialog>
}
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework twig --dir src --registry-url https://registry.buildy.tw/twig --strict-cdnnpx ui8kit add kit-dialog{# Code generated by @ui8kit/codegen. DO NOT EDIT. #}
{# Dialog — Dialog renders a native dialog element. #}
{# @param class (string) #}
{# @param id (string) #}
{# @param open (bool) #}
{# @param ariaLabelledBy (string) #}
{# @param ariaDescribedBy (string) #}
{# @param ariaLabel (string) #}
{# @param attrs (attrs) #}
{# @param children (children) #}
{% set class = class|default('') %}
{% set id = id ?? null %}
{% set open = open|default(false) %}
{% set ariaLabelledBy = ariaLabelledBy ?? null %}
{% set ariaDescribedBy = ariaDescribedBy ?? null %}
{% set ariaLabel = ariaLabel ?? null %}
{% set attrs = attrs|default([]) %}
{% set children = children|default('') %}
<dialog{{ ui8kit_attrs({'class': ui8kit_or_null(ui8kit_classes('dialogClasses', {'class': class, 'id': id, 'open': open, 'ariaLabelledBy': ariaLabelledBy, 'ariaDescribedBy': ariaDescribedBy, 'ariaLabel': ariaLabel})), 'id': ui8kit_or_null(id), 'open': open, 'aria-labelledby': ui8kit_or_null(ariaLabelledBy), 'aria-describedby': ui8kit_or_null(ariaDescribedBy), 'aria-label': ui8kit_or_null(ariaLabel)}, attrs, false, ['id', 'aria-labelledby', 'aria-describedby', 'aria-label']) }}>{{ children|raw }}</dialog>
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework latte --dir src --registry-url https://registry.buildy.tw/latte --strict-cdnnpx ui8kit add kit-dialog{* Code generated by @ui8kit/codegen. DO NOT EDIT. *}
{* Dialog — Dialog renders a native dialog element. *}
{parameters
string $class = '',
?string $id = null,
bool $open = false,
?string $ariaLabelledBy = null,
?string $ariaDescribedBy = null,
?string $ariaLabel = null,
array $attrs = [],
string $children = '',
}
<dialog n:attr="[
'class' => \UI8Kit\Latte\Rt::orNull(\UI8Kit\Latte\Classes::dialogClasses(['class' => $class, 'id' => $id, 'open' => $open, 'ariaLabelledBy' => $ariaLabelledBy, 'ariaDescribedBy' => $ariaDescribedBy, 'ariaLabel' => $ariaLabel])),
'id' => \UI8Kit\Latte\Rt::orNull($id),
'open' => $open,
'aria-labelledby' => \UI8Kit\Latte\Rt::orNull($ariaLabelledBy),
'aria-describedby' => \UI8Kit\Latte\Rt::orNull($ariaDescribedBy),
'aria-label' => \UI8Kit\Latte\Rt::orNull($ariaLabel),
...\UI8Kit\Latte\Rt::restAttrs($attrs, false, ['id', 'aria-labelledby', 'aria-describedby', 'aria-label']),
]">{$children|noescape}</dialog>Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework jinja2 --dir src --registry-url https://registry.buildy.tw/jinja2 --strict-cdnnpx ui8kit add kit-dialog{#- Code generated by @ui8kit/codegen. DO NOT EDIT.
Dialog: Dialog renders a native dialog element.
Props (p): Class (string), ID (string), Open (bool), AriaLabelledBy (string), AriaDescribedBy (string), AriaLabel (string), Attrs (attrs), Children (children).
children: TRUSTED HTML printed with |safe — never pass unescaped user input.
Classes without rendering: dialog_classes(p) (no asChild in Jinja2). -#}
<dialog
{%- with cls = dialog_classes(p) %}{%- if cls %} class="{{ cls }}"{%- endif %}{%- endwith %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'id') %}{%- if ui_is_set_str(p['ID']) %} id="{{ p['ID'] }}"{%- endif %}{%- endif %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'open') %}{%- if ui_def(p['Open'], false) %} open{%- endif %}{%- endif %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'aria-labelledby') %}{%- if ui_is_set_str(p['AriaLabelledBy']) %} aria-labelledby="{{ p['AriaLabelledBy'] }}"{%- endif %}{%- endif %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'aria-describedby') %}{%- if ui_is_set_str(p['AriaDescribedBy']) %} aria-describedby="{{ p['AriaDescribedBy'] }}"{%- endif %}{%- endif %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'aria-label') %}{%- if ui_is_set_str(p['AriaLabel']) %} aria-label="{{ p['AriaLabel'] }}"{%- endif %}{%- endif %}
{{ ui_attr_html(ui_def(p['Attrs'], {}), false, ['id', 'aria-labelledby', 'aria-describedby', 'aria-label']) }}
>{{ children|default('', true)|safe }}</dialog>
Props
Names and types come from the xgen specs of the source. Standard HTML attributes (id, role, tabIndex, aria-*) pass through to the root element; the class prop is className in React.
No props data for this item.