debian-mirror-gitlab/app/assets/javascripts/boards/components/sidebar/board_editable_item.vue

89 lines
2 KiB
Vue
Raw Normal View History

2020-11-24 15:15:51 +05:30
<script>
import { GlButton, GlLoadingIcon } from '@gitlab/ui';
export default {
components: { GlButton, GlLoadingIcon },
props: {
title: {
type: String,
required: false,
default: '',
},
loading: {
type: Boolean,
required: false,
default: false,
},
},
inject: ['canUpdate'],
data() {
return {
edit: false,
};
},
destroyed() {
window.removeEventListener('click', this.collapseWhenOffClick);
},
methods: {
collapseWhenOffClick({ target }) {
if (!this.$el.contains(target)) {
this.collapse();
}
},
expand() {
if (this.edit) {
return;
}
this.edit = true;
2021-01-03 14:25:43 +05:30
this.$emit('open');
2020-11-24 15:15:51 +05:30
window.addEventListener('click', this.collapseWhenOffClick);
},
2021-01-03 14:25:43 +05:30
collapse({ emitEvent = true } = {}) {
2020-11-24 15:15:51 +05:30
if (!this.edit) {
return;
}
this.edit = false;
2021-01-03 14:25:43 +05:30
if (emitEvent) {
this.$emit('close');
}
2020-11-24 15:15:51 +05:30
window.removeEventListener('click', this.collapseWhenOffClick);
},
2021-02-22 17:27:13 +05:30
toggle({ emitEvent = true } = {}) {
if (this.edit) {
this.collapse({ emitEvent });
} else {
this.expand();
}
},
2020-11-24 15:15:51 +05:30
},
};
</script>
<template>
<div>
<div class="gl-display-flex gl-justify-content-space-between gl-mb-3">
<span class="gl-vertical-align-middle">
<span data-testid="title">{{ title }}</span>
<gl-loading-icon v-if="loading" inline class="gl-ml-2" />
</span>
<gl-button
v-if="canUpdate"
variant="link"
2021-02-22 17:27:13 +05:30
class="gl-text-gray-900! js-sidebar-dropdown-toggle"
2020-11-24 15:15:51 +05:30
data-testid="edit-button"
2021-02-22 17:27:13 +05:30
@click="toggle"
2020-11-24 15:15:51 +05:30
>
{{ __('Edit') }}
</gl-button>
</div>
2021-02-22 17:27:13 +05:30
<div v-show="!edit" class="gl-text-gray-500" data-testid="collapsed-content">
2020-11-24 15:15:51 +05:30
<slot name="collapsed">{{ __('None') }}</slot>
</div>
<div v-show="edit" data-testid="expanded-content">
2021-02-22 17:27:13 +05:30
<slot :edit="edit"></slot>
2020-11-24 15:15:51 +05:30
</div>
</div>
</template>