npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-flags-select

v2.2.3

Published

react-flags-select React component

Downloads

106,191

Readme

react-flags-select

A React library that provides a customizable SVG flags select components and standalone SVG flags components.

Demo and Example

Live demo: ekwonye-richard.github.io/react-flags-select/

Installation

yarn add react-flags-select
npm install react-flags-select --save

Usage

ReactFlagsSelect

import React, { useState } from "react";
import ReactFlagsSelect from "react-flags-select";

const App = () => {
  const [selected, setSelected] = useState("");

  <ReactFlagsSelect
    selected={selected}
    onSelect={(code) => setSelected(code)}
  />;
};

export default App;

Country Flag

import React from "react";
import { Us } from "react-flags-select";

const Region = () => (
  <div>
    <Us /> United States
  </div>
);

export default Region;

Country Codes

Full list of Country Codes.

Props

selected

selected is a required string prop that holds the current value of the input.

    <ReactFlagsSelect
      ...
      selected={selected}
    />

onSelect

onSelect is a required function prop which recieves the user selected countryCode which should be used to update the selected value.

    <ReactFlagsSelect
      ...
      onSelect={code => setSelected(code)}
    />

placeholder

placeholder is an optional string prop used replace the default placeholder text for the select input.

<ReactFlagsSelect
  countries={["US", "GB", "FR", "DE", "IT"]}
  customLabels={{ US: "EN-US", GB: "EN-GB", FR: "FR", DE: "DE", IT: "IT" }}
  placeholder="Select Language"
/>

searchable

searchable is an optional boolean prop used which add the option to search through the options list. The default value is false.

    <ReactFlagsSelect
      ...
      searchable
    />

searchPlaceholder

searchPlaceholder is an optional string prop used replace the default placeholder text for the search input.

    <ReactFlagsSelect
      ...
      searchPlaceholder="Search countries"
    />

countries

countries is an optional array of string used replace the default full list of countries. Only countries included in the full list are valid.

    <ReactFlagsSelect
      ...
      countries={["US", "GB", "FR", "DE", "IT", "NG"]}
    />

blacklistCountries

blacklistCountries is an optional boolean prop used to indicate the countries prop should be used as blacklisted, hence these countries will be excluded in the options. The defaut value is false.

    <ReactFlagsSelect
      ...
      countries={["US", "GB", "FR", "DE", "IT", "NG"]}
      blacklistCountries
    />

customLabels

customLabels is an optional object prop used to define custom labels. The default country name for a country code will be used when the country code has no label passed.

    <ReactFlagsSelect
      ...
      customLabels={{"US": "EN-US","GB": "EN-GB","FR": "FR","DE": "DE","IT": "IT"}} />
    />

customLabels now also accepts an array of objects (CustomLabel) instead of an array of strings. The default country name will still be shown if no label is passed. Also the secondary label will only be shown if there is one present.

    <ReactFlagsSelect
      ...
      customLabels={{
        "US": { primary: "EN-US", secondary: "+1" },
        "GB": { primary: "EN-GB", secondary: "+44" },
        "FR": { primary: "FR" }
      }}
      />
    />

customLabels can also be mixed between CustomLabel and string.

    <ReactFlagsSelect
      ...
      customLabels={{
        "US": { primary: "EN-US", secondary: "+1" },
        "GB": { primary: "EN-GB", secondary: "+44" },
        "FR": "FR"
      }}
      />
    />

showSelectedLabel

showSelectedLabel is a an optional boolean prop used to show or hide the label text of a selected country. The default value is true.

    <ReactFlagsSelect
      ...
      showSelectedLabel={false}
    />

showSecondarySelectedLabel

showSecondarySelectedLabel is an optional boolean prop used to show or hide the secondary label text of a selected country. The default value is true.

    <ReactFlagsSelect
      ...
      showSecondarySelectedLabel={false}
    />

showOptionLabel

showOptionLabel is a an optional boolean prop used to show or hide the label text of countries in the options dropdown. The default value is true.

    <ReactFlagsSelect
      ...
      showOptionLabel={false}
    />

showSecondaryOptionLabel

showSecondaryOptionLabel is a an optional boolean prop used to show or hide the secondary label text of a countries in the options dropdown. The default value is true.

    <ReactFlagsSelect
      ...
      showSecondaryOptionLabel={false}
    />

selectedSize

selectedSize is an optional number prop used to set the size in pixels of the selected label and the corresponding flag.

    <ReactFlagsSelect
      ...
      selectedSize={14}
    />

optionsSize

optionsSize is an optional number prop used to set the size in pixels of the options labels and the corresponding flags.

    <ReactFlagsSelect
      ...
      optionsSize={14}
    />

className

className is an optional string prop used to pass a className to the top container of the Select component.

    <ReactFlagsSelect
      ...
      className="menu-flags"
    />

selectButtonClassName

selectButtonClassName is an optional string prop used to pass a className to the select button.

    <ReactFlagsSelect
      ...
      selectButtonClassName="menu-flags-button"
    />

fullWidth

fullWidth is an optional boolean prop used to decide if the Select component should render as a block element or inline element. The default value is true which is a block element.

    <ReactFlagsSelect
      ...
      fullWidth={false}
    />

alignOptionsToRight

alignOptionsToRight is an optional boolean prop useful when fullWidth is false to set the options alignment to right. The default value is false.

    <ReactFlagsSelect
      ...
      alignOptionsToRight
    />

disabled

disabled is a boolean prop used to disable to the Select component. The default value is false.

    <ReactFlagsSelect
      ...
      disabled
    />

id

id is a string prop used to set the id of the top container of the Select component.

    <ReactFlagsSelect
      ...
      id="flags-select"
    />

rfsKey

rfsKey is a string prop used to generate ids, data-testids and the search input's name. The default value us rfs. You should have unique rfsKey props when rendering multiple ReactFlagsSelect at the same time.

    <ReactFlagsSelect
      ...
      rfsKey="app-lang"
    />

Flags

Each country flag can be rendered as a SVG component. The components are named by countries Iso2 codes in pascal case.

<GB />

The SVG viewBox is preserved and SVG inherits it's parent element's text size.

Contribution

This project is written in Typescript and developed with Storybook. Tests are written with Jest and React Testing Library. Raise a pull request with your changes.

Installation

yarn install

Start Storybook

Builds SVG components to `src/components/Flags/Countries/

yarn start

v1 Documentation

React Flags Select v1

License

This project is distributed under the MIT license.