quivr/frontend/lib/components/ui/Ellipsis.tsx

45 lines
1.0 KiB
TypeScript
Raw Normal View History

/* eslint-disable */
2023-06-05 08:53:47 +03:00
"use client";
import { HTMLAttributes } from "react";
2023-06-05 08:53:47 +03:00
import { cn } from "@/lib/utils";
2023-06-05 08:53:47 +03:00
import Tooltip from "./Tooltip";
interface EllipsisProps extends HTMLAttributes<HTMLDivElement> {
children: string;
maxCharacters: number;
tooltip?: boolean;
}
const Ellipsis = ({
2023-06-05 08:53:47 +03:00
children: originalContent,
className,
maxCharacters,
tooltip = false,
}: EllipsisProps): JSX.Element => {
2023-06-05 08:53:47 +03:00
const renderedContent =
originalContent.length > maxCharacters
? `${originalContent.slice(0, maxCharacters)}...`
: originalContent;
console.log(originalContent, maxCharacters, tooltip, renderedContent);
if (tooltip && originalContent !== renderedContent) {
return (
<Tooltip tooltip={originalContent}>
<span aria-label={originalContent} className={cn("", className)}>
{renderedContent}
</span>
</Tooltip>
);
}
return (
<span aria-label={originalContent} className={cn("", className)}>
{renderedContent}
</span>
);
};
export default Ellipsis;