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 { | |
display: flex; | |
justify-content: center; | |
} | |
.headerlink-title { | |
color: black; | |
text-decoration: none; | |
padding: 0 5px; | |
} |
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
<Link to={`/${link}`} className='headerlink-title'> | |
{title} | |
</Link> |
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
const Header = () => { | |
return ( | |
<div className='header'> | |
<HeaderLink page='home' /> | |
<HeaderLink page='about' /> | |
<HeaderLink page='contact' /> | |
</div> | |
); | |
}; |
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
import { Link } from 'react-router-dom'; | |
import './Header.css'; | |
const HeaderLink = ({ page }) => { | |
const title = page.charAt(0).toUpperCase() + page.slice(1); | |
return <Link to={`/${page}`}>{title}</Link>; | |
}; |
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
import { BrowserRouter as Router, Route } from 'react-router-dom'; | |
function App() { | |
return ( | |
<div className='App'> | |
<Router> | |
<Route exact path='/' component={Home} /> | |
<Route exact path='/home' component={Home} /> | |
<Route exact path='/about' component={About} /> | |
<Route exact path='/contact' component={Contact} /> |
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
const Home = () => ( | |
<div> | |
<h2>Home</h2> | |
</div> | |
); | |
const About = () => ( | |
<div> | |
<h2>About</h2> | |
</div> |
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
return ( | |
<div | |
className='colorbox-container' | |
style={{ backgroundColor: `#${backgroundHex}`, color: `#${textColor}` }} | |
> | |
{`#${backgroundHex}`} | |
<br /> | |
{`Contrast ratio: ${backgroundColor | |
.contrastRatioWith(textColor) | |
.toFixed(2)}`} |
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
const backgroundColor = new Color(backgroundHex); | |
const { textColor } = backgroundColor; |
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
// returns luminance as a number between 0 and 1 | |
get luminance() { | |
return getLuminance(this.hex); | |
} | |
/* returns contrast ratio with a second color, | |
calls contrastRatioPair */ | |
contrastRatioWith(hex2) { | |
return contrastRatioPair(this.hex, hex2); | |
} |
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
// calculates contrast ratio between two hex strings | |
export function contrastRatioPair(hex1, hex2) { | |
const lum1 = getLuminance(hex1); | |
const lum2 = getLuminance(hex2); | |
return (Math.max(lum1, lum2) + 0.05) / (Math.min(lum1, lum2) + 0.05); | |
} |