1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-23 05:24:18 +00:00
pds-2021-g2-nest/code/frontend/src/components/InputWithIcon.js
2021-04-21 03:57:18 +02:00

37 lines
1.2 KiB
JavaScript

import React, {useState} from "react"
import Style from "./InputWithIcon.module.css"
import classNames from "classnames"
import make_icon from "../utils/make_icon"
export default function InputWithIcon({ icon, className, style, onFocus, onBlur, ...props }) {
const [isFocused, setFocused] = useState(false);
return (
<div className={classNames(Style.InputWithIcon, isFocused ? Style.Focused : null, className)} style={style}>
<div className={classNames(Style.IconPart)}>
{make_icon(icon)}
</div>
<input
className={classNames(Style.InputPart)}
onFocus={
event => {
setFocused(true)
if(onFocus) {
onFocus(event)
}
}
}
onBlur={
event => {
setFocused(false)
if(onBlur) {
onBlur(event)
}
}
}
{...props}
/>
</div>
)
}