ldc-groupe/resources/ts/back/Components/Inputs/SimpleSwitch.tsx

37 lines
988 B
TypeScript

// * Packages
import { usePage } from "@inertiajs/react";
// * Components shadcn
import { Switch } from "@/components/ui/switch";
// * Other
import InputError from "@/back/Components/InputError";
type SimpleSwitchProps = {
name: string;
checked?: boolean;
required?: boolean;
disabled?: boolean;
// eslint-disable-next-line no-unused-vars
setData: (name: string, value: boolean) => void;
};
export default function SimpleSwitch({
name,
checked,
required = false,
disabled = false,
setData,
}: SimpleSwitchProps) {
const { errors } = usePage().props;
return (
<div className="flex flex-col items-start w-fit gap-1.5">
<Switch
name={name}
onCheckedChange={(value) => setData(name, value)}
required={required}
checked={checked}
disabled={disabled}
/>
<InputError message={errors[name]} />
</div>
);
}