Skip to content

Instantly share code, notes, and snippets.

View souporserious's full-sized avatar

Travis Arnold souporserious

View GitHub Profile
import React, { Component } from 'react'
import { Manager, Target, Popper, Arrow } from 'react-popper'
import Portal from 'react-travel'
import outy from 'outy'
import matchSorter, { rankings } from 'match-sorter'
import Autocomplete from '../Autocomplete'
import Badge from '../Badge'
import Button from '../Button'
import Card from '../Card'
class HighlightItems extends Component {
render() {
const { items } = this.props
return (
<ItemGroup items={items}>
{({
selectItem,
selectNextItem,
selectPreviousItem,
deselectItem,
@souporserious
souporserious / Controller.jsx
Last active September 9, 2017 19:43
Allows a list of items to be selected for things like highlighting or maintaining a list of selected item[s]
import React, { Component } from 'react'
const ITEM_SELECTED = 'ITEM_SELECTED'
const ITEM_DESELECTED = 'ITEM_DESELECTED'
class Controller extends Component {
static contextTypes = {
itemLists: PropTypes.object,
}
@souporserious
souporserious / icons.js
Created September 10, 2017 02:11
Converts a Sketch file's artboards to a folder of SVGs and outputs an array of path data
const { readdirSync, readFileSync, writeFileSync } = require('fs')
const { resolve } = require('path')
const del = require('del')
const svgson = require('svgson')
const SketchTool = require('sketch-tool')
const IN_PATH = resolve(__dirname, 'icons.sketch')
const OUT_PATH = resolve(__dirname, '../packages/icons.js')
const Sketch = new SketchTool({
@souporserious
souporserious / ItemGroup.jsx
Created September 19, 2017 16:48
Loops through children to provide selected states
function firstDefined(...args) {
return args.filter(a => typeof a !== 'undefined')[0]
}
function shallowEqual(a, b) {
return JSON.stringify(a) === JSON.stringify(b)
}
class Item extends PureComponent {
static displayName = 'ItemList.Item'
import React, { Component, PureComponent, Children, cloneElement } from 'react'
import ReactDOM from 'react-dom'
const canvas = document.createElement('canvas')
const context = canvas.getContext('2d')
const fontWeight = 400
const fontSize = '16px'
const fontFamily = 'Lato'
const lineHeight = '20px'
context.font = `${fontWeight} ${fontSize} ${fontFamily}`
function getClosestScrollParent(node) {
const rootNode = typeof document === 'undefined' ? null : document.body
if (node !== null && node !== rootNode) {
if (node.scrollHeight > node.clientHeight) {
return node
} else {
return getClosestScrollParent(node.parentNode)
}
} else {
return null
import { Decay, Spring } from './wobble'
import PanResponder from 'universal-panresponder'
const decay = new Decay({ velocity: 0.8 })
decay.start({
fromValue: 12,
onUpdate: value => console.log(value),
})
// react-loco
function pad(num, size) {
let s = num + ''
while (s.length < size) s = '0' + s
return s
}
class NumberField extends Component {
// modified from: https://stackoverflow.com/questions/995183/how-to-allow-only-numeric-0-9-in-html-inputbox-using-jquery
handleKeyDown = e => {
if (
// @flow
import { parseColor } from './utils'
type Props = {
fill: string,
fillOpacity: number,
strokeAlign: 'center' | 'inside' | 'outside',
strokeOpacity: number,
strokeWeight: number,
stroke: string,