Skip to content

Instantly share code, notes, and snippets.

View phobon's full-sized avatar
🙃

Ben McCormick phobon

🙃
View GitHub Profile
@phobon
phobon / streamline icon template
Created April 29, 2019 00:11
Custom template to use for streamline icons
// default template
module.exports = ({
name,
viewBox,
pathData
}) => `import React from 'react'
const ${name}Icon = ({
size,
color,
@phobon
phobon / consuming.jsx
Created September 29, 2020 05:53
Consuming data
function fetchLedBrands = async () => {
// This can be sourced from anything, an api endpoint etc.
//[
// { id: 1, label: "a" },
// { id: 2, label: "b" },
// { id: 3, label: "c" },
// { id: 4, label: "d" },
// { id: 5, label: "e" },
//];
const dataAtom = atom({});
const Form = ({ code, name, categories, dimensions, setData, ...props }) => {
const [code, setCode] = useState(() => code);
const [name, setName] = useState(() => name);
const [categories, setCategories] = useState(() => categories);
const [dimensions, setDimensions] = useState(() => dimensions);
const updateData = e => setData({
code,
export const ParentComponent = ({ ...props }) => {
const name = useState(null);
const address = useState(null);
const other = useState(null);
const fields = [name, address, other];
return (
<form>
{fields.map(([field, setField], index) => (
@phobon
phobon / App.jsx
Last active October 15, 2020 07:36
// App.js
import { Provider } from "jotai";
import { Layout } from "./Layout";
const App = ({ children }) => {
return (
<Provider>
<Layout>
{children}
/** @jsx jsx */
import { jsx } from "@emotion/react";
import { useRef, useEffect } from "react";
import { Box, BoxProps, Image } from "@phobon/base";
import { motion } from "framer-motion";
const MotionImage = motion.custom(Image);
export interface IShiftImageProps {
loading?: "eager" | "lazy";
const balancedSum = (arr) => {
// Find the left and right parts of the array, start from the middle cos it's as good a place as any
let i = Math.floor(arr.length / 2)
let left = arr.slice(0, i).reduce((a, b) => a + b, 0)
let right = arr.slice(i + 1).reduce((a, b) => a + b, 0)
// If they're equal, you beauty
if (left === right) {
return i
}
import styled from 'styled-components'
const variants = ({ variant }) => {
const allVariants = {
danger: {
backgroundColor: 'red',
},
warning: {
backgroundColor: 'orange',
},
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable max-len */
import { StitchesCss, createCss } from '@stitches/react'
export const config = createCss({
prefix: '',
theme: {
colors: {
grey50: '#F9F9F9',
grey100: '#EAEDF0',