Skip to content
ui8kit

primitive / primitives

Input

Input primitive

Install

npx ui8kit add input

Pulls in: kit-input, recipes, utils

Preview

size: sm
size: default
size: lg
variant: default
variant: ghost

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 input
compose/Input.svelte
<!-- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. -->
<!-- Input: Input + recipe input. -->
<script lang="ts">
  import type { ComponentProps, Snippet } from "svelte";
  import Prim from "../kit/ui/input/Input.svelte";
  import { cn } from "../kit/utils";
  import { rc } from "./recipes";

  let { "size": v_size, "variant": v_variant, "state": v_state, class: className, children, ...rest }: ComponentProps<typeof Prim> & { "size"?: string | number; "variant"?: string | number; "state"?: string | number; class?: string; children?: Snippet } = $props();
  const cls = $derived(cn(rc("input", { "size": v_size, "variant": v_variant, "state": v_state }), className));
</script>

<Prim class={cls} aria-invalid={v_state === "error" ? "true" : undefined} {...rest} />

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 input
compose/input.tsx
// Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.
import type { ComponentProps } from "react";
import { Input as Prim } from "../kit/ui/input/input";
import { cn } from "../kit/utils";
import { rc } from "./recipes";

export type InputProps = Omit<ComponentProps<typeof Prim>, "tag" | "size" | "variant" | "state"> & { "size"?: string | number; "variant"?: string | number; "state"?: string | number; className?: string };

/** Input: Input + recipe input. */
export function Input({ "size": v_size, "variant": v_variant, "state": v_state, className, ...rest }: InputProps) {
  return <Prim className={cn(rc("input", { "size": v_size, "variant": v_variant, "state": v_state }), className)} aria-invalid={v_state === "error" ? "true" : undefined} {...rest} />;
}

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 input
compose/Input.vue
<!-- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. -->
<!-- Input: Input + recipe input. -->
<script setup lang="ts">
import { computed, useAttrs } from "vue";
import Prim from "../kit/ui/input/Input.vue";
import { cn } from "../kit/utils";
import { rc } from "./recipes";

defineOptions({ name: "Input", inheritAttrs: false });
const props = defineProps<{ "size"?: string | number; "variant"?: string | number; "state"?: string | number }>();
const attrs = useAttrs();
const rest = computed(() => {
  const { class: _class, ...r } = attrs;
  return r;
});
const cls = computed(() => cn(rc("input", { "size": props["size"], "variant": props["variant"], "state": props["state"] }), attrs.class as string | undefined));
const tagValue = computed(() => "");
</script>

<template>
  <Prim :class="cls" :aria-invalid="props.state === 'error' ? 'true' : undefined" v-bind="rest" />
</template>

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 input
compose/input.solid.tsx
// Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.
import { splitProps, type ComponentProps } from "solid-js";
import { Input as Prim } from "../kit/ui/input/input.solid";
import { cn } from "../kit/utils";
import { rc } from "./recipes";

export type InputProps = Omit<ComponentProps<typeof Prim>, "tag" | "class" | "className" | "size" | "variant" | "state"> & { "size"?: string | number; "variant"?: string | number; "state"?: string | number; class?: string; className?: string };

/** Input: Input + recipe input. */
export function Input(props: InputProps) {
  const [local, rest] = splitProps(props, ["size", "variant", "state", "class", "className"]);
  return <Prim class={cn(rc("input", { "size": local["size"], "variant": local["variant"], "state": local["state"] }), local.class ?? local.className)} aria-invalid={local["state"] === "error" ? "true" : undefined} {...rest} />;
}

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 input
compose/input.templ
// Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.

package compose

import "github.com/ui8kit/codegen/generated/templ/ui/input"

// InputProps: Input: Input + recipe input.
type InputProps struct {
	Size string
	Variant string
	State string
	input.InputProps
}

func inputInner(p InputProps) input.InputProps {
	in := p.InputProps
	in.Class = Join(Rc("input", map[string]string{"size": p.Size, "variant": p.Variant, "state": p.State}), p.InputProps.Class)
	if p.State == "error" {
		in.AriaInvalid = Or(in.AriaInvalid, "true")
	}
	return in
}

// Input renders Input with the composition classes.
templ Input(p InputProps) {
	@input.Input(inputInner(p))
}

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 input
compose/Input.html.twig
{# Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. #}
{# Input: Input + recipe input. Params: size, variant, state, class, attrs + the params of Input. #}
{% include 'ui/input/Input.html.twig' with compose_props('Input', _context) only %}

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 input
compose/Input.latte
{* Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. *}
{* Input: Input + recipe input. *}
{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 = [],
  $size = null,
  $variant = null,
  $state = null,
}
{include '../ui/input/Input.latte', ...\CodegenX\Compose\Latte\Compose::props('Input', ['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, 'attrs' => $attrs, 'size' => $size, 'variant' => $variant, 'state' => $state])}

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 input
compose/input.html.j2
{#- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.
    Input: Input + recipe input. Props (p): Size, Variant, State, Class, Attrs + the props of Input. -#}
{%- with p = compose_props('Input', p) %}{% include 'ui/input/input.html.j2' %}{% endwith %}

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.

Input renders a native input element (default type text).

Props of Input
PropTypeDefault Description
type string-input type (default text)
required boolean-
disabled boolean-
readOnly boolean-