UNPKG

@keycloakify/keycloak-admin-ui

Version:
23 lines 2 kB
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import { Button, Chip, ChipGroup, FormGroup, InputGroup, InputGroupItem, } from "@patternfly/react-core"; import { useState } from "react"; import { Controller, useFormContext } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { GroupPickerDialog } from "../../components/group/GroupPickerDialog"; import { HelpItem } from "../../ui-shared"; import { convertToName } from "../../components/dynamic/DynamicComponents"; export const GroupComponent = ({ name, label, helpText, required, }) => { const { t } = useTranslation(); const [open, setOpen] = useState(false); const [groups, setGroups] = useState(); const { control } = useFormContext(); return (_jsx(Controller, { name: convertToName(name), defaultValue: "", control: control, render: ({ field }) => (_jsxs(_Fragment, { children: [open && (_jsx(GroupPickerDialog, { type: "selectOne", text: { title: "selectGroup", ok: "select", }, onConfirm: (groups) => { field.onChange(groups === null || groups === void 0 ? void 0 : groups[0].path); setGroups(groups); setOpen(false); }, onClose: () => setOpen(false), filterGroups: groups })), _jsx(FormGroup, { label: t(label), labelIcon: _jsx(HelpItem, { helpText: t(helpText), fieldLabelId: `${label}` }), fieldId: name, isRequired: required, children: _jsxs(InputGroup, { children: [_jsx(InputGroupItem, { children: _jsx(ChipGroup, { children: field.value && (_jsx(Chip, { onClick: () => field.onChange(undefined), children: field.value })) }) }), _jsx(InputGroupItem, { children: _jsx(Button, { id: "kc-join-groups-button", onClick: () => setOpen(!open), variant: "secondary", "data-testid": "join-groups-button", children: t("selectGroup") }) })] }) })] })) })); }; //# sourceMappingURL=GroupComponent.js.map