feat(ui): iterate on picker

This commit is contained in:
psychedelicious
2025-05-01 15:15:15 +10:00
parent 5011fab85d
commit 31ab9be79a
10 changed files with 1030 additions and 775 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,32 +0,0 @@
import { useCallback, useEffect, useRef, useState } from 'react';
const isInitialValueFunction = <T>(value: T | (() => T)): value is () => T => {
return typeof value === 'function';
};
/**
* Extension of useState that provides imperative access to state value.
*
* @param initialValue - Initial state value or function that returns it
* @returns [state, setState, getState] - Standard state tuple plus getter
*
* @remarks
* - Only use getState() in event handlers and effects, not during rendering
* - In Concurrent Mode, getState() may return stale values before commit
*/
export const useStateImperative = <T>(
initialValue: T | (() => T)
): readonly [T, (newValue: T | ((prevState: T) => T)) => void, () => T] => {
const [state, setState] = useState(isInitialValueFunction(initialValue) ? initialValue() : initialValue);
const stateRef = useRef(state);
useEffect(() => {
stateRef.current = state;
}, [state]);
const getState = useCallback(() => {
return stateRef.current;
}, []);
return [state, setState, getState] as const;
};

View File

@@ -1,13 +0,0 @@
import { forwardRef } from 'react';
/**
* A forwardRef that works with generics and doesn't require the use of `as` to cast the type.
* See: https://www.totaltypescript.com/forwardref-with-generic-components
*/
export function fixedForwardRef<T, P = object>(
render: (props: P, ref: React.Ref<T>) => React.ReactNode
): (props: P & React.RefAttributes<T>) => React.ReactNode {
// @ts-expect-error: This is a workaround for forwardRef's crappy typing
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return forwardRef(render) as any;
}