import './ExpandableToolMenu.styl';
import { OverlayTrigger } from '../components/overlayTrigger';
import PropTypes from 'prop-types';
import React from 'react';
import ToolbarButton from './ToolbarButton.js';
import { Tooltip } from '../components/tooltip';
class ExpandableToolMenu extends React.Component {
static propTypes = {
/** Button label */
label: PropTypes.string.isRequired,
/** Array of buttons to render when expanded */
buttons: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string,
label: PropTypes.string.isRequired,
icon: PropTypes.oneOfType([
PropTypes.string,
PropTypes.shape({
name: PropTypes.string.isRequired,
}),
]),
})
).isRequired,
icon: PropTypes.oneOfType([
PropTypes.string,
PropTypes.shape({
name: PropTypes.string.isRequired,
}),
]),
onGroupMenuClick: PropTypes.func,
activeCommand: PropTypes.string,
};
static defaultProps = {
buttons: [],
icon: 'ellipse-circle',
label: 'More',
};
constructor(props) {
super(props);
this.state = {
isExpanded: false,
};
}
toolbarMenuOverlay = () => (
{this.getButtons()}
);
getButtons = () => {
return this.props.buttons.map((button, index) => {
return (
);
});
};
isActive = () => {
let isActive = false;
if (this.props.activeCommand) {
this.props.buttons.forEach(button => {
if (this.props.activeCommand === button.id) {
isActive = true;
}
});
}
return isActive;
};
activeIcon = () => {
if (this.props.activeCommand) {
return (
this.props.buttons.find(btn => this.props.activeCommand === btn.id)
.icon || this.props.icon
);
}
return this.props.icon;
};
onExpandableToolClick = () => {
if (this.props.onGroupMenuClick) {
this.props.onGroupMenuClick();
}
this.setState({
isExpanded: !this.state.isExpanded,
});
};
onOverlayHide = () => {
this.setState({
isExpanded: false,
});
};
render() {
const getToolBarButtonComponent = () => {
return (
);
};
const toolbarComponent = getToolBarButtonComponent();
return (
{toolbarComponent}
);
}
}
export default ExpandableToolMenu;