0.1.0 • Published 2 years ago

@mwid/react-country-picker v0.1.0

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

🌐 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

PropertyTypeDefaultDescription
onSelect(country: Country) => voidCalled 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
apiAll 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).
componentsReact 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.
configConfiguration-related items (that may be changed via environment variables) and constant values.
hooksCustom hooks shared across the entire component.
libRe-exports of library functions and factories. Eg, create a database connection instance.
slicesRedux 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.
testTest-specific configuration and setup.Fixtures define unchanging mock data used across multiple tests.
typesTypeScript types used across the component to define a contract on the structure of data.
utilsReusable 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

ScriptDescription
buildBuild code for production with TypeScript.
format:checkCheck all code formatting with Prettier.
format:writeFix all code formatting with Prettier.
lintLint all code with ESLint.
testRun all unit and integration tests.
storybookStart the Storybook development server.
storybook:buildBuild Storybook for publishing.

License

This project is licensed under the MIT license.