fleet/frontend/components/StatusIndicatorWithIcon/StatusIndicatorWithIcon.tsx
jacobshandling c2bd802fa4
UI - Refactor to TooltipWrapper and add offset to the tooltips on hover of the profile aggregate status indicators (#25039)
## #25038 

Refactor to TooltipWrapper and add offset to the tooltips on hover of
the profile aggregate status indicators.

<img width="1345" alt="Screenshot 2024-12-29 at 9 00 38 PM"
src="https://github.com/user-attachments/assets/3bf5cf3c-e9fc-47dc-aa07-9cef42edcae0"
/>

- [x] Changes file added for user-visible changes in `changes/`, 
- [x] Manual QA for all new/changed functionality

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2024-12-30 08:17:12 -08:00

78 lines
1.8 KiB
TypeScript

import React from "react";
import classnames from "classnames";
import { IconNames } from "components/icons";
import Icon from "components/Icon";
import TooltipWrapper from "components/TooltipWrapper";
const baseClass = "status-indicator-with-icon";
export type IndicatorStatus =
| "success"
| "successPartial"
| "pending"
| "pendingPartial"
| "error";
interface IStatusIndicatorWithIconProps {
status: IndicatorStatus;
value: string;
tooltip?: {
tooltipText: string | JSX.Element;
position?: "top" | "bottom";
};
layout?: "horizontal" | "vertical";
className?: string;
/** Classname to add to the value text */
valueClassName?: string;
}
const statusIconNameMapping: Record<IndicatorStatus, IconNames> = {
success: "success",
successPartial: "success-outline",
pending: "pending",
pendingPartial: "pending-outline",
error: "error",
};
const StatusIndicatorWithIcon = ({
status,
value,
tooltip,
layout = "horizontal",
className,
valueClassName,
}: IStatusIndicatorWithIconProps) => {
const classNames = classnames(baseClass, className);
const valueClasses = classnames(`${baseClass}__value`, valueClassName, {
[`${baseClass}__value-vertical`]: layout === "vertical",
});
const valueContent = (
<span className={valueClasses}>
<Icon name={statusIconNameMapping[status]} />
<span>{value}</span>
</span>
);
const indicatorContent = tooltip ? (
<TooltipWrapper
className={`${baseClass}__tooltip`}
tooltipClass="indicator-tip-text"
position="top"
tipContent={tooltip.tooltipText}
tipOffset={10}
showArrow
underline={false}
fixedPositionStrategy
>
{valueContent}
</TooltipWrapper>
) : (
<span>{valueContent}</span>
);
return <div className={classNames}>{indicatorContent}</div>;
};
export default StatusIndicatorWithIcon;