import clsx from "clsx"; import omit from "lodash/omit"; import { HTMLAttributes, InputHTMLAttributes, PropsWithChildren, ReactNode } from "react"; import { registerComponent } from "../../../registries/components"; export type BaseFormControlProps = { label?: string; description?: string | ReactNode; before?: ReactNode | string; after?: ReactNode | string; shadow?: boolean; value?: Value; onChange?: (name: string | undefined, value: Value) => void; /** * The input size */ size?: "small" | string; }; export type FormControlProps< Value = unknown, Attributes extends HTMLAttributes = InputHTMLAttributes > = BaseFormControlProps & Omit; export function cleanFormControlProps(props: FormControlProps, omitted: string[] = []): any { return omit(props, ["label", "description", "prefix", "suffix", "size", "shadow", ...omitted]); } export function FormControl({ children, name = "", id = name, required, before, after, description, label, size, className }: PropsWithChildren>) { return (
{label && ( )}
{before && (
{before}
)} {children} {after && (
{after}
)}
{description && (
{description}
)}
); } registerComponent("FormControl", FormControl);