Skip to content
ui8kit

primitive / kit

Kit Button

UI8Kit 3 Button primitive (unstyled), from @ui8kit/registry

Install

npx ui8kit add kit-button

Pulls in: kit-slot, 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-cdn
npx ui8kit add kit-button
kit/ui/button/Button.svelte
<!-- Code generated by @ui8kit/codegen. DO NOT EDIT. -->
<!--
  Button renders a button element, or an anchor when Href is set.
  Type/Form apply only in button mode; Disabled on anchors uses aria-disabled.
  Pressed (button mode) and Expanded print aria-pressed / aria-expanded as "true"/"false";
  unset omits the attribute.
-->
<script lang="ts" module>
  import type { Snippet } from "svelte";

  export type ButtonProps = {
    type?: "button" | "submit" | "reset";
    href?: string;
    disabled?: boolean;
    pressed?: boolean;
    expanded?: boolean;
    class?: string;
    children?: Snippet;
    [key: string]: unknown;
  };
</script>

<script lang="ts">
  import { buttonClasses } from "./button.shared";
  import { isSetStr, oneOfOr, optBoolStr, orUndef, safeRest, safeUrl } from "../../utils/expr";

  let {
    type,
    href,
    disabled,
    pressed,
    expanded,
    class: className,
    children,
    ...rawRest
  }: ButtonProps = $props();

  const rest = $derived(safeRest(rawRest, { blank: ["aria-label", "aria-pressed", "aria-expanded", "aria-controls"] }));
  const cls = $derived(buttonClasses({ className }));
</script>

