UNPKG

@vaadin/hilla-react-crud

Version:

Hilla CRUD utils for React

46 lines (45 loc) 2.25 kB
import { EndpointError } from '@vaadin/hilla-frontend'; import { type AbstractModel, type DetachedModelConstructor, type Value } from '@vaadin/hilla-lit-form'; import { type UseFormResult } from '@vaadin/hilla-react-form'; import { FormLayout } from '@vaadin/react-components/FormLayout'; import { type ComponentType, type JSX, type ReactElement } from 'react'; import { type AutoFormFieldProps, type FieldOptions } from './autoform-field.js'; import type { FormService } from './crud.js'; import { type ComponentStyleProps } from './util.js'; export declare const emptyItem: unique symbol; export type SubmitErrorEvent = { error: EndpointError; setMessage(message: string): void; }; export type SubmitEvent<TItem> = { item: TItem; }; export type DeleteErrorEvent = { error: EndpointError; setMessage(message: string): void; }; export type DeleteEvent<TItem> = { item: TItem; }; export type AutoFormLayoutRendererProps<M extends AbstractModel> = Readonly<{ form: UseFormResult<M>; children: ReadonlyArray<ReactElement<AutoFormFieldProps>>; }>; export type AutoFormProps<M extends AbstractModel = AbstractModel> = ComponentStyleProps & Readonly<{ service: FormService<Value<M>>; model: DetachedModelConstructor<M>; itemIdProperty?: string; item?: Value<M> | typeof emptyItem | null; disabled?: boolean; layoutRenderer?: ComponentType<AutoFormLayoutRendererProps<M>>; visibleFields?: string[]; hiddenFields?: string[]; formLayoutProps?: ComponentStyleProps & Pick<Parameters<typeof FormLayout>[0], 'responsiveSteps'>; fieldOptions?: Record<string, FieldOptions>; deleteButtonVisible?: boolean; onSubmitError?({ error }: SubmitErrorEvent): void; onSubmitSuccess?({ item }: SubmitEvent<Value<M>>): void; onDeleteError?({ error }: DeleteErrorEvent): void; onDeleteSuccess?({ item }: DeleteEvent<Value<M>>): void; }>; export declare function AutoForm<M extends AbstractModel>({ service, model, itemIdProperty, item, onSubmitError, onSubmitSuccess, disabled, layoutRenderer: LayoutRenderer, visibleFields, hiddenFields, formLayoutProps, fieldOptions, style, id, className, deleteButtonVisible, onDeleteSuccess, onDeleteError, }: AutoFormProps<M>): JSX.Element;