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