mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-10 09:53:48 +00:00
31fc222876
* style: disable menu bar in run mode * fix: external devices in dev mode * fix: add missing elements to translations * ux: improve translation strings * refactor: improve typing * style: blink on event change * refactor: param options is object --------- Co-authored-by: Hannes Rüger <hannesrueger@gmx.de>
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import { useSearchParams } from 'react-router-dom';
|
|
import { Input, Select, Switch } from '@chakra-ui/react';
|
|
|
|
import { isStringBoolean } from '../../utils/viewUtils';
|
|
|
|
import { ParamField } from './types';
|
|
|
|
interface EditFormInputProps {
|
|
paramField: ParamField;
|
|
}
|
|
|
|
export default function ParamInput({ paramField }: EditFormInputProps) {
|
|
const [searchParams] = useSearchParams();
|
|
const { id, type } = paramField;
|
|
|
|
if (type === 'option') {
|
|
const optionFromParams = searchParams.get(id);
|
|
const defaultOptionValue = optionFromParams || undefined;
|
|
|
|
return (
|
|
<Select placeholder='Select an option' variant='ontime' name={id} defaultValue={defaultOptionValue}>
|
|
{Object.entries(paramField.values).map(([key, value]) => (
|
|
<option key={key} value={key}>
|
|
{value}
|
|
</option>
|
|
))}
|
|
</Select>
|
|
);
|
|
}
|
|
|
|
if (type === 'boolean') {
|
|
const defaultCheckedValue = isStringBoolean(searchParams.get(id)) ?? false;
|
|
|
|
// checked value should be 'true', so it can be captured by the form event
|
|
return <Switch variant='ontime' name={id} defaultChecked={defaultCheckedValue} value='true' />;
|
|
}
|
|
|
|
if (type === 'number') {
|
|
const defaultNumberValue = searchParams.get(id) ?? '';
|
|
|
|
return <Input type='number' step='any' variant='ontime-filled' name={id} defaultValue={defaultNumberValue} />;
|
|
}
|
|
|
|
const defaultStringValue = searchParams.get(id) ?? '';
|
|
|
|
return <Input variant='ontime-filled' name={id} defaultValue={defaultStringValue} />;
|
|
}
|