numerus/web/template/app.gohtml

55 lines
1.8 KiB
Plaintext
Raw Normal View History

<!doctype html>
<html lang="{{ currentLocale }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ template "title" . }} — Numerus</title>
2023-01-17 21:28:47 +00:00
<link rel="stylesheet" type="text/css" media="screen" href="/static/numerus.css">
Reimplement the multiselect as a custom element What i really set off on was to refactor the multiselect’s x-data context to a separate JavaScript file. I did not see the need at first, thinking that it would not matter because it was used only in a template and i was not duplicating the code in my files. However, i then realized that having the context in the template means the visitor has to download it each and every time it accesses a form with a multiselect, even if nothing changed, and, worse, it would download it multiple times if there were many multiselect controls. It makes more sense to put all that into a file that the browser would only download and parse once, if the proper caching is set. Once i realized that, it was a shame that AlpineJS has no way to do the same for the HTML structure[0], for the exact same reasons: not wanting to download many times the same extra <template> and other markup required to build the control for JavaScript users. And then i remembered that this is supposed to be custom element’s main selling point. At first i tried to create a shadow DOW to replace the <select> with the same <div> and <ul> that i used with Alpine, but it turns out that <select> is not one of the allowed elements that can have a shadow root attached[0]. Therefore, i changed the custom element to extend the <div> for the <select> and <label> instead—the same element that had the x-init context—, but i would have to define or include all the styles inside the shadow DOM, and bring the lang attribute, for it to look like it did before. Out with the shadow DOM, and modify the <div>’s contents instead. At this point the code was so far removed from the declarative way that AlpineJS promotes that i did not see much value on using it, except for its reactivity. But, given that this is such a small component, at the end decided to write it all in plain JavaScript. It is more code, at least looking only at the code i had to write, but i love how i only have to add an is="numerus-multiselect" attribute to HTML for it to work. [0]: https://github.com/alpinejs/alpine/discussions/1205 [1]: https://developer.mozilla.org/en-US/docs/Web/API/Element/attachShadow
2023-03-17 13:55:12 +00:00
<script type="module" src="/static/numerus.js"></script>
</head>
<body>
2023-01-17 21:28:47 +00:00
<header>
<h1><img src="/static/numerus.svg" alt="Numerus" width="261" height="33"></h1>
<details id="profile-menu" class="menu">
<summary>
<i class="ri-eye-close-line ri-3x"></i>
</summary>
<ul role="menu" class="action-menu">
2023-01-22 21:30:15 +00:00
<li role="presentation">
<a role="menuitem" href="{{ companyURI "/profile" }}">
<i class="ri-account-circle-line"></i>
{{( pgettext "Account" "menu" )}}
</a>
</li>
<li role="presentation">
<a role="menuitem" href="{{ companyURI "/tax-details" }}">
<i class="ri-vip-diamond-line"></i>
{{( pgettext "Tax Details" "menu" )}}
</a>
2023-01-22 21:30:15 +00:00
</li>
<li role="presentation">
<form method="POST" action="/logout">
{{ csrfToken }}
<button type="submit" role="menuitem">
<i class="ri-logout-circle-line"></i>
{{( pgettext "Logout" "action" )}}
</button>
</form>
2023-01-22 21:30:15 +00:00
</li>
2023-01-17 21:28:47 +00:00
</ul>
</details>
2023-01-17 21:28:47 +00:00
</header>
<nav aria-label="{{( pgettext "Main" "title" )}}">
<ul>
2023-01-31 12:29:56 +00:00
<li><a href="{{ companyURI "/" }}">{{( pgettext "Dashboard" "nav" )}}</a></li>
2023-02-11 21:16:48 +00:00
<li><a href="{{ companyURI "/invoices" }}">{{( pgettext "Invoices" "nav" )}}</a></li>
<li><a href="{{ companyURI "/products" }}">{{( pgettext "Products" "nav" )}}</a></li>
<li><a href="{{ companyURI "/contacts" }}">{{( pgettext "Contacts" "nav" )}}</a></li>
</ul>
</nav>
2023-01-17 21:28:47 +00:00
<main>
{{- template "content" . }}
2023-01-17 21:28:47 +00:00
</main>
</body>
</html>