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

90 lines
1.9 KiB
Vue
Raw Normal View History

2019-12-26 22:10:19 +05:30
<script>
2020-04-22 19:07:51 +05:30
import { isString } from 'lodash';
2020-10-24 23:57:45 +05:30
import {
GlDeprecatedDropdown,
GlDeprecatedDropdownDivider,
GlDeprecatedDropdownItem,
} from '@gitlab/ui';
2019-12-26 22:10:19 +05:30
const isValidItem = item =>
2020-04-22 19:07:51 +05:30
isString(item.eventName) && isString(item.title) && isString(item.description);
2019-12-26 22:10:19 +05:30
export default {
components: {
2020-10-24 23:57:45 +05:30
GlDeprecatedDropdown,
GlDeprecatedDropdownDivider,
GlDeprecatedDropdownItem,
2019-12-26 22:10:19 +05:30
},
props: {
actionItems: {
type: Array,
required: true,
validator(value) {
return value.length > 1 && value.every(isValidItem);
},
},
menuClass: {
type: String,
required: false,
default: '',
},
2020-01-01 13:55:28 +05:30
variant: {
type: String,
required: false,
default: 'secondary',
},
2019-12-26 22:10:19 +05:30
},
data() {
return {
selectedItem: this.actionItems[0],
};
},
computed: {
dropdownToggleText() {
return this.selectedItem.title;
},
},
methods: {
triggerEvent() {
this.$emit(this.selectedItem.eventName);
},
2020-03-13 15:44:24 +05:30
changeSelectedItem(item) {
this.selectedItem = item;
this.$emit('change', item);
},
2019-12-26 22:10:19 +05:30
},
};
</script>
<template>
2020-10-24 23:57:45 +05:30
<gl-deprecated-dropdown
2019-12-26 22:10:19 +05:30
:menu-class="`dropdown-menu-selectable ${menuClass}`"
split
:text="dropdownToggleText"
2020-01-01 13:55:28 +05:30
:variant="variant"
2019-12-26 22:10:19 +05:30
v-bind="$attrs"
@click="triggerEvent"
>
<template v-for="(item, itemIndex) in actionItems">
2020-10-24 23:57:45 +05:30
<gl-deprecated-dropdown-item
2019-12-26 22:10:19 +05:30
:key="item.eventName"
:active="selectedItem === item"
active-class="is-active"
2020-03-13 15:44:24 +05:30
@click="changeSelectedItem(item)"
2019-12-26 22:10:19 +05:30
>
<strong>{{ item.title }}</strong>
<div>{{ item.description }}</div>
2020-10-24 23:57:45 +05:30
</gl-deprecated-dropdown-item>
2019-12-26 22:10:19 +05:30
2020-10-24 23:57:45 +05:30
<gl-deprecated-dropdown-divider
2019-12-26 22:10:19 +05:30
v-if="itemIndex < actionItems.length - 1"
:key="`${item.eventName}-divider`"
/>
</template>
2020-10-24 23:57:45 +05:30
</gl-deprecated-dropdown>
2019-12-26 22:10:19 +05:30
</template>