@mwid/react-country-picker
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

🌐 React Country Picker

A country picker component with real-time autocomplete, built with React.

Installation

# npm
npm install @mwid/react-country-picker

# Yarn
yarn add @mwid/react-country-picker

# pnpm
pnpm add @mwid/react-country-picker

Usage

Import:

// TypeScript / ESModules
import { CountryPicker } from "@mwid/react-country-picker";

// CommonJS
const { CountryPicker } = require("@mwid/react-country-picker");

Create a callback for when a country is selected:

const onSelect = useCallback(() => {
	// Do something
}, []);

Add the CountryPicker component to your JSX:

<CountryPicker onSelect={onSelect} />

Props

Property Type Default Description
onSelect (country: Country) => void Called when a country is selected from the country list.

Where Country is:

interface Country {
	officialName: string;
	commonName: string;
	flagSvgUrl: string;
}

Architecture

Project Structure

src/ Description
api All API requests and their request and response body interfaces.

Each request should be prefixed with its HTTP method (Eg, GET /countries/all -> getAllCountries) and their request/responses named similarly (Eg, getAllCountriesRequest and getAllCountriesResponse).
components React components.

Each component resides in its own directory, and sub-components that only it uses are nested under it.

Storybook stories are placed in component.stories.tsx, unit tests are placed in component.test.tsx and styled-components primitives are placed in component.style.tsx.
config Configuration-related items (that may be changed via environment variables) and constant values.
hooks Custom hooks shared across the entire component.
lib Re-exports of library functions and factories. Eg, create a database connection instance.
slices Redux state slices.

Actions are placed in slice.actions.ts, reducers are placed in slice.reducer.ts, selectors are placed in slice.selectors.ts and entity adapters are placed in entity.entity.ts.
test Test-specific configuration and setup.

Fixtures define unchanging mock data used across multiple tests.
types TypeScript types used across the component to define a contract on the structure of data.
utils Reusable utility functions and types.

Technology

Tooling

Front-end

Local Development

Install Node:

curl -L https://git.io/n-install | bash
n auto

Install dependencies:

npm i

Run unit and integration tests:

npm t

Develop in Storybook:

npm run storybook

Build for production:

npm run build

npm Scripts

Script Description
build Build code for production with TypeScript.
format:check Check all code formatting with Prettier.
format:write Fix all code formatting with Prettier.
lint Lint all code with ESLint.
test Run all unit and integration tests.
storybook Start the Storybook development server.
storybook:build Build Storybook for publishing.

License

This project is licensed under the MIT license.

Readme

Keywords

none

Package Sidebar

Install

npm i @mwid/react-country-picker

Weekly Downloads

4

Version

0.1.0

License

MIT

Unpacked Size

1.54 MB

Total Files

165

Last publish

Collaborators

  • mwid