From 9b8441c86795d3faac0611683e459936c6a2897d Mon Sep 17 00:00:00 2001 From: John Reilly Date: Wed, 8 Feb 2017 14:09:58 +0000 Subject: [PATCH 1/4] rc-tree type definition --- rc-tree/index.d.ts | 67 ++++++++++++++++++++++++++++ rc-tree/rc-tree-tests.tsx | 92 +++++++++++++++++++++++++++++++++++++++ rc-tree/tsconfig.json | 26 +++++++++++ 3 files changed, 185 insertions(+) create mode 100644 rc-tree/index.d.ts create mode 100644 rc-tree/rc-tree-tests.tsx create mode 100644 rc-tree/tsconfig.json diff --git a/rc-tree/index.d.ts b/rc-tree/index.d.ts new file mode 100644 index 0000000000..716bead23f --- /dev/null +++ b/rc-tree/index.d.ts @@ -0,0 +1,67 @@ +// Type definitions for rc-tree v1.4.3 +// 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..4e24118cf2 --- /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": false, + "baseUrl": "../", + "jsx": "react", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "rc-tree-tests.tsx" + ] +} From 9b4297d4d2cf99c62efd1909f340f360c480dd80 Mon Sep 17 00:00:00 2001 From: John Reilly Date: Wed, 8 Feb 2017 14:16:58 +0000 Subject: [PATCH 2/4] Added tslint and null checks --- rc-tree/tsconfig.json | 2 +- rc-tree/tslint.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 rc-tree/tslint.json diff --git a/rc-tree/tsconfig.json b/rc-tree/tsconfig.json index 4e24118cf2..3af3996eaf 100644 --- a/rc-tree/tsconfig.json +++ b/rc-tree/tsconfig.json @@ -9,7 +9,7 @@ "noImplicitThis": true, "noUnusedParameters": true, "noUnusedLocals": true, - "strictNullChecks": false, + "strictNullChecks": true, "baseUrl": "../", "jsx": "react", "typeRoots": [ 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" } From c3db667fc6d363f0e5d62b7624d7c3d678d75063 Mon Sep 17 00:00:00 2001 From: John Reilly Date: Wed, 8 Feb 2017 14:26:50 +0000 Subject: [PATCH 3/4] removed reference to patch version --- rc-tree/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc-tree/index.d.ts b/rc-tree/index.d.ts index 716bead23f..9f71703726 100644 --- a/rc-tree/index.d.ts +++ b/rc-tree/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for rc-tree v1.4.3 +// Type definitions for rc-tree v1.4 // Project: https://github.com/react-component/tree // Definitions by: John Reilly // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped From da32d6efa15dbe5a25fe66669bffa90a86e923d7 Mon Sep 17 00:00:00 2001 From: John Reilly Date: Wed, 8 Feb 2017 14:35:26 +0000 Subject: [PATCH 4/4] apparently v isn't allowed- who knew? --- rc-tree/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc-tree/index.d.ts b/rc-tree/index.d.ts index 9f71703726..a2e1f161b7 100644 --- a/rc-tree/index.d.ts +++ b/rc-tree/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for rc-tree v1.4 +// Type definitions for rc-tree 1.4 // Project: https://github.com/react-component/tree // Definitions by: John Reilly // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped