@douyinfe/semi-ui
Version:
A modern, comprehensive, flexible design system and UI library. Connect DesignOps & DevOps. Quickly build beautiful React apps. Maintained by Douyin-fe team.
111 lines (110 loc) • 4.22 kB
TypeScript
import React, { AriaAttributes } from 'react';
import BaseComponent from '../_base/baseComponent';
import PropTypes from 'prop-types';
import { Item, ScrollItemAdapter } from '@douyinfe/semi-foundation/lib/cjs/scrollList/itemFoundation';
import { Motion } from '../_base/base';
interface DebounceSelectFn {
(e: React.UIEvent, newSelectedNode: HTMLElement): void;
cancel(): void;
}
export interface ScrollItemProps<T extends Item> {
mode?: string;
cycled?: boolean;
list?: T[];
selectedIndex?: number;
onSelect?: (data: T) => void;
transform?: (value: any, text: string) => string;
className?: string;
motion?: Motion;
style?: React.CSSProperties;
type?: string | number;
'aria-label'?: AriaAttributes['aria-label'];
}
export interface ScrollItemState {
prependCount: number;
appendCount: number;
}
export default class ScrollItem<T extends Item> extends BaseComponent<ScrollItemProps<T>, ScrollItemState> {
static propTypes: {
mode: PropTypes.Requireable<"normal" | "wheel">;
cycled: PropTypes.Requireable<boolean>;
list: PropTypes.Requireable<any[]>;
selectedIndex: PropTypes.Requireable<number>;
onSelect: PropTypes.Requireable<(...args: any[]) => any>;
transform: PropTypes.Requireable<(...args: any[]) => any>;
className: PropTypes.Requireable<string>;
style: PropTypes.Requireable<object>;
motion: PropTypes.Requireable<NonNullable<boolean | ((...args: any[]) => any)>>;
type: PropTypes.Requireable<NonNullable<string | number>>;
};
static defaultProps: {
selectedIndex: number;
motion: boolean;
list: readonly [];
onSelect: (...args: any[]) => void;
cycled: boolean;
mode: string;
};
selectedNode: HTMLElement;
willSelectNode: HTMLElement;
list: HTMLElement;
wrapper: HTMLElement;
selector: unknown;
scrollAnimation: any;
scrolling: boolean;
throttledAdjustList: DebounceSelectFn;
debouncedSelect: DebounceSelectFn;
constructor(props?: {});
get adapter(): ScrollItemAdapter<ScrollItemProps<T>, ScrollItemState, T>;
componentWillUnmount(): void;
componentDidMount(): void;
componentDidUpdate(prevProps: ScrollItemProps<T>): void;
_cacheNode: (name: string, node: Element) => Element;
_cacheSelectedNode: (selectedNode: Element) => Element;
_cacheWillSelectNode: (node: Element) => Element;
_cacheListNode: (list: Element) => Element;
_cacheSelectorNode: (selector: Element) => Element;
_cacheWrapperNode: (wrapper: Element) => Element;
_isFirst: (node: Element) => boolean;
_isLast: (node: Element) => boolean;
/**
*
* @param {HTMLElement} refNode
* @param {number} offset
* @param {HTMLElement} listWrapper
*
* @returns {HTMLElement}
*/
getNodeByOffset(refNode: Element, offset: number, listWrapper: Element): Element;
indexIsSame: (index1: number, index2: number) => boolean;
isDisabledIndex: (index: number) => boolean;
isDisabledNode: (node: Element) => boolean;
isDisabledData: (data: T) => boolean;
isWheelMode: () => boolean;
addClassToNode: (selectedNode: Element, selectedCls?: string) => void;
getIndexByNode: (node: Element) => number;
getNodeByIndex: (index: number) => Element;
scrollToIndex: (selectedIndex: number, duration?: number) => void;
scrollToNode: (node: HTMLElement, duration: number) => void;
scrollToPos: (targetTop: number, duration?: number) => void;
scrollToSelectItem: React.UIEventHandler;
/**
*
* reset position to center of the scrollWrapper
*
* @param {HTMLElement} selectedNode
* @param {HTMLElement} scrollWnumber
* @param {number} duration
*/
scrollToCenter: ScrollItemAdapter['scrollToCenter'];
clickToSelectItem: React.MouseEventHandler;
getItmHeight: (itm: HTMLElement) => number;
renderItemList: (prefixKey?: string) => React.JSX.Element[];
renderNormalList: () => React.JSX.Element;
/**
* List of Rendering Unlimited Modes
*/
renderInfiniteList: () => React.JSX.Element;
render(): React.JSX.Element;
}
export {};