UNPKG

@timmons-group/config-form

Version:

React Components and helpers to build a form via configuration with react-hook-form and MUI

189 lines (188 loc) 9.58 kB
/** * Create a yup schema for a string field * @param {string} label * @param {boolean} [isRequired] * @param {string} [reqMessage] * @returns {YupSchema} - yup schema for the field */ export function yupString(label: string, isRequired?: boolean, reqMessage?: string): YupSchema; /** * Create a yup schema for a date field * @param {string} label - label for the field * @param {boolean} [isRequired] - is the field required * @param {string} [msg] - message to display if the field is not a valid date * @param {string} [reqMessage] - message to display if the field is required * @returns {YupSchema} - yup schema for a date field */ export function yupDate(label: string, isRequired?: boolean, msg?: string, reqMessage?: string): YupSchema; /** * Test the value to see if it is a valid date * @param {string} value * @returns {boolean} - true if the value is a valid date */ export function validDateFormat(value: string): boolean; /** * Covert multiselect form input into an api ready array * @param {Array<object>} [selections] - array of selected items * @returns {Array<{id: number}>} - array of selected items with id */ export function multiToPayload(selections?: Array<object>): Array<{ id: number; }>; /** * Create a yup schema for a typeahead field * @param {string} label - label for the field * @param {boolean} [isRequired] - is the field required * @param {string} [reqMessage] - message to display if the field is required * @returns {YupSchema} - yup schema for the field */ export function yupTypeAhead(label: string, isRequired?: boolean, reqMessage?: string): YupSchema; /** * Create a yup schema for a string field that ensures the value is trimmed * @param {string} label - label for the field * @param {boolean} [isRequired] - is the field required * @param {string} [trimMsg] - message to display if the field is not trimmed * @param {string} [reqMessage] - message to display if the field is required * @returns {YupSchema} - yup schema for the field */ export function yupTrimString(label: string, isRequired?: boolean, trimMsg?: string, reqMessage?: string, moreThings: any): YupSchema; /** * Create a yup schema for an integer field that checks max/min length * @param {string} label - label for the field * @param {boolean} [isRequired] - is the field required * @param {number} [maxLength] - max length of the field * @param {string} [msg] - message to display if the field is not an integer * @param {string} [reqMessage] - message to display if the field is required * @param {number} [minLength] - min length of the field * @param {number} [minValue] - min value of the field * @param {number} [maxValue] - max value of the field * @param {object} [options] - additional options for the field * @returns {YupSchema} */ export function yupInt(label: string, isRequired?: boolean, maxLength?: number, msg?: string, reqMessage?: string, minLength?: number, minValue?: number, maxValue?: number, options?: object): YupSchema; /** * Create a yup schema for a float field that checks max/min length * @param {string} label - label for the field * @param {boolean} [isRequired] - is the field required * @param {number} [int] - max number of integers * @param {number} [frac] - max number of decimals * @param {number} [maxLength] - max length of the field * @param {string} [msg] - message to display if the field is not in the correct format * @param {string} [maxValue] - max value of the field * @param {string} [reqMessage] - message to display if the field is required * @param {number} [minLength] - min length of the field * @param {number} [minValue] - min value of the field * @param {object} [options] - additional options for the field * @returns {YupSchema} */ export function yupFloat(label: string, isRequired?: boolean, int?: number, frac?: number, maxLength?: number, msg?: string, maxValue?: string, reqMessage?: string, minLength?: number, minValue?: number, options?: object): YupSchema; /** * Create a yup schema for a currency field that checks max/min length * @param {string} label - label for the field * @param {boolean} [isRequired] - is the field required * @param {number} [maxLength] - max length of the field * @param {string} [msg] - message to display if the field is not formatted correctly * @param {string} [reqMessage] - message to display if the field is required * @param {number} [minLength] - min length of the field * @returns {YupSchema} - yup schema for a currency field */ export function yupCurrency(label: string, isRequired?: boolean, maxLength?: number, msg?: string, reqMessage?: string, minLength?: number, maxValue: any, minValue: any): YupSchema; /** * Trim a string and check max/min and remove any leading or trailing spaces * @param {string} label - label for the field * @param {boolean} isRequired - is the field required * @param {number} maxLength - max length of the field * @param {string} msg - message to display if the field is not formatted correctly * @param {string} reqMessage - message to display if the field is required * @param {number} minLength - min length of the field * @param {object} moreThings - additional options for the field * @returns {YupSchema} - yup schema for a string field */ export function yupTrimStringMax(label: string, isRequired: boolean, maxLength: number, msg: string, reqMessage: string, minLength: number, moreThings: object): YupSchema; /** * Create a yup schema for a multiselect field * @param {string} label - label for the field * @param {boolean} isRequired - is the field required * @param {string} reqMessage - message to display if the field is required * @returns {YupSchema} - yup schema for a string field */ export function yupMultiselect(label: string, isRequired: boolean, reqMessage: string): YupSchema; /** * Extract the id of the selected item from the data * @param {boolean} multiple - is the field a multiselect * @param {object} inData - data to be extracted and formatted * @returns {string} - string of the id of the selected item or array of ids of selected items */ export function getSelectValue(multiple: boolean, inData: object): string; /** * Create a yup schema for a generic or custom object field * @param {string} label - label for the field * @param {boolean} isRequired - is the field required * @param {string} reqMessage - message to display if the field is required * @returns {YupSchema} - yup schema for an object field */ export function yupObject(label: string, isRequired: boolean, reqMessage: string): YupSchema; /** * Return whether or not the value is a valid currency format * @param {string} value * @returns {boolean} - true if the value is a valid currency format */ export function validCurrencyFormat(value: string): boolean; /** * Format validation for a double value * if i and f are not passed in, the default is 4 digits before and 4 digits after the decimal * if i or f are passed in and are not numbers, the default is 999999999 digits before and after the decimal * @param {number} value * @param {number} i - number of digits before decimal * @param {number} f - number of digits after decimal * @returns {boolean} - true if the value is a valid double format */ export function validDoubleFormat(value: number, i?: number, f?: number): boolean; /** * Create a yup schema for a given field type * @param {number} type * @param {string} label * @param {Map} validationMap * @param {object} field * @returns {YupSchema} - yup schema for a field */ export function createFieldValidation(type: number, label: string, validationMap: Map<any, any>, field: object): YupSchema; /** * The default choice formatter * @param {object} item * @param {object} [options] - options for the choice mapper * @param {string} [options.mappedId] - property to use when mapping the id * @param {string} [options.mappedLabel] - property to use when mapping the label * @returns {Array<object>} */ export function defaultChoiceFormatter(item: object, options?: { mappedId?: string; mappedLabel?: string; }): Array<object>; /** * The default parser for fetching choices. Assumes data is an array of objects and a property on response * @param {object} res - response from the fetch * @param {object} [options] - options for the choice mapper * @param {string} [options.mappedId] - property to use when mapping the id * @param {string} [options.mappedLabel] - property to use when mapping the label * @returns {Array<object>} */ export function defaultChoiceMapper(res: object, options?: { mappedId?: string; mappedLabel?: string; }): Array<object>; /** * @constant {Object} VALID_PATTERNS - regex patterns for validating fields * @property {RegExp} PHONE - regex pattern for validating phone numbers * @property {RegExp} EMAIL - regex pattern for validating email addresses * @property {RegExp} ZIP - regex pattern for validating zip codes */ export const VALID_PATTERNS: Readonly<{ PHONE: RegExp; EMAIL: RegExp; ZIP: RegExp; }>; export function attemptFormSubmit(formData: object, isEdit: boolean, { enqueueSnackbar, nav, onSuccess, onError, formatSubmitError, checkSuccess, unitLabel, successUrl, submitUrl, setModifying, formatSubmitMessage, suppressSuccessToast, suppressErrorToast }: SubmitOptions): Promise<void>; export function useFormSubmit(): FormSubmitOptions; export function createRowFields(fields: ParsedField[], columnCount: number, isInline: any): RowFields[]; export function checkConditional(condition: any, fieldValue: any): any;