diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-10-13 14:47:06 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-10-13 14:47:06 +0200 |
commit | 227b329e78a761ba3fc75c7b79048b0d387f9944 (patch) | |
tree | ac3eb57834c5b447d66c7d1e10d6e55f2046d33e /packages/gitbook-core/src | |
parent | da8c78b3c82bcf8c5e3dad2701fedb21fc10b0b4 (diff) | |
download | gitbook-227b329e78a761ba3fc75c7b79048b0d387f9944.zip gitbook-227b329e78a761ba3fc75c7b79048b0d387f9944.tar.gz gitbook-227b329e78a761ba3fc75c7b79048b0d387f9944.tar.bz2 |
Start style for dropdowns
Diffstat (limited to 'packages/gitbook-core/src')
-rw-r--r-- | packages/gitbook-core/src/components/Dropdown.js | 51 |
1 files changed, 14 insertions, 37 deletions
diff --git a/packages/gitbook-core/src/components/Dropdown.js b/packages/gitbook-core/src/components/Dropdown.js index 68fb619..78bad8d 100644 --- a/packages/gitbook-core/src/components/Dropdown.js +++ b/packages/gitbook-core/src/components/Dropdown.js @@ -11,13 +11,6 @@ const classNames = require('classnames'); * <Dropdown.Menu> * <Dropdown.Item href={...}> ... </Dropdown.Item> * <Dropdown.Item onClick={...}> ... </Dropdown.Item> - * - * <Dropdown.Item> A submenu - * <Dropdown.Menu> - * <Dropdown.Item href={...}> Subitem </Dropdown.Item> - * </Dropdown.Menu> - * </Dropdown.Item> - * * </Dropdown.Menu> * </Dropdown.Container> */ @@ -71,39 +64,27 @@ const DropdownItem = React.createClass({ }, render() { - const { - children, href, - ...otherProps - } = this.props; - delete otherProps.onCLick; + const { children, href, onClick, ...otherProps } = this.props; - const submenu = filterChildren(children, isDropdownMenu); - const inner = filterChildren(children, (child) => !isDropdownMenu(child)); + let inner = children; - return ( - <li className="GitBook-DropdownItem"> - <a href={href || '#'} onClick={this.onClick} {...otherProps} > + if (href || onClick) { + inner = ( + <a className="GitBook-DropdownItemLink" href={href || '#'} onClick={this.onClick} {...otherProps} > {inner} </a> - {submenu} - </li> + ); + } + + return ( + <div className="GitBook-DropdownItem"> + {inner} + </div> ); } }); /** - * @param {Node} children - * @param {Function} predicate - * @return {Node} children that pass the predicate - */ -function filterChildren(children, predicate) { - return React.Children.map( - children, - (child) => predicate(child) ? child : null - ); -} - -/** * A DropdownMenu to display DropdownItems. Must be inside a * DropdownContainer. */ @@ -118,17 +99,13 @@ const DropdownMenu = React.createClass({ className = classNames('GitBook-DropdownMenu', className); return ( - <ul className={className}> + <div className={className}> {children} - </ul> + </div> ); } }); -function isDropdownMenu(child) { - return (child && child.type && child.type.displayName === 'DropdownMenu'); -} - const Dropdown = { Item: DropdownItem, Menu: DropdownMenu, |