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.
Files changed (127) hide show
  1. fjkit/__init__.py +49 -0
  2. fjkit/auth/__init__.py +54 -0
  3. fjkit/auth/csrf.py +88 -0
  4. fjkit/auth/errors.py +31 -0
  5. fjkit/auth/plugin.py +496 -0
  6. fjkit/auth/sources.py +24 -0
  7. fjkit/auth/stores.py +141 -0
  8. fjkit/auth/types.py +141 -0
  9. fjkit/cli/__init__.py +67 -0
  10. fjkit/cli/build_css.py +135 -0
  11. fjkit/cli/check.py +193 -0
  12. fjkit/cli/eject.py +562 -0
  13. fjkit/cli/ejected.py +202 -0
  14. fjkit/cli/vocabulary.py +85 -0
  15. fjkit/config.py +130 -0
  16. fjkit/errors.py +156 -0
  17. fjkit/flash.py +189 -0
  18. fjkit/forms.py +145 -0
  19. fjkit/htmx.py +76 -0
  20. fjkit/icons.py +60 -0
  21. fjkit/messages.py +227 -0
  22. fjkit/mounting.py +72 -0
  23. fjkit/plugins.py +223 -0
  24. fjkit/py.typed +0 -0
  25. fjkit/rendering.py +554 -0
  26. fjkit/signing.py +63 -0
  27. fjkit/static/brand/torii-bolt.png +0 -0
  28. fjkit/static/dist/fjkit-luma.css +2 -0
  29. fjkit/static/dist/fjkit-lyra.css +2 -0
  30. fjkit/static/dist/fjkit-maia.css +2 -0
  31. fjkit/static/dist/fjkit-mira.css +2 -0
  32. fjkit/static/dist/fjkit-nova.css +2 -0
  33. fjkit/static/dist/fjkit-rhea.css +2 -0
  34. fjkit/static/dist/fjkit-sera.css +2 -0
  35. fjkit/static/dist/fjkit-vega.css +2 -0
  36. fjkit/static/icons/lucide.json +1 -0
  37. fjkit/static/js/errors.js +117 -0
  38. fjkit/static/js/multiselect.js +126 -0
  39. fjkit/static/js/reveal.js +51 -0
  40. fjkit/static/js/select.js +113 -0
  41. fjkit/static/src/fjkit.css +385 -0
  42. fjkit/static/vendor/basecoat/base/base.css +136 -0
  43. fjkit/static/vendor/basecoat/basecoat-base.css +2 -0
  44. fjkit/static/vendor/basecoat/basecoat-components.css +39 -0
  45. fjkit/static/vendor/basecoat/basecoat-luma.css +2 -0
  46. fjkit/static/vendor/basecoat/basecoat-lyra.css +2 -0
  47. fjkit/static/vendor/basecoat/basecoat-maia.css +2 -0
  48. fjkit/static/vendor/basecoat/basecoat-mira.css +2 -0
  49. fjkit/static/vendor/basecoat/basecoat-nova.css +2 -0
  50. fjkit/static/vendor/basecoat/basecoat-rhea.css +2 -0
  51. fjkit/static/vendor/basecoat/basecoat-sera.css +2 -0
  52. fjkit/static/vendor/basecoat/basecoat-vega.css +2 -0
  53. fjkit/static/vendor/basecoat/basecoat.all.css +1 -0
  54. fjkit/static/vendor/basecoat/basecoat.css +1 -0
  55. fjkit/static/vendor/basecoat/components/accordion.css +27 -0
  56. fjkit/static/vendor/basecoat/components/alert.css +38 -0
  57. fjkit/static/vendor/basecoat/components/avatar.css +47 -0
  58. fjkit/static/vendor/basecoat/components/badge.css +6 -0
  59. fjkit/static/vendor/basecoat/components/breadcrumb.css +30 -0
  60. fjkit/static/vendor/basecoat/components/button-group.css +54 -0
  61. fjkit/static/vendor/basecoat/components/button.css +6 -0
  62. fjkit/static/vendor/basecoat/components/card.css +26 -0
  63. fjkit/static/vendor/basecoat/components/chart.css +56 -0
  64. fjkit/static/vendor/basecoat/components/checkbox.css +12 -0
  65. fjkit/static/vendor/basecoat/components/collapsible.css +21 -0
  66. fjkit/static/vendor/basecoat/components/combobox.css +99 -0
  67. fjkit/static/vendor/basecoat/components/command.css +140 -0
  68. fjkit/static/vendor/basecoat/components/dialog.css +101 -0
  69. fjkit/static/vendor/basecoat/components/drawer.css +89 -0
  70. fjkit/static/vendor/basecoat/components/dropdown-menu.css +56 -0
  71. fjkit/static/vendor/basecoat/components/empty.css +26 -0
  72. fjkit/static/vendor/basecoat/components/field.css +82 -0
  73. fjkit/static/vendor/basecoat/components/form.css +9 -0
  74. fjkit/static/vendor/basecoat/components/input-group.css +74 -0
  75. fjkit/static/vendor/basecoat/components/input.css +32 -0
  76. fjkit/static/vendor/basecoat/components/item.css +50 -0
  77. fjkit/static/vendor/basecoat/components/kbd.css +6 -0
  78. fjkit/static/vendor/basecoat/components/label.css +13 -0
  79. fjkit/static/vendor/basecoat/components/native-select.css +12 -0
  80. fjkit/static/vendor/basecoat/components/popover.css +107 -0
  81. fjkit/static/vendor/basecoat/components/progress.css +14 -0
  82. fjkit/static/vendor/basecoat/components/radio.css +11 -0
  83. fjkit/static/vendor/basecoat/components/range.css +50 -0
  84. fjkit/static/vendor/basecoat/components/scrollbar.css +46 -0
  85. fjkit/static/vendor/basecoat/components/select.css +64 -0
  86. fjkit/static/vendor/basecoat/components/sidebar.css +101 -0
  87. fjkit/static/vendor/basecoat/components/skeleton.css +6 -0
  88. fjkit/static/vendor/basecoat/components/switch.css +8 -0
  89. fjkit/static/vendor/basecoat/components/table.css +34 -0
  90. fjkit/static/vendor/basecoat/components/tabs.css +31 -0
  91. fjkit/static/vendor/basecoat/components/textarea.css +7 -0
  92. fjkit/static/vendor/basecoat/components/toast.css +57 -0
  93. fjkit/static/vendor/basecoat/components/tooltip.css +82 -0
  94. fjkit/static/vendor/basecoat/js/all.min.js +1 -0
  95. fjkit/static/vendor/basecoat/styles/luma.css +1376 -0
  96. fjkit/static/vendor/basecoat/styles/lyra.css +1379 -0
  97. fjkit/static/vendor/basecoat/styles/maia.css +1364 -0
  98. fjkit/static/vendor/basecoat/styles/mira.css +1373 -0
  99. fjkit/static/vendor/basecoat/styles/nova.css +1387 -0
  100. fjkit/static/vendor/basecoat/styles/rhea.css +1381 -0
  101. fjkit/static/vendor/basecoat/styles/sera.css +1397 -0
  102. fjkit/static/vendor/basecoat/styles/vega.css +1386 -0
  103. fjkit/static/vendor/htmx/htmx.min.js +1 -0
  104. fjkit/static/vendor/htmx/json-enc.js +38 -0
  105. fjkit/styles.py +30 -0
  106. fjkit/templates/errors/page.html +92 -0
  107. fjkit/templates/ui/attrs.html +18 -0
  108. fjkit/templates/ui/button.html +64 -0
  109. fjkit/templates/ui/data.html +362 -0
  110. fjkit/templates/ui/disclosure.html +89 -0
  111. fjkit/templates/ui/feedback.html +313 -0
  112. fjkit/templates/ui/form.html +595 -0
  113. fjkit/templates/ui/icon.html +13 -0
  114. fjkit/templates/ui/layout.html +189 -0
  115. fjkit/templates/ui/nav.html +110 -0
  116. fjkit/templates/ui/overlay.html +624 -0
  117. fjkit/templates/ui/shell.html +170 -0
  118. fjkit/templates/ui/sidebar.html +170 -0
  119. fjkit/templates/ui/table.html +427 -0
  120. fjkit/templates/ui/tabs.html +133 -0
  121. fjkit/templating.py +365 -0
  122. fjkit/vendored.py +46 -0
  123. fjkit-0.1.0.dev0.dist-info/METADATA +119 -0
  124. fjkit-0.1.0.dev0.dist-info/RECORD +127 -0
  125. fjkit-0.1.0.dev0.dist-info/WHEEL +4 -0
  126. fjkit-0.1.0.dev0.dist-info/entry_points.txt +2 -0
  127. fjkit-0.1.0.dev0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,362 @@
