@totalsoft/rocket-ui
Version:
A set of reusable and composable React components built on top of Material UI core for developing fast and friendly web applications interfaces.
70 lines (69 loc) • 3 kB
TypeScript
import React from 'react';
import PropTypes from 'prop-types';
import { DynamicFieldProps } from './types';
/**
* The DynamicField component is used for rendering controls dynamically
* when the type (TextField, DateTime) isn't known beforehand
*
* It requires a controlType property that can be passed explicitly or dynamically
* Possible values: Text, Integer, Numeric, Date, Checkbox, Autocomplete, Custom
*
* DynamicField also takes as parameters the most common properties for all of the
* controls, such as value, onChange, disabled, options, etc, and passes them accordingly
* For Custom rendering, CustomComponent must be defined, and only the properties in
* customComponentProps will be forwarded
*/
declare function DynamicField<TCustomComponentProps extends object = any, TAutocompleteOptions = any>(props: DynamicFieldProps<TCustomComponentProps, TAutocompleteOptions>): React.JSX.Element;
declare namespace DynamicField {
var propTypes: {
/**
* The type of the control. Can either be one of the predefined below, or 'Custom', in which case CustomComponent needs to be defined
*/
controlType: PropTypes.Validator<string>;
/**
* The id of the element, passed to the corresponding id property of underlying controls
*/
id: PropTypes.Requireable<string>;
/**
* The value of the element, passed to the corresponding value property (ex. value for TextField, checked for Checkbox) of underlying controls
*/
value: PropTypes.Requireable<any>;
/**
* The label of the element, passed to the corresponding label property of the underlying control
*/
label: PropTypes.Requireable<string>;
/**
* The change handler of the element, passed to the corresponding onChange property of underlying controls
*/
onChange: PropTypes.Requireable<(...args: any[]) => any>;
/**
* Indicates whether the field has an error
*/
error: PropTypes.Requireable<boolean>;
/**
* A text or other element indicating the error message
*/
helperText: PropTypes.Requireable<string>;
/**
* Indicates whether the field is required
*/
required: PropTypes.Requireable<boolean>;
/**
* Indicates whether the field is read-only
*/
readOnly: PropTypes.Requireable<boolean>;
/**
* Indicates whether the field is disabled
*/
disabled: PropTypes.Requireable<boolean>;
/**
* Custom component for the input. Requires controlType to be set 'Custom'
*/
CustomComponent: PropTypes.Requireable<PropTypes.ReactComponentLike>;
/**
* Props that will be passed to the custom component. The CustomComponent property needs to be defined
*/
customComponentProps: PropTypes.Requireable<object>;
};
}
export default DynamicField;