refactor: bring back collapse button (#38742)

This commit is contained in:
Saqib Ansari 2026-04-23 11:26:20 +05:30 committed by GitHub
parent 1cf89c9bc9
commit 588112b833
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 60 additions and 7 deletions

View file

@ -55,17 +55,25 @@
aria-label="{{ __("User Menu") }}" aria-label="{{ __("User Menu") }}"
> >
<div> {{ avatar }} </div> <div> {{ avatar }} </div>
<div class="avatar-name-email ml-2 text-small overflow-hidden w-75"> <div class="avatar-name-email text-small overflow-hidden w-75" style="margin-left: 8px;">
<span class="d-block text-truncate"> <span class="d-block text-truncate">
{{ frappe.session.user_fullname }} {{ frappe.session.user_fullname }}
</span> </span>
<span class="d-block text-secondary text-truncate"> <span class="d-block text-secondary text-truncate" style="margin-top: -1px;">
{{ frappe.session.user_email }} {{ frappe.session.user_email }}
</span> </span>
</div> </div>
</a> </a>
</div> </div>
<div class="sidebar-bottom-actions d-flex align-items-center justify-content-between mt-2" style="padding: 0;">
<button class="about-sidebar-link btn btn-ghost btn-xs">
{%= frappe.utils.icon("info" , "sm", "", "", "text-ink-gray-7 current-color", true)%}
</button>
<button class="collapse-sidebar-link btn btn-ghost btn-xs">
{%= frappe.utils.icon("panel-right-open" , "sm", "", "", "text-ink-gray-7 current-color", true)%}
</button>
</div>
</div> </div>
<div class="sidebar-resize-handle"></div> <div class="sidebar-resize-handle"></div>
</div> </div>

View file

@ -336,7 +336,7 @@ frappe.ui.Sidebar = class Sidebar {
this.wrapper = $( this.wrapper = $(
frappe.render_template("sidebar", { frappe.render_template("sidebar", {
expanded: this.sidebar_expanded, expanded: this.sidebar_expanded,
avatar: frappe.avatar(frappe.session.user, "avatar-medium"), avatar: frappe.avatar(frappe.session.user, "avatar-medium-2"),
navbar_settings: frappe.boot.navbar_settings, navbar_settings: frappe.boot.navbar_settings,
}) })
).prependTo("body"); ).prependTo("body");
@ -346,6 +346,14 @@ frappe.ui.Sidebar = class Sidebar {
this.toggle_width(); this.toggle_width();
}); });
this.wrapper.find(".body-sidebar .collapse-sidebar-link").on("click", () => {
this.toggle_width();
});
this.wrapper.find(".body-sidebar .about-sidebar-link").on("click", () => {
frappe.ui.toolbar.show_about();
});
this.wrapper.find(".overlay").on("click", () => { this.wrapper.find(".overlay").on("click", () => {
this.close(); this.close();
}); });
@ -434,6 +442,8 @@ frappe.ui.Sidebar = class Sidebar {
} }
make_sidebar() { make_sidebar() {
this.empty(); this.empty();
this.wrapper.find(".collapse-sidebar-link").removeClass("hidden");
this.wrapper.find(".about-sidebar-link").removeClass("hidden");
if (this.editor.edit_mode) { if (this.editor.edit_mode) {
this.create_sidebar(this.editor.new_sidebar_items); this.create_sidebar(this.editor.new_sidebar_items);
} else { } else {
@ -461,6 +471,8 @@ frappe.ui.Sidebar = class Sidebar {
"<div class='flex' style='padding: 30px'> No Sidebar Items </div>" "<div class='flex' style='padding: 30px'> No Sidebar Items </div>"
); );
this.wrapper.find(".sidebar-items").append(no_items_message); this.wrapper.find(".sidebar-items").append(no_items_message);
this.wrapper.find(".collapse-sidebar-link").addClass("hidden");
this.wrapper.find(".about-sidebar-link").addClass("hidden");
} }
if (this.edit_mode) { if (this.edit_mode) {
$(".edit-menu").removeClass("hidden"); $(".edit-menu").removeClass("hidden");
@ -563,21 +575,30 @@ frappe.ui.Sidebar = class Sidebar {
} }
expand_sidebar() { expand_sidebar() {
let direction;
if (this.sidebar_expanded) { if (this.sidebar_expanded) {
this.wrapper.addClass("expanded"); this.wrapper.addClass("expanded");
direction = "right";
$('[data-toggle="tooltip"]').tooltip("dispose"); $('[data-toggle="tooltip"]').tooltip("dispose");
this.wrapper.find(".avatar-name-email").show(); this.wrapper.find(".avatar-name-email").show();
this.wrapper.find(".about-sidebar-link").show();
} else { } else {
this.wrapper.removeClass("expanded"); this.wrapper.removeClass("expanded");
direction = "left";
$('[data-toggle="tooltip"]').tooltip({ $('[data-toggle="tooltip"]').tooltip({
boundary: "window", boundary: "window",
container: "body", container: "body",
trigger: "hover", trigger: "hover",
}); });
this.wrapper.find(".avatar-name-email").hide(); this.wrapper.find(".avatar-name-email").hide();
this.wrapper.find(".about-sidebar-link").hide();
} }
localStorage.setItem("sidebar-expanded", this.sidebar_expanded); localStorage.setItem("sidebar-expanded", this.sidebar_expanded);
this.wrapper
.find(".body-sidebar .collapse-sidebar-link")
.find("use")
.attr("href", `#icon-panel-${direction}-open`);
this.sidebar_header.toggle_width(this.sidebar_expanded); this.sidebar_header.toggle_width(this.sidebar_expanded);
$(document).trigger("sidebar-expand", { $(document).trigger("sidebar-expand", {
sidebar_expand: this.sidebar_expanded, sidebar_expand: this.sidebar_expanded,

View file

@ -116,6 +116,14 @@
} }
} }
.avatar-medium-2 {
width: 32px;
height: 32px;
.standard-image {
@include get_textstyle("base", "regular");
}
}
.avatar-large { .avatar-large {
width: 64px; width: 64px;
height: 64px; height: 64px;

View file

@ -72,7 +72,7 @@
} }
.body-sidebar-bottom { .body-sidebar-bottom {
padding: 7px; padding: 0px;
width: 100%; width: 100%;
} }
@ -153,8 +153,9 @@
} }
.nav-item { .nav-item {
margin-left: -5px; padding: 4px 0px;
} }
.standard-items-sections { .standard-items-sections {
.dropdown-notifications { .dropdown-notifications {
.notifications-list { .notifications-list {
@ -175,8 +176,24 @@
} }
} }
.collapse-sidebar-link {
text-decoration: none;
font-size: var(--text-sm);
display: flex;
align-items: center;
svg {
margin: 0px;
flex: 0 0 auto;
}
span {
margin-left: 10px;
@include truncate();
}
@include transition(all, 0.3s, cubic-bezier(0.4, 0, 0.2, 1));
}
.nav-item { .nav-item {
margin-left: -5px; padding: 4px 8px;
} }
.dropdown-navbar-user { .dropdown-navbar-user {
@ -185,7 +202,6 @@
} }
.sidebar-user-button { .sidebar-user-button {
padding: var(--padding-sm);
border-radius: var(--border-radius-sm); border-radius: var(--border-radius-sm);
} }
} }