@threadlabs/looma 0.44.6 → 0.45.0

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.
package/README.md CHANGED
@@ -53,6 +53,30 @@ each `<ui-*>` element into its native root. Each component's styles are scoped t
53
53
  stylesheet is the only stylesheet to include. Without a build, link components one by one from
54
54
  `@threadlabs/looma/components/<tag>/<tag>.html`.
55
55
 
56
+ ## Site navigation
57
+
58
+ Provide the brand and navigation once. SiteHeader automatically adds a hamburger
59
+ beside the logo below 64rem and opens the same links in a full-height, scrollable
60
+ modal drawer with a dark backdrop. It handles focus, page scroll locking, Escape,
61
+ outside presses, and closing after link selection. No separate menu or drawer wiring
62
+ is needed. `breakpoint="sm"` and `breakpoint="md"` switch at 40rem and 48rem.
63
+
64
+ ```html
65
+ <ui-site-header>
66
+ <a slot="brand" href="/">Folio</a>
67
+ <a slot="navigation" href="/guide">Guide</a>
68
+ <a slot="navigation" href="/journal">Journal</a>
69
+ </ui-site-header>
70
+ ```
71
+
72
+ In Vue, use `SiteHeader` with `#brand`, `#navigation`, and optional `#actions`.
73
+ Router links keep their original handlers and state. Localize `label`, `menuLabel`,
74
+ and `closeLabel` as needed. Without JavaScript, navigation stays available inline.
75
+
76
+ Use the optional `menu` slot only when the trigger opens a different navigation
77
+ surface, such as a combined documentation sidebar. That explicit override owns its
78
+ own target and behavior; omitting it gives you the automatic drawer.
79
+
56
80
  ## Theming
57
81
 
58
82
  Components read design tokens (`--ui-*` custom properties) from `tokens.css` and a theme
@@ -43,6 +43,7 @@ export const icons = {
43
43
  "list-ordered": [["path",{"d":"M11 5h10"}],["path",{"d":"M11 12h10"}],["path",{"d":"M11 19h10"}],["path",{"d":"M4 4h1v5"}],["path",{"d":"M4 9h2"}],["path",{"d":"M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02"}]],
44
44
  "list-todo": [["path",{"d":"M13 5h8"}],["path",{"d":"M13 12h8"}],["path",{"d":"M13 19h8"}],["path",{"d":"m3 17 2 2 4-4"}],["rect",{"x":"3","y":"4","width":"6","height":"6","rx":"1"}]],
45
45
  "loader": [["path",{"d":"M21 12a9 9 0 1 1-6.219-8.56"}]],
46
+ "menu": [["path",{"d":"M4 5h16"}],["path",{"d":"M4 12h16"}],["path",{"d":"M4 19h16"}]],
46
47
  "merge": [["path",{"d":"m8 6 4-4 4 4"}],["path",{"d":"M12 2v10.3a4 4 0 0 1-1.172 2.872L4 22"}],["path",{"d":"m20 22-5-5"}]],
47
48
  "message-square-warning": [["path",{"d":"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z"}],["path",{"d":"M12 15h.01"}],["path",{"d":"M12 7v4"}]],
48
49
  "minus": [["path",{"d":"M5 12h14"}]],
@@ -315,16 +315,18 @@
315
315
  }
316
316
 
317
317
  :host[data-appearance="outline"]:not([data-tone="neutral"]) {
318
+ --_outline-highlight: var(--ui-surface-highlight, linear-gradient(transparent, transparent));
318
319
  --_outline-wash: oklch(from var(--_tone) l c h / calc(8% * var(--ui-tonal-opacity, 1)));
319
320
  border-color: var(--ui-button-border, var(--_tone-outline-border, var(--_tone-text)));
320
321
  background-color: var(--ui-button-surface, transparent);
321
322
  box-shadow: var(--ui-button-shadow, var(--ui-neutral-shadow));
322
323
  background-image:
323
324
  linear-gradient(var(--_outline-wash), var(--_outline-wash)),
324
- var(--ui-surface-highlight, linear-gradient(transparent, transparent));
325
+ var(--_outline-highlight);
325
326
  }
