ochreui 0.0.0-stage → 0.0.2
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/LICENSE +21 -0
- package/README.md +153 -2
- package/cli/ochreui.mjs +601 -0
- package/mcp/core.mjs +126 -0
- package/mcp/docs.json +906 -0
- package/mcp/server.mjs +23 -0
- package/package.json +393 -3
- package/registry/agent-team.ts +350 -0
- package/registry/avatar.ts +300 -0
- package/registry/badge.ts +207 -0
- package/registry/breadcrumb.ts +435 -0
- package/registry/button.ts +238 -0
- package/registry/card.ts +221 -0
- package/registry/change-summary.ts +200 -0
- package/registry/checkbox.ts +204 -0
- package/registry/code-block.ts +332 -0
- package/registry/color-picker.ts +720 -0
- package/registry/comment-thread.ts +503 -0
- package/registry/context-menu.ts +281 -0
- package/registry/cover-flow.ts +623 -0
- package/registry/date-picker.ts +799 -0
- package/registry/decision-inbox.ts +340 -0
- package/registry/dialog.ts +577 -0
- package/registry/dropdown-menu.ts +864 -0
- package/registry/email-draft.ts +916 -0
- package/registry/empty-calendar.ts +199 -0
- package/registry/empty-state.ts +164 -0
- package/registry/enrichment-orbit.ts +164 -0
- package/registry/filter-menu.ts +541 -0
- package/registry/form-field.ts +308 -0
- package/registry/frost-cloud.ts +381 -0
- package/registry/ghosted-chat.ts +210 -0
- package/registry/glow-cloud.ts +402 -0
- package/registry/grid-background.ts +164 -0
- package/registry/hover-card.ts +401 -0
- package/registry/icon-button.ts +133 -0
- package/registry/index.json +2124 -0
- package/registry/integration-beam.ts +588 -0
- package/registry/integration-grid.ts +209 -0
- package/registry/kbd.ts +176 -0
- package/registry/layer-stack.ts +351 -0
- package/registry/lead-sourcing.ts +285 -0
- package/registry/logo-cluster.ts +239 -0
- package/registry/logo-marquee.ts +505 -0
- package/registry/message-actions.ts +833 -0
- package/registry/model-orbit.ts +583 -0
- package/registry/model-wheel.ts +372 -0
- package/registry/notification-stack.ts +301 -0
- package/registry/number-input.ts +552 -0
- package/registry/number-ticker.ts +261 -0
- package/registry/ochre.css +917 -0
- package/registry/otp-input.ts +704 -0
- package/registry/overlay.ts +312 -0
- package/registry/pagination.ts +362 -0
- package/registry/popover.ts +296 -0
- package/registry/profile-menu.ts +332 -0
- package/registry/progress-tracker.ts +291 -0
- package/registry/rating.ts +461 -0
- package/registry/reaction-bar.ts +322 -0
- package/registry/region-map.ts +537 -0
- package/registry/resizable.ts +489 -0
- package/registry/scroll-area.ts +271 -0
- package/registry/segmented-control.ts +433 -0
- package/registry/select.ts +769 -0
- package/registry/separator.ts +97 -0
- package/registry/shimmer-loader.ts +211 -0
- package/registry/side-folder.ts +152 -0
- package/registry/skeleton.ts +136 -0
- package/registry/skill/INSTRUCTIONS.md +11 -0
- package/registry/skill/SKILL.md +65 -0
- package/registry/skill/checklist.md +45 -0
- package/registry/skill/references/agent-team.md +105 -0
- package/registry/skill/references/avatar.md +88 -0
- package/registry/skill/references/badge.md +92 -0
- package/registry/skill/references/breadcrumb.md +99 -0
- package/registry/skill/references/button.md +82 -0
- package/registry/skill/references/card.md +111 -0
- package/registry/skill/references/catalog.md +114 -0
- package/registry/skill/references/change-summary.md +103 -0
- package/registry/skill/references/checkbox.md +105 -0
- package/registry/skill/references/code-block.md +109 -0
- package/registry/skill/references/color-picker.md +138 -0
- package/registry/skill/references/comment-thread.md +164 -0
- package/registry/skill/references/context-menu.md +205 -0
- package/registry/skill/references/cover-flow.md +128 -0
- package/registry/skill/references/date-picker.md +154 -0
- package/registry/skill/references/decision-inbox.md +126 -0
- package/registry/skill/references/dialog.md +155 -0
- package/registry/skill/references/dropdown-menu.md +144 -0
- package/registry/skill/references/email-draft.md +182 -0
- package/registry/skill/references/empty-calendar.md +74 -0
- package/registry/skill/references/empty-state.md +118 -0
- package/registry/skill/references/enrichment-orbit.md +71 -0
- package/registry/skill/references/filter-menu.md +143 -0
- package/registry/skill/references/form-field.md +118 -0
- package/registry/skill/references/frost-cloud.md +80 -0
- package/registry/skill/references/ghosted-chat.md +75 -0
- package/registry/skill/references/glow-cloud.md +84 -0
- package/registry/skill/references/grid-background.md +76 -0
- package/registry/skill/references/hover-card.md +125 -0
- package/registry/skill/references/icon-button.md +99 -0
- package/registry/skill/references/integration-beam.md +107 -0
- package/registry/skill/references/integration-grid.md +100 -0
- package/registry/skill/references/kbd.md +65 -0
- package/registry/skill/references/layer-stack.md +115 -0
- package/registry/skill/references/lead-sourcing.md +92 -0
- package/registry/skill/references/logo-cluster.md +92 -0
- package/registry/skill/references/logo-marquee.md +123 -0
- package/registry/skill/references/message-actions.md +146 -0
- package/registry/skill/references/model-orbit.md +106 -0
- package/registry/skill/references/model-wheel.md +84 -0
- package/registry/skill/references/notification-stack.md +138 -0
- package/registry/skill/references/number-input.md +117 -0
- package/registry/skill/references/number-ticker.md +73 -0
- package/registry/skill/references/otp-input.md +142 -0
- package/registry/skill/references/pagination.md +112 -0
- package/registry/skill/references/popover.md +143 -0
- package/registry/skill/references/profile-menu.md +123 -0
- package/registry/skill/references/progress-tracker.md +122 -0
- package/registry/skill/references/rating.md +111 -0
- package/registry/skill/references/reaction-bar.md +128 -0
- package/registry/skill/references/region-map.md +109 -0
- package/registry/skill/references/resizable.md +127 -0
- package/registry/skill/references/scroll-area.md +113 -0
- package/registry/skill/references/segmented-control.md +96 -0
- package/registry/skill/references/select.md +122 -0
- package/registry/skill/references/separator.md +69 -0
- package/registry/skill/references/shimmer-loader.md +83 -0
- package/registry/skill/references/side-folder.md +75 -0
- package/registry/skill/references/skeleton.md +95 -0
- package/registry/skill/references/smart-recommendation.md +132 -0
- package/registry/skill/references/spinner.md +84 -0
- package/registry/skill/references/switch.md +79 -0
- package/registry/skill/references/tab-overload.md +70 -0
- package/registry/skill/references/tag-input.md +126 -0
- package/registry/skill/references/team-invite.md +94 -0
- package/registry/skill/references/testimonial-wall.md +110 -0
- package/registry/skill/references/text-area.md +115 -0
- package/registry/skill/references/text-field.md +126 -0
- package/registry/skill/references/text-reveal.md +71 -0
- package/registry/skill/references/thinking-loader.md +87 -0
- package/registry/skill/references/time-picker.md +122 -0
- package/registry/skill/references/tips-panel.md +115 -0
- package/registry/skill/references/toggle-group.md +98 -0
- package/registry/skill/references/tool-call-card.md +151 -0
- package/registry/skill/references/tooltip.md +94 -0
- package/registry/skill/references/tree-view.md +172 -0
- package/registry/skill/theming.md +57 -0
- package/registry/smart-recommendation.ts +415 -0
- package/registry/spinner.ts +67 -0
- package/registry/switch.ts +146 -0
- package/registry/tab-overload.ts +211 -0
- package/registry/tag-input.ts +620 -0
- package/registry/team-invite.ts +248 -0
- package/registry/testimonial-wall.ts +521 -0
- package/registry/text-area.ts +432 -0
- package/registry/text-field.ts +415 -0
- package/registry/text-reveal.ts +175 -0
- package/registry/theme.ts +68 -0
- package/registry/thinking-loader.ts +302 -0
- package/registry/time-picker.ts +828 -0
- package/registry/tips-panel.ts +312 -0
- package/registry/toggle-group.ts +357 -0
- package/registry/tool-call-card.ts +578 -0
- package/registry/tooltip.ts +486 -0
- package/registry/tree-view.ts +454 -0
- package/styles/base.css +500 -0
- package/styles/tokens.css +415 -0
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
// Ochre (https://ochreui.dev), MIT License, Copyright (c) 2026 Ochre. Keep this notice in copies of this file.
|
|
2
|
+
/**
|
|
3
|
+
* Popover, from Ochre (https://ochreui.dev).
|
|
4
|
+
* Needs ochre.css (`npx ochreui init`) and overlay.ts (`npx ochreui add overlay`).
|
|
5
|
+
*
|
|
6
|
+
* <button uiButton [uiPopoverTrigger]="pop">Share</button>
|
|
7
|
+
* <ui-popover #pop [(open)]="sharing" title="Share the report" description="…"> your form </ui-popover>
|
|
8
|
+
* A small card attached to its trigger. It stays on screen, closes on a press outside, Escape or Tab,
|
|
9
|
+
* and gives focus back to the trigger.
|
|
10
|
+
*
|
|
11
|
+
* Public styling hooks (set them on the element or any ancestor):
|
|
12
|
+
* --ui-popover-bg fill (default: the overlay surface, a step lighter in dark mode)
|
|
13
|
+
* --ui-popover-fg text
|
|
14
|
+
* --ui-popover-radius corners (default 12px; Classic 16px)
|
|
15
|
+
* --ui-popover-padding inner space (default 14px; Classic 16px)
|
|
16
|
+
* --ui-popover-shadow ring and drop shadow
|
|
17
|
+
* --ui-popover-width width when the `width` input is not set (default: fits the content)
|
|
18
|
+
* --ui-popover-drift how far it glides in from the trigger (default 4px)
|
|
19
|
+
* --ui-popover-from starting scale (default 0.96)
|
|
20
|
+
*/
|
|
21
|
+
import {
|
|
22
|
+
Component,
|
|
23
|
+
DOCUMENT,
|
|
24
|
+
DestroyRef,
|
|
25
|
+
Directive,
|
|
26
|
+
ElementRef,
|
|
27
|
+
EmbeddedViewRef,
|
|
28
|
+
PLATFORM_ID,
|
|
29
|
+
TemplateRef,
|
|
30
|
+
ViewContainerRef,
|
|
31
|
+
afterRenderEffect,
|
|
32
|
+
booleanAttribute,
|
|
33
|
+
computed,
|
|
34
|
+
contentChild,
|
|
35
|
+
effect,
|
|
36
|
+
inject,
|
|
37
|
+
input,
|
|
38
|
+
isDevMode,
|
|
39
|
+
model,
|
|
40
|
+
numberAttribute,
|
|
41
|
+
output,
|
|
42
|
+
signal,
|
|
43
|
+
untracked,
|
|
44
|
+
viewChild,
|
|
45
|
+
} from '@angular/core';
|
|
46
|
+
import { isPlatformBrowser } from '@angular/common';
|
|
47
|
+
import { OverlayAlign, OverlayDismiss, OverlayRef, OverlaySide, firstFocusable } from './overlay';
|
|
48
|
+
|
|
49
|
+
export type PopoverSide = OverlaySide;
|
|
50
|
+
export type PopoverAlign = OverlayAlign;
|
|
51
|
+
export type PopoverDismiss = OverlayDismiss;
|
|
52
|
+
|
|
53
|
+
const HASPOPUP = ['dialog', 'menu', 'listbox', 'tree', 'grid'];
|
|
54
|
+
|
|
55
|
+
let nextId = 0;
|
|
56
|
+
|
|
57
|
+
/** Lazy content: `<ng-template uiPopoverContent>` is created on open and destroyed on close. */
|
|
58
|
+
@Directive({ selector: 'ng-template[uiPopoverContent]' })
|
|
59
|
+
export class UiPopoverContent {
|
|
60
|
+
readonly template = inject(TemplateRef);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The card. Write it next to its trigger; it is promoted to the top layer while open. */
|
|
64
|
+
@Component({
|
|
65
|
+
selector: 'ui-popover',
|
|
66
|
+
exportAs: 'uiPopover',
|
|
67
|
+
host: {
|
|
68
|
+
popover: 'manual',
|
|
69
|
+
tabindex: '-1',
|
|
70
|
+
'[id]': 'id()',
|
|
71
|
+
'[attr.role]': 'role()',
|
|
72
|
+
'[attr.title]': 'null',
|
|
73
|
+
'[attr.aria-labelledby]': 'title() ? id() + "-title" : (ariaLabelledby() ?? null)',
|
|
74
|
+
'[attr.aria-describedby]': 'describedBy()',
|
|
75
|
+
'[attr.data-unstyled]': 'unstyled() || null',
|
|
76
|
+
'[style.--ui-popover-width]': 'size()',
|
|
77
|
+
},
|
|
78
|
+
template: `
|
|
79
|
+
@if (title() || description()) {
|
|
80
|
+
<div class="head">
|
|
81
|
+
@if (title()) {<p class="title" [id]="id() + '-title'" dir="auto">{{ title() }}</p>}
|
|
82
|
+
@if (description()) {<p class="desc" [id]="id() + '-desc'" dir="auto">{{ description() }}</p>}
|
|
83
|
+
</div>
|
|
84
|
+
}
|
|
85
|
+
<div class="body" [id]="id() + '-body'"><ng-content /><ng-container #slot /></div>
|
|
86
|
+
`,
|
|
87
|
+
styles: `
|
|
88
|
+
:host {
|
|
89
|
+
--_t: var(--ui-look-tray, 0);
|
|
90
|
+
--_d: var(--ui-popover-drift, 4px);
|
|
91
|
+
--_x: 0;
|
|
92
|
+
--_y: 0;
|
|
93
|
+
position: fixed;
|
|
94
|
+
inset: auto;
|
|
95
|
+
z-index: var(--ui-z-popover);
|
|
96
|
+
box-sizing: border-box;
|
|
97
|
+
inline-size: var(--ui-popover-width, max-content);
|
|
98
|
+
max-inline-size: calc(100vw - 16px);
|
|
99
|
+
max-block-size: calc(100dvh - 16px);
|
|
100
|
+
margin: 0;
|
|
101
|
+
padding: var(--ui-popover-padding, calc(var(--ui-space-3) + 2px + 2px * var(--_t)));
|
|
102
|
+
overflow: auto;
|
|
103
|
+
overscroll-behavior: contain;
|
|
104
|
+
border: 1px solid transparent;
|
|
105
|
+
border-radius: var(--ui-popover-radius, calc(var(--ui-radius-lg) + 4px * var(--_t)));
|
|
106
|
+
outline: none;
|
|
107
|
+
background: var(--ui-popover-bg, var(--ui-bg-overlay));
|
|
108
|
+
box-shadow: var(--ui-popover-shadow, var(--ui-shadow-md));
|
|
109
|
+
color: var(--ui-popover-fg, var(--ui-text));
|
|
110
|
+
font: calc(var(--ui-text-base) + 0.5px * var(--_t)) / var(--ui-leading-base) var(--ui-font-sans);
|
|
111
|
+
text-align: start;
|
|
112
|
+
transition: var(--ui-duration-3) var(--ui-ease-out);
|
|
113
|
+
transition-property: opacity, scale, translate;
|
|
114
|
+
}
|
|
115
|
+
:host(:not([data-open])) { display: none !important; }
|
|
116
|
+
:host([data-side='top']) { --_y: var(--_d); }
|
|
117
|
+
:host([data-side='bottom']) { --_y: calc(var(--_d) * -1); }
|
|
118
|
+
:host([data-side='left']) { --_x: var(--_d); }
|
|
119
|
+
:host([data-side='right']) { --_x: calc(var(--_d) * -1); }
|
|
120
|
+
:host([data-enter]) { opacity: 0; scale: var(--ui-popover-from, 0.96); translate: var(--_x) var(--_y); transition: none; }
|
|
121
|
+
:host([data-unstyled]) { padding: 0; border-radius: 0; background: none; box-shadow: none; color: inherit; font: inherit; }
|
|
122
|
+
.head { display: grid; gap: var(--ui-space-0-5); margin-block-end: calc(var(--ui-space-3) + 2px * var(--_t)); }
|
|
123
|
+
p { margin: 0; overflow-wrap: anywhere; }
|
|
124
|
+
.title { font-weight: var(--ui-weight-medium); }
|
|
125
|
+
.desc { color: var(--ui-text-muted); font-size: calc(var(--ui-text-sm) + 0.5px * var(--_t)); line-height: calc(var(--ui-leading-xs) + 1px * var(--_t)); }
|
|
126
|
+
.body { display: contents; }
|
|
127
|
+
@media (pointer: coarse) {
|
|
128
|
+
.desc { font-size: var(--ui-text-base); line-height: var(--ui-leading-sm); }
|
|
129
|
+
}
|
|
130
|
+
`,
|
|
131
|
+
})
|
|
132
|
+
export class UiPopover {
|
|
133
|
+
/** Shows it. Bind `[(open)]`: it turns false by itself on a press outside, Escape or Tab out. */
|
|
134
|
+
readonly open = model(false);
|
|
135
|
+
/** Preferred side. It flips when the other side has more room. */
|
|
136
|
+
readonly side = input<PopoverSide>('bottom');
|
|
137
|
+
/** Which edges line up. Start is the left edge, or the right one in right-to-left pages. Switches when it would stick out. */
|
|
138
|
+
readonly align = input<PopoverAlign>('start');
|
|
139
|
+
/** Gap to the anchor, in px. */
|
|
140
|
+
readonly offset = input(6, { transform: numberAttribute });
|
|
141
|
+
/** What it attaches to. Default: its `uiPopoverTrigger`, else its parent element. */
|
|
142
|
+
readonly anchor = input<HTMLElement | ElementRef<HTMLElement> | null>(null);
|
|
143
|
+
/** Heading at the top, and the accessible name. */
|
|
144
|
+
readonly title = input<string>();
|
|
145
|
+
/** A quiet line under the title, read as the description. */
|
|
146
|
+
readonly description = input<string>();
|
|
147
|
+
/** Card width: a number of px or any CSS length. Default: fits the content, never wider than the window. */
|
|
148
|
+
readonly width = input<number | string>();
|
|
149
|
+
/** Moves focus inside on open: `[autofocus]`, the first control, or the card. Never when open from the first render. */
|
|
150
|
+
readonly focusOnOpen = input(true, { transform: booleanAttribute });
|
|
151
|
+
/** Placement, motion and closing only, with no card look: your class draws it. */
|
|
152
|
+
readonly unstyled = input(false, { transform: booleanAttribute });
|
|
153
|
+
/** `dialog` by default; menus pass `menu`, selects `listbox`. */
|
|
154
|
+
readonly role = input('dialog');
|
|
155
|
+
readonly id = input(`ui-popover-${nextId++}`);
|
|
156
|
+
/** Your own label element, used when there is no title. */
|
|
157
|
+
readonly ariaLabelledby = input<string>(undefined, { alias: 'aria-labelledby' });
|
|
158
|
+
/** Your own descriptions, kept alongside the description. */
|
|
159
|
+
readonly ariaDescribedby = input<string>(undefined, { alias: 'aria-describedby' });
|
|
160
|
+
/** Why it closed by itself, just before `open` turns false. */
|
|
161
|
+
readonly dismissed = output<PopoverDismiss>();
|
|
162
|
+
|
|
163
|
+
private readonly el = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
|
|
164
|
+
private readonly lazy = contentChild(UiPopoverContent);
|
|
165
|
+
private readonly slot = viewChild.required('slot', { read: ViewContainerRef });
|
|
166
|
+
private readonly triggerEl = signal<HTMLElement | null>(null);
|
|
167
|
+
private readonly plain = signal(false);
|
|
168
|
+
protected readonly size = computed(() => {
|
|
169
|
+
const w = this.width();
|
|
170
|
+
return typeof w === 'number' ? `${w}px` : w || null;
|
|
171
|
+
});
|
|
172
|
+
protected readonly describedBy = computed(
|
|
173
|
+
() =>
|
|
174
|
+
[this.ariaDescribedby(), this.description() ? `${this.id()}-desc` : this.plain() && !this.title() ? `${this.id()}-body` : '']
|
|
175
|
+
.filter(Boolean)
|
|
176
|
+
.join(' ') || null,
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
private readonly overlay = isPlatformBrowser(inject(PLATFORM_ID))
|
|
180
|
+
? new OverlayRef(this.el, inject(DOCUMENT), {
|
|
181
|
+
anchor: () => this.anchorEl(),
|
|
182
|
+
trigger: () => this.triggerEl(),
|
|
183
|
+
side: () => this.side(),
|
|
184
|
+
align: () => this.align(),
|
|
185
|
+
offset: () => this.offset(),
|
|
186
|
+
dismiss: (reason) => this.dismiss(reason),
|
|
187
|
+
})
|
|
188
|
+
: null;
|
|
189
|
+
private view?: EmbeddedViewRef<unknown>;
|
|
190
|
+
private reason?: PopoverDismiss;
|
|
191
|
+
private first = true;
|
|
192
|
+
private warned = false;
|
|
193
|
+
|
|
194
|
+
constructor() {
|
|
195
|
+
afterRenderEffect(() => {
|
|
196
|
+
const on = this.open();
|
|
197
|
+
untracked(() => this.sync(on));
|
|
198
|
+
});
|
|
199
|
+
afterRenderEffect(() => {
|
|
200
|
+
this.side();
|
|
201
|
+
this.align();
|
|
202
|
+
this.offset();
|
|
203
|
+
this.size();
|
|
204
|
+
untracked(() => this.overlay?.place());
|
|
205
|
+
});
|
|
206
|
+
inject(DestroyRef).onDestroy(() => this.overlay?.hide(false));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
show() {
|
|
210
|
+
this.open.set(true);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** Closes it; focus goes back to the trigger if it was inside. */
|
|
214
|
+
hide() {
|
|
215
|
+
this.open.set(false);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
toggle() {
|
|
219
|
+
if (this.open()) this.dismiss('trigger');
|
|
220
|
+
else this.open.set(true);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** Places it again, after a change of size the popover cannot see. */
|
|
224
|
+
reposition() {
|
|
225
|
+
this.overlay?.place();
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** Called by `uiPopoverTrigger`. */
|
|
229
|
+
registerTrigger(el: HTMLElement | null) {
|
|
230
|
+
this.triggerEl.set(el);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
private anchorEl() {
|
|
234
|
+
const a = this.anchor();
|
|
235
|
+
return (a instanceof ElementRef ? a.nativeElement : a) ?? this.triggerEl() ?? this.el.parentElement;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
private dismiss(reason: PopoverDismiss) {
|
|
239
|
+
if (!this.open()) return;
|
|
240
|
+
this.reason = reason;
|
|
241
|
+
this.dismissed.emit(reason);
|
|
242
|
+
this.open.set(false);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
private sync(on: boolean) {
|
|
246
|
+
const focus = !this.first && this.focusOnOpen();
|
|
247
|
+
this.first = false;
|
|
248
|
+
if (!this.overlay) return;
|
|
249
|
+
if (!on) {
|
|
250
|
+
const reason = this.reason;
|
|
251
|
+
this.reason = undefined;
|
|
252
|
+
this.overlay.hide(reason !== 'outside' && reason !== 'focus-out');
|
|
253
|
+
this.view?.destroy();
|
|
254
|
+
this.view = undefined;
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const lazy = this.lazy();
|
|
258
|
+
if (lazy && !this.view) {
|
|
259
|
+
this.view = this.slot().createEmbeddedView(lazy.template);
|
|
260
|
+
this.view.detectChanges();
|
|
261
|
+
}
|
|
262
|
+
this.plain.set(!firstFocusable(this.el));
|
|
263
|
+
this.overlay.show(focus);
|
|
264
|
+
if (isDevMode() && !this.warned && !this.title() && !this.el.hasAttribute('aria-label') && !this.el.hasAttribute('aria-labelledby')) {
|
|
265
|
+
this.warned = true;
|
|
266
|
+
console.warn('ui-popover: give it a title, an aria-label or an aria-labelledby.', this.el);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** Put it on the button that opens the popover: `[uiPopoverTrigger]="pop"`. It toggles it and sets the ARIA. */
|
|
272
|
+
@Directive({
|
|
273
|
+
selector: '[uiPopoverTrigger]',
|
|
274
|
+
host: {
|
|
275
|
+
'[attr.aria-haspopup]': 'popup()',
|
|
276
|
+
'[attr.aria-expanded]': 'uiPopoverTrigger().open()',
|
|
277
|
+
'[attr.aria-controls]': 'uiPopoverTrigger().open() ? uiPopoverTrigger().id() : null',
|
|
278
|
+
'(click)': 'uiPopoverTrigger().toggle()',
|
|
279
|
+
},
|
|
280
|
+
})
|
|
281
|
+
export class UiPopoverTrigger {
|
|
282
|
+
readonly uiPopoverTrigger = input.required<UiPopover>();
|
|
283
|
+
private readonly el = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
|
|
284
|
+
protected readonly popup = computed(() => {
|
|
285
|
+
const role = this.uiPopoverTrigger().role();
|
|
286
|
+
return HASPOPUP.includes(role) ? role : 'dialog';
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
constructor() {
|
|
290
|
+
effect((onCleanup) => {
|
|
291
|
+
const popover = this.uiPopoverTrigger();
|
|
292
|
+
popover.registerTrigger(this.el);
|
|
293
|
+
onCleanup(() => popover.registerTrigger(null));
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
// Ochre (https://ochreui.dev), MIT License, Copyright (c) 2026 Ochre. Keep this notice in copies of this file.
|
|
2
|
+
/**
|
|
3
|
+
* Profile Menu, from Ochre (https://ochreui.dev).
|
|
4
|
+
* Needs ochre.css (`npx ochreui init`).
|
|
5
|
+
*
|
|
6
|
+
* <ui-profile-menu name="Noor Aziz" email="noor@northwind.dev" [setup]="{ done: 2, total: 4, next: 'Verify your email' }" (continue)="verify()">
|
|
7
|
+
* <ui-avatar uiProfileAvatar name="Noor Aziz" aria-hidden="true" />
|
|
8
|
+
* <a uiProfileMenuItem routerLink="/settings"><svg class="ui-icon" …/><span>Settings</span></a>
|
|
9
|
+
* <button uiProfileMenuItem (click)="signOut()"><svg class="ui-icon" …/><span>Log out</span></button>
|
|
10
|
+
* </ui-profile-menu>
|
|
11
|
+
* The account card behind the avatar in an app header: who is signed in, your own actions as a menu
|
|
12
|
+
* with one Tab stop, and an optional profile-setup progress bar.
|
|
13
|
+
*
|
|
14
|
+
* Public styling hooks (set them on the element or any ancestor):
|
|
15
|
+
* --ui-profile-menu-width card width (default 260px; Classic 320px); it shrinks with its container
|
|
16
|
+
* --ui-profile-menu-avatar avatar size (default 32px; Classic 40px)
|
|
17
|
+
* --ui-profile-menu-bg card fill (default: the surface)
|
|
18
|
+
* --ui-profile-menu-track progress track (default: the muted fill)
|
|
19
|
+
* --ui-profile-menu-fill progress fill (default: the accent)
|
|
20
|
+
*/
|
|
21
|
+
import {
|
|
22
|
+
Component,
|
|
23
|
+
DOCUMENT,
|
|
24
|
+
Directive,
|
|
25
|
+
ElementRef,
|
|
26
|
+
afterNextRender,
|
|
27
|
+
afterRenderEffect,
|
|
28
|
+
booleanAttribute,
|
|
29
|
+
computed,
|
|
30
|
+
contentChildren,
|
|
31
|
+
forwardRef,
|
|
32
|
+
inject,
|
|
33
|
+
input,
|
|
34
|
+
isDevMode,
|
|
35
|
+
output,
|
|
36
|
+
signal,
|
|
37
|
+
viewChild,
|
|
38
|
+
} from '@angular/core';
|
|
39
|
+
|
|
40
|
+
export interface ProfileSetup {
|
|
41
|
+
/** Steps finished, clamped to 0…total. */
|
|
42
|
+
done: number;
|
|
43
|
+
total: number;
|
|
44
|
+
/** The next step, shown on the button under the bar. Leave it out to hide the button. */
|
|
45
|
+
next?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ProfileMenuLabels {
|
|
49
|
+
/** The menu's accessible name. */
|
|
50
|
+
menu: string;
|
|
51
|
+
/** The setup block's title, also the progress bar's name. */
|
|
52
|
+
setup: string;
|
|
53
|
+
/** Shown before the next step on the button. */
|
|
54
|
+
next: string;
|
|
55
|
+
/** What screen readers hear for the bar. */
|
|
56
|
+
progress: (done: number, total: number) => string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const LABELS: ProfileMenuLabels = {
|
|
60
|
+
menu: 'Account',
|
|
61
|
+
setup: 'Profile setup',
|
|
62
|
+
next: 'Next:',
|
|
63
|
+
progress: (done, total) => `${done} of ${total} steps done`,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const T = 'var(--_t)';
|
|
67
|
+
const ELLIPSIS = 'overflow: hidden; text-overflow: ellipsis; white-space: nowrap';
|
|
68
|
+
const ITEM =
|
|
69
|
+
'display: flex; align-items: center; box-sizing: border-box; inline-size: 100%; min-inline-size: 0; margin: 0; border: 0; ' +
|
|
70
|
+
`gap: calc(var(--ui-space-2-5) + 2px * ${T}); min-block-size: calc(var(--ui-control-h-md) + 4px * ${T}); ` +
|
|
71
|
+
`padding: 0 calc(var(--ui-space-2) + 4px * ${T}); border-radius: calc(var(--ui-radius-sm) + 6px * ${T}); ` +
|
|
72
|
+
`color: var(--ui-text); font: calc(var(--ui-text-base) + 1px * ${T}) / var(--ui-leading-base) var(--ui-font-sans); ` +
|
|
73
|
+
'text-align: start; text-decoration: none; white-space: nowrap; cursor: pointer; -webkit-tap-highlight-color: transparent; ' +
|
|
74
|
+
'transition: background-color var(--_e)';
|
|
75
|
+
const PANEL =
|
|
76
|
+
`padding: calc(var(--ui-space-4) * ${T}) calc(var(--ui-space-2) * ${T}) calc(var(--ui-space-2) * ${T}); ` +
|
|
77
|
+
`border: calc(1px * ${T}) solid var(--ui-border); border-radius: calc((var(--ui-radius-xl) - 2px) * ${T}); background: var(--_bg)`;
|
|
78
|
+
const HEAD =
|
|
79
|
+
`display: flex; align-items: center; gap: calc(var(--ui-space-2-5) + 4px * ${T}); margin-inline: calc(var(--_p) * (${T} - 1)); ` +
|
|
80
|
+
`padding: calc(var(--ui-space-2) * (1 - ${T})) calc(var(--ui-space-3) - 2px * ${T}) calc(var(--ui-space-2-5) + 2px * ${T}); ` +
|
|
81
|
+
`border-block-end: calc(1px - 1px * ${T}) solid var(--ui-hairline)`;
|
|
82
|
+
const AVATAR =
|
|
83
|
+
'display: grid; place-items: center; flex: none; inline-size: var(--_av); block-size: var(--_av); border-radius: 50%; overflow: hidden; background: var(--ui-accent-soft); color: var(--ui-accent)';
|
|
84
|
+
const NAME = `${ELLIPSIS}; font-weight: var(--ui-weight-medium); font-size: calc(var(--ui-text-base) + 2px * ${T}); line-height: calc(var(--ui-leading-base) + 2px * ${T})`;
|
|
85
|
+
const EMAIL = `${ELLIPSIS}; color: var(--ui-text-muted); font-size: calc(var(--ui-text-sm) + 1px * ${T}); line-height: calc(var(--ui-leading-xs) + 4px * ${T})`;
|
|
86
|
+
const SETUP =
|
|
87
|
+
`margin: calc(var(--ui-space-1) * (1 - ${T})) calc(var(--_p) * (${T} - 1)) calc(var(--_p) * (${T} - 1)); ` +
|
|
88
|
+
`padding: var(--ui-space-2-5) calc(var(--ui-space-3) + 6px * ${T}) calc(var(--ui-space-1-5) + 6px * ${T}); ` +
|
|
89
|
+
`border-block-start: calc(1px - 1px * ${T}) solid var(--ui-hairline)`;
|
|
90
|
+
const ROW = `display: flex; justify-content: space-between; gap: var(--ui-space-2); font-size: calc(var(--ui-text-sm) + 1px * ${T}); line-height: calc(var(--ui-leading-xs) + 2px * ${T})`;
|
|
91
|
+
const MUTED = 'color: var(--ui-text-muted); font-variant-numeric: tabular-nums';
|
|
92
|
+
const BAR = `display: block; block-size: var(--ui-space-1); margin-block-start: calc(var(--ui-space-2) - 1px * ${T}); border-radius: var(--ui-radius-full); overflow: hidden`;
|
|
93
|
+
const FILL =
|
|
94
|
+
'display: block; block-size: 100%; transform-origin: var(--_o); transition: scale calc(900ms * var(--ui-motion-scale)) var(--ui-ease-out) calc(150ms * var(--ui-motion-scale))';
|
|
95
|
+
const NEXT =
|
|
96
|
+
'display: flex; align-items: center; gap: var(--ui-space-2); box-sizing: border-box; inline-size: calc(100% + var(--ui-space-4)); ' +
|
|
97
|
+
`block-size: calc(var(--ui-control-h-sm) - 2px * ${T}); margin: var(--ui-space-1-5) calc(var(--ui-space-2) * -1) 0; padding: 0 var(--ui-space-2); ` +
|
|
98
|
+
`border: 0; border-radius: calc(var(--ui-radius-sm) + 2px * ${T}); color: var(--ui-text); font: inherit; text-align: start; cursor: pointer; ` +
|
|
99
|
+
'transition: background-color var(--_e)';
|
|
100
|
+
const ARROW =
|
|
101
|
+
`inline-size: calc(var(--ui-icon-md) - 2px * ${T}); block-size: calc(var(--ui-icon-md) - 2px * ${T}); scale: var(--_dir) 1; ` +
|
|
102
|
+
'transition: color var(--_e), translate calc(200ms * var(--ui-motion-scale)) var(--ui-ease-out)';
|
|
103
|
+
|
|
104
|
+
/** One action: `<button uiProfileMenuItem>` or `<a uiProfileMenuItem>`, holding an icon, a `<span>` label and an optional `.ui-badge`. */
|
|
105
|
+
@Directive({
|
|
106
|
+
selector: 'button[uiProfileMenuItem], a[uiProfileMenuItem]',
|
|
107
|
+
host: {
|
|
108
|
+
role: 'menuitem',
|
|
109
|
+
style: ITEM,
|
|
110
|
+
'[attr.type]': 'button ? "button" : null',
|
|
111
|
+
'[attr.tabindex]': 'menu.stop() === this ? 0 : -1',
|
|
112
|
+
'[attr.aria-disabled]': 'disabled() || null',
|
|
113
|
+
'[attr.disabled]': 'button && disabled() ? "" : null',
|
|
114
|
+
'(focus)': 'menu.active.set(this)',
|
|
115
|
+
},
|
|
116
|
+
})
|
|
117
|
+
export class UiProfileMenuItem {
|
|
118
|
+
/** Skipped by the arrow keys and typeahead. On a link it sets `aria-disabled` and blocks clicks. */
|
|
119
|
+
readonly disabled = input(false, { transform: booleanAttribute });
|
|
120
|
+
|
|
121
|
+
readonly el = inject<ElementRef<HTMLButtonElement | HTMLAnchorElement>>(ElementRef).nativeElement;
|
|
122
|
+
protected readonly button = this.el.localName === 'button';
|
|
123
|
+
protected readonly menu = inject<UiProfileMenu>(forwardRef(() => UiProfileMenu));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@Component({
|
|
127
|
+
selector: 'ui-profile-menu',
|
|
128
|
+
template: `
|
|
129
|
+
<div style="${PANEL}">
|
|
130
|
+
<div style="${HEAD}">
|
|
131
|
+
<span style="${AVATAR}">
|
|
132
|
+
<ng-content select="[uiProfileAvatar]">
|
|
133
|
+
<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true" style="inline-size: 56%; block-size: 56%"><circle cx="12" cy="8" r="4.25" /><path d="M4 20.25c0-3.6 3.6-6 8-6s8 2.4 8 6c0 .7-.5 1-1.2 1H5.2c-.7 0-1.2-.3-1.2-1z" /></svg>
|
|
134
|
+
</ng-content>
|
|
135
|
+
</span>
|
|
136
|
+
<span style="display: grid; min-inline-size: 0">
|
|
137
|
+
<span dir="auto" style="${NAME}">{{ name() }}</span>
|
|
138
|
+
@if (email()) {<span dir="auto" style="${EMAIL}">{{ email() }}</span>}
|
|
139
|
+
</span>
|
|
140
|
+
</div>
|
|
141
|
+
<div style="margin-block-start: calc(var(--ui-space-1) + 2px * var(--_t))" [style.display]="items().length ? 'grid' : 'none'" [attr.role]="items().length ? 'menu' : null"
|
|
142
|
+
[attr.aria-label]="items().length ? l().menu : null" (keydown)="key($event)" (click)="clicked($event)">
|
|
143
|
+
<ng-content />
|
|
144
|
+
</div>
|
|
145
|
+
</div>
|
|
146
|
+
@if (progress(); as p) {
|
|
147
|
+
<div style="${SETUP}">
|
|
148
|
+
<div style="${ROW}"><span style="font-weight: var(--ui-weight-medium)">{{ l().setup }}</span><span aria-hidden="true" style="${MUTED}">{{ p.done }}/{{ p.total }}</span></div>
|
|
149
|
+
<span #bar class="bar" role="progressbar" style="${BAR}" [attr.aria-label]="l().setup" aria-valuemin="0" [attr.aria-valuemax]="p.total"
|
|
150
|
+
[attr.aria-valuenow]="p.done" [attr.aria-valuetext]="l().progress(p.done, p.total)">
|
|
151
|
+
<span class="fill" style="${FILL}" [style.--_f]="p.done / p.total" [attr.data-on]="seen() || null"></span>
|
|
152
|
+
</span>
|
|
153
|
+
@if (p.next) {
|
|
154
|
+
<button type="button" class="ui-pm-next" style="${NEXT}" (click)="continue.emit()">
|
|
155
|
+
<span dir="auto" style="flex: 1; ${ELLIPSIS}"><span style="${MUTED}">{{ l().next }}</span> {{ p.next }}</span>
|
|
156
|
+
<svg class="ui-icon" viewBox="0 0 24 24" aria-hidden="true" style="${ARROW}"><path d="M5 12h14M13 6l6 6-6 6" /></svg>
|
|
157
|
+
</button>
|
|
158
|
+
}
|
|
159
|
+
</div>
|
|
160
|
+
}
|
|
161
|
+
`,
|
|
162
|
+
styles: `
|
|
163
|
+
:host {
|
|
164
|
+
--_t: var(--ui-look-tray, 0);
|
|
165
|
+
--_p: calc(var(--ui-space-1) + 2px * var(--_t));
|
|
166
|
+
--_av: var(--ui-profile-menu-avatar, calc(var(--ui-space-8) + var(--ui-space-2) * var(--_t)));
|
|
167
|
+
--_bg: var(--ui-profile-menu-bg, var(--ui-bg-surface));
|
|
168
|
+
--_e: calc((140ms + 20ms * var(--_t)) * var(--ui-motion-scale)) var(--ui-ease-out);
|
|
169
|
+
--_dir: 1;
|
|
170
|
+
--_o: left;
|
|
171
|
+
display: block;
|
|
172
|
+
box-sizing: border-box;
|
|
173
|
+
inline-size: min(var(--ui-profile-menu-width, calc(260px + 60px * var(--_t))), 100%);
|
|
174
|
+
padding: var(--_p);
|
|
175
|
+
border-radius: calc(10px + 12px * var(--_t));
|
|
176
|
+
background: linear-gradient(var(--ui-tray-bg) 0 0), var(--_bg);
|
|
177
|
+
box-shadow: var(--ui-shadow-md);
|
|
178
|
+
color: var(--ui-text);
|
|
179
|
+
font: var(--ui-text-base) / var(--ui-leading-base) var(--ui-font-sans);
|
|
180
|
+
}
|
|
181
|
+
:host(:dir(rtl)) { --_dir: -1; --_o: right; }
|
|
182
|
+
@container style(--ui-look-tray: 1) { :host { box-shadow: none; } }
|
|
183
|
+
:host ::ng-deep [uiProfileAvatar] { inline-size: 100%; block-size: 100%; font-size: calc(var(--_av) * 3 / 8); object-fit: cover; }
|
|
184
|
+
:host ::ng-deep :is([uiProfileMenuItem], .ui-pm-next) { background: none; }
|
|
185
|
+
:host ::ng-deep :is([uiProfileMenuItem], .ui-pm-next) > svg { color: var(--ui-icon); transition: color var(--_e); }
|
|
186
|
+
:host ::ng-deep [uiProfileMenuItem] > svg { inline-size: calc(var(--ui-icon-md) + 4px * var(--_t)); block-size: calc(var(--ui-icon-md) + 4px * var(--_t)); }
|
|
187
|
+
:host ::ng-deep [uiProfileMenuItem] > span:not(.ui-badge) { flex: 1; min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; }
|
|
188
|
+
:host ::ng-deep :is([uiProfileMenuItem]:not([aria-disabled]), .ui-pm-next):focus-visible { background: color-mix(in srgb, var(--ui-text) 6%, transparent); }
|
|
189
|
+
:host ::ng-deep :is([uiProfileMenuItem], .ui-pm-next):focus-visible > svg { color: var(--ui-icon-active); }
|
|
190
|
+
@media (hover: hover) {
|
|
191
|
+
:host ::ng-deep :is([uiProfileMenuItem]:not([aria-disabled]), .ui-pm-next):hover { background: color-mix(in srgb, var(--ui-text) 6%, transparent); }
|
|
192
|
+
:host ::ng-deep :is([uiProfileMenuItem], .ui-pm-next):hover > svg { color: var(--ui-icon-active); }
|
|
193
|
+
}
|
|
194
|
+
:host ::ng-deep :is([uiProfileMenuItem]:not([aria-disabled]), .ui-pm-next):active { background: color-mix(in srgb, var(--ui-text) 10%, transparent); }
|
|
195
|
+
@media (hover: hover) { :host ::ng-deep .ui-pm-next:hover > svg { translate: calc(2px * var(--_dir)); } }
|
|
196
|
+
:host ::ng-deep :focus-visible { outline: var(--ui-focus-width) solid var(--ui-focus-ring); outline-offset: var(--ui-focus-offset-inset); }
|
|
197
|
+
:host ::ng-deep [uiProfileMenuItem][aria-disabled] { opacity: var(--ui-disabled-opacity); cursor: not-allowed; }
|
|
198
|
+
:host ::ng-deep a[aria-disabled] { pointer-events: none; }
|
|
199
|
+
:host ::ng-deep [uiProfileMenuItem] .ui-badge {
|
|
200
|
+
box-sizing: border-box;
|
|
201
|
+
block-size: calc(18px + 4px * var(--_t));
|
|
202
|
+
padding-inline: calc(var(--ui-space-1-5) + 2px * var(--_t));
|
|
203
|
+
border: 1px solid transparent;
|
|
204
|
+
border-radius: calc(5px + 6px * var(--_t));
|
|
205
|
+
font-size: calc(var(--ui-text-xs) + 1px * var(--_t));
|
|
206
|
+
}
|
|
207
|
+
:host ::ng-deep .ui-badge:not([class*='ui-badge-']) { background: var(--ui-info-soft); color: var(--ui-info); }
|
|
208
|
+
.bar { background: var(--ui-profile-menu-track, var(--ui-bg-muted)); }
|
|
209
|
+
.fill { background: var(--ui-profile-menu-fill, var(--ui-accent)); scale: 0 1; }
|
|
210
|
+
.fill[data-on] { scale: var(--_f) 1; }
|
|
211
|
+
@media (pointer: coarse) {
|
|
212
|
+
:host ::ng-deep :is([uiProfileMenuItem], .ui-pm-next) { min-block-size: var(--ui-control-h-touch-min); }
|
|
213
|
+
}
|
|
214
|
+
@media (forced-colors: active) {
|
|
215
|
+
:host { border: 1px solid; }
|
|
216
|
+
.bar { forced-color-adjust: none; border: 1px solid CanvasText; background: Canvas; }
|
|
217
|
+
.fill { background: CanvasText; }
|
|
218
|
+
}
|
|
219
|
+
`,
|
|
220
|
+
})
|
|
221
|
+
export class UiProfileMenu {
|
|
222
|
+
/** The signed-in person's name, on one line with an ellipsis when long. */
|
|
223
|
+
readonly name = input.required<string>();
|
|
224
|
+
/** Shown under the name, on one line with an ellipsis when long. */
|
|
225
|
+
readonly email = input<string>();
|
|
226
|
+
/** Profile-setup progress. `null` hides the block, as does a `total` of 0. */
|
|
227
|
+
readonly setup = input<ProfileSetup | null>(null);
|
|
228
|
+
/** Every visible and spoken string. Pass only the ones you change. */
|
|
229
|
+
readonly labels = input<Partial<ProfileMenuLabels>>({});
|
|
230
|
+
|
|
231
|
+
/** The next-step button under the bar. */
|
|
232
|
+
readonly continue = output<void>();
|
|
233
|
+
/** After an action is clicked or activated with Enter or Space (your own `(click)` runs first). Close an enclosing dropdown here. */
|
|
234
|
+
readonly itemSelect = output<HTMLElement>();
|
|
235
|
+
|
|
236
|
+
protected readonly l = computed(() => ({ ...LABELS, ...this.labels() }));
|
|
237
|
+
protected readonly items = contentChildren(UiProfileMenuItem, { descendants: true });
|
|
238
|
+
private readonly enabled = computed(() => this.items().filter((i) => !i.disabled() && !(i.el as HTMLButtonElement).disabled));
|
|
239
|
+
/** The item that was focused last. */
|
|
240
|
+
readonly active = signal<UiProfileMenuItem | null>(null);
|
|
241
|
+
/** The one item in the Tab order: the last one focused, or the first enabled one. */
|
|
242
|
+
readonly stop = computed(() => {
|
|
243
|
+
const a = this.active();
|
|
244
|
+
return a && this.enabled().includes(a) ? a : this.enabled()[0];
|
|
245
|
+
});
|
|
246
|
+
protected readonly progress = computed(() => {
|
|
247
|
+
const s = this.setup();
|
|
248
|
+
const total = Math.round(s?.total ?? 0);
|
|
249
|
+
if (!s || !(total > 0)) return null;
|
|
250
|
+
return { done: Math.min(total, Math.max(0, Math.round(s.done || 0))), total, next: s.next };
|
|
251
|
+
});
|
|
252
|
+
protected readonly seen = signal(false);
|
|
253
|
+
|
|
254
|
+
private readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
|
|
255
|
+
private readonly doc = inject(DOCUMENT);
|
|
256
|
+
private readonly bar = viewChild<ElementRef<HTMLElement>>('bar');
|
|
257
|
+
private typed = '';
|
|
258
|
+
private typedAt = 0;
|
|
259
|
+
|
|
260
|
+
constructor() {
|
|
261
|
+
afterRenderEffect((onCleanup) => {
|
|
262
|
+
const el = this.bar()?.nativeElement;
|
|
263
|
+
if (!el || this.seen()) return;
|
|
264
|
+
const IO = this.doc.defaultView?.IntersectionObserver;
|
|
265
|
+
if (!IO) {
|
|
266
|
+
this.seen.set(true);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
const io = new IO((entries) => {
|
|
270
|
+
if (entries.some((e) => e.isIntersecting)) {
|
|
271
|
+
io.disconnect();
|
|
272
|
+
this.seen.set(true);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
io.observe(el);
|
|
276
|
+
onCleanup(() => io.disconnect());
|
|
277
|
+
});
|
|
278
|
+
afterNextRender(() => {
|
|
279
|
+
if (!isDevMode()) return;
|
|
280
|
+
if (!this.name()?.trim()) console.warn('ui-profile-menu: give it the signed-in person\'s name.', this.host);
|
|
281
|
+
if (this.items().length && !this.l().menu.trim()) console.warn('ui-profile-menu: labels.menu is empty, so the menu has no name.', this.host);
|
|
282
|
+
for (const i of this.items()) {
|
|
283
|
+
if (!i.el.textContent?.trim() && !i.el.hasAttribute('aria-label')) console.warn('uiProfileMenuItem: an action with only an icon needs an aria-label.', i.el);
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** Moves focus to the first action, for a dropdown that has just opened. */
|
|
289
|
+
focusFirst() {
|
|
290
|
+
this.enabled()[0]?.el.focus();
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
protected key(e: KeyboardEvent) {
|
|
294
|
+
const all = this.enabled();
|
|
295
|
+
const cur = all.findIndex((i) => i.el === e.target);
|
|
296
|
+
if (cur < 0 || e.altKey || e.ctrlKey || e.metaKey) return;
|
|
297
|
+
const n = all.length;
|
|
298
|
+
const step: Record<string, number> = { ArrowDown: cur + 1, ArrowUp: cur - 1 + n, Home: 0, End: n - 1 };
|
|
299
|
+
let to = e.key in step ? step[e.key] % n : -1;
|
|
300
|
+
if (e.key === ' ' && all[cur].el.localName === 'a') {
|
|
301
|
+
e.preventDefault();
|
|
302
|
+
all[cur].el.click();
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
if (to < 0 && e.key.length === 1 && e.key !== ' ') {
|
|
306
|
+
const now = Date.now();
|
|
307
|
+
this.typed = (now - this.typedAt > 500 ? '' : this.typed) + e.key.toLowerCase();
|
|
308
|
+
this.typedAt = now;
|
|
309
|
+
const same = [...this.typed].every((c) => c === this.typed[0]);
|
|
310
|
+
const q = same ? this.typed[0] : this.typed;
|
|
311
|
+
const from = same || this.typed.length === 1 ? cur + 1 : cur;
|
|
312
|
+
for (let k = 0; k < n && to < 0; k++) {
|
|
313
|
+
const i = (from + k) % n;
|
|
314
|
+
if (all[i].el.textContent?.trim().toLowerCase().startsWith(q)) to = i;
|
|
315
|
+
}
|
|
316
|
+
if (to < 0) return;
|
|
317
|
+
}
|
|
318
|
+
if (to < 0) return;
|
|
319
|
+
e.preventDefault();
|
|
320
|
+
all[to].el.focus();
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
protected clicked(e: MouseEvent) {
|
|
324
|
+
const item = this.items().find((i) => i.el.contains(e.target as Node));
|
|
325
|
+
if (!item) return;
|
|
326
|
+
if (item.disabled()) {
|
|
327
|
+
e.preventDefault();
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
this.itemSelect.emit(item.el);
|
|
331
|
+
}
|
|
332
|
+
}
|