Files
svelte/Input.svelte
zeekayandHanzo Dev 1008926ef7 @hanzo/svelte 1.0.0 — the Svelte backend, on its own
Extracted from @hanzo/ui pkg/ui/src/backends/svelte with its history. It lived
inside a React component library, which meant every consumer of @hanzo/ui
resolved svelte whether they rendered a single Svelte component or not, and the
package declared peer svelte>=5 against a dev svelte ^4.2.20 — two answers to
one question.

Three runtime dependencies, all load-bearing: class-variance-authority for the
variants the components already used, and clsx + tailwind-merge behind cn. The
cn helper is vendored (17 lines) rather than imported back from @hanzo/ui,
because depending on the package this was extracted from would undo the split.
No design-system runtime, no icon pack, no CSS-in-JS.

svelte-check: 50 files, 0 errors.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-28 12:28:39 -07:00

41 lines
1.4 KiB
Svelte

<!-- Input — standard-token text field; class string mirrors the shadcn backend. -->
<script lang="ts">
import { cn } from './core/cn'
let className: string | undefined = undefined
export { className as class }
export let value: string | number = ''
export let type = 'text'
export let disabled = false
export let readonly = false
export let placeholder: string | undefined = undefined
// Svelte forbids `bind:value` together with a dynamic `type`; set the type via
// an action and keep `value` controlled so a consumer's `bind:value` still
// receives updates through the exported prop.
function typeAttr(node: HTMLInputElement, t: string) {
node.type = t
return { update: (next: string) => { node.type = next } }
}
</script>
<input
use:typeAttr={type}
{value}
{disabled}
{readonly}
{placeholder}
data-slot="input"
class={cn(
'flex h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-3 py-1 text-sm text-foreground shadow-xs transition-colors outline-none file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20',
className,
)}
on:input={(e) => (value = e.currentTarget.value)}
on:input
on:change
on:keydown
on:focus
on:blur
{...$$restProps}
/>