import * as React from "react"; import {observer} from "mobx-react/index"; import {DesignerHost} from '../../DesignerHost'; import CommandModel from '../ui-model/CommandModel'; interface CommondBarItemProps { model : { type: string, title: string, name: string, onclick: Function } } @observer class CommondBarItem extends React.Component { private _commondModel:CommandModel; constructor(props:CommondBarItemProps, context:any) { super(props, context); this._commondModel = DesignerHost.instance().uiModel.commandModel; this.onClick = this.onClick.bind(this); } render():JSX.Element { const {type, title, name} = this.props.model; const commondBarUseable = this._commondModel.useable; const useable = commondBarUseable && this._commondModel.getItemStatus(name); const mode = this._commondModel.mode; if (type==='button') { const className = 'rd-commandbar-item'+(useable?'':' rd-commandbar-item-disable'); return (
{ mode.indexOf('icon')>-1 && () } { mode.indexOf('text')>-1 && title}
) } else { return (
{title}
) } } onClick() { const commondBarUseable = this._commondModel.useable; const useable = this._commondModel.getItemStatus(this.props.model.name); const clickFn = this.props.model.onclick; commondBarUseable && useable && clickFn && clickFn(); } } export default CommondBarItem;