gitlab-org--gitlab-foss/app/assets/javascripts/vue_shared/components/file_icon.vue

82 lines
1.6 KiB
Vue
Raw Normal View History

2018-01-03 05:08:14 -05:00
<script>
2018-11-16 14:29:11 -05:00
import { GlLoadingIcon } from '@gitlab/ui';
import getIconForFile from './file_icon/file_icon_map';
import icon from '../../vue_shared/components/icon.vue';
2018-01-03 05:08:14 -05:00
/* This is a re-usable vue component for rendering a svg sprite
2018-01-03 05:08:14 -05:00
icon
Sample configuration:
<file-icon
name="retry"
:size="32"
css-classes="top"
/>
*/
export default {
components: {
icon,
GlLoadingIcon,
},
props: {
fileName: {
type: String,
required: true,
2018-01-04 19:18:35 -05:00
},
2018-01-03 05:08:14 -05:00
folder: {
type: Boolean,
required: false,
default: false,
},
2018-01-03 05:08:14 -05:00
opened: {
type: Boolean,
required: false,
default: false,
},
2018-01-03 05:08:14 -05:00
loading: {
type: Boolean,
required: false,
default: false,
},
2018-01-03 05:08:14 -05:00
size: {
type: Number,
required: false,
default: 16,
},
2018-01-03 05:08:14 -05:00
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-01-03 05:08:14 -05:00
},
iconSizeClass() {
return this.size ? `s${this.size}` : '';
2018-01-03 05:08:14 -05:00
},
},
};
2018-01-03 05:08:14 -05:00
</script>
<template>
<span>
2018-11-16 15:07:38 -05:00
<svg v-if="!loading && !folder" :class="[iconSizeClass, cssClasses]">
<use v-bind="{ 'xlink:href': spriteHref }" />
2018-01-03 05:08:14 -05:00
</svg>
2018-11-16 15:07:38 -05:00
<icon v-if="!loading && folder" :name="folderIconName" :size="size" css-classes="folder-icon" />
<gl-loading-icon v-if="loading" :inline="true" />
2018-01-03 05:08:14 -05:00
</span>
</template>