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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

86 lines
1.7 KiB
Vue
Raw Normal View History

2019-12-26 22:10:19 +05:30
<script>
2021-01-03 14:25:43 +05:30
import { GlDropdown, GlDropdownDivider, GlDropdownItem } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { isString } from 'lodash';
2019-12-26 22:10:19 +05:30
2021-03-08 18:12:59 +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: {
2021-01-03 14:25:43 +05:30
GlDropdown,
GlDropdownDivider,
GlDropdownItem,
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,
2021-01-03 14:25:43 +05:30
default: 'default',
2020-01-01 13:55:28 +05:30
},
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>
2021-01-03 14:25:43 +05:30
<gl-dropdown
:menu-class="menuClass"
2019-12-26 22:10:19 +05:30
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">
2021-01-03 14:25:43 +05:30
<gl-dropdown-item
2019-12-26 22:10:19 +05:30
:key="item.eventName"
2021-01-03 14:25:43 +05:30
:is-check-item="true"
:is-checked="selectedItem === item"
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>
2021-01-03 14:25:43 +05:30
</gl-dropdown-item>
2019-12-26 22:10:19 +05:30
2021-01-03 14:25:43 +05:30
<gl-dropdown-divider
2019-12-26 22:10:19 +05:30
v-if="itemIndex < actionItems.length - 1"
:key="`${item.eventName}-divider`"
/>
</template>
2021-01-03 14:25:43 +05:30
</gl-dropdown>
2019-12-26 22:10:19 +05:30
</template>