import type { JSX } from "react"; /** * React Polymorphic components type utilities * * @resources * - [Polymorphic types from Radix UI in Wanda System](https://github.com/wonderflow-bv/wanda/blob/main/packages/react-components/src/types/polymorphic/index.ts) * - [TypeScript + React: Typing Generic forwardRefs](https://fettblog.eu/typescript-react-generic-forward-refs/) * - [React with Typescript -- Generics while using React.forwardRef](https://stackoverflow.com/a/58473012/1938970) * - [How to write a generic that extracts the prop types of the component that passed in](https://stackoverflow.com/a/57846897/1938970) * - [React TS Generic component to pass generic props to children](https://stackoverflow.com/a/68442669/1938970) * - [About custom ref prop](https://gist.github.com/gaearon/1a018a023347fe1c2476073330cc5509) * - [forwardRef performance](https://github.com/facebook/react/issues/13456) * - [React docs: Exposing DOM Refs to Parent Components](https://github.com/facebook/react/issues/13456) */ export declare namespace Polymorphic { type Merge, P2 = Record> = Omit & P2; type ComponentTypes = React.ComponentClass | React.FunctionComponent | keyof JSX.IntrinsicElements; type InferProps = TComponent extends React.ComponentClass ? Props : TComponent extends React.FunctionComponent ? Props : TComponent extends React.ForwardRefExoticComponent ? Props : TComponent extends keyof JSX.IntrinsicElements ? React.ComponentPropsWithoutRef : never; type AsProp = { as?: TComponent; }; export type Ref = React.ComponentPropsWithRef["ref"]; export type Props> = Omit, keyof Props> & AsProp & Props; export type PropsWithRef> = Props & { ref?: Ref; }; type ForwardRefExoticComponent = React.ForwardRefExoticComponent : never, OwnProps & { as?: TComponent; }>>; export type ComponentForwarded> = ForwardRefExoticComponent & { (props: As extends "" ? { as: keyof JSX.IntrinsicElements; } : As extends React.ComponentType ? Merge : As extends keyof JSX.IntrinsicElements ? Merge : never): React.ReactElement | null; }; export {}; }