|
@@ -18,39 +18,40 @@ import { SingleStatValueOptions } from './shared';
|
|
|
const labelWidth = 6;
|
|
const labelWidth = 6;
|
|
|
|
|
|
|
|
export interface Props {
|
|
export interface Props {
|
|
|
- options: SingleStatValueOptions;
|
|
|
|
|
|
|
+ value: SingleStatValueOptions;
|
|
|
onChange: (valueOptions: SingleStatValueOptions) => void;
|
|
onChange: (valueOptions: SingleStatValueOptions) => void;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export class SingleStatValueEditor extends PureComponent<Props> {
|
|
export class SingleStatValueEditor extends PureComponent<Props> {
|
|
|
- onUnitChange = (unit: SelectOptionItem) => this.props.onChange({ ...this.props.options, unit: unit.value });
|
|
|
|
|
|
|
+ // @ts-ignore
|
|
|
|
|
+ onUnitChange = (unit: SelectOptionItem<string>) => this.props.onChange({ ...this.props.value, unit: unit.value });
|
|
|
|
|
|
|
|
onStatsChange = (stats: string[]) => {
|
|
onStatsChange = (stats: string[]) => {
|
|
|
const stat = stats[0] || StatID.mean;
|
|
const stat = stats[0] || StatID.mean;
|
|
|
- this.props.onChange({ ...this.props.options, stat });
|
|
|
|
|
|
|
+ this.props.onChange({ ...this.props.value, stat });
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
onDecimalChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
onDecimalChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
|
if (!isNaN(parseInt(event.target.value, 10))) {
|
|
if (!isNaN(parseInt(event.target.value, 10))) {
|
|
|
this.props.onChange({
|
|
this.props.onChange({
|
|
|
- ...this.props.options,
|
|
|
|
|
|
|
+ ...this.props.value,
|
|
|
decimals: parseInt(event.target.value, 10),
|
|
decimals: parseInt(event.target.value, 10),
|
|
|
});
|
|
});
|
|
|
} else {
|
|
} else {
|
|
|
this.props.onChange({
|
|
this.props.onChange({
|
|
|
- ...this.props.options,
|
|
|
|
|
|
|
+ ...this.props.value,
|
|
|
decimals: null,
|
|
decimals: null,
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
onPrefixChange = (event: ChangeEvent<HTMLInputElement>) =>
|
|
onPrefixChange = (event: ChangeEvent<HTMLInputElement>) =>
|
|
|
- this.props.onChange({ ...this.props.options, prefix: event.target.value });
|
|
|
|
|
|
|
+ this.props.onChange({ ...this.props.value, prefix: event.target.value });
|
|
|
onSuffixChange = (event: ChangeEvent<HTMLInputElement>) =>
|
|
onSuffixChange = (event: ChangeEvent<HTMLInputElement>) =>
|
|
|
- this.props.onChange({ ...this.props.options, suffix: event.target.value });
|
|
|
|
|
|
|
+ this.props.onChange({ ...this.props.value, suffix: event.target.value });
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
- const { stat, unit, decimals, prefix, suffix } = this.props.options;
|
|
|
|
|
|
|
+ const { stat, unit, decimals, prefix, suffix } = this.props.value;
|
|
|
|
|
|
|
|
let decimalsString = '';
|
|
let decimalsString = '';
|
|
|
if (decimals !== null && decimals !== undefined && Number.isFinite(decimals as number)) {
|
|
if (decimals !== null && decimals !== undefined && Number.isFinite(decimals as number)) {
|