@baseplate-dev/ui-components
Version:
Shared UI component library
15 lines • 1.25 kB
JavaScript
'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useControllerMerged } from '#src/hooks/use-controller-merged.js';
import { cn } from '#src/utils/index.js';
import { FormControl, FormDescription, FormItem, FormLabel, FormMessage, } from '../form-item/form-item.js';
import { Switch } from '../switch/switch.js';
function SwitchField({ label, description, error, onChange, value, className, ...props }) {
return (_jsxs(FormItem, { error: error, className: cn('space-y-2', className), children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(FormControl, { children: _jsx(Switch, { onCheckedChange: (checked) => onChange?.(checked), checked: value, ...props }) }), _jsxs("div", { className: "space-y-0.5", children: [_jsx(FormLabel, { className: "block", children: label }), _jsx(FormDescription, { children: description })] })] }), _jsx(FormMessage, {})] }));
}
function SwitchFieldController({ control, name, ...rest }) {
const { field, fieldState: { error }, } = useControllerMerged({ control, name }, rest, rest.ref);
return _jsx(SwitchField, { error: error?.message, ...rest, ...field });
}
export { SwitchField, SwitchFieldController };
//# sourceMappingURL=switch-field.js.map