colouring-montreal/app/src/frontend/building/data-components/numeric-data-entry.tsx

52 lines
1.6 KiB
TypeScript
Raw Normal View History

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-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) => {
const slugWithModifier = props.slug + (props.slugModifier ?? '');
return (
<Fragment>
<DataTitleCopyable
slug={props.slug}
slugModifier={props.slugModifier}
title={props.title}
tooltip={props.tooltip}
2019-11-22 14:30:03 -05:00
disabled={props.disabled || props.value == undefined}
copy={props.copy}
/>
<input
className="form-control"
type="number"
id={slugWithModifier}
name={slugWithModifier}
value={props.value == undefined ? '' : props.value}
step={props.step == undefined ? 1 : props.step}
max={props.max}
min={props.min}
disabled={props.mode === 'view' || props.disabled}
placeholder={props.placeholder}
required={props.required}
onChange={e =>
2019-10-16 16:13:50 -04:00
props.onChange(
props.slug,
e.target.value === '' ? null : parseFloat(e.target.value)
)
}
/>
</Fragment>
);
2019-11-07 03:13:30 -05:00
};
export default NumericDataEntry;