Giter Club home page Giter Club logo

vue-country-flag's Introduction

vue-country-flag

Country flags as a Vue Component

vue-country-flag

Monthly downloads Install size Vue.js 2 compatible Vue.js 3 compatible Version License TypeScript Supported

Vue 3 support

Since version 2.0.3, this component supports both Vue2 and Vue3 support.

In order to use it with Vue 3, please install the vue-country-flag-next package as follows:

npm install vue-country-flag-next

Vue 2 support

How to install

Get the package from NPM:

npm install vue-country-flag

How to use the component

Register CountryFlag component in your app. You can use two approaches:

  • in main.js you can mount it as a global Vue component:
import Vue from 'vue'
import CountryFlag from 'vue-country-flag'

Vue.component('country-flag', CountryFlag)
  • in a specific component (e.g.: Component.vue):
import CountryFlag from 'vue-country-flag'

new Vue({
    components: {
        CountryFlag
    }
})

Then, after the proper mounting, in your template you can call it like this:

    <country-flag country='it' size='big'/>
    <country-flag country='hr' size='normal'/>
    <country-flag country='fr' size='small'/>
    <country-flag country='rus'/>

API

Mandatory properties

Property Description Type Value
country ISO 3166-1 identifier of the country String one of the values defined here or in the extra flags

Optional properties

Property Description Type Value
size Flag size String small, normal, big
rounded Flag with rounded borders Boolean false by default
shadow Flag with box shadow around Boolean false by default
background Path where you can upload possible custom flag images String by default it uses the flags bundled in the component

by default, the flag is displayed at normal size.

Available Flags

The flags are identified using the ISO 3166-1 standard.
This component currently supports both alpha-2 and alpha-3 alternatives.

