Kit Disclosure
UI8Kit 3 Disclosure primitive (unstyled), from @ui8kit/registry
Install
npx ui8kit add kit-disclosurePulls 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-disclosure<!-- Code generated by @ui8kit/codegen. DO NOT EDIT. -->
<!--
Disclosure renders a native details element.
-->
<script lang="ts" module>
import type { Snippet } from "svelte";
export type DisclosureProps = {
open?: boolean;
class?: string;
children?: Snippet;
[key: string]: unknown;
};
</script>
<script lang="ts">
import { disclosureClasses } from "./disclosure.shared";
import { safeRest } from "../../utils/expr";
let {
open,
class: className,
children,
...rawRest
}: DisclosureProps = $props();
const rest = $derived(safeRest(rawRest, { blank: ["name"] }));
const cls = $derived(disclosureClasses({ className }));
</script>
<details {...(cls ? { class: cls } : {})} open={open || undefined} {...rest}>
{@render children?.()}
</details>
<!-- Code generated by @ui8kit/codegen. DO NOT EDIT. -->
<!--
Summary renders the native summary (the disclosure trigger).
-->
<script lang="ts" module>
import type { Snippet } from "svelte";
export type SummaryProps = {
class?: string;
children?: Snippet;
[key: string]: unknown;
};
</script>
<script lang="ts">
import { summaryClasses } from "./disclosure.shared";
import { safeRest } from "../../utils/expr";
let {
class: className,
children,
...rawRest
}: SummaryProps = $props();
const rest = $derived(safeRest(rawRest));
const cls = $derived(summaryClasses({ className }));
</script>
<summary {...(cls ? { class: cls } : {})} {...rest}>
{@render children?.()}
</summary>
// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.disclosure — shared TypeScript contract (types + classes helpers)
import { cn } from "../../utils";
/** Disclosure renders a native details element. */
export type DisclosureBaseProps = {
open?: boolean;
};
export type DisclosureClassesInput = {
className?: string;
};
/** Compose Disclosure classes without rendering — the cross-runtime `asChild` substitute. */
export function disclosureClasses(input: DisclosureClassesInput = {}): string {
return cn(input.className);
}
/** Summary renders the native summary (the disclosure trigger). */
export type SummaryBaseProps = {
};
export type SummaryClassesInput = {
className?: string;
};
/** Compose Summary classes without rendering — the cross-runtime `asChild` substitute. */
export function summaryClasses(input: SummaryClassesInput = {}): 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-disclosure// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.disclosure — shared TypeScript contract (types + classes helpers)
import { cn } from "../../utils";
/** Disclosure renders a native details element. */
export type DisclosureBaseProps = {
open?: boolean;
};
export type DisclosureClassesInput = {
className?: string;
};
/** Compose Disclosure classes without rendering — the cross-runtime `asChild` substitute. */
export function disclosureClasses(input: DisclosureClassesInput = {}): string {
return cn(input.className);
}
/** Summary renders the native summary (the disclosure trigger). */
export type SummaryBaseProps = {
};
export type SummaryClassesInput = {
className?: string;
};
/** Compose Summary classes without rendering — the cross-runtime `asChild` substitute. */
export function summaryClasses(input: SummaryClassesInput = {}): string {
return cn(input.className);
}
// Code generated by @ui8kit/codegen. DO NOT EDIT.
/**
* Disclosure is native details/summary. `name` groups exclusive accordions.
*/
import { forwardRef, type ReactNode, type DetailsHTMLAttributes, type HTMLAttributes } from "react";
import { disclosureClasses, summaryClasses } from "./disclosure.shared";
import { safeRest } from "../../utils/expr";
/**
* Disclosure renders a native details element.
*/
export type DisclosureProps = Omit<DetailsHTMLAttributes<HTMLDetailsElement>, "className" | "children" | "open"> & {
open?: boolean;
className?: string;
children?: ReactNode;
};
export const Disclosure = forwardRef<HTMLDetailsElement, DisclosureProps>(function Disclosure(
{ open, className, children, ...rawRest },
ref
) {
const rest = safeRest(rawRest, { blank: ["name"] });
const cls = disclosureClasses({ className });
return (
<details ref={ref} className={cls || undefined} open={open} {...rest}>
{children}
</details>
);
});
Disclosure.displayName = "Disclosure";
/**
* Summary renders the native summary (the disclosure trigger).
*/
export type SummaryProps = Omit<HTMLAttributes<HTMLElement>, "className" | "children"> & {
className?: string;
children?: ReactNode;
};
export const Summary = forwardRef<HTMLElement, SummaryProps>(function Summary(
{ className, children, ...rawRest },
ref
) {
const rest = safeRest(rawRest);
const cls = summaryClasses({ className });
return (
<summary ref={ref} className={cls || undefined} {...rest}>
{children}
</summary>
);
});
Summary.displayName = "Summary";
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-disclosure<!-- Code generated by @ui8kit/codegen. DO NOT EDIT. -->
<!--
Disclosure renders a native details element.
-->
<script setup lang="ts">
import { computed, useAttrs } from "vue";
import { disclosureClasses } from "./disclosure.shared";
import { safeRest } from "../../utils/expr";
defineOptions({ name: "Disclosure", 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: ["name"] });
});
const cls = computed(() => disclosureClasses({ className: callerClass.value }));
</script>
<template>
<details :class="cls || undefined" :open="props.open || undefined" v-bind="restAttrs">
<slot />
</details>
</template>
<!-- Code generated by @ui8kit/codegen. DO NOT EDIT. -->
<!--
Summary renders the native summary (the disclosure trigger).
-->
<script setup lang="ts">
import { computed, useAttrs } from "vue";
import { summaryClasses } from "./disclosure.shared";
import { safeRest } from "../../utils/expr";
defineOptions({ name: "Summary", inheritAttrs: false });
const attrs = useAttrs();
const callerClass = computed(() => attrs.class as string | undefined);
const restAttrs = computed(() => {
const { class: _class, ...restEntries } = attrs;
return safeRest(restEntries);
});
const cls = computed(() => summaryClasses({ className: callerClass.value }));
</script>
<template>
<summary :class="cls || undefined" v-bind="restAttrs">
<slot />
</summary>
</template>
// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.disclosure — shared TypeScript contract (types + classes helpers)
import { cn } from "../../utils";
/** Disclosure renders a native details element. */
export type DisclosureBaseProps = {
open?: boolean;
};
export type DisclosureClassesInput = {
className?: string;
};
/** Compose Disclosure classes without rendering — the cross-runtime `asChild` substitute. */
export function disclosureClasses(input: DisclosureClassesInput = {}): string {
return cn(input.className);
}
/** Summary renders the native summary (the disclosure trigger). */
export type SummaryBaseProps = {
};
export type SummaryClassesInput = {
className?: string;
};
/** Compose Summary classes without rendering — the cross-runtime `asChild` substitute. */
export function summaryClasses(input: SummaryClassesInput = {}): 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-disclosure// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.disclosure — shared TypeScript contract (types + classes helpers)
import { cn } from "../../utils";
/** Disclosure renders a native details element. */
export type DisclosureBaseProps = {
open?: boolean;
};
export type DisclosureClassesInput = {
className?: string;
};
/** Compose Disclosure classes without rendering — the cross-runtime `asChild` substitute. */
export function disclosureClasses(input: DisclosureClassesInput = {}): string {
return cn(input.className);
}
/** Summary renders the native summary (the disclosure trigger). */
export type SummaryBaseProps = {
};
export type SummaryClassesInput = {
className?: string;
};
/** Compose Summary classes without rendering — the cross-runtime `asChild` substitute. */
export function summaryClasses(input: SummaryClassesInput = {}): string {
return cn(input.className);
}
// Code generated by @ui8kit/codegen. DO NOT EDIT.
/**
* Disclosure is native details/summary. `name` groups exclusive accordions.
*/
import { splitProps, type JSX, type Component } from "solid-js";
import { disclosureClasses, summaryClasses } from "./disclosure.shared";
import { safeRest } from "../../utils/expr";
/**
* Disclosure renders a native details element.
*/
export type DisclosureProps = Omit<JSX.DetailsHtmlAttributes<HTMLDetailsElement>, "class" | "className" | "children" | "open"> & {
open?: boolean;
class?: string;
className?: string;
children?: JSX.Element;
};
export const Disclosure: Component<DisclosureProps> = (props) => {
const [local, rest] = splitProps(props, ["open", "class", "className", "children"]);
const cls = () => disclosureClasses({ className: local.class ?? local.className });
return (
<details {...(cls() ? { class: cls() } : {})} open={local.open || undefined} {...safeRest(rest, { blank: ["name"] })}>
{local.children}
</details>
);
};
/**
* Summary renders the native summary (the disclosure trigger).
*/
export type SummaryProps = Omit<JSX.HTMLAttributes<HTMLElement>, "class" | "className" | "children"> & {
class?: string;
className?: string;
children?: JSX.Element;
};
export const Summary: Component<SummaryProps> = (props) => {
const [local, rest] = splitProps(props, ["class", "className", "children"]);
const cls = () => summaryClasses({ className: local.class ?? local.className });
return (
<summary {...(cls() ? { class: cls() } : {})} {...safeRest(rest)}>
{local.children}
</summary>
);
};
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-disclosure// Code generated by @ui8kit/codegen. DO NOT EDIT.
/*
Disclosure is native details/summary. `name` groups exclusive accordions.
*/
package disclosure
import (
uiutils "github.com/ui8kit/codegen/generated/templ/utils"
)
// DisclosureProps configures Disclosure.
type DisclosureProps struct {
// Class — token class names supplied by the consumer
Class string
// Open — initial open state
Open bool
Name string
Attrs templ.Attributes
}
// DisclosureClasses composes Disclosure classes without rendering —
// the server-composition escape hatch for custom root elements (no asChild in templ).
func DisclosureClasses(p DisclosureProps) string {
return uiutils.Cn(p.Class)
}
// Disclosure renders the Disclosure contract.
templ Disclosure(p DisclosureProps) {
<details
if DisclosureClasses(p) != "" {
class={ DisclosureClasses(p) }
}
if !uiutils.HasAttr(p.Attrs, "open") {
open?={ p.Open }
}
if !uiutils.HasAttr(p.Attrs, "name") {
if uiutils.IsSetStr(p.Name) {
name={ p.Name }
}
}
{ uiutils.RestAttrs(p.Attrs, false, "name")... }
>
{ children... }
</details>
}
// SummaryProps configures Summary.
type SummaryProps struct {
// Class — token class names supplied by the consumer
Class string
Attrs templ.Attributes
}
// SummaryClasses composes Summary classes without rendering —
// the server-composition escape hatch for custom root elements (no asChild in templ).
func SummaryClasses(p SummaryProps) string {
return uiutils.Cn(p.Class)
}
// Summary renders the Summary contract.
templ Summary(p SummaryProps) {
<summary
if SummaryClasses(p) != "" {
class={ SummaryClasses(p) }
}
{ uiutils.RestAttrs(p.Attrs, false)... }
>
{ children... }
</summary>
}
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-disclosure{# Code generated by @ui8kit/codegen. DO NOT EDIT. #}
{# Disclosure — Disclosure renders a native details element. #}
{# @param class (string) #}
{# @param open (bool) #}
{# @param name (string) #}
{# @param attrs (attrs) #}
{# @param children (children) #}
{% set class = class|default('') %}
{% set open = open|default(false) %}
{% set name = name ?? null %}
{% set attrs = attrs|default([]) %}
{% set children = children|default('') %}
<details{{ ui8kit_attrs({'class': ui8kit_or_null(ui8kit_classes('disclosureClasses', {'class': class, 'open': open, 'name': name})), 'open': open, 'name': ui8kit_or_null(name)}, attrs, false, ['name']) }}>{{ children|raw }}</details>
{# Code generated by @ui8kit/codegen. DO NOT EDIT. #}
{# Summary — Summary renders the native summary (the disclosure trigger). #}
{# @param class (string) #}
{# @param attrs (attrs) #}
{# @param children (children) #}
{% set class = class|default('') %}
{% set attrs = attrs|default([]) %}
{% set children = children|default('') %}
<summary{{ ui8kit_attrs({'class': ui8kit_or_null(ui8kit_classes('summaryClasses', {'class': class}))}, attrs) }}>{{ children|raw }}</summary>
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-disclosure{* Code generated by @ui8kit/codegen. DO NOT EDIT. *}
{* Disclosure — Disclosure renders a native details element. *}
{parameters
string $class = '',
bool $open = false,
?string $name = null,
array $attrs = [],
string $children = '',
}
<details n:attr="[
'class' => \UI8Kit\Latte\Rt::orNull(\UI8Kit\Latte\Classes::disclosureClasses(['class' => $class, 'open' => $open, 'name' => $name])),
'open' => $open,
'name' => \UI8Kit\Latte\Rt::orNull($name),
...\UI8Kit\Latte\Rt::restAttrs($attrs, false, ['name']),
]">{$children|noescape}</details>{* Code generated by @ui8kit/codegen. DO NOT EDIT. *}
{* Summary — Summary renders the native summary (the disclosure trigger). *}
{parameters
string $class = '',
array $attrs = [],
string $children = '',
}
<summary n:attr="[
'class' => \UI8Kit\Latte\Rt::orNull(\UI8Kit\Latte\Classes::summaryClasses(['class' => $class])),
...\UI8Kit\Latte\Rt::restAttrs($attrs),
]">{$children|noescape}</summary>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-disclosure{#- Code generated by @ui8kit/codegen. DO NOT EDIT.
Disclosure: Disclosure renders a native details element.
Props (p): Class (string), Open (bool), Name (string), Attrs (attrs), Children (children).
children: TRUSTED HTML printed with |safe — never pass unescaped user input.
Classes without rendering: disclosure_classes(p) (no asChild in Jinja2). -#}
<details
{%- with cls = disclosure_classes(p) %}{%- if cls %} class="{{ cls }}"{%- endif %}{%- endwith %}
{%- 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'], {}), 'name') %}{%- if ui_is_set_str(p['Name']) %} name="{{ p['Name'] }}"{%- endif %}{%- endif %}
{{ ui_attr_html(ui_def(p['Attrs'], {}), false, ['name']) }}
>{{ children|default('', true)|safe }}</details>
{#- Code generated by @ui8kit/codegen. DO NOT EDIT.
Summary: Summary renders the native summary (the disclosure trigger).
Props (p): Class (string), Attrs (attrs), Children (children).
children: TRUSTED HTML printed with |safe — never pass unescaped user input.
Classes without rendering: summary_classes(p) (no asChild in Jinja2). -#}
<summary
{%- with cls = summary_classes(p) %}{%- if cls %} class="{{ cls }}"{%- endif %}{%- endwith %}
{{ ui_attr_html(ui_def(p['Attrs'], {})) }}
>{{ children|default('', true)|safe }}</summary>
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.