@radix-ui/react-polymorphic
Advanced tools
Comparing version 0.0.10 to 0.0.11
import * as React from "react"; | ||
export type Merge<P1 = {}, P2 = {}> = Omit<P1, keyof P2> & P2; | ||
type MergeProps<E, P = {}> = P & Merge<E extends React.ElementType ? React.ComponentPropsWithRef<E> : never, P>; | ||
/** | ||
@@ -13,2 +12,5 @@ * Infers the OwnProps if E is a ForwardRefExoticComponentWithAs | ||
type NarrowIntrinsic<E> = E extends keyof JSX.IntrinsicElements ? E : never; | ||
type ForwardRefExoticComponent<E, OwnProps> = React.ForwardRefExoticComponent<Merge<E extends React.ElementType ? React.ComponentPropsWithRef<E> : never, OwnProps & { | ||
as?: E; | ||
}>>; | ||
export interface ForwardRefComponent<IntrinsicElementString, OwnProps = {} | ||
@@ -19,29 +21,18 @@ /** | ||
*/ | ||
> extends React.ForwardRefExoticComponent<MergeProps<IntrinsicElementString, OwnProps & { | ||
as?: IntrinsicElementString; | ||
}>> { | ||
> extends ForwardRefExoticComponent<IntrinsicElementString, OwnProps> { | ||
/** | ||
* When passing an `as` prop as a string, use this overload. | ||
* When `as` prop is passed, use this overload. | ||
* Merges original own props (without DOM props) and the inferred props | ||
* from `as` element with the own props taking precendence. | ||
* | ||
* We explicitly define a `JSX.IntrinsicElements` overload so that | ||
* events are typed for consumers. | ||
* We explicitly avoid `React.ElementType` and manually narrow the prop types | ||
* so that events are typed when using JSX.IntrinsicElements. | ||
*/ | ||
<As extends keyof JSX.IntrinsicElements = NarrowIntrinsic<IntrinsicElementString>>(props: MergeProps<As, OwnProps & { | ||
<As extends keyof JSX.IntrinsicElements | React.JSXElementConstructor<any> = NarrowIntrinsic<IntrinsicElementString>>(props: As extends keyof JSX.IntrinsicElements ? Merge<JSX.IntrinsicElements[As], OwnProps & { | ||
as: As; | ||
}>): React.ReactElement | null; | ||
/** | ||
* When passing an `as` prop as a component, use this overload. | ||
* Merges original own props (without DOM props) and the inferred props | ||
* from `as` element with the own props taking precendence. | ||
* | ||
* We don't use `React.ComponentType` here as we get type errors | ||
* when consumers try to do inline `as` components. | ||
*/ | ||
<As extends React.ElementType>(props: MergeProps<As, OwnProps & { | ||
}> : As extends React.JSXElementConstructor<infer P> ? Merge<P, OwnProps & { | ||
as: As; | ||
}>): React.ReactElement | null; | ||
}> : never): React.ReactElement | null; | ||
} | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@radix-ui/react-polymorphic", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "source": "src/index.ts", |
@@ -13,2 +13,2 @@ # `react-polymorphic` | ||
This is an internal utility, not intended for public usage. | ||
View docs [here](https://radix-ui.com/primitives/docs/utilities/polymorphic). |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4360
37