{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "phone-number-field",
  "type": "registry:ui",
  "title": "Phone Number Field",
  "description": "Phone Number Field pairs a country/dial-code selector with a phone number input — UI pattern only, not SMS verification or carrier lookup.",
  "author": "Skrewww",
  "dependencies": [],
  "registryDependencies": [
    "@skrewww/select",
    "@skrewww/validation-message",
    "@skrewww/foundation"
  ],
  "docs": "Host requirements (assumed already present, not installed by this command): react, react-dom.",
  "files": [
    {
      "path": "components/ui/PhoneNumberField.tsx",
      "content": "/** @skrewww-component phone-number-field */\n\"use client\";\n\nimport { useId, type ChangeEvent, type ClipboardEvent } from \"react\";\nimport { cn } from \"@/lib/cn\";\nimport { useControllableState } from \"@/lib/use-controllable\";\nimport { ValidationMessage } from \"@/components/ui/ValidationMessage\";\nimport { SelectControl, type SelectOption } from \"@/components/ui/Select\";\nimport { TextInputControl } from \"@/components/ui/TextInputControl\";\nimport {\n  DEFAULT_PHONE_COUNTRIES,\n  formatCountryOptionLabel,\n  sanitizePhoneNumberInput,\n  type PhoneCountryOption,\n} from \"@/lib/phone-number-field-countries\";\nimport styles from \"@/components/ui/phone-number-field.module.css\";\n\nexport type { PhoneCountryOption };\n\nexport type PhoneNumberFieldProps = {\n  /** Visible fieldset legend for the compound control. */\n  label: string;\n  /** Accessible name for the country selector. Default: \"Country\". */\n  countryLabel?: string;\n  /** Accessible name for the phone number input. Default: \"Phone number\". */\n  numberLabel?: string;\n  /** Country options. Defaults to a small illustrative list — override for production. */\n  countries?: readonly PhoneCountryOption[];\n  country?: string;\n  defaultCountry?: string;\n  onCountryChange?: (country: string) => void;\n  value?: string;\n  defaultValue?: string;\n  onValueChange?: (value: string) => void;\n  placeholder?: string;\n  disabled?: boolean;\n  readOnly?: boolean;\n  required?: boolean;\n  supportingText?: string;\n  error?: string;\n  hideLabel?: boolean;\n  name?: string;\n  id?: string;\n  className?: string;\n};\n\nfunction FlagPlaceholder() {\n  return (\n    <span className={styles.flag} aria-hidden=\"true\">\n      <span className={styles.flagStripeTop} />\n      <span className={styles.flagStripeBottom} />\n    </span>\n  );\n}\n\n/**\n * Compound country dial-code selector + phone number input.\n *\n * UI pattern only — not SMS verification, carrier lookup, or reachability checks.\n */\nexport function PhoneNumberField({\n  label,\n  countryLabel = \"Country\",\n  numberLabel = \"Phone number\",\n  countries = DEFAULT_PHONE_COUNTRIES,\n  country,\n  defaultCountry,\n  onCountryChange,\n  value,\n  defaultValue = \"\",\n  onValueChange,\n  placeholder = \"Phone number\",\n  disabled = false,\n  readOnly = false,\n  required = false,\n  supportingText,\n  error,\n  hideLabel = false,\n  name: nameProp,\n  id: idProp,\n  className,\n}: PhoneNumberFieldProps) {\n  const generatedId = useId();\n  const baseId = idProp ?? generatedId;\n  const nameBase = nameProp ?? baseId.replace(/:/g, \"\");\n  const supportingId = supportingText ? `${baseId}-supporting` : undefined;\n  const errorId = error ? `${baseId}-error` : undefined;\n  const describedBy = [errorId, !error ? supportingId : undefined].filter(Boolean).join(\" \");\n  const invalid = Boolean(error);\n\n  const countryList = countries.length > 0 ? countries : DEFAULT_PHONE_COUNTRIES;\n  const fallbackCountry = countryList[0]?.value ?? \"US\";\n\n  const countryProvided = country !== undefined;\n  const [currentCountry, setCurrentCountry] = useControllableState<string>({\n    value: countryProvided ? country : undefined,\n    defaultValue: defaultCountry ?? fallbackCountry,\n    onChange: onCountryChange,\n    valueProvided: countryProvided,\n  });\n\n  const valueProvided = value !== undefined;\n  const [currentNumber, setCurrentNumber] = useControllableState<string>({\n    value: valueProvided ? sanitizePhoneNumberInput(value as string) : undefined,\n    defaultValue: sanitizePhoneNumberInput(defaultValue),\n    onChange: onValueChange,\n    valueProvided,\n  });\n\n  const selectOptions: SelectOption[] = countryList.map((option) => ({\n    value: option.value,\n    label: formatCountryOptionLabel(option),\n  }));\n\n  const countryDisabled = disabled || readOnly;\n\n  function handleCountryChange(event: ChangeEvent<HTMLSelectElement>) {\n    setCurrentCountry(event.target.value);\n  }\n\n  function handleNumberChange(event: ChangeEvent<HTMLInputElement>) {\n    setCurrentNumber(sanitizePhoneNumberInput(event.target.value));\n  }\n\n  function handleNumberPaste(event: ClipboardEvent<HTMLInputElement>) {\n    if (readOnly || disabled) return;\n    event.preventDefault();\n    const input = event.currentTarget;\n    const pasted = sanitizePhoneNumberInput(event.clipboardData.getData(\"text\"));\n    const start = input.selectionStart ?? currentNumber.length;\n    const end = input.selectionEnd ?? currentNumber.length;\n    const next = sanitizePhoneNumberInput(\n      `${currentNumber.slice(0, start)}${pasted}${currentNumber.slice(end)}`,\n    );\n    setCurrentNumber(next);\n  }\n\n  return (\n    <fieldset\n      className={cn(styles.field, className)}\n      disabled={disabled || undefined}\n      aria-describedby={describedBy || undefined}\n      aria-invalid={invalid || undefined}\n      aria-required={required || undefined}\n    >\n      <legend className={hideLabel ? styles.srOnly : styles.legend}>\n        {label}\n        {required ? (\n          <>\n            <span className={styles.required} aria-hidden=\"true\">\n              *\n            </span>\n            <span className=\"sr-only\"> (required)</span>\n          </>\n        ) : null}\n      </legend>\n\n      <div className={styles.row}>\n        <div className={styles.country}>\n          <label htmlFor={`${baseId}-country`} className={styles.srOnly}>\n            {countryLabel}\n          </label>\n          <FlagPlaceholder />\n          <SelectControl\n            id={`${baseId}-country`}\n            name={`${nameBase}-country`}\n            listboxLabel={countryLabel}\n            options={selectOptions}\n            value={currentCountry}\n            valueProvided\n            onChange={handleCountryChange}\n            disabled={countryDisabled}\n            required={required}\n            aria-invalid={invalid || undefined}\n            aria-describedby={describedBy || undefined}\n          />\n        </div>\n\n        <TextInputControl\n          id={`${baseId}-number`}\n          name={`${nameBase}-number`}\n          className={styles.number}\n          type=\"tel\"\n          autoComplete=\"tel\"\n          inputMode=\"tel\"\n          spellCheck={false}\n          aria-label={numberLabel}\n          aria-invalid={invalid || undefined}\n          aria-describedby={describedBy || undefined}\n          placeholder={placeholder}\n          value={currentNumber}\n          onChange={handleNumberChange}\n          onPaste={handleNumberPaste}\n          disabled={disabled}\n          readOnly={readOnly}\n          required={required}\n        />\n      </div>\n\n      {error ? (\n        <ValidationMessage id={errorId} type=\"error\" announce=\"off\">\n          {error}\n        </ValidationMessage>\n      ) : supportingText ? (\n        <p id={supportingId} className={styles.supporting}>\n          {supportingText}\n        </p>\n      ) : null}\n    </fieldset>\n  );\n}\n",
      "type": "registry:ui",
      "target": "~/components/ui/PhoneNumberField.tsx"
    },
    {
      "path": "components/ui/phone-number-field.module.css",
      "content": ".field {\n  display: flex;\n  flex-direction: column;\n  gap: 0.375rem;\n  width: 100%;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  min-width: 0;\n}\n\n.legend {\n  font-size: 0.875rem;\n  font-weight: 500;\n  line-height: 1.4;\n  color: var(--semantic-text-primary);\n  padding: 0;\n  margin-bottom: 0.375rem;\n}\n\n.required {\n  margin-left: 0.125rem;\n  color: var(--semantic-text-danger);\n}\n\n.srOnly {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  padding: 0;\n  margin: -1px;\n  overflow: hidden;\n  clip: rect(0, 0, 0, 0);\n  white-space: nowrap;\n  border: 0;\n}\n\n.supporting {\n  font-size: 0.8125rem;\n  line-height: 1.4;\n  color: var(--semantic-text-secondary);\n}\n\n.row {\n  display: flex;\n  flex-direction: row;\n  align-items: stretch;\n  gap: 0.5rem; /* spacing/8 */\n  width: 100%;\n  min-width: 0;\n}\n\n.country {\n  position: relative;\n  flex: 0 1 auto;\n  min-width: 8.5rem;\n  max-width: 14rem;\n}\n\n.flag {\n  position: absolute;\n  left: 0.75rem;\n  top: 50%;\n  z-index: 1;\n  transform: translateY(-50%);\n  display: flex;\n  flex-direction: column;\n  width: 1.25rem; /* 20px */\n  height: 0.875rem; /* 14px */\n  overflow: hidden;\n  border: 0.5px solid var(--semantic-border-default);\n  border-radius: 2px; /* Figma radius/xs on Flag placeholder */\n  background-color: var(--semantic-surface-default);\n  pointer-events: none;\n}\n\n.flagStripeTop {\n  flex: 1 1 50%;\n  background-color: var(--primitive-color-neutral-300);\n}\n\n.flagStripeBottom {\n  flex: 1 1 50%;\n  background-color: var(--primitive-color-neutral-500);\n}\n\n/* Room for the decorative flag inside Select’s trigger. */\n.country :global(button[role=\"combobox\"]) {\n  padding-left: 2.5rem;\n}\n\n.number {\n  flex: 1 1 auto;\n  min-width: 0;\n}\n\n@media (max-width: 420px) {\n  .row {\n    flex-wrap: wrap;\n  }\n\n  .country {\n    max-width: none;\n    width: 100%;\n  }\n\n  .number {\n    width: 100%;\n  }\n}\n",
      "type": "registry:ui",
      "target": "~/components/ui/phone-number-field.module.css"
    },
    {
      "path": "lib/cn.ts",
      "content": "export function cn(...classes: Array<string | false | null | undefined>): string {\n  return classes.filter(Boolean).join(\" \");\n}\n",
      "type": "registry:lib",
      "target": "~/lib/cn.ts"
    },
    {
      "path": "lib/use-controllable.ts",
      "content": "import { useCallback, useEffect, useRef, useState } from \"react\";\n\nexport function useControllableState<T>({\n  value,\n  defaultValue,\n  onChange,\n  controlled: controlledProp,\n  valueProvided,\n}: {\n  value?: T;\n  defaultValue?: T;\n  onChange?: (next: T) => void;\n  /** Explicit controlled override — prefer `valueProvided` from the component root. */\n  controlled?: boolean;\n  /** True when the parent passed a `value` prop, including `undefined`. */\n  valueProvided?: boolean;\n}) {\n  const [uncontrolled, setUncontrolled] = useState(defaultValue as T);\n  const isControlled = controlledProp ?? valueProvided ?? value !== undefined;\n  const current = isControlled ? (value as T) : uncontrolled;\n  const wasControlledRef = useRef(isControlled);\n\n  useEffect(() => {\n    if (process.env.NODE_ENV !== \"development\") return;\n    if (wasControlledRef.current !== isControlled) {\n      console.warn(\n        \"[Skrewww] A component changed between controlled and uncontrolled modes. Keep `value` or `defaultValue` usage consistent across renders.\",\n      );\n    }\n    wasControlledRef.current = isControlled;\n  }, [isControlled]);\n\n  const setValue = useCallback(\n    (next: T) => {\n      if (!isControlled) setUncontrolled(next);\n      onChange?.(next);\n    },\n    [isControlled, onChange],\n  );\n\n  return [current, setValue] as const;\n}\n",
      "type": "registry:lib",
      "target": "~/lib/use-controllable.ts"
    },
    {
      "path": "components/ui/TextInputControl.tsx",
      "content": "\"use client\";\n\nimport { forwardRef, type InputHTMLAttributes, type ReactNode } from \"react\";\nimport { cn } from \"@/lib/cn\";\nimport styles from \"@/components/ui/text-input.module.css\";\n\nexport type TextInputControlSize = \"sm\" | \"md\" | \"lg\";\n\nexport type TextInputControlProps = Omit<\n  InputHTMLAttributes<HTMLInputElement>,\n  \"size\"\n> & {\n  size?: TextInputControlSize;\n  leadingIcon?: ReactNode;\n  trailingIcon?: ReactNode;\n  trailingAction?: ReactNode;\n};\n\nconst sizeClass: Record<TextInputControlSize, string> = {\n  sm: styles.sizeSm,\n  md: styles.sizeMd,\n  lg: styles.sizeLg,\n};\n\n/** Control-only single-line input — compose with FormField for label and validation. */\nexport const TextInputControl = forwardRef<HTMLInputElement, TextInputControlProps>(\n  function TextInputControl(\n    {\n      size = \"md\",\n      leadingIcon,\n      trailingIcon,\n      trailingAction,\n      className,\n      disabled,\n      required,\n      readOnly,\n      ...props\n    },\n    ref,\n  ) {\n    return (\n      <div className={cn(styles.controlWrap, className)}>\n        {leadingIcon ? (\n          <span className={styles.leading} aria-hidden=\"true\">\n            {leadingIcon}\n          </span>\n        ) : null}\n\n        <input\n          ref={ref}\n          className={cn(\n            styles.input,\n            sizeClass[size],\n            leadingIcon ? styles.withLeading : undefined,\n            trailingIcon || trailingAction ? styles.withTrailing : undefined,\n          )}\n          disabled={disabled}\n          readOnly={readOnly}\n          required={required}\n          aria-required={required || undefined}\n          {...props}\n        />\n\n        {trailingAction ? (\n          <span className={styles.trailingAction}>{trailingAction}</span>\n        ) : trailingIcon ? (\n          <span className={styles.trailing} aria-hidden=\"true\">\n            {trailingIcon}\n          </span>\n        ) : null}\n      </div>\n    );\n  },\n);\n",
      "type": "registry:ui",
      "target": "~/components/ui/TextInputControl.tsx"
    },
    {
      "path": "components/ui/text-input.module.css",
      "content": ".controlWrap {\n  position: relative;\n  display: flex;\n  align-items: center;\n  width: 100%;\n}\n\n.input {\n  width: 100%;\n  border: 1px solid var(--semantic-border-default);\n  border-radius: var(--shape-radius-control);\n  /* TextInput wasn't in the originally-reported list of squircle consumers,\n     but it consumes --shape-radius-control via plain border-radius exactly\n     like Button/Checkbox/Drawer's close button — same bug, fixed the same\n     way, found while auditing the other 5. */\n  clip-path: var(--squircle-clip-path-control, none);\n  background-color: var(--surface-fill-control);\n  background-image: var(--component-surface-gradient-overlay);\n  backdrop-filter: var(--glass-backdrop-filter-sm, none);\n  color: var(--semantic-text-primary);\n  font-family: inherit;\n  line-height: 1.4;\n  transition:\n    border-color 0.15s ease,\n    box-shadow 0.15s ease;\n}\n\n.input::placeholder {\n  color: var(--semantic-text-disabled);\n}\n\n.input:hover:not(:disabled):not([aria-invalid=\"true\"]) {\n  border-color: var(--semantic-border-strong);\n}\n\n.input:focus {\n  outline: none;\n}\n\n.input:focus-visible {\n  border-color: var(--semantic-focus-ring);\n  box-shadow: 0 0 0 2px var(--semantic-focus-ring);\n}\n\n/* clip-path clips an outset box-shadow ring exactly like it clips outline\n   (same reasoning as Button/Checkbox) — an inset ring stays fully visible\n   since it never extends past the clip boundary. Squircle mode only; every\n   other shape mode keeps the outset ring above unchanged. */\n[data-skrewww-shape=\"squircle\"] .input:focus-visible {\n  box-shadow: inset 0 0 0 2px var(--semantic-focus-ring);\n}\n\n.input:disabled {\n  cursor: not-allowed;\n  pointer-events: none;\n  color: var(--semantic-text-disabled);\n  border-color: var(--semantic-border-disabled);\n  background-color: var(--semantic-surface-disabled);\n  opacity: var(--opacity-disabled);\n}\n\n.input:read-only:not(:disabled) {\n  background-color: var(--semantic-surface-subtle);\n  cursor: default;\n}\n\n.input[aria-invalid=\"true\"] {\n  border-color: var(--semantic-action-danger);\n}\n\n.input[aria-invalid=\"true\"]:focus-visible {\n  box-shadow: 0 0 0 2px var(--semantic-action-danger);\n}\n\n[data-skrewww-shape=\"squircle\"] .input[aria-invalid=\"true\"]:focus-visible {\n  box-shadow: inset 0 0 0 2px var(--semantic-action-danger);\n}\n\n.input[type=\"search\"]::-webkit-search-cancel-button {\n  -webkit-appearance: none;\n  appearance: none;\n  display: none;\n}\n\n.sizeSm {\n  min-height: var(--control-height-sm);\n  padding: 0 var(--control-padding-x-sm);\n  font-size: var(--control-font-size-sm);\n}\n\n.sizeMd {\n  min-height: var(--control-height-md);\n  padding: 0 var(--control-padding-x-md);\n  font-size: var(--control-font-size-md);\n}\n\n.sizeLg {\n  min-height: var(--control-height-lg);\n  padding: 0 var(--control-padding-x-lg);\n  font-size: var(--control-font-size-lg);\n}\n\n.withLeading {\n  padding-left: 2.25rem;\n}\n\n.withTrailing {\n  padding-right: 2.25rem;\n}\n\n.leading,\n.trailing {\n  position: absolute;\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  color: var(--semantic-icon-muted);\n  pointer-events: none;\n}\n\n.leading {\n  left: 0.75rem;\n}\n\n.trailing {\n  right: 0.75rem;\n  pointer-events: auto;\n}\n\n.trailingAction {\n  position: absolute;\n  right: 0.25rem;\n  display: inline-flex;\n  align-items: center;\n}\n\n@media (prefers-reduced-motion: reduce) {\n  .input {\n    transition: none;\n  }\n}\n",
      "type": "registry:ui",
      "target": "~/components/ui/text-input.module.css"
    },
    {
      "path": "lib/phone-number-field-countries.ts",
      "content": "/**\n * Small illustrative country/dial-code list for Phone Number Field.\n * Not a complete ISO dataset — consumers should pass `countries` for production.\n */\nexport type PhoneCountryOption = {\n  /** Stable option id (e.g. ISO 3166-1 alpha-2). */\n  value: string;\n  /** Dialing prefix including leading +, e.g. \"+1\". */\n  dialCode: string;\n  /** Human-readable country/region name. */\n  label: string;\n};\n\nexport const DEFAULT_PHONE_COUNTRIES: readonly PhoneCountryOption[] = [\n  { value: \"US\", dialCode: \"+1\", label: \"United States\" },\n  { value: \"CA\", dialCode: \"+1\", label: \"Canada\" },\n  { value: \"GB\", dialCode: \"+44\", label: \"United Kingdom\" },\n  { value: \"AU\", dialCode: \"+61\", label: \"Australia\" },\n  { value: \"DE\", dialCode: \"+49\", label: \"Germany\" },\n  { value: \"FR\", dialCode: \"+33\", label: \"France\" },\n  { value: \"IN\", dialCode: \"+91\", label: \"India\" },\n  { value: \"PK\", dialCode: \"+92\", label: \"Pakistan\" },\n  { value: \"AE\", dialCode: \"+971\", label: \"United Arab Emirates\" },\n  { value: \"BR\", dialCode: \"+55\", label: \"Brazil\" },\n  { value: \"JP\", dialCode: \"+81\", label: \"Japan\" },\n  { value: \"MX\", dialCode: \"+52\", label: \"Mexico\" },\n] as const;\n\n/** Allow digits and common phone punctuation; strip other characters. */\nexport function sanitizePhoneNumberInput(value: string): string {\n  return value.replace(/[^\\d+\\s().-]/g, \"\");\n}\n\nexport function formatCountryOptionLabel(option: PhoneCountryOption): string {\n  return `${option.label} (${option.dialCode})`;\n}\n",
      "type": "registry:lib",
      "target": "~/lib/phone-number-field-countries.ts"
    }
  ]
}