Country Name alpha-2 alpha-3
Afghanistan af afg
Åland Islands ax ala
Albania al alb
Algeria dz dza
American Samoa as asm
Andorra ad and
Angola ao ago
Anguilla ai aia
Antarctica aq ata
Antigua and Barbuda ag atg
Argentina ar arg
Armenia am arm
Aruba aw abw
Australia au aus
Austria at aut
Azerbaijan az aze
Bahamas bs bhs
Bahrain bh bhr
Bangladesh bd bgd
Barbados bb brb
Belarus by blr
Belgium be bel
Belize bz blz
Benin bj ben
Bermuda bm bmu
Bhutan bt btn
Bolivia (Plurinational State of) bo bol
Bonaire, Sint Eustatius and Saba bq bes
Bosnia and Herzegovina ba bih
Botswana bw bwa
Bouvet Island bv bvt
Brazil br bra
Virgin Islands (British) vg vgb
British Indian Ocean Territory io iot
Brunei Darussalam bn brn
Bulgaria bg bgr
Burkina Faso bf bfa
Burundi bi bdi
Cambodia kh khm
Cameroon cm cmr
Canada ca can
Cabo Verde cv cpv
Cayman Islands ky cym
Central African Republic cf caf
Chad td tcd
Chile cl chl
China cn chn
Hong Kong hk hkg
Macao mo mac
Christmas Island cx cxr
Cocos (Keeling) Islands cc cck
Colombia co col
Comoros km com
Congo cg cog
Congo, Democratic Republic of the cd cod
Cook Islands ck cok
Costa Rica cr cri
Côte d'Ivoire ci civ
Croatia hr hrv
Cuba cu cub
Curaçao cw cuw
Cyprus cy cyp
Czechia cz cze
Denmark dk dnk
Djibouti dj dji
Dominica dm dma
Dominican Republic do dom
Ecuador ec ecu
Egypt eg egy
El Salvador sv slv
Equatorial Guinea gq gnq
Eritrea er eri
Estonia ee est
Ethiopia et eth
Falkland Islands (Malvinas) fk flk
Faroe Islands fo fro
Fiji fj fji
Finland fi fin
France fr fra
French Guiana gf guf
French Polynesia pf pyf
French Southern Territories tf atf
Gabon ga gab
Gambia gm gmb
Georgia ge geo
Germany de deu
Ghana gh gha
Gibraltar gi gib
Greece gr grc
Greenland gl grl
Grenada gd grd
Guadeloupe gp glp
Guam gu gum
Guatemala gt gtm
Guernsey gg ggy
Guinea gn gin
Guinea-Bissau gw gnb
Guyana gy guy
Haiti ht hti
Heard Island and McDonald Islands hm hmd
Holy See va vat
Honduras hn hnd
Hungary hu hun
Iceland is isl
India in ind
Indonesia id idn
Iran (Islamic Republic of) ir irn
Iraq iq irq
Ireland ie irl
Isle of Man im imn
Israel il isr
Italy it ita
Jamaica jm jam
Japan jp jpn
Jersey je jey
Jordan jo jor
Kazakhstan kz kaz
Kenya ke ken
Kiribati ki kir
Korea (Democratic People's Republic of) kp prk
Korea, Republic of kr kor
Kuwait kw kwt
Kyrgyzstan kg kgz
Lao People's Democratic Republic la lao
Latvia lv lva
Lebanon lb lbn
Lesotho ls lso
Liberia lr lbr
Libya ly lby
Liechtenstein li lie
Lithuania lt ltu
Luxembourg lu lux
North Macedonia mk mkd
Madagascar mg mdg
Malawi mw mwi
Malaysia my mys
Maldives mv mdv
Mali ml mli
Malta mt mlt
Marshall Islands mh mhl
Martinique mq mtq
Mauritania mr mrt
Mauritius mu mus
Mayotte yt myt
Mexico mx mex
Micronesia (Federated States of) fm fsm
Moldova, Republic of md mda
Monaco mc mco
Mongolia mn mng
Montenegro me mne
Montserrat ms msr
Morocco ma mar
Mozambique mz moz
Myanmar mm mmr
Namibia na nam
Nauru nr nru
Nepal np npl
Netherlands nl nld
New Caledonia nc ncl
New Zealand nz nzl
Nicaragua ni nic
Niger ne ner
Nigeria ng nga
Niue nu niu
Norfolk Island nf nfk
Northern Mariana Islands mp mnp
Norway no nor
Oman om omn
Pakistan pk pak
Palau pw plw
Palestine, State of ps pse
Panama pa pan
Papua New Guinea pg png
Paraguay py pry
Peru pe per
Philippines ph phl
Pitcairn pn pcn
Poland pl pol
Portugal pt prt
Puerto Rico pr pri
Qatar qa qat
Réunion re reu
Romania ro rou
Russian Federation ru rus
Rwanda rw rwa
Saint Barthélemy bl blm
Saint Helena, Ascension and Tristan da Cunha sh shn
Saint Kitts and Nevis kn kna
Saint Lucia lc lca
Saint Martin (French part) mf maf
Saint Pierre and Miquelon pm spm
Saint Vincent and the Grenadines vc vct
Samoa ws wsm
San Marino sm smr
Sao Tome and Principe st stp
Saudi Arabia sa sau
Senegal sn sen
Serbia rs srb
Seychelles sc syc
Sierra Leone sl sle
Singapore sg sgp
Sint Maarten (Dutch part) sx sxm
Slovakia sk svk
Slovenia si svn
Solomon Islands sb slb
Somalia so som
South Africa za zaf
South Georgia and the South Sandwich Islands gs sgs
South Sudan ss ssd
Soviet Union su sun
Spain es esp
Sri Lanka lk lka
Sudan sd sdn
Suriname sr sur
Svalbard and Jan Mayen sj sjm
Eswatini sz swz
Sweden se swe
Switzerland ch che
Syrian Arab Republic sy syr
Taiwan, Province of China tw twn
Tajikistan tj tjk
Tanzania, United Republic of tz tza
Thailand th tha
Timor-Leste tl tls
Togo tg tgo
Tokelau tk tkl
Tonga to ton
Trinidad and Tobago tt tto
Tunisia tn tun
Turkey tr tur
Turkmenistan tm tkm
Turks and Caicos Islands tc tca
Tuvalu tv tuv
Uganda ug uga
Ukraine ua ukr
United Arab Emirates ae are
United Kingdom of Great Britain and Northern Ireland gb gbr
United States of America us usa
United States Minor Outlying Islands um umi
Uruguay uy ury
Uzbekistan uz uzb
Vanuatu vu vut
Venezuela (Bolivarian Republic of) ve ven
Viet Nam vn vnm
Virgin Islands (U.S.) vi vir
Wallis and Futuna wf wlf
Western Sahara eh esh
Yemen ye yem
Zambia zm zmb
Zimbabwe zw zwe

Extra flags

Country Name Flag Code
Catalonia es-ca
England gb-eng
Europe eu
Galles gb-wls
Kosovo xk
Scotland gb-sct
United Nations un

Credits

The flags used for this Vue components are provided by Flag Icons CSS.

Contributing

Please follow the guidelines here.

Building the packages

During development of the project, you might want to build the packages. This project uses Lerna to manage the two packages.

To build either or both packages, you first need to bootstrap Lerna. From the project root, run:

$ npm run bootstrap

After Lerna has been bootstrapped, you can use the build and build:next scripts defined in package.json:

$ npm run build

$ npm run build:next

See package.json for a full overview of the different build targets.

vue-country-flag's People

Contributors

dependabot[bot] avatar igorbabko avatar mannew avatar p3trur0 avatar rlizana avatar s-sasaki-0529 avatar ubaldop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vue-country-flag's Issues

[bug]vue2,can not work

<el-table-column label="C"  width="110px"><country-flag :country='ipInfo.countryCode' size='small'></country-flag></el-table-column>

Type definition file for TypeScript is missing

When I use TypeScript and import this lib, I got the error inside of VSCode and via serve, that the typedef file is missing. If it is easy for you, please add it. Otherwise, I will have a look later to generate one, when I have time.

Support typscript in vue-country-flag-next

I'm using the next library in a Vue 3 project with Typescript. When I import the library with import CountryFlag from 'vue-country-flag-next'; I get this error Cannot find module 'vue-country-flag-next' or its corresponding type declarations.

I created a new file vue-country-flag-next.d.ts in my project with declare module 'vue-country-flag-next'; as a workaround but It could be nice to support typing :D

Belarussian flag

My greetings to the support team!

I'm writing to you for the Republic of Belarus. As you could possibly know, dictator Lukashenko had falsified a presidential election on 9 August 2020 once again. He had usurped the power and jailed or forced to leave the country those considered to be his political opponents. The election's results had been denied by all of the EU members and all of them have supported the will of the people of this nation. It has been more than 1.5 years since the protests' outbreak, more than 30.000 people have been thrown in jails, and at least 10 people were killed (either shot or slaughtered).

The historical flag of a red horizontal stripe between two white ones, which has more than 100 years of history, has become a symbol of protest. 26 years ago, when Lukashenko came to power, he changed the flag and the emblem to those adopted from the Soviet Union.

These symbols are associated with lies and violence of the regime by the absolute majority of citizens this day.

The historical flag might be found here: https://github.com/egorikftp/Belarus-Flags-Museum/blob/release/app/src/main/ic_launcher-playstore.png

It is my duty to ask you to add the possibility of adding the alternative flag for Belarus to the library. It is a highly important issue for the thousands of Belarussians who keep using it. Thank you in advance!

does not work in SSR

Tried in quasar SSR app component. Triggers error at click/show component CountryFlag.

runtime-dom.esm-bundler.js?8886:34 Uncaught (in promise) TypeError: Cannot read property 'parentNode' of null
at parentNode (runtime-dom.esm-bundler.js?8886:34)
at componentEffect (runtime-core.esm-bundler.js?9e79:5276)
at Object.reactiveEffect [as update] (reactivity.esm-bundler.js?0a2b:42)
at updateComponent (runtime-core.esm-bundler.js?9e79:5142)
at processComponent (runtime-core.esm-bundler.js?9e79:5075)
at patch (runtime-core.esm-bundler.js?9e79:4673)
at patchKeyedChildren (runtime-core.esm-bundler.js?9e79:5414)
at patchChildren (runtime-core.esm-bundler.js?9e79:5357)
at patchElement (runtime-core.esm-bundler.js?9e79:4948)
at processElement (runtime-core.esm-bundler.js?9e79:4757)

missing flags css after fresh install

Hello!
Thank you for sharing package
but after installation by

npm i vue-country-flag
+ [email protected]
added 1 package from 1 contributor and audited 939528 packages in 26.977s

I am getting error:

This relative module was not found:
* ./css/flags/flags.min.css in ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./node_modules/vue-country-flag/src/CountryFlag.vue?vue&type=script&lang=js&

And I have double-checked there is no such folder as css in src in node_modules, I can see it here on github.. but probably problem is in package.json:

"files": [
    "dist/*",
    "src/**/*.vue"
  ],

as you can see css is not included

I have used:
npm -v
6.13.4
for installation

I have tried yarn 1.15.2 .. but same result

Thanks :)

