Skip to content

Instantly share code, notes, and snippets.

View souporserious's full-sized avatar

Travis Arnold souporserious

View GitHub Profile
@souporserious
souporserious / sketch-to-svg-json.js
Created May 28, 2017 21:24
Sketch to svg json loader
const { readdir, readFile } = require('fs')
const { resolve } = require('path')
const { getOptions } = require('loader-utils')
const SketchTool = require('sketch-tool')
const svgson = require('svgson')
const del = require('del')
module.exports = function(content) {
this.cacheable && this.cacheable(true)
@souporserious
souporserious / Spacer.jsx
Created June 13, 2017 02:12
React space component for padding and margin
import React from 'react'
const BASE = 8
const SIDES = ['Top', 'Right', 'Bottom', 'Left']
const SIDES_LOWERCASE = ['top', 'right', 'bottom', 'left']
function isNullLike(value) {
return value === null || typeof value === 'undefined'
}
@souporserious
souporserious / Text.jsx
Last active June 16, 2017 07:18
React Text component for all of your text styling needs
import React from 'react'
import createStyledElement from 'create-styled-element'
import { parseToRgb } from 'polished'
import { createTone } from 'tonality'
import directionalStyles from './directional-styles'
// get "directionalStyles" here: https://gist.github.com/souporserious/54f9e56ebac4fc4dab603c4212f2ec2e
const systemFonts =
'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"'
@souporserious
souporserious / directional-styles.js
Created June 16, 2017 05:50
Resolve "all, horizontal, vertical, top, right, bottom, left" to "top, right, bottom, left" with optional prefix/suffix
function capitalize(s) {
return s.slice(0, 1).toUpperCase() + s.slice(1)
}
function getValue(value, spacing) {
return !spacing || isNaN(value) ? value : value * spacing
}
function isNullLike(value) {
return value === null || typeof value === 'undefined'
@souporserious
souporserious / compute-design-system.js
Last active June 19, 2017 22:54
Compute design system styles
import deepExtend from 'deep-extend'
import colorStyles from './color-styles'
import fluidSize from './fluid-size'
import { fontBase, lineHeight, spacing, verticalRhythm } from '../design-system'
function valuesDefined(...values) {
return values.some(value => typeof value !== 'undefined')
}
function parseSides(...sides) {
import React, { Component, Children, cloneElement } from 'react'
import PropTypes from 'prop-types'
import createStyledElement from 'create-styled-element'
import Box from '../Box'
import Flex from '../Flex'
function Card({ row, subdued, ...props }) {
return (
<Flex
@souporserious
souporserious / react-docgen-loader.js
Created July 16, 2017 19:41
Load React component documentation information in Webpack using react-docgen
// Adaptation from: https://github.com/styleguidist/react-styleguidist/blob/a010018f6672af81332018399fc0e595e81d4b24/scripts/schemas/config.js
var reactDocgen = require('react-docgen')
var createDisplayNameHandler = require('react-docgen-displayname-handler')
.createDisplayNameHandler
module.exports = function(content) {
this.cacheable && this.cacheable(true)
var callback = this.async()
var file = this.request.split('!').pop()
@souporserious
souporserious / app.js
Last active April 8, 2024 12:54
Generate an array of React documentation using babel-plugin-preval and react-docgen.
// make sure to have babel-plugin-preval setup so this import works as expected
// https://github.com/kentcdodds/babel-plugin-preval
import docs from "./get-react-docs.js"
// do whatever you want with all of the component documentation
function renderDocs() {
return (
<div>
{docs.map(doc => ...)}
</div>
const path = require('path')
const express = require('express')
const webpack = require('webpack')
const webpackDevMiddleware = require('webpack-dev-middleware')
const webpackHotMiddleware = require('webpack-hot-middleware')
const config = require('./webpack.config.js')
const app = express()
const port = 8080
const compiler = webpack(config)
const middleware = webpackDevMiddleware(compiler, {
@souporserious
souporserious / react-autocompletely-components.jsx
Created July 26, 2017 01:14
Possible components that could be built with react-autocompletely.
function ArrowToggle({ active }) {
return <Icon name={active ? 'arrow-up' : 'arrow-down'} />
}
function renderTrigger({ isOpen, selectedItem, toggleMenu, ...props }) {
return (
<Button onClick={toggleMenu} {...props}>
{selectedItem} <ArrowToggle active={isOpen} />
</Button>
)