Portal/rsconcept/frontend/src/components/ui/TextContent.tsx
Ivan d23f02420a
Some checks failed
Frontend CI / build (22.x) (push) Has been cancelled
F: Improve tooltips positioning and text truncation
2024-09-02 18:33:54 +03:00

30 lines
843 B
TypeScript

import clsx from 'clsx';
import { globals } from '@/utils/constants';
import { truncateToLastWord } from '@/utils/utils';
import { CProps } from '../props';
export interface TextContentProps extends CProps.Styling {
text: string;
maxLength?: number;
noTooltip?: boolean;
}
function TextContent({ className, text, maxLength, noTooltip, ...restProps }: TextContentProps) {
const truncated = maxLength ? truncateToLastWord(text, maxLength) : text;
const isTruncated = maxLength && text.length > maxLength;
return (
<div
className={clsx('text-xs text-pretty', className)}
data-tooltip-id={isTruncated && !noTooltip ? globals.value_tooltip : undefined}
data-tooltip-html={isTruncated && !noTooltip ? text : undefined}
{...restProps}
>
{truncated}
</div>
);
}
export default TextContent;