2020-09-25 17:11:25 +00:00
|
|
|
import React, { useContext } from "react";
|
2020-10-09 06:48:50 +00:00
|
|
|
import { Popover } from "@patternfly/react-core";
|
2020-09-08 17:12:42 +00:00
|
|
|
import { HelpIcon } from "@patternfly/react-icons";
|
|
|
|
import { useTranslation } from "react-i18next";
|
2020-09-25 17:11:25 +00:00
|
|
|
import { HelpContext } from "./HelpHeader";
|
2020-09-08 17:12:42 +00:00
|
|
|
|
|
|
|
type HelpItemProps = {
|
2020-10-09 06:48:50 +00:00
|
|
|
helpText: string;
|
|
|
|
forLabel: string;
|
|
|
|
forID: string;
|
2021-04-07 17:55:50 +00:00
|
|
|
noVerticalAlign?: boolean;
|
2020-09-08 17:12:42 +00:00
|
|
|
};
|
|
|
|
|
2021-04-07 17:55:50 +00:00
|
|
|
export const HelpItem = ({
|
|
|
|
helpText,
|
|
|
|
forLabel,
|
|
|
|
forID,
|
|
|
|
noVerticalAlign = true,
|
|
|
|
}: HelpItemProps) => {
|
2020-09-08 17:12:42 +00:00
|
|
|
const { t } = useTranslation();
|
2020-09-25 17:11:25 +00:00
|
|
|
const { enabled } = useContext(HelpContext);
|
2020-09-08 17:12:42 +00:00
|
|
|
return (
|
2020-09-25 17:11:25 +00:00
|
|
|
<>
|
|
|
|
{enabled && (
|
2020-10-21 17:38:11 +00:00
|
|
|
<Popover bodyContent={t(helpText)}>
|
2020-10-09 06:48:50 +00:00
|
|
|
<button
|
2021-01-21 12:09:50 +00:00
|
|
|
id={helpText}
|
2020-10-09 06:48:50 +00:00
|
|
|
aria-label={t(`helpLabel`, { label: forLabel })}
|
|
|
|
onClick={(e) => e.preventDefault()}
|
|
|
|
aria-describedby={forID}
|
|
|
|
className="pf-c-form__group-label-help"
|
|
|
|
>
|
2021-04-07 17:55:50 +00:00
|
|
|
<HelpIcon noVerticalAlign={noVerticalAlign} />
|
2020-10-09 06:48:50 +00:00
|
|
|
</button>
|
|
|
|
</Popover>
|
2020-09-25 17:11:25 +00:00
|
|
|
)}
|
|
|
|
</>
|
2020-09-08 17:12:42 +00:00
|
|
|
);
|
|
|
|
};
|