// Libs // Misc import { BaseInputProps, BaseInputState, BaseInput, } from '../base/input/BaseInput'; import { withFormContext } from '../form/withFormContext'; import { withThemeContext } from '../themeProvider/withThemeContext'; export interface ExternalValidationComponentProps extends BaseInputProps { isValid: boolean; } export interface ExternalValidationComponentState extends BaseInputState {} export class ExternalValidationComponentRaw extends BaseInput< ExternalValidationComponentProps, ExternalValidationComponentState, HTMLInputElement > { public static defaultProps = Object.assign({}, BaseInput.defaultProps, { isValid: true, }) as ExternalValidationComponentProps; constructor(props: ExternalValidationComponentProps) { super(props); this.state = { ...this.state, handleValueChangeEnabled: false, }; if (!this.props.ignoreContext && this.props.formContext) { this.props.formContext.updateCallback(this.componentId, { isValid: props.isValid, errors: props.errors, }); } } public componentDidUpdate( prevProps: ExternalValidationComponentProps, prevState: ExternalValidationComponentState ) { if ( this.props.isValid !== prevProps.isValid || this.props.errors !== prevProps.errors ) { if (!this.props.ignoreContext && this.props.formContext) { this.props.formContext.updateCallback(this.componentId, { isValid: this.props.isValid, errors: this.props.errors, }); } } } public render() { return null; } } export const ExternalValidationComponent = withThemeContext< ExternalValidationComponentProps, InstanceType >( withFormContext( ExternalValidationComponentRaw ), 'text' ); export default ExternalValidationComponent;