import * as React from "react"; import {observer} from "mobx-react/index"; import {autobind} from "core-decorators"; import Editor from "../Editor"; import {SpinnerComponent} from "../_components/SpinnerComponent"; import {Unit} from "../../../../drawing/Unit"; import TextField from "material-ui/TextField"; @observer export class UnitSpinnerEditor extends Editor<{}> { @autobind onChange(value) { this.setValue(value); } renderValueEditor() { const {readonly} = this.props; const value = this.getValue(); const formattedValue = value.toString(); if (! readonly) { return ( ); } return ( ) } /* protected _showUnit:boolean = true; state = { originValue: null, value: null, lastKeyCode: null, modify: false }; static fixedNum = { [UnitType.Pixel]: 0, [UnitType.Inch]: 2, [UnitType.Cm]: 2, [UnitType.Mm]: 1 }; componentWillMount() { this.initialize(this.props); } componentWillReceiveProps(props, context) { this.initialize(props); } initialize(props) { const unitValue = this.getValue() || Unit.Empty; this.state.originValue = unitValue; } @autobind handleChange(event:any):void { let value = event.target.value; if(value.length == 0){ value = 0.00; }else{ //如果最后一位是点, 并且只有一个点, 则在后边补全两位 if(value[value.length - 1] == '.'){ //只有一个点,第二个点不显示 if(value.indexOf('.') == value.lastIndexOf('.')){ if(this.state.lastKeyCode == 8){ value = parseFloat(value); }else{ value = parseFloat(value).toFixed(1); } }else{ return; } } } this.setState({ value: new Unit(parseFloat(value), this.state.originValue.type), modify: true }); } @autobind onBlur():void { if (this.state.modify) { this.setValue(this.state.value); this.state.modify = false; } } @autobind onKeyDown(event:any):void { const {keyCode} = event; this.state.lastKeyCode = keyCode; if (keyCode == 13) { this.onBlur(); } } @autobind onChangeUnitType(unitType):void { this.setValue(this.getValue().changeType(unitType)); this.setState({ open: false, unitType: unitType }) } @autobind addValue(){ const unitValue = this.getValue(); this.setValue(new Unit(unitValue.value + 1, unitValue.type)); } @autobind reduceValue(){ const unitValue = this.getValue(); this.setValue(new Unit(Math.max(0, unitValue.value - 1), unitValue.type)); } renderValueEditor() { const {property} = this.props; const originValue = this.getValue(); const unitValue:Unit = (this.state.modify ? this.state.value : originValue) as Unit; const value = this.state.modify ? unitValue.value : unitValue.value.toFixed(UnitSpinnerEditor.fixedNum[unitValue.type]); return (
{ this._showUnit && }
) } */ }