Skip to content

Commit

Permalink
feat(): rework lib to support both vue 2 and 3 as well as utilize tre…
Browse files Browse the repository at this point in the history
…e shaking
  • Loading branch information
Attila Max Ruf committed Dec 25, 2020
1 parent 7206031 commit de9321a
Show file tree
Hide file tree
Showing 9 changed files with 395 additions and 454 deletions.
22 changes: 0 additions & 22 deletions .github/workflows/publish.yml

This file was deleted.

91 changes: 0 additions & 91 deletions build.js

This file was deleted.

12 changes: 0 additions & 12 deletions consts.js

This file was deleted.

26 changes: 0 additions & 26 deletions copy.js

This file was deleted.

File renamed without changes.
90 changes: 90 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import Vue, { h as v3h } from 'vue'
import * as mdi from '@mdi/js'
import './icons.css'

const vueVersion = Vue === undefined ? 3 : 2;

const versionDependentOpts = Vue
? { functional: true } // for v2.x
: {} // for v3.x

const ucFirst = (str) => str.charAt(0).toUpperCase() + str.slice(1)

function render(v2h, v2ctx) {
const data = vueVersion === 2 ? v2ctx.data : this
const props = vueVersion === 2 ? v2ctx.props : this
const attrs = vueVersion === 2 ? v2ctx.attrs : this.$attrs
const h = vueVersion === 2 ? v2h : v3h
const iconPath = mdi[`mdi${ucFirst(props.name)}`] || mdi.mdiAlert

return h('span', {
attrs: {
role: props.role,
ariaLabel: props.ariaLabel,
...attrs
},
class: {
...(data.staticClass && {
[data.staticClass]: true,
}),
[`mdi mdi-${props.name}`]: true,
'mdi-spin': props.spin === true
}
}, [
h('svg', {
attrs: {
fill: 'currentColor',
width: props.width || props.size,
height: props.height || props.size,
viewBox: props.viewBox,
xmlns: props.xmlns
}
}, [
...[props.title ? h('title', [props.title]) : undefined],
h('path', {
attrs: { d: iconPath }
})
])
])
}

export default {
install(app) {
app.component('mdicon', {
name: 'MDIcon',
...versionDependentOpts,
props: {
title: [String],
spin: [Boolean],
width: [Number, String],
height: [Number, String],
name: {
type: String,
required: true,
default: 'alert'
},
size: {
type: [Number, String],
default: 24
},
viewBox: {
type: String,
default: '0 0 24 24'
},
xmlns: {
type: String,
default: 'http://www.w3.org/2000/svg'
},
role: {
type: String,
default: 'img'
},
spin: {
type: Boolean,
default: false
}
},
render
})
}
}
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
{
"name": "mdi-vue",
"version": "1.8.1",
"version": "2.0.0",
"description": "Material Design Icons for Vue.js",
"main": "./index.js",
"main": "./main.js",
"files": [
"*"
],
"repository": "git@github.com:therufa/mdi-vue.git",
"homepage": "https://github.com/therufa/mdi-vue",
"keywords": [
"material design icons",
"vue 3",
"mdi",
"vue",
"vuejs",
"vue.js",
"material",
"design",
"icons",
"icon",
"material-design",
"material design",
"material design icons"
"material design"
],
"bugs": {
"url": "https://github.com/therufa/mdi-vue/issues"
Expand Down
67 changes: 0 additions & 67 deletions template.js

This file was deleted.

Loading

0 comments on commit de9321a

Please sign in to comment.