import * as React from "react"; import {observer} from "mobx-react/index"; import {DesignerHost} from '../../DesignerHost'; import CommandModel from '../ui-model/CommandModel'; interface props { model : { title: string, name: string, items: Array, onChange: Function } } @observer class CommandButtonGroup extends React.Component { private _commandModel:CommandModel; constructor(props, context) { super(props, context); this._commandModel = DesignerHost.instance().uiModel.commandModel; } render():JSX.Element { const {title, name, items} = this.props.model; const commandBarUseable = this._commandModel.useable; const status = this._commandModel.getItemStatus(name); const useable = commandBarUseable && status.useable; const currentValue = status.value; const renderItems = items.map((item, index) => { let className = 'group-item ' + name + '-' + item.title; if (currentValue === item.value) { className = className + ' group-item-selected'; } return (
); }); const className = 'rd-commandbar-button-group'+(useable?'':' rd-commandbar-button-group-disable'); return (
{title}
{renderItems}
) } onClick(value) { const commandBarUseable = this._commandModel.useable; const useable = this._commandModel.getItemStatus(this.props.model.name).useable; const {onChange} = this.props.model; commandBarUseable && useable && onChange && onChange(value); } } export default CommandButtonGroup;