debian-mirror-gitlab/app/assets/javascripts/vue_shared/components/file_icon.vue

82 lines
1.6 KiB
Vue
Raw Normal View History

2018-03-17 18:26:18 +05:30
<script>
2019-02-15 15:39:39 +05:30
import { GlLoadingIcon } from '@gitlab/ui';
2018-10-15 14:42:47 +05:30
import getIconForFile from './file_icon/file_icon_map';
import icon from '../../vue_shared/components/icon.vue';
2018-03-17 18:26:18 +05:30
2018-10-15 14:42:47 +05:30
/* This is a re-usable vue component for rendering a svg sprite
2018-03-17 18:26:18 +05:30
icon
Sample configuration:
<file-icon
name="retry"
:size="32"
css-classes="top"
/>
*/
2018-10-15 14:42:47 +05:30
export default {
components: {
icon,
2018-12-13 13:39:08 +05:30
GlLoadingIcon,
2018-10-15 14:42:47 +05:30
},
props: {
fileName: {
type: String,
required: true,
2018-03-17 18:26:18 +05:30
},
2018-10-15 14:42:47 +05:30
folder: {
type: Boolean,
required: false,
default: false,
},
2018-03-17 18:26:18 +05:30
2018-10-15 14:42:47 +05:30
opened: {
type: Boolean,
required: false,
default: false,
},
2018-03-17 18:26:18 +05:30
2018-10-15 14:42:47 +05:30
loading: {
type: Boolean,
required: false,
default: false,
},
2018-03-17 18:26:18 +05:30
2018-10-15 14:42:47 +05:30
size: {
type: Number,
required: false,
default: 16,
},
2018-03-17 18:26:18 +05:30
2018-10-15 14:42:47 +05:30
cssClasses: {
type: String,
required: false,
default: '',
},
},
computed: {
spriteHref() {
const iconName = getIconForFile(this.fileName) || 'file';
return `${gon.sprite_file_icons}#${iconName}`;
},
folderIconName() {
return this.opened ? 'folder-open' : 'folder';
2018-03-17 18:26:18 +05:30
},
2018-10-15 14:42:47 +05:30
iconSizeClass() {
return this.size ? `s${this.size}` : '';
2018-03-17 18:26:18 +05:30
},
2018-10-15 14:42:47 +05:30
},
};
2018-03-17 18:26:18 +05:30
</script>
<template>
<span>
2019-02-15 15:39:39 +05:30
<svg v-if="!loading && !folder" :class="[iconSizeClass, cssClasses]">
<use v-bind="{ 'xlink:href': spriteHref }" />
2018-03-17 18:26:18 +05:30
</svg>
2019-02-15 15:39:39 +05:30
<icon v-if="!loading && folder" :name="folderIconName" :size="size" css-classes="folder-icon" />
<gl-loading-icon v-if="loading" :inline="true" />
2018-03-17 18:26:18 +05:30
</span>
</template>