Older/WebApplication/NavigationBar.cpp
amass ab2fe4f492
All checks were successful
Deploy / Build (push) Successful in 7m42s
improve wt code.
2024-12-21 13:35:12 +08:00

53 lines
1.6 KiB
C++

#include "NavigationBar.h"
#include <format>
constexpr auto Burger = R"(
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
)";
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>
</div>
</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');
}}
)";
NavigationBar::NavigationBar() : Wt::WTemplate(Template) {
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()));
}