Command palette

@yasinsensoy/web

Web · Components

Input

Single-line text input.

14 exports

Live example

Preview

Code

import { Label, Input } from "@yasinsensoy/web";

<Label htmlFor="email">E-posta</Label>
<Input id="email" placeholder="[email protected]" icon="mail" />

Events

  1. Events appear here when you interact with the preview.

Appearances: outline, filled, underline, ghost

outline
filled
underline
ghost

Whole section: data-field-variant="filled" (its own variant wins)

Import

import {
  Input,
  fieldVariants,
  MASK_TOKENS,
  MASK_PRESETS,
  applyMask,
} from "@yasinsensoy/web";

Input

componentServer component

Single-line text input. Supports all native <input> props. Give aria-invalid for invalid fields; they show with a red border.

For the right keyboard on mobile use a fitting type and inputMode (e.g. type="email", inputMode="numeric", type="tel") and enable autofill with autoComplete.

  • mask: patterned input such as phone, plate, IBAN (see MaskProp).
  • label: a floating label; inside when empty, on top when typing.
Input({ type, icon, iconEnd, reveal, label, floatingLabel, mask, onValueChange, unmask, value, defaultValue, variant, effect, ...props }: InputProps): JSX.Element

Examples

<Label htmlFor="email">Email</Label>
<Input id="email" type="email" autoComplete="email" placeholder="[email protected]" />

<Input aria-invalid aria-describedby="code-error" inputMode="numeric" />

<Input type="search" icon="search" placeholder="Search" />
<Input variant="filled" placeholder="Filled" />
<Input variant="underline" placeholder="Underlined" />

<Input type="password" autoComplete="current-password" />            // shows while held
<Input type="password" autoComplete="new-password" reveal="toggle" /> // press to show, press to hide
<Input type="password" inputMode="numeric" reveal={false} />         // no button

<Input mask="phone" name="phone" />                   // 0 (532) 123 45 67
<Input mask="plate" name="plate" />                   // 34 ABC 123
<Input mask="iban" name="iban" unmask />              // "TR…" without spaces in the form
<Input mask="AA-9999" />                              // custom pattern: "AB-1234"

<Input label="Email" type="email" />                  // floating label (by appearance)
<Input label="Name" variant="filled" />               // label at the top inside the box
<Input label="Phone" mask="phone" floatingLabel="border" />

Shared look of text fields. Used by Input and Textarea.

Mobile behavior: The font size is 16 px on small screens. iOS Safari zooms the page automatically when focusing fields with text smaller than 16 px; this prevents that zoom. It drops to 14 px on wide screens.

The style (filled, underline, ghost) is chosen with the data-field-variant attribute, not classes; see FieldVariant.

fieldVariants: VariantsFunction<Record<never, never>>

MASK_TOKENS

constant

Built-in pattern letters.

MASK_TOKENS: Readonly<Record<string, MaskToken>>

MASK_PRESETS

constant

Built-in mask definitions. You can derive your own masks from these.

MASK_PRESETS: Readonly<Record<MaskPreset, MaskOptions>>

applyMask

function

Formats text with a mask. Also useful outside components: showing a stored unmasked value in a list, validating on the server, etc. Also runs on the server.

applyMask(value: string, mask: MaskProp): MaskResult

Examples

applyMask("5321234567", "phone").value;          // "0 (532) 123 45 67"
applyMask("0 (532) 123 45 67", "phone").unmasked; // "05321234567"
applyMask("34abc123", "plate");                   // { value: "34 ABC 123", complete: true, valid: true, … }
applyMask("TR00 0000", "iban").valid;             // false

Appearance of a form field. Input, Textarea, Select, Autocomplete, TagInput, NumberInput, DatePicker, TimePicker, ColorPicker and RichTextEditor take it via the variant prop; the *Field wrappers pass the same prop through.

  • outline: bordered, background same as the page (default).
  • filled: borderless, light gray fill; lightens on focus. Calmer on the eye in dense forms and on mobile.
  • underline: only a bottom line; the line darkens on focus. For plain, "paper"-looking forms and inline editing.
  • ghost: borderless and unfilled; appears on hover or focus. For places like toolbars, table cells and title editing.

Page or section-wide default: Give any container data-field-variant="filled"; all fields inside take that appearance. <body data-field-variant="filled"> in the root layout changes the whole app. It is CSS only; it works in server components too and needs no JavaScript or provider. The field's own variant prop always wins; in nested containers the nearest one applies.

