import type { ComponentChildren, VNode } from "preact"; import { cloneElement } from "preact"; /** * Passes props down to all children that accept them */ export function passPropsToChildren( children: ComponentChildren, props: Record ): ComponentChildren { if (Array.isArray(children)) { return children.map(child => { if (child && typeof child === 'object' && 'type' in child) { return cloneElement(child as VNode, props); } return child; }); } if (children && typeof children === 'object' && 'type' in children) { return cloneElement(children as VNode, props); } return children; }