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
<script type="module"> | |
// https://react.dev/blog/2024/04/25/react-19-upgrade-guide#umd-builds-removed | |
import React from "https://esm.sh/react@19/?dev" | |
import ReactDOMClient from "https://esm.sh/react-dom@19/client?dev" | |
... | |
</script> |
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
type Item = { | |
id: string | |
parentId: string | undefined | |
} | |
type NestedItem = Item & { | |
children: NestedItem[] | |
} | |
const getNestedItems = (items: Item[], parentId: string | undefined = undefined) => { |
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' | |
export type ModalResolveFn<T = unknown> = (answer?: T) => void | |
// the shape of a modal definition. A unique id and an element | |
export interface ModalDefinition<T> { | |
id: string | |
element: React.ReactNode | |
handleClose: ModalResolveFn<T> | |
} |
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' | |
// the shape of a modal definition. A unique id and an element | |
interface ModalDefinition { | |
id: string | |
content: React.ReactNode | |
} | |
type AddModalFn = (def: ModalDefinition) => void | |
type RemoveModalFn = (id: string) => void |
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
clientX/Y: 0,0 is top left of the browser window (under the toolbar/bookmarks bar) | |
offsetX/Y: 0,0 is top left of clicked element | |
screenX/Y: 0,0 is top left of monitor/display | |
pageX/Y: 0,0 is top left of page content, including scroll |
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
const obj = { | |
str: 'hello', | |
num: 1, | |
bool: true | |
} | |
type MiscObject = typeof obj | |
const fun = <T extends keyof MiscObject>(key: T): MiscObject[T] => { | |
return obj[key] |
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
const prefix = { | |
1: 'First', | |
2: 'Second', | |
3: 'Third', | |
4: 'Fourth', | |
5: 'Fifth', | |
6: 'Sixth', | |
7: 'Seventh', | |
8: 'Eighth', | |
9: 'Ninth', |
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 { useEffect, useRef } from "react" | |
const useAutoFocus = (enabled: boolean) => { | |
const ref = useRef<HTMLElement>() | |
useEffect(() => { | |
if (ref.current && enabled) { | |
setTimeout(() => ref.current?.focus(), 100) | |
} | |
}, [enabled]) |
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 { isBefore, setHours, setMinutes, setSeconds, addMinutes, setMilliseconds } from 'date-fns' | |
const setTime = (x, h = 0, m = 0, s = 0, ms = 0) => setHours(setMinutes(setSeconds(setMilliseconds(x, ms), s), m), h) | |
const from = setTime(new Date(), 9) | |
const to = setTime(new Date(), 17) | |
const step = (x) => addMinutes(x, 30) | |
const blocks = [] | |
let cursor = from |
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
const daysEnum = { | |
1: 'Sun', | |
'Sun': 1, | |
2: 'Mon', | |
'Mon': 2, | |
4: 'Tue', | |
'Tue': 4, | |
8: 'Wed', | |
'Wed': 8, | |
16: 'Thu', |
NewerOlder