{"version":3,"file":"polymorphic-factory.cjs","sources":["../../../src/core/factory/polymorphic-factory.tsx"],"sourcesContent":["import { forwardRef } from 'react';\nimport { PolymorphicComponentProps } from './create-polymorphic-component';\nimport {\n  ComponentClasses,\n  FactoryPayload,\n  identity,\n  StaticComponents,\n  ThemeExtend,\n} from './factory';\n\nexport interface PolymorphicFactoryPayload extends FactoryPayload {\n  defaultComponent: any;\n  defaultRef: any;\n}\n\nexport type PolymorphicComponentWithProps<Payload extends PolymorphicFactoryPayload> = {\n  withProps: <C = Payload['defaultComponent']>(\n    fixedProps: PolymorphicComponentProps<C, Payload['props']>\n  ) => <L = C>(props: PolymorphicComponentProps<L, Payload['props']>) => React.ReactElement;\n};\n\nexport function polymorphicFactory<Payload extends PolymorphicFactoryPayload>(\n  ui: React.ForwardRefRenderFunction<Payload['defaultRef'], Payload['props']>\n) {\n  type ComponentProps<C> = PolymorphicComponentProps<C, Payload['props']>;\n\n  type _PolymorphicComponent = <C = Payload['defaultComponent']>(\n    props: ComponentProps<C>\n  ) => React.ReactElement;\n\n  type ComponentProperties = Omit<React.FunctionComponent<ComponentProps<any>>, never>;\n\n  type PolymorphicComponent = _PolymorphicComponent &\n    ComponentProperties &\n    ThemeExtend<Payload> &\n    ComponentClasses<Payload> &\n    PolymorphicComponentWithProps<Payload> &\n    StaticComponents<Payload['staticComponents']>;\n\n  const Component = forwardRef(ui) as unknown as PolymorphicComponent;\n  Component.withProps = (fixedProps: any) => {\n    const Extended = forwardRef((props, ref) => (\n      <Component {...fixedProps} {...props} ref={ref as any} />\n    )) as any;\n    Extended.extend = Component.extend;\n    Extended.displayName = `WithProps(${Component.displayName})`;\n    return Extended;\n  };\n\n  Component.extend = identity as any;\n\n  return Component as PolymorphicComponent;\n}\n"],"names":["forwardRef","jsx","identity"],"mappings":";;;;;;AAqBO,SAAS,mBACd,EACA,EAAA;AAgBA,EAAM,MAAA,SAAA,GAAYA,iBAAW,EAAE,CAAA;AAC/B,EAAU,SAAA,CAAA,SAAA,GAAY,CAAC,UAAoB,KAAA;AACzC,IAAA,MAAM,QAAW,GAAAA,gBAAA,CAAW,CAAC,KAAA,EAAO,GAClC,qBAAAC,cAAA,CAAC,SAAW,EAAA,EAAA,GAAG,UAAa,EAAA,GAAG,KAAO,EAAA,GAAA,EAAiB,CACxD,CAAA;AACD,IAAA,QAAA,CAAS,SAAS,SAAU,CAAA,MAAA;AAC5B,IAAS,QAAA,CAAA,WAAA,GAAc,CAAa,UAAA,EAAA,SAAA,CAAU,WAAW,CAAA,CAAA,CAAA;AACzD,IAAO,OAAA,QAAA;AAAA,GACT;AAEA,EAAA,SAAA,CAAU,MAAS,GAAAC,gBAAA;AAEnB,EAAO,OAAA,SAAA;AACT;;;;"}