This commit is contained in:
2023-10-06 14:57:33 +07:00
parent 1d11e06178
commit 5376873552
50 changed files with 3683 additions and 150 deletions

View File

@@ -0,0 +1,41 @@
import { Autocomplete, TextField, TextFieldProps } from '@mui/material';
import { useState } from 'react';
import { Controller, useFormContext } from 'react-hook-form';
interface IProps {
options: any[];
name: string;
label?: string;
}
export default function RHFAutocomplete({ name, options, label, ...other }: IProps & TextFieldProps) {
const { control } = useFormContext();
console.log(control)
const [value, setValue] = useState<string | null>(options[0]);
const [inputValue, setInputValue] = useState('');
return (
<Controller
name={name}
control={control}
render={({ field, fieldState: { error } }) => (
<Autocomplete
{...field}
options={options}
value={value}
onChange={(event: any, newValue: string | null) => {
// console.log('fuck', newValue)
setValue(newValue.id);
}}
inputValue={inputValue}
onInputChange={(event, newInputValue) => {
setInputValue(newInputValue);
}}
renderInput={(params) => <TextField {...params} label={label ?? name} />}
{...other}
/>
)}
/>
);
}

View File

@@ -9,9 +9,10 @@ type IProps = Omit<FormControlLabelProps, 'control'>;
interface Props extends IProps {
name: string;
disabled?: boolean;
}
export default function RHFSwitch({ name, ...other }: Props) {
export default function RHFSwitch({ name, disabled = false, ...other }: Props) {
const { control } = useFormContext();
return (
@@ -20,7 +21,7 @@ export default function RHFSwitch({ name, ...other }: Props) {
<Controller
name={name}
control={control}
render={({ field }) => <Switch {...field} checked={field.value} />}
render={({ field }) => <Switch {...field} checked={field.value} disabled={disabled} />}
/>
}
{...other}