-
Notifications
You must be signed in to change notification settings - Fork 86
Rewrite in Typescript: Tree #315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c2ee29c
#289 Tree: mv .js -> .tsx
zaki-yama a453987
#289 Tree: Convert PropTypes to TypeScript types
zaki-yama e6acf2e
#289 Tree: mv story .js -> .tsx
zaki-yama 084342a
#289 Tree: Fix type error of knobs
zaki-yama 6e14a0d
#289 Tree: Fix React's runtime warnings
zaki-yama 5acad3b
#289 Tree: Update storyshots
zaki-yama 3771565
#289 Tree: Quit default export
zaki-yama 65e5137
#289 Tree: tweak
zaki-yama File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import React, { | ||
| Component, | ||
| Children, | ||
| cloneElement, | ||
| HTMLAttributes, | ||
| } from 'react'; | ||
| import classnames from 'classnames'; | ||
|
|
||
| export type TreeProps = { | ||
| className?: string; | ||
| label?: string; | ||
| toggleOnNodeClick?: boolean; | ||
| onNodeClick?: (...args: any[]) => any; | ||
| onNodeToggle?: (...args: any[]) => any; | ||
| onNodeLabelClick?: (...args: any[]) => any; | ||
| }; | ||
|
|
||
| export class Tree extends Component< | ||
| TreeProps & HTMLAttributes<HTMLDivElement>, | ||
| {} | ||
| > { | ||
| constructor( | ||
| props: Readonly<TreeProps & React.HTMLAttributes<HTMLDivElement>> | ||
| ) { | ||
| super(props); | ||
| this.renderTreeNode = this.renderTreeNode.bind(this); | ||
| } | ||
|
|
||
| renderTreeNode(tnode: any) { | ||
| const { | ||
| onNodeClick, | ||
| onNodeToggle, | ||
| onNodeLabelClick, | ||
| toggleOnNodeClick, | ||
| } = this.props; | ||
| return cloneElement(tnode, { | ||
| level: 1, | ||
| onNodeClick, | ||
| onNodeToggle, | ||
| onNodeLabelClick, | ||
| toggleOnNodeClick, | ||
| }); | ||
| } | ||
|
|
||
| render() { | ||
| const { | ||
| className, | ||
| label, | ||
| children, | ||
| /* eslint-disable @typescript-eslint/no-unused-vars */ | ||
| onNodeClick, | ||
| onNodeToggle, | ||
| onNodeLabelClick, | ||
| toggleOnNodeClick, | ||
| /* eslint-enable @typescript-eslint/no-unused-vars */ | ||
| ...props | ||
| } = this.props; | ||
| const treeClassNames = classnames(className, 'slds-tree-container'); | ||
| return ( | ||
| <div className={treeClassNames} role='application' {...props}> | ||
| {label ? <h4 className='slds-text-heading--label'>{label}</h4> : null} | ||
| <ul className='slds-tree' role='tree'> | ||
| {Children.map(children, this.renderTreeNode)} | ||
| </ul> | ||
| </div> | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/mashmatrix/react-lightning-design-system/pull/315/files#diff-b8e1116dcaaf4336c2da8bf811daa6c1L32
Before converting to TypeScript, propTypes were used in
cleanProps()to avoid passing unnecessary props (likeonNodeClick) to<div>element.I couldn't replace it with TypeScript's types, so this is a workaround.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I don't do this, the following runtime warnings occur: