import Typography, { ITypo, ITypoColor } from "@Front/Components/DesignSystem/Typography"; import { ReactNode } from "react"; import Validators from "../../Validators/Validators"; import BaseField, { IProps as IBaseFieldProps } from "../BaseField"; import classes from "./classes.module.scss"; export type IProps = IBaseFieldProps & { fakeplaceholder: string; textarea?: boolean; }; // @ts-ignore TODO: typing error on IProps (validator class?? cf Massi 22/02/23) export default class InputField extends BaseField { static override defaultProps: Partial = { ...BaseField.defaultProps, required: true, }; public override render(): ReactNode { let pattern; if (this.props.type === "number") { pattern = "(^[0-9]*)(\\.{0,1})([0-9]*)$"; } if (this.props.pattern) { pattern = this.props.pattern; } if (this.props.fieldRef) { this.fieldRef = this.props.fieldRef; } // we always need to control the input so we need to set the value as "" by default const value = this.state.value ?? ""; if (this.props.textarea === true) { return (
{this.props.fakeplaceholder} {!this.props.required && " (Facultatif)"}
); } else { return (
0} className={ this.props.className ? [classes["input"], classes[this.props.className]].join(" ") : classes["input"] } value={value} />
{this.props.fakeplaceholder} {!this.props.required && " (Facultatif)"}
); } } public override componentDidMount() { this.setState({ value: this.props.defaultValue ?? "", }); } // We filter the props we'll pass to the primitive input as they're useless for it // It also avoids the console warning because of passing useless props to a primitive DOM element private getHtmlAttributes() { const htmlAttributes = { ...this.props }; delete htmlAttributes.disableValidation; delete htmlAttributes.onErrors; delete htmlAttributes.fieldRef; delete htmlAttributes.className; delete htmlAttributes.defaultValue; for (const validator in Validators) { delete (htmlAttributes as { [key: string]: any })[validator]; } return htmlAttributes; } }