Commit a85b7b63 authored by Cole Bemis's avatar Cole Bemis

Create Icon component

parent 4c6b7ad3
...@@ -9,14 +9,7 @@ ...@@ -9,14 +9,7 @@
margin: 0; margin: 0;
} }
.icon {
display: inline-block;
line-height: 0;
}
.icon > svg {
stroke: currentColor;
}
</style> </style>
</head> </head>
<body> <body>
......
<template> <template>
<div>Hello World</div> <div><icon name="square" size="48"></icon></div>
</template> </template>
<script> <script>
import {mapState} from 'vuex'; import {mapState} from 'vuex';
import Icon from './Icon';
export default { export default {
name: 'App', name: 'App',
......
<template>
<div class="icon"></div>
</template>
<script>
export default {
name: 'Icon',
props: {
name: {
type: String,
required: true
},
size: {
type: String,
default: '24'
}
},
mounted() {
fetch(`./icons/${this.name}.svg`)
.then(response => {
if (response.ok) {
return response.text();
}
throw new Error(`Cannot find ${this.name}.svg`);
})
.then(svgText => {
const svgDocument = new DOMParser().parseFromString(svgText, 'image/svg+xml');
const svgIcon = svgDocument.querySelector('svg').cloneNode(true);
svgIcon.setAttribute('width', this.size);
svgIcon.setAttribute('height', this.size);
this.$el.appendChild(svgIcon);
})
.catch(error => {
console.error(error);
});
}
}
</script>
<style lang="stylus">
.icon
display inline-block
line-height 0
.icon > svg
stroke currentColor
</style>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment