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

96 lines
1.9 KiB
Vue
Raw Normal View History

2018-03-17 18:26:18 +05:30
<script>
2020-04-22 19:07:51 +05:30
import { GlLoadingIcon, GlIcon } from '@gitlab/ui';
2018-10-15 14:42:47 +05:30
import getIconForFile from './file_icon/file_icon_map';
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>
2020-07-28 23:09:34 +05:30
<gl-loading-icon v-if="loading" :inline="true" />
<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]">
2020-07-28 23:09:34 +05:30
<use v-bind="{ 'xlink:href': spriteHref }" />
</svg>
<gl-icon v-else :name="folderIconName" :size="size" class="folder-icon" />
2018-03-17 18:26:18 +05:30
</span>
</template>