import { CX } from '../constants' import Icon from './icon' import Image from './image' import Text from './text' export default class FileInput extends PureComponent { static propTypes = { onChange: PropTypes.func, file: PropTypes.any, fileType: PropTypes.string, disabled: PropTypes.bool, title: PropTypes.string, id: PropTypes.string.isRequired, height: PropTypes.string, width: PropTypes.string, isBordered: PropTypes.bool, className: PropTypes.string, } static defaultProps = { fileType: 'image', isBordered: false, } state = { file: this.props.file, hovering: false, } handleOnChange = (e) => { this.props.onChange(e) this.setState({ file: URL.createObjectURL(e.target.files[0]) }) } handleMouseLeave = () => { this.setState({ hovering: false }) } handleMouseEnter = () => { this.setState({ hovering: true }) } render() { const { id, fileType, disabled, title, height, width, className, isBordered, } = this.props const { file, hovering } = this.state const containerClasses = CX(className, { default: 1, alignItemsCenter: 1, cursorPointer: 1, justifyContentCenter: 1, overflowHidden: true, radiusSmall: isBordered, px10: isBordered, py10: isBordered, border2PX: isBordered, borderColorSecondary: isBordered, borderDashed: isBordered, }) const iconClasses = CX({ fillSecondary: !hovering, fillWhite: hovering, }) return (
{ !!title &&
{title}
}
) } }