๐
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function CurrencyInput({ | |
value, | |
onChange, | |
max, | |
}: { | |
value: number; | |
max: number; | |
onChange: (val: number) => void; | |
}) { | |
const [error, setError] = useState(''); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs from 'fs/promises'; | |
console.time('Get file sizes'); | |
const items = await fs.readdir('.'); | |
const ignore = [ | |
'_templates', | |
'.git', | |
'.github', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a React component that loads and inlines an SVG image, making it easier to style | |
// with CSS. It renders an <img> first, and then renders the inline SVG once it's been loaded. | |
import {useState, useEffect, memo, ComponentPropsWithoutRef} from "react"; | |
export const SVGImageLoader: React.FC< | |
{url: string} & ComponentPropsWithoutRef<"img"> | |
> = memo(({url, alt, ...props}) => { | |
const [data, setData] = useState<string | null>(null); | |
useEffect(() => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from "react"; | |
const CopyToClipboard:React.FC<{text:string} & React.HTMLAttributes<HTMLButtonElement>> = ({text, ...props}) => { | |
const copyToClipboard = (event:React.MouseEvent<HTMLButtonElement>, str:string) => { | |
const el = Object.assign(document.createElement('textarea'),{value:str}); | |
document.body.appendChild(el); | |
el.select(); | |
document.execCommand('copy'); | |
document.body.removeChild(el); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a symbol for our proxy | |
let isProxy = Symbol("isProxy"); | |
const handler = { | |
get(target, key) { | |
// Override access if we are checking if the object is already a proxy | |
if (key === isProxy) return true; | |
if ( | |
// Don't wrap it again if the object is already a proxy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { produce, applyPatches, enablePatches } from "immer"; | |
enablePatches(); | |
function setToValue(obj, value, path) { | |
var i; | |
path = path.split("."); | |
for (i = 0; i < path.length - 1; i++) { | |
if (!obj[path[i]]) { | |
obj[path[i]] = isNaN(parseInt(path[i], 10)) ? {} : []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import i18next from "i18next"; | |
import {initReactI18next} from "react-i18next"; | |
import LanguageDetector from "i18next-browser-languagedetector"; | |
import codegen from "codegen.macro"; | |
import debounce from "lodash.debounce"; | |
i18next | |
.use(LanguageDetector) | |
.use(initReactI18next) // passes i18n down to react-i18next | |
.init({ | |
resources: {}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
React, | |
} from "https://unpkg.com/es-react"; | |
declare global { | |
namespace JSX { | |
interface IntrinsicElements { | |
h1: any; | |
div: any; | |
h2: any; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A React hook which uses the WebUSB API to send DMX messages to a connected ENTTEC Pro device | |
// This will only work in Chrome. | |
// If you want to just try it, run it through the TypeScript compiler here https://www.typescriptlang.org/play/index.html | |
import React from "react"; | |
declare global { | |
interface Navigator { | |
// This USB type comes from @types/w3c-web-usb | |
readonly usb: USB; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions |