Skip to content
ui8kit

primitive / kit

Kit Input

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

Install

npx ui8kit add kit-input

Pulls 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-cdn
npx ui8kit add kit-input
kit/ui/input/Input.svelte
<!-- Code generated by @ui8kit/codegen. DO NOT EDIT. -->
<!--
  Input renders a native input element (default type text).
-->
<script lang="ts" module>

  export type InputProps = {
    type?: "text" | "email" | "password" | "search" | "tel" | "url" | "number" | "range" | "date" | "datetime-local" | "month" | "week" | "time" | "color" | "file" | "hidden";
    required?: boolean;
    disabled?: boolean;
    readOnly?: boolean;
    class?: string;
    [key: string]: unknown;
  };
</script>

<script lang="ts">
  import { inputClasses } from "./input.shared";
  import { defaultIfEmpty, safeRest } from "../../utils/expr";

  let {
    type,
    required,
    disabled,
    readOnly,
    class: className,
    ...rawRest
  }: InputProps = $props();

  const rest = $derived(safeRest(rawRest, { blank: ["id", "name", "placeholder", "min", "max", "step", "aria-invalid", "aria-describedby"] }));
  const cls = $derived(inputClasses({ className }));
</script>

<input type={defaultIfEmpty(type, "text")} {...(cls ? { class: cls } : {})} required={required || undefined} disabled={disabled || undefined} readonly={readOnly || undefined} {...rest} />
kit/ui/input/input.shared.ts
// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.input — shared TypeScript contract (types + classes helpers)

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

/** Input renders a native input element (default type text). */
export type InputBaseProps = {
  type?: "text" | "email" | "password" | "search" | "tel" | "url" | "number" | "range" | "date" | "datetime-local" | "month" | "week" | "time" | "color" | "file" | "hidden";
  required?: boolean;
  disabled?: boolean;
  readOnly?: boolean;
};

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

/** Compose Input classes without rendering — the cross-runtime `asChild` substitute. */
export function inputClasses(input: InputClassesInput = {}): 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-input
kit/ui/input/input.shared.ts
// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.input — shared TypeScript contract (types + classes helpers)

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

/** Input renders a native input element (default type text). */
export type InputBaseProps = {
  type?: "text" | "email" | "password" | "search" | "tel" | "url" | "number" | "range" | "date" | "datetime-local" | "month" | "week" | "time" | "color" | "file" | "hidden";
  required?: boolean;
  disabled?: boolean;
  readOnly?: boolean;
};

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

/** Compose Input classes without rendering — the cross-runtime `asChild` substitute. */
export function inputClasses(input: InputClassesInput = {}): string {
  return cn(input.className);
}
kit/ui/input/input.tsx
// Code generated by @ui8kit/codegen. DO NOT EDIT.
/**
 * Input is a single-line native form control (checkbox/radio have their own primitives).
 */

import { forwardRef, type InputHTMLAttributes } from "react";
import { inputClasses } from "./input.shared";
import { defaultIfEmpty, safeRest } from "../../utils/expr";

/**
 * Input renders a native input element (default type text).
 */
export type InputProps = Omit<InputHTMLAttributes<HTMLInputElement>, "className" | "children" | "type" | "required" | "disabled" | "readOnly"> & {
  type?: "text" | "email" | "password" | "search" | "tel" | "url" | "number" | "range" | "date" | "datetime-local" | "month" | "week" | "time" | "color" | "file" | "hidden";
  required?: boolean;
  disabled?: boolean;
  readOnly?: boolean;
  className?: string;
};

export const Input = forwardRef<HTMLInputElement, InputProps>(function Input(
  { type, required, disabled, readOnly, className, ...rawRest },
  ref
) {
  const rest = safeRest(rawRest, { blank: ["id", "name", "placeholder", "min", "max", "step", "aria-invalid", "aria-describedby"] });
  const cls = inputClasses({ className });
  return (
    <input ref={ref} type={defaultIfEmpty(type, "text")} className={cls || undefined} required={required} disabled={disabled} readOnly={readOnly} {...rest} />
  );
});
Input.displayName = "Input";

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-input
kit/ui/input/Input.vue
<!-- Code generated by @ui8kit/codegen. DO NOT EDIT. -->
<!--
  Input renders a native input element (default type text).
