import { ReactElement , RefAttributes , cloneElement } from "react" ; import { Size , SizeAdapter , normalizeSize } from "./size" ; import { mergeProps } from "./mergeProps" ; export function augmentElement ( element , newProps ) { const augmentedProps = mergeProps ( { ... element . props , ref : element . ref } , newProps ) ; return cloneElement ( element , augmentedProps ) ; } type RecordWithSize = { size : Size ; } & Record < string , any > ; export function createEmbeddableAdapter < T extends Size > ( sizeAdapter ) { return < Props extends RecordWithSize > ( element , { size , ... props } ) => { const newProps = { ... props , size : sizeAdapter [ normalizeSize ( size ) ] } ; return augmentElement ( element , newProps ) ; } ; }