Skip to content

Instantly share code, notes, and snippets.

.header {
display: flex;
justify-content: center;
}
.headerlink-title {
color: black;
text-decoration: none;
padding: 0 5px;
}
<Link to={`/${link}`} className='headerlink-title'>
{title}
</Link>
const Header = () => {
return (
<div className='header'>
<HeaderLink page='home' />
<HeaderLink page='about' />
<HeaderLink page='contact' />
</div>
);
};
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>;
};
@karenying
karenying / App.js
Last active November 22, 2020 01:20
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} />
@karenying
karenying / App.js
Last active November 22, 2020 01:28
const Home = () => (
<div>
<h2>Home</h2>
</div>
);
const About = () => (
<div>
<h2>About</h2>
</div>
return (
<div
className='colorbox-container'
style={{ backgroundColor: `#${backgroundHex}`, color: `#${textColor}` }}
>
{`#${backgroundHex}`}
<br />
{`Contrast ratio: ${backgroundColor
.contrastRatioWith(textColor)
.toFixed(2)}`}
const backgroundColor = new Color(backgroundHex);
const { textColor } = backgroundColor;
// 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);
}
// 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);
}