diff --git a/rc-tree/index.d.ts b/rc-tree/index.d.ts new file mode 100644 index 0000000000..a2e1f161b7 --- /dev/null +++ b/rc-tree/index.d.ts @@ -0,0 +1,67 @@ +// Type definitions for rc-tree 1.4 +// Project: https://github.com/react-component/tree +// Definitions by: John Reilly +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +import { + Component, + Props +} from "react"; + +export interface TreeNodeProps extends Props { + className?: string; + disabled?: boolean; + disableCheckbox?: boolean; + title?: string | JSX.Element; + isLeaf?: boolean; +} + +export class TreeNode extends Component { } + +export interface ExpandData { + expanded: boolean; + node: TreeNode; +} + +export interface CheckData { + checked: boolean; + checkedNodes: TreeNode[]; + node: TreeNode; + event: Event; +} + +export interface SelectData { + selected: boolean; + selectedNodes: TreeNode[]; + node: TreeNode; + event: Event; +} + + +export interface TreeProps extends Props { + className?: string; + prefixCls?: string; + showLine?: boolean; + showIcon?: boolean; + selectable?: boolean; + multiple?: boolean; + checkable?: boolean | JSX.Element; + defaultExpandAll?: boolean; + defaultExpandedKeys?: string[]; + expandedKeys?: string[]; + autoExpandParent?: boolean; + defaultCheckedKeys?: string[]; + checkedKeys?: string[] | { checked: string[]; halfChecked: string[] }; + checkStrictly?: boolean; + defaultSelectedKeys?: string[]; + selectedKeys?: string[]; + onExpand?: (expandedKeys: string[], e: ExpandData) => void; + onCheck?: (checkedKeys: string[], e: CheckData) => void; + onSelect?: (selectedKeys: string[], e: SelectData) => void; + filterTreeNode?: (node: TreeNode) => boolean; + loadData?: (node: TreeNode) => Promise; + draggable?: boolean; +} + +export default class Tree extends Component { } diff --git a/rc-tree/rc-tree-tests.tsx b/rc-tree/rc-tree-tests.tsx new file mode 100644 index 0000000000..ce528ba168 --- /dev/null +++ b/rc-tree/rc-tree-tests.tsx @@ -0,0 +1,92 @@ +import * as React from 'react'; +import Tree, { TreeNode, SelectData, CheckData } from 'rc-tree'; + + +interface Props { + keys: string[]; +} + +interface State { + defaultExpandedKeys: string[]; + defaultSelectedKeys: string[]; + defaultCheckedKeys: string[]; + switchIt: boolean; +} + +export class Demo extends React.Component { + constructor(props: Props) { + super(props); + + const keys = this.props.keys; + this.state = { + defaultExpandedKeys: keys, + defaultSelectedKeys: keys, + defaultCheckedKeys: keys, + switchIt: true, + }; + } + + public static defaultProps: Props = { + keys: ['0-0-0-0'], + }; + + + getInitialState() { + } + + onExpand(expandedKeys: string[]) { + console.log('onExpand', expandedKeys, arguments); + } + + onSelect(selectedKeys: string[], info: SelectData) { + console.log('selected', selectedKeys, info); + } + + onCheck(checkedKeys: string[], info: CheckData) { + console.log('onCheck', checkedKeys, info); + } + + onEdit() { + setTimeout(() => { + console.log('current key: '); + }, 0); + } + + onDel(e: React.MouseEvent) { + if (!window.confirm('sure to delete?')) { + return; + } + e.stopPropagation(); + } + + render() { + const customLabel = ( + operations: + Edit  +   + this.onDel(e)}>Delete + ); + return (
+

simple

+ + + + + + + + + + + + +
); + } +} diff --git a/rc-tree/tsconfig.json b/rc-tree/tsconfig.json new file mode 100644 index 0000000000..3af3996eaf --- /dev/null +++ b/rc-tree/tsconfig.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "noUnusedParameters": true, + "noUnusedLocals": true, + "strictNullChecks": true, + "baseUrl": "../", + "jsx": "react", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "rc-tree-tests.tsx" + ] +} diff --git a/rc-tree/tslint.json b/rc-tree/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/rc-tree/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" }