// Arbitrary text that will be truncated if there is not enough space in the container import React from 'react'; import type { ExcludeUndefined } from 'types/utils'; import type { SkeletonTextProps } from '../../chakra/skeleton'; import { Skeleton } from '../../chakra/skeleton'; import type { TooltipProps } from '../../chakra/tooltip'; import { Tooltip } from '../../chakra/tooltip'; import { TruncatedTextTooltip } from './TruncatedTextTooltip'; export interface TruncatedTextProps extends Omit { text: string; loading?: boolean; // tooltipContent is used to display the tooltip value different from the truncated value tooltipContent?: string; tooltipPlacement?: ExcludeUndefined['placement']; tooltipInteractive?: boolean; } export const TruncatedText = ({ text, tooltipPlacement, tooltipInteractive, tooltipContent, loading, ...rest }: TruncatedTextProps) => { const valueElement = ( { text } ); // if tooltipContent is provided, we display the tooltip content no matter if the value is truncated or not if (tooltipContent) { return ( { valueElement } ); }; return ( { valueElement } ); };