UNPKG

@keycloakify/keycloak-admin-ui

Version:
17 lines 1.35 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { Controller, useFormContext, } from "react-hook-form"; import { Switch } from "@patternfly/react-core"; import { FormLabel } from "../../ui-shared/controls/FormLabel"; export const SwitchControl = ({ labelOn, stringify, defaultValue, labelIcon, ...props }) => { var _a; const fallbackValue = stringify ? "false" : false; const defValue = defaultValue !== null && defaultValue !== void 0 ? defaultValue : fallbackValue; const { control } = useFormContext(); return (_jsx(FormLabel, { hasNoPaddingTop: true, name: props.name, isRequired: ((_a = props.rules) === null || _a === void 0 ? void 0 : _a.required) === true, label: props.label, labelIcon: labelIcon, children: _jsx(Controller, { control: control, name: props.name, defaultValue: defValue, render: ({ field: { onChange, value } }) => (_jsx(Switch, { ...props, id: props.name, "data-testid": props.name, label: labelOn, isChecked: stringify ? value === "true" : value, onChange: (e, checked) => { var _a; const value = stringify ? checked.toString() : checked; (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, e, checked); onChange(value); } })) }) })); }; //# sourceMappingURL=SwitchControl.js.map