Skip to content

Commit

Permalink
Refactor #5437 - For DataViewLayoutOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Mar 20, 2024
1 parent d6f209a commit fd7245d
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 65 deletions.
41 changes: 18 additions & 23 deletions components/lib/dataviewlayoutoptions/DataViewLayoutOptions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import { VNode } from 'vue';
import { ComponentHooks } from '../basecomponent';
import { PassThroughOptions } from '../passthrough';
import { SelectButtonPassThroughOptions } from '../selectbutton';
import { ClassComponent, GlobalComponentConstructor, PassThrough } from '../ts-helpers';

export declare type DataViewLayoutOptionsPassThroughOptionType =
Expand Down Expand Up @@ -56,24 +57,9 @@ export interface DataViewLayoutOptionsPassThroughMethodOptions {
export interface DataViewLayoutOptionsPassThroughOptions {
/**
* Used to pass attributes to the root's DOM element.
* @see {@link SelectButtonPassThroughOptions}
*/
root?: DataViewLayoutOptionsPassThroughOptionType;
/**
* Used to pass attributes to the list button's DOM element.
*/
listButton?: DataViewLayoutOptionsPassThroughOptionType;
/**
* Used to pass attributes to the list icon's DOM element.
*/
listIcon?: DataViewLayoutOptionsPassThroughOptionType;
/**
* Used to pass attributes to the grid button's DOM element.
*/
gridButton?: DataViewLayoutOptionsPassThroughOptionType;
/**
* Used to pass attributes to the grid icon's DOM element.
*/
gridIcon?: DataViewLayoutOptionsPassThroughOptionType;
root?: SelectButtonPassThroughOptions<DataViewLayoutOptionsSharedPassThroughMethodOptions>;
/**
* Used to manage all lifecycle hooks.
* @see {@link BaseComponent.ComponentHooks}
Expand All @@ -93,15 +79,24 @@ export interface DataViewLayoutOptionsPassThroughAttributes {
*/
export interface DataViewLayoutOptionsState {
/**
* Current list button pressed state as a boolean.
* @defaultValue false
* Default options of the component.
* @defaultValue ['list', 'grid']
*/
options: string[];
}

/**
* Custom shared passthrough(pt) option method.
*/
export interface DataViewLayoutOptionsSharedPassThroughMethodOptions {
/**
* Defines valid properties.
*/
isListButtonPressed: boolean;
props: DataViewLayoutOptionsProps;
/**
* Current grid button pressed state as a boolean.
* @defaultValue false
* Defines current inline state.
*/
isGridButtonPressed: boolean;
state: DataViewLayoutOptionsState;
}

/**
Expand Down
31 changes: 11 additions & 20 deletions components/lib/dataviewlayoutoptions/DataViewLayoutOptions.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<template>
<div :class="cx('root')" role="group" v-bind="ptmi('root')">
<button :aria-label="listViewAriaLabel" :class="cx('listButton')" @click="changeLayout('list')" type="button" :aria-pressed="isListButtonPressed" v-bind="ptm('listButton')">
<slot name="listicon">
<SelectButton :class="cx('root')" :modelValue="modelValue" :options="options" :allowEmpty="false" :unstyled="unstyled" @update:modelValue="changeLayout">
<template #option="{ option }">
<slot v-if="option === 'list'" name="listicon">
<BarsIcon v-bind="ptm('listIcon')" />
</slot>
</button>
<button :aria-label="gridViewAriaLabel" :class="cx('gridButton')" @click="changeLayout('grid')" type="button" :aria-pressed="isGridButtonPressed" v-bind="ptm('gridButton')">
<slot name="gridicon">
<slot v-else-if="option === 'grid'" name="gridicon">
<ThLargeIcon v-bind="ptm('gridIcon')" />
</slot>
</button>
</div>
</template>
</SelectButton>
</template>

<script>
import BarsIcon from 'primevue/icons/bars';
import ThLargeIcon from 'primevue/icons/thlarge';
import SelectButton from 'primevue/selectbutton';
import BaseDataViewLayoutOptions from './BaseDataViewLayoutOptions.vue';
export default {
Expand All @@ -25,21 +24,12 @@ export default {
emits: ['update:modelValue'],
data() {
return {
isListButtonPressed: false,
isGridButtonPressed: false
options: ['list', 'grid']
};
},
methods: {
changeLayout(layout) {
this.$emit('update:modelValue', layout);
if (layout === 'list') {
this.isListButtonPressed = true;
this.isGridButtonPressed = false;
} else if (layout === 'grid') {
this.isGridButtonPressed = true;
this.isListButtonPressed = false;
}
}
},
computed: {
Expand All @@ -51,8 +41,9 @@ export default {
}
},
components: {
BarsIcon: BarsIcon,
ThLargeIcon: ThLargeIcon
SelectButton,
BarsIcon,
ThLargeIcon
}
};
</script>
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
import BaseStyle from 'primevue/base/style';

const classes = {
root: 'p-dataview-layout-options p-selectbutton p-button-group',
listButton: ({ props }) => [
'p-button p-button-icon-only',
{
'p-highlight': props.modelValue === 'list'
}
],
gridButton: ({ props }) => [
'p-button p-button-icon-only',
{
'p-highlight': props.modelValue === 'grid'
}
]
root: 'p-dataview-layout-options'
};

export default BaseStyle.extend({
Expand Down
14 changes: 7 additions & 7 deletions components/lib/selectbutton/SelectButton.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import { ComponentHooks } from '../basecomponent';
import { PassThroughOptions } from '../passthrough';
import { ClassComponent, GlobalComponentConstructor, PassThrough } from '../ts-helpers';

export declare type SelectButtonPassThroughOptionType = SelectButtonPassThroughAttributes | ((options: SelectButtonPassThroughMethodOptions) => SelectButtonPassThroughAttributes | string) | string | null | undefined;
export declare type SelectButtonPassThroughOptionType<T = any> = SelectButtonPassThroughAttributes | ((options: SelectButtonPassThroughMethodOptions<T>) => SelectButtonPassThroughAttributes | string) | string | null | undefined;

/**
* Custom passthrough(pt) option method.
*/
export interface SelectButtonPassThroughMethodOptions {
export interface SelectButtonPassThroughMethodOptions<T = any> {
/**
* Defines instance.
*/
Expand All @@ -41,7 +41,7 @@ export interface SelectButtonPassThroughMethodOptions {
/**
* Defines parent options.
*/
parent: any;
parent: T;
/**
* Defines passthrough(pt) options in global config.
*/
Expand All @@ -52,19 +52,19 @@ export interface SelectButtonPassThroughMethodOptions {
* Custom passthrough(pt) options.
* @see {@link SelectButtonProps.pt}
*/
export interface SelectButtonPassThroughOptions {
export interface SelectButtonPassThroughOptions<T = any> {
/**
* Used to pass attributes to the root's DOM element.
*/
root?: SelectButtonPassThroughOptionType;
root?: SelectButtonPassThroughOptionType<T>;
/**
* Used to pass attributes to the button's DOM element.
*/
button?: SelectButtonPassThroughOptionType;
button?: SelectButtonPassThroughOptionType<T>;
/**
* Used to pass attributes to the label's DOM element.
*/
label?: SelectButtonPassThroughOptionType;
label?: SelectButtonPassThroughOptionType<T>;
/**
* Used to manage all lifecycle hooks.
* @see {@link BaseComponent.ComponentHooks}
Expand Down
8 changes: 6 additions & 2 deletions components/lib/selectbutton/SelectButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:key="getOptionRenderKey(option)"
v-ripple
:tabindex="findTabindex(option, i)"
:aria-label="getOptionLabel(option)"
:aria-label="getOptionLabel(option, i)"
:role="multiple ? 'checkbox' : 'radio'"
:aria-checked="isSelected(option)"
:aria-disabled="isOptionDisabled(option)"
Expand Down Expand Up @@ -54,7 +54,11 @@ export default {
}
}
},
getOptionLabel(option) {
getOptionLabel(option, index) {
if (this.$parent.$name === 'DataViewLayoutOptions') {
return index === 0 ? this.$parent.listViewAriaLabel : this.$parent.gridViewAriaLabel;
}
return this.optionLabel ? ObjectUtils.resolveFieldData(option, this.optionLabel) : option;
},
getOptionValue(option) {
Expand Down
1 change: 1 addition & 0 deletions nuxt-vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ export default {
'primevue/message': path.resolve(__dirname, './components/lib/message/Message.vue'),
'primevue/tree': path.resolve(__dirname, './components/lib/tree/Tree.vue'),
'primevue/badge': path.resolve(__dirname, './components/lib/badge/Badge.vue'),
'primevue/selectbutton': path.resolve(__dirname, './components/lib/selectbutton/SelectButton.vue'),
'primevue/confirmationeventbus': path.resolve(__dirname, './components/lib/confirmationeventbus/ConfirmationEventBus.js'),
'primevue/toasteventbus': path.resolve(__dirname, './components/lib/toasteventbus/ToastEventBus.js'),
'primevue/overlayeventbus': path.resolve(__dirname, './components/lib/overlayeventbus/OverlayEventBus.js'),
Expand Down

0 comments on commit fd7245d

Please sign in to comment.