primevue-mirror/components/dataviewlayoutoptions/DataViewLayoutOptions.vue

54 lines
1.8 KiB
Vue
Raw Normal View History

2022-09-06 12:03:37 +00:00
<template>
2022-12-08 11:04:25 +00:00
<div class="p-dataview-layout-options p-selectbutton p-buttonset" role="group">
<button :aria-label="listViewAriaLabel" :class="buttonListClass" @click="changeLayout('list')" type="button" :aria-pressed="isListButtonPressed">
2022-09-14 11:26:01 +00:00
<i class="pi pi-bars"></i>
</button>
2022-12-08 11:04:25 +00:00
<button :aria-label="gridViewAriaLabel" :class="buttonGridClass" @click="changeLayout('grid')" type="button" :aria-pressed="isGridButtonPressed">
2022-09-14 11:26:01 +00:00
<i class="pi pi-th-large"></i>
</button>
</div>
2022-09-06 12:03:37 +00:00
</template>
<script>
2022-09-14 11:26:01 +00:00
export default {
name: 'DataViewLayoutOptions',
emits: ['update:modelValue'],
props: {
modelValue: String
},
2022-12-08 11:04:25 +00:00
data() {
return {
isListButtonPressed: false,
isGridButtonPressed: false
};
},
2022-09-14 11:26:01 +00:00
methods: {
changeLayout(layout) {
this.$emit('update:modelValue', layout);
2022-12-08 11:04:25 +00:00
if (layout === 'list') {
this.isListButtonPressed = true;
this.isGridButtonPressed = false;
} else if (layout === 'grid') {
this.isGridButtonPressed = true;
this.isListButtonPressed = false;
}
2022-09-14 11:26:01 +00:00
}
},
computed: {
buttonListClass() {
return ['p-button p-button-icon-only', { 'p-highlight': this.modelValue === 'list' }];
},
buttonGridClass() {
return ['p-button p-button-icon-only', { 'p-highlight': this.modelValue === 'grid' }];
2022-12-08 11:04:25 +00:00
},
listViewAriaLabel() {
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.listView : undefined;
},
gridViewAriaLabel() {
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.gridView : undefined;
2022-09-14 11:26:01 +00:00
}
}
};
2022-09-06 12:03:37 +00:00
</script>