fjkit 0.1.0.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fjkit/__init__.py +49 -0
- fjkit/auth/__init__.py +54 -0
- fjkit/auth/csrf.py +88 -0
- fjkit/auth/errors.py +31 -0
- fjkit/auth/plugin.py +496 -0
- fjkit/auth/sources.py +24 -0
- fjkit/auth/stores.py +141 -0
- fjkit/auth/types.py +141 -0
- fjkit/cli/__init__.py +67 -0
- fjkit/cli/build_css.py +135 -0
- fjkit/cli/check.py +193 -0
- fjkit/cli/eject.py +562 -0
- fjkit/cli/ejected.py +202 -0
- fjkit/cli/vocabulary.py +85 -0
- fjkit/config.py +130 -0
- fjkit/errors.py +156 -0
- fjkit/flash.py +189 -0
- fjkit/forms.py +145 -0
- fjkit/htmx.py +76 -0
- fjkit/icons.py +60 -0
- fjkit/messages.py +227 -0
- fjkit/mounting.py +72 -0
- fjkit/plugins.py +223 -0
- fjkit/py.typed +0 -0
- fjkit/rendering.py +554 -0
- fjkit/signing.py +63 -0
- fjkit/static/brand/torii-bolt.png +0 -0
- fjkit/static/dist/fjkit-luma.css +2 -0
- fjkit/static/dist/fjkit-lyra.css +2 -0
- fjkit/static/dist/fjkit-maia.css +2 -0
- fjkit/static/dist/fjkit-mira.css +2 -0
- fjkit/static/dist/fjkit-nova.css +2 -0
- fjkit/static/dist/fjkit-rhea.css +2 -0
- fjkit/static/dist/fjkit-sera.css +2 -0
- fjkit/static/dist/fjkit-vega.css +2 -0
- fjkit/static/icons/lucide.json +1 -0
- fjkit/static/js/errors.js +117 -0
- fjkit/static/js/multiselect.js +126 -0
- fjkit/static/js/reveal.js +51 -0
- fjkit/static/js/select.js +113 -0
- fjkit/static/src/fjkit.css +385 -0
- fjkit/static/vendor/basecoat/base/base.css +136 -0
- fjkit/static/vendor/basecoat/basecoat-base.css +2 -0
- fjkit/static/vendor/basecoat/basecoat-components.css +39 -0
- fjkit/static/vendor/basecoat/basecoat-luma.css +2 -0
- fjkit/static/vendor/basecoat/basecoat-lyra.css +2 -0
- fjkit/static/vendor/basecoat/basecoat-maia.css +2 -0
- fjkit/static/vendor/basecoat/basecoat-mira.css +2 -0
- fjkit/static/vendor/basecoat/basecoat-nova.css +2 -0
- fjkit/static/vendor/basecoat/basecoat-rhea.css +2 -0
- fjkit/static/vendor/basecoat/basecoat-sera.css +2 -0
- fjkit/static/vendor/basecoat/basecoat-vega.css +2 -0
- fjkit/static/vendor/basecoat/basecoat.all.css +1 -0
- fjkit/static/vendor/basecoat/basecoat.css +1 -0
- fjkit/static/vendor/basecoat/components/accordion.css +27 -0
- fjkit/static/vendor/basecoat/components/alert.css +38 -0
- fjkit/static/vendor/basecoat/components/avatar.css +47 -0
- fjkit/static/vendor/basecoat/components/badge.css +6 -0
- fjkit/static/vendor/basecoat/components/breadcrumb.css +30 -0
- fjkit/static/vendor/basecoat/components/button-group.css +54 -0
- fjkit/static/vendor/basecoat/components/button.css +6 -0
- fjkit/static/vendor/basecoat/components/card.css +26 -0
- fjkit/static/vendor/basecoat/components/chart.css +56 -0
- fjkit/static/vendor/basecoat/components/checkbox.css +12 -0
- fjkit/static/vendor/basecoat/components/collapsible.css +21 -0
- fjkit/static/vendor/basecoat/components/combobox.css +99 -0
- fjkit/static/vendor/basecoat/components/command.css +140 -0
- fjkit/static/vendor/basecoat/components/dialog.css +101 -0
- fjkit/static/vendor/basecoat/components/drawer.css +89 -0
- fjkit/static/vendor/basecoat/components/dropdown-menu.css +56 -0
- fjkit/static/vendor/basecoat/components/empty.css +26 -0
- fjkit/static/vendor/basecoat/components/field.css +82 -0
- fjkit/static/vendor/basecoat/components/form.css +9 -0
- fjkit/static/vendor/basecoat/components/input-group.css +74 -0
- fjkit/static/vendor/basecoat/components/input.css +32 -0
- fjkit/static/vendor/basecoat/components/item.css +50 -0
- fjkit/static/vendor/basecoat/components/kbd.css +6 -0
- fjkit/static/vendor/basecoat/components/label.css +13 -0
- fjkit/static/vendor/basecoat/components/native-select.css +12 -0
- fjkit/static/vendor/basecoat/components/popover.css +107 -0
- fjkit/static/vendor/basecoat/components/progress.css +14 -0
- fjkit/static/vendor/basecoat/components/radio.css +11 -0
- fjkit/static/vendor/basecoat/components/range.css +50 -0
- fjkit/static/vendor/basecoat/components/scrollbar.css +46 -0
- fjkit/static/vendor/basecoat/components/select.css +64 -0
- fjkit/static/vendor/basecoat/components/sidebar.css +101 -0
- fjkit/static/vendor/basecoat/components/skeleton.css +6 -0
- fjkit/static/vendor/basecoat/components/switch.css +8 -0
- fjkit/static/vendor/basecoat/components/table.css +34 -0
- fjkit/static/vendor/basecoat/components/tabs.css +31 -0
- fjkit/static/vendor/basecoat/components/textarea.css +7 -0
- fjkit/static/vendor/basecoat/components/toast.css +57 -0
- fjkit/static/vendor/basecoat/components/tooltip.css +82 -0
- fjkit/static/vendor/basecoat/js/all.min.js +1 -0
- fjkit/static/vendor/basecoat/styles/luma.css +1376 -0
- fjkit/static/vendor/basecoat/styles/lyra.css +1379 -0
- fjkit/static/vendor/basecoat/styles/maia.css +1364 -0
- fjkit/static/vendor/basecoat/styles/mira.css +1373 -0
- fjkit/static/vendor/basecoat/styles/nova.css +1387 -0
- fjkit/static/vendor/basecoat/styles/rhea.css +1381 -0
- fjkit/static/vendor/basecoat/styles/sera.css +1397 -0
- fjkit/static/vendor/basecoat/styles/vega.css +1386 -0
- fjkit/static/vendor/htmx/htmx.min.js +1 -0
- fjkit/static/vendor/htmx/json-enc.js +38 -0
- fjkit/styles.py +30 -0
- fjkit/templates/errors/page.html +92 -0
- fjkit/templates/ui/attrs.html +18 -0
- fjkit/templates/ui/button.html +64 -0
- fjkit/templates/ui/data.html +362 -0
- fjkit/templates/ui/disclosure.html +89 -0
- fjkit/templates/ui/feedback.html +313 -0
- fjkit/templates/ui/form.html +595 -0
- fjkit/templates/ui/icon.html +13 -0
- fjkit/templates/ui/layout.html +189 -0
- fjkit/templates/ui/nav.html +110 -0
- fjkit/templates/ui/overlay.html +624 -0
- fjkit/templates/ui/shell.html +170 -0
- fjkit/templates/ui/sidebar.html +170 -0
- fjkit/templates/ui/table.html +427 -0
- fjkit/templates/ui/tabs.html +133 -0
- fjkit/templating.py +365 -0
- fjkit/vendored.py +46 -0
- fjkit-0.1.0.dev0.dist-info/METADATA +119 -0
- fjkit-0.1.0.dev0.dist-info/RECORD +127 -0
- fjkit-0.1.0.dev0.dist-info/WHEEL +4 -0
- fjkit-0.1.0.dev0.dist-info/entry_points.txt +2 -0
- fjkit-0.1.0.dev0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
{#
|
|
2
|
+
The document shell. Every page extends this, directly or through the app's
|
|
3
|
+
own base.html.
|
|
4
|
+
|
|
5
|
+
What it owns: the <head>, the theme flash-guard, the asset links, and the
|
|
6
|
+
header/main/footer skeleton. What it does not own: your brand, your nav, your
|
|
7
|
+
footer text — those are blocks.
|
|
8
|
+
|
|
9
|
+
Typical app base.html:
|
|
10
|
+
|
|
11
|
+
{% extends "ui/shell.html" %}
|
|
12
|
+
{% from "ui/nav.html" import brand, nav_links %}
|
|
13
|
+
|
|
14
|
+
{% block site_title %}Acme{% endblock %}
|
|
15
|
+
{% block brand %}{{ brand("Acme", url_for(request, "home"), "gauge") }}{% endblock %}
|
|
16
|
+
{% block nav %}{{ nav_links(request, [("home", "Overview")]) }}{% endblock %}
|
|
17
|
+
|
|
18
|
+
Fill the `sidebar` block instead of `nav` and the skeleton becomes a side
|
|
19
|
+
column plus a thin top bar; see the note above <body>.
|
|
20
|
+
#}
|
|
21
|
+
{% from "ui/feedback.html" import toast, toaster %}
|
|
22
|
+
{% from "ui/nav.html" import theme_toggle %}
|
|
23
|
+
{% from "ui/sidebar.html" import sidebar_trigger %}
|
|
24
|
+
{#
|
|
25
|
+
Rendered into a variable rather than straight into the page, because three
|
|
26
|
+
things downstream depend on whether the app filled it in: the aside has to
|
|
27
|
+
come first in the body, the content wrapper beside it changes shape, and the
|
|
28
|
+
header grows a toggle. Jinja cannot ask whether a block is empty, so the
|
|
29
|
+
block is captured once here and the emptiness test runs on the string.
|
|
30
|
+
|
|
31
|
+
The cost is buffering the sidebar's markup — a few hundred bytes — before the
|
|
32
|
+
response starts. The alternative is a second flag the app has to remember to
|
|
33
|
+
set, and that flag gets forgotten.
|
|
34
|
+
#}
|
|
35
|
+
{% set sidebar_slot %}{% block sidebar %}{% endblock %}{% endset %}
|
|
36
|
+
{% set has_sidebar = sidebar_slot.strip() | length > 0 -%}
|
|
37
|
+
<!doctype html>
|
|
38
|
+
<html lang="{% block lang %}en{% endblock %}" class="h-full">
|
|
39
|
+
<head>
|
|
40
|
+
<meta charset="utf-8">
|
|
41
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
42
|
+
<title>{% block title %}{% endblock %}{% block site_title_separator %} · {% endblock %}{% block site_title %}{% endblock %}</title>
|
|
43
|
+
{#
|
|
44
|
+
Theme is applied before first paint so a dark-mode reload never flashes
|
|
45
|
+
white. Basecoat's dark variant keys off `html.dark`, which is the only
|
|
46
|
+
thing this script touches.
|
|
47
|
+
#}
|
|
48
|
+
<script>
|
|
49
|
+
(() => {
|
|
50
|
+
const saved = localStorage.getItem("theme");
|
|
51
|
+
const dark = saved ? saved === "dark" : matchMedia("(prefers-color-scheme: dark)").matches;
|
|
52
|
+
document.documentElement.classList.toggle("dark", dark);
|
|
53
|
+
})();
|
|
54
|
+
</script>
|
|
55
|
+
{#
|
|
56
|
+
One stylesheet, named after the style pack `FjkitConfig.style` selected.
|
|
57
|
+
All eight ship built in the wheel; exactly one is ever requested.
|
|
58
|
+
#}
|
|
59
|
+
<link rel="stylesheet" href="{{ fjkit_static('dist/fjkit-' ~ fjkit_style ~ '.css') }}">
|
|
60
|
+
{#
|
|
61
|
+
Where an app overrides tokens. One file, plain CSS, no build — see the
|
|
62
|
+
brand section of the docs. Empty by default.
|
|
63
|
+
#}
|
|
64
|
+
{% block stylesheets %}{% endblock %}
|
|
65
|
+
{#
|
|
66
|
+
htmx's default handling: 2xx/3xx swap, 4xx/5xx do not. A 422 is read by
|
|
67
|
+
`js/errors.js` in `htmx:beforeSwap` instead; 204 is what `fjkit.errors`
|
|
68
|
+
answers a swap with when there is only a toast to raise.
|
|
69
|
+
#}
|
|
70
|
+
<meta name="htmx-config" content='{"responseHandling":[{"code":"204","swap":false},{"code":"[23]..","swap":true},{"code":"[45]..","swap":false,"error":true}]}'>
|
|
71
|
+
<script defer src="{{ fjkit_static('vendor/htmx/htmx.min.js') }}"></script>
|
|
72
|
+
<script defer src="{{ fjkit_static('vendor/basecoat/js/all.min.js') }}"></script>
|
|
73
|
+
{# Draws a 422 under the fields of the form that sent it. After htmx: it listens to htmx's events. #}
|
|
74
|
+
<script defer src="{{ fjkit_static('js/errors.js') }}"></script>
|
|
75
|
+
{% block head %}{% endblock %}
|
|
76
|
+
</head>
|
|
77
|
+
{#
|
|
78
|
+
With a sidebar, the aside is the first thing in the body and the wrapper is
|
|
79
|
+
its immediate next sibling. That sibling is the element Basecoat's CSS gives
|
|
80
|
+
the margin keeping the page clear of the fixed panel, and the margin slides
|
|
81
|
+
back to zero when the sidebar collapses. Anything placed between the two
|
|
82
|
+
loses the margin silently, so the shell owns this adjacency rather than
|
|
83
|
+
documenting it.
|
|
84
|
+
|
|
85
|
+
That layout also drops `mx-auto max-w-6xl`: `mx-auto` is a utility,
|
|
86
|
+
Basecoat's margin comes through `@apply` in the components layer, and
|
|
87
|
+
utilities win — a centred wrapper would park itself underneath the sidebar.
|
|
88
|
+
#}
|
|
89
|
+
<body class="min-h-full antialiased">
|
|
90
|
+
{{ sidebar_slot }}
|
|
91
|
+
<div class="{% if has_sidebar %}flex min-h-screen flex-col px-5{% else %}mx-auto flex min-h-screen max-w-6xl flex-col px-5{% endif %}">
|
|
92
|
+
{% block header %}
|
|
93
|
+
<header class="flex items-center gap-6 py-5">
|
|
94
|
+
{% if has_sidebar %}{% block sidebar_trigger %}{{ sidebar_trigger() }}{% endblock %}{% endif %}
|
|
95
|
+
{% block brand %}{% endblock %}
|
|
96
|
+
{% block nav %}{% endblock %}
|
|
97
|
+
<div class="ml-auto">
|
|
98
|
+
{% block header_actions %}{{ theme_toggle() }}{% endblock %}
|
|
99
|
+
</div>
|
|
100
|
+
</header>
|
|
101
|
+
{% endblock %}
|
|
102
|
+
|
|
103
|
+
<main class="flex-1 pb-16">
|
|
104
|
+
{% block content %}{% endblock %}
|
|
105
|
+
</main>
|
|
106
|
+
|
|
107
|
+
{% block footer_wrapper %}
|
|
108
|
+
<footer class="text-muted-foreground border-t py-5 text-xs">
|
|
109
|
+
{% block footer %}{% endblock %}
|
|
110
|
+
</footer>
|
|
111
|
+
{% endblock %}
|
|
112
|
+
</div>
|
|
113
|
+
|
|
114
|
+
{#
|
|
115
|
+
Where a message arrives — one raised on this response, or one that outlived
|
|
116
|
+
a redirect.
|
|
117
|
+
|
|
118
|
+
`fjkit_messages()` is a global rather than a context key, so a route passes
|
|
119
|
+
nothing in and a page that has never heard of messages still shows one.
|
|
120
|
+
`FlashPlugin` queues its cookie into the same place, which is why there is
|
|
121
|
+
one loop here and not two.
|
|
122
|
+
|
|
123
|
+
Iterating marks them delivered — see `fjkit.messages._Queue` — so this
|
|
124
|
+
`{% for %}` is load-bearing: it is what lets the flash cookie be cleared,
|
|
125
|
+
and an `{% if %}` deliberately does not count.
|
|
126
|
+
|
|
127
|
+
The region renders whether or not anything is in it. It is one empty
|
|
128
|
+
element, and keeping it always present lets a toast appear on a page that
|
|
129
|
+
did not know in advance one was coming.
|
|
130
|
+
#}
|
|
131
|
+
{% block toasts %}
|
|
132
|
+
{% call toaster() %}
|
|
133
|
+
{% for message in fjkit_messages() %}
|
|
134
|
+
{{ toast(message.title, message.text, category=message.category) }}
|
|
135
|
+
{% endfor %}
|
|
136
|
+
{% endcall %}
|
|
137
|
+
{% endblock %}
|
|
138
|
+
|
|
139
|
+
{#
|
|
140
|
+
A message raised on a response that only swapped a fragment has nowhere to
|
|
141
|
+
render: the toaster is on the page, not in the fragment. `fjkit.messages`
|
|
142
|
+
sends those as `HX-Trigger`, and this turns the event back into a toast.
|
|
143
|
+
|
|
144
|
+
Two reasons it is a listener rather than markup. htmx reads `HX-Trigger` in
|
|
145
|
+
`handleAjaxResponse` before it consults `responseHandling`, so this path
|
|
146
|
+
still works on a 500 — the response that most needs to say something. And
|
|
147
|
+
Basecoat exposes its toaster as a method on the element
|
|
148
|
+
(`#toaster.toast({…})`) rather than as a document-level event listener, so
|
|
149
|
+
something has to make the call.
|
|
150
|
+
|
|
151
|
+
`detail.messages`, because `fjkit.messages` sends an object. htmx hands a
|
|
152
|
+
JSON object straight through as `event.detail` and wraps anything else,
|
|
153
|
+
arrays included, as `{value: …}` — a difference invisible in a test and
|
|
154
|
+
silent in a browser, where it shows up as an empty toast.
|
|
155
|
+
|
|
156
|
+
~180 bytes. CHARTER §7 budgets client JS per page; this listener and
|
|
157
|
+
`js/errors.js` in the head are what fjkit adds beyond the two vendored
|
|
158
|
+
files. `errors.js` dispatches this same event for a message with no field
|
|
159
|
+
to land on, so there is one path into the toaster and not two.
|
|
160
|
+
#}
|
|
161
|
+
<script>
|
|
162
|
+
document.body.addEventListener({{ fjkit_toast_event | tojson }}, (event) => {
|
|
163
|
+
const toaster = document.getElementById("toaster");
|
|
164
|
+
if (!toaster || !toaster.toast) return;
|
|
165
|
+
for (const message of event.detail?.messages ?? []) toaster.toast(message);
|
|
166
|
+
});
|
|
167
|
+
</script>
|
|
168
|
+
{% block scripts %}{% endblock %}
|
|
169
|
+
</body>
|
|
170
|
+
</html>
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
{#
|
|
2
|
+
The application shell's side column — 0.5's first piece.
|
|
3
|
+
|
|
4
|
+
A back office outgrows a header bar at about six destinations: the row runs
|
|
5
|
+
out of width, and grouping ("Workspace" / "Admin") has nowhere to live. That
|
|
6
|
+
is where an app without a sidebar component starts writing
|
|
7
|
+
`fixed inset-y-0 w-64 border-r` by hand, and the closed vocabulary is gone on
|
|
8
|
+
page one.
|
|
9
|
+
|
|
10
|
+
Basecoat already ships `.sidebar`: the CSS is in the stylesheet whether or
|
|
11
|
+
not anything renders it (CHARTER.md §7), and its JS is vendored. So this file
|
|
12
|
+
is not a new widget but the fjkit-shaped door onto one already paid for —
|
|
13
|
+
route names instead of hrefs, an icon by name, closed enumerations, and no
|
|
14
|
+
class string anywhere in the signature.
|
|
15
|
+
|
|
16
|
+
The markup contract belongs to Basecoat and is load-bearing:
|
|
17
|
+
`aside.sidebar > nav > {header, section, footer}`, `[role=group] > ul > li`,
|
|
18
|
+
and the next sibling of the aside is what gets the margin that keeps the page
|
|
19
|
+
clear of it. `ui/shell.html` owns that sibling; an app calls these macros
|
|
20
|
+
through the shell's `sidebar` block and never has to know.
|
|
21
|
+
|
|
22
|
+
{% block sidebar %}
|
|
23
|
+
{% set mark %}{{ brand("Acme", url_for(request, "home"), "gauge") }}{% endset %}
|
|
24
|
+
{% call sidebar(header=mark) %}
|
|
25
|
+
{% call sidebar_group("Workspace") %}
|
|
26
|
+
{{ sidebar_link(request, "home", "Overview", icon_name="gauge") }}
|
|
27
|
+
{% endcall %}
|
|
28
|
+
{% endcall %}
|
|
29
|
+
{% endblock %}
|
|
30
|
+
#}
|
|
31
|
+
{% from "ui/attrs.html" import attrs %}
|
|
32
|
+
{% from "ui/icon.html" import icon %}
|
|
33
|
+
|
|
34
|
+
{#
|
|
35
|
+
sidebar(id, label, side, open, header, footer, **html_attrs)
|
|
36
|
+
|
|
37
|
+
side: left | right
|
|
38
|
+
|
|
39
|
+
`header` and `footer` take pre-rendered markup, like `card`'s `actions`: a
|
|
40
|
+
call block runs its body once per slot, and the body here is the navigation —
|
|
41
|
+
always present and always the biggest part. Rendering it twice to make room
|
|
42
|
+
for a brand mark is the wrong trade.
|
|
43
|
+
|
|
44
|
+
`open` is the desktop starting state only. On a narrow screen the sidebar
|
|
45
|
+
always starts closed, because it renders there as a full-screen overlay and a
|
|
46
|
+
page that opens covered by its own navigation is a bug, not a preference.
|
|
47
|
+
Basecoat's script owns both states from then on: it sets `aria-hidden` and
|
|
48
|
+
`inert` together, so a collapsed sidebar leaves the tab order rather than
|
|
49
|
+
merely going invisible, and on a narrow screen it closes itself when a link
|
|
50
|
+
inside it is followed.
|
|
51
|
+
|
|
52
|
+
Without JavaScript, the server-rendered `aria-hidden="false"` plus Basecoat's
|
|
53
|
+
`:not([data-sidebar-initialized])` rule leaves a wide screen fully navigable
|
|
54
|
+
and hides the overlay on a narrow one. The links stay in the HTML either way,
|
|
55
|
+
so a crawler and reader mode still see them.
|
|
56
|
+
#}
|
|
57
|
+
{% macro sidebar(id="sidebar", label="Main", side="left", open=true, header=none, footer=none) -%}
|
|
58
|
+
{#
|
|
59
|
+
Closed lookup, not interpolation: `data-side="{{ side }}"` would emit
|
|
60
|
+
`data-side="middle"`, which the CSS has no rule for, and the sidebar would
|
|
61
|
+
lose its border and its margin with nothing to say why. An unknown value
|
|
62
|
+
falls back to the default instead.
|
|
63
|
+
#}
|
|
64
|
+
{%- set sides = {"left": "left", "right": "right"} -%}
|
|
65
|
+
<aside class="sidebar" id="{{ id }}" data-side="{{ sides.get(side, "left") }}"
|
|
66
|
+
aria-hidden="{{ "false" if open else "true" }}"
|
|
67
|
+
{%- if not open %} data-initial-open="false" inert{% endif %}
|
|
68
|
+
{%- if kwargs %}{{ attrs(kwargs) }}{% endif %}>
|
|
69
|
+
{#
|
|
70
|
+
The <nav> is the panel; the <aside> around it is the backdrop on a narrow
|
|
71
|
+
screen, which is why clicking it closes the sidebar. `aria-label` names
|
|
72
|
+
the landmark: a page with two navigations ("Main", "Account") needs them
|
|
73
|
+
told apart in a screen reader's landmark list, and "navigation" twice
|
|
74
|
+
does not do that.
|
|
75
|
+
#}
|
|
76
|
+
<nav aria-label="{{ label }}">
|
|
77
|
+
{%- if header %}<header>{{ header }}</header>{% endif %}
|
|
78
|
+
<section>{{ caller() }}</section>
|
|
79
|
+
{%- if footer %}<footer>{{ footer }}</footer>{% endif %}
|
|
80
|
+
</nav>
|
|
81
|
+
</aside>
|
|
82
|
+
{%- endmacro %}
|
|
83
|
+
|
|
84
|
+
{#
|
|
85
|
+
sidebar_group(title) — a labelled band of links inside the sidebar.
|
|
86
|
+
|
|
87
|
+
The label is `aria-label` on the group rather than `aria-labelledby` pointing
|
|
88
|
+
at the <h3>, because the alternative generates an id per group. A page may
|
|
89
|
+
render this macro twice — a sidebar plus an htmx-swapped copy — and those ids
|
|
90
|
+
collide; a colliding `aria-labelledby` resolves to the wrong heading rather
|
|
91
|
+
than to nothing. The string matches the visible heading, so name and label
|
|
92
|
+
still agree.
|
|
93
|
+
#}
|
|
94
|
+
{% macro sidebar_group(title=none) -%}
|
|
95
|
+
<div role="group"{% if title %} aria-label="{{ title }}"{% endif %}
|
|
96
|
+
{%- if kwargs %}{{ attrs(kwargs) }}{% endif %}>
|
|
97
|
+
{%- if title %}<h3>{{ title }}</h3>{% endif %}
|
|
98
|
+
<ul>{{ caller() }}</ul>
|
|
99
|
+
</div>
|
|
100
|
+
{%- endmacro %}
|
|
101
|
+
|
|
102
|
+
{#
|
|
103
|
+
sidebar_link(request, route, label, icon_name, **html_attrs)
|
|
104
|
+
|
|
105
|
+
A route name, not a URL — same as `nav_links`. The active state compares
|
|
106
|
+
routes instead of string-matching paths, so it stays right when a URL grows a
|
|
107
|
+
query string, and a renamed path changes in one place.
|
|
108
|
+
|
|
109
|
+
The label sits in its own <span> because Basecoat truncates the last span in
|
|
110
|
+
the row: a long label ellipsises instead of pushing the icon out of the
|
|
111
|
+
panel. That is also why the icon is a parameter rather than body content.
|
|
112
|
+
#}
|
|
113
|
+
{% macro sidebar_link(request, route, label, icon_name=none) -%}
|
|
114
|
+
<li>
|
|
115
|
+
<a href="{{ url_for(request, route) }}"
|
|
116
|
+
{%- if is_active(request, route) %} aria-current="page"{% endif %}
|
|
117
|
+
{%- if kwargs %}{{ attrs(kwargs) }}{% endif %}>
|
|
118
|
+
{%- if icon_name %}{{ icon(icon_name, 16) }}{% endif %}
|
|
119
|
+
<span>{{ label }}</span>
|
|
120
|
+
</a>
|
|
121
|
+
</li>
|
|
122
|
+
{%- endmacro %}
|
|
123
|
+
|
|
124
|
+
{#
|
|
125
|
+
sidebar_submenu(label, icon_name, open) — a second level of links.
|
|
126
|
+
|
|
127
|
+
{% call sidebar_submenu("Reports", icon_name="chart-bar") %}
|
|
128
|
+
{{ sidebar_link(request, "report_daily", "Daily") }}
|
|
129
|
+
{% endcall %}
|
|
130
|
+
|
|
131
|
+
`<details>` rather than a scripted disclosure: the browser owns the open
|
|
132
|
+
state, the Enter/Space handling and the expanded announcement, and Basecoat's
|
|
133
|
+
CSS already rotates the chevron off `[open]`. Nothing is left for JavaScript
|
|
134
|
+
to add, which is the test CHARTER.md §8 sets for wrapping a native element.
|
|
135
|
+
|
|
136
|
+
Pass `open=true` for the branch the current page lives in; the router knows
|
|
137
|
+
which that is, the template does not.
|
|
138
|
+
#}
|
|
139
|
+
{% macro sidebar_submenu(label, icon_name=none, open=false) -%}
|
|
140
|
+
<li>
|
|
141
|
+
<details{% if open %} open{% endif %}{% if kwargs %}{{ attrs(kwargs) }}{% endif %}>
|
|
142
|
+
<summary>
|
|
143
|
+
{%- if icon_name %}{{ icon(icon_name, 16) }}{% endif %}
|
|
144
|
+
<span>{{ label }}</span>
|
|
145
|
+
</summary>
|
|
146
|
+
<ul>{{ caller() }}</ul>
|
|
147
|
+
</details>
|
|
148
|
+
</li>
|
|
149
|
+
{%- endmacro %}
|
|
150
|
+
|
|
151
|
+
{#
|
|
152
|
+
sidebar_trigger(target, label) — the button that collapses and reveals it.
|
|
153
|
+
|
|
154
|
+
The shell renders one when its `sidebar` block is filled. Call it yourself
|
|
155
|
+
only when you override the shell's header, or when your sidebar carries an id
|
|
156
|
+
other than the default.
|
|
157
|
+
|
|
158
|
+
`onclick` calls the method Basecoat's own script attached to the element —
|
|
159
|
+
the shape the theme toggle in `ui/nav.html` uses, and for the same reason:
|
|
160
|
+
the alternative is fjkit shipping a script of its own to bind one listener
|
|
161
|
+
(CHARTER.md §11.3), which costs a file and a load-order rule to save an
|
|
162
|
+
attribute. `aria-expanded` is deliberately absent: the script owns the open
|
|
163
|
+
state, so a value rendered here would be a second, stale copy.
|
|
164
|
+
#}
|
|
165
|
+
{% macro sidebar_trigger(target="sidebar", label="Toggle navigation") -%}
|
|
166
|
+
<button class="btn" data-variant="ghost" data-size="icon-sm" type="button"
|
|
167
|
+
aria-label="{{ label }}" aria-controls="{{ target }}"
|
|
168
|
+
onclick="document.getElementById('{{ target }}').toggle()"
|
|
169
|
+
{%- if kwargs %}{{ attrs(kwargs) }}{% endif %}>{{ icon("panel-left", 16) }}</button>
|
|
170
|
+
{%- endmacro %}
|