GithubHelp home page GithubHelp logo

ptzagk / react-flags-select Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ekwonye-richard/react-flags-select

0.0 0.0 0.0 18.31 MB

Customizable svg flags select components for React Js

JavaScript 6.23% SCSS 5.37% HTML 0.43% TypeScript 87.97%

react-flags-select's Introduction

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 a 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 a 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"
    />

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.

react-flags-select's People

Contributors

ekwonye-richard avatar eokoneyo avatar gh-action-bump-version avatar henri-vdm avatar sreenathmp avatar ikorovictor avatar a-tokyo avatar kevinbull avatar thomasdseao avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.