Refactor #3965 - Refactor on VirtualScroller

pull/4101/head^2
Tuğçe Küçükoğlu 2023-07-06 16:44:37 +03:00
parent f8f071f5ff
commit 6f6083169f
2 changed files with 33 additions and 39 deletions

View File

@ -5,6 +5,7 @@ import { useStyle } from 'primevue/usestyle';
const styles = ` const styles = `
.p-virtualscroller { .p-virtualscroller {
position: relative; position: relative;
overflow: auto;
contain: strict; contain: strict;
transform: translateZ(0); transform: translateZ(0);
will-change: scroll-position; will-change: scroll-position;
@ -64,35 +65,6 @@ const styles = `
} }
`; `;
const inlineStyles = {
root: { overflow: 'auto' }
};
const classes = {
root: ({ instance, props }) => [
'p-virtualscroller',
{
'p-virtualscroller-inline': props.inline,
'p-virtualscroller-both p-both-scroll': instance.isBoth(),
'p-virtualscroller-horizontal p-horizontal-scroll': instance.isHorizontal()
}
],
content: ({ instance }) => [
'p-virtualscroller-content',
{
'p-virtualscroller-loading': instance.d_loading
}
],
spacer: 'p-virtualscroller-spacer',
loader: ({ instance }) => [
'p-virtualscroller-loader',
{
'p-component-overlay': !instance.$slots.loader
}
],
loadingIcon: 'p-virtualscroller-loading-icon'
};
const { load: loadStyle } = useStyle(styles, { name: 'virtualscroller' }); const { load: loadStyle } = useStyle(styles, { name: 'virtualscroller' });
export default { export default {
@ -181,8 +153,6 @@ export default {
} }
}, },
css: { css: {
classes,
inlineStyles,
loadStyle loadStyle
}, },
provide() { provide() {

View File

@ -1,9 +1,9 @@
<template> <template>
<template v-if="!disabled"> <template v-if="!disabled">
<div :ref="elementRef" :class="containerClass" :tabindex="tabindex" :style="[style, sx('root')]" @scroll="onScroll" v-bind="ptm('root')" data-pc-name="virtualscroller"> <div :ref="elementRef" :class="containerClass" :tabindex="tabindex" :style="style" @scroll="onScroll" v-bind="ptm('root')" data-pc-name="virtualscroller">
<slot <slot
name="content" name="content"
:styleClass="cx('content')" :styleClass="contentClass"
:items="loadedItems" :items="loadedItems"
:getItemOptions="getOptions" :getItemOptions="getOptions"
:loading="d_loading" :loading="d_loading"
@ -18,21 +18,21 @@
:horizontal="isHorizontal()" :horizontal="isHorizontal()"
:both="isBoth()" :both="isBoth()"
> >
<div :ref="contentRef" :class="cx('content')" :style="contentStyle" v-bind="ptm('content')"> <div :ref="contentRef" :class="contentClass" :style="contentStyle" v-bind="ptm('content')">
<template v-for="(item, index) of loadedItems" :key="index"> <template v-for="(item, index) of loadedItems" :key="index">
<slot name="item" :item="item" :options="getOptions(index)"></slot> <slot name="item" :item="item" :options="getOptions(index)"></slot>
</template> </template>
</div> </div>
</slot> </slot>
<div v-if="showSpacer" :class="cx('spacer')" :style="spacerStyle" v-bind="ptm('spacer')"></div> <div v-if="showSpacer" class="p-virtualscroller-spacer" :style="spacerStyle" v-bind="ptm('spacer')"></div>
<div v-if="!loaderDisabled && showLoader && d_loading" :class="cx('loader')" v-bind="ptm('loader')"> <div v-if="!loaderDisabled && showLoader && d_loading" :class="loaderClass" v-bind="ptm('loader')">
<template v-if="$slots && $slots.loader"> <template v-if="$slots && $slots.loader">
<template v-for="(_, index) of loaderArr" :key="index"> <template v-for="(_, index) of loaderArr" :key="index">
<slot name="loader" :options="getLoaderOptions(index, isBoth() && { numCols: d_numItemsInViewport.cols })"></slot> <slot name="loader" :options="getLoaderOptions(index, isBoth() && { numCols: d_numItemsInViewport.cols })"></slot>
</template> </template>
</template> </template>
<slot name="loadingicon" :class="cx('loadingIcon')"> <slot name="loadingicon">
<SpinnerIcon spin :class="cx('loadingIcon')" v-bind="ptm('loadingIcon')" /> <SpinnerIcon spin class="p-virtualscroller-loading-icon" v-bind="ptm('loadingIcon')" />
</slot> </slot>
</div> </div>
</div> </div>
@ -615,7 +615,31 @@ export default {
}, },
computed: { computed: {
containerClass() { containerClass() {
return [this.cx('root'), this.class]; return [
'p-virtualscroller',
this.class,
{
'p-virtualscroller-inline': this.inline,
'p-virtualscroller-both p-both-scroll': this.isBoth(),
'p-virtualscroller-horizontal p-horizontal-scroll': this.isHorizontal()
}
];
},
contentClass() {
return [
'p-virtualscroller-content',
{
'p-virtualscroller-loading': this.d_loading
}
];
},
loaderClass() {
return [
'p-virtualscroller-loader',
{
'p-component-overlay': !this.$slots.loader
}
];
}, },
loadedItems() { loadedItems() {
if (this.items && !this.d_loading) { if (this.items && !this.d_loading) {