2024-08-11 14:25:10 +03:00
|
|
|
import clsx from 'clsx';
|
|
|
|
|
2025-02-20 18:10:53 +03:00
|
|
|
import { globalIDs } from '@/utils/constants';
|
2024-08-19 19:16:29 +03:00
|
|
|
import { truncateToLastWord } from '@/utils/utils';
|
2024-08-11 14:25:10 +03:00
|
|
|
|
2025-02-21 21:15:05 +03:00
|
|
|
import { type Styling } from '../props';
|
|
|
|
|
|
|
|
export interface TextContentProps extends Styling {
|
2024-11-21 15:09:51 +03:00
|
|
|
/** Text to display. */
|
2024-08-11 14:25:10 +03:00
|
|
|
text: string;
|
2024-11-21 15:09:51 +03:00
|
|
|
|
|
|
|
/** Maximum number of symbols to display. */
|
2024-08-11 14:25:10 +03:00
|
|
|
maxLength?: number;
|
2024-11-21 15:09:51 +03:00
|
|
|
|
|
|
|
/** Disable full text in a tooltip. */
|
2024-09-02 18:34:18 +03:00
|
|
|
noTooltip?: boolean;
|
2024-08-11 14:25:10 +03:00
|
|
|
}
|
|
|
|
|
2024-11-21 15:09:51 +03:00
|
|
|
/**
|
|
|
|
* Displays text limited to a certain number of symbols.
|
|
|
|
*/
|
2025-02-07 10:54:47 +03:00
|
|
|
export function TextContent({ className, text, maxLength, noTooltip, ...restProps }: TextContentProps) {
|
2024-08-19 19:16:29 +03:00
|
|
|
const truncated = maxLength ? truncateToLastWord(text, maxLength) : text;
|
2024-08-11 14:25:10 +03:00
|
|
|
const isTruncated = maxLength && text.length > maxLength;
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={clsx('text-xs text-pretty', className)}
|
2025-02-20 18:10:53 +03:00
|
|
|
data-tooltip-id={isTruncated && !noTooltip ? globalIDs.value_tooltip : undefined}
|
2024-09-02 18:34:18 +03:00
|
|
|
data-tooltip-html={isTruncated && !noTooltip ? text : undefined}
|
2024-08-11 14:25:10 +03:00
|
|
|
{...restProps}
|
|
|
|
>
|
|
|
|
{truncated}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|