@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
49 lines (48 loc) • 2.32 kB
TypeScript
import type { AriaAttributes, ReactNode } from 'react';
import type { FieldPropsGeneric, ProvideAdditionalEventArgs, SubmitState, Identifier, ReceiveAdditionalEventArgs } from '../types';
import type { ContextState } from '../DataContext';
export type DataAttributes = {
[property: `data-${string}`]: string | boolean | number;
};
type UseFieldPropsOptions = {
executeOnChangeRegardlessOfError?: boolean;
executeOnChangeRegardlessOfUnchangedValue?: boolean;
updateContextDataInSync?: boolean;
omitMultiplePathWarning?: boolean;
forceUpdateWhenContextDataIsSet?: boolean;
omitSectionPath?: boolean;
getExternalValueSnapshot?: (value: unknown) => unknown;
};
type ChangeOptions = {
preventUpdate?: boolean;
};
export default function useFieldProps<Value, EmptyValue, Props>(localProps: Props & FieldPropsGeneric<Value, EmptyValue>, { executeOnChangeRegardlessOfError, executeOnChangeRegardlessOfUnchangedValue, updateContextDataInSync, omitMultiplePathWarning, forceUpdateWhenContextDataIsSet, omitSectionPath, getExternalValueSnapshot, }?: UseFieldPropsOptions): typeof localProps & ReturnAdditional<Value>;
export type ReturnAdditional<Value> = {
/**
* The transformed value ready for display, or `undefined` if the associated field is not visible.
*/
value: Value;
isChanged: boolean;
htmlAttributes: AriaAttributes | DataAttributes;
setHasFocus: (hasFocus: boolean, overrideValue?: Value, additionalArgs?: ProvideAdditionalEventArgs) => void;
handleError: () => void;
handleFocus: () => void;
handleBlur: () => void;
handleChange: (value: Value | unknown, additionalArgs?: ProvideAdditionalEventArgs, options?: ChangeOptions) => void;
updateValue: (value: Value, options?: ChangeOptions) => void;
setChanged: (state: boolean) => void;
setDisplayValue: (value: ReactNode, { path, type }?: {
path?: Identifier;
type?: 'field';
}) => void;
forceUpdate: () => void;
hasError?: boolean;
/**
* The DataContext state object, providing access to form-level data and methods.
*/
dataContext: ContextState;
fieldState: SubmitState;
additionalArgs: ReceiveAdditionalEventArgs<Value>;
};
export { checkForError } from './useFieldError';
export declare const clearedArray: any[];