Skip to content

Add customItemsRenderer prop #152

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

Merged
merged 4 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Both options support component customization. - [examples](https://github.com/ke
| `itemsRenderer` | `Component` | `items.js` | `Component to replace the default Items component. ` |
| `forwardIconRenderer` | `Component` | | `Component to replace the default ForwardIcon component. ` |
| `treeContainerRenderer`| `Component` | `tree_container.js` | `Component to replace the default TreeContainer component. ` |
| `customItemsRenderer ` | `Component` | | `Component to replace the default Items && inner Item component.`|
| `markSelectedItem` | `boolean` | `false` | `Toggle to mark selected item. ` |

<br/>
Expand Down
39 changes: 25 additions & 14 deletions packages/core/src/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const Tree = props => {
itemsRenderer: Items = ItemsRenderer,
forwardIconRenderer,
treeContainerRenderer: TreeContainer = TreeContainerRenderer,
customItemsRenderer,
selectedItem
} = props;

Expand Down Expand Up @@ -94,20 +95,30 @@ const Tree = props => {
inputIconRenderer={inputIconRenderer}
clearIconRenderer={clearIconRenderer}
/>
<Items styles={styles} getStyles={getStyles} height={itemsHeight}>
{leaves &&
leaves.length > 0 &&
leaves.map(item => (
<Item
getStyles={getStyles}
searchTerm={searchTerm}
item={item}
onClick={onClick}
forwardIconRenderer={forwardIconRenderer}
selectedItem={selectedItem}
/>
))}
</Items>
{customItemsRenderer ? (
React.cloneElement(customItemsRenderer, {
leaves,
searchTerm,
onClick,
selectedItem,
forwardIconRenderer
})
) : (
<Items styles={styles} getStyles={getStyles} height={itemsHeight}>
{leaves &&
leaves.length > 0 &&
leaves.map(item => (
<Item
getStyles={getStyles}
searchTerm={searchTerm}
item={item}
onClick={onClick}
forwardIconRenderer={forwardIconRenderer}
selectedItem={selectedItem}
Comment on lines +116 to +117
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't want to pass these two?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as I see selected Item we pass externally

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ForwardIconRenderer the same

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's important we maintain the same API.
IT would be very confusing if the icons work in one instance but if you pass a custom list they don't.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a ping on this so that we can merge

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

/>
))}
</Items>
)}
{leaves && leaves.length === 0 && (
<NoResults
height={itemsHeight}
Expand Down