import { ComponentProps, default as React } from 'react'; /** * The following source code is mainly inspired by * https://github.com/pluralsight/classic-design-system/blob/08f0962dec18d99e1799a16c7b7eac86f01cbc27/packages/util/src/primatives.ts */ export type As = React.ElementType; /** * Omit will not distribute over unions by default, this utility type will * distribute it, allowing to omit keys from each member of the union. * * @example * type A = { a: string; b: number } * type B = { a: string; c: boolean } * type Union = A | B * * // Without DistributiveOmit * type Test1 = Omit // never (because 'a' is in both A and B) * type Test2 = Omit // B (because 'b' is not in B) */ export type DistributiveOmit = T extends any ? Omit : never; /** * Injects in given props the one of the element */ export type ForwardRefProps> = MergeProps>; export interface ForwardRefWithAsRenderFunction> { (props: PropsFromAs, ref: React.Ref>): null | React.ReactElement; /** * defaultProps are not supported on render functions */ defaultProps?: never; displayName?: string; /** * propTypes are not supported on render functions */ propTypes?: never; } export interface FunctionComponentWithAs { /** * Inherited from React.FunctionComponent with modification to support `as` */ (props: PropsWithAs, context?: any): null | React.ReactElement; /** * Inherited from React.FunctionComponent */ defaultProps?: Partial>; displayName?: string; } /** * This will merge two prop objects, giving P1 priority over P2 * In other words, any props in P1 that are also in P2 will override the ones in P2 * This is useful when combining the props of the `as` component with your own props */ export type MergeProps = DistributiveOmit & P1; /** * Get the props of a component with `as` support * This will take care of the ref and the merging of the props */ export type PropsFromAs = React.PropsWithoutRef>; /** * Props of a component with `as` support */ export type PropsWithAs = MergeProps, React.ComponentProps>; /** * An empty object type */ type EmptyProps = Record; /** * PropsType can either be an object or null/undefined */ type PropsType = null | Record; /** * Adds the `as` prop to a component's props */ type WithAs = MergeProps<{ as?: DefaultComponentType; }, ComponentProps>; /** * Wraps a component with a forwardRef and adds the `as` prop support */ export declare function forwardRefWithAs(render: ForwardRefWithAsRenderFunction): FunctionComponentWithAs; export {};