Generateurv2/frontend/components/Input.jsx

45 lines
1.2 KiB
React
Raw Normal View History

2022-06-11 23:39:03 +02:00
import styles from '../styles/input.module.scss';
import { parseClassName } from '../utils/utils.js';
2022-06-24 13:42:16 +02:00
import {AiFillEye, AiFillEyeInvisible} from 'react-icons/ai'
import { useState } from 'react';
2022-06-11 23:39:03 +02:00
export default function Input(props) {
const id = Math.random()
2022-06-24 13:42:16 +02:00
const [type, setType] = useState(props.type ||'text')
2022-06-11 23:39:03 +02:00
return (
2022-06-24 13:42:16 +02:00
<span
className={parseClassName([
styles["input-container"],
props.error ? styles["error"] : undefined,
])}
>
<input
{...props}
id={`input_${id}`}
className={styles.input}
required
placeholder=""
type={type}
/>
{props.type == "password" &&
(type != "password" ? (
<AiFillEye
onClick={() => {
setType("password");
}}
className={styles["password-toggler"]}
/>
) : (
<AiFillEyeInvisible
onClick={() => {
setType("text");
}}
className={styles["password-toggler"]}
/>
))}
2022-06-11 23:39:03 +02:00
<label className={styles.label} htmlFor={`input_${id}`}>
{props.placeholder}
</label>
<span className={styles.bar}></span>
</span>
);
}