mirror of
https://github.com/khairul169/garage-webui.git
synced 2025-06-17 22:29:32 +07:00
52 lines
1.1 KiB
TypeScript
52 lines
1.1 KiB
TypeScript
|
import React, { forwardRef } from "react";
|
||
|
import { Toggle as BaseToggle } from "react-daisyui";
|
||
|
import FormControl from "./form-control";
|
||
|
import { FieldValues } from "react-hook-form";
|
||
|
|
||
|
type ToggleProps = Omit<
|
||
|
React.ComponentPropsWithoutRef<typeof BaseToggle>,
|
||
|
"form"
|
||
|
> & { label?: string };
|
||
|
|
||
|
const Toggle = forwardRef<HTMLInputElement, ToggleProps>(
|
||
|
({ label, ...props }, ref) => {
|
||
|
return (
|
||
|
<label className="inline-flex justify-start label label-text gap-2 cursor-pointer">
|
||
|
<BaseToggle ref={ref} {...props} />
|
||
|
{label}
|
||
|
</label>
|
||
|
);
|
||
|
}
|
||
|
);
|
||
|
|
||
|
type ToggleFieldProps<T extends FieldValues> = Omit<
|
||
|
React.ComponentPropsWithoutRef<typeof FormControl<T>>,
|
||
|
"render"
|
||
|
> &
|
||
|
ToggleProps & {
|
||
|
inputClassName?: string;
|
||
|
};
|
||
|
|
||
|
export const ToggleField = <T extends FieldValues>({
|
||
|
form,
|
||
|
name,
|
||
|
title,
|
||
|
className,
|
||
|
inputClassName,
|
||
|
...props
|
||
|
}: ToggleFieldProps<T>) => {
|
||
|
return (
|
||
|
<FormControl
|
||
|
form={form}
|
||
|
name={name}
|
||
|
title={title}
|
||
|
className={className}
|
||
|
render={(field) => (
|
||
|
<Toggle {...props} {...field} className={inputClassName} />
|
||
|
)}
|
||
|
/>
|
||
|
);
|
||
|
};
|
||
|
|
||
|
export default Toggle;
|