import * as React from "react"; import {observer} from "mobx-react/index"; import {autobind} from "core-decorators"; import {DesignerHost} from '../../DesignerHost'; import CommandModel from '../ui-model/CommandModel'; interface CommandBarItemProps { model : { type: string, title: string, name: string, onClick: Function } } @observer class CommandButton extends React.Component { private _commandModel:CommandModel; constructor(props:CommandBarItemProps, context:any) { super(props, context); this._commandModel = DesignerHost.instance().uiModel.commandModel; } render():JSX.Element { const {title, name} = this.props.model; const commandBarUseable = this._commandModel.useable; const status = this._commandModel.getItemStatus(name); const useable = commandBarUseable && status.useable; const value = status.value; const mode = this._commandModel.mode; const className = 'rd-commandbar-button'+(useable ? '' : ' rd-commandbar-button-disable'); const classStatus = 'button-status' +(value === true ? ' button-used' : ''); return (
{ mode.indexOf('icon')>-1 && () } { mode.indexOf('text')>-1 &&
{title}
}
); } @autobind onClick() { const commandBarUseable = this._commandModel.useable; const status = this._commandModel.getItemStatus(this.props.model.name); const useable = status.useable; const clickFn = this.props.model.onClick; commandBarUseable && useable && clickFn && clickFn(status.value); } } export default CommandButton;