Refactor #3832 Refactor #3833 - For DataViewLayoutOptions

pull/3853/head
Tuğçe Küçükoğlu 2023-04-07 09:47:10 +03:00
parent dbf14c217d
commit 30beabe7b8
4 changed files with 48 additions and 6 deletions

View File

@ -1,7 +1,29 @@
const DataViewLayoutOptionsProps = [
{
name: 'modelValue',
type: 'string',
default: 'null',
description: 'Value of the component.'
}
];
const DataViewLayoutOptionsSlots = [
{
name: 'listicon',
description: 'Custom list icon template.'
},
{
name: 'gridicon',
description: 'Custom grid icon template.'
}
];
module.exports = { module.exports = {
dataviewlayoutoptions: { dataviewlayoutoptions: {
name: 'DataViewLayoutOptions', name: 'DataViewLayoutOptions',
description: 'When both layout modes are enabled in DataView, a UI element would be necessary to let the user toggle between the view. DataViewLayoutOptions is a helper component to display a buttonset to choose the layout mode in DataView.', description: 'When both layout modes are enabled in DataView, a UI element would be necessary to let the user toggle between the view. DataViewLayoutOptions is a helper component to display a buttonset to choose the layout mode in DataView.',
'doc-url': 'dataview' 'doc-url': 'dataview',
props: DataViewLayoutOptionsProps,
slots: DataViewLayoutOptionsSlots
} }
}; };

View File

@ -7,6 +7,7 @@
* @module dataviewlayoutoptions * @module dataviewlayoutoptions
* *
*/ */
import { VNode } from 'vue';
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers'; import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
/** /**
@ -20,9 +21,18 @@ export interface DataViewLayoutOptionsProps {
} }
/** /**
* Defines valid propslotserties in DataViewLayoutOptions component. * Defines valid slots in DataViewLayoutOptions component.
*/ */
export interface DataViewLayoutOptionsSlots {} export interface DataViewLayoutOptionsSlots {
/**
* Custom list icon template.
*/
listicon(): VNode[];
/**
* Custom grid icon template.
*/
gridicon(): VNode[];
}
/** /**
* Defines valid emits in DataViewLayoutOptions component. * Defines valid emits in DataViewLayoutOptions component.

View File

@ -23,7 +23,6 @@ describe('DataViewLayoutOptions.vue', () => {
}); });
expect(wrapper.find('.p-dataview-layout-options').exists()).toBe(true); expect(wrapper.find('.p-dataview-layout-options').exists()).toBe(true);
expect(wrapper.find('.p-highlight > .pi-th-large').exists()).toBe(true);
wrapper.vm.$emit('update:modelValue', 'list'); wrapper.vm.$emit('update:modelValue', 'list');

View File

@ -1,15 +1,22 @@
<template> <template>
<div class="p-dataview-layout-options p-selectbutton p-buttonset" role="group"> <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"> <button :aria-label="listViewAriaLabel" :class="buttonListClass" @click="changeLayout('list')" type="button" :aria-pressed="isListButtonPressed">
<i class="pi pi-bars"></i> <slot name="listicon">
<BarsIcon />
</slot>
</button> </button>
<button :aria-label="gridViewAriaLabel" :class="buttonGridClass" @click="changeLayout('grid')" type="button" :aria-pressed="isGridButtonPressed"> <button :aria-label="gridViewAriaLabel" :class="buttonGridClass" @click="changeLayout('grid')" type="button" :aria-pressed="isGridButtonPressed">
<i class="pi pi-th-large"></i> <slot name="gridicon">
<ThLargeIcon />
</slot>
</button> </button>
</div> </div>
</template> </template>
<script> <script>
import BarsIcon from 'primevue/icon/bars';
import ThLargeIcon from 'primevue/icon/thlarge';
export default { export default {
name: 'DataViewLayoutOptions', name: 'DataViewLayoutOptions',
emits: ['update:modelValue'], emits: ['update:modelValue'],
@ -48,6 +55,10 @@ export default {
gridViewAriaLabel() { gridViewAriaLabel() {
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.gridView : undefined; return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.gridView : undefined;
} }
},
components: {
BarsIcon: BarsIcon,
ThLargeIcon: ThLargeIcon
} }
}; };
</script> </script>