From a6ff5eee45215effb3344cb5d631a27a7c0369aa Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Fri, 22 Sep 2023 19:34:01 +0200 Subject: refactor(components): rewrite form components --- src/components/atoms/forms/fields/input/input.tsx | 72 +++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/components/atoms/forms/fields/input/input.tsx (limited to 'src/components/atoms/forms/fields/input/input.tsx') diff --git a/src/components/atoms/forms/fields/input/input.tsx b/src/components/atoms/forms/fields/input/input.tsx new file mode 100644 index 0000000..0f0736c --- /dev/null +++ b/src/components/atoms/forms/fields/input/input.tsx @@ -0,0 +1,72 @@ +import { + type ForwardedRef, + forwardRef, + type InputHTMLAttributes, + type HTMLInputTypeAttribute, +} from 'react'; +import styles from '../fields.module.scss'; + +export type InputProps = Omit< + InputHTMLAttributes, + 'disabled' | 'hidden' | 'readonly' | 'required' | 'type' +> & + Required, 'id' | 'name'>> & { + /** + * Should the field be disabled? + * + * @default false + */ + isDisabled?: boolean; + /** + * Should the field be hidden? + * + * @default false + */ + isHidden?: boolean; + /** + * Should the field be readonly? + * + * @default false + */ + isReadOnly?: boolean; + /** + * Should the field be required? + * + * @default false + */ + isRequired?: boolean; + /** + * The input type. + */ + type: Exclude; + }; + +const InputWithRef = ( + { + className = '', + isDisabled = false, + isHidden = false, + isReadOnly = false, + isRequired = false, + ...props + }: InputProps, + ref: ForwardedRef +) => { + const fieldClassName = `${styles.field} ${className}`; + + return ( + + ); +}; + +/** + * Input component. + */ +export const Input = forwardRef(InputWithRef); -- cgit v1.2.3