Reach UI is an accessible foundation for React applications and design systems.
The three equally important goals are to be:
- Accessible
- Composable
- Stylable
type AnyFunction = (...args: any[]) => any | |
function useEvent<T extends AnyFunction>(callback?: T) { | |
const ref = useRef<AnyFunction | undefined>(() => { | |
throw new Error("Cannot call an event handler while rendering.") | |
}) | |
// Or useInsertionEffect if it's React 18 | |
useLayoutEffect(() => { | |
ref.current = callback | |
}) |
import React, { useEffect, useMemo, useCallback, useLayoutEffect, useState } from "react"; | |
import { EditorView } from "@codemirror/view"; | |
import { EditorState, Compartment, EditorStateConfig, StateEffect, Extension } from "@codemirror/state"; | |
import { indentUnit } from "@codemirror/language"; | |
/** creates an editor view from an initial state - destroys the view on cleanup */ | |
export function useEditorView(initState: (() => EditorStateConfig) | EditorStateConfig = {}): EditorView { | |
const view = useMemo( | |
() => new EditorView({ state: EditorState.create(typeof initState === "function" ? initState() : initState) }), | |
[] |
// by dave @beesandbombs | |
int[][] result; | |
float t, c; | |
float ease(float p) { | |
return 3*p*p - 2*p*p*p; | |
} | |
float ease(float p, float g) { |
import React from 'react'; | |
import { DetectExternalEvents } from './detectexternalevents'; | |
const EXTERNAL_REACT_EVENTS = ['onMouseDown', 'onTouchStart']; | |
const EXTERNAL_DOM_EVENTS = ['mousedown', 'touchstart']; | |
export interface IDetectExternalClickProps { | |
component?: string; | |
onExternalClick: (event: Event) => void; |
from enum import Enum, EnumMeta | |
class ChoiceEnumMeta(EnumMeta): | |
def __iter__(self): | |
return ((tag, tag.value) for tag in super().__iter__()) | |
class ChoiceEnum(Enum, metaclass=ChoiceEnumMeta): | |
""" |
// UPDATE: In 2023, you should probably stop using this! The narrow version of Safari that | |
// does not support `nomodule` is probably not being used anywhere. The code below is left | |
// for posterity. | |
/** | |
* Safari 10.1 supports modules, but does not support the `nomodule` attribute - it will | |
* load <script nomodule> anyway. This snippet solve this problem, but only for script | |
* tags that load external code, e.g.: <script nomodule src="nomodule.js"></script> | |
* | |
* Again: this will **not** prevent inline script, e.g.: |
module.exports = (file, api, options) => { | |
const j = api.jscodeshift; | |
const printOptions = options.printOptions || {quote: 'single'}; | |
const root = j(file.source); | |
const requires = {}; | |
const filterAndTransformRequires = path => { | |
const varName = path.value.local.name; | |
const scopeNode = path.parentPath.scope.node; |
from keras.models import Sequential | |
from keras.layers import Dense | |
x, y = ... | |
x_val, y_val = ... | |
# 1-dimensional MSE linear regression in Keras | |
model = Sequential() | |
model.add(Dense(1, input_dim=x.shape[1])) | |
model.compile(optimizer='rmsprop', loss='mse') |