UNPKG

@stratakit/foundations

Version:
44 lines (43 loc) 2.49 kB
import * as React from "react"; import type { FocusableProps as AkFocusableProps } from "@ariakit/react/focusable"; import type { RoleProps } from "@ariakit/react/role"; export declare const isBrowser: boolean; export declare const supportsPopover: boolean; export declare function isDocument(node?: Node): node is Document; export declare function getOwnerDocument(node?: Node | null): Document | null; export declare function getWindow(node: Node): (Window & typeof globalThis) | null; /** "Parses" a string of HTML into a DocumentFragment. */ export declare function parseDOM(htmlString: string, { ownerDocument }: { ownerDocument: Document; }): DocumentFragment; /** * Wrapper over `React.forwardRef` which allows refs to be loosely typed as `HTMLElement`. * * Usage: * * ```tsx * const Button = forwardRef<"button", ButtonProps>((props, forwardedRef) => {}); * * const ref = React.useRef<HTMLElement>(null); // or React.useRef<HTMLButtonElement>(null) * <Button ref={ref} /> * ``` * * **Note**: The first type parameter is the default element type, which is slightly different * from what `React.forwardRef` expects. e.g. This utility expects `"div"` instead of `ComponentRef<"div">`. * * @private */ export declare const forwardRef: ForwardRefHelper; type ForwardRefHelper = <DefaultElement extends React.ElementType, Props extends {}>(render: React.ForwardRefRenderFunction<React.ComponentRef<DefaultElement>, React.PropsWithoutRef<Props>>) => React.ForwardRefExoticComponent<React.PropsWithoutRef<Props> & React.RefAttributes<React.ComponentRef<DefaultElement> | HTMLElement>>; /** Element type props merged with custom props. */ type MergeProps<ElementType extends React.ElementType, CustomProps extends Record<string, unknown>> = CustomProps & Omit<React.ComponentPropsWithoutRef<ElementType>, keyof CustomProps>; /** Base component props with custom props. */ export type BaseProps<ElementType extends React.ElementType = "div"> = MergeProps<ElementType, Pick<RoleProps, "render">>; /** Focusable component props with custom props. */ export type FocusableProps<ElementType extends React.ElementType = "div"> = BaseProps<ElementType> & Pick<AkFocusableProps, "disabled" | "accessibleWhenDisabled" | "autoFocus">; /** See https://github.com/Microsoft/TypeScript/issues/29729 */ export type AnyString = string & {}; export type AnyFunction = (...args: any) => any; /** Returns the value unchanged. */ export declare const identity: <T>(value: T) => T; export {};