Files
ox_lib/web/src/features/dialog/components/fields/select.tsx

40 lines
1.2 KiB
TypeScript
Raw Normal View History

import { Select } from '@mantine/core';
import { ISelect } from '../../../../interfaces/dialog';
import { Control, FieldValues, useController, UseFormRegisterReturn, UseFormSetValue } from 'react-hook-form';
import { FormValues } from '../../InputDialog';
2023-01-09 14:39:49 +01:00
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
interface Props {
row: ISelect;
index: number;
control: Control<FormValues>;
}
const SelectField: React.FC<Props> = (props) => {
const controller = useController({
name: `test.${props.index}.value`,
control: props.control,
defaultValue: props.row.default || props.row.options[0].value,
2023-01-08 11:35:30 +01:00
rules: { required: props.row.required },
});
return (
<Select
data={props.row.options}
value={controller.field.value}
name={controller.field.name}
ref={controller.field.ref}
onBlur={controller.field.onBlur}
onChange={controller.field.onChange}
disabled={props.row.disabled}
label={props.row.label}
description={props.row.description}
2023-01-08 11:35:30 +01:00
withAsterisk={props.row.required}
clearable={props.row.clearable}
2023-01-09 14:39:49 +01:00
icon={props.row.icon && <FontAwesomeIcon icon={props.row.icon} fixedWidth />}
/>
);
};
export default SelectField;