fix-1847 truncate fix for selection component.

This commit is contained in:
Owaise Imdad committed 2025-03-05 09:11:15 +05:30
1 parent 314968d1a1
commit 3226035589
2 files changed
+70

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
// src/utils/truncateUtils.js
import { isEmpty } from "./stringUtils"; // assuming you have the stringUtils file
/**
* Utility function to render a truncated value with an optional title.
* @param {string} displayName - The name or text to display.
* @param {number} maxLength - The maximum length of the text.
* @param {string} placeholder - Placeholder text if no value is provided.
* @returns {JSX.Element} - The JSX element for the rendered value.
*
*/
const truncateTextWithDottedEnds = function (text, maxLength) {
if (!text || text.length <= maxLength) return text;
return `${text.substring(0, maxLength)}...`;
};
export const renderTruncatedValue = function (
displayName,
truncate,
maxLength,
placeholder
) {
console.log(maxLength);
if (isEmpty(displayName)) return placeholder;
return truncate ? (
<span title={displayName}>{truncateTextWithDottedEnds(displayName, maxLength)}</span>
) : (
<span title={displayName}>{displayName}</span>
);
};