/** * Created by W.X. on 2016/11/18. */ import * as React from "react"; import {action} from "mobx/lib/mobx"; import {observer} from "mobx-react/index"; import {autobind} from "core-decorators"; import {Unit} from "../../../../drawing/Unit"; import Editor from "../Editor"; import {TextProperty} from "../../../../items/properties/define"; import {HorizontalTextAlignEnum, VerticalTextAlignEnum} from "../../../../configs/enums"; @observer export class AlignEditor extends Editor { private _mergeHAlignNull: boolean = false; private _mergeVAlignNull: boolean = false; getValue() { const {items} = this.props; const firstItem = items[0]; const value = { hAlign: firstItem.getPropertyValue(TextProperty.hAlign), vAlign: firstItem.getPropertyValue(TextProperty.vAlign), }; this._mergeHAlignNull = false; this._mergeVAlignNull = false; items.map((item) => { if(item.getPropertyValue(TextProperty.hAlign) !== value.hAlign){ this._mergeHAlignNull = true; } if(item.getPropertyValue(TextProperty.vAlign) !== value.vAlign){ this._mergeVAlignNull = true; } }); return { hAlign: this._mergeHAlignNull ? null : value.hAlign, vAlign: this._mergeVAlignNull ? null : value.vAlign } } renderValueEditor() { const value = this.getValue(); return (
水平
{this._renderAlignItem('horizontal', value)}
垂直
{this._renderAlignItem('vertical', value)}
); } _renderAlignItem(type:string, alginValue:any){ const options = []; const item = this.props.items[0]; // const {horizontal, vertical} = this.props.property.enumValue; const classMap = new Map(); let value; if(type === 'horizontal'){ value = alginValue.hAlign; //定义每个选项对应的class classMap.set(HorizontalTextAlignEnum.Left, "align-horizontal-left"); classMap.set(HorizontalTextAlignEnum.Center, "align-horizontal-center"); classMap.set(HorizontalTextAlignEnum.Right, "align-horizontal-right"); } else{ value = alginValue.vAlign; classMap.set(VerticalTextAlignEnum.Top, "align-vertical-top"); classMap.set(VerticalTextAlignEnum.Middle, "align-vertical-middle"); classMap.set(VerticalTextAlignEnum.Bottom, "align-vertical-bottom"); } //设置当前值的选中 if(classMap.get(value)){ classMap.set(value, classMap.get(value) + ' align-item-selected'); } classMap.forEach((className, enumValue) => { const index = options.length; options.push(
); }); return options; } @autobind @action onClick(type, value) { const {items} = this.props; const property = TextProperty[type === 'horizontal' ? 'hAlign' : 'vAlign']; items.map((item) => { item.setPropertyValue(property, value); }); } }