2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2023-04-24 14:10:17 +00:00
|
|
|
<div :class="containerClass" :style="style" v-bind="ptm('root')">
|
2022-09-06 12:03:37 +00:00
|
|
|
<slot>
|
2023-04-24 14:10:17 +00:00
|
|
|
<PVSButton type="button" class="p-splitbutton-defaultbutton" :label="label" :disabled="disabled" :aria-label="label" @click="onDefaultButtonClick" v-bind="{ ...buttonProps, ...ptm('button') }">
|
2023-04-19 07:50:39 +00:00
|
|
|
<template #icon="slotProps">
|
2023-04-18 10:50:13 +00:00
|
|
|
<slot name="icon">
|
2023-04-24 14:10:17 +00:00
|
|
|
<span :class="[icon, slotProps.class]" v-bind="ptm('icon')" />
|
2023-04-18 10:50:13 +00:00
|
|
|
</slot>
|
|
|
|
</template>
|
|
|
|
</PVSButton>
|
2022-09-06 12:03:37 +00:00
|
|
|
</slot>
|
2022-12-08 11:04:25 +00:00
|
|
|
<PVSButton
|
|
|
|
ref="button"
|
|
|
|
type="button"
|
|
|
|
class="p-splitbutton-menubutton"
|
|
|
|
:disabled="disabled"
|
|
|
|
aria-haspopup="true"
|
|
|
|
:aria-expanded="isExpanded"
|
|
|
|
:aria-controls="ariaId + '_overlay'"
|
|
|
|
@click="onDropdownButtonClick"
|
|
|
|
@keydown="onDropdownKeydown"
|
2023-05-02 08:00:39 +00:00
|
|
|
:pt="ptm('menuButton')"
|
|
|
|
v-bind="menuButtonProps"
|
2023-04-10 11:57:23 +00:00
|
|
|
>
|
2023-04-19 07:50:39 +00:00
|
|
|
<template #icon="slotProps">
|
2023-04-14 07:44:20 +00:00
|
|
|
<slot name="menubuttonicon">
|
2023-05-02 08:00:39 +00:00
|
|
|
<component :is="menuButtonIcon ? 'span' : 'ChevronDownIcon'" :class="[menuButtonIcon, slotProps.class]" v-bind="ptm('menuButton')['icon']" />
|
2023-04-14 07:44:20 +00:00
|
|
|
</slot>
|
|
|
|
</template>
|
2023-04-10 11:57:23 +00:00
|
|
|
</PVSButton>
|
2023-04-26 10:00:49 +00:00
|
|
|
<PVSMenu ref="menu" :id="ariaId + '_overlay'" :model="model" :popup="true" :autoZIndex="autoZIndex" :baseZIndex="baseZIndex" :appendTo="appendTo" :pt="ptm('menu')" />
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-04-24 14:10:17 +00:00
|
|
|
import BaseComponent from 'primevue/basecomponent';
|
2022-09-06 12:03:37 +00:00
|
|
|
import Button from 'primevue/button';
|
2023-04-18 12:53:43 +00:00
|
|
|
import ChevronDownIcon from 'primevue/icons/chevrondown';
|
2022-09-06 12:03:37 +00:00
|
|
|
import TieredMenu from 'primevue/tieredmenu';
|
2022-09-14 11:26:01 +00:00
|
|
|
import { UniqueComponentId } from 'primevue/utils';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'SplitButton',
|
2023-04-24 14:10:17 +00:00
|
|
|
extends: BaseComponent,
|
2022-12-31 09:51:37 +00:00
|
|
|
emits: ['click'],
|
2022-09-06 12:03:37 +00:00
|
|
|
props: {
|
|
|
|
label: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
icon: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
2022-09-14 11:26:01 +00:00
|
|
|
model: {
|
2022-09-06 12:03:37 +00:00
|
|
|
type: Array,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
autoZIndex: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
baseZIndex: {
|
|
|
|
type: Number,
|
|
|
|
default: 0
|
|
|
|
},
|
|
|
|
appendTo: {
|
|
|
|
type: String,
|
|
|
|
default: 'body'
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
disabled: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
class: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
buttonProps: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
menuButtonProps: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
2023-01-02 08:40:36 +00:00
|
|
|
},
|
|
|
|
menuButtonIcon: {
|
|
|
|
type: String,
|
2023-04-10 11:57:23 +00:00
|
|
|
default: undefined
|
2023-03-03 12:41:32 +00:00
|
|
|
},
|
|
|
|
severity: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
raised: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
rounded: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
text: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
outlined: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
size: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
2023-03-06 08:16:57 +00:00
|
|
|
},
|
|
|
|
plain: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
2022-12-08 11:04:25 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isExpanded: false
|
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onDropdownButtonClick() {
|
2022-12-08 11:04:25 +00:00
|
|
|
this.$refs.menu.toggle({ currentTarget: this.$el, relatedTarget: this.$refs.button.$el });
|
|
|
|
this.isExpanded = !this.$refs.menu.visible;
|
|
|
|
},
|
|
|
|
onDropdownKeydown(event) {
|
|
|
|
if (event.code === 'ArrowDown' || event.code === 'ArrowUp') {
|
|
|
|
this.onDropdownButtonClick();
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
onDefaultButtonClick(event) {
|
2023-03-17 06:59:23 +00:00
|
|
|
if (this.isExpanded) {
|
|
|
|
this.$refs.menu.hide(event);
|
|
|
|
}
|
2022-12-31 09:51:37 +00:00
|
|
|
|
2023-03-17 06:59:23 +00:00
|
|
|
this.$emit('click', event);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
ariaId() {
|
|
|
|
return UniqueComponentId();
|
|
|
|
},
|
|
|
|
containerClass() {
|
2023-03-03 12:41:32 +00:00
|
|
|
return [
|
|
|
|
'p-splitbutton p-component',
|
|
|
|
this.class,
|
|
|
|
{
|
|
|
|
[`p-button-${this.severity}`]: this.severity,
|
|
|
|
'p-button-raised': this.raised,
|
|
|
|
'p-button-rounded': this.rounded,
|
|
|
|
'p-button-text': this.text,
|
|
|
|
'p-button-outlined': this.outlined,
|
|
|
|
'p-button-sm': this.size === 'small',
|
|
|
|
'p-button-lg': this.size === 'large'
|
|
|
|
}
|
|
|
|
];
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
2022-09-14 11:26:01 +00:00
|
|
|
PVSButton: Button,
|
2023-04-10 11:57:23 +00:00
|
|
|
PVSMenu: TieredMenu,
|
|
|
|
ChevronDownIcon: ChevronDownIcon
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.p-splitbutton {
|
|
|
|
display: inline-flex;
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-splitbutton .p-splitbutton-defaultbutton,
|
|
|
|
.p-splitbutton.p-button-rounded > .p-splitbutton-defaultbutton.p-button,
|
|
|
|
.p-splitbutton.p-button-outlined > .p-splitbutton-defaultbutton.p-button {
|
|
|
|
flex: 1 1 auto;
|
|
|
|
border-top-right-radius: 0;
|
|
|
|
border-bottom-right-radius: 0;
|
|
|
|
border-right: 0 none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-splitbutton-menubutton,
|
|
|
|
.p-splitbutton.p-button-rounded > .p-splitbutton-menubutton.p-button,
|
|
|
|
.p-splitbutton.p-button-outlined > .p-splitbutton-menubutton.p-button {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
border-top-left-radius: 0;
|
|
|
|
border-bottom-left-radius: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-splitbutton .p-menu {
|
|
|
|
min-width: 100%;
|
|
|
|
}
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
.p-fluid .p-splitbutton {
|
2022-09-06 12:03:37 +00:00
|
|
|
display: flex;
|
|
|
|
}
|
|
|
|
</style>
|