/** @jsx jsx */ import { css, jsx } from "@emotion/core"; // import { css, cx } from "emotion"; import * as React from "react"; import Select, { components } from "react-select"; import { IconAtom, TextAtom } from "../../atoms"; // import * as angleDown from './angle-down.png'; // import * as angleDownGray from './angle-down-gray.png'; // @ts-ignore import COLORS from "../../constants/colors"; const DropdownIndicator = (props: any) => components.DropdownIndicator && ( {/* */} {/* */} ); class SelectOrganism extends React.Component { public state = { isFocus: false, isActive: !!this.props.value, }; public selectRef: any; public onFocus = () => { this.setState({ isFocus: true }); if (this.selectRef) { this.selectRef.focus(); } } public onBlur = () => { this.setState({ isFocus: false }); } public handleChange = (e: any) => { this.props.onChange(e.value || null); this.setState({ isActive: true }); } public render() { const { isFocus, isActive } = this.state; const { value, options, error, name, placeholder, label, icon, className, disabled, required, } = this.props; return ( {icon && ( )} {required && (isFocus || isActive) ? label : !required ? label : `* ${label}`} { this.selectRef = ref; }} components={{ DropdownIndicator }} placeholder={placeholder} options={options} value={options.filter((opt: any) => opt.value === value)[0]} name={name} onChange={this.handleChange} onBlur={this.onBlur} onFocus={this.onFocus} className="dropdown-selector" styles={{ control: () => ({ borderColor: "transparent", borderRadius: 4, borderStyle: "solid", borderWidth: 1, // boxShadow: null, boxSizing: "border-box", cursor: "default", display: "flex", flexWrap: "wrap", justifyContent: "space-between", minHeight: 38, outline: "0 !important", position: "relative", transition: "all 100ms", marginTop: (isFocus || isActive) ? "-5.5px" : "0px", }), indicatorSeparator: (base: any) => ({ ...base, display: "none", }), container: (base: any) => ({ ...base, marginTop: (isFocus || isActive) ? -15 : -18, }), valueContainer: (base: any) => ({ ...base, border: 0, padding: "10px 0", visibility: (isFocus || isActive) ? "visible" : "hidden", paddingLeft: 5, }), singleValue: (base: any) => ({ ...base, }), option: (base: any) => ({ ...base, padding: "10px 20px", borderBottom: "1px solid #F5F7FA", }), }} /> {error && ( )} {error && ( {error} )} ); } } // SelectOrganism.propTypes = { // className: PropTypes.string, // icon: PropTypes.string, // placeholder: PropTypes.string, // label: PropTypes.string, // value: PropTypes.oneOfType([ // PropTypes.shape({ // value: PropTypes.string, // label: PropTypes.string, // }), // PropTypes.any, // ]), // onChange: PropTypes.func.isRequired, // error: PropTypes.string, // // type: PropTypes.string, // disabled: PropTypes.bool, // }; export { SelectOrganism };