2018-01-03 05:08:14 -05:00
|
|
|
<script>
|
2018-11-16 14:29:11 -05:00
|
|
|
import { GlLoadingIcon } from '@gitlab/ui';
|
2018-04-10 06:10:16 -04:00
|
|
|
import getIconForFile from './file_icon/file_icon_map';
|
|
|
|
import icon from '../../vue_shared/components/icon.vue';
|
2018-01-03 05:08:14 -05:00
|
|
|
|
2018-04-10 06:10:16 -04: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"
|
|
|
|
/>
|
|
|
|
|
|
|
|
*/
|
2018-04-10 06:10:16 -04:00
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
icon,
|
2018-11-07 05:06:15 -05:00
|
|
|
GlLoadingIcon,
|
2018-04-10 06:10:16 -04:00
|
|
|
},
|
|
|
|
props: {
|
|
|
|
fileName: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
2018-01-04 19:18:35 -05:00
|
|
|
},
|
2018-01-03 05:08:14 -05:00
|
|
|
|
2018-04-10 06:10:16 -04:00
|
|
|
folder: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2018-01-03 05:08:14 -05:00
|
|
|
|
2018-04-10 06:10:16 -04:00
|
|
|
opened: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2018-01-03 05:08:14 -05:00
|
|
|
|
2018-04-10 06:10:16 -04:00
|
|
|
loading: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2018-01-03 05:08:14 -05:00
|
|
|
|
2018-04-10 06:10:16 -04:00
|
|
|
size: {
|
|
|
|
type: Number,
|
|
|
|
required: false,
|
|
|
|
default: 16,
|
|
|
|
},
|
2018-01-03 05:08:14 -05:00
|
|
|
|
2018-04-10 06:10:16 -04: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
|
|
|
},
|
2018-04-10 06:10:16 -04:00
|
|
|
iconSizeClass() {
|
|
|
|
return this.size ? `s${this.size}` : '';
|
2018-01-03 05:08:14 -05:00
|
|
|
},
|
2018-04-10 06:10:16 -04: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>
|