import { Popover } from "@mantine/core"; import { IconBug } from "@tabler/icons-react"; import type { JsonError } from "json-schema-library"; import type { JSONSchema } from "json-schema-to-ts"; import { Children, type ReactElement, type ReactNode, cloneElement, isValidElement } from "react"; import { IconButton } from "ui/components/buttons/IconButton"; import { JsonViewer } from "ui/components/code/JsonViewer"; import * as Formy from "ui/components/form/Formy"; import { getLabel } from "./utils"; export type FieldwrapperProps = { pointer: string; label?: string | false; required?: boolean; errors?: JsonError[]; schema?: Exclude; debug?: object | boolean; wrapper?: "group" | "fieldset"; hidden?: boolean; children: ReactElement | ReactNode; }; export function FieldWrapper({ pointer, label: _label, required, errors = [], schema, debug, wrapper, hidden, children }: FieldwrapperProps) { const examples = schema?.examples || []; const examplesId = `${pointer}-examples`; const description = schema?.description; const label = typeof _label !== "undefined" ? _label : schema ? getLabel(pointer, schema) : pointer; return ( 0} as={wrapper === "fieldset" ? "fieldset" : "div"} className={hidden ? "hidden" : "relative"} > {debug && (
)} {label && ( {label} {required && *} )}
{Children.count(children) === 1 && isValidElement(children) ? cloneElement(children, { // @ts-ignore list: examples.length > 0 ? examplesId : undefined }) : children} {examples.length > 0 && ( {examples.map((e, i) => ( )}
{description && {description}} {errors.length > 0 && ( {errors.map((e) => e.message).join(", ")} )}
); }