Skip to content

Instantly share code, notes, and snippets.

View nnnnat's full-sized avatar
🥧
It's scientifantastic

Nat Hamilton nnnnat

🥧
It's scientifantastic
View GitHub Profile
@nnnnat
nnnnat / SkipNav.jsx
Created August 2, 2019 17:12
Simple React SkipNav
import React from "react";
import PropTypes from "prop-types";
function SkipNav ({ message, skipLinks }) {
return (
<nav>
{skipLinks.map(({ id, label }) => <a href={`#${id}`}>{message} {label}</a>)}
</nav>
);
};

Keybase proof

I hereby claim:

  • I am nnnnat on github.
  • I am nnnnat (https://keybase.io/nnnnat) on keybase.
  • I have a public key ASAwE2szOAOmgUzjutW76G_bW6anWPxsm340K4I5_Q7AYgo

To claim this, I am signing this object:

@nnnnat
nnnnat / ssr.test.js
Created August 17, 2018 20:51
simple ssr jest test
test("SSR Loads with an HTML Body", () => {
request(url, (err, resp, body) => {
if (!err && resp.statusCode === 200) {
const cheer = cheerio.load(body);
expect(cheer("#__next").find("div")).toBeGreaterThan(0);
}
});
});
@nnnnat
nnnnat / button.test.js
Created June 22, 2018 15:28
Simple component interaction test using enzyme & jest
import React from "react";
import { shallow } from "enzyme";
import Button from "./Button";
const testClick = jest.fn();
test("Button component onClick", () => {
const component = shallow(<Button handleClick={testClick}>Button</Button>);
component.find("button").simulate("click");
expect(testClick).toHaveBeenCalled();
@nnnnat
nnnnat / example.jsx
Last active June 21, 2018 20:19
Example of passing components as props
// ===========================================================================
// App.js
// ===========================================================================
import PropComp from "components/PropComp";
import Comp from "components/Comp";
class App extends Component {
render() {
return (
<Fragment>
@nnnnat
nnnnat / ScreenReaderText.jsx
Last active November 4, 2020 03:36
Screen reader only text Styled Component
const ScreenReaderText = styled.span`
border: 0;
clip: rect(1px, 1px, 1px, 1px);
clip-path: inset(50%);
height: 1px;
margin: -1px;
overflow: hidden;
position: absolute !important;
width: 1px;
word-wrap:normal !important;
@nnnnat
nnnnat / updateFilenameLabel.js
Created February 23, 2018 01:27
update file input label
function updateFilenameLabel (input) {
const filename = input.files[0].name
input.labels[0].attributes['data-filename'].value = input.files[0].name
}