primevue-mirror/components/panel/Panel.vue

110 lines
2.9 KiB
Vue
Raw Normal View History

2022-09-06 12:03:37 +00:00
<template>
<div :class="containerClass">
<div class="p-panel-header">
<slot name="header">
2022-09-14 11:26:01 +00:00
<span v-if="header" :id="ariaId + '_header'" class="p-panel-title">{{ header }}</span>
2022-09-06 12:03:37 +00:00
</slot>
<div class="p-panel-icons">
<slot name="icons"></slot>
2022-09-14 11:26:01 +00:00
<button
v-if="toggleable"
:id="ariaId + '_header'"
v-ripple
type="button"
role="button"
class="p-panel-header-icon p-panel-toggler p-link"
:aria-label="toggleButtonProps || header"
:aria-controls="ariaId + '_content'"
:aria-expanded="!d_collapsed"
@click="toggle"
@keydown="onKeyDown"
>
<span :class="{ 'pi pi-minus': !d_collapsed, 'pi pi-plus': d_collapsed }"></span>
2022-09-06 12:03:37 +00:00
</button>
</div>
</div>
<transition name="p-toggleable-content">
2022-09-14 11:26:01 +00:00
<div v-show="!d_collapsed" :id="ariaId + '_content'" class="p-toggleable-content" role="region" :aria-labelledby="ariaId + '_header'">
2022-09-06 12:03:37 +00:00
<div class="p-panel-content">
<slot></slot>
</div>
</div>
</transition>
</div>
</template>
<script>
2022-09-14 11:26:01 +00:00
import { UniqueComponentId } from 'primevue/utils';
2022-09-06 12:03:37 +00:00
import Ripple from 'primevue/ripple';
export default {
name: 'Panel',
emits: ['update:collapsed', 'toggle'],
props: {
header: String,
toggleable: Boolean,
2022-09-14 11:26:01 +00:00
collapsed: Boolean,
toggleButtonProps: String
2022-09-06 12:03:37 +00:00
},
data() {
return {
d_collapsed: this.collapsed
2022-09-14 11:26:01 +00:00
};
2022-09-06 12:03:37 +00:00
},
watch: {
collapsed(newValue) {
this.d_collapsed = newValue;
}
},
methods: {
toggle(event) {
this.d_collapsed = !this.d_collapsed;
this.$emit('update:collapsed', this.d_collapsed);
this.$emit('toggle', {
originalEvent: event,
value: this.d_collapsed
});
2022-09-14 11:26:01 +00:00
},
onKeyDown(event) {
if (event.code === 'Enter' || event.code === 'Space') {
this.toggle(event);
event.preventDefault();
}
2022-09-06 12:03:37 +00:00
}
},
computed: {
ariaId() {
return UniqueComponentId();
},
containerClass() {
2022-09-14 11:26:01 +00:00
return ['p-panel p-component', { 'p-panel-toggleable': this.toggleable }];
2022-09-06 12:03:37 +00:00
}
},
directives: {
2022-09-14 11:26:01 +00:00
ripple: Ripple
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>
.p-panel-header {
display: flex;
justify-content: space-between;
align-items: center;
}
.p-panel-title {
line-height: 1;
}
.p-panel-header-icon {
display: inline-flex;
justify-content: center;
align-items: center;
cursor: pointer;
text-decoration: none;
overflow: hidden;
position: relative;
}
</style>