UNPKG

react-ocean-forms

Version:
147 lines (146 loc) 5.12 kB
/** * Copyright (c) 2018-present, Umweltbundesamt GmbH * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import React from 'react'; import { IFieldProps, IValueMeta, TBasicFieldValue } from './Field.types'; interface IContextMeta extends IValueMeta { defaultValue?: TBasicFieldValue; externalValue?: TBasicFieldValue; } interface ILocalOverridenMeta { disabled?: boolean; plaintext?: boolean; } interface IFieldState { touched: boolean; dirty: boolean; value: TBasicFieldValue; contextMeta: IContextMeta; propsMeta: ILocalOverridenMeta; } /** * Wrapper for input fields managed by * the form component */ export declare class BaseField extends React.Component<IFieldProps, IFieldState> { static displayName: string; constructor(props: IFieldProps); /** * Changes the field value based on changes in Form.defaultValues, * Form.values, Field.defaultValue or Field.value. The Field props * always override the Form props. Changes in defaultValue will only * update the field value, if there is no values or value prop present * and if the field hasn't been touched. */ static getDerivedStateFromProps(nextProps: IFieldProps, prevState: IFieldState): IFieldState | null; /** * Correctly calls the getDisplayValue callback * @param props Field props * @param value Field value */ private static callGetDisplayValue; /** * Calculates the new state value based on the parameters - it will return * the externalValue if it exists and has changes, or the default value * otherwise. If no state update is needed it will return undefined. Meta * changes will trigger a state change as well. * @param defaultValue Default value * @param externalValue External value * @param changes Changes object */ private static getPropValue; /** * Detects changes in the defaultValue, the externalValue and in * context.disabled or context.plaintext (merged as meta prop) * @param props Field props * @param state Field state * @param defaultValue Default value * @param externalValue External value */ private static getPropChanges; /** * Returns the local value if existing, otherwise tries to * extract the correct context value based on the fullName. * @param localValue Local value * @param contextValue Context value * @param fullName Field.fullName */ private static getLocalOverridenValue; /** * Returns either the Field.value or the correct value from * Form.values * @param props Field props */ private static getExternalValue; /** * Returns either the Field.defaultValue or the correct default value * from Form.defaultValues * @param props Field props */ private static getDefaultValue; /** * Returns a meta object for the value lifecycle hooks * @param context Form context * @param overrideDisabled Disabled prop from field * @param overridePlaintext Plaintext prop from field */ private static getValueMeta; /** * Unregisters the field from the form */ componentWillUnmount(): void; /** * Returns the current field value */ private getValue; private getSubmitValue; /** * Returns the correct asyncValidateOnChange setting, * where the field setting takes priorty over the * form setting */ private getAsyncValidateOnChangeSetting; /** * Checks if the Field is inside a valid form context * and throws an user friendly error if not */ private checkFormContext; /** * Resets the field to its default state */ private reset; /** * Validates the field * @param args Validation arguments */ private validate; /** * Handles the change event of an input field - * triggers any validation if needed and updates * the field state accordingly. * @param event Event object */ private handleFieldChanged; /** * Handles the blur event of an input field - * triggers any validation if needed and updates * the field state accordingly. */ private handleFieldBlurred; /** * Creates the properties that can be directly * mapped to the input component (e.g. html input) */ private createFieldProps; /** * Creates the meta properties with meta information * used by the input component */ private createMetaProps; render(): JSX.Element; } export declare const Field: React.ComponentType<Pick<IFieldProps, "render" | "name" | "label" | "defaultValue" | "value" | "asyncValidateOnChange" | "getDisplayValue" | "getSubmitValue" | "disabled" | "plaintext" | "onBlur" | "onChange"> & import("../../withValidation").IValidatedComponentProps>; export {};