/** * Created by W.X. on 2016/11/18. */ import * as React from "react"; import {observer} from "mobx-react/index"; import {autobind} from "core-decorators"; import {Unit} from "../../../../drawing/Unit"; import Editor from "../Editor"; import {Padding} from "../../../../items/properties/classes/Padding"; import {SpinnerComponent} from "../_components/SpinnerComponent"; import {BoxProperty} from "../../../../items/properties/define"; @observer export class PaddingEditor extends Editor { getValue(){ const {items} = this.props; const paddings: Array = items.map(item => item.getPropertyValue(this.props.property)); const calPadding = paddings[0].clone(); const directIterators = ['left', 'top', 'right', 'bottom']; if(paddings.length > 1){ for(let padding of paddings){ for(let direct of directIterators){ if(padding[direct].toPixel() !== calPadding[direct].toPixel()){ calPadding[direct] = Unit.pixel(0); } } } } return calPadding; } renderValueEditor() { const padding: Padding = this.getValue(); return (
上
右
下
左
); } @autobind onChangeTop(value: Unit) { this.changeValue('top', value); } @autobind onChangeRight(value: Unit) { this.changeValue('right', value); } @autobind onChangeBottom(value: Unit) { this.changeValue('bottom', value); } @autobind onChangeLeft(value: Unit) { this.changeValue('left', value); } changeValue(type: string, value: Unit){ const padding: Padding = this.getValue(); const newPadding = padding ? padding.clone() : new Padding(); newPadding[type] = value; this.setValue(newPadding); } }