Skip to content

Instantly share code, notes, and snippets.

View segunadebayo's full-sized avatar
😃

Segun Adebayo segunadebayo

😃
View GitHub Profile
@segunadebayo
segunadebayo / NextActiveLink.js
Last active August 18, 2019 22:01
Style active link in NextJS
@segunadebayo
segunadebayo / NextGA.js
Created August 23, 2019 13:03
Add Google Analytics to NextJS
import NextHead from 'next/head'
import React from 'react'
import ReactGA from 'react-ga'
import Router from 'next/router'
// GA Tracking Id
const gaTrackingId = '[GOOGLE ANALYTICS TRACKING ID GOES HERE]'
Router.onRouteChangeComplete = () => {
@segunadebayo
segunadebayo / Button.jsx
Created September 11, 2019 21:15 — forked from diegohaz/Button.jsx
React Component Hooks API (from Reakit)
import React from "react";
import { useButton, mergeProps } from "reakit";
function Button(props) {
// useButton should be used when the props are being applied to a non-button element
const button = useButton();
return <div {...mergeProps(button, props)} />;
}
// return value of useButton
@segunadebayo
segunadebayo / records-and-dict.ts
Last active October 10, 2019 20:16 — forked from OliverJAsh/foo.ts
Records and dictionaries in TypeScript
/*
In JavaScript, objects can be used to serve various purposes.
To maximise our usage of the type system, we should assign different types to our objects depending
on the desired purpose.
In this blog post I will clarify two common purposes for objects known as records and dictionaries
(aka maps), and how they can both be used with regards to the type system.

Reach UI Philosophy

Reach UI is an accessible foundation for React applications and design systems.

The three equally important goals are to be:

  • Accessible
  • Composable
  • Stylable
@segunadebayo
segunadebayo / machine.js
Created October 31, 2019 14:26
Generated by XState Viz: https://xstate.js.org/viz
const machine = Machine({
id: "menu-button",
initial: "unmounted",
context: {
button: null,
menu: null,
items: [],
search: "",
highlightIndex: -1
},
@segunadebayo
segunadebayo / machine.js
Last active November 19, 2019 22:41
Generated by XState Viz: https://xstate.js.org/viz
const menuButtonMachine = new Machine(
{
id: "menu-button",
initial: "idle",
context: {
activeIndex: -1,
items: [1, 2, 3],
focused: ""
},
states: {
@segunadebayo
segunadebayo / modal-route.jsx
Created December 12, 2019 12:11
Router Tabs and Modal Routes
import React, { Component } from "react";
import { Switch, Route, Link } from "react-router-dom";
import "./app.css";
const Home = () => <div>You're on the Home Tab</div>;
const Photo = ({ location }) => {
const { state = {} } = location;
const { modal } = state;
return (
<div className={modal ? "modal" : undefined}>
@segunadebayo
segunadebayo / color-mode.tsx
Created December 31, 2019 13:50
Color Mode
import * as React from "react";
const storageKey = "chakra-ui-color-mode";
const cx = (mode: ColorMode) => `chakra-ui-${mode}`;
const supportsLocalStorage = typeof Storage !== "undefined";
const getBodyElement = () => {
// for SSR
const mockBody = {
classList: {
@segunadebayo
segunadebayo / colors.md
Created April 20, 2020 10:10 — forked from 0x263b/colors.md
Random color from string in javascript

Random color from string in javascript

Consider a list of strings you need to permanently assign a random color.

First you should turn the string into a hash.

var string = "string"
var hash = 0