1
+ {% from "ui/attrs.html" import attrs %}
2
+ {% from "ui/icon.html" import icon %}
3
+
4
+ {# badge(label, variant) — variant: primary|secondary|outline|destructive|success|warning|info #}
5
+ {% macro badge(label, variant="") -%}
6
+ <span class="badge"{% if variant %} data-variant="{{ variant }}"{% endif %}{% if kwargs %}{{ attrs(kwargs) }}{% endif %}>{{ label }}</span>
7
+ {%- endmacro %}
8
+
9
+ {#
10
+ card(title, description, size, actions, padded) — a bordered panel, called as
11
+ a block macro.
12
+
13
+ {% call card("Throughput", "last 7 days") %}
14
+ <p>…</p>
15
+ {% endcall %}
16
+
17
+ `actions` takes pre-rendered markup for the right-hand side of the header:
18
+
19
+ {% set filters %}{% call button_group() %}…{% endcall %}{% endset %}
20
+ {% call card("5 tasks", actions=filters) %}…{% endcall %}
21
+
22
+ A parameter rather than a second slot: a two-slot call block runs its body
23
+ once per slot, and the common case is a heavy body with no actions at all.
24
+
25
+ `padded=false` drops the inner <section> so a table sits flush against the
26
+ card's edges. With a header as well, the body gets a rule above it; a flush
27
+ body butting into header text reads as one block.
28
+ #}
29
+ {% macro card(title=none, description=none, size="", actions=none, padded=true) -%}
30
+ {%- set has_header = title or description or actions -%}
31
+ <div class="card"{% if size %} data-size="{{ size }}"{% endif %}{% if kwargs %}{{ attrs(kwargs) }}{% endif %}>
32
+ {%- if has_header %}
33
+ <header class="flex flex-wrap items-center justify-between gap-3">
34
+ <div>
35
+ {% if title %}<h3>{{ title }}</h3>{% endif %}
36
+ {% if description %}<p>{{ description }}</p>{% endif %}
37
+ </div>
38
+ {% if actions %}{{ actions }}{% endif %}
39
+ </header>
40
+ {%- endif %}
41
+ {% if padded %}
42
+ <section>{{ caller() }}</section>
43
+ {% elif has_header %}
44
+ <div class="border-t">{{ caller() }}</div>
45
+ {% else %}
46
+ {{ caller() }}
47
+ {% endif %}
48
+ </div>
49
+ {%- endmacro %}
50
+
51
+ {#
52
+ Never build a class by interpolation (`text-{{ tone }}`): Tailwind finds
53
+ classes by scanning source text, so an interpolated one is absent from the
54
+ stylesheet. A closed lookup keeps every value in this file verbatim, where
55
+ the scan finds it.
56
+ #}
57
+ {% set _TONES = {
58
+ "success": "text-success",
59
+ "warning": "text-warning",
60
+ "info": "text-info",
61
+ "destructive": "text-destructive",
62
+ "muted": "text-muted-foreground",
63
+ } %}
64
+
65
+ {# stat(label, value, hint, icon_name, tone) — the KPI tile. #}
66
+ {% macro stat(label, value, hint=none, icon_name=none, tone=none) -%}
67
+ <div class="card" data-size="sm">
68
+ <section class="flex items-start justify-between gap-3">
69
+ <div class="space-y-1">
70
+ <p class="text-muted-foreground text-xs font-medium tracking-wide uppercase">{{ label }}</p>
71
+ <p class="text-3xl font-semibold tabular-nums {{ _TONES.get(tone, "") }}">{{ value }}</p>
72
+ {% if hint %}<p class="text-muted-foreground text-xs">{{ hint }}</p>{% endif %}
73
+ </div>
74
+ {% if icon_name %}
75
+ <span class="bg-muted text-muted-foreground grid size-9 place-items-center rounded-lg">{{ icon(icon_name, 18) }}</span>
76
+ {% endif %}
77
+ </section>
78
+ </div>
79
+ {%- endmacro %}
80
+
81
+ {#
82
+ metric_group(items) — a compact row of counts, the small sibling of stat().
83
+
84
+ `items` is a list of (label, value) pairs. Use it inside a card when the
85
+ numbers are context for something else; use stat() when they are the point of
86
+ the page.
87
+ #}
88
+ {% macro metric_group(items, cols=3) -%}
89
+ {%- set _GRID = {2: "grid-cols-2", 3: "grid-cols-3", 4: "grid-cols-4"} -%}
90
+ <dl class="grid {{ _GRID.get(cols, "grid-cols-3") }} gap-2 text-center">
91
+ {% for label, value in items %}
92
+ <div class="bg-muted/60 rounded-lg py-2.5">
93
+ <dt class="text-muted-foreground text-[0.7rem] tracking-wide uppercase">{{ label }}</dt>
94
+ <dd class="mt-1 text-xl font-semibold tabular-nums">{{ value }}</dd>
95
+ </div>
96
+ {% endfor %}
97
+ </dl>
98
+ {%- endmacro %}
99
+
100
+ {# progress(value, label) — value is 0-100. #}
101
+ {#
102
+ `id` makes the bar addressable, which is what `form(progress=…)` needs: an
103
+ upload's percentage arrives in the browser, so something has to write it into
104
+ markup the server rendered once at zero.
105
+
106
+ The three hooks below are that contract. A bar has three places the same
107
+ number is written — the width, `aria-valuenow`, and the printed percentage —
108
+ and moving one without the others is worse than moving none: a bar that fills
109
+ while the label still reads 0%, or fills for a sighted reader while a screen
110
+ reader is still told nothing has happened. They are `data-*` rather than more
111
+ ids because there is one of each per bar, and an id per part would have to be
112
+ derived from `id` and kept in step at both ends.
113
+ #}
114
+ {% macro progress(value, label=none, id=none) -%}
115
+ <div class="space-y-1.5"{% if id %} id="{{ id }}"{% endif %}>
116
+ {% if label %}
117
+ <div class="text-muted-foreground flex justify-between text-xs">
118
+ <span>{{ label }}</span><span class="tabular-nums" data-progress-value>{{ value }}%</span>
119
+ </div>
120
+ {% endif %}
121
+ <div class="progress" role="progressbar" aria-valuenow="{{ value }}" aria-valuemin="0" aria-valuemax="100">
122
+ <span style="width: {{ value }}%" data-progress-bar></span>
123
+ </div>
124
+ </div>
125
+ {%- endmacro %}
126
+
127
+ {# empty_state(title, description, icon_name) — the zero-row case, once. #}
128
+ {% macro empty_state(title, description=none, icon_name="sparkle") -%}
129
+ <div class="empty">
130
+ <header>
131
+ <figure>{{ icon(icon_name, 22) }}</figure>
132
+ <h3>{{ title }}</h3>
133
+ {% if description %}<p>{{ description }}</p>{% endif %}
134
+ </header>
135
+ </div>
136
+ {%- endmacro %}
137
+
138
+ {#
139
+ bullet_list() / list_item() — prose lists inside a card.
140
+
141
+ {% call bullet_list() %}
142
+ {% call list_item() %}Templates are compiled once per process.{% endcall %}
143
+ {% endcall %}
144
+ #}
145
+ {% macro bullet_list(tone="muted") -%}
146
+ <ul class="{{ _TONES.get(tone, "") }} space-y-2 text-sm">{{ caller() }}</ul>
147
+ {%- endmacro %}
148
+
149
+ {% macro list_item() -%}
150
+ <li>{{ caller() }}</li>
151
+ {%- endmacro %}
152
+
153
+ {#
154
+ caption(text) — a standalone line of secondary prose.
155
+
156
+ `card`, `section` and `page_header` each render a description, but each of
157
+ those is the second line of a title block and cannot move away from its
158
+ heading. This is the line that stands alone: under a table, beneath a
159
+ control, at the foot of a form. An app template cannot write one by hand —
160
+ the colour it needs (`text-muted-foreground`) is a utility the checker
161
+ rejects, and a bare `<p>` renders at body weight.
162
+
163
+ Takes the text as an argument, or a body when the caption holds a `link()`:
164
+
165
+ {{ caption("Counts refresh every five minutes.") }}
166
+
167
+ {% call caption() %}
168
+ Source: {{ link("the trial registry", href=registry_url) }}
169
+ {% endcall %}
170
+ #}
171
+ {% macro caption(text=none) -%}
172
+ <p class="text-muted-foreground text-sm"{% if kwargs %}{{ attrs(kwargs) }}{% endif %}>
173
+ {{- caller() if caller is defined else text -}}
174
+ </p>
175
+ {%- endmacro %}
176
+
177
+ {#
178
+ link(label, href) — an inline link in body copy.
179
+
180
+ Always underlined: a link distinguished by colour alone fails for a reader
181
+ who cannot see the colour.
182
+ #}
183
+ {% macro link(label, href) -%}
184
+ <a class="text-foreground underline underline-offset-4" href="{{ href }}"{% if kwargs %}{{ attrs(kwargs) }}{% endif %}>{{ label }}</a>
185
+ {%- endmacro %}
186
+
187
+ {# kbd(keys) — a keyboard key or a literal token in running text. #}
188
+ {% macro kbd(keys) -%}
189
+ <code class="kbd">{{ keys }}</code>
190
+ {%- endmacro %}
191
+
192
+ {#
193
+ code_block(source, label, wrap) — source, a log, a config, a payload.
194
+
195
+ Roadmap 0.9, pulled forward. Basecoat has no component for this and `card`
196
+ does not reach it: a code region has three problems a bare <pre> leaves open.
197
+
198
+ 1. It scrolls, so it has to be reachable. A mouse can wheel a scroll
199
+ container that nothing can focus; a keyboard cannot reach it at all.
200
+ `tabindex="0"` fixes that, and it is why this clears CHARTER §8's bar on
201
+ wrapping a native element.
202
+ 2. A focusable region needs a name, or a screen reader announces an
203
+ unlabelled stop in the tab order. `role="region"` is applied only when
204
+ there is a label for it, because an unnamed region is worse than none.
205
+ 3. Long lines. Pass `wrap=true` for emitted markup: one line of HTML holding
206
+ an inline SVG is not something to scroll sideways through.
207
+
208
+ The content is printed as text and stays text. Highlighting is client-side —
209
+ a page that wants it reads `textContent` back and marks up the tokens — which
210
+ keeps the source legible with scripting off and keeps this macro from having
211
+ to know any language.
212
+ #}
213
+ {% macro code_block(source, label=none, wrap=false) -%}
214
+ <pre class="code-block scrollbar" tabindex="0"
215
+ {%- if wrap %} data-wrap="true"{% endif %}
216
+ {%- if label %} role="region" aria-label="{{ label }}"{% endif %}
217
+ {%- if kwargs %}{{ attrs(kwargs) }}{% endif %}>{{ source }}</pre>
218
+ {%- endmacro %}
219
+
220
+ {#
221
+ item_list() / item(title, description, …) — a list of rows that are not a
222
+ table: settings, results, definitions, a feed.
223
+
224
+ Roadmap 0.9. Basecoat ships `.item-group` / `.item`, and its markup contract
225
+ is load-bearing: `.item > section` is the text column, `.item > figure` the
226
+ leading icon, `.item > aside` the trailing actions. An app should not have to
227
+ re-derive that from a stylesheet.
228
+
229
+ {% call item_list() %}
230
+ {{ item("router.py", "reads the request, calls the service") }}
231
+ {{ item("service.py", "the actual work", icon_name="gauge") }}
232
+ {% endcall %}
233
+
234
+ `description` may be markup, so a row can hold a badge or a link without the
235
+ caller reaching for |safe.
236
+
237
+ Basecoat clamps `.item p` to two lines, which suits a feed and not a
238
+ definition list; `clamp=false` releases it. It is an attribute rather than a
239
+ class because the rule lives in `fjkit.css`, beside the other `data-*`
240
+ extensions of Basecoat's API.
241
+ #}
242
+ {% macro item_list() -%}
243
+ <div class="item-group"{% if kwargs %}{{ attrs(kwargs) }}{% endif %}>{{ caller() }}</div>
244
+ {%- endmacro %}
245
+
246
+ {% macro item(title, description=none, icon_name=none, actions=none, href=none, clamp=true) -%}
247
+ {%- set tag = "a" if href else "div" -%}
248
+ <{{ tag }} class="item"{% if not clamp %} data-clamp="false"{% endif %}
249
+ {%- if href %} href="{{ href }}"{% endif %}
250
+ {%- if kwargs %}{{ attrs(kwargs) }}{% endif %}>
251
+ {%- if icon_name %}<figure>{{ icon(icon_name, 16) }}</figure>{% endif %}
252
+ <section>
253
+ <h4>{{ title }}</h4>
254
+ {%- if description %}<p>{{ description }}</p>{% endif %}
255
+ </section>
256
+ {%- if actions %}<aside>{{ actions }}</aside>{% endif %}
257
+ </{{ tag }}>
258
+ {%- endmacro %}
259
+
260
+ {#
261
+ description_list(layout) / description_item(term, value) — term-and-value pairs.
262
+
263
+ A native `<dl>`, so a screen reader announces each value as the definition of
264
+ the term beside it. `item_list` covers most of what this is used for and does
265
+ not carry that relationship: it is a list of things, and this is a list of
266
+ facts about one thing.
267
+
268
+ Every pair is wrapped in a `<div>` — permitted inside `<dl>` since HTML 5.2,
269
+ and required here, because a grid over bare `<dt>`/`<dd>` children lays them
270
+ out in document order and cannot keep a pair on one row.
271
+
272
+ {% call description_list() %}
273
+ {{ description_item("Status", badge("Active", "success")) }}
274
+ {{ description_item("Owner", task.owner) }}
275
+ {% endcall %}
276
+
277
+ `value` may be markup, like `item`'s `description`, so a row can hold a badge
278
+ or a link without the caller reaching for `|safe`. Where the value is longer
279
+ than one expression, `{% call description_item("Notes") %}…{% endcall %}` puts
280
+ it in the body instead; `value` wins if both are given.
281
+
282
+ Two layouts, and the difference is only where the term sits. `rows` moves it
283
+ beside the value once the viewport is wide enough for two columns. `stacked`
284
+ keeps it above at every width, which is what a card too narrow for a label
285
+ column needs. Neither is a class the caller writes — see `fjkit.css`, where
286
+ the `<dd>` margin reset that both depend on also lives.
287
+ #}
288
+ {% set _DL_LAYOUTS = ("rows", "stacked") %}
289
+
290
+ {% macro description_list(layout="rows") -%}
291
+ <dl class="description-list" data-layout="{{ layout if layout in _DL_LAYOUTS else "rows" }}"
292
+ {%- if kwargs %}{{ attrs(kwargs) }}{% endif %}>{{ caller() }}</dl>
293
+ {%- endmacro %}
294
+
295
+ {% macro description_item(term, value=none) -%}
296
+ <div{% if kwargs %}{{ attrs(kwargs) }}{% endif %}>
297
+ <dt>{{ term }}</dt>
298
+ <dd>{{ value if value is not none else caller() }}</dd>
299
+ </div>
300
+ {%- endmacro %}
301
+
302
+ {#
303
+ avatar(name, src, size, badge_tone, badge_icon)
304
+
305
+ `name` is required and `src` is not: the initials are what the image falls
306
+ back to, and an avatar with no name has nothing to show when the URL 404s.
307
+ Basecoat stacks both and lets the absolutely positioned `<img>` cover the
308
+ initials once it loads, so the fallback costs nothing and needs no
309
+ JavaScript.
310
+
311
+ `name` also becomes the `alt` text, so the accessible name and the visible
312
+ initials cannot disagree.
313
+
314
+ The badge is a status dot. Upstream's example writes `bg-green-600` on it;
315
+ here the colour is a role (A3), because a dot meaning "online" has to survive
316
+ a rebrand exactly like a badge meaning "done".
317
+ #}
318
+ {% set _AVATAR_BADGE_TONES = {
319
+ "success": "bg-success",
320
+ "warning": "bg-warning",
321
+ "info": "bg-info",
322
+ "destructive": "bg-destructive",
323
+ "muted": "bg-muted-foreground",
324
+ } %}
325
+
326
+ {% macro avatar(name, src=none, size="", initials=none, badge_tone=none, badge_icon=none) -%}
327
+ {#
328
+ Two letters at most: "Ada Lovelace" is AL, "Ada" is A, and a five-word name
329
+ is not five letters. Pass `initials` where the default does not survive —
330
+ a handle, a non-Latin script.
331
+ #}
332
+ {%- set letters = initials if initials is not none else (name.split() | map("first") | join)[:2] | upper -%}
333
+ <span class="avatar"{% if size %} data-size="{{ size }}"{% endif %}{% if kwargs %}{{ attrs(kwargs) }}{% endif %}>
334
+ {%- if src %}<img src="{{ src }}" alt="{{ name }}">{% endif %}
335
+ {#
336
+ The initials carry the accessible name when there is no image, and are
337
+ hidden from the tree when there is: otherwise the avatar is announced
338
+ twice, once as the alt text and once as two stray letters.
339
+ #}
340
+ <span{% if src %} aria-hidden="true"{% endif %}>{{ letters }}</span>
341
+ {%- if badge_tone or badge_icon %}
342
+ <span class="avatar-badge {{ _AVATAR_BADGE_TONES.get(badge_tone, "bg-muted-foreground") }}">
343
+ {%- if badge_icon %}{{ icon(badge_icon, 12) }}{% endif -%}
344
+ </span>
345
+ {%- endif %}
346
+ </span>
347
+ {%- endmacro %}
348
+
349
+ {#
350
+ avatar_group(overflow)
351
+
352
+ Overlapping avatars, with an optional "+3" at the end. `overflow` is a number
353
+ rather than a rendered label so the macro writes the "+" itself: a caller
354
+ passing "3 more" breaks the ring geometry the CSS gives `[data-count]`.
355
+ #}
356
+ {% macro avatar_group(overflow=none, label=none) -%}
357
+ <div class="avatar-group"{% if label %} role="group" aria-label="{{ label }}"{% endif %}
358
+ {%- if kwargs %}{{ attrs(kwargs) }}{% endif %}>
359
+ {{- caller() -}}
360
+ {%- if overflow %}<span data-count>+{{ overflow }}</span>{% endif -%}
361
+ </div>
362
+ {%- endmacro %}
@@ -0,0 +1,89 @@
1
+ {#
2
+ Showing and hiding, through the two mechanisms the browser already has.
3
+
4
+ `collapsible` and `accordion` are both `<details>`/`<summary>`: open state,
5
+ keyboard operation, the disclosure role and the announcement come from the
6
+ element. Basecoat styles the element directly — `collapsible.css` declares no
7
+ class — so these macros contribute structure and the closed vocabulary, not
8
+ behaviour.
9
+
10
+ `tooltip` is the same idea one level down: upstream draws it from a
11
+ `[data-tooltip]` attribute and CSS `content()`, so there is no JavaScript and
12
+ no second element to keep in sync.
13
+ #}
14
+ {% from "ui/attrs.html" import attrs %}
15
+ {% from "ui/icon.html" import icon %}
16
+
17
+ {#
18
+ collapsible(summary, open) — one disclosure.
19
+
20
+ A `<details>`: the open state needs no JS and no server state, and the
21
+ browser gives the summary a button role plus Enter/Space. Basecoat animates
22
+ `::details-content` and needs nothing from here.
23
+
24
+ The chevron sits inside the summary and rotates from the parent's `[open]`,
25
+ so marker and state have one source and cannot disagree. `list-none` and
26
+ Basecoat's `::-webkit-details-marker` rule remove the browser's own triangle;
27
+ without them a summary shows two markers.
28
+ #}
29
+ {% macro collapsible(summary, open=false, icon_name=none) -%}
30
+ <details class="group border-b"{% if open %} open{% endif %}{% if kwargs %}{{ attrs(kwargs) }}{% endif %}>
31
+ <summary class="flex w-full list-none items-center justify-between gap-3 py-3 text-sm font-medium
32
+ hover:underline focus-visible:outline-ring focus-visible:-outline-offset-2 focus-visible:outline-2">
33
+ <span class="flex items-center gap-2">
34
+ {%- if icon_name %}{{ icon(icon_name, 16) }}{% endif %}
35
+ {{ summary }}
36
+ </span>
37
+ {#
38
+ aria-hidden, because the summary already announces its own expanded
39
+ state. A chevron that is also read aloud says "collapsed" twice.
40
+ #}
41
+ <span aria-hidden="true" class="text-muted-foreground transition-transform group-open:rotate-180">
42
+ {{- icon("chevron-down", 16) -}}
43
+ </span>
44
+ </summary>
45
+ <div class="pb-3 text-sm">{{ caller() }}</div>
46
+ </details>
47
+ {%- endmacro %}
48
+
49
+ {#
50
+ accordion(multiple) — a stack of collapsibles, at most one open by default.
51
+
52
+ Basecoat's JS closes the siblings: it finds `.accordion` and reads
53
+ `:scope > details[open]`. `multiple` withholds that class, so a group that
54
+ allows several open panels ships no JS behaviour rather than JS asked to do
55
+ nothing.
56
+
57
+ The children are `collapsible` calls. There is no `accordion_item`: a second
58
+ macro rendering the same `<details>` would be a second place for the summary
59
+ markup to drift.
60
+ #}
61
+ {% macro accordion(multiple=false, label=none) -%}
62
+ <div {% if not multiple %}class="accordion"{% endif %}
63
+ {%- if label %} role="group" aria-label="{{ label }}"{% endif %}
64
+ {%- if kwargs %}{{ attrs(kwargs) }}{% endif %}>
65
+ {{- caller() -}}
66
+ </div>
67
+ {%- endmacro %}
68
+
69
+ {#
70
+ tooltip(text, side, align) — a hint on hover and on keyboard focus.
71
+
72
+ Upstream draws this from `[data-tooltip]` alone: the text is CSS
73
+ `content: attr(data-tooltip)`, so there is no second element, no JavaScript
74
+ and nothing to position. `side` and `align` are Basecoat's own closed
75
+ attribute vocabulary.
76
+
77
+ Two limits, both inherited from that mechanism:
78
+
79
+ * The text is not in the accessibility tree; `content()` never is. A tooltip
80
+ is a hint, never the only label. Give the control an `aria-label` when the
81
+ tooltip is the only text it has.
82
+ * It holds no markup. A tooltip that needs a heading is a popover.
83
+ #}
84
+ {% macro tooltip(text, side="top", align="center") -%}
85
+ <span data-tooltip="{{ text }}" data-side="{{ side }}" data-align="{{ align }}"
86
+ class="inline-flex"{% if kwargs %}{{ attrs(kwargs) }}{% endif %}>
87
+ {{- caller() -}}
88
+ </span>
89
+ {%- endmacro %}