@keycloakify/keycloak-account-ui
Version:
<p align="center"> <img src="https://github.com/user-attachments/assets/e31c4910-7205-441c-9a35-e134b806b3a8"> </p> <p align="center"> <i>Repackaged Keycloak Account UI</i> <br> <br> <a href="https://github.com/keycloakify/keycloak-a
29 lines • 1.94 kB
JavaScript
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
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 = (_a) => {
var _b;
var { labelOn, stringify, defaultValue, labelIcon } = _a, props = __rest(_a, ["labelOn", "stringify", "defaultValue", "labelIcon"]);
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: ((_b = props.rules) === null || _b === void 0 ? void 0 : _b.required) === true, label: props.label, labelIcon: labelIcon, children: _jsx(Controller, { control: control, name: props.name, defaultValue: defValue, render: ({ field: { onChange, value } }) => (_jsx(Switch, Object.assign({}, 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