UNPKG

@keycloakify/keycloak-admin-ui

Version:
17 lines 1.35 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { FormGroup, Switch } from "@patternfly/react-core"; import { Controller, useFormContext } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { HelpItem } from "../../ui-shared"; import { convertToName } from "../../components/dynamic/DynamicComponents"; export const BooleanComponent = ({ name, label, helpText, isDisabled = false, defaultValue, isNew = true, }) => { const { t } = useTranslation(); const { control } = useFormContext(); return (_jsx(FormGroup, { hasNoPaddingTop: true, label: t(label), fieldId: name, labelIcon: _jsx(HelpItem, { helpText: t(helpText), fieldLabelId: `${label}` }), children: _jsx(Controller, { name: convertToName(name), "data-testid": name, defaultValue: isNew ? defaultValue : false, control: control, render: ({ field }) => { var _a; return (_jsx(Switch, { id: name, isDisabled: isDisabled, label: t("on"), labelOff: t("off"), isChecked: field.value === "true" || field.value === true || ((_a = field.value) === null || _a === void 0 ? void 0 : _a[0]) === "true", onChange: (_event, value) => field.onChange("" + value), "data-testid": name, "aria-label": t(label) })); } }) })); }; //# sourceMappingURL=BooleanComponent.js.map