{#if isSetStr(href)}
  <a href={orUndef(safeUrl(href))} {...(cls ? { class: cls } : {})} aria-expanded={orUndef(optBoolStr(expanded))} aria-disabled={disabled ? "true" : undefined} tabindex={disabled ? -1 : undefined} {...rest}>
    {@render children?.()}
  </a>
{:else}
  <button type={oneOfOr(type, "button", "submit", "reset")} {...(cls ? { class: cls } : {})} disabled={disabled || undefined} aria-pressed={orUndef(optBoolStr(pressed))} aria-expanded={orUndef(optBoolStr(expanded))} {...rest}>
    {@render children?.()}
  </button>
{/if}
kit/ui/button/button.shared.ts
// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.button — shared TypeScript contract (types + classes helpers)

import { cn } from "../../utils";

/** Button renders a button element, or an anchor when Href is set. */
export type ButtonBaseProps = {
  type?: "button" | "submit" | "reset";
  href?: string;
  disabled?: boolean;
  pressed?: boolean;
  expanded?: boolean;
};

export type ButtonClassesInput = {
  className?: string;
};

/** Compose Button classes without rendering — the cross-runtime `asChild` substitute. */
export function buttonClasses(input: ButtonClassesInput = {}): string {
  return cn(input.className);
}

Svelte registry item (JSON)

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-cdn
npx ui8kit add kit-button
kit/ui/button/button.shared.ts
// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.button — shared TypeScript contract (types + classes helpers)

import { cn } from "../../utils";

/** Button renders a button element, or an anchor when Href is set. */
export type ButtonBaseProps = {
  type?: "button" | "submit" | "reset";
  href?: string;
  disabled?: boolean;
  pressed?: boolean;
  expanded?: boolean;
};

export type ButtonClassesInput = {
  className?: string;
};

/** Compose Button classes without rendering — the cross-runtime `asChild` substitute. */
export function buttonClasses(input: ButtonClassesInput = {}): string {
  return cn(input.className);
}
kit/ui/button/button.tsx
// Code generated by @ui8kit/codegen. DO NOT EDIT.
/**
 * Button triggers an action. With `href` it renders an anchor (navigation that
 * looks like an action). Event handlers (onClick) flow through attrs/rest.
 * Pressed / Expanded are the semantic ARIA state props (toggle, disclosure).
 */

import { forwardRef, type ReactNode, type AnchorHTMLAttributes, type ButtonHTMLAttributes, type Ref } from "react";
import { buttonClasses } from "./button.shared";
import { isSetStr, oneOfOr, optBoolStr, orUndef, safeRest, safeUrl } from "../../utils/expr";
import { Slot } from "../slot/slot";

/**
 * Button renders a button element, or an anchor when Href is set.
 * Type/Form apply only in button mode; Disabled on anchors uses aria-disabled.
 * Pressed (button mode) and Expanded print aria-pressed / aria-expanded as "true"/"false";
 * unset omits the attribute.
 */
export type ButtonProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement> & ButtonHTMLAttributes<HTMLButtonElement>, "className" | "children" | "type" | "href" | "disabled" | "pressed" | "expanded"> & {
  type?: "button" | "submit" | "reset";
  href?: string;
  disabled?: boolean;
  pressed?: boolean;
  expanded?: boolean;
  className?: string;
  children?: ReactNode;
  asChild?: boolean;
};

export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, ButtonProps>(function Button(
  { type, href, disabled, pressed, expanded, className, children, asChild, ...rawRest },
  ref
) {
  const rest = safeRest(rawRest, { blank: ["aria-label", "aria-pressed", "aria-expanded", "aria-controls"] });
  const cls = buttonClasses({ className });
  if (asChild) {
    return (
      <Slot ref={ref} className={cls} {...rest}>
        {children}
      </Slot>
    );
  }
  return (
    isSetStr(href) ? (
      <a ref={ref as Ref<HTMLAnchorElement>} href={orUndef(safeUrl(href))} className={cls || undefined} aria-expanded={orUndef(optBoolStr(expanded))} aria-disabled={disabled ? "true" : undefined} tabIndex={disabled ? -1 : undefined} {...rest}>
        {children}
      </a>
    ) : (
      <button ref={ref as Ref<HTMLButtonElement>} type={oneOfOr(type, "button", "submit", "reset")} className={cls || undefined} disabled={disabled} aria-pressed={orUndef(optBoolStr(pressed))} aria-expanded={orUndef(optBoolStr(expanded))} {...rest}>
        {children}
      </button>
    )
  );
});
Button.displayName = "Button";

React registry item (JSON)

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-cdn
npx ui8kit add kit-button
kit/ui/button/Button.vue
<!-- Code generated by @ui8kit/codegen. DO NOT EDIT. -->
<!--
  Button renders a button element, or an anchor when Href is set.
  Type/Form apply only in button mode; Disabled on anchors uses aria-disabled.
  Pressed (button mode) and Expanded print aria-pressed / aria-expanded as "true"/"false";
  unset omits the attribute.
-->
<script setup lang="ts">
import { computed, useAttrs } from "vue";
import { buttonClasses } from "./button.shared";
import { isSetStr, oneOfOr, optBoolStr, orUndef, safeRest, safeUrl } from "../../utils/expr";

defineOptions({ name: "Button", inheritAttrs: false });

const props = withDefaults(defineProps<{
  type?: "button" | "submit" | "reset";
  href?: string;
  disabled?: boolean;
  pressed?: boolean;
  expanded?: boolean;
}>(), { pressed: undefined, expanded: undefined });

const attrs = useAttrs();
const callerClass = computed(() => attrs.class as string | undefined);
const restAttrs = computed(() => {
  const { class: _class, ...restEntries } = attrs;
  return safeRest(restEntries, { blank: ["aria-label", "aria-pressed", "aria-expanded", "aria-controls"] });
});
const cls = computed(() => buttonClasses({ className: callerClass.value }));
</script>

<template>
  <a v-if="isSetStr(props.href)" :href="orUndef(safeUrl(props.href))" :class="cls || undefined" :aria-expanded="orUndef(optBoolStr(props.expanded))" :aria-disabled="props.disabled ? 'true' : undefined" :tabindex="props.disabled ? -1 : undefined" v-bind="restAttrs">
    <slot />
  </a>
  <button v-else :type="oneOfOr(props.type, 'button', 'submit', 'reset')" :class="cls || undefined" :disabled="props.disabled || undefined" :aria-pressed="orUndef(optBoolStr(props.pressed))" :aria-expanded="orUndef(optBoolStr(props.expanded))" v-bind="restAttrs">
    <slot />
  </button>
</template>
kit/ui/button/button.shared.ts
// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.button — shared TypeScript contract (types + classes helpers)

import { cn } from "../../utils";

/** Button renders a button element, or an anchor when Href is set. */
export type ButtonBaseProps = {
  type?: "button" | "submit" | "reset";
  href?: string;
  disabled?: boolean;
  pressed?: boolean;
  expanded?: boolean;
};

export type ButtonClassesInput = {
  className?: string;
};

/** Compose Button classes without rendering — the cross-runtime `asChild` substitute. */
export function buttonClasses(input: ButtonClassesInput = {}): string {
  return cn(input.className);
}

Vue registry item (JSON)

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-cdn
npx ui8kit add kit-button
kit/ui/button/button.shared.ts
// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.button — shared TypeScript contract (types + classes helpers)

import { cn } from "../../utils";

/** Button renders a button element, or an anchor when Href is set. */
export type ButtonBaseProps = {
  type?: "button" | "submit" | "reset";
  href?: string;
  disabled?: boolean;
  pressed?: boolean;
  expanded?: boolean;
};

export type ButtonClassesInput = {
  className?: string;
};

/** Compose Button classes without rendering — the cross-runtime `asChild` substitute. */
export function buttonClasses(input: ButtonClassesInput = {}): string {
  return cn(input.className);
}
kit/ui/button/button.solid.tsx
// Code generated by @ui8kit/codegen. DO NOT EDIT.
/**
 * Button triggers an action. With `href` it renders an anchor (navigation that
 * looks like an action). Event handlers (onClick) flow through attrs/rest.
 * Pressed / Expanded are the semantic ARIA state props (toggle, disclosure).
 */

import { splitProps, type JSX, type Component } from "solid-js";
import { buttonClasses } from "./button.shared";
import { isSetStr, oneOfOr, optBoolStr, orUndef, safeRest, safeUrl } from "../../utils/expr";

/**
 * Button renders a button element, or an anchor when Href is set.
 * Type/Form apply only in button mode; Disabled on anchors uses aria-disabled.
 * Pressed (button mode) and Expanded print aria-pressed / aria-expanded as "true"/"false";
 * unset omits the attribute.
 */
export type ButtonProps = Omit<JSX.HTMLAttributes<HTMLElement>, "class" | "className" | "children" | "type" | "href" | "disabled" | "pressed" | "expanded" | "ref"> & {
  type?: "button" | "submit" | "reset";
  href?: string;
  disabled?: boolean;
  pressed?: boolean;
  expanded?: boolean;
  class?: string;
  className?: string;
  children?: JSX.Element;
  ref?: (el: HTMLElement) => void;
};

export const Button: Component<ButtonProps> = (props) => {
  const [local, rest] = splitProps(props, ["type", "href", "disabled", "pressed", "expanded", "class", "className", "children"]);
  const cls = () => buttonClasses({ className: local.class ?? local.className });
  return (
    <>
      {isSetStr(local.href) ? (
        <a href={orUndef(safeUrl(local.href))} {...(cls() ? { class: cls() } : {})} aria-expanded={orUndef(optBoolStr(local.expanded))} aria-disabled={local.disabled ? "true" : undefined} tabIndex={local.disabled ? -1 : undefined} {...safeRest(rest, { blank: ["aria-label", "aria-pressed", "aria-expanded", "aria-controls"] })}>
          {local.children}
        </a>
      ) : (
        <button type={oneOfOr(local.type, "button", "submit", "reset")} {...(cls() ? { class: cls() } : {})} disabled={local.disabled || undefined} aria-pressed={orUndef(optBoolStr(local.pressed))} aria-expanded={orUndef(optBoolStr(local.expanded))} {...safeRest(rest, { blank: ["aria-label", "aria-pressed", "aria-expanded", "aria-controls"] })}>
          {local.children}
        </button>
      )}
    </>
  );
};

Solid registry item (JSON)

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-cdn
npx ui8kit add kit-button
ui/button/button.templ
// Code generated by @ui8kit/codegen. DO NOT EDIT.

/*
Button triggers an action. With `href` it renders an anchor (navigation that
looks like an action). Event handlers (onClick) flow through attrs/rest.
Pressed / Expanded are the semantic ARIA state props (toggle, disclosure).
*/

package button

import (
	"strconv"

	uiutils "github.com/ui8kit/codegen/generated/templ/utils"
)

// ButtonProps configures Button.
type ButtonProps struct {
	// Class — token class names supplied by the consumer
	Class string
	// Type — button type (default button)
	Type string
	// Form — associated form id (button mode)
	Form string
	// Href — renders an anchor when set
	Href string
	// Disabled — blocks interaction
	Disabled bool
	// Pressed — toggle state → aria-pressed (button mode); unset omits it
	Pressed *bool
	// Expanded — disclosure state → aria-expanded; unset omits it
	Expanded *bool
	AriaLabel string
	AriaPressed string
	AriaExpanded string
	AriaControls string
	Attrs templ.Attributes
}

// ButtonClasses composes Button classes without rendering —
// the server-composition escape hatch for custom root elements (no asChild in templ).
func ButtonClasses(p ButtonProps) string {
	return uiutils.Cn(p.Class)
}

// Button renders the Button contract.
templ Button(p ButtonProps) {
	if uiutils.IsSetStr(p.Href) {
		<a
			if !uiutils.HasAttr(p.Attrs, "href") {
				if uiutils.IsSetStr(uiutils.SafeURL(p.Href)) {
					href={ uiutils.SafeURL(p.Href) }
				}
			}
			if ButtonClasses(p) != "" {
				class={ ButtonClasses(p) }
			}
			if !uiutils.HasAttr(p.Attrs, "aria-expanded") {
				if !uiutils.IsSetStr(p.AriaExpanded) {
					if uiutils.IsSetStr(uiutils.OptBoolStr(p.Expanded)) {
						aria-expanded={ uiutils.OptBoolStr(p.Expanded) }
					}
				}
			}
			if !uiutils.HasAttr(p.Attrs, "aria-label") {
				if uiutils.IsSetStr(p.AriaLabel) {
					aria-label={ p.AriaLabel }
				}
			}
			if !uiutils.HasAttr(p.Attrs, "aria-pressed") {
				if uiutils.IsSetStr(p.AriaPressed) {
					aria-pressed={ p.AriaPressed }
				}
			}
			if !uiutils.HasAttr(p.Attrs, "aria-expanded") {
				if uiutils.IsSetStr(p.AriaExpanded) {
					aria-expanded={ p.AriaExpanded }
				}
			}
			if !uiutils.HasAttr(p.Attrs, "aria-controls") {
				if uiutils.IsSetStr(p.AriaControls) {
					aria-controls={ p.AriaControls }
				}
			}
			if !uiutils.HasAttr(p.Attrs, "aria-disabled") {
				if p.Disabled {
					aria-disabled={ "true" }
				}
			}
			if !uiutils.HasAttr(p.Attrs, "tabindex") {
				if p.Disabled {
					tabindex={ strconv.Itoa(int(-1)) }
				}
			}
			{ uiutils.RestAttrs(p.Attrs, false, "aria-label", "aria-pressed", "aria-expanded", "aria-controls")... }
		>
			{ children... }
		</a>
	} else {
		<button
			if !uiutils.HasAttr(p.Attrs, "type") {
				type={ uiutils.OneOfOr(p.Type, "button", "submit", "reset") }
			}
			if ButtonClasses(p) != "" {
				class={ ButtonClasses(p) }
			}
			if !uiutils.HasAttr(p.Attrs, "disabled") {
				disabled?={ p.Disabled }
			}
			if !uiutils.HasAttr(p.Attrs, "form") {
				if uiutils.IsSetStr(p.Form) {
					form={ p.Form }
				}
			}
			if !uiutils.HasAttr(p.Attrs, "aria-pressed") {
				if !uiutils.IsSetStr(p.AriaPressed) {
					if uiutils.IsSetStr(uiutils.OptBoolStr(p.Pressed)) {
						aria-pressed={ uiutils.OptBoolStr(p.Pressed) }
					}
				}
			}
			if !uiutils.HasAttr(p.Attrs, "aria-expanded") {
				if !uiutils.IsSetStr(p.AriaExpanded) {
					if uiutils.IsSetStr(uiutils.OptBoolStr(p.Expanded)) {
						aria-expanded={ uiutils.OptBoolStr(p.Expanded) }
					}
				}
			}
			if !uiutils.HasAttr(p.Attrs, "aria-label") {
				if uiutils.IsSetStr(p.AriaLabel) {
					aria-label={ p.AriaLabel }
				}
			}
			if !uiutils.HasAttr(p.Attrs, "aria-pressed") {
				if uiutils.IsSetStr(p.AriaPressed) {
					aria-pressed={ p.AriaPressed }
				}
			}
			if !uiutils.HasAttr(p.Attrs, "aria-expanded") {
				if uiutils.IsSetStr(p.AriaExpanded) {
					aria-expanded={ p.AriaExpanded }
				}
			}
			if !uiutils.HasAttr(p.Attrs, "aria-controls") {
				if uiutils.IsSetStr(p.AriaControls) {
					aria-controls={ p.AriaControls }
				}
			}
			{ uiutils.RestAttrs(p.Attrs, false, "form", "aria-label", "aria-pressed", "aria-expanded", "aria-controls")... }
		>
			{ children... }
		</button>
	}
}

templ registry item (JSON)

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-cdn
npx ui8kit add kit-button
ui/button/Button.html.twig
{# Code generated by @ui8kit/codegen. DO NOT EDIT. #}
{# Button — Button renders a button element, or an anchor when Href is set. #}
{# @param class (string) #}
{# @param type (string) #}
{# @param form (string) #}
{# @param href (string) #}
{# @param disabled (bool) #}
{# @param pressed (bool) #}
{# @param expanded (bool) #}
{# @param ariaLabel (string) #}
{# @param ariaPressed (string) #}
{# @param ariaExpanded (string) #}
{# @param ariaControls (string) #}
{# @param attrs (attrs) #}
{# @param children (children) #}
{% set class = class|default('') %}
{% set type = type|default('') %}
{% set form = form ?? null %}
{% set href = href|default('') %}
{% set disabled = disabled|default(false) %}
{% set pressed = pressed ?? null %}
{% set expanded = expanded ?? null %}
{% set ariaLabel = ariaLabel ?? null %}
{% set ariaPressed = ariaPressed ?? null %}
{% set ariaExpanded = ariaExpanded ?? null %}
{% set ariaControls = ariaControls ?? null %}
{% set attrs = attrs|default([]) %}
{% set children = children|default('') %}
{% if ui8kit_is_set_str(href) %}<a{{ ui8kit_attrs({'href': ui8kit_or_null(ui8kit_safe_url(href)), 'class': ui8kit_or_null(ui8kit_classes('buttonClasses', {'class': class, 'type': type, 'form': form, 'href': href, 'disabled': disabled, 'pressed': pressed, 'expanded': expanded, 'ariaLabel': ariaLabel, 'ariaPressed': ariaPressed, 'ariaExpanded': ariaExpanded, 'ariaControls': ariaControls})), 'aria-label': ui8kit_or_null(ariaLabel), 'aria-pressed': ui8kit_or_null(ariaPressed), 'aria-expanded': (ui8kit_or_null(ariaExpanded) ?? ui8kit_or_null(ui8kit_opt_bool_str(expanded))), 'aria-controls': ui8kit_or_null(ariaControls), 'aria-disabled': (disabled ? 'true' : null), 'tabindex': (disabled ? (-1 ~ '') : null)}, attrs, false, ['aria-label', 'aria-pressed', 'aria-expanded', 'aria-controls']) }}>{{ children|raw }}</a>{% else %}<button{{ ui8kit_attrs({'type': ui8kit_one_of_or(type, 'button', ['submit', 'reset']), 'class': ui8kit_or_null(ui8kit_classes('buttonClasses', {'class': class, 'type': type, 'form': form, 'href': href, 'disabled': disabled, 'pressed': pressed, 'expanded': expanded, 'ariaLabel': ariaLabel, 'ariaPressed': ariaPressed, 'ariaExpanded': ariaExpanded, 'ariaControls': ariaControls})), 'disabled': disabled, 'form': ui8kit_or_null(form), 'aria-label': ui8kit_or_null(ariaLabel), 'aria-pressed': (ui8kit_or_null(ariaPressed) ?? ui8kit_or_null(ui8kit_opt_bool_str(pressed))), 'aria-expanded': (ui8kit_or_null(ariaExpanded) ?? ui8kit_or_null(ui8kit_opt_bool_str(expanded))), 'aria-controls': ui8kit_or_null(ariaControls)}, attrs, false, ['form', 'aria-label', 'aria-pressed', 'aria-expanded', 'aria-controls']) }}>{{ children|raw }}</button>{% endif %}

Twig registry item (JSON)

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-cdn
npx ui8kit add kit-button
ui/button/Button.latte
{* Code generated by @ui8kit/codegen. DO NOT EDIT. *}
{* Button — Button renders a button element, or an anchor when Href is set. *}
{parameters
  string $class = '',
  string $type = '',
  ?string $form = null,
  string $href = '',
  bool $disabled = false,
  ?bool $pressed = null,
  ?bool $expanded = null,
  ?string $ariaLabel = null,
  ?string $ariaPressed = null,
  ?string $ariaExpanded = null,
  ?string $ariaControls = null,
  array $attrs = [],
  string $children = '',
}
{if \UI8Kit\Latte\Rt::isSetStr($href)}<a n:attr="[
  'href' => \UI8Kit\Latte\Rt::orNull(\UI8Kit\Latte\Rt::safeUrl($href)),
  'class' => \UI8Kit\Latte\Rt::orNull(\UI8Kit\Latte\Classes::buttonClasses(['class' => $class, 'type' => $type, 'form' => $form, 'href' => $href, 'disabled' => $disabled, 'pressed' => $pressed, 'expanded' => $expanded, 'ariaLabel' => $ariaLabel, 'ariaPressed' => $ariaPressed, 'ariaExpanded' => $ariaExpanded, 'ariaControls' => $ariaControls])),
  'aria-label' => \UI8Kit\Latte\Rt::orNull($ariaLabel),
  'aria-pressed' => \UI8Kit\Latte\Rt::orNull($ariaPressed),
  'aria-expanded' => (\UI8Kit\Latte\Rt::orNull($ariaExpanded) ?? \UI8Kit\Latte\Rt::orNull(\UI8Kit\Latte\Rt::optBoolStr($expanded))),
  'aria-controls' => \UI8Kit\Latte\Rt::orNull($ariaControls),
  'aria-disabled' => ($disabled ? 'true' : null),
  'tabindex' => ($disabled ? ((string) -1) : null),
  ...\UI8Kit\Latte\Rt::restAttrs($attrs, false, ['aria-label', 'aria-pressed', 'aria-expanded', 'aria-controls']),
]">{$children|noescape}</a>{else}<button n:attr="[
  'type' => \UI8Kit\Latte\Rt::oneOfOr($type, 'button', ['submit', 'reset']),
  'class' => \UI8Kit\Latte\Rt::orNull(\UI8Kit\Latte\Classes::buttonClasses(['class' => $class, 'type' => $type, 'form' => $form, 'href' => $href, 'disabled' => $disabled, 'pressed' => $pressed, 'expanded' => $expanded, 'ariaLabel' => $ariaLabel, 'ariaPressed' => $ariaPressed, 'ariaExpanded' => $ariaExpanded, 'ariaControls' => $ariaControls])),
  'disabled' => $disabled,
  'form' => \UI8Kit\Latte\Rt::orNull($form),
  'aria-label' => \UI8Kit\Latte\Rt::orNull($ariaLabel),
  'aria-pressed' => (\UI8Kit\Latte\Rt::orNull($ariaPressed) ?? \UI8Kit\Latte\Rt::orNull(\UI8Kit\Latte\Rt::optBoolStr($pressed))),
  'aria-expanded' => (\UI8Kit\Latte\Rt::orNull($ariaExpanded) ?? \UI8Kit\Latte\Rt::orNull(\UI8Kit\Latte\Rt::optBoolStr($expanded))),
  'aria-controls' => \UI8Kit\Latte\Rt::orNull($ariaControls),
  ...\UI8Kit\Latte\Rt::restAttrs($attrs, false, ['form', 'aria-label', 'aria-pressed', 'aria-expanded', 'aria-controls']),
]">{$children|noescape}</button>{/if}

Latte registry item (JSON)

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-cdn
npx ui8kit add kit-button
ui/button/button.html.j2
{#- Code generated by @ui8kit/codegen. DO NOT EDIT.
    Button: Button renders a button element, or an anchor when Href is set.
    Type/Form apply only in button mode; Disabled on anchors uses aria-disabled.
    Pressed (button mode) and Expanded print aria-pressed / aria-expanded as "true"/"false";
    unset omits the attribute.
    Props (p): Class (string), Type (string), Form (string), Href (string), Disabled (bool), Pressed (bool), Expanded (bool), AriaLabel (string), AriaPressed (string), AriaExpanded (string), AriaControls (string), Attrs (attrs), Children (children).
    children: TRUSTED HTML printed with |safe — never pass unescaped user input.
    Classes without rendering: button_classes(p) (no asChild in Jinja2). -#}
{%- if ui_is_set_str(ui_def(p['Href'], '')) %}<a
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'href') %}{%- if ui_is_set_str(ui_safe_url(ui_def(p['Href'], ''))) %} href="{{ ui_safe_url(ui_def(p['Href'], '')) }}"{%- endif %}{%- endif %}
  {%- with cls = button_classes(p) %}{%- if cls %} class="{{ cls }}"{%- endif %}{%- endwith %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'aria-expanded') %}{%- if not ui_is_set_str(p['AriaExpanded']) %}{%- if ui_is_set_str(ui_opt_bool_str(ui_def(p['Expanded'], none))) %} aria-expanded="{{ ui_opt_bool_str(ui_def(p['Expanded'], none)) }}"{%- endif %}{%- 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 %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'aria-pressed') %}{%- if ui_is_set_str(p['AriaPressed']) %} aria-pressed="{{ p['AriaPressed'] }}"{%- endif %}{%- endif %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'aria-expanded') %}{%- if ui_is_set_str(p['AriaExpanded']) %} aria-expanded="{{ p['AriaExpanded'] }}"{%- endif %}{%- endif %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'aria-controls') %}{%- if ui_is_set_str(p['AriaControls']) %} aria-controls="{{ p['AriaControls'] }}"{%- endif %}{%- endif %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'aria-disabled') %}{%- if ui_def(p['Disabled'], false) %} aria-disabled="{{ 'true' }}"{%- endif %}{%- endif %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'tabindex') %}{%- if ui_def(p['Disabled'], false) %} tabindex="{{ ui_s(-1) }}"{%- endif %}{%- endif %}
  {{ ui_attr_html(ui_def(p['Attrs'], {}), false, ['aria-label', 'aria-pressed', 'aria-expanded', 'aria-controls']) }}
>{{ children|default('', true)|safe }}</a>{%- else %}<button
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'type') %} type="{{ ui_map_or(ui_def(p['Type'], ''), {'submit': 'submit', 'reset': 'reset'}, 'button') }}"{%- endif %}
  {%- with cls = button_classes(p) %}{%- if cls %} class="{{ cls }}"{%- endif %}{%- endwith %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'disabled') %}{%- if ui_def(p['Disabled'], false) %} disabled{%- endif %}{%- endif %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'form') %}{%- if ui_is_set_str(p['Form']) %} form="{{ p['Form'] }}"{%- endif %}{%- endif %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'aria-pressed') %}{%- if not ui_is_set_str(p['AriaPressed']) %}{%- if ui_is_set_str(ui_opt_bool_str(ui_def(p['Pressed'], none))) %} aria-pressed="{{ ui_opt_bool_str(ui_def(p['Pressed'], none)) }}"{%- endif %}{%- endif %}{%- endif %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'aria-expanded') %}{%- if not ui_is_set_str(p['AriaExpanded']) %}{%- if ui_is_set_str(ui_opt_bool_str(ui_def(p['Expanded'], none))) %} aria-expanded="{{ ui_opt_bool_str(ui_def(p['Expanded'], none)) }}"{%- endif %}{%- 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 %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'aria-pressed') %}{%- if ui_is_set_str(p['AriaPressed']) %} aria-pressed="{{ p['AriaPressed'] }}"{%- endif %}{%- endif %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'aria-expanded') %}{%- if ui_is_set_str(p['AriaExpanded']) %} aria-expanded="{{ p['AriaExpanded'] }}"{%- endif %}{%- endif %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'aria-controls') %}{%- if ui_is_set_str(p['AriaControls']) %} aria-controls="{{ p['AriaControls'] }}"{%- endif %}{%- endif %}
  {{ ui_attr_html(ui_def(p['Attrs'], {}), false, ['form', 'aria-label', 'aria-pressed', 'aria-expanded', 'aria-controls']) }}
>{{ children|default('', true)|safe }}</button>{%- endif %}

Jinja2 registry item (JSON)

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.