import * as React from 'react'; // import {isString} from 'lodash'; import * as uuidv4 from 'uuid/v4' // import RenderHtml from '../renderFunction'; import PropsTypes from './types'; import Icon from '../Icon' import Button from '../Button' // import classNames from "classnames"; interface State { uuid: string, active: boolean, activeElement: string | null, text: string | null } export default class Index extends React.Component { private button = React.createRef(); constructor(props: PropsTypes, public state: State ) { super(props); this.state = { uuid: uuidv4(), active: false, activeElement: null, text:null } } componentDidMount() { document.addEventListener("mousedown", this.handleClickOutside, false); } componentWillUnmount() { document.removeEventListener("mousedown", this.handleClickOutside, false); } handleClickOutside = (event:any) => { const inp = this.button.current && this.button.current['contains'] && this.button.current['contains'](event.target); if (inp) { this.setState({ activeElement: this.state.uuid }) } if (!inp) { this.setState({ active: !this.state.active, activeElement: null }) } }; handleClick = () => { const {disabled} = this.props; if (disabled) { return } this.props.onClick && this.props.onClick() }; buttonClick() { this.setState({ active: !this.state.active }) } ddClick(item:any) { const {displayField, prefix} = this.props; let x:string = displayField ? item[displayField] : item; x = prefix ? prefix + x : x; this.setState({ activeElement: null, active: false, text: x }, () => { this.props.onClick && this.props.onClick(item) }) } ddMenu() { const {data, displayField} = this.props; if (data && data.length) { return data.map((item:any, i:number) => { return this.ddClick(item)} > {displayField ? item[displayField] : item} }) } } renderTypeRender() { const {uuid, active, activeElement, text} = this.state; const {data, fluid} = this.props; let textObj:any = {} if (text) { textObj = { text: text } } return
{data && data.length ? : null }
} public render(): JSX.Element { return this.renderTypeRender(); } }