fleet/frontend/components/TableContainer/DataTable/TooltipTruncatedTextCell/TooltipTruncatedTextCell.tsx
Gabriel Hernandez 1e6839c004
Feat UI resend profile (#18111)
relates to #17896

UI implementation of the resend profile feature. This adds a resend
button on the OS Settings modal row items that will request the profile
is resent.


![image](https://github.com/fleetdm/fleet/assets/1153709/f9072ccc-2d28-4638-adea-da3cb25da33b)

- [x] Changes file added for user-visible changes in `changes/` or
`orbit/changes/`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [x] Manual QA for all new/changed functionality

---------

Co-authored-by: Roberto Dip <me@roperzh.com>
2024-04-15 14:17:08 +01:00

75 lines
2.2 KiB
TypeScript

import React from "react";
import { uniqueId } from "lodash";
import classnames from "classnames";
import ReactTooltip from "react-tooltip";
import { DEFAULT_EMPTY_CELL_VALUE } from "utilities/constants";
import { COLORS } from "styles/var/colors";
interface ITooltipTruncatedTextCellProps {
value: React.ReactNode;
/** Tooltip to dispay. If this is provided then this will be rendered as the tooltip content. If
* not, the value will be displayed as the tooltip content. Defaults to `undefined` */
tooltip?: React.ReactNode;
/** If set to `true` the text inside the tooltip will break on words instead of any character.
* By default the tooltip text breaks on any character.
* Default is `false`.
*/
tooltipBreakOnWord?: boolean;
/** @deprecated use the prop `className` in order to add custom classes to this component */
classes?: string;
className?: string;
}
const baseClass = "tooltip-truncated-cell";
const TooltipTruncatedTextCell = ({
value,
tooltip,
tooltipBreakOnWord = false,
classes = "w250",
className,
}: ITooltipTruncatedTextCellProps): JSX.Element => {
const classNames = classnames(baseClass, classes, className, {
"tooltip-break-on-word": tooltipBreakOnWord,
});
const tooltipId = uniqueId();
const isDefaultValue = value === DEFAULT_EMPTY_CELL_VALUE;
return (
<div className={classNames}>
<div
className="data-table__tooltip-truncated-text"
data-tip
data-for={tooltipId}
data-tip-disable={isDefaultValue}
>
<span
className={`data-table__tooltip-truncated-text--cell ${
isDefaultValue ? "text-muted" : ""
} `}
>
{value}
</span>
</div>
<ReactTooltip
place="top"
effect="solid"
backgroundColor={COLORS["tooltip-bg"]}
id={tooltipId}
data-html
className="truncated-tooltip" // responsive widths
clickable
delayHide={200} // need delay set to hover using clickable
>
<>
{tooltip ?? value}
<div className="safari-hack">&nbsp;</div>
{/* Fixes triple click selecting next element in Safari */}
</>
</ReactTooltip>
</div>
);
};
export default TooltipTruncatedTextCell;