1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { FloatCommandInputParameter, isRequiredInput } from '~/models/workflow';
7 import { Field } from 'redux-form';
8 import { isNumber } from '~/validators/is-number';
9 import { GenericInput } from '~/views/run-process-panel/inputs/generic-input';
10 import { Input as MaterialInput } from '@material-ui/core';
11 import { GenericInputProps } from './generic-input';
12 export interface FloatInputProps {
13 input: FloatCommandInputParameter;
15 export const FloatInput = ({ input }: FloatInputProps) =>
19 component={FloatInputComponent}
21 format={value => isNaN(value) ? '' : JSON.stringify(value)}
23 isRequiredInput(input)
25 : () => undefined,]} />;
27 class FloatInputComponent extends React.Component<GenericInputProps> {
29 endsWithDecimalSeparator: false,
32 handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
33 const [base, fraction] = event.target.value.split('.');
34 this.setState({ endsWithDecimalSeparator: fraction === '' });
35 this.props.input.onChange(event);
43 value: this.props.input.value + (this.state.endsWithDecimalSeparator ? '.' : ''),
44 onChange: this.handleChange,
53 const Input = (props: GenericInputProps) =>
54 <MaterialInput fullWidth {...props.input} />;