/** @jsx jsx */ import { css, jsx } from "@emotion/core"; // import { css, cx } from "emotion"; import * as React from "react"; import { IconAtom, TextAtom } from "../../atoms"; // @ts-ignore import COLORS from "../../constants/colors"; class InputOrganism extends React.PureComponent { public state = { isFocus: false, isActive: !!this.props.value, }; private input: HTMLInputElement | HTMLTextAreaElement | null; public onFocus = () => { this.setState({ isFocus: true }); if (this.input) { this.input.focus(); } } public onBlur = () => { this.setState({ isFocus: false }); if (this.props.onBlur) { this.props.onBlur(); } } public onScroll = () => { if (this.input) { window.scrollTo({ top: this.input.offsetTop - 200, behavior: "smooth", }); } } public handleChange = ( e: React.ChangeEvent, ) => { this.props.onChange(e); this.setState({ isActive: !!e.target.value }); } public render() { const { isFocus, isActive } = this.state; const { value, error, name, placeholder, label, icon, className, type = "text", disabled, height, required, onKeyUp = () => {}, } = this.props; return (
{icon && ( )}
{required && (isFocus || isActive) ? label : !required ? label : `* ${label}`} {type !== "textarea" && ( { this.input = input; }} type={type} className="w-100 ph2 outline-0 bn" css={css` ::placeholder { color: ${COLORS.BLACK.LIGHT}; opacity: 1; } font-size: 0.8rem; cursor: ${disabled ? "not-allowed" : "auto"}; background: transparent; opacity: ${isFocus || isActive ? "1" : "0"}; height: ${height || "auto"}; transition: all 0.4s ease; margin-top: -0.5px; transform: translateY(${isFocus || isActive ? -2 : 0}px); @media screen and (min-width: 30em) { font-size: 1rem; margin: 0; } color: ${COLORS.BLACK.DARKER}; background: ${COLORS.WHITE.NORMAL}; `} onKeyUp={onKeyUp} name={name} value={value} placeholder={placeholder} onChange={this.handleChange} onBlur={this.onBlur} disabled={disabled} data-test={this.props["data-test"]} style={{ color: `${COLORS.BLACK.DARKER}` }} /> )} {type === "textarea" && (