Last active
November 29, 2019 04:34
-
-
Save nschairer/f3163a4eea8f27fc8e2f6d455fba70dc to your computer and use it in GitHub Desktop.
React Components
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
//Header component | |
const Header = props => { | |
return ( | |
<div style={style.containerStyle}> | |
<div style={style.navStyle}> | |
<a style={style.navItem}href='#'>About</a> | |
<a style={style.navItem}href='#'>Home</a> | |
</div> | |
<h3 style={style.textStyle}>Noah Schairer</h3> | |
</div> | |
) | |
} | |
//Header Style | |
const style = { | |
containerStyle: { | |
display: 'flex', | |
flexDirection: 'row', | |
justifyContent: 'space-between', | |
backgroundColor: '#fff', | |
boxShadow: '1px 1px 6px 6px #f8f8f8' | |
}, | |
textStyle: { | |
color: 'black', | |
padding: '18px', | |
}, | |
navStyle: { | |
display: 'flex', | |
flexDirection: 'row', | |
justifyContent: 'center', | |
alignItems: 'center', | |
paddingLeft: '8px' | |
}, | |
navItem: { | |
padding: '5px', | |
textDecoration: 'none', | |
color: '#000', | |
fontSize:'14px' | |
} | |
} | |
/////////Using react-router-dom | |
import React, { Component } from 'react' | |
import {Link} from 'react-router-dom' | |
class Navbar extends Component { | |
state = { | |
active: '/' | |
} | |
underline(path){ | |
return this.state.active===path?'2px solid black':'2px solid transparent' | |
} | |
render() { | |
const c = this.state.active | |
return ( | |
<div style={style.containerStyle}> | |
<div style={style.navStyle}> | |
<div style={{height: '100%', display: 'flex', justifyContent: 'center',alignItems: 'center',borderBottom: this.underline('/')}}> | |
<Link onClick={() => this.setState({active:'/'})} style={style.navItem} to='/'>Home</Link> | |
</div> | |
<div style={{height: '100%', display: 'flex', justifyContent: 'center',alignItems: 'center',borderBottom: this.underline('/About')}}> | |
<Link onClick={() => this.setState({active:'/About'})} style={style.navItem} to='/About'>About</Link> | |
</div> | |
</div> | |
<p style={style.textStyle}>Noah Schairer</p> | |
</div> | |
) | |
} | |
} | |
const style = { | |
containerStyle: { | |
display: 'flex', | |
flexDirection: 'row', | |
justifyContent: 'space-between', | |
backgroundColor: '#fff', | |
boxShadow: '1px 1px 6px 6px #f8f8f8' | |
}, | |
textStyle: { | |
color: 'black', | |
fontSize: '14px', | |
padding: '18px' | |
}, | |
navStyle: { | |
display: 'flex', | |
flexDirection: 'row', | |
justifyContent: 'center', | |
alignItems: 'center', | |
paddingLeft: '8px' | |
}, | |
navItem: { | |
padding: '5px', | |
textDecoration: 'none', | |
color: '#000', | |
fontSize:'14px', | |
display: 'block' | |
} | |
} | |
export default Navbar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment