Skip to content
On this page

Country Input

A <RichSelect /> made only to pick a list of countries with beautiful flags for each country. Add your favorite countries & search for other countries.

Preview & Playground 🖼️

Here you may find a preview of the component, with error & possible variants.

🏄 Click to expand the code
vue
<script setup lang="ts">
import { CountryInput } from '@flavorly/vanilla-components'
import { ref } from 'vue'

const value = ref('PT')
const valueErrors = ref('US')
</script>

<template>
  <PreviewWrapper>
    <div class="grid space-y-2">
      <!-- Regular -->
      <CountryInput
        v-model="value"
        placeholder="Simple with icon"
        feedback="You can add SVGs as addons before & After"
      />
      <!-- Errors -->
      <CountryInput
        v-model="valueErrors"
        placeholder="Elon Musk"
        feedback="Im showing only because you cleared errors"
        errors="We have a problem Musk, Abort! Write to clear"
      />
    </div>
  </PreviewWrapper>
</template>

Props 📥

Props available for this component extending the default variant & global props.

PropDescriptionAccepted ValuesDefault
modelValueThe value for the elementAny, Valid Country ISO Codeundefined
favoriteCountriesArray of favorite countries to preloadArray['us','gb','pt','fr','de']
labelWithDialCodeIf you want the label with a dial codeBooleanfalse
labelWithCountryCodeIf you want the label with country codeBooleanfalse
searchBoxPlaceholderPlaceholder for the Search BoxstringSearch here
noResultsTextWhen no results are found, the text to displaystringSorry...
searchingTextText to display while searchingstringPlease wait...
loadingClosedPlaceholderWhen loading but dropdown closedstringLoading please wait...
loadingMoreResultsTextText while is pulling for next pagesstringLoading more options...
minimumInputLengthTextA function or a number with the minimum chars to searchString, Function3

Slots 🧬

Current slots available for this component are the following:

Slot label

The slot that will be used for the label of the country, for the current selected option and when closed

AttributeDescriptionType
optionThe given optionObject
classNameThe current class nameString

Slot option

The slot for the option on the select dropdown.

AttributeDescriptionType
optionThe given optionObject
classNameThe current class nameString
isSelectedIf the current option is selectedBoolean

Slot before

Slot to override or pre-pend to the component before the component, ex: icon, etc.

AttributeDescriptionType
classNameClasses injectedString

Slot after

Slot to override or append to the component before the component, ex: icon, etc.

Attributes specially injected to the after slot for some inputs ( Ex: Password )

AttributeDescriptionType
hasErrorsIf the field has errorsBoolean
typeType of inputString
showingPasswordIf the password showing is toggledBoolean

Slot errors

Slot that holds the error messages when the component errors prop is defined.

AttributeDescriptionType
errorsThe errors being injected[String, Array]
hasErrorsIf the field has errorsBoolean

Slot feedback

Slot that holds the feedback messages when the component feedback prop is defined. When showing errors the feedback will be hidden by default, and vice-versa.

AttributeDescriptionType
errorsThe errors being injected[String, Array, Undefined]
feedbackThe feedback message[String, Undefined]

Events 🚇

Here you may find the events emitted by this component.

EventDescriptionValue
update:modelValueWhen the value changesany

| update:countryDialCode | The country dial code | string | | update:countryCode | The ISO country code | string | | update:countryName | The English name of the country | string |

Additional Components

You may also find additional components like CountryOption & CountryFlag, they bootstrap the current component, but you may use them standalone The Country input is just a mix of the Rich Select & the Country Option. I will not bother document there here for the time being, as it find it useless.

Released under the MIT License.