ConceptPortal-public/rsconcept/frontend/src/components/ui/TextContent.tsx
Ivan 44b0705521
Some checks are pending
Frontend CI / build (22.x) (push) Waiting to run
R: use alias instead of relative path
2025-01-28 23:23:42 +03:00

37 lines
1.0 KiB
TypeScript

import clsx from 'clsx';
import { CProps } from '@/components/props';
import { globals } from '@/utils/constants';
import { truncateToLastWord } from '@/utils/utils';
export interface TextContentProps extends CProps.Styling {
/** Text to display. */
text: string;
/** Maximum number of symbols to display. */
maxLength?: number;
/** Disable full text in a tooltip. */
noTooltip?: boolean;
}
/**
* Displays text limited to a certain number of symbols.
*/
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;