Skip to content

Commit

Permalink
Fixed #2063 - New Component: VirtualScroll
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed May 25, 2021
1 parent 9d03ef6 commit deae083
Show file tree
Hide file tree
Showing 6 changed files with 506 additions and 0 deletions.
1 change: 1 addition & 0 deletions exports/virtualscroll.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './components/virtualscroll/VirtualScroll';
3 changes: 3 additions & 0 deletions exports/virtualscroll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = require('./components/virtualscroll/VirtualScroll');
1 change: 1 addition & 0 deletions src/assets/style/primereact.css
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,4 @@
@import '../../components/chip/Chip.css';
@import '../../components/cascadeselect/CascadeSelect.css';
@import '../../components/treeselect/TreeSelect.css';
@import '../../components/virtualscroll/VirtualScroll.css';
40 changes: 40 additions & 0 deletions src/components/virtualscroll/VirtualScroll.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.p-virtual-scroll {
position: relative;
overflow: auto;
contain: strict;
transform: translateZ(0);
will-change: scroll-position;
}

.p-virtual-scroll-content {
position: absolute;
top: 0;
left: 0;
contain: content;
min-height: 100%;
min-width: 100%;
}

.p-virtual-scroll-spacer {
position: absolute;
top: 0;
left: 0;
height: 1px;
width: 1px;
transform-origin: 0 0;
pointer-events: none;
}

.p-virtual-scroll-loader {
position: sticky;
top: 0;
left: 0;
width: 100%;
height: 100%;
}

.p-virtual-scroll-loader.p-component-overlay {
display: flex;
align-items: center;
justify-content: center;
}
70 changes: 70 additions & 0 deletions src/components/virtualscroll/VirtualScroll.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import * as React from 'react';

type VirtualScrollItemsType = any[] | any[][] | undefined | null;

type VirtualScrollItemSizeType = number | number[];

type VirtualScrollOrientationType = 'vertical' | 'horizontal' | 'both';

type VirtualScrollLoadingTemplateType = React.ReactNode | ((options: VirtualScrollLoadingTemplateOptions) => React.ReactNode);

type VirtualScrollItemTemplateType = React.ReactNode | ((item: any, options: VirtualScrollTemplateOptions) => React.ReactNode);

type VirtualScrollContentTemplateType = React.ReactNode | ((options: VirtualScrollContentTemplateOptions) => React.ReactNode);

type VirtualScrollStateType = number | VirtualScrollState;

type VirtualScrollToIndexType = number | number[];

interface VirtualScrollState {
rows: number;
cols: number;
}

interface VirtualScrollTemplateOptions {
index: number;
count: number;
first: boolean;
last: boolean;
even: boolean;
odd: boolean;
props: VirtualScrollProps;
}

interface VirtualScrollLoadingTemplateOptions extends VirtualScrollTemplateOptions {
numCols: number;
}

interface VirtualScrollContentTemplateOptions {
className: string;
ref: any;
children: any;
element: JSX.Element;
props: VirtualScrollProps;
}

interface VirtualScrollChangeParams {
first: VirtualScrollStateType;
numItems: VirtualScrollStateType;
}

export interface VirtualScrollProps {
id?: string;
style?: object;
className?: string;
items?: VirtualScrollItemsType;
itemSize?: VirtualScrollItemSizeType;
orientation?: VirtualScrollOrientationType;
numToleratedItems?: number;
delay?: number;
lazy?: boolean;
showLoader?: boolean;
loadingTemplate?: VirtualScrollLoadingTemplateType;
itemTemplate?: VirtualScrollItemTemplateType;
contentTemplate?: VirtualScrollContentTemplateType;
onScrollChange?(e: VirtualScrollChangeParams): void;
}

export declare class VirtualScroll extends React.Component<VirtualScrollProps, any> {
public scrollToIndex(index: VirtualScrollToIndexType): void;
}
Loading

0 comments on commit deae083

Please sign in to comment.