Files
Trilium/apps/client/src/widgets/react/FormGroup.tsx

31 lines
1.0 KiB
TypeScript
Raw Normal View History

import { cloneElement, ComponentChildren, RefObject, VNode } from "preact";
import { CSSProperties } from "preact/compat";
import { useUniqueName } from "./hooks";
2025-08-04 20:34:47 +03:00
interface FormGroupProps {
name: string;
2025-08-05 19:06:47 +03:00
labelRef?: RefObject<HTMLLabelElement>;
2025-08-06 18:38:52 +03:00
label?: string;
2025-08-04 21:17:35 +03:00
title?: string;
className?: string;
children: VNode<any>;
2025-08-07 19:20:35 +03:00
description?: string | ComponentChildren;
2025-08-14 22:27:07 +03:00
disabled?: boolean;
style?: CSSProperties;
2025-08-04 20:34:47 +03:00
}
export default function FormGroup({ name, label, title, className, children, description, labelRef, disabled, style }: FormGroupProps) {
const id = useUniqueName(name);
const childWithId = cloneElement(children, { id });
2025-08-04 20:34:47 +03:00
return (
<div className={`form-group ${className} ${disabled ? "disabled" : ""}`} title={title} style={style}>
{ label &&
<label style={{ width: "100%" }} ref={labelRef} htmlFor={id}>{label}</label>}
{childWithId}
2025-08-04 21:17:35 +03:00
{description && <small className="form-text">{description}</small>}
2025-08-04 20:34:47 +03:00
</div>
);
}