Skip to content

Commit

Permalink
fix long titles
Browse files Browse the repository at this point in the history
  • Loading branch information
shahednasser committed Aug 14, 2024
1 parent c355f27 commit 46f6667
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// @refresh reset

import React, { useEffect, useRef, useState } from "react"
import React, { useEffect, useMemo, useRef, useState } from "react"
import { SidebarItemCategory as SidebarItemCategoryType } from "types"
import { Loading, SidebarItem, useSidebar } from "../../../.."
import clsx from "clsx"
Expand Down Expand Up @@ -48,6 +48,11 @@ export const SidebarItemCategory = ({
item.onOpen?.()
}

const isTitleOneWord = useMemo(
() => item.title.split(" ").length === 1,
[item.title]
)

return (
<div className={clsx("my-docs_0.75 w-full relative", className)}>
<div className="px-docs_0.75">
Expand All @@ -57,7 +62,8 @@ export const SidebarItemCategory = ({
"flex justify-between items-center gap-docs_0.5",
"text-medusa-fg-muted",
"cursor-pointer relative",
"z-[2] break-words"
"z-[2]",
!isTitleOneWord && "break-words"
)}
tabIndex={-1}
onClick={() => {
Expand All @@ -67,7 +73,14 @@ export const SidebarItemCategory = ({
setOpen((prev) => !prev)
}}
>
<span className="text-compact-x-small-plus">{item.title}</span>
<span
className={clsx(
"text-compact-x-small-plus",
isTitleOneWord && "truncate"
)}
>
{item.title}
</span>
{item.additionalElms}
{!item.additionalElms && (
<>
Expand Down
12 changes: 10 additions & 2 deletions www/packages/docs-ui/src/components/Sidebar/Item/Link/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,20 @@ export const SidebarItemLink = ({
return !item.isChildSidebar && (item.children?.length || 0) > 0
}, [item.children])

const isTitleOneWord = useMemo(
() => item.title.split(" ").length === 1,
[item.title]
)

return (
<li ref={ref}>
<span className="block px-docs_0.75">
<Link
href={item.isPathHref ? item.path : `#${item.path}`}
className={clsx(
"py-docs_0.25 px-docs_0.5",
"block w-full rounded-docs_sm break-words",
"block w-full rounded-docs_sm",
!isTitleOneWord && "break-words",
active && [
"bg-medusa-bg-base",
"shadow-elevation-card-rest dark:shadow-elevation-card-rest-dark",
Expand All @@ -112,7 +118,9 @@ export const SidebarItemLink = ({
shallow={!item.isPathHref}
{...item.linkProps}
>
<span>{item.title}</span>
<span className={clsx(isTitleOneWord && "truncate")}>
{item.title}
</span>
{item.additionalElms}
</Link>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,19 @@ export const SidebarItemSubCategory = ({
return item.children?.length || 0 > 0
}, [item.children])

const isTitleOneWord = useMemo(
() => item.title.split(" ").length === 1,
[item.title]
)

return (
<li ref={ref}>
<span className="block px-docs_0.75">
<span
className={clsx(
"py-docs_0.25 px-docs_0.5",
"block w-full break-words",
"block w-full",
!isTitleOneWord && "break-words",
active && [
"rounded-docs_sm",
"shadow-borders-base dark:shadow-borders-base-dark",
Expand All @@ -110,7 +116,9 @@ export const SidebarItemSubCategory = ({
className
)}
>
<span>{item.title}</span>
<span className={clsx(isTitleOneWord && "truncate")}>
{item.title}
</span>
{item.additionalElms}
</span>
</span>
Expand Down

0 comments on commit 46f6667

Please sign in to comment.