ant-design/components/tree/index.tsx

108 lines
3.4 KiB
TypeScript
Raw Normal View History

2016-09-21 11:54:53 +08:00
import React from 'react';
2016-08-24 16:09:55 +08:00
import RcTree, { TreeNode } from 'rc-tree';
2016-06-01 12:08:08 +08:00
import animation from '../_util/openAnimation';
2016-08-24 16:09:55 +08:00
export interface AntTreeNodeProps {
2016-07-13 11:14:24 +08:00
disabled?: boolean;
disableCheckbox?: boolean;
title?: string | React.ReactNode;
key?: string;
isLeaf?: boolean;
}
2016-08-24 16:09:55 +08:00
export class AntTreeNode extends React.Component<AntTreeNodeProps, {}> {
render() {
return <AntTreeNode {...this.props} />;
}
}
2016-08-24 16:09:55 +08:00
export interface AntTreeNodeEvent {
2016-07-13 11:14:24 +08:00
event: 'check' | 'select';
2016-08-24 16:09:55 +08:00
node: AntTreeNode;
2016-07-13 11:14:24 +08:00
checked?: boolean;
2016-08-24 16:09:55 +08:00
checkedNodes?: Array<AntTreeNode>;
2016-07-13 11:14:24 +08:00
selected?: boolean;
2016-08-24 16:09:55 +08:00
selectedNodes?: Array<AntTreeNode>;
}
2016-08-24 16:09:55 +08:00
export interface AntTreeNodeMouseEvent {
node: AntTreeNode;
2016-07-13 11:14:24 +08:00
event: React.MouseEventHandler;
}
2016-07-07 20:25:03 +08:00
export interface TreeProps {
2016-07-13 11:14:24 +08:00
showLine?: boolean;
2016-07-13 17:22:23 +08:00
className?: string;
2016-07-13 11:14:24 +08:00
/** 是否支持多选 */
2016-07-13 17:22:23 +08:00
multiple?: boolean;
2016-08-24 16:09:55 +08:00
/** 是否自动展开父节点 */
2016-07-13 11:14:24 +08:00
autoExpandParent?: boolean;
2016-08-24 16:09:55 +08:00
/** checkable状态下节点选择完全受控父子节点选中状态不再关联*/
2016-07-13 11:14:24 +08:00
checkStrictly?: boolean;
/** 是否支持选中 */
checkable?: boolean;
/** 默认展开所有树节点 */
defaultExpandAll?: boolean;
/** 默认展开指定的树节点 */
defaultExpandedKeys?: Array<string>;
/** (受控)展开指定的树节点 */
expandedKeys?: Array<string>;
/** (受控)选中复选框的树节点 */
checkedKeys?: Array<string> | { checked: Array<string>, halfChecked: Array<string> };
2016-07-13 11:14:24 +08:00
/** 默认选中复选框的树节点 */
defaultCheckedKeys?: Array<string>;
/** (受控)设置选中的树节点 */
selectedKeys?: Array<string>;
/** 默认选中的树节点 */
defaultSelectedKeys?: Array<string>;
/** 展开/收起节点时触发 */
2016-08-24 16:09:55 +08:00
onExpand?: (expandedKeys: Array<string>, info: { node: AntTreeNode, expanded: boolean }) => void | PromiseLike<any>;
2016-07-13 11:14:24 +08:00
/** 点击复选框触发 */
2016-08-24 16:09:55 +08:00
onCheck?: (checkedKeys: Array<string>, e: AntTreeNodeEvent) => void;
2016-07-13 11:14:24 +08:00
/** 点击树节点触发 */
2016-08-24 16:09:55 +08:00
onSelect?: (selectedKeys: Array<string>, e: AntTreeNodeEvent) => void;
/** filter some AntTreeNodes as you need. it should return true */
filterAntTreeNode?: (node: AntTreeNode) => boolean;
2016-07-13 11:14:24 +08:00
/** 异步加载数据 */
2016-08-24 16:09:55 +08:00
loadData?: (node: AntTreeNode) => PromiseLike<any>;
2016-07-13 11:14:24 +08:00
/** 响应右键点击 */
2016-08-24 16:09:55 +08:00
onRightClick?: (options: AntTreeNodeMouseEvent) => void;
/** 设置节点可拖拽IE>8*/
2016-07-13 11:14:24 +08:00
draggable?: boolean;
/** 开始拖拽时调用 */
2016-08-24 16:09:55 +08:00
onDragStart?: (options: AntTreeNodeMouseEvent) => void;
2016-07-13 11:14:24 +08:00
/** dragenter 触发时调用 */
2016-08-24 16:09:55 +08:00
onDragEnter?: (options: AntTreeNodeMouseEvent) => void;
/** dragover 触发时调用 */
2016-08-24 16:09:55 +08:00
onDragOver?: (options: AntTreeNodeMouseEvent) => void;
2016-07-13 11:14:24 +08:00
/** dragleave 触发时调用 */
2016-08-24 16:09:55 +08:00
onDragLeave?: (options: AntTreeNodeMouseEvent) => void;
2016-07-13 11:14:24 +08:00
/** drop 触发时调用 */
2016-08-24 16:09:55 +08:00
onDrop?: (options: AntTreeNodeMouseEvent) => void;
2016-07-13 11:14:24 +08:00
style?: React.CSSProperties;
prefixCls?: string;
filterTreeNode?: (node: AntTreeNode) => boolean;
}
export default class Tree extends React.Component<TreeProps, any> {
2016-08-24 16:09:55 +08:00
static TreeNode = TreeNode;
static defaultProps = {
prefixCls: 'ant-tree',
checkable: false,
showIcon: false,
openAnimation: animation,
2016-07-13 11:14:24 +08:00
};
2015-08-03 16:07:21 +08:00
render() {
2015-08-19 12:18:10 +08:00
const props = this.props;
let checkable = props.checkable;
return (
2016-07-13 11:14:24 +08:00
<RcTree {...props}
checkable={checkable ? (<span className={`${props.prefixCls}-checkbox-inner`}></span>) : checkable }>
{this.props.children}
</RcTree>
);
2015-08-03 16:07:21 +08:00
}
}