2018-03-17 18:26:18 +05:30
|
|
|
<script>
|
2023-04-23 21:23:45 +05:30
|
|
|
import { getIconForFile } from '@gitlab/svgs/src/file_icon_map';
|
2020-04-22 19:07:51 +05:30
|
|
|
import { GlLoadingIcon, GlIcon } from '@gitlab/ui';
|
2020-07-28 23:09:34 +05:30
|
|
|
import { FILE_SYMLINK_MODE } from '../constants';
|
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: {
|
2018-12-13 13:39:08 +05:30
|
|
|
GlLoadingIcon,
|
2020-04-22 19:07:51 +05:30
|
|
|
GlIcon,
|
2018-10-15 14:42:47 +05:30
|
|
|
},
|
|
|
|
props: {
|
|
|
|
fileName: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
2018-03-17 18:26:18 +05:30
|
|
|
},
|
2020-07-28 23:09:34 +05:30
|
|
|
fileMode: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
folder: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2020-04-22 19:07:51 +05:30
|
|
|
submodule: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
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: {
|
2020-07-28 23:09:34 +05:30
|
|
|
isSymlink() {
|
|
|
|
return this.fileMode === FILE_SYMLINK_MODE;
|
|
|
|
},
|
2018-10-15 14:42:47 +05:30
|
|
|
spriteHref() {
|
2020-04-22 19:07:51 +05:30
|
|
|
const iconName = this.submodule ? 'folder-git' : getIconForFile(this.fileName) || 'file';
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
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>
|
2021-09-30 23:02:18 +05:30
|
|
|
<gl-loading-icon v-if="loading" size="sm" :inline="true" />
|
2021-12-11 22:18:48 +05:30
|
|
|
<gl-icon v-else-if="isSymlink" name="symlink" :size="size" />
|
2020-10-24 23:57:45 +05:30
|
|
|
<svg v-else-if="!folder" :key="spriteHref" :class="[iconSizeClass, cssClasses]">
|
2023-04-23 21:23:45 +05:30
|
|
|
<use :href="spriteHref" />
|
2020-07-28 23:09:34 +05:30
|
|
|
</svg>
|
2021-03-11 19:13:27 +05:30
|
|
|
<gl-icon
|
|
|
|
v-else
|
|
|
|
:name="folderIconName"
|
|
|
|
:size="size"
|
|
|
|
class="folder-icon"
|
|
|
|
data-qa-selector="folder_icon_content"
|
|
|
|
/>
|
2018-03-17 18:26:18 +05:30
|
|
|
</span>
|
|
|
|
</template>
|