UNPKG

@keycloakify/keycloak-admin-ui

Version:
13 lines 1.06 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { Switch } from "@patternfly/react-core"; import { Controller, useFormContext } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { FormGroupField } from "../../identity-providers/component/FormGroupField"; export const SwitchField = ({ label, field, fieldType = "string", isReadOnly = false, defaultValue, }) => { const { t } = useTranslation(); const { control } = useFormContext(); return (_jsx(FormGroupField, { label: label, children: _jsx(Controller, { name: field, defaultValue: defaultValue ? defaultValue : fieldType === "string" ? "false" : false, control: control, render: ({ field }) => (_jsx(Switch, { id: label, label: t("on"), labelOff: t("off"), isChecked: fieldType === "string" ? field.value === "true" : field.value, onChange: (_event, value) => field.onChange(fieldType === "string" ? "" + value : value), isDisabled: isReadOnly, "aria-label": label })) }) })); }; //# sourceMappingURL=SwitchField.js.map