|
@@ -15,15 +15,20 @@ interface IFloatLineComponentProps {
|
|
|
step?: string,
|
|
|
digits?: number;
|
|
|
globalState: GlobalState
|
|
|
+ min?: number
|
|
|
+ max?: number
|
|
|
+ smallUI?: boolean;
|
|
|
+ onEnter?: (newValue:number) => void;
|
|
|
}
|
|
|
|
|
|
export class FloatLineComponent extends React.Component<IFloatLineComponentProps, { value: string }> {
|
|
|
private _localChange = false;
|
|
|
private _store: number;
|
|
|
+ private _smallUI: boolean;
|
|
|
|
|
|
constructor(props: IFloatLineComponentProps) {
|
|
|
super(props);
|
|
|
-
|
|
|
+ this._smallUI = props.smallUI ? props.smallUI : false;
|
|
|
let currentValue = this.props.target[this.props.propertyName];
|
|
|
this.state = { value: currentValue ? (this.props.isInteger ? currentValue.toFixed(0) : currentValue.toFixed(this.props.digits || 2)) : "0" };
|
|
|
this._store = currentValue;
|
|
@@ -77,13 +82,18 @@ export class FloatLineComponent extends React.Component<IFloatLineComponentProps
|
|
|
valueAsNumber = parseFloat(valueString);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
this._localChange = true;
|
|
|
this.setState({ value: valueString});
|
|
|
|
|
|
if (isNaN(valueAsNumber)) {
|
|
|
return;
|
|
|
}
|
|
|
+ if(this.props.max != undefined && (valueAsNumber > this.props.max)) {
|
|
|
+ valueAsNumber = this.props.max;
|
|
|
+ }
|
|
|
+ if(this.props.min != undefined && (valueAsNumber < this.props.min)) {
|
|
|
+ valueAsNumber = this.props.min;
|
|
|
+ }
|
|
|
|
|
|
this.props.target[this.props.propertyName] = valueAsNumber;
|
|
|
this.raiseOnPropertyChanged(valueAsNumber, this._store);
|
|
@@ -92,6 +102,8 @@ export class FloatLineComponent extends React.Component<IFloatLineComponentProps
|
|
|
}
|
|
|
|
|
|
render() {
|
|
|
+ let className = this._smallUI ? "short": "value";
|
|
|
+
|
|
|
return (
|
|
|
<div>
|
|
|
{
|
|
@@ -99,10 +111,21 @@ export class FloatLineComponent extends React.Component<IFloatLineComponentProps
|
|
|
<div className="label">
|
|
|
{this.props.label}
|
|
|
</div>
|
|
|
- <div className="value">
|
|
|
- <input type="number" step={this.props.step || "0.01"} className="numeric-input"
|
|
|
+ <div className={className}>
|
|
|
+ <input type="number" step={this.props.step || "0.01"} className="numeric-input"
|
|
|
onBlur={evt => {
|
|
|
this.props.globalState.blockKeyboardEvents = false;
|
|
|
+ if(this.props.onEnter) {
|
|
|
+ this.props.onEnter(this._store);
|
|
|
+ }
|
|
|
+ }}
|
|
|
+ onKeyDown={evt => {
|
|
|
+ if (evt.keyCode !== 13) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(this.props.onEnter) {
|
|
|
+ this.props.onEnter(this._store);
|
|
|
+ }
|
|
|
}}
|
|
|
onFocus={() => this.props.globalState.blockKeyboardEvents = true}
|
|
|
value={this.state.value} onChange={evt => this.updateValue(evt.target.value)} />
|