Files
omni-tools/src/components/options/RadioWithTextField.tsx

47 lines
1.0 KiB
TypeScript
Raw Normal View History

2024-06-26 09:02:05 +01:00
import { Box } from '@mui/material';
2024-06-23 15:14:14 +01:00
import React from 'react';
import TextFieldWithDesc from './TextFieldWithDesc';
2024-06-25 03:11:48 +01:00
import SimpleRadio from './SimpleRadio';
2024-06-23 15:14:14 +01:00
const RadioWithTextField = <T,>({
fieldName,
2024-06-25 03:11:48 +01:00
radioValue,
2024-06-23 15:14:14 +01:00
title,
2024-06-25 03:11:48 +01:00
onRadioChange,
2024-06-23 15:14:14 +01:00
value,
description,
2024-06-25 03:11:48 +01:00
onTextChange,
typeDescription
2024-06-23 15:14:14 +01:00
}: {
fieldName: string;
title: string;
2024-06-25 03:11:48 +01:00
radioValue: T;
onRadioChange: (val: T) => void;
2024-06-23 15:14:14 +01:00
value: string;
description: string;
onTextChange: (value: string) => void;
2024-06-25 03:11:48 +01:00
typeDescription?: string;
2024-06-23 15:14:14 +01:00
}) => {
2024-06-25 03:11:48 +01:00
const onChange = () => onRadioChange(radioValue);
2024-06-23 15:14:14 +01:00
return (
<Box>
2024-06-25 03:11:48 +01:00
<SimpleRadio
value={radioValue}
onChange={onChange}
fieldName={fieldName}
title={title}
description={typeDescription}
/>
2024-06-23 15:14:14 +01:00
<TextFieldWithDesc
value={value}
2024-06-27 12:39:38 +01:00
onChange={(val) => {
if (typeof val === 'string') onTextChange(val);
else onTextChange(val.target.value);
}}
2024-06-23 15:14:14 +01:00
description={description}
/>
</Box>
);
};
export default RadioWithTextField;