1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-26 23:14:19 +00:00
pds-2021-g2-nest/code/frontend/src/components/InputWithIcon.js

38 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-04-21 01:57:18 +00:00
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>
)
}