326
327
 
327
328
  :host[data-appearance="outline"]:not([data-tone="neutral"]):hover:not(:disabled, [aria-disabled="true"]) {
329
+ --_outline-highlight: var(--ui-neutral-highlight, var(--ui-surface-highlight, linear-gradient(transparent, transparent)));
328
330
  --_outline-wash: oklch(from var(--_tone) l c h / calc(12% * var(--ui-tonal-opacity, 1)));
329
331
  background-color: var(--ui-button-hover-surface, transparent);
330
332
  border-color: var(--ui-button-hover-border, var(--_tone-outline-border));
@@ -52,6 +52,7 @@
52
52
  'list-ordered': [{ tag: 'path', d: 'M11 5h10' }, { tag: 'path', d: 'M11 12h10' }, { tag: 'path', d: 'M11 19h10' }, { tag: 'path', d: 'M4 4h1v5' }, { tag: 'path', d: 'M4 9h2' }, { tag: 'path', d: 'M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02' }],
53
53
  'list-todo': [{ tag: 'path', d: 'M13 5h8' }, { tag: 'path', d: 'M13 12h8' }, { tag: 'path', d: 'M13 19h8' }, { tag: 'path', d: 'm3 17 2 2 4-4' }, { tag: 'rect', x: '3', y: '4', width: '6', height: '6', rx: '1' }],
54
54
  'loader': [{ tag: 'path', d: 'M21 12a9 9 0 1 1-6.219-8.56' }],
55
+ 'menu': [{ tag: 'path', d: 'M4 5h16' }, { tag: 'path', d: 'M4 12h16' }, { tag: 'path', d: 'M4 19h16' }],
55
56
  'merge': [{ tag: 'path', d: 'm8 6 4-4 4 4' }, { tag: 'path', d: 'M12 2v10.3a4 4 0 0 1-1.172 2.872L4 22' }, { tag: 'path', d: 'm20 22-5-5' }],
56
57
  'message-square-warning': [{ tag: 'path', d: 'M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z' }, { tag: 'path', d: 'M12 15h.01' }, { tag: 'path', d: 'M12 7v4' }],
57
58
  'minus': [{ tag: 'path', d: 'M5 12h14' }],
@@ -419,15 +419,17 @@
419
419
  }
420
420
 
421
421
  :host[data-appearance="outline"]:not([data-tone="neutral"]) {
422
+ --_outline-highlight: var(--ui-surface-highlight, linear-gradient(transparent, transparent));
422
423
  --_outline-wash: oklch(from var(--_icon-button-solid-surface, var(--ui-accent)) l c h / calc(8% * var(--ui-tonal-opacity, 1)));
423
424
  border-color: var(--ui-icon-button-border, var(--_tone-outline-border));
424
425
  background-color: var(--ui-icon-button-outline-surface, transparent);
425
426
  background-image:
426
427
  linear-gradient(var(--_outline-wash), var(--_outline-wash)),
427
- var(--ui-surface-highlight, linear-gradient(transparent, transparent));
428
+ var(--_outline-highlight);
428
429
  }
429
430
 
