1
0
Fork 0

fix(gui): handle decimal inputs correctly

This commit is contained in:
Sean Sube 2023-01-08 13:25:02 -06:00
parent 2328c5f46a
commit d5c4040b07
2 changed files with 12 additions and 2 deletions

View File

@ -80,10 +80,11 @@ export function Img2Img(props: Img2ImgProps) {
setParams(newParams);
}} />
<NumericField
decimal
label='Width'
min={0}
max={1}
step='any'
step={0.1}
value={strength}
onChange={(value) => {
setStrength(value);

View File

@ -2,7 +2,16 @@ import { doesExist } from '@apextoaster/js-utils';
import { TextField } from '@mui/material';
import * as React from 'react';
export function parseNumber(num: string, decimal=false): number {
if (decimal) {
return parseFloat(num);
} else {
return parseInt(num, 10);
}
}
export interface ImageControlProps {
decimal?: boolean;
label: string;
min: number;
max: number;
@ -22,7 +31,7 @@ export function NumericField(props: ImageControlProps) {
value={value}
onChange={(event) => {
if (doesExist(props.onChange)) {
props.onChange(parseInt(event.target.value, 10));
props.onChange(parseNumber(event.target.value, props.decimal));
}
}}
/>;