2019-08-23 12:35:17 -04:00
|
|
|
import React, { Fragment } from 'react';
|
|
|
|
|
2019-10-17 08:15:48 -04:00
|
|
|
import { BaseDataEntryProps } from './data-entry';
|
2019-11-07 02:39:26 -05:00
|
|
|
import { DataTitleCopyable } from './data-title';
|
2019-08-23 12:35:17 -04:00
|
|
|
|
2019-10-16 16:13:50 -04:00
|
|
|
|
2019-10-17 08:15:48 -04:00
|
|
|
interface NumericDataEntryProps extends BaseDataEntryProps {
|
2019-10-16 16:13:50 -04:00
|
|
|
value?: number;
|
|
|
|
placeholder?: string;
|
|
|
|
step?: number;
|
|
|
|
min?: number;
|
|
|
|
max?: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
const NumericDataEntry: React.FunctionComponent<NumericDataEntryProps> = (props) => {
|
2021-03-11 14:06:25 -05:00
|
|
|
const slugWithModifier = props.slug + (props.slugModifier ?? '');
|
|
|
|
|
2019-08-23 12:35:17 -04:00
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<DataTitleCopyable
|
|
|
|
slug={props.slug}
|
2021-03-11 14:06:25 -05:00
|
|
|
slugModifier={props.slugModifier}
|
2019-08-23 12:35:17 -04:00
|
|
|
title={props.title}
|
|
|
|
tooltip={props.tooltip}
|
2019-11-22 14:30:03 -05:00
|
|
|
disabled={props.disabled || props.value == undefined}
|
2019-08-23 12:35:17 -04:00
|
|
|
copy={props.copy}
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
className="form-control"
|
|
|
|
type="number"
|
2021-03-11 14:06:25 -05:00
|
|
|
id={slugWithModifier}
|
|
|
|
name={slugWithModifier}
|
2019-11-22 11:03:36 -05:00
|
|
|
value={props.value == undefined ? '' : props.value}
|
|
|
|
step={props.step == undefined ? 1 : props.step}
|
2019-08-23 12:35:17 -04:00
|
|
|
max={props.max}
|
2019-11-22 11:03:36 -05:00
|
|
|
min={props.min}
|
2019-08-23 12:35:17 -04:00
|
|
|
disabled={props.mode === 'view' || props.disabled}
|
|
|
|
placeholder={props.placeholder}
|
2021-03-11 14:00:49 -05:00
|
|
|
required={props.required}
|
2020-08-04 10:54:49 -04:00
|
|
|
onChange={e =>
|
2019-10-16 16:13:50 -04:00
|
|
|
props.onChange(
|
|
|
|
props.slug,
|
|
|
|
e.target.value === '' ? null : parseFloat(e.target.value)
|
|
|
|
)
|
|
|
|
}
|
2019-08-23 12:35:17 -04:00
|
|
|
/>
|
|
|
|
</Fragment>
|
|
|
|
);
|
2019-11-07 03:13:30 -05:00
|
|
|
};
|
2019-08-23 12:35:17 -04:00
|
|
|
|
|
|
|
export default NumericDataEntry;
|