import cx from 'classnames' import React, { PureComponent, FormEvent, ChangeEvent } from 'react' import slugify from '@sindresorhus/slugify' import DatePicker from 'react-datepicker' import { ReactComponent as SearchIcon } from '../../../img/search.svg' import Help from './Help' import Label from './Label' import Row from './Row' import InputGroup from './InputGroup' import styles from './Input.module.scss' interface InputProps { name: string label: string placeholder?: string required?: boolean help?: string tag?: string type?: string options?: string[] additionalComponent?: any value?: string onChange?( event: | FormEvent | ChangeEvent | ChangeEvent | ChangeEvent ): void rows?: number group?: any multiple?: boolean } interface InputState { isFocused: boolean dateCreated?: Date } export default class Input extends PureComponent { public state: InputState = { isFocused: false, dateCreated: new Date() } public inputWrapClasses() { if (this.props.type === 'search') { return styles.inputWrapSearch } else if (this.props.type === 'search' && this.state.isFocused) { return cx(styles.inputWrapSearch, styles.isFocused) } else if (this.state.isFocused && this.props.type !== 'search') { return cx(styles.inputWrap, styles.isFocused) } else { return styles.inputWrap } } public toggleFocus = () => { this.setState({ isFocused: !this.state.isFocused }) } private handleDateChange = (date: Date) => { this.setState({ dateCreated: date }) const event = { currentTarget: { name: 'dateCreated', value: date } } this.props.onChange!(event as any) // eslint-disable-line @typescript-eslint/no-non-null-assertion } public InputComponent = () => { const { type, options, group, name, required, onChange, value } = this.props const wrapClass = this.inputWrapClasses() switch (type) { case 'select': return (
) case 'textarea': return (