mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-02 11:59:17 -05:00
20 lines
513 B
TypeScript
20 lines
513 B
TypeScript
|
import { MergeAndOverride } from '../../../../types/utils'
|
||
|
|
||
|
type PolymorphicComponentOwnProps<E extends React.ElementType> = {
|
||
|
as?: E
|
||
|
}
|
||
|
|
||
|
export type PolymorphicComponentProps<E extends React.ElementType> =
|
||
|
MergeAndOverride<React.ComponentProps<E>, PolymorphicComponentOwnProps<E>>
|
||
|
|
||
|
function PolymorphicComponent<E extends React.ElementType = 'div'>({
|
||
|
as,
|
||
|
...props
|
||
|
}: PolymorphicComponentProps<E>) {
|
||
|
const Component = as || 'div'
|
||
|
|
||
|
return <Component {...props} />
|
||
|
}
|
||
|
|
||
|
export default PolymorphicComponent
|