Search Field
Search Field component
Install
npx ui8kit add search-fieldPulls in: box, compose, input, kit-box, kit-input, lucide-icon, utils
Preview
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 search-field<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!-- A search input with a magnifier. `value` fires on every keystroke with the new text. -->
<script lang="ts" module>
import type { Snippet } from "svelte";
export type SearchFieldProps = {
value: string;
placeholder?: string;
label: string;
class?: string;
onvalue?: (value: string) => void;
};
</script>
<script lang="ts">
import Box from "../compose/Box.svelte";
import Input from "../compose/Input.svelte";
import LucideIcon from "../icons/LucideIcon.svelte";
import { cn } from "../utils";
let { value, placeholder, label, class: className, onvalue }: SearchFieldProps = $props();
</script>
<Box class={cn("relative min-w-44 flex-1", className)} role="search" data-slot="search-field">
<LucideIcon name="search" size={16} class="pointer-events-none absolute top-2 left-3 text-muted-foreground" />
<Input
size="sm"
type="search"
placeholder={placeholder}
aria-label={label}
class="pr-3 pl-10"
value={value}
oninput={(event: Event & { currentTarget: HTMLInputElement }) => onvalue?.(event.currentTarget.value)}
/>
</Box>
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 search-field// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/** A search input with a magnifier. `value` fires on every keystroke with the new text. */
import { type ChangeEvent, type ReactNode } from "react";
import { Box, Input } from "../compose";
import { LucideIcon } from "../icons/LucideIcon";
import { cn } from "../utils";
export type SearchFieldProps = {
value: string;
placeholder?: string;
label: string;
className?: string;
onValue?: (value: string) => void;
};
export function SearchField({ value, placeholder, label, className, onValue }: SearchFieldProps) {
return (
<Box className={cn("relative min-w-44 flex-1", className)} role="search" data-slot="search-field">
<LucideIcon name="search" size={16} className="pointer-events-none absolute top-2 left-3 text-muted-foreground" />
<Input
size="sm"
type="search"
placeholder={placeholder}
aria-label={label}
className="pr-3 pl-10"
value={value}
onChange={(event: ChangeEvent<HTMLInputElement>) => onValue?.(event.currentTarget.value)}
/>
</Box>
);
}
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 search-field<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!-- A search input with a magnifier. `value` fires on every keystroke with the new text. -->
<script lang="ts">
export type SearchFieldProps = {
value: string;
placeholder?: string;
label: string;
class?: string;
};
</script>
<script setup lang="ts">
import Box from "../compose/Box.vue";
import Input from "../compose/Input.vue";
import LucideIcon from "../icons/LucideIcon.vue";
import { cn } from "../utils";
const { value, placeholder, label, class: className } = defineProps<SearchFieldProps>();
const emit = defineEmits<{ value: [value: string] }>();
</script>
<template>
<Box :class="cn('relative min-w-44 flex-1', className)" role="search" data-slot="search-field">
<LucideIcon name="search" :size="16" class="pointer-events-none absolute top-2 left-3 text-muted-foreground" />
<Input
size="sm"
type="search"
:placeholder="placeholder"
:aria-label="label"
class="pr-3 pl-10"
:value="value"
@input="(event: Event & { currentTarget: HTMLInputElement }) => emit('value', event.currentTarget.value)"
/>
</Box>
</template>
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 search-field// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/** A search input with a magnifier. `value` fires on every keystroke with the new text. */
import { type JSX } from "solid-js";
import { Box, Input } from "../compose";
import { LucideIcon } from "../icons/LucideIcon";
import { cn } from "../utils";
export type SearchFieldProps = {
value: string;
placeholder?: string;
label: string;
class?: string;
onValue?: (value: string) => void;
};
export function SearchField({ value, placeholder, label, class: className, onValue }: SearchFieldProps) {
return (
<Box class={cn("relative min-w-44 flex-1", className)} role="search" data-slot="search-field">
<LucideIcon name="search" size={16} class="pointer-events-none absolute top-2 left-3 text-muted-foreground" />
<Input
size="sm"
type="search"
placeholder={placeholder}
aria-label={label}
class="pr-3 pl-10"
value={value}
onInput={(event: InputEvent & { currentTarget: HTMLInputElement }) => onValue?.(event.currentTarget.value)}
/>
</Box>
);
}
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 search-field// Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
// Source: packages/compose-gen/specs/parts/search-field.json
package blocks
import (
"github.com/ui8kit/codegen/generated/templ/ui/box"
"github.com/ui8kit/codegen/generated/templ/compose"
"github.com/ui8kit/codegen/generated/templ/icons"
"github.com/ui8kit/codegen/generated/templ/ui/input"
uiutils "github.com/ui8kit/codegen/generated/templ/orgutils"
)
// SearchFieldProps are the props of SearchField; the values are the JSON shapes of the TypeScript props.
type SearchFieldProps struct {
Value any `json:"value"`
Placeholder any `json:"placeholder"`
Label any `json:"label"`
Class string `json:"className"`
}
// A search input with a magnifier. `value` fires on every keystroke with the new text.
templ SearchField(p SearchFieldProps) {
{{ vValue := p.Value }}
{{ vPlaceholder := p.Placeholder }}
{{ vLabel := p.Label }}
@compose.Box(compose.BoxProps{BoxProps: box.BoxProps{Class: uiutils.S(uiutils.Cnv("relative min-w-44 flex-1", p.Class)), Attrs: uiutils.Attrs("role", "search", "data-slot", "search-field")}}) {
@icons.LucideIcon(icons.LucideIconProps{Name: "search", Size: 16, Class: "pointer-events-none absolute top-2 left-3 text-muted-foreground"})
@compose.Input(compose.InputProps{Size: "sm", InputProps: input.InputProps{Type: "search", Placeholder: uiutils.S(vPlaceholder), Class: "pr-3 pl-10", Value: uiutils.SP(vValue), Attrs: uiutils.Attrs("aria-label", vLabel)}})
}
}
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 search-field{#- Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
Source: packages/compose-gen/specs/parts/search-field.json
A search input with a magnifier. `value` fires on every keystroke with the new text.
Props (p): value, placeholder, label, className. -#}
{%- set v_value = (p.value ?? null) -%}
{%- set v_placeholder = (p.placeholder ?? null) -%}
{%- set v_label = (p.label ?? null) -%}
{%- set c_1 -%}
{{ include('icons/LucideIcon.html.twig', {'name': 'search', 'size': 16, 'class': 'pointer-events-none absolute top-2 left-3 text-muted-foreground'}, with_context = false) }}
{{ include('compose/Input.html.twig', {'size': 'sm', 'type': 'search', 'placeholder': og_s(v_placeholder), 'class': 'pr-3 pl-10', 'value': og_s(v_value), 'attrs': og_attrs(['aria-label', v_label])}, with_context = false) }}
{%- endset -%}
{{ include('compose/Box.html.twig', {'class': og_s(og_cnv(['relative min-w-44 flex-1', (p.className ?? '')])), 'attrs': og_attrs(['role', 'search', 'data-slot', 'search-field']), 'children': c_1}, with_context = false) }}
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 search-field{* Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
Source: packages/compose-gen/specs/parts/search-field.json
A search input with a magnifier. `value` fires on every keystroke with the new text.
Props (p): value, placeholder, label, className. *}
{var $v_value = ($p['value'] ?? null)}
{var $v_placeholder = ($p['placeholder'] ?? null)}
{var $v_label = ($p['label'] ?? null)}
{capture $c_1}
{=og_include('icons/LucideIcon.latte', ['name' => 'search', 'size' => 16, 'class' => 'pointer-events-none absolute top-2 left-3 text-muted-foreground'])|noescape}
{=og_include('compose/Input.latte', ['size' => 'sm', 'type' => 'search', 'placeholder' => og_s($v_placeholder), 'class' => 'pr-3 pl-10', 'value' => og_s($v_value), 'attrs' => og_attrs(['aria-label', $v_label])])|noescape}
{/capture}
{=og_include('compose/Box.latte', ['class' => og_s(og_cnv(['relative min-w-44 flex-1', ($p['className'] ?? '')])), 'attrs' => og_attrs(['role', 'search', 'data-slot', 'search-field']), 'children' => (string) $c_1])|noescape}
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 search-field{#- Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
Source: packages/compose-gen/specs/parts/search-field.json
A search input with a magnifier. `value` fires on every keystroke with the new text.
Props (p): value, placeholder, label, className. -#}
{%- set v_value = og_def(p['value'], none) -%}
{%- set v_placeholder = og_def(p['placeholder'], none) -%}
{%- set v_label = og_def(p['label'], none) -%}
{%- set c_1 -%}
{{ og_include('icons/lucide-icon.html.j2', {'p': {'Name': 'search', 'Size': 16, 'Class': 'pointer-events-none absolute top-2 left-3 text-muted-foreground'}}) }}
{{ og_include('compose/input.html.j2', {'p': {'Size': 'sm', 'Type': 'search', 'Placeholder': og_s(v_placeholder), 'Class': 'pr-3 pl-10', 'Value': og_s(v_value), 'Attrs': og_attrs(['aria-label', v_label])}}) }}
{%- endset -%}
{{ og_include('compose/box.html.j2', {'p': {'Class': og_s(og_cnv(['relative min-w-44 flex-1', og_def(p['className'], '')])), 'Attrs': og_attrs(['role', 'search', 'data-slot', 'search-field'])}, 'children': c_1}) }}
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.
A search input with a magnifier. `value` fires on every keystroke with the new text.
| Prop | Type | Default | Description |
|---|---|---|---|
| value (required) | string | - | |
| placeholder | string | - | |
| label (required) | string | - | accessible name |