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 props { model : { title: string, name: string, openLabel: string, closeLabel: string, onChange: Function } } @observer class CommandSwitch extends React.Component { private _commandModel:CommandModel; constructor(props, context) { super(props, context); this._commandModel = DesignerHost.instance().uiModel.commandModel; } render():JSX.Element { const {title, openLabel, closeLabel, name} = this.props.model; const commandBarUseable = this._commandModel.useable; const status = this._commandModel.getItemStatus(name); const useable = commandBarUseable && status.useable; const className = 'rd-commandbar-switch' + (useable ? '' : ' rd-commandbar-switch-disable'); const classWarpper = 'switch-warpper ' + (status.value ? 'switch-warpper-open' : 'switch-warpper-close'); const text = title + (status.value ? openLabel : closeLabel); return (
{text}
) } @autobind onClick() { const {onChange, name} = this.props.model; const commandBarUseable = this._commandModel.useable; const useable = this._commandModel.getItemStatus(name).useable; commandBarUseable && useable && onChange && onChange(); } } export default CommandSwitch;