{
  "package": "@blade-ai/weft",
  "status": "beta",
  "version": "0.1.0",
  "updated": "2026-11-24",
  "component": "PhoneNumberInput",
  "import": "import { PhoneNumberInput } from \"@blade-ai/weft/components/phone-number-input\";",
  "docs": "/components/phone-number-input",
  "description": "Collects a phone number with its country code. The country part shows a flag and dial code and opens a searchable list; the number formats as you type and is stored as E.164.",
  "props": [
    {
      "name": "label",
      "type": "string",
      "default": "Phone number",
      "required": true,
      "description": "Visible label that names both the picker and the number."
    },
    {
      "name": "labelPosition",
      "type": "\"top\" | \"left\"",
      "values": [
        "top",
        "left"
      ],
      "default": "top",
      "required": false,
      "description": "Label above or beside the field."
    },
    {
      "name": "defaultCountry",
      "type": "string",
      "default": "US",
      "required": false,
      "description": "ISO 3166-1 alpha-2, must be in allowedCountries. Blade AI is US-focused."
    },
    {
      "name": "allowedCountries",
      "type": "string[]",
      "default": null,
      "required": false,
      "description": "Limit the country list (ISO codes). Default: the built-in list; the full \"all countries\" list is UNDEFINED · needs decision."
    },
    {
      "name": "showCountry",
      "type": "boolean",
      "default": true,
      "required": false,
      "description": "Show the flag and the country picker."
    },
    {
      "name": "showDialCode",
      "type": "boolean",
      "default": true,
      "required": false,
      "description": "Show the dial code next to the flag."
    },
    {
      "name": "value · defaultValue",
      "type": "string (E.164)",
      "default": "",
      "required": false,
      "description": "Number in E.164, e.g. \"+14155550132\". Displayed formatted for the country."
    },
    {
      "name": "onChange",
      "type": "({ value, phoneNumber, country, dialCode, isValid }) => void",
      "default": null,
      "required": false,
      "description": "Called on every edit and country change. value = E.164; phoneNumber = national, formatted."
    },
    {
      "name": "onBlur",
      "type": "(event) => void",
      "default": null,
      "required": false,
      "description": "Called when focus leaves the whole field (not when moving picker → number). Validate here."
    },
    {
      "name": "onCountryChange",
      "type": "({ country, dialCode }) => void",
      "default": null,
      "required": false,
      "description": "Fires on picker select and on paste auto-detect."
    },
    {
      "name": "placeholder",
      "type": "string",
      "default": "(201) 555-0123",
      "required": false,
      "description": "Hint inside the number part; defaults to an example for the selected country."
    },
    {
      "name": "size",
      "type": "\"small\" | \"medium\" | \"large\"",
      "values": [
        "small",
        "medium",
        "large"
      ],
      "default": "medium",
      "required": false,
      "description": "Height 32 / 36 / 48px."
    },
    {
      "name": "validationState",
      "type": "\"none\" | \"error\" | \"success\"",
      "values": [
        "none",
        "error",
        "success"
      ],
      "default": "none",
      "required": false,
      "description": "Validation feedback; the app sets it on blur."
    },
    {
      "name": "helpText · errorText · successText",
      "type": "ReactNode",
      "default": null,
      "required": false,
      "description": "Why the number is needed; errorText and successText replace helpText."
    },
    {
      "name": "isDisabled · isRequired",
      "type": "boolean",
      "default": false,
      "required": false,
      "description": "Disabled: neither part focusable, not submitted. Required adds the necessity indicator and aria-required."
    },
    {
      "name": "isLoading",
      "type": "boolean",
      "default": false,
      "required": false,
      "description": "Spinner replaces the chevron; aria-busy. Editable while loading: UNDEFINED · needs decision (fallback: editable)."
    },
    {
      "name": "isReadOnly",
      "type": "boolean",
      "default": false,
      "required": false,
      "description": "Focusable and submitted; the picker does not open. Visual treatment: UNDEFINED · needs decision."
    },
    {
      "name": "name",
      "type": "string",
      "default": null,
      "required": false,
      "description": "Form field name; submits the E.164 value."
    },
    {
      "name": "autoFocus",
      "type": "boolean",
      "default": false,
      "required": false,
      "description": "Focuses the number, not the picker."
    }
  ],
  "states": [
    {
      "name": "empty",
      "trigger": "First render, value = \"\", not focused",
      "tokens": "bg surface.background.gray.subtle · border + divider interactive.border.gray.default · dial code surface.text.gray.normal · chevron surface.icon.gray.muted · placeholder + help surface.text.gray.muted",
      "notes": "Placeholder is a country example, never the label."
    },
    {
      "name": "typing",
      "trigger": "Focus in the number, digits being entered",
      "tokens": "focus-visible tokens · value surface.text.gray.normal",
      "notes": "Formats as you type: 415 → (415) → (415) 55 → (415) 555-0132. No validation yet."
    },
    {
      "name": "filled",
      "trigger": "value ≠ \"\", not focused",
      "tokens": "empty tokens · value surface.text.gray.normal",
      "notes": "Display (415) 555-0132 · stored +14155550132."
    },
    {
      "name": "hover",
      "trigger": "Pointer over picker or number",
      "tokens": "border interactive.border.gray.highlighted on the whole field",
      "notes": "One border for both parts; divider unchanged. No ring."
    },
    {
      "name": "focus-visible",
      "trigger": "Keyboard focus on picker or number",
      "tokens": "border interactive.border.primary.default · ring 3px interactive.border.primary.faded (box-shadow)",
      "notes": "Ring wraps the whole group, not each part."
    },
    {
      "name": "disabled",
      "trigger": "isDisabled",
      "tokens": "bg interactive.background.gray.disabled · border interactive.border.gray.default · opacity opacity.600 on the field",
      "notes": "Picker and number not focusable; no hover."
    },
    {
      "name": "read-only",
      "trigger": "isReadOnly",
      "tokens": "UNDEFINED · needs decision (shown with filled tokens)",
      "notes": "Value copyable; picker does not open; chevron hidden (UNDEFINED · needs decision)."
    },
    {
      "name": "loading",
      "trigger": "isLoading",
      "tokens": "filled tokens · spinner 14px surface.icon.gray.muted replaces the chevron",
      "notes": "aria-busy=\"true\". Editable while loading: UNDEFINED · needs decision."
    },
    {
      "name": "invalid (bad format)",
      "trigger": "validationState = \"error\", set on blur",
      "tokens": "border feedback.border.negative.intense · error text feedback.text.negative.intense",
      "notes": "\"Enter a 10-digit US phone number.\" replaces help. Focused + invalid: UNDEFINED · needs decision."
    },
    {
      "name": "success",
      "trigger": "validationState = \"success\"",
      "tokens": "border interactive.border.gray.default · help feedback.text.positive.intense + check",
      "notes": "e.g. after OTP verification. Success border / bg: UNDEFINED · needs decision."
    },
    {
      "name": "country picker open",
      "trigger": "Click / Enter / Space / ↓ on the picker",
      "tokens": "field: focus-visible tokens · list bg popup.background.gray.subtle · border popup.border.gray.subtle · shadow elevation.mid.raised · selected interactive.background.primary.faded · active interactive.background.gray.default",
      "notes": "Chevron rotates 180°. List max height size.240, then scrolls. Bottom Sheet on mobile: UNDEFINED · not built."
    },
    {
      "name": "country search",
      "trigger": "Typing in the list's search field",
      "tokens": "query surface.text.gray.normal · placeholder surface.text.gray.muted · divider surface.border.gray.muted",
      "notes": "Matches name, ISO code or dial code; first match is active."
    },
    {
      "name": "no country results",
      "trigger": "Query matches nothing",
      "tokens": "text surface.text.gray.muted",
      "notes": "\"No countries match ‘xyz’\" (aria-live polite). Enter does nothing."
    },
    {
      "name": "long country name",
      "trigger": "Option name wider than the list",
      "tokens": "name interactive.text.gray.normal · dial code surface.text.gray.muted",
      "notes": "Name wraps to 2 lines then truncates; dial code keeps its own slot. Trigger never shows the name."
    }
  ],
  "sizes": [
    {
      "property": "Height",
      "value": "32 / 36 / 48",
      "token": "size.32 · size.36 · size.48"
    },
    {
      "property": "Horizontal padding",
      "value": "picker 12 / 8 (small 8 / 6) · number 12 (small, large 8)",
      "token": "picker spacing.4 / spacing.3 (small spacing.3 / spacing.15) · number spacing.4 (small, large spacing.3)"
    },
    {
      "property": "Picker gap (flag · dial code · chevron)",
      "value": "6 (small, large 4)",
      "token": "spacing.15 (small, large spacing.2)"
    },
    {
      "property": "Chevron / spinner / flag",
      "value": "14 small, medium · 16 large · flag 16 × 12",
      "token": "size.14 · size.16 · colour surface.icon.gray.muted"
    },
    {
      "property": "Number / dial code / placeholder",
      "value": "13 / 20 / 400 (14 on large)",
      "token": "fonts.size.1200 / lineHeights.100 (fonts.size.100 on large)"
    },
    {
      "property": "Label ↔ field ↔ help gap",
      "value": "top 8 · left 12",
      "token": "spacing.3 · spacing.4"
    },
    {
      "property": "Help / error / success text",
      "value": "12 / 16 / 400 · tracking 0.01em",
      "token": "fonts.size.75 / lineHeights.50 / letterSpacings.200"
    },
    {
      "property": "Left label column",
      "value": "80",
      "token": "no token · matches Text Input"
    },
    {
      "property": "Border · divider · ring",
      "value": "1 · 1 · 3",
      "token": "border.width.thin · interactive.border.gray.default · border.width.3 + interactive.border.primary.faded"
    },
    {
      "property": "Radius · disabled opacity",
      "value": "0 · 50%",
      "token": "border.radius.none · opacity.600"
    },
    {
      "property": "Country list",
      "value": "option min 32 · list max 240 · width = field",
      "token": "size.32 · size.240 · list padding spacing.2 · option padding spacing.3"
    }
  ],
  "behaviour": {
    "elements": "role=\"group\" wrapper → country picker (combobox button + listbox) + <input type=\"tel\" inputmode=\"tel\" autocomplete=\"tel\">. Help and error share one message slot.",
    "storage vs display": "Store and emit E.164 only (value = \"+14155550132\"). Display the national format for the selected country: \"(415) 555-0132\". Never store spaces, brackets or dashes.",
    "as-you-type formatting": "Re-format on every input with the country pattern; keep the caret after the digit just typed. Strip spaces, dashes, dots, brackets and a leading trunk 0. Letters are ignored.",
    "paste / autofill +number": "Text starting with + (or 00) is parsed: the matching country is selected, the dial code stripped and onCountryChange fires. Shared dial codes (+1) keep the current country.",
    "default country": "defaultCountry = \"US\". Overriding from the account country, then the browser locale, is left to the app. The list never opens on load.",
    "dial-code-only input": "If only the dial code is present, the field is empty: value = \"\", not invalid.",
    "validation timing": "The component reports isValid and fires onBlur when focus leaves the whole group; the app validates on blur and on submit, never mid-typing, and re-validates on every change once invalid. Error text replaces help text.",
    "max length per country": "Digits beyond the country's national length are blocked (US 10, India 10, UK 10, UAE 9); never more than 15 digits in E.164. isValid = full national length (libphonenumber-grade rules: UNDEFINED · needs decision).",
    "examples": "US: shows \"(415) 555-0132\", stores \"+14155550132\". India: shows \"98765 43210\", stores \"+919876543210\".",
    "changing country": "Keep the national digits, re-format for the new country. Focus moves to the number after selection.",
    "disabled / read-only / loading": "isDisabled: neither part focusable, not submitted. isReadOnly: focusable, submitted, picker does not open. isLoading: spinner replaces the chevron; editable while loading: UNDEFINED · needs decision.",
    "country data": "A built-in subset of countries with national length and display pattern; the full list and flag asset source (emoji used) are UNDEFINED · needs decision."
  },
  "keyboard": [
    {
      "key": "Tab / Shift+Tab",
      "action": "Picker → number → next field, and back. Both parts are tab stops."
    },
    {
      "key": "Enter / Space / ↓ / Alt+↓ (picker)",
      "action": "Opens the country list; focus goes to its search field; the selected country is active."
    },
    {
      "key": "Letters (picker closed)",
      "action": "Typeahead: jumps to the next country starting with the typed letters (\"in\" → India) without opening the list; resets after 500ms."
    },
    {
      "key": "Type (list open)",
      "action": "Filters by country name, ISO code or dial code (\"+44\"); first match becomes active."
    },
    {
      "key": "↑ / ↓ · Home / End · Enter",
      "action": "Moves the active option; Enter selects, closes the list and moves focus to the number."
    },
    {
      "key": "Escape",
      "action": "Closes the list without changing the country; focus returns to the picker."
    },
    {
      "key": "Digits / Backspace / Cmd + V (number)",
      "action": "Native editing; formatting re-applies after each change; paste of +number auto-selects the country. Enter submits the form."
    }
  ],
  "accessibility": {
    "summary": "One visible label names both parts; the picker is a combobox, the number a native tel input.",
    "aria": [
      {
        "element": "Group wrapper",
        "attributes": "role=\"group\" aria-labelledby=\"{labelId}\"",
        "when": "Always"
      },
      {
        "element": "Country picker",
        "attributes": "role=\"combobox\" aria-haspopup=\"listbox\" aria-expanded aria-controls=\"{listId}\" · accessible name \"Country: United States, +1\"",
        "when": "showCountry = true"
      },
      {
        "element": "Country list",
        "attributes": "role=\"listbox\" · role=\"option\" aria-selected · search input aria-activedescendant=\"{optionId}\"",
        "when": "List open"
      },
      {
        "element": "<input> (number)",
        "attributes": "type=\"tel\" inputmode=\"tel\" autocomplete=\"tel\" · label via <label for>",
        "when": "Always"
      },
      {
        "element": "<input> (number)",
        "attributes": "aria-describedby=\"{messageId}\" · aria-invalid=\"true\"",
        "when": "Help / error shown · validationState = error"
      },
      {
        "element": "Group wrapper",
        "attributes": "aria-busy=\"true\"",
        "when": "isLoading"
      },
      {
        "element": "Picker + number",
        "attributes": "aria-required=\"true\" · disabled · aria-readonly=\"true\" (picker) / readOnly (input)",
        "when": "isRequired · isDisabled · isReadOnly"
      },
      {
        "element": "Flag · chevron · spinner",
        "attributes": "aria-hidden=\"true\" (country is in the picker's name)",
        "when": "Always"
      },
      {
        "element": "No-results message",
        "attributes": "role=\"status\" aria-live=\"polite\"",
        "when": "Query matches no country"
      }
    ]
  },
  "usage": {
    "do": [
      "Always show a visible label that names both parts; use the placeholder only as a country example.",
      "Default to US +1 (or the account's country) and keep the list searchable.",
      "Set type=\"tel\", inputmode=\"tel\" and autocomplete=\"tel\" so keypads and autofill work.",
      "Store E.164; display the national format and format as the user types.",
      "Auto-select the country when a +number is pasted or autofilled.",
      "Use the exact tokens in the States table; one border and one ring wrap the whole field."
    ],
    "dont": [
      "Don't split the number or the dial code into separate fields.",
      "Don't validate mid-typing or show help and error text together.",
      "Don't reject spaces, dashes, brackets or a leading 0 — strip them.",
      "Don't block paste.",
      "Don't treat a dial-code-only value (\"+1\") as invalid — it is empty.",
      "Don't show the country name in the trigger — flag + dial code only.",
      "Don't build anything marked UNDEFINED until it has a decision."
    ]
  },
  "example": "<PhoneNumberInput label=\"Phone number\" defaultCountry=\"US\" helpText=\"We'll send a one-time password to this number.\" onChange={({ value, isValid }) => setPhone(value)} onBlur={validate} />"
}
