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