import type { ReactNode } from "react"; import type { FieldValues } from "react-hook-form"; import { EditableSection, type EditableSectionProps, } from "../containers/EditableSection"; import { type FormEditorProps, useFormEditorModal } from "./useFormEditorModal"; export interface FormEditableSectionProps extends Pick< EditableSectionProps, | "accent" | "children" | "className" | "details" | "disabled" | "editAriaLabel" | "editIcon" | "editIconVariant" | "title" | "titleBadge" >, Omit, "size" | "title"> { /** Size of the editor modal. */ modalSize?: FormEditorProps["size"]; /** Heading of the editor modal. Defaults to `title`. */ modalTitle?: string; } /** * An EditableSection whose editor is a modal owning its own Form — see * useFormEditorModal for how the edit is kept out of the screen's state. The * body stays `children`, so the read-only content is written as plain JSX. */ export function FormEditableSection({ title, titleBadge, details, editAriaLabel, editIcon, editIconVariant, accent, className, disabled, modalSize, modalTitle, children, ...editorProps }: FormEditableSectionProps): ReactNode { const { open, editor } = useFormEditorModal({ ...editorProps, title: modalTitle ?? title, size: modalSize, accent, }); return ( {children} {editor} ); }