Socket
Book a DemoInstallSign in
Socket

country-dropdown

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

country-dropdown

Easily create fully customizable country, state, and city dropdowns with this comprehensive package. Perfect for any web form or application requiring accurate geographic selection, this package supports dynamic and dependent dropdowns, ensuring a seamles

0.1.4
latest
npmnpm
Version published
Weekly downloads
3
-40%
Maintainers
1
Weekly downloads
 
Created
Source

Country Dropdown

A customizable React component for country, state, and city dropdowns.

Installation

Step 1: Install the package from npm.

To get started with the Country Dropdown component, follow these steps:

npm i country-dropdown

Step 2: Request an API key from Country State City API.

Before using the component, you need to get an API key from the Country State City API website.

Step 3: Set the API key in the environment(.env) file.

Please make sure to replace the your_api_key in the .env file with your actual API key.

REACT_APP_COUNTRY_STATE_CITY_API_KEY = your_api_key

Step 4: Wrap your component using ValueProvider.

Wrap your components using the ValueProvider component to ensure proper functionality.

import { ValueProvider } from "country-dropdown";

<ValueProvider>
    <YourComponents>
</ValueProvider>

Step 5: Import the Dropdown component and use it.

Import the Dropdown component and integrate it into your application, providing a suitable onChange function.

import { Dropdown, ValueProvider } from "country-dropdown";

<ValueProvider>
    <Dropdown
        onChange={(value, type) => handleChange(value, type)}
    />
</ValueProvider>

Prop NameTypeDescription
onChange(value: object, type: string) => voidA callback function triggered when the value of the dropdown changes. Receives the selected value and the type of dropdown (e.g., "Country", "State", "City").
dropdownOptions (optional)Array<string>An array of strings representing the dropdown options. Determines the number of dropdowns to display. Example: ["Country", "State", "City"].
cityPlaceholder (optional)stringThe placeholder text to display in the city dropdown.
statePlaceholder (optional)stringThe placeholder text to display in the state dropdown.
countryPlaceholder (optional)stringThe placeholder text to display in the country dropdown.
containerClassName (optional)stringA CSS class name or Tailwind classes to customize the styling of the container that wraps the dropdown component.
inputClassName (optional)stringA CSS class name or Tailwind classes to customize the styling of the dropdown input field.
optionItemClassName (optional)stringA CSS class name or Tailwind classes to customize the styling of the dropdown options.
optionItemSelectedClassName (optional)stringA CSS class name or Tailwind classes to customize the styling of the selected dropdown options.
optionsListClassName (optional)stringA CSS class name or Tailwind classes to customize the styling of the dropdown options list.
optionItemHoverClassName (optional)stringA CSS class name or Tailwind classes to customize the styling of the dropdown options when hovered. Use hover: for Tailwind classes and :hover for regular CSS classes.
defaultCountryValue (optional)stringThe ISO2 code for the default country to be selected if Country is not present in the dropdown options.
defaultStateValue (optional)stringThe ISO2 code for the default state to be selected if Country and State are not present in the dropdown options.
labelClasses (optional)stringA CSS class name or Tailwind classes to customize the styling of the input label.
cityLabel (optional)stringA label for the city dropdown.
countryLabel (optional)stringA label for the country dropdown.
stateLabel (optional)stringA label for the state dropdown.
cityDropdownName (optional)stringA name for the city dropdown.
stateDropdownName (optional)stringA name for the state dropdown.
countryDropdownName (optional)stringA name for the country dropdown.

Click here to visit Countries States Cities Demo for reference

Reference for ISO2 code

Use Dropdown with react-hook-form Library

import { DropdownWithReactHookForm } from "country-dropdown";

<DropdownWithReactHookForm
    onDropdownChange={(value, type) =>
        handleChange(value, type)
    }
    dropdownOptions={["City", "State", "Country"]}
/>

Prop NameTypeDescription
onDropdownChange(value: object, type: string) => voidA callback function triggered when the value of the dropdown changes. Receives the selected value and the type of dropdown (e.g., "Country", "State", "City").
dropdownOptions (optional)Array<string>An array of strings representing the dropdown options. Determines the number of dropdowns to display. Example: ["Country", "State", "City"].
cityPlaceholder (optional)stringThe placeholder text to display in the city dropdown.
statePlaceholder (optional)stringThe placeholder text to display in the state dropdown.
countryPlaceholder (optional)stringThe placeholder text to display in the country dropdown.
containerClassName (optional)stringA CSS class name or Tailwind classes to customize the styling of the container that wraps the dropdown component.
inputClassName (optional)stringA CSS class name or Tailwind classes to customize the styling of the dropdown input field.
optionItemClassName (optional)stringA CSS class name or Tailwind classes to customize the styling of the dropdown options.
optionItemSelectedClassName (optional)stringA CSS class name or Tailwind classes to customize the styling of the selected dropdown options.
optionsListClassName (optional)stringA CSS class name or Tailwind classes to customize the styling of the dropdown options list.
optionItemHoverClassName (optional)stringA CSS class name or Tailwind classes to customize the styling of the dropdown options when hovered. Use hover: for Tailwind classes and :hover for regular CSS classes.
defaultCountryValue (optional)stringThe ISO2 code for the default country to be selected if Country is not present in the dropdown options.
defaultStateValue (optional)stringThe ISO2 code for the default state to be selected if Country and State are not present in the dropdown options.
labelClasses (optional)stringA CSS class name or Tailwind classes to customize the styling of the input label.
cityLabel (optional)stringA label for the city dropdown.
countryLabel (optional)stringA label for the country dropdown.
stateLabel (optional)stringA label for the state dropdown.
cityDropdownName (optional)stringA name for the city dropdown.
stateDropdownName (optional)stringA name for the state dropdown.
countryDropdownName (optional)stringA name for the country dropdown.
errorClassNames (optional)stringCSS class name or Tailwind classes to customize the styling of the error message.
cityValidations (optional)RegisterOptionsValidations for city dropdown
stateValidations (optional)RegisterOptionsValidations for state dropdown
countryValidations (optional)RegisterOptionsValidations for country dropdown

Keywords

dropdown

FAQs

Package last updated on 18 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.