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

106 lines
2.3 KiB
Vue
Raw Normal View History

2018-05-09 12:01:36 +05:30
<script>
2019-02-15 15:39:39 +05:30
import { GlTooltipDirective } from '@gitlab/ui';
2018-10-15 14:42:47 +05:30
import Icon from '~/vue_shared/components/icon.vue';
import { __, sprintf } from '~/locale';
2018-12-05 23:21:45 +05:30
import { getCommitIconMap } from '~/ide/utils';
2018-05-09 12:01:36 +05:30
export default {
components: {
2018-10-15 14:42:47 +05:30
Icon,
},
directives: {
2019-02-15 15:39:39 +05:30
GlTooltip: GlTooltipDirective,
2018-05-09 12:01:36 +05:30
},
props: {
file: {
type: Object,
required: true,
},
2018-10-15 14:42:47 +05:30
showTooltip: {
type: Boolean,
required: false,
default: false,
},
showStagedIcon: {
type: Boolean,
required: false,
2019-12-04 20:38:33 +05:30
default: true,
2018-10-15 14:42:47 +05:30
},
2018-12-05 23:21:45 +05:30
size: {
type: Number,
required: false,
default: 12,
},
2019-07-07 11:18:12 +05:30
isCentered: {
type: Boolean,
required: false,
default: true,
},
2018-05-09 12:01:36 +05:30
},
computed: {
changedIcon() {
2019-10-12 21:52:04 +05:30
// False positive i18n lint: https://gitlab.com/gitlab-org/frontend/eslint-plugin-i18n/issues/26
// eslint-disable-next-line @gitlab/i18n/no-non-i18n-strings
2019-12-04 20:38:33 +05:30
const suffix = !this.file.changed && this.file.staged && this.showStagedIcon ? '-solid' : '';
2018-11-18 11:00:15 +05:30
return `${getCommitIconMap(this.file).icon}${suffix}`;
2018-05-09 12:01:36 +05:30
},
changedIconClass() {
2018-12-05 23:21:45 +05:30
return `${this.changedIcon} float-left d-block`;
2018-10-15 14:42:47 +05:30
},
tooltipTitle() {
if (!this.showTooltip) return undefined;
const type = this.file.tempFile ? 'addition' : 'modification';
if (this.file.changed && !this.file.staged) {
return sprintf(__('Unstaged %{type}'), {
type,
});
} else if (!this.file.changed && this.file.staged) {
return sprintf(__('Staged %{type}'), {
type,
});
} else if (this.file.changed && this.file.staged) {
return sprintf(__('Unstaged and staged %{type}'), {
2019-09-30 21:07:59 +05:30
type,
2018-10-15 14:42:47 +05:30
});
}
return undefined;
2018-05-09 12:01:36 +05:30
},
2018-11-18 11:00:15 +05:30
showIcon() {
return this.file.changed || this.file.tempFile || this.file.staged || this.file.deleted;
},
2018-05-09 12:01:36 +05:30
},
};
</script>
<template>
2019-07-07 11:18:12 +05:30
<span
v-gl-tooltip.right
:title="tooltipTitle"
:class="{ 'ml-auto': isCentered }"
2019-10-12 21:52:04 +05:30
class="file-changed-icon d-inline-block"
2019-07-07 11:18:12 +05:30
>
2019-02-15 15:39:39 +05:30
<icon v-if="showIcon" :name="changedIcon" :size="size" :css-classes="changedIconClass" />
2018-10-15 14:42:47 +05:30
</span>
2018-05-09 12:01:36 +05:30
</template>
2018-12-05 23:21:45 +05:30
<style>
.file-addition,
.file-addition-solid {
color: #1aaa55;
}
.file-modified,
.file-modified-solid {
color: #fc9403;
}
.file-deletion,
.file-deletion-solid {
color: #db3b21;
}
</style>