Skip to content

Commit 1b47cc8

Browse files
committed
settings: improve menu rendering especially in collapsed mode
1 parent 233a7fe commit 1b47cc8

File tree

1 file changed

+26
-35
lines changed

1 file changed

+26
-35
lines changed

src/packages/frontend/account/account-page.tsx

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ import { UpgradesPage } from "./upgrades/upgrades-page";
8989

9090
export const ACCOUNT_SETTINGS_ICON_NAME: IconName = "settings";
9191

92+
const ACCOUNT_MENU_INLINE_CSS = `
93+
.account-menu-inline-collapsed .ant-menu-item,
94+
.account-menu-inline-collapsed .ant-menu-submenu-title {
95+
padding-inline: 0px;
96+
text-align: center;
97+
}
98+
.account-menu-inline-collapsed .ant-menu-submenu-title {
99+
padding-right: 20px;
100+
}
101+
.account-menu-inline-collapsed .ant-menu-submenu-arrow {
102+
right: 5px;
103+
}
104+
`;
105+
92106
// Type for valid menu keys
93107
type MenuKey =
94108
| "settings"
@@ -494,25 +508,26 @@ export const AccountPage: React.FC = () => {
494508
});
495509
}
496510

511+
function visibleLabel(label) {
512+
return hidden ? <span>{label.props.children[0]}</span> : label;
513+
}
514+
497515
// Process tabs to handle nested children for sub-tabs
498516
const children = {};
499517
const titles = {}; // Always store full labels for renderTitle()
500518
for (const tab of tabs) {
501519
if (tab.type == "divider") {
502520
continue;
503521
}
522+
const originalLabel = tab.label;
523+
titles[tab.key] = originalLabel;
524+
tab.label = visibleLabel(originalLabel);
525+
504526
if (Array.isArray(tab.children)) {
505527
// Handle nested submenus generically (preferences, billing, etc.)
506528
const subTabs = tab.children;
507529
tab.children = subTabs.map((subTab) => {
508-
// When collapsed, show only the icon; otherwise show full label.
509-
const label = hidden ? (
510-
<span style={{ paddingLeft: "5px" }}>
511-
{subTab.label.props.children[0]}
512-
</span>
513-
) : (
514-
subTab.label
515-
);
530+
const label = visibleLabel(subTab.label);
516531
return {
517532
key: subTab.key,
518533
label,
@@ -524,34 +539,8 @@ export const AccountPage: React.FC = () => {
524539
children[subTab.key] = subTab.children;
525540
titles[subTab.key] = subTab.label; // Always store original full label
526541
}
527-
} else if (tab.key === "settings" || tab.key === "profile") {
528-
// Handle settings and profile as top-level pages
529-
// Store original full label for renderTitle()
530-
const originalLabel = tab.label;
531-
// Extract just the icon (first child) from the span when hidden
532-
tab.label = hidden ? (
533-
<span style={{ paddingLeft: "5px" }}>
534-
{tab.label.props.children[0]}
535-
</span>
536-
) : (
537-
tab.label
538-
);
539-
children[tab.key] = tab.children;
540-
titles[tab.key] = originalLabel; // Store original label
541-
delete tab.children;
542542
} else {
543-
// Store original full label for renderTitle()
544-
const originalLabel = tab.label;
545-
// Extract just the icon (first child) from the span when hidden
546-
tab.label = hidden ? (
547-
<span style={{ paddingLeft: "5px" }}>
548-
{tab.label.props.children[0]}
549-
</span>
550-
) : (
551-
tab.label
552-
);
553543
children[tab.key] = tab.children;
554-
titles[tab.key] = originalLabel; // Store original label
555544
delete tab.children;
556545
}
557546
}
@@ -612,6 +601,7 @@ export const AccountPage: React.FC = () => {
612601
}}
613602
>
614603
<Menu
604+
className={hidden ? "account-menu-inline-collapsed" : undefined}
615605
openKeys={openKeys}
616606
onOpenChange={handleOpenChange}
617607
mode="inline"
@@ -624,7 +614,7 @@ export const AccountPage: React.FC = () => {
624614
}
625615
inlineIndent={hidden ? 0 : 24}
626616
style={{
627-
width: hidden ? 50 : 200,
617+
width: hidden ? 50 : 220,
628618
background: "#00000005",
629619
flex: "1 1 auto",
630620
overflowY: "auto",
@@ -677,6 +667,7 @@ export const AccountPage: React.FC = () => {
677667

678668
return (
679669
<div className="smc-vfill">
670+
<style>{ACCOUNT_MENU_INLINE_CSS}</style>
680671
{is_logged_in && !get_api_key ? (
681672
render_logged_in_view()
682673
) : (

0 commit comments

Comments
 (0)