n8n/packages/editor-ui/src/components/NodeIcon.vue

92 lines
1.7 KiB
Vue
Raw Normal View History

2019-06-23 03:35:23 -07:00
<template>
<div class="node-icon-wrapper" :style="iconStyleData">
2019-06-23 03:35:23 -07:00
<div v-if="nodeIconData !== null" class="icon">
<img :src="nodeIconData.path" style="width: 100%; height: 100%;" v-if="nodeIconData.type === 'file'"/>
<font-awesome-icon :icon="nodeIconData.path" v-else-if="nodeIconData.type === 'fa'" />
</div>
<div v-else class="node-icon-placeholder">
{{nodeType !== null ? nodeType.displayName.charAt(0) : '?' }}
</div>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
interface NodeIconData {
type: string;
path: string;
}
export default Vue.extend({
name: 'NodeIcon',
props: [
'nodeType',
'size',
2019-06-23 03:35:23 -07:00
],
computed: {
iconStyleData (): object {
if (!this.size) {
return {};
}
2019-07-25 10:15:41 -07:00
const size = parseInt(this.size, 10);
return {
width: size + 'px',
height: size + 'px',
'font-size': Math.floor(parseInt(this.size, 10) * 0.6) + 'px',
'line-height': size + 'px',
'border-radius': Math.ceil(size / 2) + 'px',
2019-07-25 10:15:41 -07:00
};
},
2019-06-23 03:35:23 -07:00
nodeIconData (): null | NodeIconData {
if (this.nodeType === null) {
return null;
}
const restUrl = this.$store.getters.getRestUrl;
if (this.nodeType.icon) {
let type, path;
[type, path] = this.nodeType.icon.split(':');
const returnData = {
type,
path,
};
if (type === 'file') {
returnData.path = restUrl + '/node-icon/' + this.nodeType.name;
}
return returnData;
}
return null;
},
},
});
</script>
<style lang="scss">
.node-icon-wrapper {
width: 30px;
height: 30px;
border-radius: 15px;
2019-06-23 03:35:23 -07:00
color: #444;
line-height: 30px;
font-size: 1.1em;
overflow: hidden;
background-color: #fff;
text-align: center;
font-weight: bold;
font-size: 20px;
2019-06-23 03:35:23 -07:00
.node-icon-placeholder {
text-align: center;
}
}
</style>