Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Feb 20, 2020
1 parent b2bb26b commit 4e240f6
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
@@ -1,3 +1,6 @@
# Mac OS X
.DS_Store

# Logs
logs
*.log
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
@@ -0,0 +1 @@
v12.14.1
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 hiroki
Copyright (c) 2020 Hiroki Osame

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
19 changes: 19 additions & 0 deletions icon-register.js
@@ -0,0 +1,19 @@
import svgLayer from './key';

export default {
name: 'icon-register',
functional: true,
props: {
id: {
type: String,
required: true,
},
},
inject: {
svgLayer,
},
render(h, ctx) {
const id = ctx.injections.svgLayer.register(ctx.props.id, ctx.children[0]);
return h('svg', [h('use', { attrs: { 'xlink:href': `#${id}` }})]);
},
};
54 changes: 54 additions & 0 deletions icons-layer.vue
@@ -0,0 +1,54 @@
<template>
<div>
<svg
xmlns="http://www.w3.org/2000/svg"
v-show="false"
>
<template v-for="(icon, id) in icons">
<component
:id="id"
:is="icon"
/>
</template>
</svg>
<slot />
</div>
</template>

<script>
import svgLayer from './key';
export default {
name: 'icons-layer',
props: {
namespace: {
type: String,
default: 'icon-',
},
},
provide() {
const vm = this;
return {
[svgLayer]: {
register(id, vnode) {
const registeredId = vm.namespace + id;
vm.$set(
vm.icons,
registeredId,
{ render: () => vnode },
);
return registeredId;
},
},
};
},
data() {
return {
icons: {},
};
},
};
</script>
1 change: 1 addition & 0 deletions key.js
@@ -0,0 +1 @@
export default 'vue-svg-icon-set-key';
17 changes: 17 additions & 0 deletions loader.js
@@ -0,0 +1,17 @@
const iconRegisterPath = require.resolve('./icon-register');

module.exports = (svgStr) => {
const id = 'hello-world';

// TODO: generate ID from file name, overrideable via WP options
// TODO: transpile svg to symbol
// TODO: replace color with currentColor

return `
<template><icon-register id="${id}">${svgStr}</icon-register></template>
<script>
import IconRegister from '${iconRegisterPath}';
export default { components: { IconRegister } };
</script>
`;
};
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions package.json
@@ -0,0 +1,11 @@
{
"name": "vue-svg-icon-set",
"version": "1.0.0",
"description": "",
"main": "icons-layer.vue",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Hiroki Osame <hiroki.osame@gmail.com>",
"license": "MIT"
}

0 comments on commit 4e240f6

Please sign in to comment.