430
431
  :host[data-appearance="outline"]:not([data-tone="neutral"]):hover:enabled:not([aria-disabled="true"]) {
432
+ --_outline-highlight: var(--ui-neutral-highlight, var(--ui-surface-highlight, linear-gradient(transparent, transparent)));
431
433
  --_outline-wash: oklch(from var(--_icon-button-solid-surface, var(--ui-accent)) l c h / calc(12% * var(--ui-tonal-opacity, 1)));
432
434
  background-color: var(--ui-icon-button-hover-surface, transparent);
433
435
  border-color: var(--ui-icon-button-hover-border, var(--_tone-outline-border));
@@ -1,16 +1,40 @@
1
- <template component="ui-site-header">
1
+ <link rel="component" href="../ui-icon-button/ui-icon-button.html">
2
+ <link rel="component" href="../ui-icon/ui-icon.html">
3
+ <template component="ui-site-header" module="./ui-site-header.js">
2
4
  <defs>
3
5
  <prop name="label" type="string" default="Main">Accessible name for the primary navigation region.</prop>
4
6
  <prop name="sticky" type="boolean" default="false">Keeps the header at the top of its scrolling container.</prop>
5
7
  <prop name="breakpoint" type="keyword" values="sm, md, lg" default="lg"
6
- >The viewport width at which navigation replaces the menu trigger: sm is 40rem, md 48rem, and lg 64rem. The consumer owns the menu or drawer the trigger
7
- opens.</prop>
8
+ >The viewport width at which navigation changes from an automatic mobile drawer to inline links: sm is 40rem, md 48rem, and lg 64rem.</prop>
9
+ <prop name="menuLabel" type="string" default="Open navigation">Accessible name of the automatic mobile menu button.</prop>
10
+ <prop name="closeLabel" type="string" default="Close navigation">Accessible name of the drawer's close button.</prop>
11
+ <state name="enhanced" type="boolean" value="false"></state>
12
+ <state name="drawer" type="boolean" value="false"></state>
8
13
  </defs>
9
14
  <header>
10
- <span class="menu"><slot name="menu"></slot></span>
11
15
  <div class="identity">
12
16
  <div class="brand"><slot name="brand"></slot></div>
13
- <nav class="navigation" from:aria-label="$label"><slot name="navigation"></slot></nav>
17
+ <div class="menu">
18
+ <div class="custom-menu"><slot name="menu"></slot></div>
19
+ <div class="automatic-menu">
20
+ <ui-icon-button $ref="trigger" size="sm" from:label="$menuLabel" aria-haspopup="dialog" aria-expanded="false"><ui-icon
21
+ name="menu"
22
+ ></ui-icon></ui-icon-button>
23
+ </div>
24
+ </div>
25
+ <dialog
26
+ class="navigation-panel"
27
+ $ref="panel"
28
+ from:open="true"
29
+ from:role="{ true: 'dialog', false: 'none' }[concat($drawer)]"
30
+ from:aria-label="{ true: $label, false: null }[concat($drawer)]"
31
+ >
32
+ <div class="panel-heading">
33
+ <span class="panel-title">{$label}</span>
34
+ <ui-icon-button $ref="close" size="sm" from:label="$closeLabel"><ui-icon name="x"></ui-icon></ui-icon-button>
35
+ </div>
36
+ <nav class="navigation" $ref="navigation" from:aria-label="$label"><slot name="navigation"></slot></nav>
37
+ </dialog>
14
38
  </div>
15
39
  <div class="actions"><slot name="actions"></slot></div>
16
40
  </header>
@@ -35,16 +59,13 @@
35
59
  inset-block-start: 0;
36
60
  z-index: var(--ui-site-header-z-index, 10);
37
61
  }
