UNPKG

maz-ui

Version:

A standalone components library for Vue.Js 3 & Nuxt.Js 3

1 lines 6.91 kB
import{t as _plugin_vue_export_helper_default}from"./_plugin-vue_export-helper.ChmETRGw.js";import{useInstanceUniqId}from"../composables/useInstanceUniqId.js";import{useDisplayNames}from"../composables/useDisplayNames.js";import{t as MazSelect_default}from"./MazSelect.CyyabkpB.js";import{computed,createBlock,createCommentVNode,createElementBlock,createElementVNode,createVNode,defineAsyncComponent,defineComponent,mergeProps,normalizeClass,normalizeStyle,openBlock,renderSlot,toDisplayString,unref,withCtx}from"vue";import{useTranslations}from"@maz-ui/translations/composables/useTranslations";import{getBrowserLocale}from"@maz-ui/utils/helpers/getBrowserLocale";import{getCountryFlagUrl}from"@maz-ui/utils/helpers/getCountryFlagUrl";import '../assets/MazSelectCountry.kRB-iu5_.css';var _hoisted_1={key:0,class:`m-select-country__select__item__flag-container`};var _hoisted_2={key:1,class:`m-select-country__select__item__list-flag`};var _hoisted_3={class:`maz-text-muted`};var MazSelectCountry_default=_plugin_vue_export_helper_default(defineComponent({inheritAttrs:!1,__name:`MazSelectCountry`,props:{style:{type:[Boolean,null,String,Object,Array]},class:{type:[Boolean,null,String,Object,Array]},id:{},color:{default:`primary`},size:{default:`md`},preferredCodes:{},ignoredCodes:{},onlyCodes:{},listPosition:{},hideFlags:{type:Boolean},search:{type:Boolean,default:!0},showCodeInList:{type:Boolean,default:!1},locale:{},success:{type:Boolean},error:{type:Boolean},warning:{type:Boolean},displayCode:{type:Boolean},searchThreshold:{},translations:{},hint:{},options:{},displayNamesOptions:{default:()=>({type:`region`,languageDisplay:`standard`,fallback:`code`,style:`long`})},codesType:{},open:{type:Boolean},label:{},placeholder:{},modelValue:{},optionValueKey:{default:`code`},optionLabelKey:{default:`name`},optionInputValueKey:{default:`name`},preferPosition:{},fallbackPosition:{},itemHeight:{},maxListHeight:{},maxListWidth:{default:250},minListHeight:{},minListWidth:{default:200},searchFunction:{type:Function},required:{type:Boolean},disabled:{type:Boolean},block:{type:Boolean},autocomplete:{},formatInputValue:{type:Function},transition:{}},emits:[`update:model-value`],setup(__props){let instanceId=useInstanceUniqId({componentName:`MazSelectCountry`,providedId:__props.id});let{t,locale:mazLocale}=useTranslations();let locale=computed(()=>__props.locale??mazLocale.value??getBrowserLocale());let MazLazyImg=defineAsyncComponent(()=>import(`../components/MazLazyImg.js`));let{getAllDisplayNames}=useDisplayNames(locale);let displayNames=getAllDisplayNames({type:()=>__props.displayNamesOptions.type,languageDisplay:()=>__props.displayNamesOptions.languageDisplay,fallback:()=>__props.displayNamesOptions.fallback,style:()=>__props.displayNamesOptions.style,onlyCodes:()=>__props.onlyCodes,excludedCodes:()=>__props.ignoredCodes,preferredCodes:()=>__props.preferredCodes,codesType:computed(()=>__props.codesType?__props.codesType:__props.displayNamesOptions.type===`region`?`country`:`iso`)});let countriesOptions=computed(()=>__props.options?__props.options:displayNames?.value??[]);let messages=computed(()=>({searchPlaceholder:__props.translations?.searchPlaceholder??t(`selectCountry.searchPlaceholder`)}));function getFlagUrl(code,size=`h20`){return getCountryFlagUrl(code.slice(0,2),size)||getCountryFlagUrl(code.slice(3,5),size)||getCountryFlagUrl(code,size)}let flagUrl=computed(()=>{if(__props.modelValue)return getFlagUrl(__props.modelValue)});return(_ctx,_cache)=>(openBlock(),createElementBlock(`div`,{class:normalizeClass([`m-select-country m-reset-css`,[__props.class,{"--no-flags":__props.hideFlags}]]),style:normalizeStyle(__props.style)},[createVNode(MazSelect_default,mergeProps({id:unref(instanceId),"model-value":__props.modelValue},_ctx.$attrs,{class:`m-select-country__select`,"option-value-key":__props.optionValueKey,"option-label-key":__props.optionLabelKey,"option-input-value-key":__props.displayCode?`code`:__props.optionInputValueKey,"max-list-width":__props.maxListWidth,"min-list-width":__props.minListWidth,disabled:__props.disabled,color:__props.color,placeholder:__props.placeholder,label:__props.label,size:__props.size,multiple:!1,"list-position":__props.listPosition,error:__props.error,warning:__props.warning,success:__props.success,search:__props.search,block:__props.block,autocomplete:__props.autocomplete,"item-height":__props.itemHeight,"max-list-height":__props.maxListHeight,"min-list-height":__props.minListHeight,required:__props.required,"search-function":__props.searchFunction,"format-input-value":__props.formatInputValue,translations:messages.value,"search-threshold":__props.searchThreshold,options:countriesOptions.value,hint:__props.hint,open:__props.open,"onUpdate:modelValue":_cache[0]||=$event=>_ctx.$emit(`update:model-value`,$event)}),{"left-icon":withCtx(()=>[renderSlot(_ctx.$slots,`selector-flag`,{countryCode:__props.modelValue},()=>[flagUrl.value&&!__props.hideFlags?(openBlock(),createBlock(unref(MazLazyImg),{key:0,src:flagUrl.value,alt:__props.modelValue,width:`20`,height:`20`,class:`maz-size-5 maz-rounded`,"img-class":`maz-size-5 maz-rounded`},null,8,[`src`,`alt`])):createCommentVNode(``,!0)],!0)]),"no-results":withCtx(()=>[renderSlot(_ctx.$slots,`no-results`,{},void 0,!0)]),default:withCtx(({option,isSelected})=>[createElementVNode(`div`,{class:normalizeClass([`m-select-country__select__item`,{"m-select-country__select__item--selected":isSelected}])},[!__props.hideFlags&&typeof option.code==`string`?(openBlock(),createElementBlock(`span`,_hoisted_1,[renderSlot(_ctx.$slots,`country-list-flag`,{option,isSelected},()=>[option.code&&getFlagUrl(option.code)?(openBlock(),createBlock(unref(MazLazyImg),{key:0,src:getFlagUrl(option.code),alt:`${option.name} flag`,width:`20`,height:`20`,class:`maz-size-5 maz-rounded`,"img-class":`maz-rounded maz-h-5 maz-w-5`},null,8,[`src`,`alt`])):(openBlock(),createElementBlock(`span`,_hoisted_2,toDisplayString(option.code),1))],!0)])):createCommentVNode(``,!0),createElementVNode(`div`,{class:normalizeClass([`maz-flex maz-flex-1 maz-gap-2 maz-truncate`,{"maz-font-semibold":isSelected}])},[__props.showCodeInList?renderSlot(_ctx.$slots,`country-list-code`,{key:0,option,isSelected},()=>[createElementVNode(`span`,_hoisted_3,toDisplayString(option.code),1)],!0):createCommentVNode(``,!0),renderSlot(_ctx.$slots,`country-list-name`,{option,isSelected},()=>[createElementVNode(`span`,null,toDisplayString(option.name),1)],!0)],2)],2)]),_:3},16,`id.model-value.option-value-key.option-label-key.option-input-value-key.max-list-width.min-list-width.disabled.color.placeholder.label.size.list-position.error.warning.success.search.block.autocomplete.item-height.max-list-height.min-list-height.required.search-function.format-input-value.translations.search-threshold.options.hint.open`.split(`.`))],6))}}),[[`__scopeId`,`data-v-49632158`]]);export{MazSelectCountry_default as t};