Skip to content

Commit

Permalink
feat(SLB-390): adjust truncation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Luqmaan Essop committed Jun 19, 2024
1 parent 37c0975 commit a7f1725
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
12 changes: 6 additions & 6 deletions packages/ui/src/components/Molecules/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ export function BreadCrumbs() {
<div aria-hidden="true">
<ChevronRightIcon
className={
'hidden sm:flex rotate-180 sm:rotate-0 w-4 h-4 text-gray-400 mr-4'
'hidden xl:flex rotate-180 xl:rotate-0 w-4 h-4 text-gray-400 mr-4'
}
/>
</div>
<button
className="mr-4 hidden sm:flex items-center rounded-sm px-1 py-2 bg-gray-100 hover:bg-gray-200 h-2"
className="mr-4 hidden xl:flex items-center rounded-sm px-1 py-2 bg-gray-100 hover:bg-gray-200 h-2"
onClick={() => {
setHideInnerBreadcrumbs(false);
setToggleMoreBreadcrumbs(true);
Expand All @@ -59,7 +59,7 @@ export function BreadCrumbs() {
className={clsx(
'',
index < breadcrumbs.length - 1
? 'hidden sm:inline-flex sm:items-center'
? 'hidden xl:inline-flex xl:items-center'
: 'inline-flex items-center',
)}
key={id}
Expand All @@ -76,7 +76,7 @@ export function BreadCrumbs() {
>
<ChevronRightIcon
className={
'rotate-180 sm:rotate-0 w-4 h-4 text-gray-400 mr-4'
'rotate-180 xl:rotate-0 w-4 h-4 text-gray-400 mr-4'
}
/>
</div>
Expand All @@ -88,7 +88,7 @@ export function BreadCrumbs() {
'inline-flex items-center text-sm font-medium hover:text-blue-600 whitespace-nowrap',
index < breadcrumbs.length - 1 &&
hideInnerBreadcrumbs !== true
? 'hidden sm:inline-flex sm:items-center'
? 'hidden xl:inline-flex xl:items-center'
: 'inline-flex items-center',
hideInnerBreadcrumbs === true &&
index > 0 &&
Expand All @@ -108,7 +108,7 @@ export function BreadCrumbs() {
</svg>
)}
<span className="mr-4">
{truncateString({ value: title, maxChar: 20 })}
{truncateString({ value: title, maxChar: 25 })}
</span>
</Link>
</li>
Expand Down
13 changes: 9 additions & 4 deletions packages/ui/src/utils/stringTruncation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@ export const truncateString = ({
const words = value.split(' ');

let result = '';
for (const word of words) {
words.forEach((word, index) => {
if (index === 0) {
// Skip the first word
result = word;
return;
}
if (result.length + word.length + 1 > maxChar) {
break;
return;
}
result += (result ? ' ' : '') + word;
}
result += ' ' + word;
});

return result + '...';
};

0 comments on commit a7f1725

Please sign in to comment.