{"version":3,"file":"create-polymorphic-component.mjs","sources":["../../../src/core/factory/create-polymorphic-component.ts"],"sourcesContent":["import React from 'react';\n\ntype ExtendedProps<Props = {}, OverrideProps = {}> = OverrideProps &\n  Omit<Props, keyof OverrideProps>;\n\ntype ElementType = keyof JSX.IntrinsicElements | React.JSXElementConstructor<any>;\n\ntype PropsOf<C extends ElementType> = JSX.LibraryManagedAttributes<\n  C,\n  React.ComponentPropsWithoutRef<C>\n>;\n\ntype ComponentProp<C> = {\n  component?: C;\n};\n\ntype InheritedProps<C extends ElementType, Props = {}> = ExtendedProps<PropsOf<C>, Props>;\n\nexport type PolymorphicRef<C> = C extends React.ElementType\n  ? React.ComponentPropsWithRef<C>['ref']\n  : never;\n\nexport type PolymorphicComponentProps<C, Props = {}> = C extends React.ElementType\n  ? InheritedProps<C, Props & ComponentProp<C>> & {\n      ref?: PolymorphicRef<C>;\n      renderRoot?: (props: any) => any;\n    }\n  : Props & { component: React.ElementType; renderRoot?: (props: Record<string, any>) => any };\n\nexport function createPolymorphicComponent<\n  ComponentDefaultType,\n  Props,\n  StaticComponents = Record<string, never>,\n>(component: any) {\n  type ComponentProps<C> = PolymorphicComponentProps<C, Props>;\n\n  type _PolymorphicComponent = <C = ComponentDefaultType>(\n    props: ComponentProps<C>\n  ) => React.ReactElement;\n\n  type ComponentProperties = Omit<React.FunctionComponent<ComponentProps<any>>, never>;\n\n  type PolymorphicComponent = _PolymorphicComponent & ComponentProperties & StaticComponents;\n\n  return component as PolymorphicComponent;\n}\n"],"names":[],"mappings":"AACO,SAAS,0BAA0B,CAAC,SAAS,EAAE;AACtD,EAAE,OAAO,SAAS,CAAC;AACnB;;;;"}