diff options
| author | Armand Philippot <git@armandphilippot.com> | 2021-12-20 19:06:49 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2021-12-20 19:06:49 +0100 |
| commit | 43cdb7607d9423109758334155acfe844eab6ea5 (patch) | |
| tree | 0798fbb6f00bfbdbc3bd64759ffdb305dee43f0c /src/components/Form | |
| parent | f9df5cbce7db38ce83cc8b40346c9cabde5debc4 (diff) | |
chore: define search form visibility
Diffstat (limited to 'src/components/Form')
| -rw-r--r-- | src/components/Form/Form.module.scss | 5 | ||||
| -rw-r--r-- | src/components/Form/Form.tsx | 9 | ||||
| -rw-r--r-- | src/components/Form/Input/Input.tsx | 44 |
3 files changed, 37 insertions, 21 deletions
diff --git a/src/components/Form/Form.module.scss b/src/components/Form/Form.module.scss index f23dfde..891db19 100644 --- a/src/components/Form/Form.module.scss +++ b/src/components/Form/Form.module.scss @@ -2,6 +2,11 @@ .wrapper { width: 100%; + + &--search { + display: flex; + flex-flow: row nowrap; + } } .item { diff --git a/src/components/Form/Form.tsx b/src/components/Form/Form.tsx index 5e26e81..dd1bc63 100644 --- a/src/components/Form/Form.tsx +++ b/src/components/Form/Form.tsx @@ -4,12 +4,19 @@ import styles from './Form.module.scss'; const Form = ({ children, submitHandler, + modifier = '', }: { children: ReactNode; submitHandler: any; + modifier?: string; }) => { + const classes = + modifier !== '' + ? `${styles.wrapper} ${styles[`wrapper--${modifier}`]}` + : styles.wrapper; + return ( - <form onSubmit={submitHandler} className={styles.wrapper}> + <form onSubmit={submitHandler} className={classes}> {children} </form> ); diff --git a/src/components/Form/Input/Input.tsx b/src/components/Form/Input/Input.tsx index 901b9ab..2ee214b 100644 --- a/src/components/Form/Input/Input.tsx +++ b/src/components/Form/Input/Input.tsx @@ -1,25 +1,28 @@ -import { ChangeEvent, SetStateAction } from 'react'; +import { ChangeEvent, ForwardedRef, forwardRef, SetStateAction } from 'react'; import styles from '../Form.module.scss'; -type InputType = 'text' | 'number'; +type InputType = 'text' | 'number' | 'search'; -const Input = ({ - id, - name, - value, - setValue, - type = 'text', - required = false, - label, -}: { - id: string; - name: string; - value: string; - setValue: (value: SetStateAction<string>) => void; - type?: InputType; - required?: boolean; - label?: string; -}) => { +const Input = ( + { + id, + name, + value, + setValue, + type = 'text', + required = false, + label, + }: { + id: string; + name: string; + value: string; + setValue: (value: SetStateAction<string>) => void; + type?: InputType; + required?: boolean; + label?: string; + }, + ref: ForwardedRef<HTMLInputElement> +) => { const updateValue = (e: ChangeEvent<HTMLInputElement>) => { setValue(e.target.value); }; @@ -33,6 +36,7 @@ const Input = ({ </label> )} <input + ref={ref} type={type} id={id} name={name} @@ -44,4 +48,4 @@ const Input = ({ ); }; -export default Input; +export default forwardRef(Input); |
