@veracity/vui
Version:
Veracity UI is a React component library crafted for use within Veracity applications and pages. Based on Styled Components and @xstyled.
43 lines (42 loc) • 2.38 kB
TypeScript
import { AnyFunction, CreateContextOptions, CreateContextReturn } from "./types.js";
import React, { DependencyList, Dispatch, RefObject, SetStateAction } from "react";
//#region src/utils/react.d.ts
type ReactRef<T> = React.Ref<T> | React.RefObject<T> | React.MutableRefObject<T>;
/**
* Assigns given value to the provided ref.
* Supports ref as function (e.g. useState) and classic ref (e.g. useRef).
*/
declare function assignRef<T = any>(ref: ReactRef<T> | undefined, value: T): void;
/** Generic function to create new Context and context access hook. */
declare function createContext$1<ContextType>(options?: CreateContextOptions): CreateContextReturn<ContextType>;
/** Assigns a node to all provided refs. */
declare function mergeRefs<T>(...refs: (ReactRef<T> | undefined)[]): (node: T | null) => void;
/** Returns given callback with a stable reference, but keeps it updated internally. */
declare function useCallbackRef<T extends AnyFunction>(callback?: T, deps?: DependencyList): T;
/**
* Triggers given callback when an event happens outside of a given element.
* Event listeners are attached to the window object.
* @param ref - element to check click position for
* @param callback - function triggered on outside click
* @param events - array of events listened for (default: ['mousedown', 'touchstart'])
*/
declare function useClickOutside(ref: RefObject<HTMLElement | null> | RefObject<HTMLElement | null>[], callback?: (event: Event) => void, events?: string[]): void;
type UseControlledProps<T> = {
defaultValue?: T;
onChange?: (value: T) => void;
value?: T;
};
/** Supports state management in components that can be controlled or uncontrolled. */
declare function useControlled<T>(props: UseControlledProps<T>): [T, Dispatch<SetStateAction<T>>, {
isControlled: boolean;
reset: () => void;
}];
/** Returns an array with each prefix added to the id. Useful for aria attributes in compound components. */
declare function useIds(id: string, prefixes: string[]): string[];
/**
* Provides a function, which can be called to check if component using the hook is mounted or unmounted.
*/
declare function useIsMounted(): () => boolean;
//#endregion
export { UseControlledProps, assignRef, createContext$1 as createContext, mergeRefs, useCallbackRef, useClickOutside, useControlled, useIds, useIsMounted };
//# sourceMappingURL=react.d.ts.map