-->
<script setup lang="ts">
import { computed, useAttrs } from "vue";
import { inputClasses } from "./input.shared";
import { defaultIfEmpty, safeRest } from "../../utils/expr";

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

const props = defineProps<{
  type?: "text" | "email" | "password" | "search" | "tel" | "url" | "number" | "range" | "date" | "datetime-local" | "month" | "week" | "time" | "color" | "file" | "hidden";
  required?: boolean;
  disabled?: boolean;
  readOnly?: 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", "placeholder", "min", "max", "step", "aria-invalid", "aria-describedby"] });
});
const cls = computed(() => inputClasses({ className: callerClass.value }));
</script>

<template>
  <input :type="defaultIfEmpty(props.type, 'text')" :class="cls || undefined" :required="props.required || undefined" :disabled="props.disabled || undefined" :readonly="props.readOnly || undefined" v-bind="restAttrs" />
</template>
kit/ui/input/input.shared.ts
// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.input — shared TypeScript contract (types + classes helpers)

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

/** Input renders a native input element (default type text). */
export type InputBaseProps = {
  type?: "text" | "email" | "password" | "search" | "tel" | "url" | "number" | "range" | "date" | "datetime-local" | "month" | "week" | "time" | "color" | "file" | "hidden";
  required?: boolean;
  disabled?: boolean;
  readOnly?: boolean;
};

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

/** Compose Input classes without rendering — the cross-runtime `asChild` substitute. */
export function inputClasses(input: InputClassesInput = {}): 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-input
kit/ui/input/input.shared.ts
// Code generated by @ui8kit/codegen. DO NOT EDIT.
// ui.input — shared TypeScript contract (types + classes helpers)

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

/** Input renders a native input element (default type text). */
export type InputBaseProps = {
  type?: "text" | "email" | "password" | "search" | "tel" | "url" | "number" | "range" | "date" | "datetime-local" | "month" | "week" | "time" | "color" | "file" | "hidden";
  required?: boolean;
  disabled?: boolean;
  readOnly?: boolean;
};

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

/** Compose Input classes without rendering — the cross-runtime `asChild` substitute. */
export function inputClasses(input: InputClassesInput = {}): string {
  return cn(input.className);
}
kit/ui/input/input.solid.tsx
// Code generated by @ui8kit/codegen. DO NOT EDIT.
/**
 * Input is a single-line native form control (checkbox/radio have their own primitives).
 */

import { splitProps, type JSX, type Component } from "solid-js";
import { inputClasses } from "./input.shared";
import { defaultIfEmpty, safeRest } from "../../utils/expr";

/**
 * Input renders a native input element (default type text).
 */
export type InputProps = Omit<JSX.InputHTMLAttributes<HTMLInputElement>, "class" | "className" | "children" | "type" | "required" | "disabled" | "readOnly"> & {
  type?: "text" | "email" | "password" | "search" | "tel" | "url" | "number" | "range" | "date" | "datetime-local" | "month" | "week" | "time" | "color" | "file" | "hidden";
  required?: boolean;
  disabled?: boolean;
  readOnly?: boolean;
  class?: string;
  className?: string;
};

export const Input: Component<InputProps> = (props) => {
  const [local, rest] = splitProps(props, ["type", "required", "disabled", "readOnly", "class", "className"]);
  const cls = () => inputClasses({ className: local.class ?? local.className });
  return (
    <input type={defaultIfEmpty(local.type, "text")} {...(cls() ? { class: cls() } : {})} required={local.required || undefined} disabled={local.disabled || undefined} readonly={local.readOnly || undefined} {...safeRest(rest, { blank: ["id", "name", "placeholder", "min", "max", "step", "aria-invalid", "aria-describedby"] })} />
  );
};

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-input
ui/input/input.templ
// Code generated by @ui8kit/codegen. DO NOT EDIT.

/*
Input is a single-line native form control (checkbox/radio have their own primitives).
*/

package input

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

// InputProps configures Input.
type InputProps struct {
	// Class — token class names supplied by the consumer
	Class string
	// Type — input type (default text)
	Type string
	ID string
	Name string
	Value *string
	Placeholder string
	Min string
	Max string
	Step string
	Required bool
	Disabled bool
	ReadOnly bool
	AriaInvalid string
	AriaDescribedBy string
	Attrs templ.Attributes
}

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

