1.0.0 • Published 2 years ago

volkeno-react-country-state-city v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

volkeno-react-country-state-city

This library provides React components to display dropdowns of connected countries, states and cities (choose a country, it displays the affected states, choose a state, it has displays the affected cities).

Single select

NPM JavaScript Style Guide

Install

npm install --save volkeno-react-country-state-city

Usage

import React, { useState } from 'react'
import {
  CountrySelector,
  StateSelector,
  CitySelector
} from 'volkeno-react-country-state-city'
import 'volkeno-react-country-state-city/dist/index.css'

const App = () => {
  const [country, setCountry] = useState<any>('')
  const [state, setState] = useState<any>('')
  const [city, setCity] = useState<any>('')

  const handleCountrySelect = (option: any) => {
    setCountry(option)
  }

  const handleStateSelect = (option: any) => {
    setState(option)
  }

  const handleCitySelect = (option: any) => {
    setCity(option)
  }
  return (
    <div style={{display: 'flex', justifyContent: 'center', alignItems: 'center', border: '2px solid grey', margin: '5rem'}}>
      <CountrySelector
        onChange={handleCountrySelect}
        name='country'
        placeholder='Select a country'
        value={country}
      />
      <StateSelector
        country={country}
        name='state'
        value={state}
        countryPlaceholder='Select a country first'
        onChange={handleStateSelect}
      />
      <CitySelector
        state={state}
        name='city'
        value={city}
        statePlaceholder='Select a state first'
        onChange={handleCitySelect}
      />
    </div>
  )
}

export default App

Configuration - Props

<CountrySelector/>

PropertyTypeRequireDefaultDescription
namestringfalsecountryname of input
containerClassstringfalse...ClassName of select container
onChangefunctiontrue...Callback that gets called when the user selects a country. Use this to store the value in whatever store you're using.
optionClassstringfalse...ClassName of label container
styleContainerReact.CSSPropertiesfalse...Apply a style to the select container
valuenumbertrue...The currently selected country.
placeholderstringfalse"Select Country"The default option label.

<StateSelector/>

PropertyTypeRequireDefaultDescription
countryobjecttrue...The currently selected country.
namestringfalsestatename of input
containerClassstringfalse...ClassName of select container
onChangefunctiontrue...Callback that gets called when the user selects a state. Use this to store the value in whatever store you're using.
optionClassstringfalse...ClassName of label container
styleContainerReact.CSSPropertiesfalse...Apply a style to the select container
valuenumbertrue...The currently selected country.
placeholderstringfalse"Select State"The default option label.
countryPlaceholderstringfalse"Select Country"The label that appears in the state dropdown when the user hasn't selected a country yet.

<CitySelector/>

PropertyTypeRequireDefaultDescription
stateobjecttrue...The currently selected state.
namestringfalsecityname of input
containerClassstringfalse...ClassName of select container
onChangefunctiontrue...Callback that gets called when the user selects a state. Use this to store the value in whatever store you're using.
optionClassstringfalse...ClassName of label container
styleContainerReact.CSSPropertiesfalse...Apply a style to the select container
valuenumbertrue...The currently selected state.
placeholderstringfalse"Select State"The default option label.
statePlaceholderstringfalse"Select State"The label that appears in the city dropdown when the user hasn't selected a state yet.

License

MIT © VolkenoMakers

1.0.0

2 years ago