keycloak-scim/js/libs/ui-shared/src/controls/HelpItem.tsx

38 lines
984 B
TypeScript
Raw Normal View History

import { Popover } from "@patternfly/react-core";
2020-09-08 17:12:42 +00:00
import { HelpIcon } from "@patternfly/react-icons";
2023-03-07 09:29:40 +00:00
import { ReactNode } from "react";
import { useHelp } from "../context/HelpContext";
2020-09-08 17:12:42 +00:00
type HelpItemProps = {
helpText: string | ReactNode;
2021-12-14 14:56:36 +00:00
fieldLabelId: string;
noVerticalAlign?: boolean;
unWrap?: boolean;
2020-09-08 17:12:42 +00:00
};
export const HelpItem = ({
helpText,
2021-12-14 14:56:36 +00:00
fieldLabelId,
noVerticalAlign = true,
unWrap = false,
}: HelpItemProps) => {
const { enabled } = useHelp();
2021-08-26 12:15:28 +00:00
return enabled ? (
2023-03-07 09:29:40 +00:00
<Popover bodyContent={helpText}>
2021-08-26 12:15:28 +00:00
<>
{!unWrap && (
<button
2023-03-07 09:29:40 +00:00
data-testid={`help-label-${fieldLabelId}`}
aria-label={fieldLabelId}
2021-08-26 12:15:28 +00:00
onClick={(e) => e.preventDefault()}
className="pf-c-form__group-label-help"
>
<HelpIcon noVerticalAlign={noVerticalAlign} />
</button>
)}
{unWrap && <HelpIcon noVerticalAlign={noVerticalAlign} />}
</>
</Popover>
) : null;
2020-09-08 17:12:42 +00:00
};