npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-widget-tree-basic

v1.0.1

Published

tree-basic

Downloads

8

Readme

react-widget-tree-basic

Tree基础组件

安装

npm install --save react-widget-tree-basic

使用

Edit react-widget-tree-basic


import TreeBasic from 'react-widget-tree-basic';

export default () => <TreeBasic loadData={...} itemRender={...} />

Interfaces

export interface TreeBasicProps<T = DataType> {
    /** 样式前缀 */
    prefixCls: string;
    /** 样式名称 */
    className?: string;
    /** 样式属性 */
    style?: React.CSSProperties;
    /** 树根节点ID */
    rootId: string | number | null;
    /** tree 数据结构 id 属性名称 */
    idField: string;
    /** tree 数据结构 leaf 属性名称 */
    leafField: string;
    /** tree 数据结构 parent 属性名称 */
    pidField: string;
    /** 最大展开层级限制没,默认:99 */
    maxDepth: number;
    /** 异步检测耗时机制,超过该时长即认定为异步加载,默认:16 ms */
    asyncTestDelay: number;
    /** 已展开的节点ID */
    expandedIds: (string | number)[];
    /** Tree数据加载器,必填 */
    loadData: (data: T, node: Node<T>) => T[] | Promise<any>;
    /** 自定义TreeNode的render返回 */
    nodeRender?: (props: nodeRenderProps<T>, item: React.ReactNode, children: React.ReactNode) => React.ReactNode;
    /** 自定义TreeItem的render返回,必填 */
    itemRender: (props: itemRenderProps<T>) => React.ReactNode;
    /** 自定义TreeNode的子节点渲染,一般动画需要使用。*/
    childrenRender: (props: childrenRenderProps<T>) => React.ReactNode;
    /** 异步加载时的加载内容返回,默认为:null */
    loadRender?: (props: LoadRenderProps<T>) => React.ReactNode;
    /** 自定义Tree容器组件*/
    rootComponent: React.ElementType;
}

export declare type renderProps<T> = Omit<TreeNodeProps<T>, "render" | "childrenRender">;
export interface TreeNodeProps<T = DataType> {
    node: Node<T>;
    isRoot: boolean;
    render?: (props: renderProps<T>, nodeItem: React.ReactNode, children: React.ReactNode) => React.ReactNode;
}

export interface TreeNodeProps {
	node: Node;
	isRoot: boolean;
	render?: (
		props: renderProps,
		nodeItem: React.ReactNode,
		children: React.ReactNode
	) => React.ReactNode;
}
export interface childrenRenderProps<T = DataType> {
    getChildren: () => React.ReactNode;
    expanded: boolean;
    loading: boolean;
    root: boolean;
    node: Node<T>;
    data: T;
}
export interface itemRenderProps<T = DataType> {
    expanded: boolean;
    loading: boolean;
    leaf: boolean;
    node: Node<T>;
    data: T;
}
export declare function toMarked(array: any[]): any;
export declare type DataType = Record<string, any>;
export declare type IdType = string | number;
export declare type nodeRenderProps<T> = renderProps<T>;
export interface LoadRenderProps<T = DataType> {
    root: boolean;
    node: Node;
    data: T;
}

defaultProps

{
	prefixCls: "rw-tree",
	rootId: null,
	idField: "id",
	leafField: "leaf",
	pidField: "pid",
	maxDepth: 99, 
	asyncTestDelay: 16,
	expandedIds: [],
	childrenRender(props) {
		if (!props.expanded) return null;
		return props.getChildren();
	},
	rootComponent: "div",
}