Refactor #3924 - For OrderList

pull/3950/head
Tuğçe Küçükoğlu 2023-05-09 19:03:01 +03:00
parent c7ffcaa08d
commit f1ea8f9f9a
4 changed files with 150 additions and 16 deletions

View File

@ -47,6 +47,12 @@ const OrderListProps = [
type: 'boolean', type: 'boolean',
default: 'false', default: 'false',
description: 'Whether to displays rows with alternating colors.' description: 'Whether to displays rows with alternating colors.'
},
{
name: 'pt',
type: 'any',
default: 'null',
description: 'Uses to pass attributes to DOM elements inside the component.'
} }
]; ];

View File

@ -43,6 +43,7 @@ import { MenuPassThroughOptions } from '../menu';
import { MenubarPassThroughOptions } from '../menubar'; import { MenubarPassThroughOptions } from '../menubar';
import { MessagePassThroughOptions } from '../message'; import { MessagePassThroughOptions } from '../message';
import { MultiSelectPassThroughOptions } from '../multiselect'; import { MultiSelectPassThroughOptions } from '../multiselect';
import { OrderListPassThroughOptions } from '../orderlist';
import { OverlayPanelPassThroughOptions } from '../overlaypanel'; import { OverlayPanelPassThroughOptions } from '../overlaypanel';
import { PaginatorPassThroughOptions } from '../paginator'; import { PaginatorPassThroughOptions } from '../paginator';
import { PanelPassThroughOptions } from '../panel'; import { PanelPassThroughOptions } from '../panel';
@ -134,6 +135,7 @@ interface PrimeVuePTOptions {
menubar?: MenubarPassThroughOptions; menubar?: MenubarPassThroughOptions;
message?: MessagePassThroughOptions; message?: MessagePassThroughOptions;
multiselect?: MultiSelectPassThroughOptions; multiselect?: MultiSelectPassThroughOptions;
orderlist?: OrderListPassThroughOptions;
overlaypanel?: OverlayPanelPassThroughOptions; overlaypanel?: OverlayPanelPassThroughOptions;
paginator?: PaginatorPassThroughOptions; paginator?: PaginatorPassThroughOptions;
panel?: PanelPassThroughOptions; panel?: PanelPassThroughOptions;

View File

@ -8,8 +8,20 @@
* *
*/ */
import { ButtonHTMLAttributes, HTMLAttributes, VNode } from 'vue'; import { ButtonHTMLAttributes, HTMLAttributes, VNode } from 'vue';
import { ButtonPassThroughOptionType } from '../button';
import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers'; import { ClassComponent, GlobalComponentConstructor } from '../ts-helpers';
export declare type OrderListPassThroughOptionType = OrderListPassThroughAttributes | ((options: OrderListPassThroughMethodOptions) => OrderListPassThroughAttributes) | null | undefined;
/**
* Custom passthrough(pt) option method.
*/
export interface OrderListPassThroughMethodOptions {
props: OrderListProps;
state: OrderListState;
context: OrderListState;
}
/** /**
* Custom reorder event * Custom reorder event
* @see {@link OrderListEmits.reorder} * @see {@link OrderListEmits.reorder}
@ -44,6 +56,100 @@ export interface OrderListSelectionChangeEvent {
value: any[]; value: any[];
} }
/**
* Custom passthrough(pt) options.
* @see {@link OrderListProps.pt}
*/
export interface OrderListPassThroughOptions {
/**
* Uses to pass attributes to the root's DOM element.
*/
root?: OrderListPassThroughOptionType;
/**
* Uses to pass attributes to the controls' DOM element.
*/
controls?: OrderListPassThroughOptionType;
/**
* Uses to pass attributes to the Button component.
*/
moveUpButton?: ButtonPassThroughOptionType;
/**
* Uses to pass attributes to the Button component.
*/
moveTopButton?: ButtonPassThroughOptionType;
/**
* Uses to pass attributes to the Button component.
*/
moveDownButton?: ButtonPassThroughOptionType;
/**
* Uses to pass attributes to the Button component.
*/
moveBottomButton?: ButtonPassThroughOptionType;
/**
* Uses to pass attributes to the container's DOM element.
*/
container?: OrderListPassThroughOptionType;
/**
* Uses to pass attributes to the header's DOM element.
*/
header?: OrderListPassThroughOptionType;
/**
* Uses to pass attributes to the list's DOM element.
*/
list?: OrderListPassThroughOptionType;
/**
* Uses to pass attributes to the item's DOM element.
*/
item?: OrderListPassThroughOptionType;
}
/**
* Custom passthrough attributes for each DOM elements
*/
export interface OrderListPassThroughAttributes {
[key: string]: any;
}
/**
* Defines current inline state in OrderList component.
*/
export interface OrderListState {
/**
* Current id state as a string.
*/
id: string;
/**
* Current id state as a string.
*/
d_selection: any[];
/**
* Current focused state as a boolean.
* @defaultValue false
*/
focused: boolean;
/**
* Current focused item index as a number.
* @defaultvalue -1
*/
focusedOptionIndex: number;
}
/**
* Defines current inline state in OrderList component.
*/
export interface OrderListState {
/**
* Current active state of the item as a boolean.
* @defaultValue false
*/
active: boolean;
/**
* Current focus state of the item as a boolean.
* @defaultValue false
*/
focused: boolean;
}
/** /**
* Defines valid properties in OrderList component. * Defines valid properties in OrderList component.
*/ */

View File

@ -1,39 +1,39 @@
<template> <template>
<div :class="containerClass"> <div :class="containerClass" v-bind="ptm('root')">
<div class="p-orderlist-controls"> <div class="p-orderlist-controls" v-bind="ptm('controls')">
<slot name="controlsstart"></slot> <slot name="controlsstart"></slot>
<OLButton type="button" @click="moveUp" :aria-label="moveUpAriaLabel" :disabled="moveDisabled()" v-bind="moveUpButtonProps"> <OLButton type="button" @click="moveUp" :aria-label="moveUpAriaLabel" :disabled="moveDisabled()" v-bind="moveUpButtonProps" :pt="ptm('moveUpButton')">
<template #icon> <template #icon>
<slot name="moveupicon"> <slot name="moveupicon">
<AngleUpIcon /> <AngleUpIcon v-bind="ptm('moveUpButton')['icon']" />
</slot> </slot>
</template> </template>
</OLButton> </OLButton>
<OLButton type="button" @click="moveTop" :aria-label="moveTopAriaLabel" :disabled="moveDisabled()" v-bind="moveTopButtonProps"> <OLButton type="button" @click="moveTop" :aria-label="moveTopAriaLabel" :disabled="moveDisabled()" v-bind="moveTopButtonProps" :pt="ptm('moveTopButton')">
<template #icon <template #icon>
><slot name="movetopicon"> <slot name="movetopicon">
<AngleDoubleUpIcon /> <AngleDoubleUpIcon v-bind="ptm('moveTopButton')['icon']" />
</slot> </slot>
</template> </template>
</OLButton> </OLButton>
<OLButton type="button" @click="moveDown" :aria-label="moveDownAriaLabel" :disabled="moveDisabled()" v-bind="moveDownButtonProps"> <OLButton type="button" @click="moveDown" :aria-label="moveDownAriaLabel" :disabled="moveDisabled()" v-bind="moveDownButtonProps" :pt="ptm('moveDownButton')">
<template #icon> <template #icon>
<slot name="movedownicon"> <slot name="movedownicon">
<AngleDownIcon /> <AngleDownIcon v-bind="ptm('moveDownButton')['icon']" />
</slot> </slot>
</template> </template>
</OLButton> </OLButton>
<OLButton type="button" @click="moveBottom" :aria-label="moveBottomAriaLabel" :disabled="moveDisabled()" v-bind="moveBottomButtonProps"> <OLButton type="button" @click="moveBottom" :aria-label="moveBottomAriaLabel" :disabled="moveDisabled()" v-bind="moveBottomButtonProps" :pt="ptm('moveBottomButton')">
<template #icon> <template #icon>
<slot name="movebottomicon"> <slot name="movebottomicon">
<AngleDoubleDownIcon /> <AngleDoubleDownIcon v-bind="ptm('moveBottomButton')['icon']" />
</slot> </slot>
</template> </template>
</OLButton> </OLButton>
<slot name="controlsend"></slot> <slot name="controlsend"></slot>
</div> </div>
<div class="p-orderlist-list-container"> <div class="p-orderlist-list-container" v-bind="ptm('container')">
<div v-if="$slots.header" class="p-orderlist-header"> <div v-if="$slots.header" class="p-orderlist-header" v-bind="ptm('header')">
<slot name="header"></slot> <slot name="header"></slot>
</div> </div>
<transition-group <transition-group
@ -52,10 +52,20 @@
@focus="onListFocus" @focus="onListFocus"
@blur="onListBlur" @blur="onListBlur"
@keydown="onListKeyDown" @keydown="onListKeyDown"
v-bind="listProps" v-bind="{ ...listProps, ...ptm('list') }"
> >
<template v-for="(item, i) of modelValue" :key="getItemKey(item, i)"> <template v-for="(item, i) of modelValue" :key="getItemKey(item, i)">
<li :id="id + '_' + i" v-ripple role="option" :class="itemClass(item, `${id}_${i}`)" @click="onItemClick($event, item, i)" @touchend="onItemTouchEnd" :aria-selected="isSelected(item)" @mousedown="onOptionMouseDown(i)"> <li
:id="id + '_' + i"
v-ripple
role="option"
:class="itemClass(item, `${id}_${i}`)"
@click="onItemClick($event, item, i)"
@touchend="onItemTouchEnd"
:aria-selected="isSelected(item)"
@mousedown="onOptionMouseDown(i)"
v-bind="getPTOptions(item, 'item')"
>
<slot name="item" :item="item" :index="i"> </slot> <slot name="item" :item="item" :index="i"> </slot>
</li> </li>
</template> </template>
@ -65,6 +75,7 @@
</template> </template>
<script> <script>
import BaseComponent from 'primevue/basecomponent';
import Button from 'primevue/button'; import Button from 'primevue/button';
import AngleDoubleDownIcon from 'primevue/icons/angledoubledown'; import AngleDoubleDownIcon from 'primevue/icons/angledoubledown';
import AngleDoubleUpIcon from 'primevue/icons/angledoubleup'; import AngleDoubleUpIcon from 'primevue/icons/angledoubleup';
@ -75,6 +86,7 @@ import { DomHandler, ObjectUtils, UniqueComponentId } from 'primevue/utils';
export default { export default {
name: 'OrderList', name: 'OrderList',
extends: BaseComponent,
emits: ['update:modelValue', 'reorder', 'update:selection', 'selection-change', 'focus', 'blur'], emits: ['update:modelValue', 'reorder', 'update:selection', 'selection-change', 'focus', 'blur'],
props: { props: {
modelValue: { modelValue: {
@ -179,6 +191,14 @@ export default {
getItemKey(item, index) { getItemKey(item, index) {
return this.dataKey ? ObjectUtils.resolveFieldData(item, this.dataKey) : index; return this.dataKey ? ObjectUtils.resolveFieldData(item, this.dataKey) : index;
}, },
getPTOptions(item, key) {
return this.ptm(key, {
context: {
active: this.isSelected(item),
focused: this.id === this.focusedOptionId
}
});
},
isSelected(item) { isSelected(item) {
return ObjectUtils.findIndexInList(item, this.d_selection) != -1; return ObjectUtils.findIndexInList(item, this.d_selection) != -1;
}, },