Neurotic Pantaloon Maker

    popup-dispatcher

    0.0.1 • Public • Published

    popup-dispatcher

    Incapsulation of mouse and time wathchers to hide popup controls or windows on web page

    Travis build status Code Climate Test Coverage Dependency Status devDependency Status

    SYNOPSIS

    class Dropdown extends React.Component {
      static defaultProps = {
        items: ['item1', 'item2', 'item3'],
      }
      constructor(props){
        super(props)
        this.state = {
          opened: false,
          current: '...'
        }
        this.disp = new PopupDispatcher
        this.disp.on('done', () => this.setState({opened:false}) )
      }
     
      handleClick = () => {
        this.setState({ opened: ! this.state.opened })
      }
     
      handleSelect = (item) => {
        this.setState({current: item}),
        this.disp.finish()
      }
     
      render() {
        if( this.state.opened ) this.disp.start()
        return (
          <div>
     
            <{...this.disp.props({})} onClick={this.handleClick}>
              <span>{this.state.current}</span>
            </a>
     
            <ul {...this.disp.props({onMouseOver:()=>console.log('we need this handler too')})}>
              { this.props.items.map( (item,i) => (
                <li onClick={()=> this.handleSelect(item)}>
                  <a href="#">{item}</a>
                </li>
              ) ) }
            </ul>
     
          </div>
        )
      }
    }

    Methods

    • start() - enable
    • stop() - disable
    • watch() - begin watch timer, called from onMouseOut() returned by props()
    • unwatch() - cancel watch timer, called from onMouseOver() returned by props()
    • props() - props filter for component to watch

    Keywords

    none

    Install

    npm i popup-dispatcher

    DownloadsWeekly Downloads

    1

    Version

    0.0.1

    License

    MIT

    Last publish

    Collaborators

    • oklas