@keycloakify/keycloak-admin-ui
Version:
Repackaged Keycloak Admin UI
17 lines • 1.59 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { HelpItem, KeycloakSelect, SelectVariant, } from "../../ui-shared";
import { FormGroup, SelectOption } from "@patternfly/react-core";
import { useState } from "react";
import { Controller, useFormContext } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { convertToName } from "../../components/dynamic/DynamicComponents";
export const ListComponent = ({ name, label, helpText, defaultValue, options, required, isDisabled = false, }) => {
const { t } = useTranslation();
const { control } = useFormContext();
const [open, setOpen] = useState(false);
return (_jsx(FormGroup, { label: t(label), labelIcon: _jsx(HelpItem, { helpText: t(helpText), fieldLabelId: `${label}` }), fieldId: name, isRequired: required, children: _jsx(Controller, { name: convertToName(name), "data-testid": name, defaultValue: defaultValue || (options === null || options === void 0 ? void 0 : options[0]) || "", control: control, render: ({ field }) => (_jsx(KeycloakSelect, { toggleId: name, isDisabled: isDisabled, onToggle: (toggle) => setOpen(toggle), onSelect: (value) => {
field.onChange(value);
setOpen(false);
}, selections: field.value, variant: SelectVariant.single, "aria-label": t(label), isOpen: open, children: options === null || options === void 0 ? void 0 : options.map((option) => (_jsx(SelectOption, { selected: option === field.value, value: option, children: option }, option))) })) }) }));
};
//# sourceMappingURL=ListComponent.js.map