get rid of hidden margin?

Right now the sprites seem to have some sort of hidden margin, possibly described in issue #14

I would like the flag sprite to have no margin at all, and to be exactly as big as the sprite itself, so that I can avoid issues like this:

image

Where there is a huge hidden margin (padding?) that won't allow the flag to align with the flexbox's aligh-items: flex-end prop:

image

The height of the <span> that the package renders is fine I think

image

But the browser tools show a different height/width without margin or padding:

image

For reference, here's the element in the console:

image

Issues in Vue 3

I'm getting the following error in Vue 3:

Uncaught (in promise) Error: Dynamic require of "node_modules/vue-country-flag-next/dist/flags.png" is not supported

I tried importing directly in the Component and globally.

import CountryFlag from "vue-country-flag-next"

  components: {
    CountryFlag,
  }

      <template v-slot:[`item.country`]="{ item, highlightMatches }">
        <td v-html="highlightMatches(item.country)"></td>
        <country-flag :country="item.country" size="small" />
      </template>

could we add label prop?

Hi thanks for this handy package.
is it possible add label prop so that user can customize the display label? current it is display country code, if we need display something else there is no way do it. thanks for considering.

Flags have incorrect size on IE & Edge browser

Hi,

there is something wrong with displaying flags on IE/Edge. They don't have inline style for transform scale, so provided size doesn't apply. On Chrome, Firefox & Opera problem doesn't exist.

