@mantine/core
Version:
React components library focused on usability, accessibility and developer experience
1 lines • 3.82 kB
Source Map (JSON)
{"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":";;;;;;;AAMO,CAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,C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