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

102 lines
2.3 KiB
Vue
Raw Normal View History

2020-11-24 15:15:51 +05:30
<script>
import {
GlDropdown,
GlDropdownItem,
GlDropdownDivider,
2021-01-03 14:25:43 +05:30
GlButton,
2020-11-24 15:15:51 +05:30
GlTooltipDirective,
} from '@gitlab/ui';
export default {
components: {
GlDropdown,
GlDropdownItem,
GlDropdownDivider,
2021-01-03 14:25:43 +05:30
GlButton,
2020-11-24 15:15:51 +05:30
},
directives: {
GlTooltip: GlTooltipDirective,
},
props: {
actions: {
type: Array,
required: true,
},
selectedKey: {
type: String,
required: false,
default: '',
},
2021-01-03 14:25:43 +05:30
category: {
type: String,
required: false,
default: 'secondary',
},
variant: {
type: String,
required: false,
default: 'default',
},
2020-11-24 15:15:51 +05:30
},
computed: {
hasMultipleActions() {
return this.actions.length > 1;
},
selectedAction() {
2021-03-08 18:12:59 +05:30
return this.actions.find((x) => x.key === this.selectedKey) || this.actions[0];
2020-11-24 15:15:51 +05:30
},
},
methods: {
handleItemClick(action) {
this.$emit('select', action.key);
},
handleClick(action, evt) {
return action.handle?.(evt);
},
},
};
</script>
<template>
<gl-dropdown
v-if="hasMultipleActions"
v-gl-tooltip="selectedAction.tooltip"
:text="selectedAction.text"
:split-href="selectedAction.href"
2021-01-03 14:25:43 +05:30
:variant="variant"
:category="category"
2020-11-24 15:15:51 +05:30
split
@click="handleClick(selectedAction, $event)"
>
2021-09-30 23:02:18 +05:30
<template #button-content>
2020-11-24 15:15:51 +05:30
<span class="gl-new-dropdown-button-text" v-bind="selectedAction.attrs">
{{ selectedAction.text }}
</span>
</template>
<template v-for="(action, index) in actions">
<gl-dropdown-item
:key="action.key"
:is-check-item="true"
:is-checked="action.key === selectedAction.key"
:secondary-text="action.secondaryText"
:data-testid="`action_${action.key}`"
@click="handleItemClick(action)"
>
2021-03-11 19:13:27 +05:30
<span class="gl-font-weight-bold">{{ action.text }}</span>
2020-11-24 15:15:51 +05:30
</gl-dropdown-item>
<gl-dropdown-divider v-if="index != actions.length - 1" :key="action.key + '_divider'" />
</template>
</gl-dropdown>
2021-01-03 14:25:43 +05:30
<gl-button
2020-11-24 15:15:51 +05:30
v-else-if="selectedAction"
v-gl-tooltip="selectedAction.tooltip"
v-bind="selectedAction.attrs"
2021-01-03 14:25:43 +05:30
:variant="variant"
:category="category"
2020-11-24 15:15:51 +05:30
:href="selectedAction.href"
@click="handleClick(selectedAction, $event)"
>
{{ selectedAction.text }}
2021-01-03 14:25:43 +05:30
</gl-button>
2020-11-24 15:15:51 +05:30
</template>