From UIProvider: appearance.defaults.field is the default variant and effect of all fields; appearance.variants.field adds your own styles (string: classes, based on outline; object: { extends: "filled", className }). The field's own prop still wins.

defineAppearance({
  defaults: { field: { variant: "glass", effect: "glow" } },
  variants: { field: { glass: { extends: "filled", className: "backdrop-blur bg-muted/60" } } },
});

Focus look: No ring is drawn outside the focused field (so it doesn't cover a floating label on the top border); the border thickens inward by 2 px and gets colored. The space the field takes doesn't change. The color is chosen with the --ui-field-focus CSS variable (the primary color by default); it can be set for a theme, page, section or single field:

:root { --ui-field-focus: oklch(0.55 0.2 260); }
[data-theme="ocean"] { --ui-field-focus: var(--ui-success); }
<form className="[--ui-field-focus:var(--ui-success)]">…</form>
<TextField label="Note" className="[--ui-field-focus:orange]" />
type FieldVariant = "outline" | "filled" | "underline" | "ghost"

Examples

<Input variant="filled" placeholder="Search" />
<Select variant="underline" items={cities} />

<form data-field-variant="filled">
  <TextField label="Name" />          // filled
  <SelectField label="City" items={cities} /> // filled
  <Input variant="outline" />       // its own setting wins
</form>

InputProps

interface

Props of the Input component.

Extends: ComponentProps<"input">

NameTypeDefaultDescription
icon?IconPropIcon at the start of the field: a name ("search") or an element.
iconEnd?IconPropIcon or small content at the end of the field (e.g. a unit, "TL").
variant?FieldVariant | CustomVariant<"field">Appearance: outline (bordered), filled, underline or ghost (plain). If omitted, the setting of the nearest data-field-variant container is used, or outline if there is none. See FieldVariant.
effect?EffectPropEffect or effects of the field box (e.g. "glow", ["lift", "beam"]). The accent color is the focus color (--ui-field-focus). If omitted, UIProvider appearance.defaults.field.effect. See BuiltinEffect.
label?ReactNodeFloating label. While the field is empty it sits inside the field like a placeholder; on focus or when the field is filled it shrinks and moves up. It is linked to the field automatically (the accessible name comes from it); if id is omitted, one is generated. The placeholder (placeholder) is visible only while the label is up. Where it lifts to is chosen with floatingLabel. In a form, use TextField floatingLabel together with a label, description and error message.
floatingLabel?FloatingLabeltruePosition of the floating label: true (by appearance; default), "border" (on the top line) or "inside" (at the top inside the box). false disables the floating label. See FloatingLabel.
mask?MaskPropInput mask: formats what is typed by a pattern (phone, plate, IBAN…). Give a preset name ("phone", "plate", "iban", "tckn", "card", "date"…), a pattern ("(999) 999 99 99") or a detailed definition. See MaskProp. - Formatted while typing, pasting and on autofill; separators are added automatically and the caret stays in place. - The mobile keyboard is chosen by the pattern (numeric keyboard for a digit pattern). - When empty, the placeholder is generated from the pattern (0 (___) ___ __ __). - An incomplete value (maskIncomplete) or a checksum-failing value (maskInvalid, e.g. a wrong IBAN) doesn't submit the form; inside TextField the message appears under the field. value/defaultValue can be given with or without separators. The component runs on the client; an Input without a mask stays a server component.
onValueChange?(value: string, details: MaskResult) => voidOnly with mask: called with the formatted text and details (unmasked, complete, valid) when the value changes. See MaskResult.
unmask?booleanfalseOnly with mask: the form submits the value without separators (05321234567 instead of 0 (532) 123 45 67). The field shows the formatted text.
reveal?PasswordRevealMode | false"hold"Only for type="password": the eye button at the end of the field. - "hold": the password shows while held and hides on release (hold Space/Enter on the keyboard). - "toggle": each press toggles between show/hide. It hides automatically when the form is submitted. - false: no button (e.g. fields like a PIN that nobody should see). Pressing the button doesn't take focus from the field; the keyboard doesn't close on mobile. Button texts are changed in the dictionary's ui namespace (showPassword, hidePassword, holdToShowPassword; see UIProvider messages).

Position of the floating label. See InputProps.floatingLabel.

  • true: chosen by appearance: on the line (border) for outline fields, inside the box (inside) for filled, underline and ghost fields. It also follows the page-wide data-field-variant setting.
  • "border": sits on the top border; the border is cut behind the label. The field height doesn't change.
  • "inside": shrinks to the top inside the box; the field gets a bit taller (48 px).
  • false: no floating label.
type FloatingLabel = boolean | "border" | "inside"

MaskToken

interface

Which characters a letter in a mask pattern accepts.

NameTypeDescription
testRegExpRegular expression that tests a single character. When transform is set, the transformed character is tested.
transform?(char: string) => stringTransforms the character before accepting it (e.g. to uppercase).

Examples

// Hexadecimal digit, converted to uppercase.
const hex: MaskToken = { test: /[0-9A-F]/, transform: (c) => c.toUpperCase() };

Built-in masks. Each brings the pattern, the mobile keyboard type (inputMode), the autofill hint and, where needed, checksum validation.

  • phone: Turkish phone number, 0 (532) 123 45 67. Same result whether or not the leading 0 is typed.
  • phoneIntl: Turkish phone number in international format, +90 (532) 123 45 67.
  • plate: Turkish license plate, 34 ABC 123. Letters are uppercased; the province code (01–81) and the letter/digit count rule are checked.
  • tckn: Turkish national ID number, 11 digits; validated with the official algorithm.
  • taxNumber: Turkish tax ID number (VKN), 10 digits.
  • iban: Turkish IBAN, TR12 3456 …; validated with the mod-97 checksum.
  • card: Credit card, 1234 5678 9012 3456; validated with Luhn.
  • expiry: Card expiry date, MM/YY.
  • date: Date, DD.MM.YYYY; checked to be a real day.
  • time: Time, HH:MM (00:00–23:59).
  • postalCode: Postal code, 5 digits.
type MaskPreset = "phone" | "phoneIntl" | "plate" | "tckn" | "taxNumber" | "iban" | "card" | "expiry" | "date" | "time" | "postalCode"

MaskOptions

interface

Detailed mask definition. See MaskProp.

NameTypeDescription
patternstring | readonly string[]Pattern or patterns. With an array, the pattern that best fits the input is used (e.g. different formats for landlines and mobiles). See MaskProp.
tokens?Record<string, MaskToken>Additional or overridden letters to use in the pattern.
validate?(unmasked: string, formatted: string) => booleanCalled when the value is complete; returning false marks the field invalid (customError) and shows invalidMessage. Receives the value without separators (see MaskResult.unmasked).
invalidMessage?stringMessage shown when validate fails. Defaults to the maskInvalid text in the dictionary.
placeholder?stringPlaceholder shown while the field is empty. Generated from the pattern by default ((___) ___).
inputMode?"text" | "numeric" | "tel" | "decimal"Mobile keyboard. Defaults to numeric when the pattern only asks for digits.
autoComplete?stringBrowser autofill hint (e.g. tel-national).

Mask of a field. Given in three forms:

  1. Built-in mask name (MaskPreset): "phone", "plate", "iban"…
  2. Pattern (or an array of patterns): the letters below stand for a character the user types; everything else is a literal that is inserted automatically.
  3. 9: digit
  4. a: letter (including Turkish letters)
  5. A: letter, converted to uppercase
  6. *: letter or digit
  7. X: letter or digit, converted to uppercase
  8. {n} / {n,m} / {n,}: how many times the previous letter repeats (e.g. A{1,3} is 1–3 letters). In a variable-length section, type the separator (e.g. a space) to move to the next section, or just type a character of the next kind.
  9. \: makes the next character a literal (\9 → "9").
  10. Detailed definition (MaskOptions): custom letters, validation, placeholder, keyboard type.
type MaskProp = MaskPreset | (string & {}) | readonly string[] | MaskOptions

Examples

<Input mask="phone" />                           // 0 (532) 123 45 67
<Input mask="(999) 999-9999" />                  // custom pattern
<Input mask="99 A{1,3} 9{2,5}" />                // free, plate-like pattern
<Input mask={["9999 999 99 99", "999 999 99 99"]} />
<Input mask={{ pattern: "#HHHHHH", tokens: { H: { test: /[0-9A-F]/, transform: (c) => c.toUpperCase() } } }} />

MaskResult

interface

Result of applyMask.

NameTypeDescription
valuestringFormatted text (shown in the field).
unmaskedstringValue without separators: the typed characters and letter/digit literals of the pattern (0 (532) 123 45 67 → "05321234567", 34 ABC 123 → "34ABC123").
completebooleanAre all required sections of the pattern filled? false for an empty value.
validbooleanDoes the complete value pass the mask's validation? Same as complete for masks without validation.

How the show/hide password button works. See InputProps.reveal.

type PasswordRevealMode = "hold" | "toggle"