ant-design/components/tree/index.tsx

104 lines
3.2 KiB
TypeScript
Raw Normal View History

import * as React from 'react';
import RcTree from 'rc-tree';
2016-06-01 12:08:08 +08:00
import animation from '../_util/openAnimation';
2016-07-07 20:25:03 +08:00
export interface TreeNodeProps {
2016-07-13 11:14:24 +08:00
disabled?: boolean;
disableCheckbox?: boolean;
title?: string | React.ReactNode;
key?: string;
isLeaf?: boolean;
}
export class TreeNode extends React.Component<TreeNodeProps, {}> {
}
2016-07-07 20:25:03 +08:00
export interface TreeNodeEvent {
2016-07-13 11:14:24 +08:00
event: 'check' | 'select';
node: TreeNode;
checked?: boolean;
checkedNodes?: Array<TreeNode>;
selected?: boolean;
selectedNodes?: Array<TreeNode>;
}
2016-07-07 20:25:03 +08:00
export interface TreeNodeMouseEvent {
2016-07-13 11:14:24 +08:00
node: TreeNode;
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-07-13 11:14:24 +08:00
autoExpandParent?: boolean;
/**checkable状态下节点选择完全受控父子节点选中状态不再关联*/
2016-07-13 11:14:24 +08:00
checkStrictly?: boolean;
/** 是否支持选中 */
checkable?: boolean;
/** 默认展开所有树节点 */
defaultExpandAll?: boolean;
/** 默认展开指定的树节点 */
defaultExpandedKeys?: Array<string>;
/** (受控)展开指定的树节点 */
expandedKeys?: Array<string>;
/** (受控)选中复选框的树节点 */
checkedKeys?: Array<string>;
/** 默认选中复选框的树节点 */
defaultCheckedKeys?: Array<string>;
/** (受控)设置选中的树节点 */
selectedKeys?: Array<string>;
/** 默认选中的树节点 */
defaultSelectedKeys?: Array<string>;
/** 展开/收起节点时触发 */
2016-07-13 17:22:23 +08:00
onExpand?: (expandedKeys: Array<string>, info: { node: TreeNode, expanded: boolean }) => void | PromiseLike<any>;
2016-07-13 11:14:24 +08:00
/** 点击复选框触发 */
onCheck?: (checkedKeys: Array<string>, e: TreeNodeEvent) => void;
/** 点击树节点触发 */
onSelect?: (selectedKeys: Array<string>, e: TreeNodeEvent) => void;
/** filter some treeNodes as you need. it should return true */
2016-07-13 11:14:24 +08:00
filterTreeNode?: (node: TreeNode) => boolean;
/** 异步加载数据 */
loadData?: (node: TreeNode) => PromiseLike<any>;
/** 响应右键点击 */
onRightClick?: (options: TreeNodeMouseEvent) => void;
/** 设置节点可拖拽IE>8*/
2016-07-13 11:14:24 +08:00
draggable?: boolean;
/** 开始拖拽时调用 */
2016-07-13 17:22:23 +08:00
onDragStart?: (options: TreeNodeMouseEvent) => void;
2016-07-13 11:14:24 +08:00
/** dragenter 触发时调用 */
2016-07-13 17:22:23 +08:00
onDragEnter?: (options: TreeNodeMouseEvent) => void;
/** dragover 触发时调用 */
2016-07-13 17:22:23 +08:00
onDragOver?: (options: TreeNodeMouseEvent) => void;
2016-07-13 11:14:24 +08:00
/** dragleave 触发时调用 */
2016-07-13 17:22:23 +08:00
onDragLeave?: (options: TreeNodeMouseEvent) => void;
2016-07-13 11:14:24 +08:00
/** drop 触发时调用 */
2016-07-13 17:22:23 +08:00
onDrop?: (options: TreeNodeMouseEvent) => void;
2016-07-13 11:14:24 +08:00
style?: React.CSSProperties;
prefixCls?: string;
}
export default class Tree extends React.Component<TreeProps, any> {
static TreeNode = RcTree.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
}
}