2023-03-14 20:03:02 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import classnames from "classnames";
|
|
|
|
|
|
|
|
|
|
import { IconNames } from "components/icons";
|
|
|
|
|
import Icon from "components/Icon";
|
2024-12-30 16:17:12 +00:00
|
|
|
import TooltipWrapper from "components/TooltipWrapper";
|
2023-03-14 20:03:02 +00:00
|
|
|
|
|
|
|
|
const baseClass = "status-indicator-with-icon";
|
|
|
|
|
|
2023-04-26 18:31:38 +00:00
|
|
|
export type IndicatorStatus =
|
|
|
|
|
| "success"
|
|
|
|
|
| "successPartial"
|
|
|
|
|
| "pending"
|
|
|
|
|
| "pendingPartial"
|
2025-05-01 18:43:38 +00:00
|
|
|
| "error"
|
|
|
|
|
| "failure"
|
|
|
|
|
| "actionRequired";
|
2023-03-14 20:03:02 +00:00
|
|
|
|
|
|
|
|
interface IStatusIndicatorWithIconProps {
|
2025-05-22 23:45:43 +00:00
|
|
|
/** Determines which icon to display */
|
2023-04-26 18:31:38 +00:00
|
|
|
status: IndicatorStatus;
|
2025-05-22 23:45:43 +00:00
|
|
|
/** The text to be displayed */
|
2023-03-14 20:03:02 +00:00
|
|
|
value: string;
|
|
|
|
|
tooltip?: {
|
|
|
|
|
tooltipText: string | JSX.Element;
|
|
|
|
|
position?: "top" | "bottom";
|
|
|
|
|
};
|
2023-10-06 22:04:33 +00:00
|
|
|
layout?: "horizontal" | "vertical";
|
2023-03-14 20:03:02 +00:00
|
|
|
className?: string;
|
2023-10-06 22:04:33 +00:00
|
|
|
/** Classname to add to the value text */
|
|
|
|
|
valueClassName?: string;
|
2023-03-14 20:03:02 +00:00
|
|
|
}
|
|
|
|
|
|
2023-04-26 18:31:38 +00:00
|
|
|
const statusIconNameMapping: Record<IndicatorStatus, IconNames> = {
|
2023-03-14 20:03:02 +00:00
|
|
|
success: "success",
|
2023-10-31 16:06:38 +00:00
|
|
|
successPartial: "success-outline",
|
2023-03-14 20:03:02 +00:00
|
|
|
pending: "pending",
|
2023-10-31 16:06:38 +00:00
|
|
|
pendingPartial: "pending-outline",
|
2023-03-14 20:03:02 +00:00
|
|
|
error: "error",
|
2025-05-01 18:43:38 +00:00
|
|
|
failure: "error-outline",
|
|
|
|
|
actionRequired: "error",
|
2023-03-14 20:03:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const StatusIndicatorWithIcon = ({
|
|
|
|
|
status,
|
|
|
|
|
value,
|
|
|
|
|
tooltip,
|
2023-10-06 22:04:33 +00:00
|
|
|
layout = "horizontal",
|
2023-03-14 20:03:02 +00:00
|
|
|
className,
|
2023-10-06 22:04:33 +00:00
|
|
|
valueClassName,
|
2023-03-14 20:03:02 +00:00
|
|
|
}: IStatusIndicatorWithIconProps) => {
|
|
|
|
|
const classNames = classnames(baseClass, className);
|
|
|
|
|
|
2023-10-06 22:04:33 +00:00
|
|
|
const valueClasses = classnames(`${baseClass}__value`, valueClassName, {
|
|
|
|
|
[`${baseClass}__value-vertical`]: layout === "vertical",
|
|
|
|
|
});
|
2023-03-14 20:03:02 +00:00
|
|
|
const valueContent = (
|
2023-10-06 22:04:33 +00:00
|
|
|
<span className={valueClasses}>
|
2025-05-01 18:43:38 +00:00
|
|
|
<Icon
|
|
|
|
|
name={statusIconNameMapping[status]}
|
|
|
|
|
color={status === "failure" ? "ui-fleet-black-50" : undefined}
|
|
|
|
|
/>
|
2023-03-14 20:03:02 +00:00
|
|
|
<span>{value}</span>
|
|
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const indicatorContent = tooltip ? (
|
2024-12-30 16:17:12 +00:00
|
|
|
<TooltipWrapper
|
|
|
|
|
className={`${baseClass}__tooltip`}
|
|
|
|
|
tooltipClass="indicator-tip-text"
|
|
|
|
|
position="top"
|
|
|
|
|
tipContent={tooltip.tooltipText}
|
|
|
|
|
tipOffset={10}
|
|
|
|
|
showArrow
|
|
|
|
|
underline={false}
|
|
|
|
|
fixedPositionStrategy
|
|
|
|
|
>
|
|
|
|
|
{valueContent}
|
|
|
|
|
</TooltipWrapper>
|
2023-03-14 20:03:02 +00:00
|
|
|
) : (
|
|
|
|
|
<span>{valueContent}</span>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return <div className={classNames}>{indicatorContent}</div>;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default StatusIndicatorWithIcon;
|