38
- .menu, .actions {
39
- display: flex !important;
62
+ .actions {
63
+ display: grid !important;
40
64
  flex: none;
41
65
  align-items: center !important;
42
66
  gap: var(--ui-space-2) !important;
43
67
  min-inline-size: 0;
44
68
  max-inline-size: 100%;
45
- }
46
- .actions {
47
- display: grid !important;
48
69
  grid-auto-flow: column !important;
49
70
  grid-auto-columns: minmax(max-content, var(--ui-control-min-block-size)) !important;
50
71
  justify-items: center !important;
@@ -82,10 +103,6 @@
82
103
  font-size: var(--ui-font-size-sm);
83
104
  font-weight: var(--ui-font-semibold);
84
105
  }
85
- /* Without a supplied menu trigger, keep the destinations available on narrow screens. */
86
- :host:has(> .menu:not(:empty)) .navigation {
87
- display: none !important;
88
- }
89
106
  .navigation > :slotted(a) {
90
107
  color: inherit;
91
108
  text-decoration: none;
@@ -97,7 +114,7 @@
97
114
  outline: var(--ui-focus-width) solid var(--ui-focus-ring);
98
115
  outline-offset: var(--ui-focus-width);
99
116
  }
100
- .menu:empty, .actions:empty, .brand:empty, .navigation:empty {
117
+ .actions:empty, .brand:empty, .navigation:empty {
101
118
  display: none !important;
102
119
  }
103
120
  @media (min-width: 40rem) {
@@ -105,35 +122,150 @@
105
122
  min-block-size: var(--ui-site-header-height, 4.25rem);
106
123
  column-gap: var(--ui-space-4) !important;
107
124
  }
108
- :host([breakpoint="sm"]) .navigation:not(:empty) {
109
- display: flex !important;
110
- }
111
- :host([breakpoint="sm"]) .menu {
112
- display: none !important;
113
- }
114
125
  }
115
126
  @media (min-width: 48rem) {
116
127
  :host([breakpoint="md"]) {
117
128
  min-block-size: var(--ui-site-header-height, 4.25rem);
118
129
  column-gap: var(--ui-space-4) !important;
119
130
  }
120
- :host([breakpoint="md"]) .navigation:not(:empty) {
121
- display: flex !important;
122
- }
123
- :host([breakpoint="md"]) .menu {
124
- display: none !important;
125
- }
126
131
  }
127
132
  @media (min-width: 64rem) {
128
133
  :host([breakpoint="lg"]) {
129
134
  min-block-size: var(--ui-site-header-height, 4.25rem);
130
135
  column-gap: var(--ui-space-4) !important;
131
136
  }
132
- :host([breakpoint="lg"]) .navigation:not(:empty) {
133
- display: flex !important;
137
+ }
138
+ /* The same navigation remains inline before upgrade and on desktop. No links are cloned or moved. */
139
+ .navigation-panel {
140
+ position: static;
141
+ display: flex !important;
142
+ align-items: baseline !important;
143
+ min-inline-size: 0;
144
+ max-inline-size: none;
145
+ margin: 0 !important;
146
+ padding: 0 !important;
147
+ border: 0;
148
+ background: transparent;
149
+ color: inherit;
150
+ }
151
+ .navigation-panel:not([open]), .menu, .panel-heading {
152
+ display: none !important;
153
+ }
154
+ :host(:state(drawer)) .identity {
155
+ flex-wrap: nowrap !important;
156
+ align-items: center !important;
157
+ }
158
+ :host(:state(drawer)) .brand {
159
+ flex: 1 1 0;
160
+ }
161
+ :host(:state(enhanced):state(drawer)):has(.navigation:not(:empty), .custom-menu:not(:empty)) .menu {
162
+ display: grid !important;
163
+ grid-template-columns: minmax(max-content, var(--ui-control-min-block-size)) !important;
164
+ justify-items: center !important;
165
+ flex: none;
166
+ }
167
+ .automatic-menu {
168
+ display: grid !important;
169
+ justify-items: center !important;
170
+ }
171
+ .custom-menu:empty, .menu:has(> .custom-menu:not(:empty)) .automatic-menu {
172
+ display: none !important;
173
+ }
174
+ :host(:state(drawer)) .navigation-panel {
175
+ position: fixed;
176
+ inset-block: 0;
177
+ inset-inline-start: 0;
178
+ inset-inline-end: auto;
179
+ box-sizing: border-box !important;
180
+ inline-size: min(var(--ui-site-header-navigation-width, 280px), 85vw);
181
+ max-inline-size: none;
182
+ block-size: 100dvh;
183
+ max-block-size: none;
184
+ margin: 0 !important;
185
+ padding: 0 !important;
186
+ overflow: hidden;
187
+ border: 0;
188
+ border-inline-end: var(--ui-border-width) solid var(--ui-overlay-border, var(--ui-border-divider));
189
+ background: var(--ui-overlay-surface, var(--ui-surface-elevated));
190
+ color: var(--ui-text-primary);
191
+ box-shadow: var(--ui-elevation-overlay, var(--ui-shadow-lg));
192
+ transform: translateX(-100%);
193
+ transition:
194
+ transform var(--ui-motion-reveal) var(--ui-motion-reveal-ease),
195
+ display var(--ui-motion-reveal) allow-discrete,
196
+ overlay var(--ui-motion-reveal) allow-discrete;
197
+ }
198
+ :host(:state(drawer)) .navigation-panel[open] {
199
+ display: flex !important;
200
+ flex-direction: column !important;
201
+ align-items: stretch !important;
202
+ transform: translateX(0);
203
+ }
204
+ :host(:state(drawer)) .navigation-panel:dir(rtl):not([open]) {
205
+ transform: translateX(100%);
206
+ }
207
+ @starting-style {
208
+ :host(:state(drawer)) .navigation-panel[open] {
209
+ transform: translateX(-100%);
210
+ }
211
+ :host(:state(drawer)) .navigation-panel[open]:dir(rtl) {
212
+ transform: translateX(100%);
134
213
  }
135
- :host([breakpoint="lg"]) .menu {
136
- display: none !important;
214
+ }
215
+ :host {
216
+ --_ui-site-header-backdrop: var(--ui-overlay-backdrop, rgb(0 0 0 / 0.32));
217
+ }
218
+ .navigation-panel::backdrop {
219
+ background: var(--_ui-site-header-backdrop);
220
+ }
221
+ .navigation-panel[data-ui-backdrop-hidden]::backdrop {
222
+ background: transparent;
223
+ }
224
+ :host(:state(drawer)) .panel-heading {
225
+ display: flex !important;
226
+ align-items: center !important;
227
+ justify-content: space-between !important;
228
+ gap: var(--ui-space-3) !important;
229
+ padding: var(--ui-space-4) !important;
230
+ flex: none;
231
+ border-block-end: var(--ui-border-width) solid var(--ui-border-divider);
232
+ }
233
+ .panel-title {
234
+ font-size: var(--ui-font-size-lg);
235
+ font-weight: var(--ui-font-semibold);
236
+ line-height: var(--ui-line-height-tight);
237
+ }
238
+ :host(:state(drawer)) .navigation {
239
+ font-weight: var(--ui-font-normal);
240
+ flex: 1 1 auto;
241
+ flex-direction: column !important;
242
+ flex-wrap: nowrap !important;
243
+ align-items: stretch !important;
244
+ gap: var(--ui-space-4) !important;
245
+ min-block-size: 0;
246
+ overflow: auto;
247
+ --_ui-scroll-fade-direction: to bottom;
248
+ --_ui-scroll-fade-size: var(--ui-scroll-fade-size, 24px);
249
+ mask-image: linear-gradient(
250
+ var(--_ui-scroll-fade-direction),
251
+ transparent,
252
+ #000 var(--_ui-scroll-fade-start),
253
+ #000 calc(100% - var(--_ui-scroll-fade-end)),
254
+ transparent
255
+ );
256
+ animation: ui-scroll-fade-start linear, ui-scroll-fade-start-hold linear, ui-scroll-fade-end-hold linear, ui-scroll-fade-end linear;
257
+ animation-timeline: scroll(self block);
258
+ animation-range:
259
+ 0 var(--_ui-scroll-fade-size),
260
+ var(--_ui-scroll-fade-size) calc(100% + 1px),
261
+ -1px calc(100% - var(--_ui-scroll-fade-size)),
262
+ calc(100% - var(--_ui-scroll-fade-size)) 100%;
263
+ overscroll-behavior: contain;
264
+ padding: var(--ui-space-4) !important;
265
+ }
266
+ @media (prefers-reduced-motion: reduce) {
267
+ :host(:state(drawer)) .navigation-panel {
268
+ transition: none;
137
269
  }
138
270
  }
139
271
  :host[hidden] {
@@ -0,0 +1,82 @@
1
+ import { closeDialog, closeOverlay, openOverlay, requestTopOverlayClose, showDialog } from "../shared/overlay.js";
2
+
3
+ const BREAKPOINTS = { sm: "40rem", md: "48rem", lg: "64rem" };
4
+
5
+ /** Presents the authored navigation inline on desktop and in a modal drawer on mobile. */
6
+ export function connect(host) {
7
+ const { panel, trigger, close, navigation } = host.refs;
8
+ const document = panel.ownerDocument;
9
+ const view = document.defaultView;
10
+ const id = panel.id ||= `ui-site-navigation-${Math.random().toString(36).slice(2, 11)}`;
11
+ let media;
12
+ let breakpoint;
13
+ let open = false;
14
+ trigger.setAttribute("aria-controls", id);
15
+
16
+ const dismiss = () => {
17
+ if (!open) return;
18
+ open = false;
19
+ trigger.setAttribute("aria-expanded", "false");
20
+ closeDialog(panel);
21
+ closeOverlay(document, id);
22
+ };
23
+ const syncMode = () => {
24
+ const drawer = media?.matches ?? false;
25
+ if (drawer === host.state.drawer) return;
26
+ const focusedLink = navigation.contains(document.activeElement) ? document.activeElement : null;
27
+ dismiss();
28
+ // A pending overlay transition would keep the inline desktop navigation in the top layer.
29
+ for (const animation of panel.getAnimations()) animation.cancel();
30
+ if (drawer) closeDialog(panel);
31
+ else panel.setAttribute("open", "");
32
+ host.state.drawer = drawer;
33
+ if (!drawer) focusedLink?.focus({ preventScroll: true });
34
+ };
35
+ const watchBreakpoint = () => {
36
+ const next = host.props.breakpoint.value;
37
+ if (next === breakpoint) return;
38
+ breakpoint = next;
39
+ media?.removeEventListener("change", syncMode);
40
+ media = view.matchMedia(`(width < ${BREAKPOINTS[next] ?? BREAKPOINTS.lg})`);
41
+ media.addEventListener("change", syncMode);
42
+ syncMode();
43
+ };
44
+ const onTrigger = () => {
45
+ if (!host.state.drawer || open) return;
46
+ open = true;
47
+ trigger.setAttribute("aria-expanded", "true");
48
+ showDialog(panel, true);
49
+ openOverlay({ id, modal: true, element: panel, dismissible: true, requestClose: dismiss });
50
+ };
51
+ const onNavigation = (event) => {
52
+ if (event.target.closest?.("a[href]")) dismiss();
53
+ };
54
+ const onCancel = (event) => {
55
+ event.preventDefault();
56
+ requestTopOverlayClose(document, "escape", "keyboard");
57
+ };
58
+ const onClose = (event) => {
59
+ if (event.target === panel && !panel.open) dismiss();
60
+ };
61
+ trigger.addEventListener("click", onTrigger);
62
+ close.addEventListener("click", dismiss);
63
+ navigation.addEventListener("click", onNavigation);
64
+ panel.addEventListener("cancel", onCancel);
65
+ panel.addEventListener("close", onClose);
66
+ host.state.enhanced = true;
67
+ const stop = host.effect(watchBreakpoint);
68
+ watchBreakpoint();
69
+ return () => {
70
+ stop();
71
+ media?.removeEventListener("change", syncMode);
72
+ trigger.removeEventListener("click", onTrigger);
73
+ close.removeEventListener("click", dismiss);
74
+ navigation.removeEventListener("click", onNavigation);
75
+ panel.removeEventListener("cancel", onCancel);
76
+ panel.removeEventListener("close", onClose);
77
+ dismiss();
78
+ host.state.enhanced = false;
79
+ host.state.drawer = false;
80
+ panel.setAttribute("open", "");
81
+ };
82
+ }