Command palette

@yasinsensoy/native

React Native · Components

TextField

Labeled text field: label, description, error message, required marker, password show/hide and icons.

9 exports

Import

import { TextField, applyMask } from "@yasinsensoy/native";

TextField

component

Labeled text field: label, description, error message, required marker, password show/hide and icons. On focus a 2 px border in the theme color (inset like on web; text does not shift), the danger color on error.

TextField(props: TextFieldProps): ReactElement<unknown, string | JSXElementConstructor<any>>

Examples

<TextField label="Email" keyboardType="email-address" autoComplete="email" />
<TextField label="Password" type="password" error={errors.password} required />

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

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.

Password reveal mode (same as web).

  • "hold": visible while the eye button is held.
  • "toggle": each tap toggles it.
  • false: no button.
type PasswordReveal = "hold" | "toggle" | false

TextField props.

Extends: FieldProps, Omit<TextInputProps, "editable" | "style">

NameTypeDefaultDescription
ref?Ref<TextInputRef>Ref of the underlying native element.
variant?FieldVariant"outline"Appearance. See FieldVariant.
type?"text" | "password""text""password" is a password field (hidden text + eye button).
reveal?PasswordReveal"hold"Password reveal. See PasswordReveal.
icon?IconPropIcon at the start of the box.
iconEnd?IconPropIcon at the end of the box.
readOnly?booleanRead-only: can be focused, selected and copied but not changed.
mask?MaskPropInput mask: formats input by a pattern (phone, plate, IBAN…). Same engine and same built-in names as mask on web; keyboard type, placeholder and capitalization are set automatically. For a complete value whose checksum fails (e.g. a wrong IBAN) an error shows on blur. See MaskProp.
onValueChange?(value: string, details: MaskResult) => voidOnly with mask: called with the formatted text and details (unmasked, complete, valid) when the value changes. See MaskResult.
style?StyleProp<ViewStyle>Style of the box.