-
Notifications
You must be signed in to change notification settings - Fork 3
Web/navbar hide #41
Web/navbar hide #41
Changes from 12 commits
22303c8
58d4ba5
7db28cc
3c1fd03
91164a8
e6e6a3b
b11641b
4765501
f141789
e542304
6e61284
a0112fe
f66d3b0
898adda
0e4f69d
34b6748
2283f6b
ce1ab1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import React from 'react'; | ||
|
||
const Main = () => (<div>HOME PAGE</div>); | ||
const Main = () => (<div className="pad-nav">HOME PAGE</div>); | ||
|
||
export default Main; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
div#demo | ||
width: 50% | ||
margin-left: 25% | ||
height: 90000000px |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,21 @@ | ||
nav | ||
display: flex | ||
z-index: 500 | ||
background: $white | ||
box-shadow: 0px 4px 6px $shadow | ||
height: 64px | ||
position: fixed | ||
width: 100% | ||
transition: background $transition-time-long, shadow $transition-time-long, opacity $transition-time | ||
|
||
> div | ||
display: inline-flex | ||
> div:last-of-type | ||
width: 80% | ||
justify-content: flex-end | ||
> div:first-of-type | ||
width: 20% | ||
justify-content: flex-start | ||
> div > div | ||
display: flex | ||
margin-top: 12px | ||
margin-bottom: 12px | ||
align-items: center | ||
margin-right: 7.5% | ||
> div > div:first-of-type | ||
margin-left: 24px | ||
> div > div:last-of-type | ||
margin-right: 24px | ||
a | ||
display: flex | ||
align-items: center | ||
text-decoration: none | ||
font-family: Apercu Pro | ||
font-size: 18px | ||
color: $primary | ||
a:visited | ||
color: $primary | ||
|
||
a:hover | ||
color: #00D5D5 | ||
img | ||
margin-top: 3px | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spaces should always be multiples of 4 - can you change this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a hack because the logo looked slightly off :( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 4px looks fine too though - I'll make this change |
||
width: 32px | ||
|
||
.below-nav | ||
padding-top: 64px | ||
&.transparent | ||
background: transparent | ||
|
||
&.hide | ||
opacity: 0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,11 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Link } from 'react-router-dom'; | ||
import { DISPLAY_TYPE } from '../../containers/navbar/DisplayTypes'; | ||
import { BUTTON_TYPE } from '../../containers/navbar/ButtonTypes'; | ||
import { SecondaryButton } from '../input/buttons'; | ||
|
||
import logo from '../../assets/logo.png'; | ||
|
||
const getLogo = () => ( | ||
<Link to="/"><img alt="" src={logo} /></Link> | ||
); | ||
import logo from '../../assets/logo.svg'; | ||
|
||
const getButton = (buttonType) => { | ||
switch (buttonType) { | ||
|
@@ -23,43 +20,95 @@ const getButton = (buttonType) => { | |
} | ||
}; | ||
|
||
const Navbar = ({ displayType, buttonType }) => { | ||
switch (displayType) { | ||
case DISPLAY_TYPE.ONLY_LOGO: | ||
return ( | ||
<nav> | ||
<div> | ||
<div>{getLogo()}</div> | ||
</div> | ||
</nav> | ||
); | ||
case DISPLAY_TYPE.LOGO_AND_BUTTON: | ||
return ( | ||
<nav> | ||
<div> | ||
<div>{getLogo()}</div> | ||
</div> | ||
<div> | ||
<div>{getButton(buttonType)}</div> | ||
</div> | ||
</nav> | ||
); | ||
default: | ||
return ( | ||
<nav> | ||
<div> | ||
<div>{getLogo()}</div> | ||
class Navbar extends React.Component { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe you need to add a Right now the component is not updating based on incoming props. Reproduction steps:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't repro anymore after f66d3b0 - let me know if it works when you get the chance! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I can't reproduce it anymore. But wouldn't it be better to have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I’ll have a closer look at this tonight There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mingyokim sorry, I'm not sure I understand - doesn't a prop change force the container to re-render? From what I understand, https://github.com/nwhacks/nwhacks2019/blob/master/web/containers/navbar/index.js#L57 It also seems like setting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Officially, react only distinguishes between class and function (potentially stateful and stateless respectively), and:
https://reactjs.org/docs/components-and-props.html#functional-and-class-components There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so props do cause a render on stateful components? oops i was mistaken, it's all good then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar question: https://www.reddit.com/r/reactjs/comments/7tn79g/state_and_componentwillreceiveprops/ class Foo extends Component {
state = { value: this.props.value }
// If the props change, update state
componentWillReceiveProps (nextProps) {
if (nextProps.value !== this.props.value) {
this.setState({ value: nextProps.value })
}
}
render () {
// render based on state.value
}
} Top response:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
https://reactjs.org/docs/react-component.html Okay, so clearly change in props cause a re-render, If this is the case, definitely use props rather than state because the component is not modifying the Approving There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll just do one last sanity check |
||
constructor(props) { | ||
super(props); | ||
const { displayType, buttonType } = props; | ||
this.state = { | ||
displayType, | ||
buttonType, | ||
hidden: false, | ||
transparent: true, | ||
lastY: 0, | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
window.addEventListener('scroll', this.handleScroll, { passive: true }); | ||
} | ||
|
||
componentWillUnmount() { | ||
window.removeEventListener('scroll', this.handleScroll); | ||
} | ||
|
||
handleScroll = () => { | ||
// Calculate scroll direction | ||
const { lastY } = this.state; | ||
const scrollingDown = (window.scrollY - lastY) >= 0; | ||
|
||
// Calculate position | ||
const offset = window.pageYOffset || document.documentElement.scrollTop; | ||
const atTop = offset < 96; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we store There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure - 96 is in the CSS as navbar height, but I’ll replicate it here |
||
|
||
// Calculate transparency | ||
const transparent = scrollingDown ? offset < 256 : atTop; | ||
|
||
// Update state | ||
this.setState({ | ||
transparent, | ||
hidden: (!atTop && scrollingDown), | ||
lastY: window.scrollY, | ||
}); | ||
} | ||
|
||
render() { | ||
const { displayType, buttonType, hidden, transparent } = this.state; | ||
const button = getButton(buttonType); | ||
const links = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cleaann but can we name this something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True! |
||
<Link to="/"><b>About</b></Link>, | ||
<Link to="/"><b>Stories</b></Link>, | ||
<Link to="/"><b>FAQ</b></Link>, | ||
<Link to="/"><b>Sponsors</b></Link>, | ||
<Link to="/"><b>2018</b></Link>, | ||
button, | ||
]; | ||
|
||
let linksDiv; | ||
let key = 0; | ||
switch (displayType) { | ||
case DISPLAY_TYPE.ONLY_LOGO: | ||
break; | ||
case DISPLAY_TYPE.LOGO_AND_BUTTON: | ||
linksDiv = <div className="flex ai-center">{button}</div>; | ||
break; | ||
default: | ||
linksDiv = links.map(l => ( | ||
<div | ||
key={key += 1} | ||
className="flex ai-center margin-sides-large"> | ||
{l} | ||
</div> | ||
<div> | ||
<div><Link to="/">About</Link></div> | ||
<div><Link to="/">FAQ</Link></div> | ||
<div><Link to="/">Sponsors</Link></div> | ||
<div><Link to="/">2018</Link></div> | ||
<div>{getButton(buttonType)}</div> | ||
)); | ||
} | ||
|
||
return ( | ||
<nav className={`fill-width flex ${hidden ? 'hide' : ''} ${transparent ? 'transparent' : 'shadow'}`}> | ||
<div className="flex ai-center jc-start margin-sides"> | ||
<div className="flex ai-center"> | ||
<Link to="/"><img alt="nwHacks" src={logo} /></Link> | ||
</div> | ||
</nav> | ||
); | ||
</div> | ||
<div className="flex jc-end margin-horizontal-divs fill-width"> | ||
{linksDiv} | ||
</div> | ||
</nav> | ||
); | ||
} | ||
} | ||
|
||
Navbar.propTypes = { | ||
displayType: PropTypes.symbol, | ||
buttonType: PropTypes.symbol, | ||
}; | ||
|
||
export default Navbar; |
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.
curious, why is this needed?
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.
This keeps the navbar above all other elements, so long as we avoid using z-index elsewhere