mirror of
https://github.com/discourse/discourse.git
synced 2025-03-04 18:29:20 +00:00
DEV: Support new header button/icon ordering APIs on widget header (#26264)
This commit is contained in:
parent
d0d4a363d4
commit
dd1a14ac6c
@ -240,7 +240,7 @@ createWidget("header-icons", {
|
|||||||
init() {
|
init() {
|
||||||
registerWidgetShim(
|
registerWidgetShim(
|
||||||
"extra-icon",
|
"extra-icon",
|
||||||
"div.wrapper",
|
"span.wrapper",
|
||||||
hbs`<LegacyHeaderIconShim @component={{@data.component}} />`
|
hbs`<LegacyHeaderIconShim @component={{@data.component}} />`
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -253,49 +253,48 @@ createWidget("header-icons", {
|
|||||||
const icons = [];
|
const icons = [];
|
||||||
|
|
||||||
const resolvedIcons = _extraHeaderIcons.resolve();
|
const resolvedIcons = _extraHeaderIcons.resolve();
|
||||||
|
|
||||||
resolvedIcons.forEach((icon) => {
|
resolvedIcons.forEach((icon) => {
|
||||||
if (["search", "user-menu", "hamburger"].includes(icon.key)) {
|
if (icon.key === "search") {
|
||||||
return;
|
icons.push(
|
||||||
|
this.attach("header-dropdown", {
|
||||||
|
title: "search.title",
|
||||||
|
icon: "search",
|
||||||
|
iconId: SEARCH_BUTTON_ID,
|
||||||
|
action: "toggleSearchMenu",
|
||||||
|
active: this.search.visible,
|
||||||
|
href: getURL("/search"),
|
||||||
|
classNames: ["search-dropdown"],
|
||||||
|
})
|
||||||
|
);
|
||||||
|
} else if (icon.key === "user-menu" && attrs.user) {
|
||||||
|
icons.push(
|
||||||
|
this.attach("user-dropdown", {
|
||||||
|
active: attrs.userVisible,
|
||||||
|
action: "toggleUserMenu",
|
||||||
|
user: attrs.user,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
} else if (
|
||||||
|
icon.key === "hamburger" &&
|
||||||
|
(!attrs.sidebarEnabled || this.site.mobileView)
|
||||||
|
) {
|
||||||
|
icons.push(
|
||||||
|
this.attach("header-dropdown", {
|
||||||
|
title: "hamburger_menu",
|
||||||
|
icon: "bars",
|
||||||
|
iconId: "toggle-hamburger-menu",
|
||||||
|
active: attrs.hamburgerVisible,
|
||||||
|
action: "toggleHamburger",
|
||||||
|
href: "",
|
||||||
|
classNames: ["hamburger-dropdown"],
|
||||||
|
})
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
icons.push(this.attach("extra-icon", { component: icon.value }));
|
||||||
}
|
}
|
||||||
icons.push(this.attach("extra-icon", { component: icon.value }));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const search = this.attach("header-dropdown", {
|
|
||||||
title: "search.title",
|
|
||||||
icon: "search",
|
|
||||||
iconId: SEARCH_BUTTON_ID,
|
|
||||||
action: "toggleSearchMenu",
|
|
||||||
active: this.search.visible,
|
|
||||||
href: getURL("/search"),
|
|
||||||
classNames: ["search-dropdown"],
|
|
||||||
});
|
|
||||||
|
|
||||||
icons.push(search);
|
|
||||||
|
|
||||||
const hamburger = this.attach("header-dropdown", {
|
|
||||||
title: "hamburger_menu",
|
|
||||||
icon: "bars",
|
|
||||||
iconId: "toggle-hamburger-menu",
|
|
||||||
active: attrs.hamburgerVisible,
|
|
||||||
action: "toggleHamburger",
|
|
||||||
href: "",
|
|
||||||
classNames: ["hamburger-dropdown"],
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!attrs.sidebarEnabled || this.site.mobileView) {
|
|
||||||
icons.push(hamburger);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (attrs.user) {
|
|
||||||
icons.push(
|
|
||||||
this.attach("user-dropdown", {
|
|
||||||
active: attrs.userVisible,
|
|
||||||
action: "toggleUserMenu",
|
|
||||||
user: attrs.user,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return icons;
|
return icons;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -496,7 +495,11 @@ export default createWidget("header", {
|
|||||||
services: ["router", "search"],
|
services: ["router", "search"],
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
registerWidgetShim("extra-button", "div.wrapper", hbs`<@data.component />`);
|
registerWidgetShim(
|
||||||
|
"extra-button",
|
||||||
|
"span.wrapper",
|
||||||
|
hbs`<@data.component />`
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
defaultState() {
|
defaultState() {
|
||||||
@ -538,13 +541,11 @@ export default createWidget("header", {
|
|||||||
const resolvedButtons = _extraHeaderButtons.resolve();
|
const resolvedButtons = _extraHeaderButtons.resolve();
|
||||||
resolvedButtons.forEach((button) => {
|
resolvedButtons.forEach((button) => {
|
||||||
if (button.key === "auth") {
|
if (button.key === "auth") {
|
||||||
return;
|
buttons.push(this.attach("header-buttons", attrs));
|
||||||
}
|
}
|
||||||
buttons.push(this.attach("extra-button", { component: button.value }));
|
buttons.push(this.attach("extra-button", { component: button.value }));
|
||||||
});
|
});
|
||||||
|
|
||||||
buttons.push(this.attach("header-buttons", attrs));
|
|
||||||
|
|
||||||
const panels = [];
|
const panels = [];
|
||||||
panels.push(h("span.header-buttons", buttons), headerIcons);
|
panels.push(h("span.header-buttons", buttons), headerIcons);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user