* Introduced ButtonCtrl, IconButtonCtrl, NativeSelectCtrl, PasswordInputCtrl, SwitchCtrl, TextAreaCtrl, TextInputCtrl * Updated FormerControllers.types.ts to include SpecialIDProps * Enhanced lib.ts to export new components
33 lines
980 B
TypeScript
33 lines
980 B
TypeScript
import { Switch, type SwitchProps, Tooltip } from '@mantine/core';
|
|
import { Controller } from 'react-hook-form';
|
|
|
|
import type { FormerControllersProps, SpecialIDProps } from '../FormerControllers.types';
|
|
|
|
const SwitchCtrl = (props: FormerControllersProps & SpecialIDProps & SwitchProps) => {
|
|
const { control, name, sid, tooltip, ...innerProps } = props;
|
|
return (
|
|
<Controller
|
|
control={control}
|
|
name={name}
|
|
render={({ field, formState }) => (
|
|
<Tooltip label={tooltip ?? ''} withArrow>
|
|
<Switch
|
|
{...innerProps}
|
|
{...field}
|
|
checked={!!field.value}
|
|
disabled={formState.disabled}
|
|
id={`field_${name}_${sid ?? ''}`}
|
|
key={`field_${name}_${sid ?? ''}`}
|
|
onChange={(e) => {
|
|
field.onChange((e.currentTarget ?? e.target)?.checked);
|
|
}}
|
|
/>
|
|
</Tooltip>
|
|
)}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export { SwitchCtrl };
|
|
export default SwitchCtrl;
|