Skip to content

Commit 7f14e20

Browse files
authored
fix(sidebar): Move Alpha and Beta badges next to labels (#3456)
1 parent 3c259f9 commit 7f14e20

3 files changed

Lines changed: 20 additions & 10 deletions

File tree

packages/ui/src/features/sidebar/components/SidebarItem.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,19 @@ interface SidebarItemProps {
2525
onDoubleClick?: () => void;
2626
onContextMenu?: (e: React.MouseEvent) => void;
2727
action?: SidebarItemAction;
28+
/** Hugs the label but never truncates with it; pushes endContent right. */
29+
badge?: React.ReactNode;
2830
endContent?: React.ReactNode;
2931
disabled?: boolean;
3032
}
3133

32-
function SidebarItemLabel({ label }: { label: React.ReactNode }) {
34+
function SidebarItemLabel({
35+
label,
36+
grow,
37+
}: {
38+
label: React.ReactNode;
39+
grow: boolean;
40+
}) {
3341
const canTooltip = typeof label === "string" || typeof label === "number";
3442

3543
const measureRef = useCallback((el: HTMLSpanElement | null) => {
@@ -44,7 +52,7 @@ function SidebarItemLabel({ label }: { label: React.ReactNode }) {
4452
}, []);
4553

4654
const span = (
47-
<span ref={measureRef} className="min-w-0 flex-1 truncate">
55+
<span ref={measureRef} className={cn("min-w-0 truncate", grow && "flex-1")}>
4856
{label}
4957
</span>
5058
);
@@ -76,6 +84,7 @@ export function SidebarItem({
7684
onClick,
7785
onDoubleClick,
7886
onContextMenu,
87+
badge,
7988
endContent,
8089
disabled,
8190
}: SidebarItemProps) {
@@ -108,7 +117,12 @@ export function SidebarItem({
108117
) : null}
109118
<span className="flex min-w-0 flex-1 flex-col">
110119
<span className="flex min-h-[18px] items-center gap-1">
111-
<SidebarItemLabel label={label} />
120+
<SidebarItemLabel label={label} grow={!badge} />
121+
{badge ? (
122+
<span className="mr-auto ml-1 flex shrink-0 items-center">
123+
{badge}
124+
</span>
125+
) : null}
112126
{endContent}
113127
</span>
114128
{subtitle ? (

packages/ui/src/features/sidebar/components/items/HomeItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ export function HomeItem({
2727
/>
2828
</>
2929
}
30+
badge={<Badge variant="info">Alpha</Badge>}
3031
isActive={isActive}
3132
onClick={onClick}
32-
endContent={<Badge variant="info">Alpha</Badge>}
3333
/>
3434
);
3535
}

packages/ui/src/features/sidebar/components/items/InboxItem.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,10 @@ export function InboxItem({
4141
/>
4242
</>
4343
}
44+
badge={<Badge variant="warning">Beta</Badge>}
4445
isActive={isActive}
4546
onClick={onClick}
46-
endContent={
47-
<>
48-
<Badge variant="warning">Beta</Badge>
49-
<SidebarKbdHint keys={SHORTCUTS.INBOX} />
50-
</>
51-
}
47+
endContent={<SidebarKbdHint keys={SHORTCUTS.INBOX} />}
5248
/>
5349
</div>
5450
</Tooltip>

0 commit comments

Comments
 (0)