Older/WebApplication/NavigationBar.cpp

53 lines
1.6 KiB
C++
Raw Normal View History

2024-12-18 23:35:26 +08:00
#include "NavigationBar.h"
2024-12-21 13:35:12 +08:00
#include <format>
2024-12-18 23:35:26 +08:00
2024-12-21 13:35:12 +08:00
constexpr auto Burger = R"(
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
)";
2024-12-18 23:35:26 +08:00
2024-12-21 13:35:12 +08:00
constexpr auto Menu = R"(
<div class="bulma-navbar-start">
<a class="bulma-navbar-item">Home</a>
</div>
<div class="bulma-navbar-end">
<div class="bulma-navbar-item">
<div class="bulma-buttons">
<a class="bulma-button bulma-is-primary">
<strong></strong>
</a>
<a class="bulma-button bulma-is-light">登录</a>
</div>
2024-12-18 23:35:26 +08:00
</div>
2024-12-21 13:35:12 +08:00
</div>
)";
constexpr auto Template = R"(
<div class="bulma-navbar-brand">
<a class="bulma-navbar-item" href="https://amass.fun">子非鱼</a>
${navbar-burger role="button" class="bulma-navbar-burger" aria-label="menu" aria-expanded="false"}
</div>
${navbar-menu class="bulma-navbar-menu"}
)";
constexpr auto JS = R"(
function(o) {{
{}.classList.toggle('bulma-is-active');
{}.classList.toggle('bulma-is-active');
}}
2024-12-18 23:35:26 +08:00
)";
NavigationBar::NavigationBar() : Wt::WTemplate(Template) {
2024-12-21 13:35:12 +08:00
setHtmlTagName("nav");
setStyleClass("bulma-navbar");
setAttributeValue("role", "navigation");
setAttributeValue("aria-label", "main navigation");
auto navbarBurger = bindWidget("navbar-burger", std::make_unique<Wt::WTemplate>(Burger));
navbarBurger->setHtmlTagName("a");
auto navbarMenu = bindWidget("navbar-menu", std::make_unique<Wt::WTemplate>(Menu));
navbarBurger->clicked().connect(std::format(JS, navbarBurger->id(), navbarMenu->id()));
2024-12-18 23:35:26 +08:00
}