GithubHelp home page GithubHelp logo

vue-flag-icon's Introduction

Vue-Flag-Icon

NPM

a Vue2 Compoment for flag-icon-css

Install

npm i --save vue-flag-icon

Usage

Just declare the global Compoment with the use directive in your app

import FlagIcon from 'vue-flag-icon'
Vue.use(FlagIcon);

Then to use it

<template>
<div>
...

<flag iso="it" />
<flag iso="gb" />
<flag iso="us" />

...
</div>
</template

To see a full set of all the icons and countries iso codes visit the flag-icon-css website. There are 246 different icons there.

Being svg files they are resizable as long as you set the font size accordingly in a wrapper element

<div style="font-size:180px">
    <flag iso="it" />
</div>

The property iso can be as well dinamically set from an object

let guy = {
    name: "Vincenzo",
    nationality: "it"
}

in the Compoment you should dinamically bind the value

<flag :iso="guy.nationality" />

Screenshot

Code Example

(it is the basic vue-cli webpack template)

<template>
  <div id="app">
    <img src="./assets/logo.png">
    <hello></hello>
    <flag iso="it" />
    <flag iso="gb" />
    <flag iso="us" />
  </div>
</template>

<script>
import Hello from './components/Hello'

export default {
  name: 'app',
  components: {
    Hello
  }
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

Additional Props

From 1.0.4 you can now specify two different properties:

  • squared : it will render the flag as a square if true, otherwise the flag will be rectangular shaped (true by default).
  • title : you can specify the title of the flag icon, (by default it will be overwritten by the iso)

Result

image

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.