/* * Copyright 2007-2017 Charles du Jeu - Abstrium SAS * This file is part of Pydio. * * Pydio is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Pydio is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Pydio. If not, see . * * The latest code can be found at . */ import Utils from './Utils' const React = require('react') const ReactDOM = require('react-dom') const {Menu} = require('material-ui') const Controller = require('pydio/model/controller') const ButtonMenu = React.createClass({ propTypes:{ buttonTitle : React.PropTypes.oneOfType([React.PropTypes.string,React.PropTypes.object]).isRequired, menuItems : React.PropTypes.array.isRequired, className : React.PropTypes.string, raised : React.PropTypes.bool, direction : React.PropTypes.oneOf(['left', 'right']) }, componentDidMount: function(){ if(this.props.openOnEvent){ this.props.pydio.observe(this.props.openOnEvent, () => { this.showMenu();}); } }, getInitialState: function(){ return {showMenu: false}; }, showMenu: function(event){ let anchor; if(event){ anchor = event.currentTarget; }else{ anchor = this._buttonDOM; } this.setState({ showMenu: true, anchor: anchor }) }, menuClicked: function(event, index, object){ //object.payload(); this.setState({showMenu: false}); }, render: function(){ let label = {this.props.buttonTitle} let button; const props = { primary: this.props.primary, secondary: this.props.secondary, disabled: this.props.disabeld, label: label, onTouchTap: this.showMenu, onClick:(e => e.stopPropagation()) }; const {menuItems} = this.props; const {showMenu, anchor} = this.state; if(menuItems.length){ if(this.props.raised){ button = {this._buttonDOM = ReactDOM.findDOMNode(b);}}/>; }else{ button = {this._buttonDOM = ReactDOM.findDOMNode(b);}}/>; } } return ( {button} {this.setState({showMenu: false})}} style={{marginTop: 1}} useLayerForClickAway={false} > {Utils.itemsToMenu(menuItems, this.menuClicked)} ); } }); import MenuItemsConsumer from './MenuItemsConsumer' export default MenuItemsConsumer(ButtonMenu)