@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
59 lines (58 loc) • 3 kB
TypeScript
import type { RefObject } from 'react';
import type { JsonObject } from '../../utils/json-pointer';
import IsolationCommitButton from './IsolationCommitButton';
import IsolationResetButton from './IsolationResetButton';
import { type DataContextProviderProps as ProviderProps } from '../../DataContext/Provider';
import type { IsolationDataReference } from './IsolationDataReference';
import type { OnCommit, Path } from '../../types';
export type IsolationProviderProps<Data extends JsonObject> = {
/**
* Will be called on a nested form context commit – if validation has passed. The first parameter is the committed data object. The second parameter is an object containing a method to clear the internal data `{ clearData }`.
*/
onCommit?: OnCommit<Data>;
/**
* Form.Isolation: Will be called when the form is cleared via Form.clearData
*/
onClear?: () => void;
/**
* Transform the data before it gets committed to the form. The first parameter is the isolated data object. The second parameter is the outer context data object (Form.Handler).
*/
transformOnCommit?: (isolatedData: Data, handlerData: Data) => JsonObject;
/**
* Prevent the form from being submitted when there are fields with errors inside the Form.Isolation.
*/
bubbleValidation?: boolean;
/**
* Prevents uncommitted changes before the form is submitted. Will display an error message if user tries to submit without committing their changes.
*/
preventUncommittedChanges?: boolean;
/**
* If set to `true`, the Form.Isolation will reset its data context after committing the data to the outer context.
*/
resetDataAfterCommit?: boolean;
/**
* Provide a reference by using `Form.Isolation.createDataReference`.
*/
dataReference?: IsolationDataReference;
/**
* JSON Pointer to define the object key for all the generated nested field data. When provided, Form.Isolation will inherit schema validation from the parent Form.Handler for fields within this path.
*/
path?: Path;
/**
* Used internally by the Form.Isolation component
*/
isolate?: boolean;
};
export type IsolationProps<Data extends JsonObject> = Omit<ProviderProps<Data>, 'onSubmit' | 'onSubmitRequest' | 'onSubmitComplete' | 'minimumAsyncBehaviorTime' | 'asyncSubmitTimeout' | 'scrollTopOnSubmit' | 'sessionStorageId' | 'globalStatusId'> & {
/**
* Provide a ref to a function that can be called from any location to commit the data to the form.
*/
commitHandleRef?: RefObject<() => void>;
};
declare function IsolationProvider<Data extends JsonObject>(props: IsolationProps<Data>): import("react/jsx-runtime").JSX.Element;
declare namespace IsolationProvider {
var CommitButton: typeof IsolationCommitButton;
var ResetButton: typeof IsolationResetButton;
var createDataReference: typeof import("./IsolationDataReference").createDataReference;
}
export default IsolationProvider;