import { cloneElement, ComponentChildren, RefObject, VNode } from "preact"; import { CSSProperties } from "preact/compat"; import { useUniqueName } from "./hooks"; interface FormGroupProps { name: string; labelRef?: RefObject; label?: string; title?: string; className?: string; children: VNode; description?: string | ComponentChildren; disabled?: boolean; style?: CSSProperties; } export default function FormGroup({ name, label, title, className, children, description, labelRef, disabled, style }: FormGroupProps) { const id = useUniqueName(name); const childWithId = cloneElement(children, { id }); return (
{ label && } {childWithId} {description &&
{description}
}
); } /** * Similar to {@link FormGroup} but allows more than one child. Due to this behaviour, there is no automatic ID assignment. */ export function FormMultiGroup({ label, children }: { label: string, children: ComponentChildren }) { return (
{label && } {children}
); }