Only workaround I found to set inline style manually.

This dependency was not found (vue3 + vue-country-flag-next)

Hello,

I've added the dependency vue-country-flag-next using yarn in my project, and followed the doc to register the component, but I get the following error

 ERROR  Failed to compile with 1 error                                                                                                                                                                             11:38:05
This dependency was not found:

* vue-country-flag in ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader-v16/dist??ref--0-1!./src/components/LocaleSwitcher.vue?vue&type=script&lang=js

To install it, you can run: npm install --save vue-country-flag

Here is how I registered it

<template>
 <country-flag :country="locale" size="big"/></option>
</template>

<script>
import CountryFlag from 'vue-country-flag'

export default {
  components: {
    CountryFlag
  }
}
</script>

Not working with Vue 3?

Hi, tried with Vue 3 but seems not working?

fix for Vue 3

change this
import CountryFlag from 'vue-country-flag-icon'
to this
import CountryFlag from 'vue-country-flag-next'

White empty space for non-existing countries

Hi! There is white empty space instead of nothing if prop country is a non-existing country code. It's weird.
There should be some kind of validation to check the existence of such a country code to render Flag component.
image

White Flags on White Background

Flags that have white backgrounds such as Japan, Monaco, Madagascar
white background flags
(and many others) do not look like flags when displayed on white backgrounds. We wanted to add some slight elevation to the flags by adding a box shadow. However, upon looking closely at flags.png, not all the flags are of equal width making the box-shadow look inconsistent. And this is not even taking into account the 3px white space on the left and right sides (why do you need that?) which I had to account for as well.
flags with boxshadow whitespace

My suggestion is 3 things:

  1. Can we make all the flags the same width in flags.png
  2. Can we remove the white space in the left and right sides
  3. Make elevation (box shadow) a prop??

At the very least #1 would be required. #2 can be handled by css on my end if you don't agree.

vue-country-flag/dist/flags.png 404 not found

Stack

  • nuxt v2.15.6
  • vue-country-flag v2.1.1

reproduction link
Just a simple yarn create nuxt-app with vue-country-flag dependency.

Problem
When I use the country-flag component I get a 404 for http://localhost:3000/vue-country-flag/dist/flags.png on initial render (SSR).
Is it possible to get vue-country-flag working in SSR mode?

Workaround
Wrap it around special component who disable SSR.

Nuxt: Sizes not working

Hi,
I can't get the sizes to work in Nuxt. I think I might be missing something?

@plugins/vue-flags.js

import Vue from 'vue';
import CountryFlag from 'vue-country-flag';