// Input renders the Input contract.
templ Input(p InputProps) {
	<input
		if !uiutils.HasAttr(p.Attrs, "type") {
			type={ uiutils.DefaultIfEmpty(p.Type, "text") }
		}
		if InputClasses(p) != "" {
			class={ InputClasses(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, "value") {
			if p.Value != nil {
				value={ *p.Value }
			}
		}
		if !uiutils.HasAttr(p.Attrs, "placeholder") {
			if uiutils.IsSetStr(p.Placeholder) {
				placeholder={ p.Placeholder }
			}
		}
		if !uiutils.HasAttr(p.Attrs, "min") {
			if uiutils.IsSetStr(p.Min) {
				min={ p.Min }
			}
		}
		if !uiutils.HasAttr(p.Attrs, "max") {
			if uiutils.IsSetStr(p.Max) {
				max={ p.Max }
			}
		}
		if !uiutils.HasAttr(p.Attrs, "step") {
			if uiutils.IsSetStr(p.Step) {
				step={ p.Step }
			}
		}
		if !uiutils.HasAttr(p.Attrs, "required") {
			required?={ p.Required }
		}
		if !uiutils.HasAttr(p.Attrs, "disabled") {
			disabled?={ p.Disabled }
		}
		if !uiutils.HasAttr(p.Attrs, "readonly") {
			readonly?={ p.ReadOnly }
		}
		if !uiutils.HasAttr(p.Attrs, "aria-invalid") {
			if uiutils.IsSetStr(p.AriaInvalid) {
				aria-invalid={ p.AriaInvalid }
			}
		}
		if !uiutils.HasAttr(p.Attrs, "aria-describedby") {
			if uiutils.IsSetStr(p.AriaDescribedBy) {
				aria-describedby={ p.AriaDescribedBy }
			}
		}
		{ uiutils.RestAttrs(p.Attrs, false, "id", "name", "placeholder", "min", "max", "step", "aria-invalid", "aria-describedby")... }
	/>
}

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-input
ui/input/Input.html.twig
{# Code generated by @ui8kit/codegen. DO NOT EDIT. #}
{# Input — Input renders a native input element (default type text). #}
{# @param class (string) #}
{# @param type (string) #}
{# @param id (string) #}
{# @param name (string) #}
{# @param value (string) #}
{# @param placeholder (string) #}
{# @param min (string) #}
{# @param max (string) #}
{# @param step (string) #}
{# @param required (bool) #}
{# @param disabled (bool) #}
{# @param readOnly (bool) #}
{# @param ariaInvalid (string) #}
{# @param ariaDescribedBy (string) #}
{# @param attrs (attrs) #}
{% set class = class|default('') %}
{% set type = type|default('') %}
{% set id = id ?? null %}
{% set name = name ?? null %}
{% set value = value ?? null %}
{% set placeholder = placeholder ?? null %}
{% set min = min ?? null %}
{% set max = max ?? null %}
{% set step = step ?? null %}
{% set required = required|default(false) %}
{% set disabled = disabled|default(false) %}
{% set readOnly = readOnly|default(false) %}
{% set ariaInvalid = ariaInvalid ?? null %}
{% set ariaDescribedBy = ariaDescribedBy ?? null %}
{% set attrs = attrs|default([]) %}
<input{{ ui8kit_attrs({'type': ui8kit_default_if_empty(type, 'text'), 'class': ui8kit_or_null(ui8kit_classes('inputClasses', {'class': class, 'type': type, 'id': id, 'name': name, 'value': value, 'placeholder': placeholder, 'min': min, 'max': max, 'step': step, 'required': required, 'disabled': disabled, 'readOnly': readOnly, 'ariaInvalid': ariaInvalid, 'ariaDescribedBy': ariaDescribedBy})), 'id': ui8kit_or_null(id), 'name': ui8kit_or_null(name), 'value': value, 'placeholder': ui8kit_or_null(placeholder), 'min': ui8kit_or_null(min), 'max': ui8kit_or_null(max), 'step': ui8kit_or_null(step), 'required': required, 'disabled': disabled, 'readonly': readOnly, 'aria-invalid': ui8kit_or_null(ariaInvalid), 'aria-describedby': ui8kit_or_null(ariaDescribedBy)}, attrs, false, ['id', 'name', 'placeholder', 'min', 'max', 'step', 'aria-invalid', 'aria-describedby']) }}>

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-input
ui/input/Input.latte
{* Code generated by @ui8kit/codegen. DO NOT EDIT. *}
{* Input — Input renders a native input element (default type text). *}
{parameters
  string $class = '',
  string $type = '',
  ?string $id = null,
  ?string $name = null,
  ?string $value = null,
  ?string $placeholder = null,
  ?string $min = null,
  ?string $max = null,
  ?string $step = null,
  bool $required = false,
  bool $disabled = false,
  bool $readOnly = false,
  ?string $ariaInvalid = null,
  ?string $ariaDescribedBy = null,
  array $attrs = [],
}
<input n:attr="[
  'type' => \UI8Kit\Latte\Rt::defaultIfEmpty($type, 'text'),
  'class' => \UI8Kit\Latte\Rt::orNull(\UI8Kit\Latte\Classes::inputClasses(['class' => $class, 'type' => $type, 'id' => $id, 'name' => $name, 'value' => $value, 'placeholder' => $placeholder, 'min' => $min, 'max' => $max, 'step' => $step, 'required' => $required, 'disabled' => $disabled, 'readOnly' => $readOnly, 'ariaInvalid' => $ariaInvalid, 'ariaDescribedBy' => $ariaDescribedBy])),
  'id' => \UI8Kit\Latte\Rt::orNull($id),
  'name' => \UI8Kit\Latte\Rt::orNull($name),
  'value' => $value,
  'placeholder' => \UI8Kit\Latte\Rt::orNull($placeholder),
  'min' => \UI8Kit\Latte\Rt::orNull($min),
  'max' => \UI8Kit\Latte\Rt::orNull($max),
  'step' => \UI8Kit\Latte\Rt::orNull($step),
  'required' => $required,
  'disabled' => $disabled,
  'readonly' => $readOnly,
  'aria-invalid' => \UI8Kit\Latte\Rt::orNull($ariaInvalid),
  'aria-describedby' => \UI8Kit\Latte\Rt::orNull($ariaDescribedBy),
  ...\UI8Kit\Latte\Rt::restAttrs($attrs, false, ['id', 'name', 'placeholder', 'min', 'max', 'step', 'aria-invalid', 'aria-describedby']),
]">

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-input
ui/input/input.html.j2
{#- Code generated by @ui8kit/codegen. DO NOT EDIT.
    Input: Input renders a native input element (default type text).
    Props (p): Class (string), Type (string), ID (string), Name (string), Value (string), Placeholder (string), Min (string), Max (string), Step (string), Required (bool), Disabled (bool), ReadOnly (bool), AriaInvalid (string), AriaDescribedBy (string), Attrs (attrs).
    Classes without rendering: input_classes(p) (no asChild in Jinja2). -#}
<input
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'type') %} type="{{ ui_default_if_empty(ui_def(p['Type'], ''), 'text') }}"{%- endif %}
  {%- with cls = input_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'], {}), 'value') %}{%- if p['Value'] is defined and p['Value'] is not none %} value="{{ p['Value'] }}"{%- endif %}{%- endif %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'placeholder') %}{%- if ui_is_set_str(p['Placeholder']) %} placeholder="{{ p['Placeholder'] }}"{%- endif %}{%- endif %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'min') %}{%- if ui_is_set_str(p['Min']) %} min="{{ p['Min'] }}"{%- endif %}{%- endif %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'max') %}{%- if ui_is_set_str(p['Max']) %} max="{{ p['Max'] }}"{%- endif %}{%- endif %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'step') %}{%- if ui_is_set_str(p['Step']) %} step="{{ p['Step'] }}"{%- endif %}{%- endif %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'required') %}{%- if ui_def(p['Required'], false) %} required{%- endif %}{%- endif %}
  {%- 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'], {}), 'readonly') %}{%- if ui_def(p['ReadOnly'], false) %} readonly{%- endif %}{%- endif %}
  {%- if not ui_has_attr(ui_def(p['Attrs'], {}), 'aria-invalid') %}{%- if ui_is_set_str(p['AriaInvalid']) %} aria-invalid="{{ p['AriaInvalid'] }}"{%- 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', 'placeholder', 'min', 'max', 'step', 'aria-invalid', 'aria-describedby']) }}
>

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.