mood-ui 0.11.0 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/data-display/calendar/AgendaView.cjs.map +1 -1
- package/dist/components/data-display/calendar/AgendaView.mjs.map +1 -1
- package/dist/components/data-display/calendar/AgendaView.vue_vue_type_script_setup_true_lang.cjs +11 -6
- package/dist/components/data-display/calendar/AgendaView.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/data-display/calendar/AgendaView.vue_vue_type_script_setup_true_lang.mjs +18 -13
- package/dist/components/data-display/calendar/AgendaView.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/data-display/calendar/Calendar.vue_vue_type_script_setup_true_lang.mjs +4 -4
- package/dist/components/data-display/calendar/Calendar.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/data-display/calendar/DayView.cjs.map +1 -1
- package/dist/components/data-display/calendar/DayView.mjs.map +1 -1
- package/dist/components/data-display/calendar/DayView.vue_vue_type_script_setup_true_lang.cjs +14 -9
- package/dist/components/data-display/calendar/DayView.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/data-display/calendar/DayView.vue_vue_type_script_setup_true_lang.mjs +22 -17
- package/dist/components/data-display/calendar/DayView.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/data-display/calendar/MonthView.cjs +1 -1
- package/dist/components/data-display/calendar/MonthView.cjs.map +1 -1
- package/dist/components/data-display/calendar/MonthView.mjs +1 -1
- package/dist/components/data-display/calendar/MonthView.mjs.map +1 -1
- package/dist/components/data-display/calendar/MonthView.vue_vue_type_script_setup_true_lang.cjs +15 -17
- package/dist/components/data-display/calendar/MonthView.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/data-display/calendar/MonthView.vue_vue_type_script_setup_true_lang.mjs +18 -20
- package/dist/components/data-display/calendar/MonthView.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/data-display/calendar/Scheduler.cjs.map +1 -1
- package/dist/components/data-display/calendar/Scheduler.mjs.map +1 -1
- package/dist/components/data-display/calendar/Scheduler.vue_vue_type_script_setup_true_lang.cjs +14 -9
- package/dist/components/data-display/calendar/Scheduler.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/data-display/calendar/Scheduler.vue_vue_type_script_setup_true_lang.mjs +22 -17
- package/dist/components/data-display/calendar/Scheduler.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/data-display/calendar/WeekView.cjs.map +1 -1
- package/dist/components/data-display/calendar/WeekView.mjs.map +1 -1
- package/dist/components/data-display/calendar/WeekView.vue_vue_type_script_setup_true_lang.cjs +14 -9
- package/dist/components/data-display/calendar/WeekView.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/data-display/calendar/WeekView.vue_vue_type_script_setup_true_lang.mjs +22 -17
- package/dist/components/data-display/calendar/WeekView.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/data-display/date-picker/DateRangePicker.vue_vue_type_script_setup_true_lang.mjs +3 -3
- package/dist/components/data-display/date-picker/DateRangePicker.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/data-display/date-picker/DateTimePicker.cjs.map +1 -1
- package/dist/components/data-display/date-picker/DateTimePicker.mjs.map +1 -1
- package/dist/components/data-display/date-picker/DateTimePicker.vue_vue_type_script_setup_true_lang.cjs +1 -1
- package/dist/components/data-display/date-picker/DateTimePicker.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/data-display/date-picker/DateTimePicker.vue_vue_type_script_setup_true_lang.mjs +3 -3
- package/dist/components/data-display/date-picker/DateTimePicker.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/feedback/Banner.vue_vue_type_script_setup_true_lang.mjs +4 -4
- package/dist/components/feedback/Banner.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/feedback/Drawer.cjs.map +1 -1
- package/dist/components/feedback/Drawer.mjs.map +1 -1
- package/dist/components/feedback/Drawer.vue_vue_type_script_setup_true_lang.cjs +4 -9
- package/dist/components/feedback/Drawer.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/feedback/Drawer.vue_vue_type_script_setup_true_lang.mjs +9 -14
- package/dist/components/feedback/Drawer.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/feedback/Modal.cjs.map +1 -1
- package/dist/components/feedback/Modal.mjs.map +1 -1
- package/dist/components/feedback/Modal.vue_vue_type_script_setup_true_lang.cjs +4 -9
- package/dist/components/feedback/Modal.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/feedback/Modal.vue_vue_type_script_setup_true_lang.mjs +9 -14
- package/dist/components/feedback/Modal.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/feedback/Tooltip.cjs.map +1 -1
- package/dist/components/feedback/Tooltip.mjs.map +1 -1
- package/dist/components/feedback/Tooltip.vue_vue_type_script_setup_true_lang.cjs +44 -17
- package/dist/components/feedback/Tooltip.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/feedback/Tooltip.vue_vue_type_script_setup_true_lang.mjs +44 -17
- package/dist/components/feedback/Tooltip.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/forms/Combobox.cjs.map +1 -1
- package/dist/components/forms/Combobox.mjs.map +1 -1
- package/dist/components/forms/Combobox.vue_vue_type_script_setup_true_lang.cjs +2 -2
- package/dist/components/forms/Combobox.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/forms/Combobox.vue_vue_type_script_setup_true_lang.mjs +2 -2
- package/dist/components/forms/Combobox.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/forms/PhoneInput.cjs.map +1 -1
- package/dist/components/forms/PhoneInput.mjs.map +1 -1
- package/dist/components/forms/PhoneInput.vue_vue_type_script_setup_true_lang.cjs +6 -1
- package/dist/components/forms/PhoneInput.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/forms/PhoneInput.vue_vue_type_script_setup_true_lang.mjs +6 -1
- package/dist/components/forms/PhoneInput.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/forms/SearchInput.cjs.map +1 -1
- package/dist/components/forms/SearchInput.mjs.map +1 -1
- package/dist/components/forms/SearchInput.vue_vue_type_script_setup_true_lang.cjs +8 -6
- package/dist/components/forms/SearchInput.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/forms/SearchInput.vue_vue_type_script_setup_true_lang.mjs +8 -6
- package/dist/components/forms/SearchInput.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/layout/PopoverPanel.cjs +1 -1
- package/dist/components/layout/PopoverPanel.cjs.map +1 -1
- package/dist/components/layout/PopoverPanel.mjs +1 -1
- package/dist/components/layout/PopoverPanel.mjs.map +1 -1
- package/dist/components/layout/PopoverPanel.vue_vue_type_script_setup_true_lang.cjs +2 -2
- package/dist/components/layout/PopoverPanel.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/layout/PopoverPanel.vue_vue_type_script_setup_true_lang.mjs +2 -2
- package/dist/components/layout/PopoverPanel.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/navigation/Switcher.cjs.map +1 -1
- package/dist/components/navigation/Switcher.mjs.map +1 -1
- package/dist/components/navigation/Switcher.vue_vue_type_script_setup_true_lang.cjs +38 -40
- package/dist/components/navigation/Switcher.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/navigation/Switcher.vue_vue_type_script_setup_true_lang.mjs +38 -40
- package/dist/components/navigation/Switcher.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/composables/eventColors.cjs +51 -27
- package/dist/composables/eventColors.cjs.map +1 -1
- package/dist/composables/eventColors.mjs +51 -27
- package/dist/composables/eventColors.mjs.map +1 -1
- package/dist/composables/useBodyScrollLock.cjs +44 -0
- package/dist/composables/useBodyScrollLock.cjs.map +1 -0
- package/dist/composables/useBodyScrollLock.mjs +43 -0
- package/dist/composables/useBodyScrollLock.mjs.map +1 -0
- package/dist/composables/useCalendarTheme.cjs +29 -8
- package/dist/composables/useCalendarTheme.cjs.map +1 -1
- package/dist/composables/useCalendarTheme.mjs +29 -8
- package/dist/composables/useCalendarTheme.mjs.map +1 -1
- package/dist/composables/usePopover.cjs +44 -12
- package/dist/composables/usePopover.cjs.map +1 -1
- package/dist/composables/usePopover.mjs +44 -12
- package/dist/composables/usePopover.mjs.map +1 -1
- package/dist/mood-ui.css +9 -9
- package/dist/types/composables/eventColors.d.ts +2 -2
- package/dist/types/composables/useBodyScrollLock.d.ts +19 -0
- package/dist/types/composables/useCalendarTheme.d.ts +2 -0
- package/dist/types/interfaces/data-display/calendar/AgendaView.interface.d.ts +5 -0
- package/dist/types/interfaces/data-display/calendar/DayView.interface.d.ts +5 -0
- package/dist/types/interfaces/data-display/calendar/MonthView.interface.d.ts +5 -0
- package/dist/types/interfaces/data-display/calendar/Scheduler.interface.d.ts +5 -0
- package/dist/types/interfaces/data-display/calendar/WeekView.interface.d.ts +5 -0
- package/dist/types/utils/calendarTooltip.d.ts +13 -0
- package/dist/types/utils/cssLength.d.ts +5 -0
- package/dist/types/utils/tooltipArrow.d.ts +34 -0
- package/dist/utils/calendarTooltip.cjs +18 -0
- package/dist/utils/calendarTooltip.cjs.map +1 -0
- package/dist/utils/calendarTooltip.mjs +18 -0
- package/dist/utils/calendarTooltip.mjs.map +1 -0
- package/dist/utils/cssLength.cjs +13 -0
- package/dist/utils/cssLength.cjs.map +1 -0
- package/dist/utils/cssLength.mjs +13 -0
- package/dist/utils/cssLength.mjs.map +1 -0
- package/dist/utils/tooltipArrow.cjs +37 -0
- package/dist/utils/tooltipArrow.cjs.map +1 -0
- package/dist/utils/tooltipArrow.mjs +36 -0
- package/dist/utils/tooltipArrow.mjs.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhoneInput.mjs","names":[],"sources":["../../../src/components/forms/PhoneInput.vue"],"sourcesContent":["<template>\n <div :class=\"['flex flex-col gap-1.5', fullWidth ? 'w-full' : 'inline-flex']\">\n <!-- Label -->\n <label\n v-if=\"label\"\n :for=\"fieldId\"\n class=\"text-caption font-medium text-foreground\"\n >\n {{ label }}\n <span v-if=\"required\" aria-hidden=\"true\" class=\"text-destructive ml-0.5\"\n >*</span\n >\n </label>\n\n <!-- Unified field wrapper -->\n <div\n ref=\"wrapperEl\"\n :class=\"[\n 'modo-field-wrapper flex items-center overflow-hidden',\n wrapperVariantClasses,\n wrapperHeightClass,\n radiusClasses,\n fullWidth ? 'w-full' : '',\n isDisabled ? 'opacity-60 cursor-not-allowed' : '',\n ]\"\n >\n <!-- Country selector trigger -->\n <button\n ref=\"triggerRef\"\n type=\"button\"\n :disabled=\"isDisabled || readonly\"\n :aria-label=\"loc.phoneInput.selectCountry\"\n :aria-expanded=\"isOpen\"\n :aria-haspopup=\"'listbox'\"\n :class=\"[\n 'flex items-center self-stretch shrink-0 select-none',\n 'transition-colors duration-fast ease-standard',\n triggerPaddingClass,\n isDisabled || readonly ? 'cursor-not-allowed' : 'cursor-pointer',\n ]\"\n @click=\"onTriggerClick\"\n @keydown=\"onTriggerKeydown\"\n >\n <span\n aria-hidden=\"true\"\n :class=\"['leading-none shrink-0', flagSizeClass]\"\n >\n {{ selectedCountry ? countryFlag(selectedCountry.iso) : \"🌐\" }}\n </span>\n <span\n :class=\"[\n 'tabular-nums text-muted-foreground font-medium shrink-0',\n triggerTextClass,\n ]\"\n >\n +{{ selectedCountry?.dial ?? \"?\" }}\n </span>\n <ChevronDownIcon\n aria-hidden=\"true\"\n :class=\"[\n 'shrink-0 transition-transform duration-base ease-standard',\n affordanceIconClass,\n chevronSizeClass,\n isOpen ? 'rotate-180' : '',\n ]\"\n />\n </button>\n\n <!-- Vertical divider -->\n <div aria-hidden=\"true\" class=\"w-px self-stretch bg-border shrink-0\" />\n\n <!-- Phone number input -->\n <input\n :id=\"fieldId\"\n ref=\"inputRef\"\n type=\"tel\"\n inputmode=\"tel\"\n :value=\"localNumber\"\n :placeholder=\"placeholder ?? ''\"\n :disabled=\"isDisabled\"\n :readonly=\"readonly\"\n :required=\"required\"\n :name=\"name ? `${name}-local` : undefined\"\n :autocomplete=\"autocomplete ?? 'tel-national'\"\n :autofocus=\"autofocus\"\n :aria-label=\"!label ? (ariaLabel ?? undefined) : undefined\"\n :aria-invalid=\"hasError || undefined\"\n :aria-describedby=\"describedBy\"\n :aria-required=\"required || undefined\"\n :class=\"[\n 'modo-field-native flex-1 min-w-0 bg-transparent',\n 'text-foreground placeholder:text-muted-foreground',\n 'disabled:cursor-not-allowed',\n inputTextClass,\n inputPaddingClass,\n ]\"\n @input=\"onInput\"\n @change=\"onChange\"\n @focus=\"$emit('focus', $event)\"\n @blur=\"$emit('blur', $event)\"\n />\n\n <!-- Loading spinner -->\n <Loader\n v-if=\"loading\"\n :size=\"resolvedSize === 'large' ? 'medium' : 'small'\"\n :class=\"['shrink-0', affordanceIconClass]\"\n />\n </div>\n\n <!-- Hidden input carrying the full formatted value for form submission -->\n <input v-if=\"name\" type=\"hidden\" :name=\"name\" :value=\"currentFormValue\" />\n\n <!-- Error / helper text -->\n <div v-if=\"errorText || helperText\" class=\"flex items-start gap-2\">\n <Typography\n v-if=\"errorText\"\n :id=\"errorId\"\n variant=\"caption\"\n size=\"medium\"\n color=\"danger\"\n as=\"p\"\n >\n {{ errorText }}\n </Typography>\n <Typography\n v-else-if=\"helperText\"\n :id=\"helperId\"\n variant=\"caption\"\n size=\"medium\"\n color=\"muted\"\n as=\"p\"\n >\n {{ helperText }}\n </Typography>\n </div>\n\n <!-- Country dropdown -->\n <PopoverPanel\n :open=\"isOpen\"\n :style=\"mergedPanelStyle\"\n :radius=\"radius\"\n role=\"listbox\"\n :labelledBy=\"fieldId\"\n @update:panelRef=\"panelRef = $event\"\n >\n <div style=\"max-height: 296px\" class=\"flex flex-col\">\n <!-- Search input -->\n <div class=\"px-3 border-b border-border shrink-0\">\n <div class=\"flex items-center gap-2 h-7\">\n <MagnifyingGlassIcon\n class=\"w-4 h-4 shrink-0 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n <input\n ref=\"searchEl\"\n v-model=\"searchQuery\"\n type=\"text\"\n autocomplete=\"off\"\n spellcheck=\"false\"\n :placeholder=\"loc.phoneInput.searchCountry\"\n class=\"modo-field-native flex-1 min-w-0 bg-transparent p-0 text-caption text-foreground placeholder:text-muted-foreground\"\n @keydown=\"onSearchKeydown\"\n />\n <Button\n v-if=\"searchQuery\"\n variant=\"text\"\n size=\"xs\"\n radius=\"full\"\n :icon=\"XMarkIcon\"\n :ariaLabel=\"loc.common.clear\"\n tabindex=\"-1\"\n :class=\"['shrink-0', affordanceActionClass]\"\n @click=\"searchQuery = ''\"\n />\n </div>\n </div>\n\n <!-- Countries list -->\n <ul\n ref=\"listEl\"\n role=\"listbox\"\n class=\"modo-stagger flex-1 overflow-y-auto w-full\"\n style=\"min-height: 2.5rem\"\n tabindex=\"-1\"\n >\n <li\n v-if=\"filteredCountries.length === 0\"\n class=\"px-3 py-4 text-caption text-muted-foreground text-center\"\n >\n {{ loc.phoneInput.noResults }}\n </li>\n <li\n v-for=\"(c, i) in filteredCountries\"\n :key=\"c.iso\"\n :id=\"optionId(c.iso)\"\n role=\"option\"\n :aria-selected=\"c.iso === activeIso\"\n :class=\"[\n 'flex items-center gap-2.5 px-3 py-2 text-body cursor-pointer select-none',\n 'transition-colors duration-fast ease-standard',\n ['text-foreground', optionHover],\n i === activeIndex ? optionSurface : '',\n c.iso === activeIso ? 'font-medium' : '',\n ]\"\n @pointerenter=\"activeIndex = i\"\n @click=\"selectCountry(c)\"\n >\n <span aria-hidden=\"true\" class=\"text-base leading-none shrink-0\">\n {{ countryFlag(c.iso) }}\n </span>\n <span class=\"flex-1 min-w-0 truncate text-foreground\">{{\n c.name\n }}</span>\n <span\n class=\"shrink-0 tabular-nums text-muted-foreground text-[11px]\"\n >\n +{{ c.dial }}\n </span>\n <CheckIcon\n v-if=\"c.iso === activeIso\"\n :class=\"['w-4 h-4 shrink-0', checkColorClass]\"\n aria-hidden=\"true\"\n />\n </li>\n </ul>\n </div>\n </PopoverPanel>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { computed, nextTick, ref, useId, watch } from \"vue\";\nimport type { PhoneInput } from \"../../interfaces/forms/PhoneInput.interface\";\nimport {\n PHONE_COUNTRIES,\n countryFlag,\n findCountryByIso,\n type PhoneCountry,\n} from \"../../data/phoneCountries\";\nimport {\n useFieldState,\n useFieldClasses,\n FIELD_AFFORDANCE_ICON_BY_COLOR,\n FIELD_AFFORDANCE_ACTION_BY_COLOR,\n} from \"../../composables/useField\";\nimport { usePopover } from \"../../composables/usePopover\";\nimport {\n useResolvedSize,\n useSizeTokens,\n useModoLocale,\n} from \"../../composables/useModoConfig\";\nimport PopoverPanel from \"../layout/PopoverPanel.vue\";\nimport Typography from \"../data-display/Typography.vue\";\nimport Loader from \"../feedback/Loader.vue\";\nimport Button from \"./Button.vue\";\nimport {\n ChevronDownIcon,\n MagnifyingGlassIcon,\n XMarkIcon,\n CheckIcon,\n} from \"@heroicons/vue/24/outline\";\n\nconst loc = useModoLocale();\n\nconst emit = defineEmits<{\n \"update:modelValue\": [value: string];\n \"update:country\": [iso: string];\n change: [value: string];\n focus: [event: FocusEvent];\n blur: [event: FocusEvent];\n}>();\n\nconst props = withDefaults(defineProps<PhoneInput>(), {\n defaultCountry: \"US\",\n format: \"national\",\n variant: \"outline\",\n color: \"default\",\n disabled: false,\n readonly: false,\n required: false,\n loading: false,\n fullWidth: false,\n autofocus: false,\n});\n\nconst resolvedSize = useResolvedSize(() => props.size);\nconst sz = useSizeTokens(() => props.size);\n\n// ── Refs ──────────────────────────────────────────────────────────────────────\nconst inputRef = ref<HTMLInputElement | null>(null);\nconst searchEl = ref<HTMLInputElement | null>(null);\nconst listEl = ref<HTMLElement | null>(null);\nconst wrapperEl = ref<HTMLElement | null>(null);\nconst dropdownWidth = ref(\"\");\n\n// ── Internal state ────────────────────────────────────────────────────────────\nconst localNumber = ref(\"\");\nconst internalCountry = ref((props.defaultCountry ?? \"US\").toUpperCase());\n\n// ── Field state ───────────────────────────────────────────────────────────────\nconst {\n fieldId,\n radius,\n stateColor,\n hasError,\n isDisabled,\n errorId,\n helperId,\n describedBy,\n} = useFieldState(props, {\n componentName: \"PhoneInput\",\n idPrefix: \"modo-phone\",\n});\n\nconst { wrapperVariantClasses, radiusClasses } = useFieldClasses({\n variant: () => props.variant,\n stateColor,\n hasError,\n radius,\n forceFocus: () => isOpen.value,\n halo: () => props.halo,\n});\n\n// ── Country resolution ────────────────────────────────────────────────────────\nconst activeIso = computed(() =>\n (props.country !== undefined\n ? props.country\n : internalCountry.value\n ).toUpperCase(),\n);\nconst selectedCountry = computed(() => findCountryByIso(activeIso.value));\n\n// ── Format helpers ────────────────────────────────────────────────────────────\nfunction buildValue(local: string, dialCode: string): string {\n const fmt = props.format ?? \"national\";\n if (fmt === \"e164\") return `+${dialCode}${local.replace(/\\D/g, \"\")}`;\n if (fmt === \"international\") return `+${dialCode}${local}`;\n return local;\n}\n\nfunction extractNational(v: string | undefined, dialCode: string): string {\n if (!v) return \"\";\n const prefix = `+${dialCode}`;\n if (v.startsWith(prefix)) return v.slice(prefix.length);\n return v;\n}\n\nconst currentFormValue = computed(() =>\n selectedCountry.value\n ? buildValue(localNumber.value, selectedCountry.value.dial)\n : localNumber.value,\n);\n\n// Sync external modelValue → localNumber\nwatch(\n () => props.modelValue,\n (v) => {\n const dial = selectedCountry.value?.dial ?? \"\";\n const national = extractNational(v, dial);\n if (national !== localNumber.value) localNumber.value = national;\n },\n { immediate: true },\n);\n\n// ── Popover ───────────────────────────────────────────────────────────────────\nconst {\n triggerRef,\n panelRef,\n isOpen,\n panelStyle,\n open: openPopover,\n close: closePopover,\n toggle: togglePopover,\n} = usePopover({\n placement: \"bottom-start\",\n onOpen: () => {\n dropdownWidth.value = wrapperEl.value\n ? `${wrapperEl.value.getBoundingClientRect().width}px`\n : \"260px\";\n searchQuery.value = \"\";\n activeIndex.value = Math.max(\n 0,\n filteredCountries.value.findIndex((c) => c.iso === activeIso.value),\n );\n nextTick(() => {\n searchEl.value?.focus();\n scrollActiveIntoView();\n });\n },\n onClose: () => {\n searchQuery.value = \"\";\n activeIndex.value = -1;\n },\n});\n\nconst mergedPanelStyle = computed(() => ({\n ...panelStyle.value,\n ...(dropdownWidth.value ? { width: dropdownWidth.value } : {}),\n}));\n\n// ── Search + filtered list ────────────────────────────────────────────────────\nconst searchQuery = ref(\"\");\nconst activeIndex = ref(-1);\nconst autoListboxId = useId();\n\nconst optionId = (iso: string) =>\n `modo-phone-listbox-${autoListboxId}-opt-${iso}`;\n\nconst filteredCountries = computed<PhoneCountry[]>(() => {\n const q = searchQuery.value.trim().toLowerCase();\n if (!q) return PHONE_COUNTRIES as unknown as PhoneCountry[];\n return (PHONE_COUNTRIES as unknown as PhoneCountry[]).filter(\n (c) =>\n c.name.toLowerCase().includes(q) ||\n c.iso.toLowerCase().includes(q) ||\n c.dial.startsWith(q.replace(/^\\+/, \"\")),\n );\n});\n\nwatch(filteredCountries, (list) => {\n const idx = list.findIndex((c) => c.iso === activeIso.value);\n activeIndex.value = idx >= 0 ? idx : 0;\n});\n\n// ── Option styles ─────────────────────────────────────────────────────────────\nconst OPTION_SURFACE: Record<string, string> = {\n default: \"bg-muted\",\n primary: \"bg-primary/10\",\n danger: \"bg-destructive/10\",\n success: \"bg-success/10\",\n warning: \"bg-warning/10\",\n};\nconst OPTION_HOVER: Record<string, string> = {\n default: \"hover:bg-muted\",\n primary: \"hover:bg-primary/10\",\n danger: \"hover:bg-destructive/10\",\n success: \"hover:bg-success/10\",\n warning: \"hover:bg-warning/10\",\n};\nconst optionSurface = computed(\n () => OPTION_SURFACE[stateColor.value] ?? \"bg-muted\",\n);\nconst optionHover = computed(\n () => OPTION_HOVER[stateColor.value] ?? \"hover:bg-muted\",\n);\nconst CHECK_COLOR_BY_STATE: Record<string, string> = {\n default: \"text-foreground\",\n primary: \"text-primary\",\n danger: \"text-destructive\",\n success: \"text-success\",\n warning: \"text-warning\",\n};\nconst checkColorClass = computed(\n () => CHECK_COLOR_BY_STATE[stateColor.value] ?? \"text-foreground\",\n);\nconst affordanceIconClass = computed(\n () =>\n FIELD_AFFORDANCE_ICON_BY_COLOR[stateColor.value] ?? \"text-muted-foreground\",\n);\nconst affordanceActionClass = computed(\n () =>\n FIELD_AFFORDANCE_ACTION_BY_COLOR[stateColor.value] ??\n \"text-muted-foreground hover:text-foreground\",\n);\n\n// ── Size classes ──────────────────────────────────────────────────────────────\nconst wrapperHeightClass = computed(() => {\n // sz.value.padX is e.g. \"px-2.5\" — convert to pr-* for the wrapper right edge\n const pr = sz.value.padX.replace(\"px-\", \"pr-\");\n return `${sz.value.control} ${pr}`;\n});\n\nconst triggerPaddingClass = computed(() => {\n switch (resolvedSize.value) {\n case \"small\":\n return \"pl-2.5 pr-1.5 gap-1\";\n case \"large\":\n return \"pl-4 pr-2 gap-1.5\";\n default:\n return \"pl-3 pr-2 gap-1\";\n }\n});\n\nconst flagSizeClass = computed(() => {\n switch (resolvedSize.value) {\n case \"small\":\n return \"text-sm\";\n case \"large\":\n return \"text-xl\";\n default:\n return \"text-base\";\n }\n});\n\nconst triggerTextClass = computed(() => {\n switch (resolvedSize.value) {\n case \"small\":\n return \"text-[11px]\";\n case \"large\":\n return \"text-body\";\n default:\n return \"text-caption\";\n }\n});\n\nconst chevronSizeClass = computed(() => {\n switch (resolvedSize.value) {\n case \"small\":\n return \"w-3 h-3\";\n case \"large\":\n return \"w-4 h-4\";\n default:\n return \"w-3.5 h-3.5\";\n }\n});\n\nconst inputTextClass = computed(() => sz.value.text);\n\nconst inputPaddingClass = computed(() => {\n // pr-3 leaves a comfortable gap on the right edge as well; the\n // legacy showroom relied on the field-native default padding which\n // we override here. Without pl-3 numbers visually butt up against\n // the country trigger divider.\n return \"pl-3 pr-3\";\n});\n\n// ── Event handlers ────────────────────────────────────────────────────────────\nfunction onInput(e: Event) {\n const val = (e.target as HTMLInputElement).value;\n localNumber.value = val;\n emit(\"update:modelValue\", buildValue(val, selectedCountry.value?.dial ?? \"\"));\n}\n\nfunction onChange(e: Event) {\n const val = (e.target as HTMLInputElement).value;\n emit(\"change\", buildValue(val, selectedCountry.value?.dial ?? \"\"));\n}\n\nfunction selectCountry(c: PhoneCountry) {\n if (props.country === undefined) internalCountry.value = c.iso;\n emit(\"update:country\", c.iso);\n emit(\"update:modelValue\", buildValue(localNumber.value, c.dial));\n closePopover();\n nextTick(() => inputRef.value?.focus());\n}\n\nfunction onTriggerClick() {\n if (isDisabled.value || props.readonly) return;\n togglePopover();\n}\n\nfunction onTriggerKeydown(e: KeyboardEvent) {\n if (isDisabled.value || props.readonly) return;\n if (e.key === \"ArrowDown\" || e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n if (!isOpen.value) openPopover();\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n closePopover();\n }\n}\n\nfunction onSearchKeydown(e: KeyboardEvent) {\n const list = filteredCountries.value;\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n activeIndex.value = Math.min(activeIndex.value + 1, list.length - 1);\n scrollActiveIntoView();\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n activeIndex.value = Math.max(activeIndex.value - 1, 0);\n scrollActiveIntoView();\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n const c = list[activeIndex.value];\n if (c) selectCountry(c);\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n closePopover();\n triggerRef.value?.focus?.();\n } else if (e.key === \"Tab\") {\n closePopover();\n }\n}\n\nfunction scrollActiveIntoView() {\n nextTick(() => {\n const c = filteredCountries.value[activeIndex.value];\n if (!c || !listEl.value) return;\n const el = document.getElementById(optionId(c.iso));\n el?.scrollIntoView({ block: \"nearest\" });\n });\n}\n\n// ── Expose ────────────────────────────────────────────────────────────────────\ndefineExpose({\n focus: () => inputRef.value?.focus(),\n blur: () => inputRef.value?.blur(),\n inputRef,\n});\n</script>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"PhoneInput.mjs","names":[],"sources":["../../../src/components/forms/PhoneInput.vue"],"sourcesContent":["<template>\n <div :class=\"['flex flex-col gap-1.5', fullWidth ? 'w-full' : 'inline-flex']\">\n <!-- Label -->\n <label\n v-if=\"label\"\n :for=\"fieldId\"\n class=\"text-caption font-medium text-foreground\"\n >\n {{ label }}\n <span v-if=\"required\" aria-hidden=\"true\" class=\"text-destructive ml-0.5\"\n >*</span\n >\n </label>\n\n <!-- Unified field wrapper -->\n <div\n ref=\"wrapperEl\"\n :class=\"[\n 'modo-field-wrapper flex items-center overflow-hidden',\n wrapperVariantClasses,\n wrapperHeightClass,\n radiusClasses,\n fullWidth ? 'w-full' : '',\n isDisabled ? 'opacity-60 cursor-not-allowed' : '',\n ]\"\n >\n <!-- Country selector trigger -->\n <button\n ref=\"triggerRef\"\n type=\"button\"\n :disabled=\"isDisabled || readonly\"\n :aria-label=\"loc.phoneInput.selectCountry\"\n :aria-expanded=\"isOpen\"\n :aria-haspopup=\"'listbox'\"\n :class=\"[\n 'flex items-center self-stretch shrink-0 select-none',\n 'transition-colors duration-fast ease-standard',\n triggerPaddingClass,\n isDisabled || readonly ? 'cursor-not-allowed' : 'cursor-pointer',\n ]\"\n @click=\"onTriggerClick\"\n @keydown=\"onTriggerKeydown\"\n >\n <span\n aria-hidden=\"true\"\n :class=\"['leading-none shrink-0', flagSizeClass]\"\n >\n {{ selectedCountry ? countryFlag(selectedCountry.iso) : \"🌐\" }}\n </span>\n <span\n :class=\"[\n 'tabular-nums text-muted-foreground font-medium shrink-0',\n triggerTextClass,\n ]\"\n >\n +{{ selectedCountry?.dial ?? \"?\" }}\n </span>\n <ChevronDownIcon\n aria-hidden=\"true\"\n :class=\"[\n 'shrink-0 transition-transform duration-base ease-standard',\n affordanceIconClass,\n chevronSizeClass,\n isOpen ? 'rotate-180' : '',\n ]\"\n />\n </button>\n\n <!-- Vertical divider -->\n <div aria-hidden=\"true\" class=\"w-px self-stretch bg-border shrink-0\" />\n\n <!-- Phone number input -->\n <input\n :id=\"fieldId\"\n ref=\"inputRef\"\n type=\"tel\"\n inputmode=\"tel\"\n :value=\"localNumber\"\n :placeholder=\"placeholder ?? ''\"\n :disabled=\"isDisabled\"\n :readonly=\"readonly\"\n :required=\"required\"\n :name=\"name ? `${name}-local` : undefined\"\n :autocomplete=\"autocomplete ?? 'tel-national'\"\n :autofocus=\"autofocus\"\n :aria-label=\"!label ? (ariaLabel ?? undefined) : undefined\"\n :aria-invalid=\"hasError || undefined\"\n :aria-describedby=\"describedBy\"\n :aria-required=\"required || undefined\"\n :class=\"[\n 'modo-field-native flex-1 min-w-0 bg-transparent',\n 'text-foreground placeholder:text-muted-foreground',\n 'disabled:cursor-not-allowed',\n inputTextClass,\n inputPaddingClass,\n ]\"\n @input=\"onInput\"\n @change=\"onChange\"\n @focus=\"$emit('focus', $event)\"\n @blur=\"$emit('blur', $event)\"\n />\n\n <!-- Loading spinner -->\n <Loader\n v-if=\"loading\"\n :size=\"resolvedSize === 'large' ? 'medium' : 'small'\"\n :class=\"['shrink-0', affordanceIconClass]\"\n />\n </div>\n\n <!-- Hidden input carrying the full formatted value for form submission -->\n <input v-if=\"name\" type=\"hidden\" :name=\"name\" :value=\"currentFormValue\" />\n\n <!-- Error / helper text -->\n <div v-if=\"errorText || helperText\" class=\"flex items-start gap-2\">\n <Typography\n v-if=\"errorText\"\n :id=\"errorId\"\n variant=\"caption\"\n size=\"medium\"\n color=\"danger\"\n as=\"p\"\n >\n {{ errorText }}\n </Typography>\n <Typography\n v-else-if=\"helperText\"\n :id=\"helperId\"\n variant=\"caption\"\n size=\"medium\"\n color=\"muted\"\n as=\"p\"\n >\n {{ helperText }}\n </Typography>\n </div>\n\n <!-- Country dropdown -->\n <PopoverPanel\n :open=\"isOpen\"\n :style=\"mergedPanelStyle\"\n :radius=\"radius\"\n role=\"listbox\"\n :labelledBy=\"fieldId\"\n @update:panelRef=\"panelRef = $event\"\n >\n <div style=\"max-height: 296px\" class=\"flex flex-col\">\n <!-- Search input -->\n <div class=\"px-3 border-b border-border shrink-0\">\n <div class=\"flex items-center gap-2 h-7\">\n <MagnifyingGlassIcon\n class=\"w-4 h-4 shrink-0 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n <input\n ref=\"searchEl\"\n v-model=\"searchQuery\"\n type=\"text\"\n autocomplete=\"off\"\n spellcheck=\"false\"\n :placeholder=\"loc.phoneInput.searchCountry\"\n class=\"modo-field-native flex-1 min-w-0 bg-transparent p-0 text-caption text-foreground placeholder:text-muted-foreground\"\n @keydown=\"onSearchKeydown\"\n />\n <Button\n v-if=\"searchQuery\"\n variant=\"text\"\n size=\"xs\"\n radius=\"full\"\n :icon=\"XMarkIcon\"\n :ariaLabel=\"loc.common.clear\"\n tabindex=\"-1\"\n :class=\"['shrink-0', affordanceActionClass]\"\n @click=\"searchQuery = ''\"\n />\n </div>\n </div>\n\n <!-- Countries list -->\n <ul\n ref=\"listEl\"\n role=\"listbox\"\n class=\"modo-stagger flex-1 overflow-y-auto w-full\"\n style=\"min-height: 2.5rem\"\n tabindex=\"-1\"\n >\n <li\n v-if=\"filteredCountries.length === 0\"\n class=\"px-3 py-4 text-caption text-muted-foreground text-center\"\n >\n {{ loc.phoneInput.noResults }}\n </li>\n <li\n v-for=\"(c, i) in filteredCountries\"\n :key=\"c.iso\"\n :id=\"optionId(c.iso)\"\n role=\"option\"\n :aria-selected=\"c.iso === activeIso\"\n :class=\"[\n 'flex items-center gap-2.5 px-3 py-2 text-body cursor-pointer select-none',\n 'transition-colors duration-fast ease-standard',\n ['text-foreground', optionHover],\n i === activeIndex ? optionSurface : '',\n c.iso === activeIso ? 'font-medium' : '',\n ]\"\n @pointerenter=\"activeIndex = i\"\n @click=\"selectCountry(c)\"\n >\n <span aria-hidden=\"true\" class=\"text-base leading-none shrink-0\">\n {{ countryFlag(c.iso) }}\n </span>\n <span class=\"flex-1 min-w-0 truncate text-foreground\">{{\n c.name\n }}</span>\n <span\n class=\"shrink-0 tabular-nums text-muted-foreground text-[11px]\"\n >\n +{{ c.dial }}\n </span>\n <CheckIcon\n v-if=\"c.iso === activeIso\"\n :class=\"['w-4 h-4 shrink-0', checkColorClass]\"\n aria-hidden=\"true\"\n />\n </li>\n </ul>\n </div>\n </PopoverPanel>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { computed, nextTick, ref, useId, watch } from \"vue\";\nimport type { PhoneInput } from \"../../interfaces/forms/PhoneInput.interface\";\nimport {\n PHONE_COUNTRIES,\n countryFlag,\n findCountryByIso,\n type PhoneCountry,\n} from \"../../data/phoneCountries\";\nimport {\n useFieldState,\n useFieldClasses,\n FIELD_AFFORDANCE_ICON_BY_COLOR,\n FIELD_AFFORDANCE_ACTION_BY_COLOR,\n} from \"../../composables/useField\";\nimport { usePopover } from \"../../composables/usePopover\";\nimport {\n useResolvedSize,\n useSizeTokens,\n useModoLocale,\n} from \"../../composables/useModoConfig\";\nimport PopoverPanel from \"../layout/PopoverPanel.vue\";\nimport Typography from \"../data-display/Typography.vue\";\nimport Loader from \"../feedback/Loader.vue\";\nimport Button from \"./Button.vue\";\nimport {\n ChevronDownIcon,\n MagnifyingGlassIcon,\n XMarkIcon,\n CheckIcon,\n} from \"@heroicons/vue/24/outline\";\n\nconst loc = useModoLocale();\n\nconst emit = defineEmits<{\n \"update:modelValue\": [value: string];\n \"update:country\": [iso: string];\n change: [value: string];\n focus: [event: FocusEvent];\n blur: [event: FocusEvent];\n}>();\n\nconst props = withDefaults(defineProps<PhoneInput>(), {\n defaultCountry: \"US\",\n format: \"national\",\n variant: \"outline\",\n color: \"default\",\n disabled: false,\n readonly: false,\n required: false,\n loading: false,\n fullWidth: false,\n autofocus: false,\n});\n\nconst resolvedSize = useResolvedSize(() => props.size);\nconst sz = useSizeTokens(() => props.size);\n\n// ── Refs ──────────────────────────────────────────────────────────────────────\nconst inputRef = ref<HTMLInputElement | null>(null);\nconst searchEl = ref<HTMLInputElement | null>(null);\nconst listEl = ref<HTMLElement | null>(null);\nconst wrapperEl = ref<HTMLElement | null>(null);\nconst dropdownWidth = ref(\"\");\n\n// ── Internal state ────────────────────────────────────────────────────────────\nconst localNumber = ref(\"\");\nconst internalCountry = ref((props.defaultCountry ?? \"US\").toUpperCase());\n\n// ── Field state ───────────────────────────────────────────────────────────────\nconst {\n fieldId,\n radius,\n stateColor,\n hasError,\n isDisabled,\n errorId,\n helperId,\n describedBy,\n} = useFieldState(props, {\n componentName: \"PhoneInput\",\n idPrefix: \"modo-phone\",\n});\n\nconst { wrapperVariantClasses, radiusClasses } = useFieldClasses({\n variant: () => props.variant,\n stateColor,\n hasError,\n radius,\n forceFocus: () => isOpen.value,\n halo: () => props.halo,\n});\n\n// ── Country resolution ────────────────────────────────────────────────────────\nconst activeIso = computed(() =>\n (props.country !== undefined\n ? props.country\n : internalCountry.value\n ).toUpperCase(),\n);\nconst selectedCountry = computed(() => findCountryByIso(activeIso.value));\n\n// ── Format helpers ────────────────────────────────────────────────────────────\nfunction buildValue(local: string, dialCode: string): string {\n const fmt = props.format ?? \"national\";\n if (fmt === \"e164\") return `+${dialCode}${local.replace(/\\D/g, \"\")}`;\n if (fmt === \"international\") return `+${dialCode}${local}`;\n return local;\n}\n\nfunction extractNational(v: string | undefined, dialCode: string): string {\n if (!v) return \"\";\n const prefix = `+${dialCode}`;\n if (v.startsWith(prefix)) return v.slice(prefix.length);\n return v;\n}\n\nconst currentFormValue = computed(() =>\n selectedCountry.value\n ? buildValue(localNumber.value, selectedCountry.value.dial)\n : localNumber.value,\n);\n\n// Sync external modelValue → localNumber\nwatch(\n () => props.modelValue,\n (v) => {\n const dial = selectedCountry.value?.dial ?? \"\";\n const national = extractNational(v, dial);\n if (national !== localNumber.value) localNumber.value = national;\n },\n { immediate: true },\n);\n\n// ── Popover ───────────────────────────────────────────────────────────────────\nconst {\n triggerRef,\n panelRef,\n isOpen,\n panelStyle,\n open: openPopover,\n close: closePopover,\n toggle: togglePopover,\n} = usePopover({\n placement: \"bottom-start\",\n onOpen: () => {\n dropdownWidth.value = wrapperEl.value\n ? `${wrapperEl.value.getBoundingClientRect().width}px`\n : \"260px\";\n searchQuery.value = \"\";\n activeIndex.value = Math.max(\n 0,\n filteredCountries.value.findIndex((c) => c.iso === activeIso.value),\n );\n nextTick(() => {\n searchEl.value?.focus();\n scrollActiveIntoView();\n });\n },\n onClose: () => {\n searchQuery.value = \"\";\n activeIndex.value = -1;\n },\n});\n\nconst mergedPanelStyle = computed(() => ({\n ...panelStyle.value,\n ...(dropdownWidth.value ? { width: dropdownWidth.value } : {}),\n}));\n\n// ── Search + filtered list ────────────────────────────────────────────────────\nconst searchQuery = ref(\"\");\nconst activeIndex = ref(-1);\nconst autoListboxId = useId();\n\nconst optionId = (iso: string) =>\n `modo-phone-listbox-${autoListboxId}-opt-${iso}`;\n\nconst filteredCountries = computed<PhoneCountry[]>(() => {\n const q = searchQuery.value.trim().toLowerCase();\n if (!q) return PHONE_COUNTRIES as unknown as PhoneCountry[];\n return (PHONE_COUNTRIES as unknown as PhoneCountry[]).filter(\n (c) =>\n c.name.toLowerCase().includes(q) ||\n c.iso.toLowerCase().includes(q) ||\n c.dial.startsWith(q.replace(/^\\+/, \"\")),\n );\n});\n\nwatch(filteredCountries, (list) => {\n const idx = list.findIndex((c) => c.iso === activeIso.value);\n activeIndex.value = idx >= 0 ? idx : 0;\n});\n\n// ── Option styles ─────────────────────────────────────────────────────────────\nconst OPTION_SURFACE: Record<string, string> = {\n default: \"bg-muted\",\n primary: \"bg-primary/10\",\n danger: \"bg-destructive/10\",\n success: \"bg-success/10\",\n warning: \"bg-warning/10\",\n};\nconst OPTION_HOVER: Record<string, string> = {\n default: \"hover:bg-muted\",\n primary: \"hover:bg-primary/10\",\n danger: \"hover:bg-destructive/10\",\n success: \"hover:bg-success/10\",\n warning: \"hover:bg-warning/10\",\n};\nconst optionSurface = computed(\n () => OPTION_SURFACE[stateColor.value] ?? \"bg-muted\",\n);\nconst optionHover = computed(\n () => OPTION_HOVER[stateColor.value] ?? \"hover:bg-muted\",\n);\nconst CHECK_COLOR_BY_STATE: Record<string, string> = {\n default: \"text-foreground\",\n primary: \"text-primary\",\n danger: \"text-destructive\",\n success: \"text-success\",\n warning: \"text-warning\",\n};\nconst checkColorClass = computed(\n () => CHECK_COLOR_BY_STATE[stateColor.value] ?? \"text-foreground\",\n);\nconst affordanceIconClass = computed(\n () =>\n FIELD_AFFORDANCE_ICON_BY_COLOR[stateColor.value] ?? \"text-muted-foreground\",\n);\nconst affordanceActionClass = computed(\n () =>\n FIELD_AFFORDANCE_ACTION_BY_COLOR[stateColor.value] ??\n \"text-muted-foreground hover:text-foreground\",\n);\n\n// ── Size classes ──────────────────────────────────────────────────────────────\nconst wrapperHeightClass = computed(() => {\n // sz.value.padX is e.g. \"px-2.5\" — convert to pr-* for the wrapper right edge\n const pr = sz.value.padX.replace(\"px-\", \"pr-\");\n return `${sz.value.control} ${pr}`;\n});\n\nconst triggerPaddingClass = computed(() => {\n switch (resolvedSize.value) {\n case \"small\":\n return \"pl-2.5 pr-1.5 gap-1\";\n case \"large\":\n return \"pl-4 pr-2 gap-1.5\";\n default:\n return \"pl-3 pr-2 gap-1\";\n }\n});\n\nconst flagSizeClass = computed(() => {\n switch (resolvedSize.value) {\n case \"small\":\n return \"text-sm\";\n case \"large\":\n return \"text-xl\";\n default:\n return \"text-base\";\n }\n});\n\nconst triggerTextClass = computed(() => {\n switch (resolvedSize.value) {\n case \"small\":\n return \"text-[11px]\";\n case \"large\":\n return \"text-body\";\n default:\n return \"text-caption\";\n }\n});\n\nconst chevronSizeClass = computed(() => {\n switch (resolvedSize.value) {\n case \"small\":\n return \"w-3 h-3\";\n case \"large\":\n return \"w-4 h-4\";\n default:\n return \"w-3.5 h-3.5\";\n }\n});\n\nconst inputTextClass = computed(() => sz.value.text);\n\nconst inputPaddingClass = computed(() => {\n // pr-3 leaves a comfortable gap on the right edge as well; the\n // legacy showroom relied on the field-native default padding which\n // we override here. Without pl-3 numbers visually butt up against\n // the country trigger divider.\n return \"pl-3 pr-3\";\n});\n\n// ── Event handlers ────────────────────────────────────────────────────────────\nfunction onInput(e: Event) {\n const val = (e.target as HTMLInputElement).value;\n localNumber.value = val;\n emit(\"update:modelValue\", buildValue(val, selectedCountry.value?.dial ?? \"\"));\n}\n\nfunction onChange(e: Event) {\n const val = (e.target as HTMLInputElement).value;\n emit(\"change\", buildValue(val, selectedCountry.value?.dial ?? \"\"));\n}\n\nfunction selectCountry(c: PhoneCountry) {\n if (props.country === undefined) internalCountry.value = c.iso;\n emit(\"update:country\", c.iso);\n emit(\"update:modelValue\", buildValue(localNumber.value, c.dial));\n closePopover();\n nextTick(() => inputRef.value?.focus());\n}\n\nfunction onTriggerClick() {\n if (isDisabled.value || props.readonly) return;\n togglePopover();\n}\n\nfunction onTriggerKeydown(e: KeyboardEvent) {\n if (isDisabled.value || props.readonly) return;\n if (e.key === \"ArrowDown\" || e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n if (!isOpen.value) openPopover();\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n closePopover();\n }\n}\n\nfunction onSearchKeydown(e: KeyboardEvent) {\n const list = filteredCountries.value;\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n activeIndex.value = Math.min(activeIndex.value + 1, list.length - 1);\n scrollActiveIntoView();\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n activeIndex.value = Math.max(activeIndex.value - 1, 0);\n scrollActiveIntoView();\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n const c = list[activeIndex.value];\n if (c) selectCountry(c);\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n closePopover();\n triggerRef.value?.focus?.();\n } else if (e.key === \"Tab\") {\n // The search field lives inside a panel teleported to <body>, i.e. at the\n // very end of the document. Letting the browser resolve Tab from there\n // walks *past* the whole field — the number input sits earlier in the DOM\n // and is never reached — so focus landed on whatever followed the panel\n // while the panel was unmounting. Drive the destination explicitly:\n // forwards continues into the number input, backwards returns to the flag\n // trigger, which is the order the field reads in.\n e.preventDefault();\n closePopover();\n if (e.shiftKey) triggerRef.value?.focus?.();\n else inputRef.value?.focus();\n }\n}\n\nfunction scrollActiveIntoView() {\n nextTick(() => {\n const c = filteredCountries.value[activeIndex.value];\n if (!c || !listEl.value) return;\n const el = document.getElementById(optionId(c.iso));\n el?.scrollIntoView({ block: \"nearest\" });\n });\n}\n\n// ── Expose ────────────────────────────────────────────────────────────────────\ndefineExpose({\n focus: () => inputRef.value?.focus(),\n blur: () => inputRef.value?.blur(),\n inputRef,\n});\n</script>\n"],"mappings":""}
|
|
@@ -305,7 +305,12 @@ var PhoneInput_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ (0,
|
|
|
305
305
|
e.preventDefault();
|
|
306
306
|
closePopover();
|
|
307
307
|
triggerRef.value?.focus?.();
|
|
308
|
-
} else if (e.key === "Tab")
|
|
308
|
+
} else if (e.key === "Tab") {
|
|
309
|
+
e.preventDefault();
|
|
310
|
+
closePopover();
|
|
311
|
+
if (e.shiftKey) triggerRef.value?.focus?.();
|
|
312
|
+
else inputRef.value?.focus();
|
|
313
|
+
}
|
|
309
314
|
}
|
|
310
315
|
function scrollActiveIntoView() {
|
|
311
316
|
(0, vue.nextTick)(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhoneInput.vue_vue_type_script_setup_true_lang.cjs","names":["$emit"],"sources":["../../../src/components/forms/PhoneInput.vue"],"sourcesContent":["<template>\n <div :class=\"['flex flex-col gap-1.5', fullWidth ? 'w-full' : 'inline-flex']\">\n <!-- Label -->\n <label\n v-if=\"label\"\n :for=\"fieldId\"\n class=\"text-caption font-medium text-foreground\"\n >\n {{ label }}\n <span v-if=\"required\" aria-hidden=\"true\" class=\"text-destructive ml-0.5\"\n >*</span\n >\n </label>\n\n <!-- Unified field wrapper -->\n <div\n ref=\"wrapperEl\"\n :class=\"[\n 'modo-field-wrapper flex items-center overflow-hidden',\n wrapperVariantClasses,\n wrapperHeightClass,\n radiusClasses,\n fullWidth ? 'w-full' : '',\n isDisabled ? 'opacity-60 cursor-not-allowed' : '',\n ]\"\n >\n <!-- Country selector trigger -->\n <button\n ref=\"triggerRef\"\n type=\"button\"\n :disabled=\"isDisabled || readonly\"\n :aria-label=\"loc.phoneInput.selectCountry\"\n :aria-expanded=\"isOpen\"\n :aria-haspopup=\"'listbox'\"\n :class=\"[\n 'flex items-center self-stretch shrink-0 select-none',\n 'transition-colors duration-fast ease-standard',\n triggerPaddingClass,\n isDisabled || readonly ? 'cursor-not-allowed' : 'cursor-pointer',\n ]\"\n @click=\"onTriggerClick\"\n @keydown=\"onTriggerKeydown\"\n >\n <span\n aria-hidden=\"true\"\n :class=\"['leading-none shrink-0', flagSizeClass]\"\n >\n {{ selectedCountry ? countryFlag(selectedCountry.iso) : \"🌐\" }}\n </span>\n <span\n :class=\"[\n 'tabular-nums text-muted-foreground font-medium shrink-0',\n triggerTextClass,\n ]\"\n >\n +{{ selectedCountry?.dial ?? \"?\" }}\n </span>\n <ChevronDownIcon\n aria-hidden=\"true\"\n :class=\"[\n 'shrink-0 transition-transform duration-base ease-standard',\n affordanceIconClass,\n chevronSizeClass,\n isOpen ? 'rotate-180' : '',\n ]\"\n />\n </button>\n\n <!-- Vertical divider -->\n <div aria-hidden=\"true\" class=\"w-px self-stretch bg-border shrink-0\" />\n\n <!-- Phone number input -->\n <input\n :id=\"fieldId\"\n ref=\"inputRef\"\n type=\"tel\"\n inputmode=\"tel\"\n :value=\"localNumber\"\n :placeholder=\"placeholder ?? ''\"\n :disabled=\"isDisabled\"\n :readonly=\"readonly\"\n :required=\"required\"\n :name=\"name ? `${name}-local` : undefined\"\n :autocomplete=\"autocomplete ?? 'tel-national'\"\n :autofocus=\"autofocus\"\n :aria-label=\"!label ? (ariaLabel ?? undefined) : undefined\"\n :aria-invalid=\"hasError || undefined\"\n :aria-describedby=\"describedBy\"\n :aria-required=\"required || undefined\"\n :class=\"[\n 'modo-field-native flex-1 min-w-0 bg-transparent',\n 'text-foreground placeholder:text-muted-foreground',\n 'disabled:cursor-not-allowed',\n inputTextClass,\n inputPaddingClass,\n ]\"\n @input=\"onInput\"\n @change=\"onChange\"\n @focus=\"$emit('focus', $event)\"\n @blur=\"$emit('blur', $event)\"\n />\n\n <!-- Loading spinner -->\n <Loader\n v-if=\"loading\"\n :size=\"resolvedSize === 'large' ? 'medium' : 'small'\"\n :class=\"['shrink-0', affordanceIconClass]\"\n />\n </div>\n\n <!-- Hidden input carrying the full formatted value for form submission -->\n <input v-if=\"name\" type=\"hidden\" :name=\"name\" :value=\"currentFormValue\" />\n\n <!-- Error / helper text -->\n <div v-if=\"errorText || helperText\" class=\"flex items-start gap-2\">\n <Typography\n v-if=\"errorText\"\n :id=\"errorId\"\n variant=\"caption\"\n size=\"medium\"\n color=\"danger\"\n as=\"p\"\n >\n {{ errorText }}\n </Typography>\n <Typography\n v-else-if=\"helperText\"\n :id=\"helperId\"\n variant=\"caption\"\n size=\"medium\"\n color=\"muted\"\n as=\"p\"\n >\n {{ helperText }}\n </Typography>\n </div>\n\n <!-- Country dropdown -->\n <PopoverPanel\n :open=\"isOpen\"\n :style=\"mergedPanelStyle\"\n :radius=\"radius\"\n role=\"listbox\"\n :labelledBy=\"fieldId\"\n @update:panelRef=\"panelRef = $event\"\n >\n <div style=\"max-height: 296px\" class=\"flex flex-col\">\n <!-- Search input -->\n <div class=\"px-3 border-b border-border shrink-0\">\n <div class=\"flex items-center gap-2 h-7\">\n <MagnifyingGlassIcon\n class=\"w-4 h-4 shrink-0 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n <input\n ref=\"searchEl\"\n v-model=\"searchQuery\"\n type=\"text\"\n autocomplete=\"off\"\n spellcheck=\"false\"\n :placeholder=\"loc.phoneInput.searchCountry\"\n class=\"modo-field-native flex-1 min-w-0 bg-transparent p-0 text-caption text-foreground placeholder:text-muted-foreground\"\n @keydown=\"onSearchKeydown\"\n />\n <Button\n v-if=\"searchQuery\"\n variant=\"text\"\n size=\"xs\"\n radius=\"full\"\n :icon=\"XMarkIcon\"\n :ariaLabel=\"loc.common.clear\"\n tabindex=\"-1\"\n :class=\"['shrink-0', affordanceActionClass]\"\n @click=\"searchQuery = ''\"\n />\n </div>\n </div>\n\n <!-- Countries list -->\n <ul\n ref=\"listEl\"\n role=\"listbox\"\n class=\"modo-stagger flex-1 overflow-y-auto w-full\"\n style=\"min-height: 2.5rem\"\n tabindex=\"-1\"\n >\n <li\n v-if=\"filteredCountries.length === 0\"\n class=\"px-3 py-4 text-caption text-muted-foreground text-center\"\n >\n {{ loc.phoneInput.noResults }}\n </li>\n <li\n v-for=\"(c, i) in filteredCountries\"\n :key=\"c.iso\"\n :id=\"optionId(c.iso)\"\n role=\"option\"\n :aria-selected=\"c.iso === activeIso\"\n :class=\"[\n 'flex items-center gap-2.5 px-3 py-2 text-body cursor-pointer select-none',\n 'transition-colors duration-fast ease-standard',\n ['text-foreground', optionHover],\n i === activeIndex ? optionSurface : '',\n c.iso === activeIso ? 'font-medium' : '',\n ]\"\n @pointerenter=\"activeIndex = i\"\n @click=\"selectCountry(c)\"\n >\n <span aria-hidden=\"true\" class=\"text-base leading-none shrink-0\">\n {{ countryFlag(c.iso) }}\n </span>\n <span class=\"flex-1 min-w-0 truncate text-foreground\">{{\n c.name\n }}</span>\n <span\n class=\"shrink-0 tabular-nums text-muted-foreground text-[11px]\"\n >\n +{{ c.dial }}\n </span>\n <CheckIcon\n v-if=\"c.iso === activeIso\"\n :class=\"['w-4 h-4 shrink-0', checkColorClass]\"\n aria-hidden=\"true\"\n />\n </li>\n </ul>\n </div>\n </PopoverPanel>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { computed, nextTick, ref, useId, watch } from \"vue\";\nimport type { PhoneInput } from \"../../interfaces/forms/PhoneInput.interface\";\nimport {\n PHONE_COUNTRIES,\n countryFlag,\n findCountryByIso,\n type PhoneCountry,\n} from \"../../data/phoneCountries\";\nimport {\n useFieldState,\n useFieldClasses,\n FIELD_AFFORDANCE_ICON_BY_COLOR,\n FIELD_AFFORDANCE_ACTION_BY_COLOR,\n} from \"../../composables/useField\";\nimport { usePopover } from \"../../composables/usePopover\";\nimport {\n useResolvedSize,\n useSizeTokens,\n useModoLocale,\n} from \"../../composables/useModoConfig\";\nimport PopoverPanel from \"../layout/PopoverPanel.vue\";\nimport Typography from \"../data-display/Typography.vue\";\nimport Loader from \"../feedback/Loader.vue\";\nimport Button from \"./Button.vue\";\nimport {\n ChevronDownIcon,\n MagnifyingGlassIcon,\n XMarkIcon,\n CheckIcon,\n} from \"@heroicons/vue/24/outline\";\n\nconst loc = useModoLocale();\n\nconst emit = defineEmits<{\n \"update:modelValue\": [value: string];\n \"update:country\": [iso: string];\n change: [value: string];\n focus: [event: FocusEvent];\n blur: [event: FocusEvent];\n}>();\n\nconst props = withDefaults(defineProps<PhoneInput>(), {\n defaultCountry: \"US\",\n format: \"national\",\n variant: \"outline\",\n color: \"default\",\n disabled: false,\n readonly: false,\n required: false,\n loading: false,\n fullWidth: false,\n autofocus: false,\n});\n\nconst resolvedSize = useResolvedSize(() => props.size);\nconst sz = useSizeTokens(() => props.size);\n\n// ── Refs ──────────────────────────────────────────────────────────────────────\nconst inputRef = ref<HTMLInputElement | null>(null);\nconst searchEl = ref<HTMLInputElement | null>(null);\nconst listEl = ref<HTMLElement | null>(null);\nconst wrapperEl = ref<HTMLElement | null>(null);\nconst dropdownWidth = ref(\"\");\n\n// ── Internal state ────────────────────────────────────────────────────────────\nconst localNumber = ref(\"\");\nconst internalCountry = ref((props.defaultCountry ?? \"US\").toUpperCase());\n\n// ── Field state ───────────────────────────────────────────────────────────────\nconst {\n fieldId,\n radius,\n stateColor,\n hasError,\n isDisabled,\n errorId,\n helperId,\n describedBy,\n} = useFieldState(props, {\n componentName: \"PhoneInput\",\n idPrefix: \"modo-phone\",\n});\n\nconst { wrapperVariantClasses, radiusClasses } = useFieldClasses({\n variant: () => props.variant,\n stateColor,\n hasError,\n radius,\n forceFocus: () => isOpen.value,\n halo: () => props.halo,\n});\n\n// ── Country resolution ────────────────────────────────────────────────────────\nconst activeIso = computed(() =>\n (props.country !== undefined\n ? props.country\n : internalCountry.value\n ).toUpperCase(),\n);\nconst selectedCountry = computed(() => findCountryByIso(activeIso.value));\n\n// ── Format helpers ────────────────────────────────────────────────────────────\nfunction buildValue(local: string, dialCode: string): string {\n const fmt = props.format ?? \"national\";\n if (fmt === \"e164\") return `+${dialCode}${local.replace(/\\D/g, \"\")}`;\n if (fmt === \"international\") return `+${dialCode}${local}`;\n return local;\n}\n\nfunction extractNational(v: string | undefined, dialCode: string): string {\n if (!v) return \"\";\n const prefix = `+${dialCode}`;\n if (v.startsWith(prefix)) return v.slice(prefix.length);\n return v;\n}\n\nconst currentFormValue = computed(() =>\n selectedCountry.value\n ? buildValue(localNumber.value, selectedCountry.value.dial)\n : localNumber.value,\n);\n\n// Sync external modelValue → localNumber\nwatch(\n () => props.modelValue,\n (v) => {\n const dial = selectedCountry.value?.dial ?? \"\";\n const national = extractNational(v, dial);\n if (national !== localNumber.value) localNumber.value = national;\n },\n { immediate: true },\n);\n\n// ── Popover ───────────────────────────────────────────────────────────────────\nconst {\n triggerRef,\n panelRef,\n isOpen,\n panelStyle,\n open: openPopover,\n close: closePopover,\n toggle: togglePopover,\n} = usePopover({\n placement: \"bottom-start\",\n onOpen: () => {\n dropdownWidth.value = wrapperEl.value\n ? `${wrapperEl.value.getBoundingClientRect().width}px`\n : \"260px\";\n searchQuery.value = \"\";\n activeIndex.value = Math.max(\n 0,\n filteredCountries.value.findIndex((c) => c.iso === activeIso.value),\n );\n nextTick(() => {\n searchEl.value?.focus();\n scrollActiveIntoView();\n });\n },\n onClose: () => {\n searchQuery.value = \"\";\n activeIndex.value = -1;\n },\n});\n\nconst mergedPanelStyle = computed(() => ({\n ...panelStyle.value,\n ...(dropdownWidth.value ? { width: dropdownWidth.value } : {}),\n}));\n\n// ── Search + filtered list ────────────────────────────────────────────────────\nconst searchQuery = ref(\"\");\nconst activeIndex = ref(-1);\nconst autoListboxId = useId();\n\nconst optionId = (iso: string) =>\n `modo-phone-listbox-${autoListboxId}-opt-${iso}`;\n\nconst filteredCountries = computed<PhoneCountry[]>(() => {\n const q = searchQuery.value.trim().toLowerCase();\n if (!q) return PHONE_COUNTRIES as unknown as PhoneCountry[];\n return (PHONE_COUNTRIES as unknown as PhoneCountry[]).filter(\n (c) =>\n c.name.toLowerCase().includes(q) ||\n c.iso.toLowerCase().includes(q) ||\n c.dial.startsWith(q.replace(/^\\+/, \"\")),\n );\n});\n\nwatch(filteredCountries, (list) => {\n const idx = list.findIndex((c) => c.iso === activeIso.value);\n activeIndex.value = idx >= 0 ? idx : 0;\n});\n\n// ── Option styles ─────────────────────────────────────────────────────────────\nconst OPTION_SURFACE: Record<string, string> = {\n default: \"bg-muted\",\n primary: \"bg-primary/10\",\n danger: \"bg-destructive/10\",\n success: \"bg-success/10\",\n warning: \"bg-warning/10\",\n};\nconst OPTION_HOVER: Record<string, string> = {\n default: \"hover:bg-muted\",\n primary: \"hover:bg-primary/10\",\n danger: \"hover:bg-destructive/10\",\n success: \"hover:bg-success/10\",\n warning: \"hover:bg-warning/10\",\n};\nconst optionSurface = computed(\n () => OPTION_SURFACE[stateColor.value] ?? \"bg-muted\",\n);\nconst optionHover = computed(\n () => OPTION_HOVER[stateColor.value] ?? \"hover:bg-muted\",\n);\nconst CHECK_COLOR_BY_STATE: Record<string, string> = {\n default: \"text-foreground\",\n primary: \"text-primary\",\n danger: \"text-destructive\",\n success: \"text-success\",\n warning: \"text-warning\",\n};\nconst checkColorClass = computed(\n () => CHECK_COLOR_BY_STATE[stateColor.value] ?? \"text-foreground\",\n);\nconst affordanceIconClass = computed(\n () =>\n FIELD_AFFORDANCE_ICON_BY_COLOR[stateColor.value] ?? \"text-muted-foreground\",\n);\nconst affordanceActionClass = computed(\n () =>\n FIELD_AFFORDANCE_ACTION_BY_COLOR[stateColor.value] ??\n \"text-muted-foreground hover:text-foreground\",\n);\n\n// ── Size classes ──────────────────────────────────────────────────────────────\nconst wrapperHeightClass = computed(() => {\n // sz.value.padX is e.g. \"px-2.5\" — convert to pr-* for the wrapper right edge\n const pr = sz.value.padX.replace(\"px-\", \"pr-\");\n return `${sz.value.control} ${pr}`;\n});\n\nconst triggerPaddingClass = computed(() => {\n switch (resolvedSize.value) {\n case \"small\":\n return \"pl-2.5 pr-1.5 gap-1\";\n case \"large\":\n return \"pl-4 pr-2 gap-1.5\";\n default:\n return \"pl-3 pr-2 gap-1\";\n }\n});\n\nconst flagSizeClass = computed(() => {\n switch (resolvedSize.value) {\n case \"small\":\n return \"text-sm\";\n case \"large\":\n return \"text-xl\";\n default:\n return \"text-base\";\n }\n});\n\nconst triggerTextClass = computed(() => {\n switch (resolvedSize.value) {\n case \"small\":\n return \"text-[11px]\";\n case \"large\":\n return \"text-body\";\n default:\n return \"text-caption\";\n }\n});\n\nconst chevronSizeClass = computed(() => {\n switch (resolvedSize.value) {\n case \"small\":\n return \"w-3 h-3\";\n case \"large\":\n return \"w-4 h-4\";\n default:\n return \"w-3.5 h-3.5\";\n }\n});\n\nconst inputTextClass = computed(() => sz.value.text);\n\nconst inputPaddingClass = computed(() => {\n // pr-3 leaves a comfortable gap on the right edge as well; the\n // legacy showroom relied on the field-native default padding which\n // we override here. Without pl-3 numbers visually butt up against\n // the country trigger divider.\n return \"pl-3 pr-3\";\n});\n\n// ── Event handlers ────────────────────────────────────────────────────────────\nfunction onInput(e: Event) {\n const val = (e.target as HTMLInputElement).value;\n localNumber.value = val;\n emit(\"update:modelValue\", buildValue(val, selectedCountry.value?.dial ?? \"\"));\n}\n\nfunction onChange(e: Event) {\n const val = (e.target as HTMLInputElement).value;\n emit(\"change\", buildValue(val, selectedCountry.value?.dial ?? \"\"));\n}\n\nfunction selectCountry(c: PhoneCountry) {\n if (props.country === undefined) internalCountry.value = c.iso;\n emit(\"update:country\", c.iso);\n emit(\"update:modelValue\", buildValue(localNumber.value, c.dial));\n closePopover();\n nextTick(() => inputRef.value?.focus());\n}\n\nfunction onTriggerClick() {\n if (isDisabled.value || props.readonly) return;\n togglePopover();\n}\n\nfunction onTriggerKeydown(e: KeyboardEvent) {\n if (isDisabled.value || props.readonly) return;\n if (e.key === \"ArrowDown\" || e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n if (!isOpen.value) openPopover();\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n closePopover();\n }\n}\n\nfunction onSearchKeydown(e: KeyboardEvent) {\n const list = filteredCountries.value;\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n activeIndex.value = Math.min(activeIndex.value + 1, list.length - 1);\n scrollActiveIntoView();\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n activeIndex.value = Math.max(activeIndex.value - 1, 0);\n scrollActiveIntoView();\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n const c = list[activeIndex.value];\n if (c) selectCountry(c);\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n closePopover();\n triggerRef.value?.focus?.();\n } else if (e.key === \"Tab\") {\n closePopover();\n }\n}\n\nfunction scrollActiveIntoView() {\n nextTick(() => {\n const c = filteredCountries.value[activeIndex.value];\n if (!c || !listEl.value) return;\n const el = document.getElementById(optionId(c.iso));\n el?.scrollIntoView({ block: \"nearest\" });\n });\n}\n\n// ── Expose ────────────────────────────────────────────────────────────────────\ndefineExpose({\n focus: () => inputRef.value?.focus(),\n blur: () => inputRef.value?.blur(),\n inputRef,\n});\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuQA,MAAM,MAAM,sBAAA,eAAe;EAE3B,MAAM,OAAO;EAQb,MAAM,QAAQ;EAad,MAAM,eAAe,sBAAA,sBAAs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AA,YAAA,GAAA,GAAA,IAAA,oBAI3B,MALL,cAAA,GAAA,IAAA,kBAAA,GAAA,IAAA,OAIK,IAAG,CAAC,WAAW,UAAS,EAAA,EAAA,KAAA,GAAA,IAAA,oBAAA,IAAA,KAAA,IAAA,GAAA,IAAA,WAAA,KAAA,GAAA,GAAA,IAAA,oBAkCxB,IAAA,UAAA,OAAA,GAAA,IAAA,YA/Bc,kBAAA,QAAT,GAAG,MAAC;+DA+BT,MAAA;OA9BF,KAAK,EAAE;OACP,IAAI,SAAS,EAAE,IAAG;OACnB,MAAK;OACJ,iBAAe,EAAE,QAAQ,UAAA;OACzB,QAAA,GAAA,IAAA,gBAAK;;;4BAA+L,YAAA,MAAW;QAAiB,MAAM,YAAA,QAAc,cAAA,QAAa;QAAqB,EAAE,QAAQ,UAAA,QAAS,gBAAA;;OAOzS,iBAAY,WAAE,YAAA,QAAc;OAC5B,UAAK,WAAE,cAAc,EAAC;;mCAIhB,QAFP,cAAA,GAAA,IAAA,kBAAA,GAAA,IAAA,OACK,uBAAA,YAAW,CAAC,EAAE,IAAG,CAAA,EAAA,EAAA;mCAIb,QAFT,cAAA,GAAA,IAAA,iBACE,EAAE,KAAI,EAAA,EAAA;mCAMD,QAJP,aAEC,QAAA,GAAA,IAAA,iBACK,EAAE,KAAI,EAAA,EAAA;OAGJ,EAAE,QAAQ,UAAA,UAAA,GAAA,IAAA,YAAA,GAAA,GAAA,IAAA,cAAA,GAAA,IAAA,OAGhB,0BAAA,UAAA,EAAA;;QAFC,QAAA,GAAA,IAAA,gBAAK,CAAA,oBAAuB,gBAAA,MAAe,CAAA;QAC5C,eAAY"}
|
|
1
|
+
{"version":3,"file":"PhoneInput.vue_vue_type_script_setup_true_lang.cjs","names":["$emit"],"sources":["../../../src/components/forms/PhoneInput.vue"],"sourcesContent":["<template>\n <div :class=\"['flex flex-col gap-1.5', fullWidth ? 'w-full' : 'inline-flex']\">\n <!-- Label -->\n <label\n v-if=\"label\"\n :for=\"fieldId\"\n class=\"text-caption font-medium text-foreground\"\n >\n {{ label }}\n <span v-if=\"required\" aria-hidden=\"true\" class=\"text-destructive ml-0.5\"\n >*</span\n >\n </label>\n\n <!-- Unified field wrapper -->\n <div\n ref=\"wrapperEl\"\n :class=\"[\n 'modo-field-wrapper flex items-center overflow-hidden',\n wrapperVariantClasses,\n wrapperHeightClass,\n radiusClasses,\n fullWidth ? 'w-full' : '',\n isDisabled ? 'opacity-60 cursor-not-allowed' : '',\n ]\"\n >\n <!-- Country selector trigger -->\n <button\n ref=\"triggerRef\"\n type=\"button\"\n :disabled=\"isDisabled || readonly\"\n :aria-label=\"loc.phoneInput.selectCountry\"\n :aria-expanded=\"isOpen\"\n :aria-haspopup=\"'listbox'\"\n :class=\"[\n 'flex items-center self-stretch shrink-0 select-none',\n 'transition-colors duration-fast ease-standard',\n triggerPaddingClass,\n isDisabled || readonly ? 'cursor-not-allowed' : 'cursor-pointer',\n ]\"\n @click=\"onTriggerClick\"\n @keydown=\"onTriggerKeydown\"\n >\n <span\n aria-hidden=\"true\"\n :class=\"['leading-none shrink-0', flagSizeClass]\"\n >\n {{ selectedCountry ? countryFlag(selectedCountry.iso) : \"🌐\" }}\n </span>\n <span\n :class=\"[\n 'tabular-nums text-muted-foreground font-medium shrink-0',\n triggerTextClass,\n ]\"\n >\n +{{ selectedCountry?.dial ?? \"?\" }}\n </span>\n <ChevronDownIcon\n aria-hidden=\"true\"\n :class=\"[\n 'shrink-0 transition-transform duration-base ease-standard',\n affordanceIconClass,\n chevronSizeClass,\n isOpen ? 'rotate-180' : '',\n ]\"\n />\n </button>\n\n <!-- Vertical divider -->\n <div aria-hidden=\"true\" class=\"w-px self-stretch bg-border shrink-0\" />\n\n <!-- Phone number input -->\n <input\n :id=\"fieldId\"\n ref=\"inputRef\"\n type=\"tel\"\n inputmode=\"tel\"\n :value=\"localNumber\"\n :placeholder=\"placeholder ?? ''\"\n :disabled=\"isDisabled\"\n :readonly=\"readonly\"\n :required=\"required\"\n :name=\"name ? `${name}-local` : undefined\"\n :autocomplete=\"autocomplete ?? 'tel-national'\"\n :autofocus=\"autofocus\"\n :aria-label=\"!label ? (ariaLabel ?? undefined) : undefined\"\n :aria-invalid=\"hasError || undefined\"\n :aria-describedby=\"describedBy\"\n :aria-required=\"required || undefined\"\n :class=\"[\n 'modo-field-native flex-1 min-w-0 bg-transparent',\n 'text-foreground placeholder:text-muted-foreground',\n 'disabled:cursor-not-allowed',\n inputTextClass,\n inputPaddingClass,\n ]\"\n @input=\"onInput\"\n @change=\"onChange\"\n @focus=\"$emit('focus', $event)\"\n @blur=\"$emit('blur', $event)\"\n />\n\n <!-- Loading spinner -->\n <Loader\n v-if=\"loading\"\n :size=\"resolvedSize === 'large' ? 'medium' : 'small'\"\n :class=\"['shrink-0', affordanceIconClass]\"\n />\n </div>\n\n <!-- Hidden input carrying the full formatted value for form submission -->\n <input v-if=\"name\" type=\"hidden\" :name=\"name\" :value=\"currentFormValue\" />\n\n <!-- Error / helper text -->\n <div v-if=\"errorText || helperText\" class=\"flex items-start gap-2\">\n <Typography\n v-if=\"errorText\"\n :id=\"errorId\"\n variant=\"caption\"\n size=\"medium\"\n color=\"danger\"\n as=\"p\"\n >\n {{ errorText }}\n </Typography>\n <Typography\n v-else-if=\"helperText\"\n :id=\"helperId\"\n variant=\"caption\"\n size=\"medium\"\n color=\"muted\"\n as=\"p\"\n >\n {{ helperText }}\n </Typography>\n </div>\n\n <!-- Country dropdown -->\n <PopoverPanel\n :open=\"isOpen\"\n :style=\"mergedPanelStyle\"\n :radius=\"radius\"\n role=\"listbox\"\n :labelledBy=\"fieldId\"\n @update:panelRef=\"panelRef = $event\"\n >\n <div style=\"max-height: 296px\" class=\"flex flex-col\">\n <!-- Search input -->\n <div class=\"px-3 border-b border-border shrink-0\">\n <div class=\"flex items-center gap-2 h-7\">\n <MagnifyingGlassIcon\n class=\"w-4 h-4 shrink-0 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n <input\n ref=\"searchEl\"\n v-model=\"searchQuery\"\n type=\"text\"\n autocomplete=\"off\"\n spellcheck=\"false\"\n :placeholder=\"loc.phoneInput.searchCountry\"\n class=\"modo-field-native flex-1 min-w-0 bg-transparent p-0 text-caption text-foreground placeholder:text-muted-foreground\"\n @keydown=\"onSearchKeydown\"\n />\n <Button\n v-if=\"searchQuery\"\n variant=\"text\"\n size=\"xs\"\n radius=\"full\"\n :icon=\"XMarkIcon\"\n :ariaLabel=\"loc.common.clear\"\n tabindex=\"-1\"\n :class=\"['shrink-0', affordanceActionClass]\"\n @click=\"searchQuery = ''\"\n />\n </div>\n </div>\n\n <!-- Countries list -->\n <ul\n ref=\"listEl\"\n role=\"listbox\"\n class=\"modo-stagger flex-1 overflow-y-auto w-full\"\n style=\"min-height: 2.5rem\"\n tabindex=\"-1\"\n >\n <li\n v-if=\"filteredCountries.length === 0\"\n class=\"px-3 py-4 text-caption text-muted-foreground text-center\"\n >\n {{ loc.phoneInput.noResults }}\n </li>\n <li\n v-for=\"(c, i) in filteredCountries\"\n :key=\"c.iso\"\n :id=\"optionId(c.iso)\"\n role=\"option\"\n :aria-selected=\"c.iso === activeIso\"\n :class=\"[\n 'flex items-center gap-2.5 px-3 py-2 text-body cursor-pointer select-none',\n 'transition-colors duration-fast ease-standard',\n ['text-foreground', optionHover],\n i === activeIndex ? optionSurface : '',\n c.iso === activeIso ? 'font-medium' : '',\n ]\"\n @pointerenter=\"activeIndex = i\"\n @click=\"selectCountry(c)\"\n >\n <span aria-hidden=\"true\" class=\"text-base leading-none shrink-0\">\n {{ countryFlag(c.iso) }}\n </span>\n <span class=\"flex-1 min-w-0 truncate text-foreground\">{{\n c.name\n }}</span>\n <span\n class=\"shrink-0 tabular-nums text-muted-foreground text-[11px]\"\n >\n +{{ c.dial }}\n </span>\n <CheckIcon\n v-if=\"c.iso === activeIso\"\n :class=\"['w-4 h-4 shrink-0', checkColorClass]\"\n aria-hidden=\"true\"\n />\n </li>\n </ul>\n </div>\n </PopoverPanel>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { computed, nextTick, ref, useId, watch } from \"vue\";\nimport type { PhoneInput } from \"../../interfaces/forms/PhoneInput.interface\";\nimport {\n PHONE_COUNTRIES,\n countryFlag,\n findCountryByIso,\n type PhoneCountry,\n} from \"../../data/phoneCountries\";\nimport {\n useFieldState,\n useFieldClasses,\n FIELD_AFFORDANCE_ICON_BY_COLOR,\n FIELD_AFFORDANCE_ACTION_BY_COLOR,\n} from \"../../composables/useField\";\nimport { usePopover } from \"../../composables/usePopover\";\nimport {\n useResolvedSize,\n useSizeTokens,\n useModoLocale,\n} from \"../../composables/useModoConfig\";\nimport PopoverPanel from \"../layout/PopoverPanel.vue\";\nimport Typography from \"../data-display/Typography.vue\";\nimport Loader from \"../feedback/Loader.vue\";\nimport Button from \"./Button.vue\";\nimport {\n ChevronDownIcon,\n MagnifyingGlassIcon,\n XMarkIcon,\n CheckIcon,\n} from \"@heroicons/vue/24/outline\";\n\nconst loc = useModoLocale();\n\nconst emit = defineEmits<{\n \"update:modelValue\": [value: string];\n \"update:country\": [iso: string];\n change: [value: string];\n focus: [event: FocusEvent];\n blur: [event: FocusEvent];\n}>();\n\nconst props = withDefaults(defineProps<PhoneInput>(), {\n defaultCountry: \"US\",\n format: \"national\",\n variant: \"outline\",\n color: \"default\",\n disabled: false,\n readonly: false,\n required: false,\n loading: false,\n fullWidth: false,\n autofocus: false,\n});\n\nconst resolvedSize = useResolvedSize(() => props.size);\nconst sz = useSizeTokens(() => props.size);\n\n// ── Refs ──────────────────────────────────────────────────────────────────────\nconst inputRef = ref<HTMLInputElement | null>(null);\nconst searchEl = ref<HTMLInputElement | null>(null);\nconst listEl = ref<HTMLElement | null>(null);\nconst wrapperEl = ref<HTMLElement | null>(null);\nconst dropdownWidth = ref(\"\");\n\n// ── Internal state ────────────────────────────────────────────────────────────\nconst localNumber = ref(\"\");\nconst internalCountry = ref((props.defaultCountry ?? \"US\").toUpperCase());\n\n// ── Field state ───────────────────────────────────────────────────────────────\nconst {\n fieldId,\n radius,\n stateColor,\n hasError,\n isDisabled,\n errorId,\n helperId,\n describedBy,\n} = useFieldState(props, {\n componentName: \"PhoneInput\",\n idPrefix: \"modo-phone\",\n});\n\nconst { wrapperVariantClasses, radiusClasses } = useFieldClasses({\n variant: () => props.variant,\n stateColor,\n hasError,\n radius,\n forceFocus: () => isOpen.value,\n halo: () => props.halo,\n});\n\n// ── Country resolution ────────────────────────────────────────────────────────\nconst activeIso = computed(() =>\n (props.country !== undefined\n ? props.country\n : internalCountry.value\n ).toUpperCase(),\n);\nconst selectedCountry = computed(() => findCountryByIso(activeIso.value));\n\n// ── Format helpers ────────────────────────────────────────────────────────────\nfunction buildValue(local: string, dialCode: string): string {\n const fmt = props.format ?? \"national\";\n if (fmt === \"e164\") return `+${dialCode}${local.replace(/\\D/g, \"\")}`;\n if (fmt === \"international\") return `+${dialCode}${local}`;\n return local;\n}\n\nfunction extractNational(v: string | undefined, dialCode: string): string {\n if (!v) return \"\";\n const prefix = `+${dialCode}`;\n if (v.startsWith(prefix)) return v.slice(prefix.length);\n return v;\n}\n\nconst currentFormValue = computed(() =>\n selectedCountry.value\n ? buildValue(localNumber.value, selectedCountry.value.dial)\n : localNumber.value,\n);\n\n// Sync external modelValue → localNumber\nwatch(\n () => props.modelValue,\n (v) => {\n const dial = selectedCountry.value?.dial ?? \"\";\n const national = extractNational(v, dial);\n if (national !== localNumber.value) localNumber.value = national;\n },\n { immediate: true },\n);\n\n// ── Popover ───────────────────────────────────────────────────────────────────\nconst {\n triggerRef,\n panelRef,\n isOpen,\n panelStyle,\n open: openPopover,\n close: closePopover,\n toggle: togglePopover,\n} = usePopover({\n placement: \"bottom-start\",\n onOpen: () => {\n dropdownWidth.value = wrapperEl.value\n ? `${wrapperEl.value.getBoundingClientRect().width}px`\n : \"260px\";\n searchQuery.value = \"\";\n activeIndex.value = Math.max(\n 0,\n filteredCountries.value.findIndex((c) => c.iso === activeIso.value),\n );\n nextTick(() => {\n searchEl.value?.focus();\n scrollActiveIntoView();\n });\n },\n onClose: () => {\n searchQuery.value = \"\";\n activeIndex.value = -1;\n },\n});\n\nconst mergedPanelStyle = computed(() => ({\n ...panelStyle.value,\n ...(dropdownWidth.value ? { width: dropdownWidth.value } : {}),\n}));\n\n// ── Search + filtered list ────────────────────────────────────────────────────\nconst searchQuery = ref(\"\");\nconst activeIndex = ref(-1);\nconst autoListboxId = useId();\n\nconst optionId = (iso: string) =>\n `modo-phone-listbox-${autoListboxId}-opt-${iso}`;\n\nconst filteredCountries = computed<PhoneCountry[]>(() => {\n const q = searchQuery.value.trim().toLowerCase();\n if (!q) return PHONE_COUNTRIES as unknown as PhoneCountry[];\n return (PHONE_COUNTRIES as unknown as PhoneCountry[]).filter(\n (c) =>\n c.name.toLowerCase().includes(q) ||\n c.iso.toLowerCase().includes(q) ||\n c.dial.startsWith(q.replace(/^\\+/, \"\")),\n );\n});\n\nwatch(filteredCountries, (list) => {\n const idx = list.findIndex((c) => c.iso === activeIso.value);\n activeIndex.value = idx >= 0 ? idx : 0;\n});\n\n// ── Option styles ─────────────────────────────────────────────────────────────\nconst OPTION_SURFACE: Record<string, string> = {\n default: \"bg-muted\",\n primary: \"bg-primary/10\",\n danger: \"bg-destructive/10\",\n success: \"bg-success/10\",\n warning: \"bg-warning/10\",\n};\nconst OPTION_HOVER: Record<string, string> = {\n default: \"hover:bg-muted\",\n primary: \"hover:bg-primary/10\",\n danger: \"hover:bg-destructive/10\",\n success: \"hover:bg-success/10\",\n warning: \"hover:bg-warning/10\",\n};\nconst optionSurface = computed(\n () => OPTION_SURFACE[stateColor.value] ?? \"bg-muted\",\n);\nconst optionHover = computed(\n () => OPTION_HOVER[stateColor.value] ?? \"hover:bg-muted\",\n);\nconst CHECK_COLOR_BY_STATE: Record<string, string> = {\n default: \"text-foreground\",\n primary: \"text-primary\",\n danger: \"text-destructive\",\n success: \"text-success\",\n warning: \"text-warning\",\n};\nconst checkColorClass = computed(\n () => CHECK_COLOR_BY_STATE[stateColor.value] ?? \"text-foreground\",\n);\nconst affordanceIconClass = computed(\n () =>\n FIELD_AFFORDANCE_ICON_BY_COLOR[stateColor.value] ?? \"text-muted-foreground\",\n);\nconst affordanceActionClass = computed(\n () =>\n FIELD_AFFORDANCE_ACTION_BY_COLOR[stateColor.value] ??\n \"text-muted-foreground hover:text-foreground\",\n);\n\n// ── Size classes ──────────────────────────────────────────────────────────────\nconst wrapperHeightClass = computed(() => {\n // sz.value.padX is e.g. \"px-2.5\" — convert to pr-* for the wrapper right edge\n const pr = sz.value.padX.replace(\"px-\", \"pr-\");\n return `${sz.value.control} ${pr}`;\n});\n\nconst triggerPaddingClass = computed(() => {\n switch (resolvedSize.value) {\n case \"small\":\n return \"pl-2.5 pr-1.5 gap-1\";\n case \"large\":\n return \"pl-4 pr-2 gap-1.5\";\n default:\n return \"pl-3 pr-2 gap-1\";\n }\n});\n\nconst flagSizeClass = computed(() => {\n switch (resolvedSize.value) {\n case \"small\":\n return \"text-sm\";\n case \"large\":\n return \"text-xl\";\n default:\n return \"text-base\";\n }\n});\n\nconst triggerTextClass = computed(() => {\n switch (resolvedSize.value) {\n case \"small\":\n return \"text-[11px]\";\n case \"large\":\n return \"text-body\";\n default:\n return \"text-caption\";\n }\n});\n\nconst chevronSizeClass = computed(() => {\n switch (resolvedSize.value) {\n case \"small\":\n return \"w-3 h-3\";\n case \"large\":\n return \"w-4 h-4\";\n default:\n return \"w-3.5 h-3.5\";\n }\n});\n\nconst inputTextClass = computed(() => sz.value.text);\n\nconst inputPaddingClass = computed(() => {\n // pr-3 leaves a comfortable gap on the right edge as well; the\n // legacy showroom relied on the field-native default padding which\n // we override here. Without pl-3 numbers visually butt up against\n // the country trigger divider.\n return \"pl-3 pr-3\";\n});\n\n// ── Event handlers ────────────────────────────────────────────────────────────\nfunction onInput(e: Event) {\n const val = (e.target as HTMLInputElement).value;\n localNumber.value = val;\n emit(\"update:modelValue\", buildValue(val, selectedCountry.value?.dial ?? \"\"));\n}\n\nfunction onChange(e: Event) {\n const val = (e.target as HTMLInputElement).value;\n emit(\"change\", buildValue(val, selectedCountry.value?.dial ?? \"\"));\n}\n\nfunction selectCountry(c: PhoneCountry) {\n if (props.country === undefined) internalCountry.value = c.iso;\n emit(\"update:country\", c.iso);\n emit(\"update:modelValue\", buildValue(localNumber.value, c.dial));\n closePopover();\n nextTick(() => inputRef.value?.focus());\n}\n\nfunction onTriggerClick() {\n if (isDisabled.value || props.readonly) return;\n togglePopover();\n}\n\nfunction onTriggerKeydown(e: KeyboardEvent) {\n if (isDisabled.value || props.readonly) return;\n if (e.key === \"ArrowDown\" || e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n if (!isOpen.value) openPopover();\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n closePopover();\n }\n}\n\nfunction onSearchKeydown(e: KeyboardEvent) {\n const list = filteredCountries.value;\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n activeIndex.value = Math.min(activeIndex.value + 1, list.length - 1);\n scrollActiveIntoView();\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n activeIndex.value = Math.max(activeIndex.value - 1, 0);\n scrollActiveIntoView();\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n const c = list[activeIndex.value];\n if (c) selectCountry(c);\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n closePopover();\n triggerRef.value?.focus?.();\n } else if (e.key === \"Tab\") {\n // The search field lives inside a panel teleported to <body>, i.e. at the\n // very end of the document. Letting the browser resolve Tab from there\n // walks *past* the whole field — the number input sits earlier in the DOM\n // and is never reached — so focus landed on whatever followed the panel\n // while the panel was unmounting. Drive the destination explicitly:\n // forwards continues into the number input, backwards returns to the flag\n // trigger, which is the order the field reads in.\n e.preventDefault();\n closePopover();\n if (e.shiftKey) triggerRef.value?.focus?.();\n else inputRef.value?.focus();\n }\n}\n\nfunction scrollActiveIntoView() {\n nextTick(() => {\n const c = filteredCountries.value[activeIndex.value];\n if (!c || !listEl.value) return;\n const el = document.getElementById(optionId(c.iso));\n el?.scrollIntoView({ block: \"nearest\" });\n });\n}\n\n// ── Expose ────────────────────────────────────────────────────────────────────\ndefineExpose({\n focus: () => inputRef.value?.focus(),\n blur: () => inputRef.value?.blur(),\n inputRef,\n});\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuQA,MAAM,MAAM,sBAAA,eAAe;EAE3B,MAAM,OAAO;EAQb,MAAM,QAAQ;EAad,MAAM,eAAe,sBAAA,sBAAsB,MAAM,KAAK;EACtD,MAAM,KAAK,sBAAA,oBAAoB,MAAM,KAAK;EAG1C,MAAM,YAAA,GAAA,IAAA,KAAwC,KAAK;EACnD,MAAM,YAAA,GAAA,IAAA,KAAwC,KAAK;EACnD,MAAM,UAAA,GAAA,IAAA,KAAiC,KAAK;EAC5C,MAAM,aAAA,GAAA,IAAA,KAAoC,KAAK;EAC/C,MAAM,iBAAA,GAAA,IAAA,KAAoB,GAAG;EAG7B,MAAM,eAAA,GAAA,IAAA,KAAkB,GAAG;EAC3B,MAAM,mBAAA,GAAA,IAAA,MAAuB,MAAM,kBAAkB,MAAM,aAAa,CAAC;EAGzE,MAAM,EACJ,SACA,QACA,YACA,UACA,YACA,SACA,UACA,gBACE,iBAAA,cAAc,OAAO;GACvB,eAAe;GACf,UAAU;GACX,CAAC;EAEF,MAAM,EAAE,uBAAuB,kBAAkB,iBAAA,gBAAgB;GAC/D,eAAe,MAAM;GACrB;GACA;GACA;GACA,kBAAkB,OAAO;GACzB,YAAY,MAAM;GACnB,CAAC;EAGF,MAAM,aAAA,GAAA,IAAA,iBACH,MAAM,YAAY,KAAA,IACf,MAAM,UACN,gBAAgB,OAClB,aAAa,CAChB;EACD,MAAM,mBAAA,GAAA,IAAA,gBAAiC,uBAAA,iBAAiB,UAAU,MAAM,CAAC;EAGzE,SAAS,WAAW,OAAe,U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,EAAA;mCAMD,QAJP,aAEC,QAAA,GAAA,IAAA,iBACK,EAAE,KAAI,EAAA,EAAA;OAGJ,EAAE,QAAQ,UAAA,UAAA,GAAA,IAAA,YAAA,GAAA,GAAA,IAAA,cAAA,GAAA,IAAA,OAGhB,0BAAA,UAAA,EAAA;;QAFC,QAAA,GAAA,IAAA,gBAAK,CAAA,oBAAuB,gBAAA,MAAe,CAAA;QAC5C,eAAY"}
|
|
@@ -304,7 +304,12 @@ var PhoneInput_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ def
|
|
|
304
304
|
e.preventDefault();
|
|
305
305
|
closePopover();
|
|
306
306
|
triggerRef.value?.focus?.();
|
|
307
|
-
} else if (e.key === "Tab")
|
|
307
|
+
} else if (e.key === "Tab") {
|
|
308
|
+
e.preventDefault();
|
|
309
|
+
closePopover();
|
|
310
|
+
if (e.shiftKey) triggerRef.value?.focus?.();
|
|
311
|
+
else inputRef.value?.focus();
|
|
312
|
+
}
|
|
308
313
|
}
|
|
309
314
|
function scrollActiveIntoView() {
|
|
310
315
|
nextTick(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhoneInput.vue_vue_type_script_setup_true_lang.mjs","names":["$emit"],"sources":["../../../src/components/forms/PhoneInput.vue"],"sourcesContent":["<template>\n <div :class=\"['flex flex-col gap-1.5', fullWidth ? 'w-full' : 'inline-flex']\">\n <!-- Label -->\n <label\n v-if=\"label\"\n :for=\"fieldId\"\n class=\"text-caption font-medium text-foreground\"\n >\n {{ label }}\n <span v-if=\"required\" aria-hidden=\"true\" class=\"text-destructive ml-0.5\"\n >*</span\n >\n </label>\n\n <!-- Unified field wrapper -->\n <div\n ref=\"wrapperEl\"\n :class=\"[\n 'modo-field-wrapper flex items-center overflow-hidden',\n wrapperVariantClasses,\n wrapperHeightClass,\n radiusClasses,\n fullWidth ? 'w-full' : '',\n isDisabled ? 'opacity-60 cursor-not-allowed' : '',\n ]\"\n >\n <!-- Country selector trigger -->\n <button\n ref=\"triggerRef\"\n type=\"button\"\n :disabled=\"isDisabled || readonly\"\n :aria-label=\"loc.phoneInput.selectCountry\"\n :aria-expanded=\"isOpen\"\n :aria-haspopup=\"'listbox'\"\n :class=\"[\n 'flex items-center self-stretch shrink-0 select-none',\n 'transition-colors duration-fast ease-standard',\n triggerPaddingClass,\n isDisabled || readonly ? 'cursor-not-allowed' : 'cursor-pointer',\n ]\"\n @click=\"onTriggerClick\"\n @keydown=\"onTriggerKeydown\"\n >\n <span\n aria-hidden=\"true\"\n :class=\"['leading-none shrink-0', flagSizeClass]\"\n >\n {{ selectedCountry ? countryFlag(selectedCountry.iso) : \"🌐\" }}\n </span>\n <span\n :class=\"[\n 'tabular-nums text-muted-foreground font-medium shrink-0',\n triggerTextClass,\n ]\"\n >\n +{{ selectedCountry?.dial ?? \"?\" }}\n </span>\n <ChevronDownIcon\n aria-hidden=\"true\"\n :class=\"[\n 'shrink-0 transition-transform duration-base ease-standard',\n affordanceIconClass,\n chevronSizeClass,\n isOpen ? 'rotate-180' : '',\n ]\"\n />\n </button>\n\n <!-- Vertical divider -->\n <div aria-hidden=\"true\" class=\"w-px self-stretch bg-border shrink-0\" />\n\n <!-- Phone number input -->\n <input\n :id=\"fieldId\"\n ref=\"inputRef\"\n type=\"tel\"\n inputmode=\"tel\"\n :value=\"localNumber\"\n :placeholder=\"placeholder ?? ''\"\n :disabled=\"isDisabled\"\n :readonly=\"readonly\"\n :required=\"required\"\n :name=\"name ? `${name}-local` : undefined\"\n :autocomplete=\"autocomplete ?? 'tel-national'\"\n :autofocus=\"autofocus\"\n :aria-label=\"!label ? (ariaLabel ?? undefined) : undefined\"\n :aria-invalid=\"hasError || undefined\"\n :aria-describedby=\"describedBy\"\n :aria-required=\"required || undefined\"\n :class=\"[\n 'modo-field-native flex-1 min-w-0 bg-transparent',\n 'text-foreground placeholder:text-muted-foreground',\n 'disabled:cursor-not-allowed',\n inputTextClass,\n inputPaddingClass,\n ]\"\n @input=\"onInput\"\n @change=\"onChange\"\n @focus=\"$emit('focus', $event)\"\n @blur=\"$emit('blur', $event)\"\n />\n\n <!-- Loading spinner -->\n <Loader\n v-if=\"loading\"\n :size=\"resolvedSize === 'large' ? 'medium' : 'small'\"\n :class=\"['shrink-0', affordanceIconClass]\"\n />\n </div>\n\n <!-- Hidden input carrying the full formatted value for form submission -->\n <input v-if=\"name\" type=\"hidden\" :name=\"name\" :value=\"currentFormValue\" />\n\n <!-- Error / helper text -->\n <div v-if=\"errorText || helperText\" class=\"flex items-start gap-2\">\n <Typography\n v-if=\"errorText\"\n :id=\"errorId\"\n variant=\"caption\"\n size=\"medium\"\n color=\"danger\"\n as=\"p\"\n >\n {{ errorText }}\n </Typography>\n <Typography\n v-else-if=\"helperText\"\n :id=\"helperId\"\n variant=\"caption\"\n size=\"medium\"\n color=\"muted\"\n as=\"p\"\n >\n {{ helperText }}\n </Typography>\n </div>\n\n <!-- Country dropdown -->\n <PopoverPanel\n :open=\"isOpen\"\n :style=\"mergedPanelStyle\"\n :radius=\"radius\"\n role=\"listbox\"\n :labelledBy=\"fieldId\"\n @update:panelRef=\"panelRef = $event\"\n >\n <div style=\"max-height: 296px\" class=\"flex flex-col\">\n <!-- Search input -->\n <div class=\"px-3 border-b border-border shrink-0\">\n <div class=\"flex items-center gap-2 h-7\">\n <MagnifyingGlassIcon\n class=\"w-4 h-4 shrink-0 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n <input\n ref=\"searchEl\"\n v-model=\"searchQuery\"\n type=\"text\"\n autocomplete=\"off\"\n spellcheck=\"false\"\n :placeholder=\"loc.phoneInput.searchCountry\"\n class=\"modo-field-native flex-1 min-w-0 bg-transparent p-0 text-caption text-foreground placeholder:text-muted-foreground\"\n @keydown=\"onSearchKeydown\"\n />\n <Button\n v-if=\"searchQuery\"\n variant=\"text\"\n size=\"xs\"\n radius=\"full\"\n :icon=\"XMarkIcon\"\n :ariaLabel=\"loc.common.clear\"\n tabindex=\"-1\"\n :class=\"['shrink-0', affordanceActionClass]\"\n @click=\"searchQuery = ''\"\n />\n </div>\n </div>\n\n <!-- Countries list -->\n <ul\n ref=\"listEl\"\n role=\"listbox\"\n class=\"modo-stagger flex-1 overflow-y-auto w-full\"\n style=\"min-height: 2.5rem\"\n tabindex=\"-1\"\n >\n <li\n v-if=\"filteredCountries.length === 0\"\n class=\"px-3 py-4 text-caption text-muted-foreground text-center\"\n >\n {{ loc.phoneInput.noResults }}\n </li>\n <li\n v-for=\"(c, i) in filteredCountries\"\n :key=\"c.iso\"\n :id=\"optionId(c.iso)\"\n role=\"option\"\n :aria-selected=\"c.iso === activeIso\"\n :class=\"[\n 'flex items-center gap-2.5 px-3 py-2 text-body cursor-pointer select-none',\n 'transition-colors duration-fast ease-standard',\n ['text-foreground', optionHover],\n i === activeIndex ? optionSurface : '',\n c.iso === activeIso ? 'font-medium' : '',\n ]\"\n @pointerenter=\"activeIndex = i\"\n @click=\"selectCountry(c)\"\n >\n <span aria-hidden=\"true\" class=\"text-base leading-none shrink-0\">\n {{ countryFlag(c.iso) }}\n </span>\n <span class=\"flex-1 min-w-0 truncate text-foreground\">{{\n c.name\n }}</span>\n <span\n class=\"shrink-0 tabular-nums text-muted-foreground text-[11px]\"\n >\n +{{ c.dial }}\n </span>\n <CheckIcon\n v-if=\"c.iso === activeIso\"\n :class=\"['w-4 h-4 shrink-0', checkColorClass]\"\n aria-hidden=\"true\"\n />\n </li>\n </ul>\n </div>\n </PopoverPanel>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { computed, nextTick, ref, useId, watch } from \"vue\";\nimport type { PhoneInput } from \"../../interfaces/forms/PhoneInput.interface\";\nimport {\n PHONE_COUNTRIES,\n countryFlag,\n findCountryByIso,\n type PhoneCountry,\n} from \"../../data/phoneCountries\";\nimport {\n useFieldState,\n useFieldClasses,\n FIELD_AFFORDANCE_ICON_BY_COLOR,\n FIELD_AFFORDANCE_ACTION_BY_COLOR,\n} from \"../../composables/useField\";\nimport { usePopover } from \"../../composables/usePopover\";\nimport {\n useResolvedSize,\n useSizeTokens,\n useModoLocale,\n} from \"../../composables/useModoConfig\";\nimport PopoverPanel from \"../layout/PopoverPanel.vue\";\nimport Typography from \"../data-display/Typography.vue\";\nimport Loader from \"../feedback/Loader.vue\";\nimport Button from \"./Button.vue\";\nimport {\n ChevronDownIcon,\n MagnifyingGlassIcon,\n XMarkIcon,\n CheckIcon,\n} from \"@heroicons/vue/24/outline\";\n\nconst loc = useModoLocale();\n\nconst emit = defineEmits<{\n \"update:modelValue\": [value: string];\n \"update:country\": [iso: string];\n change: [value: string];\n focus: [event: FocusEvent];\n blur: [event: FocusEvent];\n}>();\n\nconst props = withDefaults(defineProps<PhoneInput>(), {\n defaultCountry: \"US\",\n format: \"national\",\n variant: \"outline\",\n color: \"default\",\n disabled: false,\n readonly: false,\n required: false,\n loading: false,\n fullWidth: false,\n autofocus: false,\n});\n\nconst resolvedSize = useResolvedSize(() => props.size);\nconst sz = useSizeTokens(() => props.size);\n\n// ── Refs ──────────────────────────────────────────────────────────────────────\nconst inputRef = ref<HTMLInputElement | null>(null);\nconst searchEl = ref<HTMLInputElement | null>(null);\nconst listEl = ref<HTMLElement | null>(null);\nconst wrapperEl = ref<HTMLElement | null>(null);\nconst dropdownWidth = ref(\"\");\n\n// ── Internal state ────────────────────────────────────────────────────────────\nconst localNumber = ref(\"\");\nconst internalCountry = ref((props.defaultCountry ?? \"US\").toUpperCase());\n\n// ── Field state ───────────────────────────────────────────────────────────────\nconst {\n fieldId,\n radius,\n stateColor,\n hasError,\n isDisabled,\n errorId,\n helperId,\n describedBy,\n} = useFieldState(props, {\n componentName: \"PhoneInput\",\n idPrefix: \"modo-phone\",\n});\n\nconst { wrapperVariantClasses, radiusClasses } = useFieldClasses({\n variant: () => props.variant,\n stateColor,\n hasError,\n radius,\n forceFocus: () => isOpen.value,\n halo: () => props.halo,\n});\n\n// ── Country resolution ────────────────────────────────────────────────────────\nconst activeIso = computed(() =>\n (props.country !== undefined\n ? props.country\n : internalCountry.value\n ).toUpperCase(),\n);\nconst selectedCountry = computed(() => findCountryByIso(activeIso.value));\n\n// ── Format helpers ────────────────────────────────────────────────────────────\nfunction buildValue(local: string, dialCode: string): string {\n const fmt = props.format ?? \"national\";\n if (fmt === \"e164\") return `+${dialCode}${local.replace(/\\D/g, \"\")}`;\n if (fmt === \"international\") return `+${dialCode}${local}`;\n return local;\n}\n\nfunction extractNational(v: string | undefined, dialCode: string): string {\n if (!v) return \"\";\n const prefix = `+${dialCode}`;\n if (v.startsWith(prefix)) return v.slice(prefix.length);\n return v;\n}\n\nconst currentFormValue = computed(() =>\n selectedCountry.value\n ? buildValue(localNumber.value, selectedCountry.value.dial)\n : localNumber.value,\n);\n\n// Sync external modelValue → localNumber\nwatch(\n () => props.modelValue,\n (v) => {\n const dial = selectedCountry.value?.dial ?? \"\";\n const national = extractNational(v, dial);\n if (national !== localNumber.value) localNumber.value = national;\n },\n { immediate: true },\n);\n\n// ── Popover ───────────────────────────────────────────────────────────────────\nconst {\n triggerRef,\n panelRef,\n isOpen,\n panelStyle,\n open: openPopover,\n close: closePopover,\n toggle: togglePopover,\n} = usePopover({\n placement: \"bottom-start\",\n onOpen: () => {\n dropdownWidth.value = wrapperEl.value\n ? `${wrapperEl.value.getBoundingClientRect().width}px`\n : \"260px\";\n searchQuery.value = \"\";\n activeIndex.value = Math.max(\n 0,\n filteredCountries.value.findIndex((c) => c.iso === activeIso.value),\n );\n nextTick(() => {\n searchEl.value?.focus();\n scrollActiveIntoView();\n });\n },\n onClose: () => {\n searchQuery.value = \"\";\n activeIndex.value = -1;\n },\n});\n\nconst mergedPanelStyle = computed(() => ({\n ...panelStyle.value,\n ...(dropdownWidth.value ? { width: dropdownWidth.value } : {}),\n}));\n\n// ── Search + filtered list ────────────────────────────────────────────────────\nconst searchQuery = ref(\"\");\nconst activeIndex = ref(-1);\nconst autoListboxId = useId();\n\nconst optionId = (iso: string) =>\n `modo-phone-listbox-${autoListboxId}-opt-${iso}`;\n\nconst filteredCountries = computed<PhoneCountry[]>(() => {\n const q = searchQuery.value.trim().toLowerCase();\n if (!q) return PHONE_COUNTRIES as unknown as PhoneCountry[];\n return (PHONE_COUNTRIES as unknown as PhoneCountry[]).filter(\n (c) =>\n c.name.toLowerCase().includes(q) ||\n c.iso.toLowerCase().includes(q) ||\n c.dial.startsWith(q.replace(/^\\+/, \"\")),\n );\n});\n\nwatch(filteredCountries, (list) => {\n const idx = list.findIndex((c) => c.iso === activeIso.value);\n activeIndex.value = idx >= 0 ? idx : 0;\n});\n\n// ── Option styles ─────────────────────────────────────────────────────────────\nconst OPTION_SURFACE: Record<string, string> = {\n default: \"bg-muted\",\n primary: \"bg-primary/10\",\n danger: \"bg-destructive/10\",\n success: \"bg-success/10\",\n warning: \"bg-warning/10\",\n};\nconst OPTION_HOVER: Record<string, string> = {\n default: \"hover:bg-muted\",\n primary: \"hover:bg-primary/10\",\n danger: \"hover:bg-destructive/10\",\n success: \"hover:bg-success/10\",\n warning: \"hover:bg-warning/10\",\n};\nconst optionSurface = computed(\n () => OPTION_SURFACE[stateColor.value] ?? \"bg-muted\",\n);\nconst optionHover = computed(\n () => OPTION_HOVER[stateColor.value] ?? \"hover:bg-muted\",\n);\nconst CHECK_COLOR_BY_STATE: Record<string, string> = {\n default: \"text-foreground\",\n primary: \"text-primary\",\n danger: \"text-destructive\",\n success: \"text-success\",\n warning: \"text-warning\",\n};\nconst checkColorClass = computed(\n () => CHECK_COLOR_BY_STATE[stateColor.value] ?? \"text-foreground\",\n);\nconst affordanceIconClass = computed(\n () =>\n FIELD_AFFORDANCE_ICON_BY_COLOR[stateColor.value] ?? \"text-muted-foreground\",\n);\nconst affordanceActionClass = computed(\n () =>\n FIELD_AFFORDANCE_ACTION_BY_COLOR[stateColor.value] ??\n \"text-muted-foreground hover:text-foreground\",\n);\n\n// ── Size classes ──────────────────────────────────────────────────────────────\nconst wrapperHeightClass = computed(() => {\n // sz.value.padX is e.g. \"px-2.5\" — convert to pr-* for the wrapper right edge\n const pr = sz.value.padX.replace(\"px-\", \"pr-\");\n return `${sz.value.control} ${pr}`;\n});\n\nconst triggerPaddingClass = computed(() => {\n switch (resolvedSize.value) {\n case \"small\":\n return \"pl-2.5 pr-1.5 gap-1\";\n case \"large\":\n return \"pl-4 pr-2 gap-1.5\";\n default:\n return \"pl-3 pr-2 gap-1\";\n }\n});\n\nconst flagSizeClass = computed(() => {\n switch (resolvedSize.value) {\n case \"small\":\n return \"text-sm\";\n case \"large\":\n return \"text-xl\";\n default:\n return \"text-base\";\n }\n});\n\nconst triggerTextClass = computed(() => {\n switch (resolvedSize.value) {\n case \"small\":\n return \"text-[11px]\";\n case \"large\":\n return \"text-body\";\n default:\n return \"text-caption\";\n }\n});\n\nconst chevronSizeClass = computed(() => {\n switch (resolvedSize.value) {\n case \"small\":\n return \"w-3 h-3\";\n case \"large\":\n return \"w-4 h-4\";\n default:\n return \"w-3.5 h-3.5\";\n }\n});\n\nconst inputTextClass = computed(() => sz.value.text);\n\nconst inputPaddingClass = computed(() => {\n // pr-3 leaves a comfortable gap on the right edge as well; the\n // legacy showroom relied on the field-native default padding which\n // we override here. Without pl-3 numbers visually butt up against\n // the country trigger divider.\n return \"pl-3 pr-3\";\n});\n\n// ── Event handlers ────────────────────────────────────────────────────────────\nfunction onInput(e: Event) {\n const val = (e.target as HTMLInputElement).value;\n localNumber.value = val;\n emit(\"update:modelValue\", buildValue(val, selectedCountry.value?.dial ?? \"\"));\n}\n\nfunction onChange(e: Event) {\n const val = (e.target as HTMLInputElement).value;\n emit(\"change\", buildValue(val, selectedCountry.value?.dial ?? \"\"));\n}\n\nfunction selectCountry(c: PhoneCountry) {\n if (props.country === undefined) internalCountry.value = c.iso;\n emit(\"update:country\", c.iso);\n emit(\"update:modelValue\", buildValue(localNumber.value, c.dial));\n closePopover();\n nextTick(() => inputRef.value?.focus());\n}\n\nfunction onTriggerClick() {\n if (isDisabled.value || props.readonly) return;\n togglePopover();\n}\n\nfunction onTriggerKeydown(e: KeyboardEvent) {\n if (isDisabled.value || props.readonly) return;\n if (e.key === \"ArrowDown\" || e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n if (!isOpen.value) openPopover();\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n closePopover();\n }\n}\n\nfunction onSearchKeydown(e: KeyboardEvent) {\n const list = filteredCountries.value;\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n activeIndex.value = Math.min(activeIndex.value + 1, list.length - 1);\n scrollActiveIntoView();\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n activeIndex.value = Math.max(activeIndex.value - 1, 0);\n scrollActiveIntoView();\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n const c = list[activeIndex.value];\n if (c) selectCountry(c);\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n closePopover();\n triggerRef.value?.focus?.();\n } else if (e.key === \"Tab\") {\n closePopover();\n }\n}\n\nfunction scrollActiveIntoView() {\n nextTick(() => {\n const c = filteredCountries.value[activeIndex.value];\n if (!c || !listEl.value) return;\n const el = document.getElementById(optionId(c.iso));\n el?.scrollIntoView({ block: \"nearest\" });\n });\n}\n\n// ── Expose ────────────────────────────────────────────────────────────────────\ndefineExpose({\n focus: () => inputRef.value?.focus(),\n blur: () => inputRef.value?.blur(),\n inputRef,\n});\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuQA,MAAM,MAAM,eAAe;EAE3B,MAAM,OAAO;EAQb,MAAM,QAAQ;EAad,MAAM,eAAe,sBAAsB,MAAM,KAAK;EACtD,MAAM,KAAK,oBAAoB,MAAM,KAAK;EAG1C,MAAM,WAAW,IAA6B,KAAK;EACnD,MAAM,WAAW,IAA6B,KAAK;EACnD,MAAM,SAAS,IAAwB,KAAK;EAC5C,MAAM,YAAY,IAAwB,KAAK;EAC/C,MAAM,gBAAgB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EAAA,IAAA,mBAAA,IAAA,KAAA,GAAA,UAAA,KAAA,EAE7B,mBAgCK,UAAA,MAAA,WA/Bc,kBAAA,QAAT,GAAG,MAAC;0BADd,mBAgCK,MAAA;OA9BF,KAAK,EAAE;OACP,IAAI,SAAS,EAAE,IAAG;OACnB,MAAK;OACJ,iBAAe,EAAE,QAAQ,UAAA;OACzB,OAAK,eAAA;;;4BAA+L,YAAA,MAAW;QAAiB,MAAM,YAAA,QAAc,cAAA,QAAa;QAAqB,EAAE,QAAQ,UAAA,QAAS,gBAAA;;OAOzS,iBAAY,WAAE,YAAA,QAAc;OAC5B,UAAK,WAAE,cAAc,EAAC;;OAEvB,mBAEO,QAFP,aAEO,gBADF,MAAA,YAAW,CAAC,EAAE,IAAG,CAAA,EAAA,EAAA;OAEtB,mBAES,QAFT,aAES,gBADP,EAAE,KAAI,EAAA,EAAA;OAER,mBAIO,QAJP,aAEC,OACE,gBAAG,EAAE,KAAI,EAAA,EAAA;OAGJ,EAAE,QAAQ,UAAA,SAAA,WAAA,EADlB,YAIE,MAAA,UAAA,EAAA;;QAFC,OAAK,eAAA,CAAA,oBAAuB,gBAAA,MAAe,CAAA;QAC5C,eAAY"}
|
|
1
|
+
{"version":3,"file":"PhoneInput.vue_vue_type_script_setup_true_lang.mjs","names":["$emit"],"sources":["../../../src/components/forms/PhoneInput.vue"],"sourcesContent":["<template>\n <div :class=\"['flex flex-col gap-1.5', fullWidth ? 'w-full' : 'inline-flex']\">\n <!-- Label -->\n <label\n v-if=\"label\"\n :for=\"fieldId\"\n class=\"text-caption font-medium text-foreground\"\n >\n {{ label }}\n <span v-if=\"required\" aria-hidden=\"true\" class=\"text-destructive ml-0.5\"\n >*</span\n >\n </label>\n\n <!-- Unified field wrapper -->\n <div\n ref=\"wrapperEl\"\n :class=\"[\n 'modo-field-wrapper flex items-center overflow-hidden',\n wrapperVariantClasses,\n wrapperHeightClass,\n radiusClasses,\n fullWidth ? 'w-full' : '',\n isDisabled ? 'opacity-60 cursor-not-allowed' : '',\n ]\"\n >\n <!-- Country selector trigger -->\n <button\n ref=\"triggerRef\"\n type=\"button\"\n :disabled=\"isDisabled || readonly\"\n :aria-label=\"loc.phoneInput.selectCountry\"\n :aria-expanded=\"isOpen\"\n :aria-haspopup=\"'listbox'\"\n :class=\"[\n 'flex items-center self-stretch shrink-0 select-none',\n 'transition-colors duration-fast ease-standard',\n triggerPaddingClass,\n isDisabled || readonly ? 'cursor-not-allowed' : 'cursor-pointer',\n ]\"\n @click=\"onTriggerClick\"\n @keydown=\"onTriggerKeydown\"\n >\n <span\n aria-hidden=\"true\"\n :class=\"['leading-none shrink-0', flagSizeClass]\"\n >\n {{ selectedCountry ? countryFlag(selectedCountry.iso) : \"🌐\" }}\n </span>\n <span\n :class=\"[\n 'tabular-nums text-muted-foreground font-medium shrink-0',\n triggerTextClass,\n ]\"\n >\n +{{ selectedCountry?.dial ?? \"?\" }}\n </span>\n <ChevronDownIcon\n aria-hidden=\"true\"\n :class=\"[\n 'shrink-0 transition-transform duration-base ease-standard',\n affordanceIconClass,\n chevronSizeClass,\n isOpen ? 'rotate-180' : '',\n ]\"\n />\n </button>\n\n <!-- Vertical divider -->\n <div aria-hidden=\"true\" class=\"w-px self-stretch bg-border shrink-0\" />\n\n <!-- Phone number input -->\n <input\n :id=\"fieldId\"\n ref=\"inputRef\"\n type=\"tel\"\n inputmode=\"tel\"\n :value=\"localNumber\"\n :placeholder=\"placeholder ?? ''\"\n :disabled=\"isDisabled\"\n :readonly=\"readonly\"\n :required=\"required\"\n :name=\"name ? `${name}-local` : undefined\"\n :autocomplete=\"autocomplete ?? 'tel-national'\"\n :autofocus=\"autofocus\"\n :aria-label=\"!label ? (ariaLabel ?? undefined) : undefined\"\n :aria-invalid=\"hasError || undefined\"\n :aria-describedby=\"describedBy\"\n :aria-required=\"required || undefined\"\n :class=\"[\n 'modo-field-native flex-1 min-w-0 bg-transparent',\n 'text-foreground placeholder:text-muted-foreground',\n 'disabled:cursor-not-allowed',\n inputTextClass,\n inputPaddingClass,\n ]\"\n @input=\"onInput\"\n @change=\"onChange\"\n @focus=\"$emit('focus', $event)\"\n @blur=\"$emit('blur', $event)\"\n />\n\n <!-- Loading spinner -->\n <Loader\n v-if=\"loading\"\n :size=\"resolvedSize === 'large' ? 'medium' : 'small'\"\n :class=\"['shrink-0', affordanceIconClass]\"\n />\n </div>\n\n <!-- Hidden input carrying the full formatted value for form submission -->\n <input v-if=\"name\" type=\"hidden\" :name=\"name\" :value=\"currentFormValue\" />\n\n <!-- Error / helper text -->\n <div v-if=\"errorText || helperText\" class=\"flex items-start gap-2\">\n <Typography\n v-if=\"errorText\"\n :id=\"errorId\"\n variant=\"caption\"\n size=\"medium\"\n color=\"danger\"\n as=\"p\"\n >\n {{ errorText }}\n </Typography>\n <Typography\n v-else-if=\"helperText\"\n :id=\"helperId\"\n variant=\"caption\"\n size=\"medium\"\n color=\"muted\"\n as=\"p\"\n >\n {{ helperText }}\n </Typography>\n </div>\n\n <!-- Country dropdown -->\n <PopoverPanel\n :open=\"isOpen\"\n :style=\"mergedPanelStyle\"\n :radius=\"radius\"\n role=\"listbox\"\n :labelledBy=\"fieldId\"\n @update:panelRef=\"panelRef = $event\"\n >\n <div style=\"max-height: 296px\" class=\"flex flex-col\">\n <!-- Search input -->\n <div class=\"px-3 border-b border-border shrink-0\">\n <div class=\"flex items-center gap-2 h-7\">\n <MagnifyingGlassIcon\n class=\"w-4 h-4 shrink-0 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n <input\n ref=\"searchEl\"\n v-model=\"searchQuery\"\n type=\"text\"\n autocomplete=\"off\"\n spellcheck=\"false\"\n :placeholder=\"loc.phoneInput.searchCountry\"\n class=\"modo-field-native flex-1 min-w-0 bg-transparent p-0 text-caption text-foreground placeholder:text-muted-foreground\"\n @keydown=\"onSearchKeydown\"\n />\n <Button\n v-if=\"searchQuery\"\n variant=\"text\"\n size=\"xs\"\n radius=\"full\"\n :icon=\"XMarkIcon\"\n :ariaLabel=\"loc.common.clear\"\n tabindex=\"-1\"\n :class=\"['shrink-0', affordanceActionClass]\"\n @click=\"searchQuery = ''\"\n />\n </div>\n </div>\n\n <!-- Countries list -->\n <ul\n ref=\"listEl\"\n role=\"listbox\"\n class=\"modo-stagger flex-1 overflow-y-auto w-full\"\n style=\"min-height: 2.5rem\"\n tabindex=\"-1\"\n >\n <li\n v-if=\"filteredCountries.length === 0\"\n class=\"px-3 py-4 text-caption text-muted-foreground text-center\"\n >\n {{ loc.phoneInput.noResults }}\n </li>\n <li\n v-for=\"(c, i) in filteredCountries\"\n :key=\"c.iso\"\n :id=\"optionId(c.iso)\"\n role=\"option\"\n :aria-selected=\"c.iso === activeIso\"\n :class=\"[\n 'flex items-center gap-2.5 px-3 py-2 text-body cursor-pointer select-none',\n 'transition-colors duration-fast ease-standard',\n ['text-foreground', optionHover],\n i === activeIndex ? optionSurface : '',\n c.iso === activeIso ? 'font-medium' : '',\n ]\"\n @pointerenter=\"activeIndex = i\"\n @click=\"selectCountry(c)\"\n >\n <span aria-hidden=\"true\" class=\"text-base leading-none shrink-0\">\n {{ countryFlag(c.iso) }}\n </span>\n <span class=\"flex-1 min-w-0 truncate text-foreground\">{{\n c.name\n }}</span>\n <span\n class=\"shrink-0 tabular-nums text-muted-foreground text-[11px]\"\n >\n +{{ c.dial }}\n </span>\n <CheckIcon\n v-if=\"c.iso === activeIso\"\n :class=\"['w-4 h-4 shrink-0', checkColorClass]\"\n aria-hidden=\"true\"\n />\n </li>\n </ul>\n </div>\n </PopoverPanel>\n </div>\n</template>\n\n<script setup lang=\"ts\">\nimport { computed, nextTick, ref, useId, watch } from \"vue\";\nimport type { PhoneInput } from \"../../interfaces/forms/PhoneInput.interface\";\nimport {\n PHONE_COUNTRIES,\n countryFlag,\n findCountryByIso,\n type PhoneCountry,\n} from \"../../data/phoneCountries\";\nimport {\n useFieldState,\n useFieldClasses,\n FIELD_AFFORDANCE_ICON_BY_COLOR,\n FIELD_AFFORDANCE_ACTION_BY_COLOR,\n} from \"../../composables/useField\";\nimport { usePopover } from \"../../composables/usePopover\";\nimport {\n useResolvedSize,\n useSizeTokens,\n useModoLocale,\n} from \"../../composables/useModoConfig\";\nimport PopoverPanel from \"../layout/PopoverPanel.vue\";\nimport Typography from \"../data-display/Typography.vue\";\nimport Loader from \"../feedback/Loader.vue\";\nimport Button from \"./Button.vue\";\nimport {\n ChevronDownIcon,\n MagnifyingGlassIcon,\n XMarkIcon,\n CheckIcon,\n} from \"@heroicons/vue/24/outline\";\n\nconst loc = useModoLocale();\n\nconst emit = defineEmits<{\n \"update:modelValue\": [value: string];\n \"update:country\": [iso: string];\n change: [value: string];\n focus: [event: FocusEvent];\n blur: [event: FocusEvent];\n}>();\n\nconst props = withDefaults(defineProps<PhoneInput>(), {\n defaultCountry: \"US\",\n format: \"national\",\n variant: \"outline\",\n color: \"default\",\n disabled: false,\n readonly: false,\n required: false,\n loading: false,\n fullWidth: false,\n autofocus: false,\n});\n\nconst resolvedSize = useResolvedSize(() => props.size);\nconst sz = useSizeTokens(() => props.size);\n\n// ── Refs ──────────────────────────────────────────────────────────────────────\nconst inputRef = ref<HTMLInputElement | null>(null);\nconst searchEl = ref<HTMLInputElement | null>(null);\nconst listEl = ref<HTMLElement | null>(null);\nconst wrapperEl = ref<HTMLElement | null>(null);\nconst dropdownWidth = ref(\"\");\n\n// ── Internal state ────────────────────────────────────────────────────────────\nconst localNumber = ref(\"\");\nconst internalCountry = ref((props.defaultCountry ?? \"US\").toUpperCase());\n\n// ── Field state ───────────────────────────────────────────────────────────────\nconst {\n fieldId,\n radius,\n stateColor,\n hasError,\n isDisabled,\n errorId,\n helperId,\n describedBy,\n} = useFieldState(props, {\n componentName: \"PhoneInput\",\n idPrefix: \"modo-phone\",\n});\n\nconst { wrapperVariantClasses, radiusClasses } = useFieldClasses({\n variant: () => props.variant,\n stateColor,\n hasError,\n radius,\n forceFocus: () => isOpen.value,\n halo: () => props.halo,\n});\n\n// ── Country resolution ────────────────────────────────────────────────────────\nconst activeIso = computed(() =>\n (props.country !== undefined\n ? props.country\n : internalCountry.value\n ).toUpperCase(),\n);\nconst selectedCountry = computed(() => findCountryByIso(activeIso.value));\n\n// ── Format helpers ────────────────────────────────────────────────────────────\nfunction buildValue(local: string, dialCode: string): string {\n const fmt = props.format ?? \"national\";\n if (fmt === \"e164\") return `+${dialCode}${local.replace(/\\D/g, \"\")}`;\n if (fmt === \"international\") return `+${dialCode}${local}`;\n return local;\n}\n\nfunction extractNational(v: string | undefined, dialCode: string): string {\n if (!v) return \"\";\n const prefix = `+${dialCode}`;\n if (v.startsWith(prefix)) return v.slice(prefix.length);\n return v;\n}\n\nconst currentFormValue = computed(() =>\n selectedCountry.value\n ? buildValue(localNumber.value, selectedCountry.value.dial)\n : localNumber.value,\n);\n\n// Sync external modelValue → localNumber\nwatch(\n () => props.modelValue,\n (v) => {\n const dial = selectedCountry.value?.dial ?? \"\";\n const national = extractNational(v, dial);\n if (national !== localNumber.value) localNumber.value = national;\n },\n { immediate: true },\n);\n\n// ── Popover ───────────────────────────────────────────────────────────────────\nconst {\n triggerRef,\n panelRef,\n isOpen,\n panelStyle,\n open: openPopover,\n close: closePopover,\n toggle: togglePopover,\n} = usePopover({\n placement: \"bottom-start\",\n onOpen: () => {\n dropdownWidth.value = wrapperEl.value\n ? `${wrapperEl.value.getBoundingClientRect().width}px`\n : \"260px\";\n searchQuery.value = \"\";\n activeIndex.value = Math.max(\n 0,\n filteredCountries.value.findIndex((c) => c.iso === activeIso.value),\n );\n nextTick(() => {\n searchEl.value?.focus();\n scrollActiveIntoView();\n });\n },\n onClose: () => {\n searchQuery.value = \"\";\n activeIndex.value = -1;\n },\n});\n\nconst mergedPanelStyle = computed(() => ({\n ...panelStyle.value,\n ...(dropdownWidth.value ? { width: dropdownWidth.value } : {}),\n}));\n\n// ── Search + filtered list ────────────────────────────────────────────────────\nconst searchQuery = ref(\"\");\nconst activeIndex = ref(-1);\nconst autoListboxId = useId();\n\nconst optionId = (iso: string) =>\n `modo-phone-listbox-${autoListboxId}-opt-${iso}`;\n\nconst filteredCountries = computed<PhoneCountry[]>(() => {\n const q = searchQuery.value.trim().toLowerCase();\n if (!q) return PHONE_COUNTRIES as unknown as PhoneCountry[];\n return (PHONE_COUNTRIES as unknown as PhoneCountry[]).filter(\n (c) =>\n c.name.toLowerCase().includes(q) ||\n c.iso.toLowerCase().includes(q) ||\n c.dial.startsWith(q.replace(/^\\+/, \"\")),\n );\n});\n\nwatch(filteredCountries, (list) => {\n const idx = list.findIndex((c) => c.iso === activeIso.value);\n activeIndex.value = idx >= 0 ? idx : 0;\n});\n\n// ── Option styles ─────────────────────────────────────────────────────────────\nconst OPTION_SURFACE: Record<string, string> = {\n default: \"bg-muted\",\n primary: \"bg-primary/10\",\n danger: \"bg-destructive/10\",\n success: \"bg-success/10\",\n warning: \"bg-warning/10\",\n};\nconst OPTION_HOVER: Record<string, string> = {\n default: \"hover:bg-muted\",\n primary: \"hover:bg-primary/10\",\n danger: \"hover:bg-destructive/10\",\n success: \"hover:bg-success/10\",\n warning: \"hover:bg-warning/10\",\n};\nconst optionSurface = computed(\n () => OPTION_SURFACE[stateColor.value] ?? \"bg-muted\",\n);\nconst optionHover = computed(\n () => OPTION_HOVER[stateColor.value] ?? \"hover:bg-muted\",\n);\nconst CHECK_COLOR_BY_STATE: Record<string, string> = {\n default: \"text-foreground\",\n primary: \"text-primary\",\n danger: \"text-destructive\",\n success: \"text-success\",\n warning: \"text-warning\",\n};\nconst checkColorClass = computed(\n () => CHECK_COLOR_BY_STATE[stateColor.value] ?? \"text-foreground\",\n);\nconst affordanceIconClass = computed(\n () =>\n FIELD_AFFORDANCE_ICON_BY_COLOR[stateColor.value] ?? \"text-muted-foreground\",\n);\nconst affordanceActionClass = computed(\n () =>\n FIELD_AFFORDANCE_ACTION_BY_COLOR[stateColor.value] ??\n \"text-muted-foreground hover:text-foreground\",\n);\n\n// ── Size classes ──────────────────────────────────────────────────────────────\nconst wrapperHeightClass = computed(() => {\n // sz.value.padX is e.g. \"px-2.5\" — convert to pr-* for the wrapper right edge\n const pr = sz.value.padX.replace(\"px-\", \"pr-\");\n return `${sz.value.control} ${pr}`;\n});\n\nconst triggerPaddingClass = computed(() => {\n switch (resolvedSize.value) {\n case \"small\":\n return \"pl-2.5 pr-1.5 gap-1\";\n case \"large\":\n return \"pl-4 pr-2 gap-1.5\";\n default:\n return \"pl-3 pr-2 gap-1\";\n }\n});\n\nconst flagSizeClass = computed(() => {\n switch (resolvedSize.value) {\n case \"small\":\n return \"text-sm\";\n case \"large\":\n return \"text-xl\";\n default:\n return \"text-base\";\n }\n});\n\nconst triggerTextClass = computed(() => {\n switch (resolvedSize.value) {\n case \"small\":\n return \"text-[11px]\";\n case \"large\":\n return \"text-body\";\n default:\n return \"text-caption\";\n }\n});\n\nconst chevronSizeClass = computed(() => {\n switch (resolvedSize.value) {\n case \"small\":\n return \"w-3 h-3\";\n case \"large\":\n return \"w-4 h-4\";\n default:\n return \"w-3.5 h-3.5\";\n }\n});\n\nconst inputTextClass = computed(() => sz.value.text);\n\nconst inputPaddingClass = computed(() => {\n // pr-3 leaves a comfortable gap on the right edge as well; the\n // legacy showroom relied on the field-native default padding which\n // we override here. Without pl-3 numbers visually butt up against\n // the country trigger divider.\n return \"pl-3 pr-3\";\n});\n\n// ── Event handlers ────────────────────────────────────────────────────────────\nfunction onInput(e: Event) {\n const val = (e.target as HTMLInputElement).value;\n localNumber.value = val;\n emit(\"update:modelValue\", buildValue(val, selectedCountry.value?.dial ?? \"\"));\n}\n\nfunction onChange(e: Event) {\n const val = (e.target as HTMLInputElement).value;\n emit(\"change\", buildValue(val, selectedCountry.value?.dial ?? \"\"));\n}\n\nfunction selectCountry(c: PhoneCountry) {\n if (props.country === undefined) internalCountry.value = c.iso;\n emit(\"update:country\", c.iso);\n emit(\"update:modelValue\", buildValue(localNumber.value, c.dial));\n closePopover();\n nextTick(() => inputRef.value?.focus());\n}\n\nfunction onTriggerClick() {\n if (isDisabled.value || props.readonly) return;\n togglePopover();\n}\n\nfunction onTriggerKeydown(e: KeyboardEvent) {\n if (isDisabled.value || props.readonly) return;\n if (e.key === \"ArrowDown\" || e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n if (!isOpen.value) openPopover();\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n closePopover();\n }\n}\n\nfunction onSearchKeydown(e: KeyboardEvent) {\n const list = filteredCountries.value;\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n activeIndex.value = Math.min(activeIndex.value + 1, list.length - 1);\n scrollActiveIntoView();\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n activeIndex.value = Math.max(activeIndex.value - 1, 0);\n scrollActiveIntoView();\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n const c = list[activeIndex.value];\n if (c) selectCountry(c);\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n closePopover();\n triggerRef.value?.focus?.();\n } else if (e.key === \"Tab\") {\n // The search field lives inside a panel teleported to <body>, i.e. at the\n // very end of the document. Letting the browser resolve Tab from there\n // walks *past* the whole field — the number input sits earlier in the DOM\n // and is never reached — so focus landed on whatever followed the panel\n // while the panel was unmounting. Drive the destination explicitly:\n // forwards continues into the number input, backwards returns to the flag\n // trigger, which is the order the field reads in.\n e.preventDefault();\n closePopover();\n if (e.shiftKey) triggerRef.value?.focus?.();\n else inputRef.value?.focus();\n }\n}\n\nfunction scrollActiveIntoView() {\n nextTick(() => {\n const c = filteredCountries.value[activeIndex.value];\n if (!c || !listEl.value) return;\n const el = document.getElementById(optionId(c.iso));\n el?.scrollIntoView({ block: \"nearest\" });\n });\n}\n\n// ── Expose ────────────────────────────────────────────────────────────────────\ndefineExpose({\n focus: () => inputRef.value?.focus(),\n blur: () => inputRef.value?.blur(),\n inputRef,\n});\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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"sourcesContent":["<template> \n <div :class=\"['flex flex-col gap-1.5', fullWidth ? 'w-full' : 'inline-flex']\"> \n <label \n v-if=\"label\" \n :for=\"fieldId\" \n class=\"text-caption font-medium text-foreground\" \n > \n {{ label }} \n <span v-if=\"required\" aria-hidden=\"true\" class=\"text-destructive ml-0.5\">*</span> \n </label> \n \n <div\n ref=\"wrapperEl\"\n :class=\"[\n 'modo-field-wrapper flex items-center gap-2',\n wrapperVariantClasses,\n wrapperSizeClasses,\n radiusClasses,\n fullWidth ? 'w-full' : '',\n isDisabled ? 'opacity-60 cursor-not-allowed' : '',\n ]\"\n >\n <MagnifyingGlassIcon \n aria-hidden=\"true\" \n :class=\"['shrink-0', affordanceIconClass, iconSizeClasses]\" \n /> \n \n <input \n :id=\"fieldId\" \n ref=\"inputRef\" \n type=\"search\" \n :value=\"modelValue ?? ''\" \n :placeholder=\"placeholder\" \n :disabled=\"isDisabled\" \n :readonly=\"readonly\" \n :required=\"required\" \n :name=\"name\" \n :maxlength=\"maxLength\" \n :autofocus=\"autofocus\" \n autocomplete=\"off\" \n spellcheck=\"false\" \n role=\"searchbox\"\n :aria-label=\"!label ? ariaLabel : undefined\"\n :aria-invalid=\"hasError || undefined\"\n :aria-describedby=\"describedBy\"\n :aria-required=\"required || undefined\"\n :aria-expanded=\"hasDropdown ? isOpen : undefined\"\n :aria-controls=\"hasDropdown && isOpen ? `${fieldId}-results` : undefined\"\n :aria-activedescendant=\"isOpen && highlightedIdx >= 0 ? `${fieldId}-opt-${highlightedIdx}` : undefined\"\n :class=\"[ \n 'modo-field-native flex-1 min-w-0 bg-transparent p-0', \n 'text-foreground placeholder:text-muted-foreground', \n 'disabled:cursor-not-allowed', \n inputTextClasses, \n ]\" \n @input=\"onInput\" \n @keydown=\"onKeydown\" \n @focus=\"onFocus\" \n @blur=\"onBlur\" \n /> \n \n <Loader \n v-if=\"loading\" \n :size=\"size === 'large' ? 'medium' : 'small'\" \n :class=\"['shrink-0', affordanceIconClass]\" \n /> \n \n <Button \n v-else-if=\"hasValue && !isDisabled && !readonly\" \n variant=\"text\" \n size=\"xs\" \n radius=\"full\" \n :icon=\"XMarkIcon\" \n :ariaLabel=\"loc.searchInput.clear\" \n tabindex=\"-1\" \n :class=\"['shrink-0', affordanceActionClass]\" \n @click=\"onClear\" \n /> \n \n <!-- The shortcut hint stays while the field is empty (focused or not)\n so focusing never removes it and reflows the width. It yields to\n the clear button as soon as there is a value. -->\n <kbd\n v-else-if=\"shortcut\"\n aria-hidden=\"true\"\n :class=\"[ \n 'shrink-0 select-none rounded-md px-1.5 py-0.5', \n 'text-[11px] leading-none font-sans font-medium tabular-nums', \n 'bg-muted text-muted-foreground border border-border', \n ]\" \n > \n {{ shortcutLabel }}\n </kbd>\n </div>\n\n <!-- RESULTS DROPDOWN -->\n <PopoverPanel\n v-if=\"hasDropdown\"\n :open=\"isOpen\"\n :style=\"panelStyle\"\n :radius=\"resolvedRadius\"\n role=\"presentation\"\n @update:panelRef=\"panelRef = $event\"\n >\n <!-- mousedown.prevent keeps focus in the input while clicking a row -->\n <div class=\"modo-search-results\" @mousedown.prevent>\n <slot\n name=\"results\"\n :items=\"resultItems\"\n :query=\"String(modelValue ?? '')\"\n :highlighted=\"highlightedIdx\"\n :select=\"selectResult\"\n :close=\"closePopover\"\n >\n <div v-if=\"loading\" class=\"px-3 py-6 flex items-center justify-center\">\n <slot name=\"loading\"><Loader size=\"small\" /></slot>\n </div>\n <div\n v-else-if=\"!resultItems.length\"\n class=\"px-3 py-6 text-center text-muted-foreground text-body\"\n >\n <slot name=\"empty\">{{ emptyText }}</slot>\n </div>\n <ul v-else :id=\"`${fieldId}-results`\" role=\"listbox\" class=\"flex flex-col\">\n <template v-for=\"row in renderRows\" :key=\"row.key\">\n <li\n v-if=\"row.kind === 'header'\"\n role=\"presentation\"\n class=\"px-3 pt-2 pb-1 text-caption font-medium text-muted-foreground select-none\"\n >\n {{ row.label }}\n </li>\n <li\n v-else\n :id=\"`${fieldId}-opt-${row.index}`\"\n role=\"option\"\n :aria-selected=\"row.index === highlightedIdx\"\n :aria-disabled=\"row.item.disabled || undefined\"\n >\n <component\n :is=\"row.item.href && !row.item.disabled ? 'a' : 'div'\"\n :href=\"row.item.href && !row.item.disabled ? row.item.href : undefined\"\n :target=\"row.item.external ? '_blank' : undefined\"\n :rel=\"row.item.external ? 'noopener noreferrer' : undefined\"\n class=\"flex items-center gap-2.5 px-3 py-2 text-body transition-colors duration-fast ease-standard\"\n :class=\"[\n row.item.disabled\n ? 'opacity-50 cursor-not-allowed'\n : 'cursor-pointer',\n row.index === highlightedIdx && !row.item.disabled ? 'bg-accent' : '',\n ]\"\n @mouseenter=\"row.item.disabled ? null : (highlightedIdx = row.index)\"\n @click=\"selectResult(row.item)\"\n >\n <slot name=\"item\" :item=\"row.item\" :active=\"row.index === highlightedIdx\">\n <component\n :is=\"row.item.icon\"\n v-if=\"row.item.icon\"\n class=\"size-4 shrink-0 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n <span class=\"flex flex-col min-w-0 flex-1\">\n <span class=\"truncate\">{{ row.item.label }}</span>\n <span\n v-if=\"row.item.description\"\n class=\"text-caption text-muted-foreground truncate\"\n >{{ row.item.description }}</span>\n </span>\n <span\n v-if=\"row.item.shortcut\"\n class=\"ml-2 text-caption text-muted-foreground tabular-nums shrink-0\"\n aria-hidden=\"true\"\n >{{ row.item.shortcut }}</span>\n </slot>\n </component>\n </li>\n </template>\n </ul>\n </slot>\n </div>\n </PopoverPanel>\n\n <div\n v-if=\"errorText || helperText || showCounterEffective\" \n class=\"flex items-start justify-between gap-2\" \n > \n <Typography \n v-if=\"errorText\" \n :id=\"errorId\" \n variant=\"caption\" \n size=\"medium\" \n color=\"danger\" \n as=\"p\" \n > \n {{ errorText }} \n </Typography> \n <Typography \n v-else-if=\"helperText\" \n :id=\"helperId\" \n variant=\"caption\" \n size=\"medium\" \n color=\"muted\" \n as=\"p\" \n > \n {{ helperText }} \n </Typography> \n <span v-else class=\"flex-1\" /> \n \n <span \n v-if=\"showCounterEffective\" \n :id=\"counterId\" \n :class=\"[ \n 'text-caption shrink-0 tabular-nums', \n counterOverflow ? 'text-destructive' : 'text-muted-foreground', \n ]\" \n > \n {{ currentLength }}/{{ maxLength }} \n </span> \n </div> \n </div> \n</template> \n \n<script setup lang=\"ts\"> \nimport { computed, onBeforeUnmount, onMounted, ref, useSlots, watch, nextTick } from 'vue';\nimport type { SearchInput, SearchResultItem } from '../../interfaces/forms/SearchInput.interface';\nimport {\n useFieldState,\n useFieldClasses,\n FIELD_AFFORDANCE_ACTION_BY_COLOR,\n FIELD_AFFORDANCE_ICON_BY_COLOR,\n} from '../../composables/useField';\nimport Loader from '../feedback/Loader.vue';\nimport Button from './Button.vue';\nimport PopoverPanel from '../layout/PopoverPanel.vue';\nimport { usePopover } from '../../composables/usePopover';\nimport { MagnifyingGlassIcon, XMarkIcon } from '@heroicons/vue/24/outline';\nimport Typography from '../data-display/Typography.vue';\nimport { useModoLocale, useResolvedRadius, useResolvedSize, useSizeTokens } from '../../composables/useModoConfig';\n\nconst loc = useModoLocale();\nconst slots = useSlots();\n\nconst emit = defineEmits<{\n 'update:modelValue': [value: string];\n change: [value: string];\n focus: [event: FocusEvent];\n blur: [event: FocusEvent];\n clear: [];\n /** Se emite al presionar Enter o tras el debounce. */\n search: [value: string];\n /** A result row was chosen (click / Enter on the highlighted row). */\n select: [item: SearchResultItem];\n /** Results popover open state (for `v-model:open`). */\n 'update:open': [value: boolean];\n}>();\n\nconst props = withDefaults(defineProps<SearchInput>(), {\n variant: 'outline',\n color: 'default',\n disabled: false,\n readonly: false,\n required: false,\n loading: false,\n fullWidth: false,\n showCounter: false,\n autofocus: false,\n debounce: 0,\n placeholder: 'Search…',\n resultsPlacement: 'bottom-start',\n});\n \nconst resolvedSize = useResolvedSize(() => props.size);\nconst sz = useSizeTokens(() => props.size);\n\nconst inputRef = ref<HTMLInputElement | null>(null); \nconst focused = ref(false); \n \nconst { \n fieldId, \n radius, \n stateColor, \n hasError, \n hasValue, \n isDisabled, \n currentLength, \n showCounterEffective, \n counterOverflow, \n errorId, \n helperId, \n counterId, \n describedBy, \n} = useFieldState(props, { componentName: 'SearchInput', idPrefix: 'modo-search' }); \n \nconst { wrapperVariantClasses, radiusClasses } = useFieldClasses({ \n variant: () => props.variant, \n stateColor, \n hasError, \n radius, \n halo: () => props.halo, \n}); \n\nconst affordanceIconClass = computed(() => FIELD_AFFORDANCE_ICON_BY_COLOR[stateColor.value] ?? 'text-muted-foreground');\nconst affordanceActionClass = computed(() => FIELD_AFFORDANCE_ACTION_BY_COLOR[stateColor.value] ?? 'text-muted-foreground hover:text-foreground');\n\n/* ---------- Results dropdown ---------- */\nconst resolvedRadius = useResolvedRadius(() => props.radius);\n\n// The dropdown is active when the host passes `items` (even empty) or a custom\n// `#results` slot. Filtering/async stays with the host — this only renders.\nconst hasDropdown = computed(() => props.items !== undefined || !!slots.results);\nconst resultItems = computed<SearchResultItem[]>(() => props.items ?? []);\n\nconst highlightedIdx = ref(-1);\nconst {\n triggerRef: popoverTrigger,\n panelRef,\n isOpen,\n panelStyle,\n open: openPopover,\n close: closePopover,\n} = usePopover({\n placement: () => props.resultsPlacement,\n matchTriggerWidth: true,\n closeOnEscape: false, // handled on the input so focus stays in the field\n closeOnScroll: false, // reposition on scroll; focusing the input can auto-scroll it into view\n onOpen: () => emit('update:open', true),\n onClose: () => { emit('update:open', false); highlightedIdx.value = -1; },\n});\n\nconst wrapperEl = ref<HTMLElement | null>(null);\nwatch(wrapperEl, (el) => { popoverTrigger.value = el; });\n\n// Flat render list with a group header inserted whenever `group` changes.\ntype RenderRow =\n | { kind: 'header'; label: string; key: string }\n | { kind: 'option'; item: SearchResultItem; index: number; key: string };\nconst renderRows = computed<RenderRow[]>(() => {\n const rows: RenderRow[] = [];\n let prevGroup: string | undefined;\n resultItems.value.forEach((item, index) => {\n if (item.group && item.group !== prevGroup) {\n rows.push({ kind: 'header', label: item.group, key: `h-${index}` });\n prevGroup = item.group;\n }\n rows.push({ kind: 'option', item, index, key: `o-${item.id ?? index}` });\n });\n return rows;\n});\n\nconst enabledIndices = computed(() =>\n resultItems.value.map((it, i) => (it.disabled ? -1 : i)).filter((i) => i !== -1),\n);\n\n// Show the popover only while focused and there is something to render.\nconst shouldShowResults = computed(() =>\n hasDropdown.value && focused.value &&\n (resultItems.value.length > 0 || props.loading || !!props.emptyText || !!slots.empty),\n);\n\nfunction syncOpen() {\n if (shouldShowResults.value) { if (!isOpen.value) openPopover(); }\n else if (isOpen.value) closePopover();\n}\nwatch(shouldShowResults, syncOpen);\nwatch(() => resultItems.value.length, () => { if (isOpen.value || shouldShowResults.value) nextTick(syncOpen); });\n\n// Optional external control via `v-model:open`.\nwatch(() => props.open, (v) => {\n if (v === undefined) return;\n if (v && shouldShowResults.value) openPopover();\n else if (!v) closePopover();\n});\n\nfunction moveHighlight(delta: 1 | -1) {\n const order = enabledIndices.value;\n if (!order.length) return;\n const cur = order.indexOf(highlightedIdx.value);\n highlightedIdx.value = cur === -1\n ? (delta > 0 ? order[0] : order[order.length - 1])\n : order[(cur + delta + order.length) % order.length];\n}\n\nfunction selectResult(item: SearchResultItem) {\n if (item.disabled) return;\n emit('select', item);\n closePopover();\n}\n\n/* ---------- Debounce ---------- */\nlet debounceTimer: number | null = null; \nfunction scheduleSearch(value: string) { \n if (!props.debounce || props.debounce <= 0) return; \n if (debounceTimer !== null) clearTimeout(debounceTimer); \n debounceTimer = window.setTimeout(() => { \n emit('search', value); \n debounceTimer = null; \n }, props.debounce); \n} \nfunction cancelDebounce() { \n if (debounceTimer !== null) { \n clearTimeout(debounceTimer); \n debounceTimer = null; \n } \n} \n \n/* ---------- Events ---------- */ \nfunction onInput(e: Event) { \n const target = e.target as HTMLInputElement; \n emit('update:modelValue', target.value); \n scheduleSearch(target.value); \n} \n \nfunction onKeydown(e: KeyboardEvent) {\n // Arrow keys drive the results dropdown when it is available.\n if (hasDropdown.value && (e.key === 'ArrowDown' || e.key === 'ArrowUp')) {\n e.preventDefault();\n if (!isOpen.value && shouldShowResults.value) openPopover();\n moveHighlight(e.key === 'ArrowDown' ? 1 : -1);\n return;\n }\n if (e.key === 'Enter') {\n // Enter picks the highlighted result if the dropdown is open; otherwise\n // it keeps the existing \"submit search\" behaviour.\n if (isOpen.value && highlightedIdx.value >= 0) {\n const item = resultItems.value[highlightedIdx.value];\n if (item && !item.disabled) {\n e.preventDefault();\n selectResult(item);\n return;\n }\n }\n e.preventDefault();\n cancelDebounce();\n emit('search', String(props.modelValue ?? ''));\n return;\n }\n if (e.key === 'Escape') {\n // First Escape closes the dropdown; a second (or when closed) clears.\n if (isOpen.value) {\n e.preventDefault();\n closePopover();\n return;\n }\n if (hasValue.value) {\n e.preventDefault();\n onClear();\n }\n }\n}\n \nfunction onFocus(e: FocusEvent) {\n focused.value = true;\n emit('focus', e);\n // Open the results popover on focus if there is anything to show. Done\n // explicitly (not only via the watcher) so it fires on the very first focus.\n if (hasDropdown.value) nextTick(syncOpen);\n}\n \nfunction onBlur(e: FocusEvent) { \n focused.value = false; \n emit('blur', e); \n} \n \nfunction onClear() { \n cancelDebounce(); \n emit('update:modelValue', ''); \n emit('clear'); \n emit('search', ''); \n inputRef.value?.focus(); \n} \n \n/* ---------- Shortcut ---------- */\n// Stays `false` on SSR and on the first client paint to keep them\n// identical, then flips to the real platform value in onMounted. Without\n// this guard the server would render `Ctrl+K` and the client would\n// immediately replace it with `⌘K`, triggering a hydration warning.\nconst isMac = ref(false);\nonMounted(() => {\n isMac.value = /Mac|iPod|iPhone|iPad/.test(navigator.platform);\n});\n \ninterface ParsedShortcut { \n key: string; \n ctrl: boolean; \n meta: boolean; \n shift: boolean; \n alt: boolean; \n} \n \nconst parsedShortcut = computed<ParsedShortcut | null>(() => { \n if (!props.shortcut) return null; \n const parts = props.shortcut.toLowerCase().split('+').map((p) => p.trim()); \n const result: ParsedShortcut = { key: '', ctrl: false, meta: false, shift: false, alt: false }; \n for (const part of parts) { \n if (part === 'cmd' || part === 'meta' || part === 'command') { \n if (isMac.value) result.meta = true; \n else result.ctrl = true; \n } else if (part === 'ctrl' || part === 'control') { \n result.ctrl = true; \n } else if (part === 'shift') { \n result.shift = true; \n } else if (part === 'alt' || part === 'option') { \n result.alt = true; \n } else { \n result.key = part; \n } \n } \n return result.key ? result : null; \n}); \n \nconst shortcutLabel = computed(() => { \n const s = parsedShortcut.value; \n if (!s) return ''; \n const segs: string[] = []; \n if (s.meta) segs.push(isMac.value ? '⌘' : 'Ctrl');\n else if (s.ctrl) segs.push(isMac.value ? '⌃' : 'Ctrl');\n if (s.alt) segs.push(isMac.value ? '⌥' : 'Alt');\n if (s.shift) segs.push(isMac.value ? '⇧' : 'Shift');\n segs.push(s.key.length === 1 ? s.key.toUpperCase() : s.key); \n return segs.join(isMac.value ? '' : '+'); \n}); \n \nfunction onGlobalKeydown(e: KeyboardEvent) { \n const s = parsedShortcut.value; \n if (!s) return; \n \n // No robar atajos mientras el usuario escribe en otro campo (a menos que sea una combinación con modificador). \n const target = e.target as HTMLElement | null; \n const typingElsewhere = !!target && (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable); \n const hasModifier = s.meta || s.ctrl || s.alt; \n if (typingElsewhere && !hasModifier && target !== inputRef.value) return; \n \n if ( \n e.key.toLowerCase() === s.key && \n e.metaKey === s.meta && \n e.ctrlKey === s.ctrl && \n e.shiftKey === s.shift && \n e.altKey === s.alt \n ) { \n e.preventDefault(); \n inputRef.value?.focus(); \n inputRef.value?.select(); \n } \n} \n \nonMounted(() => { \n if (parsedShortcut.value) { \n window.addEventListener('keydown', onGlobalKeydown); \n } \n}); \n \nonBeforeUnmount(() => { \n cancelDebounce(); \n window.removeEventListener('keydown', onGlobalKeydown); \n}); \n \n/* ---------- Classes ---------- */ \n \nconst wrapperSizeClasses = computed(() => `${sz.value.control} ${sz.value.padX}`);\n\nconst inputTextClasses = computed(() => sz.value.text);\n\nconst iconSizeClasses = computed(() => sz.value.icon); \n \ndefineExpose({ \n focus: () => inputRef.value?.focus(), \n blur: () => inputRef.value?.blur(), \n select: () => inputRef.value?.select(), \n clear: onClear, \n inputRef, \n}); \n</script>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"SearchInput.cjs","names":[],"sources":["../../../src/components/forms/SearchInput.vue"],"sourcesContent":["<template> \n <div :class=\"['flex flex-col gap-1.5', fullWidth ? 'w-full' : 'inline-flex']\"> \n <label \n v-if=\"label\" \n :for=\"fieldId\" \n class=\"text-caption font-medium text-foreground\" \n > \n {{ label }} \n <span v-if=\"required\" aria-hidden=\"true\" class=\"text-destructive ml-0.5\">*</span> \n </label> \n \n <div\n ref=\"wrapperEl\"\n :class=\"[\n 'modo-field-wrapper flex items-center gap-2',\n wrapperVariantClasses,\n wrapperSizeClasses,\n radiusClasses,\n fullWidth ? 'w-full' : '',\n isDisabled ? 'opacity-60 cursor-not-allowed' : '',\n ]\"\n >\n <MagnifyingGlassIcon \n aria-hidden=\"true\" \n :class=\"['shrink-0', affordanceIconClass, iconSizeClasses]\" \n /> \n \n <input \n :id=\"fieldId\" \n ref=\"inputRef\" \n type=\"search\" \n :value=\"modelValue ?? ''\" \n :placeholder=\"placeholder\" \n :disabled=\"isDisabled\" \n :readonly=\"readonly\" \n :required=\"required\" \n :name=\"name\" \n :maxlength=\"maxLength\" \n :autofocus=\"autofocus\" \n autocomplete=\"off\" \n spellcheck=\"false\" \n role=\"searchbox\"\n :aria-label=\"!label ? ariaLabel : undefined\"\n :aria-invalid=\"hasError || undefined\"\n :aria-describedby=\"describedBy\"\n :aria-required=\"required || undefined\"\n :aria-expanded=\"hasDropdown ? isOpen : undefined\"\n :aria-controls=\"hasDropdown && isOpen ? `${fieldId}-results` : undefined\"\n :aria-activedescendant=\"isOpen && highlightedIdx >= 0 ? `${fieldId}-opt-${highlightedIdx}` : undefined\"\n :class=\"[ \n 'modo-field-native flex-1 min-w-0 bg-transparent p-0', \n 'text-foreground placeholder:text-muted-foreground', \n 'disabled:cursor-not-allowed', \n inputTextClasses, \n ]\" \n @input=\"onInput\" \n @keydown=\"onKeydown\" \n @focus=\"onFocus\" \n @blur=\"onBlur\" \n /> \n \n <Loader \n v-if=\"loading\" \n :size=\"size === 'large' ? 'medium' : 'small'\" \n :class=\"['shrink-0', affordanceIconClass]\" \n /> \n \n <Button \n v-else-if=\"hasValue && !isDisabled && !readonly\" \n variant=\"text\" \n size=\"xs\" \n radius=\"full\" \n :icon=\"XMarkIcon\" \n :ariaLabel=\"loc.searchInput.clear\" \n tabindex=\"-1\" \n :class=\"['shrink-0', affordanceActionClass]\" \n @click=\"onClear\" \n /> \n \n <!-- The shortcut hint stays while the field is empty (focused or not)\n so focusing never removes it and reflows the width. It yields to\n the clear button as soon as there is a value. -->\n <kbd\n v-else-if=\"shortcut\"\n aria-hidden=\"true\"\n :class=\"[ \n 'shrink-0 select-none rounded-md px-1.5 py-0.5', \n 'text-[11px] leading-none font-sans font-medium tabular-nums', \n 'bg-muted text-muted-foreground border border-border', \n ]\" \n > \n {{ shortcutLabel }}\n </kbd>\n </div>\n\n <!-- RESULTS DROPDOWN -->\n <PopoverPanel\n v-if=\"hasDropdown\"\n :open=\"isOpen\"\n :style=\"panelStyle\"\n :radius=\"resolvedRadius\"\n role=\"presentation\"\n @update:panelRef=\"panelRef = $event\"\n >\n <!-- mousedown.prevent keeps focus in the input while clicking a row -->\n <div class=\"modo-search-results\" @mousedown.prevent>\n <slot\n name=\"results\"\n :items=\"resultItems\"\n :query=\"String(modelValue ?? '')\"\n :highlighted=\"highlightedIdx\"\n :select=\"selectResult\"\n :close=\"closePopover\"\n >\n <!--\n The panel loader only takes over when there is nothing\n to show yet. Swapping a populated list for a spinner on\n every keystroke makes the dropdown collapse and reopen\n as the user types; the affordance spinner in the field\n already signals the in-flight request.\n -->\n <div v-if=\"loading && !resultItems.length\" class=\"px-3 py-6 flex items-center justify-center\">\n <slot name=\"loading\"><Loader size=\"small\" /></slot>\n </div>\n <div\n v-else-if=\"!resultItems.length\"\n class=\"px-3 py-6 text-center text-muted-foreground text-body\"\n >\n <slot name=\"empty\">{{ emptyText }}</slot>\n </div>\n <ul\n v-else\n :id=\"`${fieldId}-results`\"\n role=\"listbox\"\n :aria-busy=\"loading || undefined\"\n class=\"flex flex-col\"\n >\n <template v-for=\"row in renderRows\" :key=\"row.key\">\n <li\n v-if=\"row.kind === 'header'\"\n role=\"presentation\"\n class=\"px-3 pt-2 pb-1 text-caption font-medium text-muted-foreground select-none\"\n >\n {{ row.label }}\n </li>\n <li\n v-else\n :id=\"`${fieldId}-opt-${row.index}`\"\n role=\"option\"\n :aria-selected=\"row.index === highlightedIdx\"\n :aria-disabled=\"row.item.disabled || undefined\"\n >\n <component\n :is=\"row.item.href && !row.item.disabled ? 'a' : 'div'\"\n :href=\"row.item.href && !row.item.disabled ? row.item.href : undefined\"\n :target=\"row.item.external ? '_blank' : undefined\"\n :rel=\"row.item.external ? 'noopener noreferrer' : undefined\"\n class=\"flex items-center gap-2.5 px-3 py-2 text-body transition-colors duration-fast ease-standard\"\n :class=\"[\n row.item.disabled\n ? 'opacity-50 cursor-not-allowed'\n : 'cursor-pointer',\n row.index === highlightedIdx && !row.item.disabled ? 'bg-accent' : '',\n ]\"\n @mouseenter=\"row.item.disabled ? null : (highlightedIdx = row.index)\"\n @click=\"selectResult(row.item)\"\n >\n <slot name=\"item\" :item=\"row.item\" :active=\"row.index === highlightedIdx\">\n <component\n :is=\"row.item.icon\"\n v-if=\"row.item.icon\"\n class=\"size-4 shrink-0 text-muted-foreground\"\n aria-hidden=\"true\"\n />\n <span class=\"flex flex-col min-w-0 flex-1\">\n <span class=\"truncate\">{{ row.item.label }}</span>\n <span\n v-if=\"row.item.description\"\n class=\"text-caption text-muted-foreground truncate\"\n >{{ row.item.description }}</span>\n </span>\n <span\n v-if=\"row.item.shortcut\"\n class=\"ml-2 text-caption text-muted-foreground tabular-nums shrink-0\"\n aria-hidden=\"true\"\n >{{ row.item.shortcut }}</span>\n </slot>\n </component>\n </li>\n </template>\n </ul>\n </slot>\n </div>\n </PopoverPanel>\n\n <div\n v-if=\"errorText || helperText || showCounterEffective\" \n class=\"flex items-start justify-between gap-2\" \n > \n <Typography \n v-if=\"errorText\" \n :id=\"errorId\" \n variant=\"caption\" \n size=\"medium\" \n color=\"danger\" \n as=\"p\" \n > \n {{ errorText }} \n </Typography> \n <Typography \n v-else-if=\"helperText\" \n :id=\"helperId\" \n variant=\"caption\" \n size=\"medium\" \n color=\"muted\" \n as=\"p\" \n > \n {{ helperText }} \n </Typography> \n <span v-else class=\"flex-1\" /> \n \n <span \n v-if=\"showCounterEffective\" \n :id=\"counterId\" \n :class=\"[ \n 'text-caption shrink-0 tabular-nums', \n counterOverflow ? 'text-destructive' : 'text-muted-foreground', \n ]\" \n > \n {{ currentLength }}/{{ maxLength }} \n </span> \n </div> \n </div> \n</template> \n \n<script setup lang=\"ts\"> \nimport { computed, onBeforeUnmount, onMounted, ref, useSlots, watch, nextTick } from 'vue';\nimport type { SearchInput, SearchResultItem } from '../../interfaces/forms/SearchInput.interface';\nimport {\n useFieldState,\n useFieldClasses,\n FIELD_AFFORDANCE_ACTION_BY_COLOR,\n FIELD_AFFORDANCE_ICON_BY_COLOR,\n} from '../../composables/useField';\nimport Loader from '../feedback/Loader.vue';\nimport Button from './Button.vue';\nimport PopoverPanel from '../layout/PopoverPanel.vue';\nimport { usePopover } from '../../composables/usePopover';\nimport { MagnifyingGlassIcon, XMarkIcon } from '@heroicons/vue/24/outline';\nimport Typography from '../data-display/Typography.vue';\nimport { useModoLocale, useResolvedRadius, useResolvedSize, useSizeTokens } from '../../composables/useModoConfig';\n\nconst loc = useModoLocale();\nconst slots = useSlots();\n\nconst emit = defineEmits<{\n 'update:modelValue': [value: string];\n change: [value: string];\n focus: [event: FocusEvent];\n blur: [event: FocusEvent];\n clear: [];\n /** Se emite al presionar Enter o tras el debounce. */\n search: [value: string];\n /** A result row was chosen (click / Enter on the highlighted row). */\n select: [item: SearchResultItem];\n /** Results popover open state (for `v-model:open`). */\n 'update:open': [value: boolean];\n}>();\n\nconst props = withDefaults(defineProps<SearchInput>(), {\n variant: 'outline',\n color: 'default',\n disabled: false,\n readonly: false,\n required: false,\n loading: false,\n fullWidth: false,\n showCounter: false,\n autofocus: false,\n debounce: 0,\n placeholder: 'Search…',\n resultsPlacement: 'bottom-start',\n});\n \nconst resolvedSize = useResolvedSize(() => props.size);\nconst sz = useSizeTokens(() => props.size);\n\nconst inputRef = ref<HTMLInputElement | null>(null); \nconst focused = ref(false); \n \nconst { \n fieldId, \n radius, \n stateColor, \n hasError, \n hasValue, \n currentLength,\n showCounterEffective, \n counterOverflow, \n errorId, \n helperId, \n counterId, \n describedBy, \n} = useFieldState(props, { componentName: 'SearchInput', idPrefix: 'modo-search' }); \n \nconst { wrapperVariantClasses, radiusClasses } = useFieldClasses({ \n variant: () => props.variant, \n stateColor, \n hasError, \n radius, \n halo: () => props.halo, \n}); \n\n// Deliberately NOT `useFieldState`'s `isDisabled`, which also reports true\n// while `loading`. That is right for a field being submitted, but fatal for a\n// search box: the results are what load, not the input. Disabling it mid-query\n// makes the browser blur the element the user is typing in — focus is lost, the\n// results popover closes, and the next keystroke is dropped. For SearchInput,\n// only an explicit `disabled` disables.\nconst isDisabled = computed(() => !!props.disabled);\n\nconst affordanceIconClass = computed(() => FIELD_AFFORDANCE_ICON_BY_COLOR[stateColor.value] ?? 'text-muted-foreground');\nconst affordanceActionClass = computed(() => FIELD_AFFORDANCE_ACTION_BY_COLOR[stateColor.value] ?? 'text-muted-foreground hover:text-foreground');\n\n/* ---------- Results dropdown ---------- */\nconst resolvedRadius = useResolvedRadius(() => props.radius);\n\n// The dropdown is active when the host passes `items` (even empty) or a custom\n// `#results` slot. Filtering/async stays with the host — this only renders.\nconst hasDropdown = computed(() => props.items !== undefined || !!slots.results);\nconst resultItems = computed<SearchResultItem[]>(() => props.items ?? []);\n\nconst highlightedIdx = ref(-1);\nconst {\n triggerRef: popoverTrigger,\n panelRef,\n isOpen,\n panelStyle,\n open: openPopover,\n close: closePopover,\n} = usePopover({\n placement: () => props.resultsPlacement,\n matchTriggerWidth: true,\n closeOnEscape: false, // handled on the input so focus stays in the field\n closeOnScroll: false, // reposition on scroll; focusing the input can auto-scroll it into view\n onOpen: () => emit('update:open', true),\n onClose: () => { emit('update:open', false); highlightedIdx.value = -1; },\n});\n\nconst wrapperEl = ref<HTMLElement | null>(null);\nwatch(wrapperEl, (el) => { popoverTrigger.value = el; });\n\n// Flat render list with a group header inserted whenever `group` changes.\ntype RenderRow =\n | { kind: 'header'; label: string; key: string }\n | { kind: 'option'; item: SearchResultItem; index: number; key: string };\nconst renderRows = computed<RenderRow[]>(() => {\n const rows: RenderRow[] = [];\n let prevGroup: string | undefined;\n resultItems.value.forEach((item, index) => {\n if (item.group && item.group !== prevGroup) {\n rows.push({ kind: 'header', label: item.group, key: `h-${index}` });\n prevGroup = item.group;\n }\n rows.push({ kind: 'option', item, index, key: `o-${item.id ?? index}` });\n });\n return rows;\n});\n\nconst enabledIndices = computed(() =>\n resultItems.value.map((it, i) => (it.disabled ? -1 : i)).filter((i) => i !== -1),\n);\n\n// Show the popover only while focused and there is something to render.\nconst shouldShowResults = computed(() =>\n hasDropdown.value && focused.value &&\n (resultItems.value.length > 0 || props.loading || !!props.emptyText || !!slots.empty),\n);\n\nfunction syncOpen() {\n if (shouldShowResults.value) { if (!isOpen.value) openPopover(); }\n else if (isOpen.value) closePopover();\n}\nwatch(shouldShowResults, syncOpen);\nwatch(() => resultItems.value.length, () => { if (isOpen.value || shouldShowResults.value) nextTick(syncOpen); });\n\n// Optional external control via `v-model:open`.\nwatch(() => props.open, (v) => {\n if (v === undefined) return;\n if (v && shouldShowResults.value) openPopover();\n else if (!v) closePopover();\n});\n\nfunction moveHighlight(delta: 1 | -1) {\n const order = enabledIndices.value;\n if (!order.length) return;\n const cur = order.indexOf(highlightedIdx.value);\n highlightedIdx.value = cur === -1\n ? (delta > 0 ? order[0] : order[order.length - 1])\n : order[(cur + delta + order.length) % order.length];\n}\n\nfunction selectResult(item: SearchResultItem) {\n if (item.disabled) return;\n emit('select', item);\n closePopover();\n}\n\n/* ---------- Debounce ---------- */\nlet debounceTimer: number | null = null; \nfunction scheduleSearch(value: string) { \n if (!props.debounce || props.debounce <= 0) return; \n if (debounceTimer !== null) clearTimeout(debounceTimer); \n debounceTimer = window.setTimeout(() => { \n emit('search', value); \n debounceTimer = null; \n }, props.debounce); \n} \nfunction cancelDebounce() { \n if (debounceTimer !== null) { \n clearTimeout(debounceTimer); \n debounceTimer = null; \n } \n} \n \n/* ---------- Events ---------- */ \nfunction onInput(e: Event) { \n const target = e.target as HTMLInputElement; \n emit('update:modelValue', target.value); \n scheduleSearch(target.value); \n} \n \nfunction onKeydown(e: KeyboardEvent) {\n // Arrow keys drive the results dropdown when it is available.\n if (hasDropdown.value && (e.key === 'ArrowDown' || e.key === 'ArrowUp')) {\n e.preventDefault();\n if (!isOpen.value && shouldShowResults.value) openPopover();\n moveHighlight(e.key === 'ArrowDown' ? 1 : -1);\n return;\n }\n if (e.key === 'Enter') {\n // Enter picks the highlighted result if the dropdown is open; otherwise\n // it keeps the existing \"submit search\" behaviour.\n if (isOpen.value && highlightedIdx.value >= 0) {\n const item = resultItems.value[highlightedIdx.value];\n if (item && !item.disabled) {\n e.preventDefault();\n selectResult(item);\n return;\n }\n }\n e.preventDefault();\n cancelDebounce();\n emit('search', String(props.modelValue ?? ''));\n return;\n }\n if (e.key === 'Escape') {\n // First Escape closes the dropdown; a second (or when closed) clears.\n if (isOpen.value) {\n e.preventDefault();\n closePopover();\n return;\n }\n if (hasValue.value) {\n e.preventDefault();\n onClear();\n }\n }\n}\n \nfunction onFocus(e: FocusEvent) {\n focused.value = true;\n emit('focus', e);\n // Open the results popover on focus if there is anything to show. Done\n // explicitly (not only via the watcher) so it fires on the very first focus.\n if (hasDropdown.value) nextTick(syncOpen);\n}\n \nfunction onBlur(e: FocusEvent) {\n focused.value = false;\n emit('blur', e);\n}\n \nfunction onClear() { \n cancelDebounce(); \n emit('update:modelValue', ''); \n emit('clear'); \n emit('search', ''); \n inputRef.value?.focus(); \n} \n \n/* ---------- Shortcut ---------- */\n// Stays `false` on SSR and on the first client paint to keep them\n// identical, then flips to the real platform value in onMounted. Without\n// this guard the server would render `Ctrl+K` and the client would\n// immediately replace it with `⌘K`, triggering a hydration warning.\nconst isMac = ref(false);\nonMounted(() => {\n isMac.value = /Mac|iPod|iPhone|iPad/.test(navigator.platform);\n});\n \ninterface ParsedShortcut { \n key: string; \n ctrl: boolean; \n meta: boolean; \n shift: boolean; \n alt: boolean; \n} \n \nconst parsedShortcut = computed<ParsedShortcut | null>(() => { \n if (!props.shortcut) return null; \n const parts = props.shortcut.toLowerCase().split('+').map((p) => p.trim()); \n const result: ParsedShortcut = { key: '', ctrl: false, meta: false, shift: false, alt: false }; \n for (const part of parts) { \n if (part === 'cmd' || part === 'meta' || part === 'command') { \n if (isMac.value) result.meta = true; \n else result.ctrl = true; \n } else if (part === 'ctrl' || part === 'control') { \n result.ctrl = true; \n } else if (part === 'shift') { \n result.shift = true; \n } else if (part === 'alt' || part === 'option') { \n result.alt = true; \n } else { \n result.key = part; \n } \n } \n return result.key ? result : null; \n}); \n \nconst shortcutLabel = computed(() => { \n const s = parsedShortcut.value; \n if (!s) return ''; \n const segs: string[] = []; \n if (s.meta) segs.push(isMac.value ? '⌘' : 'Ctrl');\n else if (s.ctrl) segs.push(isMac.value ? '⌃' : 'Ctrl');\n if (s.alt) segs.push(isMac.value ? '⌥' : 'Alt');\n if (s.shift) segs.push(isMac.value ? '⇧' : 'Shift');\n segs.push(s.key.length === 1 ? s.key.toUpperCase() : s.key); \n return segs.join(isMac.value ? '' : '+'); \n}); \n \nfunction onGlobalKeydown(e: KeyboardEvent) { \n const s = parsedShortcut.value; \n if (!s) return; \n \n // No robar atajos mientras el usuario escribe en otro campo (a menos que sea una combinación con modificador). \n const target = e.target as HTMLElement | null; \n const typingElsewhere = !!target && (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable); \n const hasModifier = s.meta || s.ctrl || s.alt; \n if (typingElsewhere && !hasModifier && target !== inputRef.value) return; \n \n if ( \n e.key.toLowerCase() === s.key && \n e.metaKey === s.meta && \n e.ctrlKey === s.ctrl && \n e.shiftKey === s.shift && \n e.altKey === s.alt \n ) { \n e.preventDefault(); \n inputRef.value?.focus(); \n inputRef.value?.select(); \n } \n} \n \nonMounted(() => { \n if (parsedShortcut.value) { \n window.addEventListener('keydown', onGlobalKeydown); \n } \n}); \n \nonBeforeUnmount(() => { \n cancelDebounce(); \n window.removeEventListener('keydown', onGlobalKeydown); \n}); \n \n/* ---------- Classes ---------- */ \n \nconst wrapperSizeClasses = computed(() => `${sz.value.control} ${sz.value.padX}`);\n\nconst inputTextClasses = computed(() => sz.value.text);\n\nconst iconSizeClasses = computed(() => sz.value.icon); \n \ndefineExpose({ \n focus: () => inputRef.value?.focus(), \n blur: () => inputRef.value?.blur(), \n select: () => inputRef.value?.select(), \n clear: onClear, \n inputRef, \n}); \n</script>\n"],"mappings":""}
|