Vue.use(CountryFlag);

in my nuxt.config

  plugins: [
    { src: '@/plugins/vue-flags.js' }
]

and in a component I want to use it in,

 <CountryFlag country="fr" size="small" />

Yet the size attribute doesn't do anything, it's always normal size which is too big for my use case.

I might be missing a step or it just doesn't work with Nuxt?

Failure to render in CodeSandbox

Let me be clear that I think this is 100% not your fault, but on the off chance it is a bug on this side, or something that can be adjusted, I thought I'd file it. I know it isn't your job to support an online editor, but again I figured it couldn't hurt to mention it. :)

So long story short, the component doesn't work in Code Sandbox. You can see my code here:

https://codesandbox.io/s/vue-template-tn6p7?fontsize=14

I see nothing in the logs, nor the console. However, the same code, exported and ran locally on my machine, works fine.

Again, feel free to close, but if it's a small thing that could be addressed, I thought I'd share. Thank you for reading!

Reduce the footprint

It could be cool to reduce the footprint of the component.
Possible approaches:

  • avoid to bundle minified CSS in each built .js file
  • find an alternative to Base64 sprite bundled in CSS (as pointed in #21)

USSR flag request ☭

Hello.

Before USSR destruction people of USSR voted to save USSR, but leaders of UA Kravchuk, BLR Shuskevich and Russia Eltsin dissolved USSR in 1991.

Current Russian flag has controversial associations for many people, specially since WW2.
It is highly important for dozens of Russians to use USSR flag.

https://en.wikipedia.org/wiki/Flag_of_the_Soviet_Union

Thank you for understanding.

Add CSP support

Remove inline styles (styleInject) to support CSP (Content Security Policy).

Error:
image

Typings

There are no typings in this package. They aren't listed in package.json and the unused d.ts files are only declaring its existence without any further description of what the component properties are, or that there is a component in the first place. Take a look at the excellent typings in bootstrap-vue.

Flags invisible for Android chrome browser

Tried both alpha 2 and alpha 3 ISSO 3166-1 it gives error. Secondly the flags are bit blurry for Firefox. Please let me know what are the supporting changes to be importantly for chrome android app. Thanks in advance.

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '_c')

I installed latest version (2.3.2).
My vue js version is 3.2.26.

Following the docs, after importing & registering in specific component, I use e.g. the following:
<country-flag country='fr' size='small'/>
The error I get is

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '_c')
    at Proxy.__vue_render__ (country-flag.esm.js?eea2:231:1) etc..

I get the error from line 231 in country-flag.esm.js
Any ideas?

vue-country-flag-next relies on imports from vue-country-flag

for vue-country-flag-next, seems there are still some imports relying on vue-country-flag

Error: ENOENT: no such file or diru/Documents/apps//node_modules/vue-country-flag.esm.js'
at Object.openSync (node:fs:59
at Object.readFileSync (node:f

.f isn't scoped to the componet

Any element with the class of .f is being styled by the styles in this component.

In our application, our customers are allowed to create or provide supplemental HTML, and some customers use 'f' as a class. This is causing many of their UIR elements to appear broken.

Space still available after scaling

As you can see it here in my image:

image

I use the medium flag. The problem is, that the space around is to high. It comes from the width/height 64px whily you scale it down to half of it. So it will show 32px but it will keep the original height/width. Just scaled down.

When I override the 64px with e.g. 32px (due to medium that I want) the position of the css-sprite is not correct anymore. See:

image

So I can try to fix the CSS for my needs (could be tricky) or it should be an option to shrink it really down to the exact size. Or you should have different css-sprites for small, medium, large (?).

Invalid or unexpected token

"vue-country-flag": "^2.1.0"
"nuxt": "^2.15.4"

I get an error: Invalid or unexpected token. It was working with ^2.0.4. The error occurs because of the SSR.

Flag sprite is Base64 Encoded causing a 30% increase in size

Just thought you should know that Base64 encoding images should be avoided. See: https://stackoverflow.com/a/11402374/2719773

The production JS files seem to have the flag sprite embedded as a Base64 string. I think that this is not necessary. Modern server and HTTP protocols help minimize the impact of making multiple requests for resources. I think that it will have a better impact on overall build sizes with minimal performance impact by requesting the image as a file instead of parsing the string.

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.