forked from elastic/eui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from cchaos/rk/side-nav-2/hovers
Simplify flyout children logic by adding `EuiNavDrawerGroup`
- Loading branch information
Showing
5 changed files
with
66 additions
and
92 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -235,6 +235,7 @@ export { | |
|
||
export { | ||
EuiNavDrawer, | ||
EuiNavDrawerGroup, | ||
EuiNavDrawerFlyout, | ||
} from './nav_drawer'; | ||
|
||
|
This file contains 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 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 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,48 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
|
||
import { EuiListGroup } from '../list_group/list_group'; | ||
|
||
export const EuiNavDrawerGroup = ({ className, listItems, flyoutMenuButtonClick, ...rest }) => { | ||
const classes = classNames( | ||
'euiNavDrawerGroup', | ||
className | ||
); | ||
|
||
// Create handlers if flyoutMenu exists | ||
const newListItems = listItems.map((item) => { | ||
// If the flyout menu exists, pass back the list of times and the title with the onClick handler of the item | ||
if (item.flyoutMenu && flyoutMenuButtonClick) { | ||
const items = [...item.flyoutMenu.listItems]; | ||
const title = `${item.flyoutMenu.title}`; | ||
item.onClick = () => flyoutMenuButtonClick(items, title); | ||
} | ||
|
||
// Then remove the flyoutMenu key | ||
delete item.flyoutMenu; | ||
|
||
// And return the item | ||
return item; | ||
}); | ||
|
||
|
||
return ( | ||
<EuiListGroup className={classes} listItems={newListItems} {...rest} /> | ||
); | ||
}; | ||
|
||
EuiNavDrawerGroup.propTypes = { | ||
listItems: PropTypes.arrayOf(PropTypes.shape({ | ||
...EuiListGroup.propTypes.listItems[0], | ||
flyoutMenu: PropTypes.shape({ | ||
title: PropTypes.string.isRequired, | ||
listItems: EuiListGroup.propTypes.listItems.isRequired, | ||
}), | ||
})).isRequired, | ||
/** | ||
* While not normally required, it is required to pass a function for handling | ||
* of the flyout menu button click | ||
*/ | ||
flyoutMenuButtonClick: PropTypes.func, | ||
}; |