From be0df2d563ad038233c6aca705a2c56d282338f5 Mon Sep 17 00:00:00 2001 From: Floyd Chen Date: Mon, 23 Jul 2018 11:14:16 -0500 Subject: [PATCH 1/6] added comments to nav --- src/Nav/Nav.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Nav/Nav.js b/src/Nav/Nav.js index af29de9f..56002680 100644 --- a/src/Nav/Nav.js +++ b/src/Nav/Nav.js @@ -14,8 +14,10 @@ export class Nav extends React.Component { }; } + // floyd: i don't think we need this function if we handle onClick properly UNSAFE_componentWillReceiveProps(nextProps) { if (nextProps.activeIndex !== this.props.activeIndex) { + console.log("check check"); this.setState({ "activeIndex": nextProps.activeIndex }); } } @@ -46,6 +48,7 @@ export class Nav extends React.Component { ignoreActive={ignoreActive} > {data.map(nav => { + console.log("nav", nav); const { title, collapsed, ...others } = nav; if (!nav.subNav) { return ( From 8624dd9b420bdcfad2afee61d3d5d20c89f614c1 Mon Sep 17 00:00:00 2001 From: Floyd Chen Date: Thu, 26 Jul 2018 08:46:18 -0500 Subject: [PATCH 2/6] not finished. stuck on the hamburger of horizontal navs --- src/Nav/Nav.css | 5 + src/Nav/Nav.js | 314 ++++++++++++++++++++++++++++++++++------ src/Nav/README.md | 28 +++- src/NavItem/NavItem.css | 13 +- src/NavItem/NavItem.js | 68 ++++++++- src/styles/layout.css | 2 +- 6 files changed, 373 insertions(+), 57 deletions(-) diff --git a/src/Nav/Nav.css b/src/Nav/Nav.css index cfc6bdec..3aed5e2b 100644 --- a/src/Nav/Nav.css +++ b/src/Nav/Nav.css @@ -6,6 +6,11 @@ height: auto; } +.horizontal { + display: flex; + flex-direction: row; +} + .nav a { text-decoration: none; } \ No newline at end of file diff --git a/src/Nav/Nav.js b/src/Nav/Nav.js index 56002680..1d8ae473 100644 --- a/src/Nav/Nav.js +++ b/src/Nav/Nav.js @@ -8,20 +8,44 @@ import { NavItem } from "../NavItem"; export class Nav extends React.Component { constructor(props) { super(props); + this.NavRef = React.createRef(); this.state = { "activeIndex": props.activeIndex, // The index of selected menu item. - "collapsed": props.collapsed // Whether or not sub-nav menu collapsed. + "collapsed": props.collapsed, // Whether or not sub-nav menu collapsed. + "width": window.innerWidth // the width of the Nav, + // "visibleNavItems": }; } + componentDidMount() { + if (this.props.horizontal && typeof this.props.subNav === "undefined") { + // console.log('width', this.NavRef.current.offsetWidth); + // console.log('left', this.NavRef.current.offsetLeft); + console.log( + "right", + this.NavRef.current.offsetLeft + this.NavRef.current.offsetWidth + ); + console.log("window.innerWidth", window.innerWidth); + // const lastChildWidth = this.NavRef.current.children[this.NavRef.current.children.length - 1].offsetWidth; + // const lastChildLeft = this.NavRef.current.children[this.NavRef.current.children.length - 1].offsetLeft; + // console.log('last child\'s offset right', lastChildLeft + lastChildWidth); + } + + window.addEventListener("resize", this.updateDimensions); + } + // floyd: i don't think we need this function if we handle onClick properly UNSAFE_componentWillReceiveProps(nextProps) { if (nextProps.activeIndex !== this.props.activeIndex) { - console.log("check check"); + // console.log("check check"); this.setState({ "activeIndex": nextProps.activeIndex }); } } + componentWillUnmount() { + window.removeEventListener("resize", this.updateDimensions); + } + _handleClick = (index, event) => { this.setState({ "activeIndex": index }); if (this.props.onClick) { @@ -36,11 +60,44 @@ export class Nav extends React.Component { } }; - _buildNavByData = () => { - const { className, data, ignoreActive, onClick, style } = this.props; + updateNav = () => { + console.log("nav should shrink now!"); + }; + + updateDimensions = () => { + this.setState({ + "width": window.innerWidth + }); + if (this.NavRef.current !== null) { + const lastChildWidth = this.NavRef.current.children[ + this.NavRef.current.children.length - 1 + ].offsetWidth; + const lastChildLeft = this.NavRef.current.children[ + this.NavRef.current.children.length - 1 + ].offsetLeft; + const lastChildRight = lastChildWidth + lastChildLeft; + if (window.innerWidth < lastChildRight) { + this.updateNav(); + } + } + }; + + _buildNavByData = data => { + const { + className, + ignoreActive, + onClick, + style, + subNav, + horizontal + } = this.props; return (