fleet/frontend/components/StatusIndicatorWithIcon/StatusIndicatorWithIcon.tsx
Gabriel Hernandez e822132590
Feat/disk encryption page (#10288)
related to #9402 and #9404

Implements UI for toggling off and on fleet mdm disk encryption
management and also the disk encryption aggregate data tables.

**Toggling disk encryption:**


![image](https://user-images.githubusercontent.com/1153709/222773636-2943521b-6e88-4154-980b-92e1122aebfc.png)

**disk encryption aggregate:**


![image](https://user-images.githubusercontent.com/1153709/222773592-0781fe1b-7808-4e50-b7de-03c6817c612f.png)

- [x] Changes file added for user-visible changes in `changes/` or
`orbit/changes/`.
- [x] Manual QA for all new/changed functionality
2023-03-14 13:03:02 -07:00

69 lines
1.6 KiB
TypeScript

import React from "react";
import ReactTooltip from "react-tooltip";
import { uniqueId } from "lodash";
import classnames from "classnames";
import { IconNames } from "components/icons";
import Icon from "components/Icon";
import { COLORS } from "styles/var/colors";
const baseClass = "status-indicator-with-icon";
type Status = "success" | "pending" | "error";
interface IStatusIndicatorWithIconProps {
status: Status;
value: string;
tooltip?: {
tooltipText: string | JSX.Element;
position?: "top" | "bottom";
};
className?: string;
}
const statusIconNameMapping: Record<Status, IconNames> = {
success: "success",
pending: "pending",
error: "error",
};
const StatusIndicatorWithIcon = ({
status,
value,
tooltip,
className,
}: IStatusIndicatorWithIconProps) => {
const classNames = classnames(baseClass, className);
const id = `status-${uniqueId()}`;
const valueContent = (
<span className={`${baseClass}__value`}>
<Icon name={statusIconNameMapping[status]} />
<span>{value}</span>
</span>
);
const indicatorContent = tooltip ? (
<>
<span data-tip data-for={id}>
{valueContent}
</span>
<ReactTooltip
className={`${baseClass}__tooltip`}
place={tooltip?.position ? tooltip.position : "top"}
type="dark"
effect="solid"
id={id}
backgroundColor={COLORS["tooltip-bg"]}
>
{tooltip.tooltipText}
</ReactTooltip>
</>
) : (
<span>{valueContent}</span>
);
return <div className={classNames}>{indicatorContent}</div>;
};
export default StatusIndicatorWithIcon;