Gathering detailed insights and metrics for react-flag-icon-css
Gathering detailed insights and metrics for react-flag-icon-css
Gathering detailed insights and metrics for react-flag-icon-css
Gathering detailed insights and metrics for react-flag-icon-css
@types/react-flag-icon-css
TypeScript definitions for react-flag-icon-css
@native-html/css-processor
An inline CSS processor to translate CSS properties to React Native styles.
flag-icons
> A curated collection of all country flags in SVG — plus the CSS for easier integration. See the [demo](https://flagicons.lipis.dev).
identity-obj-proxy
an identity object using ES6 proxies
npm install react-flag-icon-css
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
86 Stars
267 Commits
13 Forks
4 Watching
374 Branches
1 Contributors
Updated on 18 Jun 2024
JavaScript (98.6%)
CSS (1.4%)
Cumulative downloads
Total Downloads
Last day
-23.2%
1,258
Compared to previous day
Last week
-1.6%
7,606
Compared to previous week
Last month
-1.4%
30,713
Compared to previous month
Last year
-27.3%
481,351
Compared to previous year
3
47
A simple React
SVG country flags component: it works with Css Modules
(default) or standard Css
.
React Flag Icon Css is distributed as an npm package.
We recommend installing and managing npm
packages with yarn
or npm 6
:
1$ yarn add react-flag-icon-css
or with npm
1:
1$ npm install --save react-flag-icon-css
1 You can omit --save if using npm >= 5.
create-react-app
appApps bootstrapped with create-react-app
support this module out of the box, just follow the Basic Usage example and remember to set useCssModules
to false
(create-react-app
does not currently support Css modules in its stable version, you can try the alpha but it will still not work with this module).
We recommend using the webpack 4
module bundler and ecosystem to assemble your app, even though this module works with webpack >= 1
and should also work with other bundlers.
If you are using webpack
, you will need to install and configure a few commmonly used modules - see the webpack 4 example project (also available for: webpack 3, webpack 2, and webpack 1).
1$ yarn add -D babel-loader css-loader file-loader style-loader extract-text-webpack-plugin
or with npm
:
1$ npm install --save-dev ...
Import FlagIconFactory
from react-flag-icon-css
, it accepts the React
module as the first argument and creates the FlagIcon
component (remove the @flow comment if you don't use Flow
, it does not have any effect). This approach ensures that FlagIcon
uses your app's React
instance, avoiding issues such as two versions of React
being loaded at the same time.
1/* your-app/your-components-directory/FlagIcon.js */ 2// @flow 3import * as React from 'react' 4import FlagIconFactory from 'react-flag-icon-css' 5 6// Please only use `FlagIconFactory` one time in your application, there is no 7// need to use it multiple times (it would slow down your app). You may place the 8// line below in a `FlagIcon.js` file in your 'components' directory, then 9// write `export default FlagIcon` as shown below and import it elsewhere in your app. 10const FlagIcon = FlagIconFactory(React) 11// If you are not using css modules, write the following: 12// const FlagIcon = FlagIconFactory(React, { useCssModules: false }) 13 14export default FlagIcon
1/* your-app/App.js */ 2// @flow 3import * as React from 'react'; 4import ReactDOM from 'react-dom' 5import FlagIcon from './your-components-directory/FlagIcon.js' 6 7const App = (props = {}) => 8 <div> 9 <FlagIcon code={props.code} size={props.size} /> 10 </div> 11 12const rootEL = document.body.querySelector('#app') 13 14const appProps = { code: 'it', size: '3x' } 15ReactDOM.render(<App {...appProps} />, rootEL)
A webpack 3
example project is available (webpack 2 and webpack 1 versions).
The entries marked with *
are required.
Prop | Type | Flow Type | Default | Description | Supported values |
---|---|---|---|---|---|
code * | String | FlagIconCodeType 1 | ISO 3166-1-alpha-2 code. | The list is here. | |
size | String | FlagIconSizeType | lg, 2x, 3x, 4x, 5x | ||
flip | String | FlagIconFlipType | horizontal, vertical | ||
rotate | Number | FlagIconRotateType | 30, 60, 90, 180, 270 | ||
squared | Boolean | boolean | false | Uses the 1x1 image if true . | |
Component | String | string | span | e.g span , div | |
className | String | string | This is always appended as-is to class in the HTML. | e.g some-class | |
styleName | String | string | This is mapped to a CSS module and appended to class inthe HTML. | e.g some-class | |
Children | String | React$Element<*> | React element. | e.g <Something /> |
Remember to always build FlagIcon
with FlagIconFactory
.
1 Upgrade to version 1.0.17 or later of this module.
The entries marked with *
are required.
Argument | Type | Flow Type | Description | Supported values |
---|---|---|---|---|
React * | Module | ReactModule | Your app's React instance. | Versions in peerDependencies. |
options | Object | FlagIconOptionsType | See FlagIconFactory options below. |
Argument | Type | Flow Type | Description | Supported values | Default |
---|---|---|---|---|---|
useCssModules | Boolean | Boolean | Use CSS modules styles (your module bundler must be correctly setup). | true , false | true |
customCodes 2 | Object | Object | An object literal whose keys are your custom codes. Example. | ||
themeStyles | Object | CssModule | Set this if useCssModules is true and a) you want to apply styles to FlagIcon using .theme-base and/orb) you are using custom flags. |
2 Upgrade to version 1.0.17 or later of this module.
This module has 0 Flow errors on flow-bin
version: ^0.76.0.
If in your app you are using a Flow version that is the same or newer than that, you should not need any specific configuration excluding the installation of the flow-typed definition for prop-types
(you may also take the opportunity to install definitions for all your app's modules using flow-typed).
However, if in your app you are using a newer or particularly older version (not recommended) of Flow, it may throw warnings or errors. Please open an issue or submit a pull request if this module has not yet been made compatible with a newer Flow version.
FlagIconFactory options.customCodes
to make this module aware of your codes. Otherwise: runtime warnings in development (and Flow errors, if you use it).Css Modules
, import your styles in someVariable
and set FlagIconFactory options.themeStyles
to someVariable
. Otherwise: runtime Css Modules
errors.Flow
use CustomFlagIconFactory
and not FlagIconFactory
. Otherwise: Flow
errors.We recommend organizing your custom flags in a folder similar to example-custom-flags
. You may copy-paste it in the root of your app and replace the codes and images.
Example folder structure:
|-- app.js
|-- example-custom-flags
|--index.js
|--istyles.css
|--images
|--1x1
|--ex1.svg
|--ex2.svg
|--ex3.svg
|--4x3
|--ex1.svg
|--ex2.svg
|--ex3.svg
Write the styles for each one of your codes, and load the appropriate images:
1/* example-custom-flags/styles.css */ 2/** 3 * Note: you can use PostCSS, SASS or whatever preprocessor your 4 * app is using here. 5 */ 6.flag-icon-ex1 { 7 background-image: url(../images/4x3/ex1.svg); 8} 9 10.flag-icon-ex1.flag-icon-squared { 11 background-image: url(../images/1x1/ex1.svg); 12} 13 14/* ... */ 15
Import the styles and export them and the object with your codes:
1/* example-custom-flags/index.js */ 2import styles from './styles.css' 3 4const codes = { 5 ex1: 'Example 1 country', 6 ex2: 'Example 2 country', 7 ex3: 'Example 3 country', 8} 9 10// You can comment or remove the following line if you don't use Facebook's Flow. 11export type CustomCodeType = $Keys<typeof codes> 12 13export { styles, codes }
Import CustomFlagIconFactory
in your app and build FlagIcon
as shown:
1/* app.js */ 2// @flow 3import React from 'react' 4import { CustomFlagIconFactory } from 'react-flag-icon-css' 5import { styles, codes } from './my-custom-flags' 6 7// Using 'react-css-modules'? Use this: 8const optionsCssModules = { customCodes: codes, themeStyles: styles } 9const FlagIconCssModules = CustomFlagIconFactory(React, optionsCssModules) 10 11// Using global CSS? Use this instead: 12const options = { useCssModules: false, customCodes: codes } 13const FlagIcon = CustomFlagIconFactory(React, options) 14
Note: when you build FlagIcon with CustomFlagIconFactory, it can be used with both built-in and custom codes.
Runtime type checking: in development mode (process.env.NODE_ENV !== 'production'
), when using unsupported props or prop values, you are warned at runtime by Failed prop type errors in the browser console. Feature powered by prop-types
.
Static type checking:
If you use Facebook's flow
in your app (otherwise you can skip this section, unless you want to submit a pull request), it should automatically pick up this package's definitions from the .js.flow
files that are distributed with it, checking your code accordingly when you run yarn flow
. Using the latest Flow
version or the version in ./package.json
is recommended. We also recommend using a Flow
-aware editor such as Nuclide
for Atom
.
If you use Microsoft's TypeScript
in your app (otherwise you can skip this section, unless you want to submit a pull request), the package that contains the type definitions for this module is: @types/react-flag-icon-css.
Contributions are welcome:
:pencil2: Write code: use a topic branch, follow the AngularJS commit style guidelines and check that yarn prepublish
(build, test, type checking, linting ...) returns zero errors before opening a PR. If you want to make major modifications to the code, please open an issue to discuss them first.
:bug: Report a bug: first, search all issues. If nothing turns up, open a new issue and be as specific as possible, so that we can reproduce your setup and find out if it is a bug or a configuration issue.
:triangular_ruler: Propose a feature: first, search all issues. If nothing turns up, open a new issue and describe what the proposed feature should do, why you think it is important and an example use case.
Thanks! :blue_heart:
:star: Starring it lets you keep track of this project and helps more people discover it.
This project uses the great SVG country flags from flag-icon-css.
This project is licensed under the terms of the MIT license.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/22 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
71 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More