1.0.0 • Published 4 years ago

vue-mdi v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Vue MDI

VueJS Component for Material Design Icons

Installation

Install the icon content @mdi/js package and this module

npm install --save @mdi/js
npm install --save vue-mdi

And import VueMdi css file in your app entry point

import 'vue-mdi/dist/mdi.css';

Add more icons packs

You can also include a set of Material Design Icons Light

npm install --save @mdi/light-js

Usage

Recommended

The following examples are based on a project configured with vue-cli.

src/main.js

import Vue from 'vue'
import App from './App'
import { VueMdi, library } from 'vue-mdi'
import { mdiAccount } from '@mdi/js'
import 'vue-mdi/dist/mdi.css';

library.add({ mdiAccount })

Vue.component('vue-mdi', VueMdi)

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  components: { App },
  template: '<App/>'
})

src/App.vue

<template>
  <div id="app">
    <vue-mdi icon="account" />
  </div>
</template>

<script>
export default {
  name: 'App'
}
</script>

Using default icons

import { library } from 'vue-mdi'
import { mdiAccount } from '@mdi/js'

library.add({ mdiAccount })
<!-- The default MDI icons is implicit -->
<vue-mdi icon="account" />

<!-- It's better to be explicit -->
<vue-mdi :icon="['mdi', 'account']" />

Using Light icons

import { library } from 'vue-mdi'
import { mdilAccount } from '@mdi/light-js'

library.add({ mdilAccount })
<vue-mdi :icon="['mdil', 'account']" />

The icon property

The icon property of the VueMdi component can be used in the following way:

Shorthand that assumes a prefix of mdi

<vue-mdi icon="android" />
<vue-mdi icon="facebook" />

<vue-mdi :icon="['mdi', 'android']" /> # Same as above
<vue-mdi :icon="['mdi', 'facebook']" /> # Same as above

For the above to work you must add the android and facebook icon to the library.

import { library } from 'vue-mdi'
import { mdiAndroid, mdiFacebook } from '@mdi/js'

library.add({ mdiAndroid, mdiFacebook })

In the event that you are using an icon with a multi-word name please note that you would need to pass in the icon name using kebab-case as opposed to camelCase.

<vue-mdi icon="android" />  # import { mdiAndroid } from '@mdi/js'

Explicit prefix

<vue-mdi :icon="['mdi', 'facebook']" />

For the above to work you must add the facebook icon (MDI default pack) to the library.

import { library } from 'vue-mdi'
import { mdiFacebook } from '@mdi/js'

library.add({ mdiFacebook })

Icon property declared by the object

<template>
  <div id="app">
    <vue-mdi :icon="icon" />
  </div>
</template>

<script>
export default {
  name: 'App',
  data() {
    return {
      icon: {
        prefix: 'mdil',
        name: 'account'
      }
    }
  }
}
</script>

For the above to work you must add the MDI Light account icon to the library.

import { library } from 'vue-mdi'
import { mdilAccount } from '@mdi/light-js'

library.add({ mdilAccount })

Using the concept of a library

Explicitly selecting icons offer the advantage of only bundling the icons that you use in your final bundled file. This allows us to subset MDI's thousands of icons to just the small number that are normally used.

Import the specific icons that you need

import { library } from 'vue-mdi'
import { mdiAccount, mdiBlockHelper } from '@mdi/js'
import { mdilAccount } from '@mdi/light-js'

library.add({ mdiAccount, mdiBlockHelper, mdilAccount })

Reset all loaded icons

import { library } from 'vue-mdi'

library.reset()

VueMdi component props

PropPropTypesDefaultDetails
iconobject, array, stringrequiredMDI icon property (see above). Make sure that you added this icon from @mdi/js or @mdi/light-js to the library
titlestring, nullnullA11y <title>{title}</title>
descriptionstring, nullnullA11y <desc>{desc}</desc>
sizenumber, string, nullnullIcon size. Will be converted to {size * 1.5}rem. If a string is specified, it can only take the following values: mdi-18px, mdi-24px, mdi-36px, mdi-48px.
colorstring#000Icon color. Can accept any CSS color value
horizontalboolfalseFlip Horizontal
verticalboolfalseFlip Vertical
rotatenumber0Degrees 0 to 360
spinbool, numberfalseAdding animation for icon spin. If a number is set, it is equal to the number of seconds for a full rotation of the icon. If set to true, the number of seconds is 2. Counterclockwise

Note: Additional props will be applied to the <svg> element.

Development

To develop clone the repo and run npm install.

Tasks

CommandPurpose
buildBuild a development version of the library using Rollup
distBuild a production version of the library using Rollup
testExecute unit tests
lintRun ESlint for lint project files

Related Packages

NPM @MDI Organization