2
0
mirror of https://github.com/frappe/books.git synced 2025-02-11 00:18:45 +00:00
books/src/components/Icon.vue
18alantom 2f6a2f4cc2 refactor: vue 2 → 3 migration
- render functions
- slots
- creation
2022-02-10 12:11:51 +05:30

55 lines
1.1 KiB
Vue

<template>
<component
v-bind="$attrs"
:is="iconComponent"
:class="iconClasses"
:active="active"
/>
</template>
<script>
const components = {};
const requireComponent = require.context('./Icons', true, /\w+\.(vue)$/);
requireComponent.keys().forEach(fileName => {
const componentConfig = requireComponent(fileName);
let match = fileName.match(/\.\/(\d+)\/((\w|-)+).vue/);
let [, size, name] = match || [];
if (name) {
components[size] = components[size] || {};
components[size][name] = componentConfig.default || componentConfig;
}
});
export default {
name: 'Icon',
props: ['name', 'active', 'size', 'height'],
computed: {
iconComponent() {
try {
return components[this.size][this.name];
} catch (error) {
return null;
}
},
iconClasses() {
let sizeClass = {
'8': 'w-2 h-2',
'12': 'w-3 h-3',
'16': 'w-4 h-4',
'18': 'w-5 h-5',
'24': 'w-6 h-6'
}[this.size];
if (this.height) {
sizeClass = `w-${this.height} h-${this.height}`;
}
return [sizeClass, 'fill-current'];
}
}
};
</script>