import { i18nTranslation, ValidationSchema, YupInstance } from './helpers'; /** * A minimal FC (Functional Component) type. * This avoids importing React while still allowing you to type component props. */ type FC
= (props: P) => any;
interface CommonFieldConfig {
/**
* used to override input grid size (12 columns), default is 12
* 6 is half, in smaller screens it will force to 12
*/
flex?: number;
/**
* The order of the field in the form.
* If not specified, the order will be determined by the order of the fields in the object.
*/
order?: number;
/**
* Whether to show the field or not.
*/
hide?: boolean;
/**
* Whether to autofocus on first appear
* make sure you have only one field with this prop
*/
autoFocus?: boolean;
}
/**
* Config for a custom field.
*/
interface BaseCustomFieldConfig extends CommonFieldConfig {
type: 'custom';
initialValue?: any;
validationSchema?: ValidationSchema;
}
/**
* Config for a custom input field.
*/
interface InputCustomFieldConfig extends BaseCustomFieldConfig {
fieldType: 'input';
initialValue?: string;
fieldProps?: {
/**
* The label to be displayed before the input.
*/
label?: string;
/**
* The placeholder to be displayed inside the input.
*/
placeholder?: string;
/**
* The tooltip to be displayed on hover '?'.
*/
tip?: string;
/**
* Whether to show the required '*' sign or not.
*/
addRequiredAsterisk?: boolean;
/**
* The data test id to be injected to the input element.
*/
'data-test-id'?: string;
/**
* the autocomplete attribute for the input
*/
autoComplete?: string;
/**
* if true, the input will be multiline
*/
multiline?: boolean;
/**
* the html input type default: text
*/
type?: string;
};
}
/**
* Config for a custom select field.
*/
interface SelectCustomFieldConfig extends BaseCustomFieldConfig {
fieldType: 'select';
fieldProps?: {
/**
* The label to be displayed before the select.
*/
label?: string;
/**
* The tooltip to be displayed on hover '?'.
*/
tip?: string;
/**
* The data test id to be injected to the select element.
*/
'data-test-id'?: string;
/**
* If true, you can select multiple options
*/
multi?: boolean;
/**
* The options to be displayed in the select.
*/
options: {
label: string;
value: string | number;
}[];
/**
* If true, will show a clear button to clear the selected value.
*/
clearable?: boolean;
/**
* If true, the select popup will close when an option is selected.
*/
closeOnSelect?: boolean;
};
}
/**
* Config for a custom select field.
*/
interface DisclaimerCustomFieldConfig extends BaseCustomFieldConfig {
fieldType: 'disclaimer';
fieldProps: {
name: string;
/**
* The label of the field that will be shown beside the checkbox.
*/
label: string;
};
}
export type CustomFieldConfig = InputCustomFieldConfig | SelectCustomFieldConfig | DisclaimerCustomFieldConfig;
/**
* Config for a standard field.
*/
interface StandardFieldConfig extends CommonFieldConfig {
type: 'email' | 'name' | 'firstName' | 'lastName' | 'password' | 'confirmPassword' | 'companyName' | 'disclaimer' | 'phoneNumber' | 'username';
initialValue?: any;
Component?: FC