UNPKG

@kiwicom/smart-faq

Version:

Smart FAQ

66 lines (56 loc) 1.36 kB
// @flow import * as React from 'react'; import HelpTooltip from './HelpTooltip'; import type { Props as HelpTooptipProps } from './HelpTooltip'; type Props = HelpTooptipProps & { disabled: boolean, iconName: string, tracker?: () => void, }; type State = { opened: boolean, }; export default class HoverHelpTooltip extends React.PureComponent< Props, State, > { static defaultProps = { ...HelpTooltip.defaultProps, iconName: 'md-info-outline', disabled: false, }; state: State = { opened: false, }; show = () => { if (!this.props.disabled) { this.setState({ opened: true }); } this.props.tracker && this.props.tracker(); }; hide = () => { if (!this.props.disabled) { this.setState({ opened: false }); } }; render() { const { disabled, iconName, children, ...helpTooptipProps } = this.props; return ( <HelpTooltip {...helpTooptipProps} open={!disabled && this.state.opened}> <div onTouchStart={this.show} onTouchEnd={this.hide} onMouseEnter={this.show} onMouseLeave={this.hide} style={{ display: 'flex', alignItems: 'center' }} > {children || ( <div> <i className={iconName} /> </div> )} </div> </HelpTooltip> ); } }