Skip to content

Instantly share code, notes, and snippets.

View chaance's full-sized avatar
🏄‍♂️
Out there

Chance Strickland chaance

🏄‍♂️
Out there
View GitHub Profile
@chaance
chaance / machine.js
Created October 9, 2020 21:16
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
/**
* @typedef {Object} ClassifyProps
* @property {React.ElementType} [as] - Element to render
* @property {import('clsx').ClassValue} [className] - Composable classnames passed to clsx
*/
/**
* @param {ClassifyProps} props
*/
function Classify({ as: El = "div", ...props }) {
@chaance
chaance / Flex.tsx
Created September 4, 2020 17:15
Interop flex concept
import * as React from 'react';
import omit from 'lodash.omit';
import { cssReset, isUndefined } from '@interop-ui/utils';
import { forwardRef, createStyleObj } from '@interop-ui/react-utils';
/* -------------------------------------------------------------------------------------------------
* Flex
* -----------------------------------------------------------------------------------------------*/
const FLEX_NAME = 'Flex';
@chaance
chaance / alt.ts
Created August 25, 2020 01:07
alt-PurusAnte
/**
* Given a desired minimum contrast ratio, a base color, and an array of colors,
* return the first color in the array with an acceptable level of contrast
* against the base color.
* @param options
*/
function getFirstUsableColorBasedOnContrastRatio(options: {
ratio: number;
baseColor: Color;
colors: Color[];
fn slice_out_of_array() {
let a = [1, 2, 3, 4, 5];
let nice_slice = &a[1..4];
}
Listbox has turned out to be a real test for us in many ways. Primarily, it
challenges our desire for maximum composability, a key goal for all of the
Reach UI components. A listbox select component essentially consists of:
- A button the user clicks when a listbox is closed
- A list of options in a popover that is displayed after a user clicks
This sounds a lot like MenuButton from a UI perspective, but two key
differences:
@chaance
chaance / typography.css
Created May 13, 2020 19:15
Example of scaled relative font sizes
:root {
/* smallest screens */
--line-height: 1.2;
--font-size: 13px;
--rhythm: calc(var(--line-height) * var(--font-size));
}
/* larger phones */
@media screen and (min-width: 400px) {
html {
import React from 'react';
export type Breakpoints = {
[key: string]: number;
};
export type MediaQueries<BP extends Breakpoints, T> = {
[key in keyof BP]: T;
};
@chaance
chaance / emotion.d.ts
Last active May 5, 2020 15:59
Overriding the default theme types in Emotion 11
// this goes in you root types directory, filename is the [name-of-your-module].d.ts
import '@emotion/react';
import { MyCustomTheme } from './theme';
declare module '@emotion/react' {
export interface Theme extends MyCustomTheme {}
}
@chaance
chaance / useDebounce.ts
Last active April 9, 2020 19:51
Simple debounce hook for React
function useDebounce<F extends Function>(
func: F,
delay: number,
immediate?: boolean
) {
let debouncedFunc = useRef(func);
useEffect(() => {
let timeout: number | null;
debouncedFunc.current = (((...args: any[]) => {
let callNow = immediate && timeout == null;