ant-design/components/tree/index.tsx
Zhiqiang Gong 722b24b813 add disabled prop (#11188)
First of all, thank you for your contribution! :-)

Please makes sure that these checkboxes are checked before submitting your PR, thank you!

* [x] Make sure that you propose PR to right branch: bugfix for `master`, feature for latest active branch `feature-x.x`.
* [x] Make sure that you follow antd's [code convention](https://github.com/ant-design/ant-design/wiki/Code-convention-for-antd).
* [x] Run `npm run lint` and fix those errors before submitting in order to keep consistent code style.
* [x] Rebase before creating a PR to keep commit history clear.
* [x] Add some descriptions and refer relative issues for you PR.

Extra checklist:

**if** *isBugFix* **:**

  * [x] Make sure that you add at least one unit test for the bug which you had fixed.

**elif** *isNewFeature* **:**

  * [ ] Update API docs for the component.
  * [ ] Update/Add demo to demonstrate new feature.
  * [ ] Update TypeScript definition for the component.
  * [ ] Add unit tests for the feature.

tslint检测时报错
类型“IntrinsicAttributes & IntrinsicClassAttributes<Tree> & Readonly<{ children?: ReactNode; }> & Read...”上不存在属性“disabled”。
2018-07-11 19:39:41 +08:00

137 lines
4.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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