2022-11-18 01:36:53 -05:00
|
|
|
import clsx from "clsx"
|
2022-04-09 20:48:19 -04:00
|
|
|
import React from "react"
|
|
|
|
import styles from "./input.module.css"
|
2022-03-22 23:06:15 -04:00
|
|
|
|
|
|
|
type Props = React.HTMLProps<HTMLInputElement> & {
|
2022-04-09 20:48:19 -04:00
|
|
|
label?: string
|
2022-11-16 03:49:12 -05:00
|
|
|
width?: number | string
|
|
|
|
height?: number | string
|
2022-11-18 01:36:53 -05:00
|
|
|
labelClassName?: string
|
2022-03-22 23:06:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line react/display-name
|
2022-04-09 20:48:19 -04:00
|
|
|
const Input = React.forwardRef<HTMLInputElement, Props>(
|
2022-11-18 01:36:53 -05:00
|
|
|
({ label, className, width, height, labelClassName, ...props }, ref) => {
|
2022-04-09 20:48:19 -04:00
|
|
|
return (
|
2022-11-16 03:49:12 -05:00
|
|
|
<div
|
|
|
|
className={styles.wrapper}
|
|
|
|
style={{
|
|
|
|
width,
|
|
|
|
height
|
|
|
|
}}
|
|
|
|
>
|
2022-11-18 01:36:53 -05:00
|
|
|
{label && (
|
|
|
|
<label
|
|
|
|
aria-labelledby={label}
|
|
|
|
className={clsx(styles.label, labelClassName)}
|
|
|
|
>
|
|
|
|
{label}
|
|
|
|
</label>
|
|
|
|
)}
|
2022-04-09 20:48:19 -04:00
|
|
|
<input
|
|
|
|
ref={ref}
|
2022-11-18 01:36:53 -05:00
|
|
|
id={label}
|
2022-11-20 23:54:34 -05:00
|
|
|
className={clsx(styles.input, label && styles.withLabel, className)}
|
2022-04-09 20:48:19 -04:00
|
|
|
{...props}
|
2022-11-16 03:49:12 -05:00
|
|
|
style={{
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
...(props.style || {})
|
|
|
|
}}
|
2022-04-09 20:48:19 -04:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
2022-03-22 23:06:15 -04:00
|
|
|
|
|
|
|
export default Input
|