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;
|
2020-09-08 17:12:42 +00:00
|
|
|
};
|
|
|
|
|
2020-10-09 06:48:50 +00:00
|
|
|
export const HelpItem = ({ helpText, forLabel, forID }: 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
|
|
|
|
aria-label={t(`helpLabel`, { label: forLabel })}
|
|
|
|
onClick={(e) => e.preventDefault()}
|
|
|
|
aria-describedby={forID}
|
|
|
|
className="pf-c-form__group-label-help"
|
|
|
|
>
|
|
|
|
<HelpIcon noVerticalAlign />
|
|
|
|
</button>
|
|
|
|
</Popover>
|
2020-09-25 17:11:25 +00:00
|
|
|
)}
|
|
|
|
</>
|
2020-09-08 17:12:42 +00:00
|
|
|
);
|
|
|
|
};
|