Kit Form
UI8Kit 3 Form primitive (unstyled), from @ui8kit/registry
Install
npx ui8kit add kit-formPulls 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-form<!-- Code generated by @ui8kit/codegen. DO NOT EDIT. -->
<!--
Form renders a native form element; method is whitelisted (get|post|dialog).
-->
<script lang="ts" module>
import type { Snippet } from "svelte";
export type FormProps = {
method?: "get" | "post" | "dialog";
novalidate?: boolean;
class?: string;
children?: Snippet;
[key: string]: unknown;
};
</script>
<script lang="ts">
import { formClasses } from "./form.shared";
import { oneOfOrLower, orUndef, safeRest } from "../../utils/expr";
let {
method,
novalidate: noValidate,
class: className,
children,
...rawRest
}: FormProps = $props();
const rest = $derived(safeRest(rawRest, { blank: ["id", "name", "action", "enctype", "autocomplete", "target", "aria-label", "aria-labelledby", "aria-describedby"] }));
const cls = $derived(formClasses({ className }));
</script>
<form {...(cls ? { class: cls } : {})} method={orUndef(oneOfOrLower(method, "", "get", "post", "dialog"))} novalidate={noValidate || undefined} {...rest}>
{@render children?.()}
</form>
// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.form — shared TypeScript contract (types + classes helpers)
import { cn } from "../../utils";
/** Form renders a native form element; method is whitelisted (get|post|dialog). */
export type FormBaseProps = {
method?: "get" | "post" | "dialog";
noValidate?: boolean;
};
export type FormClassesInput = {
className?: string;
};
/** Compose Form classes without rendering — the cross-runtime `asChild` substitute. */
export function formClasses(input: FormClassesInput = {}): 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-form// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.form — shared TypeScript contract (types + classes helpers)
import { cn } from "../../utils";
/** Form renders a native form element; method is whitelisted (get|post|dialog). */
export type FormBaseProps = {
method?: "get" | "post" | "dialog";
noValidate?: boolean;
};
export type FormClassesInput = {
className?: string;
};
/** Compose Form classes without rendering — the cross-runtime `asChild` substitute. */
export function formClasses(input: FormClassesInput = {}): string {
return cn(input.className);
}
// Code generated by @ui8kit/codegen. DO NOT EDIT.
/**
* Form is the native <form>. Submission, validation and state are the consumer's;
* the primitive only types the native form attributes.
*/
import { forwardRef, type ReactNode, type FormHTMLAttributes } from "react";
import { formClasses } from "./form.shared";
import { oneOfOrLower, orUndef, safeRest } from "../../utils/expr";
/**
* Form renders a native form element; method is whitelisted (get|post|dialog).
*/
export type FormProps = Omit<FormHTMLAttributes<HTMLFormElement>, "className" | "children" | "method" | "noValidate"> & {
method?: "get" | "post" | "dialog";
noValidate?: boolean;
className?: string;
children?: ReactNode;
};
export const Form = forwardRef<HTMLFormElement, FormProps>(function Form(
{ method, noValidate, className, children, ...rawRest },
ref
) {
const rest = safeRest(rawRest, { blank: ["id", "name", "action", "enctype", "autocomplete", "target", "aria-label", "aria-labelledby", "aria-describedby"] });
const cls = formClasses({ className });
return (
<form ref={ref} className={cls || undefined} method={orUndef(oneOfOrLower(method, "", "get", "post", "dialog"))} noValidate={noValidate} {...rest}>
{children}
</form>
);
});
Form.displayName = "Form";
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-form<!-- Code generated by @ui8kit/codegen. DO NOT EDIT. -->
<!--
Form renders a native form element; method is whitelisted (get|post|dialog).
-->
<script setup lang="ts">
import { computed, useAttrs } from "vue";
import { formClasses } from "./form.shared";
import { oneOfOrLower, orUndef, safeRest } from "../../utils/expr";
defineOptions({ name: "Form", inheritAttrs: false });
const props = defineProps<{
method?: "get" | "post" | "dialog";
noValidate?: 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", "name", "action", "enctype", "autocomplete", "target", "aria-label", "aria-labelledby", "aria-describedby"] });
});
const cls = computed(() => formClasses({ className: callerClass.value }));
</script>
<template>
<form :class="cls || undefined" :method="orUndef(oneOfOrLower(props.method, '', 'get', 'post', 'dialog'))" :novalidate="props.noValidate || undefined" v-bind="restAttrs">
<slot />
</form>
</template>
// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.form — shared TypeScript contract (types + classes helpers)
import { cn } from "../../utils";
/** Form renders a native form element; method is whitelisted (get|post|dialog). */
export type FormBaseProps = {
method?: "get" | "post" | "dialog";
noValidate?: boolean;
};
export type FormClassesInput = {
className?: string;
};
/** Compose Form classes without rendering — the cross-runtime `asChild` substitute. */
export function formClasses(input: FormClassesInput = {}): 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-form// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.form — shared TypeScript contract (types + classes helpers)
import { cn } from "../../utils";
/** Form renders a native form element; method is whitelisted (get|post|dialog). */
export type FormBaseProps = {
method?: "get" | "post" | "dialog";
noValidate?: boolean;
};
export type FormClassesInput = {
className?: string;
};
/** Compose Form classes without rendering — the cross-runtime `asChild` substitute. */
export function formClasses(input: FormClassesInput = {}): string {
return cn(input.className);
}
// Code generated by @ui8kit/codegen. DO NOT EDIT.
/**
* Form is the native <form>. Submission, validation and state are the consumer's;
* the primitive only types the native form attributes.
*/
import { splitProps, type JSX, type Component } from "solid-js";
import { formClasses } from "./form.shared";
import { oneOfOrLower, orUndef, safeRest } from "../../utils/expr";
/**
* Form renders a native form element; method is whitelisted (get|post|dialog).
*/
export type FormProps = Omit<JSX.FormHTMLAttributes<HTMLFormElement>, "class" | "className" | "children" | "method" | "noValidate"> & {
method?: "get" | "post" | "dialog";
noValidate?: boolean;
class?: string;
className?: string;
children?: JSX.Element;
};
export const Form: Component<FormProps> = (props) => {
const [local, rest] = splitProps(props, ["method", "noValidate", "class", "className", "children"]);
const cls = () => formClasses({ className: local.class ?? local.className });
return (
<form {...(cls() ? { class: cls() } : {})} method={orUndef(oneOfOrLower(local.method, "", "get", "post", "dialog"))} novalidate={local.noValidate || undefined} {...safeRest(rest, { blank: ["id", "name", "action", "enctype", "autocomplete", "target", "aria-label", "aria-labelledby", "aria-describedby"] })}>
{local.children}
</form>
);
};
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-form// Code generated by @ui8kit/codegen. DO NOT EDIT.
/*
Form is the native <form>. Submission, validation and state are the consumer's;
the primitive only types the native form attributes.
*/
package form
import (
uiutils "github.com/ui8kit/codegen/generated/templ/utils"
)
// FormProps configures Form.
type FormProps struct {
// Class — token class names supplied by the consumer
Class string
ID string
Name string
// Action — submission URL
Action string
// Method — HTTP method: get | post | dialog (omitted when empty)
Method string
// Enctype — encoding for post (e.g. multipart/form-data)
Enctype string
// NoValidate — skip native constraint validation
NoValidate bool
// Autocomplete — on | off
Autocomplete string
// Target — browsing context for the response
Target string
AriaLabel string
AriaLabelledBy string
AriaDescribedBy string
Attrs templ.Attributes
}
// FormClasses composes Form classes without rendering —
// the server-composition escape hatch for custom root elements (no asChild in templ).
func FormClasses(p FormProps) string {
return uiutils.Cn(p.Class)
}
// Form renders the Form contract.
templ Form(p FormProps) {
<form
if FormClasses(p) != "" {
class={ FormClasses(p) }
}
if !uiutils.HasAttr(p.Attrs, "id") {
if uiutils.IsSetStr(p.ID) {
id={ p.ID }
}
}
if !uiutils.HasAttr(p.Attrs, "name") {
if uiutils.IsSetStr(p.Name) {
name={ p.Name }
}
}
if !uiutils.HasAttr(p.Attrs, "action") {
if uiutils.IsSetStr(uiutils.SafeURL(p.Action)) {
action={ uiutils.SafeURL(p.Action) }
}
}
if !uiutils.HasAttr(p.Attrs, "method") {
if uiutils.IsSetStr(uiutils.OneOfOrLower(p.Method, "", "get", "post", "dialog")) {
method={ uiutils.OneOfOrLower(p.Method, "", "get", "post", "dialog") }
}
}
if !uiutils.HasAttr(p.Attrs, "enctype") {
if uiutils.IsSetStr(p.Enctype) {
enctype={ p.Enctype }
}
}
if !uiutils.HasAttr(p.Attrs, "novalidate") {
novalidate?={ p.NoValidate }
}
if !uiutils.HasAttr(p.Attrs, "autocomplete") {
if uiutils.IsSetStr(p.Autocomplete) {
autocomplete={ p.Autocomplete }
}
}
if !uiutils.HasAttr(p.Attrs, "target") {
if uiutils.IsSetStr(p.Target) {
target={ p.Target }
}
}
if !uiutils.HasAttr(p.Attrs, "aria-label") {
if uiutils.IsSetStr(p.AriaLabel) {
aria-label={ p.AriaLabel }
}
}
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 }
}
}
{ uiutils.RestAttrs(p.Attrs, false, "id", "name", "action", "enctype", "autocomplete", "target", "aria-label", "aria-labelledby", "aria-describedby")... }
>
{ children... }
</form>
}
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-form{# Code generated by @ui8kit/codegen. DO NOT EDIT. #}
{# Form — Form renders a native form element; method is whitelisted (get|post|dialog). #}
{# @param class (string) #}
{# @param id (string) #}
{# @param name (string) #}
{# @param action (string) #}
{# @param method (string) #}
{# @param encType (string) #}
{# @param noValidate (bool) #}
{# @param autoComplete (string) #}
{# @param target (string) #}
{# @param ariaLabel (string) #}
{# @param ariaLabelledBy (string) #}
{# @param ariaDescribedBy (string) #}
{# @param attrs (attrs) #}
{# @param children (children) #}
{% set class = class|default('') %}
{% set id = id ?? null %}
{% set name = name ?? null %}
{% set action = action ?? null %}
{% set method = method|default('') %}
{% set encType = encType ?? null %}
{% set noValidate = noValidate|default(false) %}
{% set autoComplete = autoComplete ?? null %}
{% set target = target ?? null %}
{% set ariaLabel = ariaLabel ?? null %}
{% set ariaLabelledBy = ariaLabelledBy ?? null %}
{% set ariaDescribedBy = ariaDescribedBy ?? null %}
{% set attrs = attrs|default([]) %}
{% set children = children|default('') %}
<form{{ ui8kit_attrs({'class': ui8kit_or_null(ui8kit_classes('formClasses', {'class': class, 'id': id, 'name': name, 'action': action, 'method': method, 'encType': encType, 'noValidate': noValidate, 'autoComplete': autoComplete, 'target': target, 'ariaLabel': ariaLabel, 'ariaLabelledBy': ariaLabelledBy, 'ariaDescribedBy': ariaDescribedBy})), 'id': ui8kit_or_null(id), 'name': ui8kit_or_null(name), 'action': ui8kit_url_or_null(action), 'method': ui8kit_or_null(ui8kit_one_of_or_lower(method, '', ['get', 'post', 'dialog'])), 'enctype': ui8kit_or_null(encType), 'novalidate': noValidate, 'autocomplete': ui8kit_or_null(autoComplete), 'target': ui8kit_or_null(target), 'aria-label': ui8kit_or_null(ariaLabel), 'aria-labelledby': ui8kit_or_null(ariaLabelledBy), 'aria-describedby': ui8kit_or_null(ariaDescribedBy)}, attrs, false, ['id', 'name', 'action', 'enctype', 'autocomplete', 'target', 'aria-label', 'aria-labelledby', 'aria-describedby']) }}>{{ children|raw }}</form>
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-form{* Code generated by @ui8kit/codegen. DO NOT EDIT. *}
{* Form — Form renders a native form element; method is whitelisted (get|post|dialog). *}
{parameters
string $class = '',
?string $id = null,
?string $name = null,
?string $action = null,
string $method = '',
?string $encType = null,
bool $noValidate = false,
?string $autoComplete = null,
?string $target = null,
?string $ariaLabel = null,
?string $ariaLabelledBy = null,
?string $ariaDescribedBy = null,
array $attrs = [],
string $children = '',
}
<form n:attr="[
'class' => \UI8Kit\Latte\Rt::orNull(\UI8Kit\Latte\Classes::formClasses(['class' => $class, 'id' => $id, 'name' => $name, 'action' => $action, 'method' => $method, 'encType' => $encType, 'noValidate' => $noValidate, 'autoComplete' => $autoComplete, 'target' => $target, 'ariaLabel' => $ariaLabel, 'ariaLabelledBy' => $ariaLabelledBy, 'ariaDescribedBy' => $ariaDescribedBy])),
'id' => \UI8Kit\Latte\Rt::orNull($id),
'name' => \UI8Kit\Latte\Rt::orNull($name),
'action' => \UI8Kit\Latte\Rt::urlOrNull($action),
'method' => \UI8Kit\Latte\Rt::orNull(\UI8Kit\Latte\Rt::oneOfOrLower($method, '', ['get', 'post', 'dialog'])),
'enctype' => \UI8Kit\Latte\Rt::orNull($encType),
'novalidate' => $noValidate,
'autocomplete' => \UI8Kit\Latte\Rt::orNull($autoComplete),
'target' => \UI8Kit\Latte\Rt::orNull($target),
'aria-label' => \UI8Kit\Latte\Rt::orNull($ariaLabel),
'aria-labelledby' => \UI8Kit\Latte\Rt::orNull($ariaLabelledBy),
'aria-describedby' => \UI8Kit\Latte\Rt::orNull($ariaDescribedBy),
...\UI8Kit\Latte\Rt::restAttrs($attrs, false, ['id', 'name', 'action', 'enctype', 'autocomplete', 'target', 'aria-label', 'aria-labelledby', 'aria-describedby']),
]">{$children|noescape}</form>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-form{#- Code generated by @ui8kit/codegen. DO NOT EDIT.
Form: Form renders a native form element; method is whitelisted (get|post|dialog).
Props (p): Class (string), ID (string), Name (string), Action (string), Method (string), Enctype (string), NoValidate (bool), Autocomplete (string), Target (string), AriaLabel (string), AriaLabelledBy (string), AriaDescribedBy (string), Attrs (attrs), Children (children).
children: TRUSTED HTML printed with |safe — never pass unescaped user input.
Classes without rendering: form_classes(p) (no asChild in Jinja2). -#}
<form
{%- with cls = form_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'], {}), 'name') %}{%- if ui_is_set_str(p['Name']) %} name="{{ p['Name'] }}"{%- endif %}{%- endif %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'action') %}{%- if ui_is_set_str(p['Action']) and ui_safe_url(p['Action']) != '' %} action="{{ p['Action'] }}"{%- endif %}{%- endif %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'method') %}{%- if ui_is_set_str(ui_map_or(ui_def(p['Method'], ''), {'get': 'get', 'post': 'post', 'dialog': 'dialog'}, '', true)) %} method="{{ ui_map_or(ui_def(p['Method'], ''), {'get': 'get', 'post': 'post', 'dialog': 'dialog'}, '', true) }}"{%- endif %}{%- endif %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'enctype') %}{%- if ui_is_set_str(p['Enctype']) %} enctype="{{ p['Enctype'] }}"{%- endif %}{%- endif %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'novalidate') %}{%- if ui_def(p['NoValidate'], false) %} novalidate{%- endif %}{%- endif %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'autocomplete') %}{%- if ui_is_set_str(p['Autocomplete']) %} autocomplete="{{ p['Autocomplete'] }}"{%- endif %}{%- endif %}
{%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'target') %}{%- if ui_is_set_str(p['Target']) %} target="{{ p['Target'] }}"{%- 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-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 %}
{{ ui_attr_html(ui_def(p['Attrs'], {}), false, ['id', 'name', 'action', 'enctype', 'autocomplete', 'target', 'aria-label', 'aria-labelledby', 'aria-describedby']) }}
>{{ children|default('', true)|safe }}</form>
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.