mn-angular-lib 2.0.33 → 2.0.35
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/fesm2022/mn-angular-lib-alert.mjs +515 -527
- package/fesm2022/mn-angular-lib-alert.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-bottom-sheet.mjs +264 -357
- package/fesm2022/mn-angular-lib-bottom-sheet.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-button.mjs +819 -382
- package/fesm2022/mn-angular-lib-button.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-calendar-core.mjs +240 -365
- package/fesm2022/mn-angular-lib-calendar-core.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-calendar.mjs +1691 -1545
- package/fesm2022/mn-angular-lib-calendar.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-collection.mjs +2367 -2796
- package/fesm2022/mn-angular-lib-collection.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-core.mjs +693 -1241
- package/fesm2022/mn-angular-lib-core.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-display.mjs +679 -712
- package/fesm2022/mn-angular-lib-display.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-forms.mjs +3671 -4647
- package/fesm2022/mn-angular-lib-forms.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-keyboard.mjs +221 -190
- package/fesm2022/mn-angular-lib-keyboard.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-modal-core.mjs +711 -896
- package/fesm2022/mn-angular-lib-modal-core.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-modal-ui.mjs +2089 -2035
- package/fesm2022/mn-angular-lib-modal-ui.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-modal.mjs +76 -121
- package/fesm2022/mn-angular-lib-modal.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-rich-text-editor.mjs +289 -277
- package/fesm2022/mn-angular-lib-rich-text-editor.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-segmented.mjs +189 -241
- package/fesm2022/mn-angular-lib-segmented.mjs.map +1 -1
- package/fesm2022/mn-angular-lib-tab.mjs +409 -642
- package/fesm2022/mn-angular-lib-tab.mjs.map +1 -1
- package/fesm2022/mn-angular-lib.mjs +16 -29
- package/package.json +1 -1
- package/types/mn-angular-lib-alert.d.ts +239 -241
- package/types/mn-angular-lib-bottom-sheet.d.ts +190 -150
- package/types/mn-angular-lib-button.d.ts +319 -317
- package/types/mn-angular-lib-calendar-core.d.ts +199 -209
- package/types/mn-angular-lib-calendar.d.ts +656 -511
- package/types/mn-angular-lib-collection.d.ts +1649 -1585
- package/types/mn-angular-lib-core.d.ts +524 -535
- package/types/mn-angular-lib-display.d.ts +946 -886
- package/types/mn-angular-lib-forms.d.ts +3012 -3013
- package/types/mn-angular-lib-keyboard.d.ts +125 -85
- package/types/mn-angular-lib-modal-core.d.ts +978 -994
- package/types/mn-angular-lib-modal-ui.d.ts +541 -493
- package/types/mn-angular-lib-modal.d.ts +24 -27
- package/types/mn-angular-lib-rich-text-editor.d.ts +131 -98
- package/types/mn-angular-lib-segmented.d.ts +354 -341
- package/types/mn-angular-lib-tab.d.ts +345 -336
- package/types/mn-angular-lib.d.ts +16 -16
- package/fesm2022/mn-angular-lib.mjs.map +0 -1
|
@@ -1,646 +1,413 @@
|
|
|
1
|
-
import * as i0 from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { LucideDynamicIcon } from
|
|
5
|
-
import * as lucide from
|
|
6
|
-
import {
|
|
7
|
-
import { MnCollectionState } from
|
|
8
|
-
import { CommonModule } from
|
|
9
|
-
import { MnBadge, MnSkeleton } from
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const CHEVRON_SCROLL_RATIO =
|
|
15
|
-
/** Fallback number of skeleton tabs when no items are known and no count is given. */
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { ChangeDetectorRef, Component, EventEmitter, Input, Output, ViewChild, inject, isSignal, signal } from "@angular/core";
|
|
3
|
+
import { ActivatedRoute, Router } from "@angular/router";
|
|
4
|
+
import { LucideDynamicIcon } from "@lucide/angular";
|
|
5
|
+
import * as lucide from "lucide";
|
|
6
|
+
import { MnTranslatePipe, lucideIcons } from "mn-angular-lib/core";
|
|
7
|
+
import { MnCollectionState } from "mn-angular-lib/collection";
|
|
8
|
+
import { CommonModule } from "@angular/common";
|
|
9
|
+
import { MnBadge, MnSkeleton } from "mn-angular-lib/button";
|
|
10
|
+
const ICONS = lucideIcons({
|
|
11
|
+
ChevronLeft: lucide.ChevronLeft,
|
|
12
|
+
ChevronRight: lucide.ChevronRight
|
|
13
|
+
});
|
|
14
|
+
const CHEVRON_SCROLL_RATIO = .75;
|
|
16
15
|
const DEFAULT_SKELETON_TAB_COUNT = 3;
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
/** Key used for a label that slugs to nothing (e.g. punctuation only). */
|
|
20
|
-
const FALLBACK_TAB_URL_KEY = 'tab';
|
|
21
|
-
/**
|
|
22
|
-
* Slugs a tab label into the value it takes in the URL: the last segment of a
|
|
23
|
-
* translation key, kebab-cased. `matches.hub.tab.entrants` → `entrants`,
|
|
24
|
-
* `members.tabMembers` → `tab-members`.
|
|
25
|
-
* @param label - The tab's label or translation key.
|
|
26
|
-
*/
|
|
16
|
+
const DEFAULT_TAB_URL_PARAM = "tab";
|
|
17
|
+
const FALLBACK_TAB_URL_KEY = "tab";
|
|
27
18
|
function tabUrlKey(label) {
|
|
28
|
-
|
|
29
|
-
const slug = segment
|
|
30
|
-
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
31
|
-
.replace(/[^a-zA-Z0-9]+/g, '-')
|
|
32
|
-
.replace(/^-+|-+$/g, '')
|
|
33
|
-
.toLowerCase();
|
|
34
|
-
return slug || FALLBACK_TAB_URL_KEY;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Tab component that renders a horizontal tab bar.
|
|
38
|
-
* Supports translation keys for labels via MnTranslatePipe.
|
|
39
|
-
*
|
|
40
|
-
* The active tab is mirrored in the URL query string by default, so a reload,
|
|
41
|
-
* a back button or a shared link lands on the same tab; see
|
|
42
|
-
* {@link MnTabDataSource.urlParam} to rename that parameter or switch it off.
|
|
43
|
-
*/
|
|
44
|
-
class MnTabComponent {
|
|
45
|
-
/**
|
|
46
|
-
* Router the active tab is written to. Optional: a tab bar used outside a
|
|
47
|
-
* routed application still works, it just has no URL to mirror into.
|
|
48
|
-
*/
|
|
49
|
-
router = inject(Router, { optional: true });
|
|
50
|
-
/** Route the tab value is read back from; absent for the same reason as {@link router}. */
|
|
51
|
-
route = inject(ActivatedRoute, { optional: true });
|
|
52
|
-
/**
|
|
53
|
-
* Marks the view whenever {@link currentActive} moves. The selection changes from three
|
|
54
|
-
* places Angular does not notice under OnPush: the query-parameter subscription, the
|
|
55
|
-
* {@link ngDoCheck} re-resolve, and a stale item being dropped — only a click arrives
|
|
56
|
-
* through a listener that dirties the view by itself.
|
|
57
|
-
*/
|
|
58
|
-
cdr = inject(ChangeDetectorRef);
|
|
59
|
-
/** Watches the URL so a deep link, a back button or an in-app link moves the tab bar. */
|
|
60
|
-
queryParamsSub;
|
|
61
|
-
/**
|
|
62
|
-
* URL keys of the current items, memoised on the items array so a slug is
|
|
63
|
-
* computed once per tab set rather than on every change-detection pass.
|
|
64
|
-
*/
|
|
65
|
-
urlKeyCache;
|
|
66
|
-
/** URL key of {@link currentActive}, so a rebuilt tab set can be recognised as the same tab. */
|
|
67
|
-
currentKey;
|
|
68
|
-
/**
|
|
69
|
-
* Key of a selection whose URL write has not landed yet. Navigation is
|
|
70
|
-
* asynchronous, so a consumer that rebuilds its tabs in response to the click
|
|
71
|
-
* can be resolved against a URL that still names the previous tab; until the
|
|
72
|
-
* write completes, this is the truth about what the user picked.
|
|
73
|
-
*/
|
|
74
|
-
pendingKey;
|
|
75
|
-
/** Set on destroy so a deferred restore can't announce a tab nobody is showing. */
|
|
76
|
-
destroyed = false;
|
|
77
|
-
/** The horizontally-scrolling wrapper the edge fade is painted onto. */
|
|
78
|
-
scrollContainer;
|
|
79
|
-
/** The tab row; queried for the active tab so the indicator can measure it. */
|
|
80
|
-
tabList;
|
|
81
|
-
/** The shared underline that slides to the active tab. */
|
|
82
|
-
indicator;
|
|
83
|
-
/** Pending indicator remeasure, cancelled on destroy so a post-destroy frame can't read a detached ref. */
|
|
84
|
-
indicatorFrame;
|
|
85
|
-
/**
|
|
86
|
-
* True while a click-initiated slide is animating. The active tab's
|
|
87
|
-
* `font-bold` widens the row, which fires {@link resizeObserver}; without
|
|
88
|
-
* this guard the observer's snap ({@link updateIndicator} with `animate:
|
|
89
|
-
* false`) would land the indicator at its target the same frame the slide
|
|
90
|
-
* starts, so the transition never paints. Set synchronously in
|
|
91
|
-
* {@link setActive} — before the frame runs — so the guard doesn't depend on
|
|
92
|
-
* rAF-vs-ResizeObserver callback ordering.
|
|
93
|
-
*/
|
|
94
|
-
sliding = false;
|
|
95
|
-
/** Clears {@link sliding} after the slide finishes; re-armed per click, cancelled on destroy. */
|
|
96
|
-
slidingTimer;
|
|
97
|
-
/** Slide duration in ms; matches the indicator's `duration-300` transition. */
|
|
98
|
-
static SLIDE_MS = 300;
|
|
99
|
-
/** How far the fade reaches in from each overflowing edge. */
|
|
100
|
-
static FADE = '2rem';
|
|
101
|
-
/** Data source containing tab items and default active index. */
|
|
102
|
-
dataSource;
|
|
103
|
-
/**
|
|
104
|
-
* Whether to enable horizontal scrolling when items overflow.
|
|
105
|
-
* When true, tabs scroll horizontally instead of overflowing their container.
|
|
106
|
-
*
|
|
107
|
-
* Defaults to `true`: the tab bar never wraps (`flex-nowrap`), so without
|
|
108
|
-
* scrolling an overflowing bar would clip its last tabs or push the page width
|
|
109
|
-
* on narrow screens. When the tabs already fit, `overflow-x-auto` is a no-op,
|
|
110
|
-
* so this default only ever changes behaviour for the overflow case it fixes.
|
|
111
|
-
*/
|
|
112
|
-
scrollable = true;
|
|
113
|
-
/**
|
|
114
|
-
* Whether tabs should stretch to fill the available width.
|
|
115
|
-
* Defaults to false, so tabs only take as much space as their content.
|
|
116
|
-
*/
|
|
117
|
-
justified = false;
|
|
118
|
-
/** Icons rendered by the template. */
|
|
119
|
-
icons = ICONS;
|
|
120
|
-
/**
|
|
121
|
-
* Whether tabs are scrolled out of view past the start edge, which shows the start chevron.
|
|
122
|
-
* A signal, so a write from the scroll handler or the resize observer marks the view by itself.
|
|
123
|
-
*/
|
|
124
|
-
canScrollStart = signal(false, /* @ts-ignore */
|
|
125
|
-
...(ngDevMode ? [{ debugName: "canScrollStart" }] : /* istanbul ignore next */ []));
|
|
126
|
-
/** Whether tabs are hidden past the end edge, which shows the end chevron. */
|
|
127
|
-
canScrollEnd = signal(false, /* @ts-ignore */
|
|
128
|
-
...(ngDevMode ? [{ debugName: "canScrollEnd" }] : /* istanbul ignore next */ []));
|
|
129
|
-
/** Emits the newly activated tab item whenever the active tab changes. */
|
|
130
|
-
activeChange = new EventEmitter();
|
|
131
|
-
/** The currently active tab item. */
|
|
132
|
-
currentActive;
|
|
133
|
-
/** Watches the wrapper and the tab row so the fade re-evaluates on width or content changes. */
|
|
134
|
-
resizeObserver;
|
|
135
|
-
/**
|
|
136
|
-
* Whether the tab bar is loading and should render skeleton tabs, from
|
|
137
|
-
* {@link MnTabDataSource.state}.
|
|
138
|
-
*/
|
|
139
|
-
get isLoadingState() {
|
|
140
|
-
return this.dataSource.state === MnCollectionState.LOADING;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Index array sizing the loading skeleton: `skeletonCount` when provided,
|
|
144
|
-
* otherwise the number of known items, falling back to a default when none.
|
|
145
|
-
*/
|
|
146
|
-
get skeletonTabs() {
|
|
147
|
-
const count = this.dataSource.skeletonCount ?? (this.dataSource.items.length || DEFAULT_SKELETON_TAB_COUNT);
|
|
148
|
-
return Array.from({ length: count }, (_, index) => index);
|
|
149
|
-
}
|
|
150
|
-
constructor() {
|
|
151
|
-
// The URL is a second source of truth for the selection: a deep link, an
|
|
152
|
-
// in-app link into another tab of the page already on screen, or the back
|
|
153
|
-
// button all change it without a click landing on this component.
|
|
154
|
-
this.queryParamsSub = this.route?.queryParamMap.subscribe((params) => {
|
|
155
|
-
const param = this.urlParam();
|
|
156
|
-
if (param)
|
|
157
|
-
this.activateUrlKey(params.get(param));
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Re-resolves the active tab on every change-detection pass.
|
|
162
|
-
*
|
|
163
|
-
* The data source is often populated or rebuilt asynchronously (tabs that
|
|
164
|
-
* depend on fetched data or permissions). Resolving the active tab only once
|
|
165
|
-
* at init would leave {@link currentActive} pointing at a stale item — the
|
|
166
|
-
* tab bar would then highlight nothing and swallow the first click — so the
|
|
167
|
-
* selection is kept in sync with whatever the data source currently holds.
|
|
168
|
-
*/
|
|
169
|
-
ngDoCheck() {
|
|
170
|
-
this.syncActiveTab();
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Starts watching the scroll wrapper so the edge fade stays honest. A scroll
|
|
174
|
-
* moves the fade to whichever side now hides tabs; a resize (viewport change)
|
|
175
|
-
* or a change to the tab row's width (tabs added, relabelled, skeleton →
|
|
176
|
-
* loaded) re-checks whether either edge overflows at all.
|
|
177
|
-
*/
|
|
178
|
-
ngAfterViewInit() {
|
|
179
|
-
const el = this.scrollContainer?.nativeElement;
|
|
180
|
-
if (!el)
|
|
181
|
-
return;
|
|
182
|
-
this.resizeObserver = new ResizeObserver(() => {
|
|
183
|
-
this.updateEdgeFades();
|
|
184
|
-
// Tabs may have reflowed (viewport change, justified widths); snap the
|
|
185
|
-
// indicator to the new geometry — animating a resize tick reads as jank.
|
|
186
|
-
// But skip the snap mid-slide: a click's own `font-bold` resizes the row
|
|
187
|
-
// and fires this observer, and snapping there kills the slide it triggered.
|
|
188
|
-
if (!this.sliding)
|
|
189
|
-
this.updateIndicator(false);
|
|
190
|
-
});
|
|
191
|
-
this.resizeObserver.observe(el);
|
|
192
|
-
if (el.firstElementChild)
|
|
193
|
-
this.resizeObserver.observe(el.firstElementChild);
|
|
194
|
-
this.updateEdgeFades();
|
|
195
|
-
// Place the indicator on the default tab without a slide-in from zero.
|
|
196
|
-
this.updateIndicator(false);
|
|
197
|
-
}
|
|
198
|
-
/** Wrapper geometry (`scrollWidth:clientWidth`) at the last fade evaluation. */
|
|
199
|
-
lastFadeGeometry = '';
|
|
200
|
-
/**
|
|
201
|
-
* Re-evaluates the edge fade when the wrapper's scrollable extent changes without its box
|
|
202
|
-
* changing. {@link resizeObserver} only sees border-box changes, and the tab row is a
|
|
203
|
-
* block-level flex container that keeps its parent's width while its tabs overflow inside it,
|
|
204
|
-
* so tabs that arrive after init (permission-gated tabs, badge counts, skeleton → loaded) grow
|
|
205
|
-
* `scrollWidth` without firing it; until a resize or scroll the fade stayed off. Two property
|
|
206
|
-
* reads per pass; the repaint only runs when they moved.
|
|
207
|
-
*/
|
|
208
|
-
ngAfterViewChecked() {
|
|
209
|
-
const el = this.scrollContainer?.nativeElement;
|
|
210
|
-
if (!el)
|
|
211
|
-
return;
|
|
212
|
-
const geometry = `${el.scrollWidth}:${el.clientWidth}`;
|
|
213
|
-
if (geometry === this.lastFadeGeometry)
|
|
214
|
-
return;
|
|
215
|
-
this.lastFadeGeometry = geometry;
|
|
216
|
-
this.updateEdgeFades();
|
|
217
|
-
}
|
|
218
|
-
ngOnDestroy() {
|
|
219
|
-
this.destroyed = true;
|
|
220
|
-
this.queryParamsSub?.unsubscribe();
|
|
221
|
-
this.resizeObserver?.disconnect();
|
|
222
|
-
if (this.indicatorFrame !== undefined)
|
|
223
|
-
cancelAnimationFrame(this.indicatorFrame);
|
|
224
|
-
if (this.slidingTimer !== undefined)
|
|
225
|
-
clearTimeout(this.slidingTimer);
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Paints a fade over whichever edge has tabs scrolled out of view — a soft
|
|
229
|
-
* dissolve that reads as "more this way", the affordance a hidden scrollbar
|
|
230
|
-
* otherwise costs us. Uses a mask (content → transparent) rather than a
|
|
231
|
-
* background-coloured overlay, so it needs no knowledge of the theme.
|
|
232
|
-
*
|
|
233
|
-
* The fade alone only reads as "more" when it dissolves a tab cut off
|
|
234
|
-
* mid-label. When a tab boundary lands exactly on the edge it merely softens
|
|
235
|
-
* a complete label and the hidden tabs go unnoticed, so the same overflow
|
|
236
|
-
* also shows a chevron in the faded strip ({@link canScrollStart},
|
|
237
|
-
* {@link canScrollEnd}).
|
|
238
|
-
*/
|
|
239
|
-
updateEdgeFades() {
|
|
240
|
-
const el = this.scrollContainer?.nativeElement;
|
|
241
|
-
if (!el)
|
|
242
|
-
return;
|
|
243
|
-
const fadeStart = el.scrollLeft > 1;
|
|
244
|
-
const fadeEnd = el.scrollLeft + el.clientWidth < el.scrollWidth - 1;
|
|
245
|
-
this.canScrollStart.set(this.scrollable && fadeStart);
|
|
246
|
-
this.canScrollEnd.set(this.scrollable && fadeEnd);
|
|
247
|
-
const f = MnTabComponent.FADE;
|
|
248
|
-
let mask = '';
|
|
249
|
-
if (this.scrollable && fadeStart && fadeEnd) {
|
|
250
|
-
mask = `linear-gradient(to right, transparent 0, #000 ${f}, #000 calc(100% - ${f}), transparent 100%)`;
|
|
251
|
-
}
|
|
252
|
-
else if (this.scrollable && fadeStart) {
|
|
253
|
-
mask = `linear-gradient(to right, transparent 0, #000 ${f}, #000 100%)`;
|
|
254
|
-
}
|
|
255
|
-
else if (this.scrollable && fadeEnd) {
|
|
256
|
-
mask = `linear-gradient(to right, #000 0, #000 calc(100% - ${f}), transparent 100%)`;
|
|
257
|
-
}
|
|
258
|
-
el.style.maskImage = mask;
|
|
259
|
-
el.style.setProperty('-webkit-mask-image', mask);
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Scrolls the bar by most of its visible width towards one edge, from a chevron press. The
|
|
263
|
-
* scroll event that follows moves the fade and hides the chevron whose edge has been reached.
|
|
264
|
-
* Jumps instead of gliding for a user who asked for reduced motion.
|
|
265
|
-
* @param direction - -1 towards the start, 1 towards the end.
|
|
266
|
-
*/
|
|
267
|
-
scrollTabs(direction) {
|
|
268
|
-
const el = this.scrollContainer?.nativeElement;
|
|
269
|
-
if (!el)
|
|
270
|
-
return;
|
|
271
|
-
const reduceMotion = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
|
|
272
|
-
el.scrollBy({
|
|
273
|
-
left: direction * el.clientWidth * CHEVRON_SCROLL_RATIO,
|
|
274
|
-
behavior: reduceMotion ? 'auto' : 'smooth',
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Sets the given tab item as active, invoking deactivate/activate callbacks,
|
|
279
|
-
* and records the selection in the URL so it survives a reload or a share.
|
|
280
|
-
* @param item - The tab item to activate.
|
|
281
|
-
*/
|
|
282
|
-
setActive(item) {
|
|
283
|
-
if (this.currentActive === item) {
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
this.activate(item);
|
|
287
|
-
this.writeUrl(item);
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Whether a tab is the bar's single Tab stop: the active tab, or the first tab while none is
|
|
291
|
-
* active yet. Every other tab is reached with the arrow keys, so Tab leaves the bar in one press.
|
|
292
|
-
* @param item - The tab to check.
|
|
293
|
-
* @returns True for the one tab that keeps `tabindex="0"`.
|
|
294
|
-
*/
|
|
295
|
-
isTabStop(item) {
|
|
296
|
-
return this.currentActive ? this.currentActive === item : this.dataSource?.items[0] === item;
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* Keyboard handling on a tab. Left and Right move to the previous or next tab and wrap at the
|
|
300
|
-
* ends, Home and End jump to the first and last; the tab moved to is activated at once
|
|
301
|
-
* (automatic activation) and receives focus. Enter and Space activate the focused tab, handled
|
|
302
|
-
* on keydown so Space does not scroll the page first. Other keys are left alone.
|
|
303
|
-
* @param event - The keydown on a tab.
|
|
304
|
-
* @param item - The tab the key was pressed on.
|
|
305
|
-
*/
|
|
306
|
-
onTabKeydown(event, item) {
|
|
307
|
-
const items = this.dataSource?.items ?? [];
|
|
308
|
-
const index = items.indexOf(item);
|
|
309
|
-
if (index < 0)
|
|
310
|
-
return;
|
|
311
|
-
let target;
|
|
312
|
-
switch (event.key) {
|
|
313
|
-
case 'ArrowRight':
|
|
314
|
-
target = (index + 1) % items.length;
|
|
315
|
-
break;
|
|
316
|
-
case 'ArrowLeft':
|
|
317
|
-
target = (index - 1 + items.length) % items.length;
|
|
318
|
-
break;
|
|
319
|
-
case 'Home':
|
|
320
|
-
target = 0;
|
|
321
|
-
break;
|
|
322
|
-
case 'End':
|
|
323
|
-
target = items.length - 1;
|
|
324
|
-
break;
|
|
325
|
-
case 'Enter':
|
|
326
|
-
case ' ':
|
|
327
|
-
event.preventDefault();
|
|
328
|
-
this.setActive(item);
|
|
329
|
-
return;
|
|
330
|
-
default:
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
event.preventDefault();
|
|
334
|
-
this.setActive(items[target]);
|
|
335
|
-
this.focusTab(target);
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Moves focus to the tab at `index` and scrolls it into view inside a scrollable bar. Focusing
|
|
339
|
-
* works before change detection has moved `tabindex="0"` onto it, because a script may focus an
|
|
340
|
-
* element with `tabindex="-1"`.
|
|
341
|
-
* @param index - Position of the tab in the data source's items.
|
|
342
|
-
*/
|
|
343
|
-
focusTab(index) {
|
|
344
|
-
const tabs = this.tabList?.nativeElement.querySelectorAll('[role="tab"]');
|
|
345
|
-
const tab = tabs?.[index];
|
|
346
|
-
if (!tab)
|
|
347
|
-
return;
|
|
348
|
-
tab.focus();
|
|
349
|
-
tab.scrollIntoView?.({ block: 'nearest', inline: 'nearest' });
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
* Moves the selection to `item` and tells the consumer about it: the
|
|
353
|
-
* deactivate/activate/emit sequence a click produces, shared by the click
|
|
354
|
-
* path and the URL-driven ones (deep link, back button), which owe the
|
|
355
|
-
* consumer the same notifications.
|
|
356
|
-
* @param item - The tab item to activate.
|
|
357
|
-
*/
|
|
358
|
-
activate(item) {
|
|
359
|
-
this.currentActive?.onDeactivate?.();
|
|
360
|
-
item.onClick?.();
|
|
361
|
-
this.select(item);
|
|
362
|
-
this.activeChange.emit(item);
|
|
363
|
-
// Slide the underline to the new tab. Measure on the next frame, after
|
|
364
|
-
// change detection has applied the active tab's `font-bold` (which widens
|
|
365
|
-
// it) so the indicator lands on the final, bolded geometry. Guard the slide
|
|
366
|
-
// against the resize snap the same `font-bold` triggers (see {@link sliding}).
|
|
367
|
-
this.beginSlide();
|
|
368
|
-
this.scheduleIndicator(true);
|
|
369
|
-
}
|
|
370
|
-
/**
|
|
371
|
-
* Marks a click-driven slide as in progress and schedules the guard to lift
|
|
372
|
-
* once the transition has finished. A timeout (not `transitionend`) so the
|
|
373
|
-
* flag still clears under `motion-reduce`, where no transition event fires.
|
|
374
|
-
*/
|
|
375
|
-
beginSlide() {
|
|
376
|
-
this.sliding = true;
|
|
377
|
-
if (this.slidingTimer !== undefined)
|
|
378
|
-
clearTimeout(this.slidingTimer);
|
|
379
|
-
this.slidingTimer = setTimeout(() => {
|
|
380
|
-
this.slidingTimer = undefined;
|
|
381
|
-
this.sliding = false;
|
|
382
|
-
}, MnTabComponent.SLIDE_MS);
|
|
383
|
-
}
|
|
384
|
-
/**
|
|
385
|
-
* Moves the shared underline to the active tab. When `animate` is false the
|
|
386
|
-
* move is snapped (no slide) by disabling the transition for one reflow —
|
|
387
|
-
* used on init, async selection and resize, where a slide would read as jank.
|
|
388
|
-
* @param animate - Whether the move should slide (true) or snap (false).
|
|
389
|
-
*/
|
|
390
|
-
updateIndicator(animate) {
|
|
391
|
-
const bar = this.indicator?.nativeElement;
|
|
392
|
-
const list = this.tabList?.nativeElement;
|
|
393
|
-
if (!bar || !list)
|
|
394
|
-
return;
|
|
395
|
-
const active = list.querySelector('[role="tab"][aria-selected="true"]');
|
|
396
|
-
if (!active) {
|
|
397
|
-
bar.style.opacity = '0';
|
|
398
|
-
return;
|
|
399
|
-
}
|
|
400
|
-
if (!animate)
|
|
401
|
-
bar.style.transition = 'none';
|
|
402
|
-
bar.style.opacity = '1';
|
|
403
|
-
bar.style.width = `${active.offsetWidth}px`;
|
|
404
|
-
bar.style.transform = `translateX(${active.offsetLeft}px)`;
|
|
405
|
-
if (!animate) {
|
|
406
|
-
// Force a reflow so the snapped values apply before the transition is
|
|
407
|
-
// restored, then hand animation back to the CSS class.
|
|
408
|
-
void bar.offsetWidth;
|
|
409
|
-
bar.style.transition = '';
|
|
410
|
-
}
|
|
411
|
-
this.revealActiveTab(active);
|
|
412
|
-
}
|
|
413
|
-
/**
|
|
414
|
-
* Scrolls the strip so the active tab is fully in view, clear of the 2rem edge the fade and
|
|
415
|
-
* the scroll chevron cover. Only keyboard focus used to scroll, so a deep link to a tab past
|
|
416
|
-
* the fold ("?tab=results" on a phone) opened with the strip at its start and the selected
|
|
417
|
-
* tab out of sight. Sets scrollLeft on the strip itself rather than calling scrollIntoView,
|
|
418
|
-
* which would scroll the page too.
|
|
419
|
-
* @param active - The selected tab element.
|
|
420
|
-
*/
|
|
421
|
-
revealActiveTab(active) {
|
|
422
|
-
const box = this.scrollContainer?.nativeElement;
|
|
423
|
-
if (!this.scrollable || !box || box.scrollWidth <= box.clientWidth)
|
|
424
|
-
return;
|
|
425
|
-
const edge = 32;
|
|
426
|
-
const boxRect = box.getBoundingClientRect();
|
|
427
|
-
const tabRect = active.getBoundingClientRect();
|
|
428
|
-
if (tabRect.left < boxRect.left + edge) {
|
|
429
|
-
box.scrollLeft -= boxRect.left + edge - tabRect.left;
|
|
430
|
-
}
|
|
431
|
-
else if (tabRect.right > boxRect.right - edge) {
|
|
432
|
-
box.scrollLeft += tabRect.right - (boxRect.right - edge);
|
|
433
|
-
}
|
|
434
|
-
this.updateEdgeFades();
|
|
435
|
-
}
|
|
436
|
-
/**
|
|
437
|
-
* Remeasures the indicator on the next animation frame, so the read happens
|
|
438
|
-
* after layout reflects the latest active-tab classes. Coalesces bursts and
|
|
439
|
-
* is cancellable on destroy.
|
|
440
|
-
* @param animate - Whether the resulting move should slide.
|
|
441
|
-
*/
|
|
442
|
-
scheduleIndicator(animate) {
|
|
443
|
-
if (this.indicatorFrame !== undefined)
|
|
444
|
-
cancelAnimationFrame(this.indicatorFrame);
|
|
445
|
-
this.indicatorFrame = requestAnimationFrame(() => {
|
|
446
|
-
this.indicatorFrame = undefined;
|
|
447
|
-
this.updateIndicator(animate);
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
/**
|
|
451
|
-
* Returns the resolved badge value for a tab item, supporting both plain numbers and Signal<number>.
|
|
452
|
-
* @param item - The tab item whose badge to resolve.
|
|
453
|
-
*/
|
|
454
|
-
getBadge(item) {
|
|
455
|
-
if (isSignal(item.badge))
|
|
456
|
-
return item.badge();
|
|
457
|
-
return item.badge;
|
|
458
|
-
}
|
|
459
|
-
/**
|
|
460
|
-
* Ensures {@link currentActive} references a tab that still exists in the data
|
|
461
|
-
* source, preferring the tab named in the URL and falling back to the
|
|
462
|
-
* configured default tab when the current selection is missing or stale
|
|
463
|
-
* (e.g. after the items array is replaced).
|
|
464
|
-
*/
|
|
465
|
-
syncActiveTab() {
|
|
466
|
-
const items = this.dataSource?.items;
|
|
467
|
-
if (!items || items.length === 0) {
|
|
468
|
-
if (this.currentActive !== undefined) {
|
|
469
|
-
this.currentActive = undefined;
|
|
470
|
-
this.currentKey = undefined;
|
|
471
|
-
this.cdr.markForCheck();
|
|
472
|
-
this.scheduleIndicator(false);
|
|
473
|
-
}
|
|
474
|
-
return;
|
|
475
|
-
}
|
|
476
|
-
if (this.currentActive && items.includes(this.currentActive)) {
|
|
477
|
-
return;
|
|
478
|
-
}
|
|
479
|
-
const defaultIndex = this.dataSource.defaultActive;
|
|
480
|
-
const index = defaultIndex >= 0 && defaultIndex < items.length ? defaultIndex : 0;
|
|
481
|
-
const fallback = items[index];
|
|
482
|
-
const restored = this.itemFromUrl(items);
|
|
483
|
-
const previousKey = this.currentKey;
|
|
484
|
-
this.select(restored ?? fallback);
|
|
485
|
-
// Selection resolved from data (not a user click): snap, don't slide.
|
|
486
|
-
this.scheduleIndicator(false);
|
|
487
|
-
if (restored && restored !== fallback && this.currentKey !== previousKey) {
|
|
488
|
-
// The URL asks for a tab the consumer has not rendered, so this selection
|
|
489
|
-
// has to be announced like a click's would be — but only the first time,
|
|
490
|
-
// or a consumer that rebuilds its items array would re-run the tab's
|
|
491
|
-
// callbacks on every rebuild. Deferred out of the change-detection pass
|
|
492
|
-
// that resolved it: the consumer will flip its own state in response, and
|
|
493
|
-
// doing that mid-pass writes to bindings that have already been checked.
|
|
494
|
-
queueMicrotask(() => this.announceRestored(restored));
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
/**
|
|
498
|
-
* Records `item` as the selection, remembering its URL key so the same tab is
|
|
499
|
-
* recognised after the consumer rebuilds the items array.
|
|
500
|
-
* @param item - The newly selected tab.
|
|
501
|
-
*/
|
|
502
|
-
select(item) {
|
|
503
|
-
const items = this.dataSource.items;
|
|
504
|
-
this.currentActive = item;
|
|
505
|
-
this.currentKey = this.urlKeys(items)[items.indexOf(item)];
|
|
506
|
-
this.cdr.markForCheck();
|
|
507
|
-
}
|
|
508
|
-
/**
|
|
509
|
-
* Runs the restored tab's callbacks a change-detection pass later, unless the
|
|
510
|
-
* selection moved on in the meantime (a click, or another tab set arriving).
|
|
511
|
-
* @param item - The tab restored from the URL.
|
|
512
|
-
*/
|
|
513
|
-
announceRestored(item) {
|
|
514
|
-
if (this.destroyed || this.currentActive !== item)
|
|
515
|
-
return;
|
|
516
|
-
item.onClick?.();
|
|
517
|
-
this.activeChange.emit(item);
|
|
518
|
-
}
|
|
519
|
-
/**
|
|
520
|
-
* Activates the tab a URL value names, when it is not the tab already on
|
|
521
|
-
* screen. Values naming no known tab are ignored: another tab bar on the page
|
|
522
|
-
* may own that parameter, and a stale link should leave the default standing.
|
|
523
|
-
* @param key - The value read from the query parameter, if any.
|
|
524
|
-
*/
|
|
525
|
-
activateUrlKey(key) {
|
|
526
|
-
const items = this.dataSource?.items;
|
|
527
|
-
if (!key || !items?.length)
|
|
528
|
-
return;
|
|
529
|
-
const item = items[this.urlKeys(items).indexOf(key)];
|
|
530
|
-
if (!item || item === this.currentActive)
|
|
531
|
-
return;
|
|
532
|
-
this.activate(item);
|
|
533
|
-
}
|
|
534
|
-
/**
|
|
535
|
-
* The query parameter this tab bar mirrors into, or undefined when there is
|
|
536
|
-
* nothing to mirror into (no router) or the consumer switched it off.
|
|
537
|
-
*/
|
|
538
|
-
urlParam() {
|
|
539
|
-
if (!this.router || !this.route)
|
|
540
|
-
return undefined;
|
|
541
|
-
const param = this.dataSource?.urlParam ?? DEFAULT_TAB_URL_PARAM;
|
|
542
|
-
return param === false || param === '' ? undefined : param;
|
|
543
|
-
}
|
|
544
|
-
/**
|
|
545
|
-
* The tab the current URL asks for, if it names one of `items`.
|
|
546
|
-
* @param items - The tab set to resolve the URL value against.
|
|
547
|
-
*/
|
|
548
|
-
itemFromUrl(items) {
|
|
549
|
-
const param = this.urlParam();
|
|
550
|
-
if (!param)
|
|
551
|
-
return undefined;
|
|
552
|
-
const key = this.pendingKey ?? this.route?.snapshot.queryParamMap.get(param);
|
|
553
|
-
if (!key)
|
|
554
|
-
return undefined;
|
|
555
|
-
const index = this.urlKeys(items).indexOf(key);
|
|
556
|
-
return index === -1 ? undefined : items[index];
|
|
557
|
-
}
|
|
558
|
-
/**
|
|
559
|
-
* Records the active tab in the query string, replacing the current history
|
|
560
|
-
* entry: switching tabs is not a navigation to walk back through, and back
|
|
561
|
-
* should leave the page rather than retrace its tabs.
|
|
562
|
-
* @param item - The tab that just became active.
|
|
563
|
-
*/
|
|
564
|
-
writeUrl(item) {
|
|
565
|
-
const param = this.urlParam();
|
|
566
|
-
if (!param || !this.router)
|
|
567
|
-
return;
|
|
568
|
-
const items = this.dataSource.items;
|
|
569
|
-
const key = this.urlKeys(items)[items.indexOf(item)];
|
|
570
|
-
if (!key)
|
|
571
|
-
return;
|
|
572
|
-
this.pendingKey = key;
|
|
573
|
-
// No path commands and no `relativeTo`, so only the query string changes.
|
|
574
|
-
// That holds wherever the tab bar sits, including a modal body, which has
|
|
575
|
-
// no route of its own to be relative to.
|
|
576
|
-
void this.router
|
|
577
|
-
.navigate([], {
|
|
578
|
-
queryParams: { [param]: key },
|
|
579
|
-
queryParamsHandling: 'merge',
|
|
580
|
-
replaceUrl: true,
|
|
581
|
-
})
|
|
582
|
-
.catch(() => undefined)
|
|
583
|
-
.then(() => {
|
|
584
|
-
// Only clear our own write; a later click already owns the pending key.
|
|
585
|
-
if (this.pendingKey === key)
|
|
586
|
-
this.pendingKey = undefined;
|
|
587
|
-
});
|
|
588
|
-
}
|
|
589
|
-
/**
|
|
590
|
-
* The URL key of every tab, in item order: the item's `id`, else a slug of
|
|
591
|
-
* its label. Repeats are numbered so each tab still round-trips through the
|
|
592
|
-
* URL; give such tabs an explicit `id` to choose the value yourself.
|
|
593
|
-
* @param items - The tab set to key.
|
|
594
|
-
*/
|
|
595
|
-
urlKeys(items) {
|
|
596
|
-
if (this.urlKeyCache?.items === items)
|
|
597
|
-
return this.urlKeyCache.keys;
|
|
598
|
-
const used = new Map();
|
|
599
|
-
const keys = items.map((item) => {
|
|
600
|
-
const base = item.id ?? tabUrlKey(item.label);
|
|
601
|
-
const taken = used.get(base) ?? 0;
|
|
602
|
-
used.set(base, taken + 1);
|
|
603
|
-
return taken === 0 ? base : `${base}-${taken + 1}`;
|
|
604
|
-
});
|
|
605
|
-
this.urlKeyCache = { items, keys };
|
|
606
|
-
return keys;
|
|
607
|
-
}
|
|
608
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.7", ngImport: i0, type: MnTabComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
609
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.7", type: MnTabComponent, isStandalone: true, selector: "mn-tab", inputs: { dataSource: "dataSource", scrollable: "scrollable", justified: "justified" }, outputs: { activeChange: "activeChange" }, viewQueries: [{ propertyName: "scrollContainer", first: true, predicate: ["scrollContainer"], descendants: true }, { propertyName: "tabList", first: true, predicate: ["tabList"], descendants: true }, { propertyName: "indicator", first: true, predicate: ["indicator"], descendants: true }], ngImport: i0, template: "<div class=\"relative\">\n <!--\n Scroll chevrons, one per edge that hides tabs. They sit in the 2rem strip the edge fade\n dissolves, so they cover nothing still legible. aria-hidden and out of the Tab order: the\n arrow keys already move between tabs (and scroll them into view), and a screen reader reads\n every tab whether scrolled into view or not. mousedown is cancelled so a press does not\n take focus away from the active tab.\n -->\n @if (canScrollStart()) {\n <button\n (click)=\"scrollTabs(-1)\"\n (mousedown)=\"$event.preventDefault()\"\n aria-hidden=\"true\"\n class=\"absolute inset-y-0 left-0 z-10 flex w-8 cursor-pointer items-center justify-start text-base-content hover:text-primary\"\n data-mn-tab-scroll=\"start\"\n tabindex=\"-1\"\n type=\"button\"\n >\n <svg [size]=\"18\" [lucideIcon]=\"icons.ChevronLeft\"></svg>\n </button>\n }\n @if (canScrollEnd()) {\n <button\n (click)=\"scrollTabs(1)\"\n (mousedown)=\"$event.preventDefault()\"\n aria-hidden=\"true\"\n class=\"absolute inset-y-0 right-0 z-10 flex w-8 cursor-pointer items-center justify-end text-base-content hover:text-primary\"\n data-mn-tab-scroll=\"end\"\n tabindex=\"-1\"\n type=\"button\"\n >\n <svg [size]=\"18\" [lucideIcon]=\"icons.ChevronRight\"></svg>\n </button>\n }\n <div\n #scrollContainer\n (scroll)=\"updateEdgeFades()\"\n class=\"flex justify-start scrollbar-hide\"\n [class.overflow-x-auto]=\"scrollable\"\n [class.overflow-y-hidden]=\"scrollable\"\n >\n <div\n #tabList\n role=\"tablist\"\n class=\"tabs relative flex flex-nowrap -mb-[1px] border-b border-base-300\"\n [class.w-full]=\"justified\"\n >\n <!--\n Shared sliding indicator: a single underline that travels to the active\n tab, rather than each tab flipping its own border on/off (which snaps).\n Pinned to left-0/top-auto so offsetLeft maps 1:1 regardless of the\n flex justify-content or the justified full-width layout; position and\n width are measured and set from TS. Sits on the same baseline as the\n hover ::after so hover \u2192 select reads as one continuous underline.\n -->\n <div\n #indicator\n aria-hidden=\"true\"\n class=\"pointer-events-none absolute left-0 top-auto bottom-0 h-[2px] w-0 bg-primary opacity-0 transition-[transform,width] duration-300 ease-out motion-reduce:transition-none\"\n ></div>\n @if (isLoadingState) {\n @for (i of skeletonTabs; track i) {\n <div\n [class.flex-1]=\"justified\"\n class=\"tab px-4 py-2 border-b-2 border-transparent flex items-center justify-center\"\n >\n <mn-skeleton [data]=\"{ shape: 'rectangle', width: '4.5rem', height: '1rem' }\"></mn-skeleton>\n </div>\n }\n } @else {\n @for (item of dataSource.items; track item.label) {\n <!-- One Tab stop per bar (the active tab); the arrow keys, Home and End move between\n tabs and activate them, the WAI-ARIA tabs pattern. Every tab used to be its own\n Tab stop with no arrow keys, so crossing an eight-tab bar took eight presses. -->\n <div\n (click)=\"setActive(item)\"\n (keydown)=\"onTabKeydown($event, item)\"\n [attr.aria-selected]=\"currentActive === item\"\n [attr.tabindex]=\"isTabStop(item) ? 0 : -1\"\n [class.hover:after:scale-x-100]=\"currentActive !== item\"\n [class.flex-1]=\"justified\"\n [class.font-bold]=\"currentActive === item\"\n [class.text-base-content]=\"currentActive !== item\"\n [class.text-primary]=\"currentActive === item\"\n class=\"tab relative px-4 py-2 border-b-2 border-transparent cursor-pointer select-none transition-colors whitespace-nowrap text-center flex items-center gap-2 after:content-[''] after:absolute after:inset-x-0 after:-bottom-[2px] after:h-[2px] after:bg-primary/60 after:origin-center after:scale-x-0 after:transition-transform after:duration-300 after:ease-out\"\n role=\"tab\"\n >\n {{ item.label | mnTranslate }}\n @let badge = getBadge(item);\n @if (badge && badge > 0) {\n <span [data]=\"{ size: 'sm', color: 'accent', variant: 'fill' }\" mnBadge>{{ badge }}</span>\n }\n </div>\n }\n }\n </div>\n </div>\n</div>\n", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "component", type: MnBadge, selector: "span[mnBadge]", inputs: ["data"] }, { kind: "component", type: MnSkeleton, selector: "mn-skeleton", inputs: ["data"] }, { kind: "component", type: LucideDynamicIcon, selector: "svg[lucideIcon]", inputs: ["lucideIcon"] }, { kind: "pipe", type: MnTranslatePipe, name: "mnTranslate" }] });
|
|
19
|
+
return (label.split(".").pop() ?? label).replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/[^a-zA-Z0-9]+/g, "-").replace(/^-+|-+$/g, "").toLowerCase() || FALLBACK_TAB_URL_KEY;
|
|
610
20
|
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
21
|
+
var MnTabComponent = class MnTabComponent {
|
|
22
|
+
router = inject(Router, { optional: true });
|
|
23
|
+
route = inject(ActivatedRoute, { optional: true });
|
|
24
|
+
cdr = inject(ChangeDetectorRef);
|
|
25
|
+
queryParamsSub;
|
|
26
|
+
urlKeyCache;
|
|
27
|
+
currentKey;
|
|
28
|
+
pendingKey;
|
|
29
|
+
destroyed = false;
|
|
30
|
+
scrollContainer;
|
|
31
|
+
tabList;
|
|
32
|
+
indicator;
|
|
33
|
+
indicatorFrame;
|
|
34
|
+
sliding = false;
|
|
35
|
+
slidingTimer;
|
|
36
|
+
static SLIDE_MS = 300;
|
|
37
|
+
static FADE = "2rem";
|
|
38
|
+
dataSource;
|
|
39
|
+
scrollable = true;
|
|
40
|
+
justified = false;
|
|
41
|
+
icons = ICONS;
|
|
42
|
+
canScrollStart = signal(false, ...ngDevMode ? [{ debugName: "canScrollStart" }] : /* istanbul ignore next */ []);
|
|
43
|
+
canScrollEnd = signal(false, ...ngDevMode ? [{ debugName: "canScrollEnd" }] : /* istanbul ignore next */ []);
|
|
44
|
+
activeChange = new EventEmitter();
|
|
45
|
+
currentActive;
|
|
46
|
+
resizeObserver;
|
|
47
|
+
get isLoadingState() {
|
|
48
|
+
return this.dataSource.state === MnCollectionState.LOADING;
|
|
49
|
+
}
|
|
50
|
+
get skeletonTabs() {
|
|
51
|
+
const count = this.dataSource.skeletonCount ?? (this.dataSource.items.length || DEFAULT_SKELETON_TAB_COUNT);
|
|
52
|
+
return Array.from({ length: count }, (_, index) => index);
|
|
53
|
+
}
|
|
54
|
+
constructor() {
|
|
55
|
+
this.queryParamsSub = this.route?.queryParamMap.subscribe((params) => {
|
|
56
|
+
const param = this.urlParam();
|
|
57
|
+
if (param) this.activateUrlKey(params.get(param));
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
ngDoCheck() {
|
|
61
|
+
this.syncActiveTab();
|
|
62
|
+
}
|
|
63
|
+
ngAfterViewInit() {
|
|
64
|
+
const el = this.scrollContainer?.nativeElement;
|
|
65
|
+
if (!el) return;
|
|
66
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
67
|
+
this.updateEdgeFades();
|
|
68
|
+
if (!this.sliding) this.updateIndicator(false);
|
|
69
|
+
});
|
|
70
|
+
this.resizeObserver.observe(el);
|
|
71
|
+
if (el.firstElementChild) this.resizeObserver.observe(el.firstElementChild);
|
|
72
|
+
this.updateEdgeFades();
|
|
73
|
+
this.updateIndicator(false);
|
|
74
|
+
}
|
|
75
|
+
lastFadeGeometry = "";
|
|
76
|
+
ngAfterViewChecked() {
|
|
77
|
+
const el = this.scrollContainer?.nativeElement;
|
|
78
|
+
if (!el) return;
|
|
79
|
+
const geometry = `${el.scrollWidth}:${el.clientWidth}`;
|
|
80
|
+
if (geometry === this.lastFadeGeometry) return;
|
|
81
|
+
this.lastFadeGeometry = geometry;
|
|
82
|
+
this.updateEdgeFades();
|
|
83
|
+
}
|
|
84
|
+
ngOnDestroy() {
|
|
85
|
+
this.destroyed = true;
|
|
86
|
+
this.queryParamsSub?.unsubscribe();
|
|
87
|
+
this.resizeObserver?.disconnect();
|
|
88
|
+
if (this.indicatorFrame !== void 0) cancelAnimationFrame(this.indicatorFrame);
|
|
89
|
+
if (this.slidingTimer !== void 0) clearTimeout(this.slidingTimer);
|
|
90
|
+
}
|
|
91
|
+
updateEdgeFades() {
|
|
92
|
+
const el = this.scrollContainer?.nativeElement;
|
|
93
|
+
if (!el) return;
|
|
94
|
+
const fadeStart = el.scrollLeft > 1;
|
|
95
|
+
const fadeEnd = el.scrollLeft + el.clientWidth < el.scrollWidth - 1;
|
|
96
|
+
this.canScrollStart.set(this.scrollable && fadeStart);
|
|
97
|
+
this.canScrollEnd.set(this.scrollable && fadeEnd);
|
|
98
|
+
const f = MnTabComponent.FADE;
|
|
99
|
+
let mask = "";
|
|
100
|
+
if (this.scrollable && fadeStart && fadeEnd) mask = `linear-gradient(to right, transparent 0, #000 ${f}, #000 calc(100% - ${f}), transparent 100%)`;
|
|
101
|
+
else if (this.scrollable && fadeStart) mask = `linear-gradient(to right, transparent 0, #000 ${f}, #000 100%)`;
|
|
102
|
+
else if (this.scrollable && fadeEnd) mask = `linear-gradient(to right, #000 0, #000 calc(100% - ${f}), transparent 100%)`;
|
|
103
|
+
el.style.maskImage = mask;
|
|
104
|
+
el.style.setProperty("-webkit-mask-image", mask);
|
|
105
|
+
}
|
|
106
|
+
scrollTabs(direction) {
|
|
107
|
+
const el = this.scrollContainer?.nativeElement;
|
|
108
|
+
if (!el) return;
|
|
109
|
+
const reduceMotion = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
110
|
+
el.scrollBy({
|
|
111
|
+
left: direction * el.clientWidth * CHEVRON_SCROLL_RATIO,
|
|
112
|
+
behavior: reduceMotion ? "auto" : "smooth"
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
setActive(item) {
|
|
116
|
+
if (this.currentActive === item) return;
|
|
117
|
+
this.activate(item);
|
|
118
|
+
this.writeUrl(item);
|
|
119
|
+
}
|
|
120
|
+
isTabStop(item) {
|
|
121
|
+
return this.currentActive ? this.currentActive === item : this.dataSource?.items[0] === item;
|
|
122
|
+
}
|
|
123
|
+
onTabKeydown(event, item) {
|
|
124
|
+
const items = this.dataSource?.items ?? [];
|
|
125
|
+
const index = items.indexOf(item);
|
|
126
|
+
if (index < 0) return;
|
|
127
|
+
let target;
|
|
128
|
+
switch (event.key) {
|
|
129
|
+
case "ArrowRight":
|
|
130
|
+
target = (index + 1) % items.length;
|
|
131
|
+
break;
|
|
132
|
+
case "ArrowLeft":
|
|
133
|
+
target = (index - 1 + items.length) % items.length;
|
|
134
|
+
break;
|
|
135
|
+
case "Home":
|
|
136
|
+
target = 0;
|
|
137
|
+
break;
|
|
138
|
+
case "End":
|
|
139
|
+
target = items.length - 1;
|
|
140
|
+
break;
|
|
141
|
+
case "Enter":
|
|
142
|
+
case " ":
|
|
143
|
+
event.preventDefault();
|
|
144
|
+
this.setActive(item);
|
|
145
|
+
return;
|
|
146
|
+
default: return;
|
|
147
|
+
}
|
|
148
|
+
event.preventDefault();
|
|
149
|
+
this.setActive(items[target]);
|
|
150
|
+
this.focusTab(target);
|
|
151
|
+
}
|
|
152
|
+
focusTab(index) {
|
|
153
|
+
const tab = (this.tabList?.nativeElement.querySelectorAll("[role=\"tab\"]"))?.[index];
|
|
154
|
+
if (!tab) return;
|
|
155
|
+
tab.focus();
|
|
156
|
+
tab.scrollIntoView?.({
|
|
157
|
+
block: "nearest",
|
|
158
|
+
inline: "nearest"
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
activate(item) {
|
|
162
|
+
this.currentActive?.onDeactivate?.();
|
|
163
|
+
item.onClick?.();
|
|
164
|
+
this.select(item);
|
|
165
|
+
this.activeChange.emit(item);
|
|
166
|
+
this.beginSlide();
|
|
167
|
+
this.scheduleIndicator(true);
|
|
168
|
+
}
|
|
169
|
+
beginSlide() {
|
|
170
|
+
this.sliding = true;
|
|
171
|
+
if (this.slidingTimer !== void 0) clearTimeout(this.slidingTimer);
|
|
172
|
+
this.slidingTimer = setTimeout(() => {
|
|
173
|
+
this.slidingTimer = void 0;
|
|
174
|
+
this.sliding = false;
|
|
175
|
+
}, MnTabComponent.SLIDE_MS);
|
|
176
|
+
}
|
|
177
|
+
updateIndicator(animate) {
|
|
178
|
+
const bar = this.indicator?.nativeElement;
|
|
179
|
+
const list = this.tabList?.nativeElement;
|
|
180
|
+
if (!bar || !list) return;
|
|
181
|
+
const active = list.querySelector("[role=\"tab\"][aria-selected=\"true\"]");
|
|
182
|
+
if (!active) {
|
|
183
|
+
bar.style.opacity = "0";
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (!animate) bar.style.transition = "none";
|
|
187
|
+
bar.style.opacity = "1";
|
|
188
|
+
bar.style.width = `${active.offsetWidth}px`;
|
|
189
|
+
bar.style.transform = `translateX(${active.offsetLeft}px)`;
|
|
190
|
+
if (!animate) {
|
|
191
|
+
bar.offsetWidth;
|
|
192
|
+
bar.style.transition = "";
|
|
193
|
+
}
|
|
194
|
+
this.revealActiveTab(active);
|
|
195
|
+
}
|
|
196
|
+
revealActiveTab(active) {
|
|
197
|
+
const box = this.scrollContainer?.nativeElement;
|
|
198
|
+
if (!this.scrollable || !box || box.scrollWidth <= box.clientWidth) return;
|
|
199
|
+
const edge = 32;
|
|
200
|
+
const boxRect = box.getBoundingClientRect();
|
|
201
|
+
const tabRect = active.getBoundingClientRect();
|
|
202
|
+
if (tabRect.left < boxRect.left + edge) box.scrollLeft -= boxRect.left + edge - tabRect.left;
|
|
203
|
+
else if (tabRect.right > boxRect.right - edge) box.scrollLeft += tabRect.right - (boxRect.right - edge);
|
|
204
|
+
this.updateEdgeFades();
|
|
205
|
+
}
|
|
206
|
+
scheduleIndicator(animate) {
|
|
207
|
+
if (this.indicatorFrame !== void 0) cancelAnimationFrame(this.indicatorFrame);
|
|
208
|
+
this.indicatorFrame = requestAnimationFrame(() => {
|
|
209
|
+
this.indicatorFrame = void 0;
|
|
210
|
+
this.updateIndicator(animate);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
getBadge(item) {
|
|
214
|
+
if (isSignal(item.badge)) return item.badge();
|
|
215
|
+
return item.badge;
|
|
216
|
+
}
|
|
217
|
+
syncActiveTab() {
|
|
218
|
+
const items = this.dataSource?.items;
|
|
219
|
+
if (!items || items.length === 0) {
|
|
220
|
+
if (this.currentActive !== void 0) {
|
|
221
|
+
this.currentActive = void 0;
|
|
222
|
+
this.currentKey = void 0;
|
|
223
|
+
this.cdr.markForCheck();
|
|
224
|
+
this.scheduleIndicator(false);
|
|
225
|
+
}
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (this.currentActive && items.includes(this.currentActive)) return;
|
|
229
|
+
const defaultIndex = this.dataSource.defaultActive;
|
|
230
|
+
const fallback = items[defaultIndex >= 0 && defaultIndex < items.length ? defaultIndex : 0];
|
|
231
|
+
const restored = this.itemFromUrl(items);
|
|
232
|
+
const previousKey = this.currentKey;
|
|
233
|
+
this.select(restored ?? fallback);
|
|
234
|
+
this.scheduleIndicator(false);
|
|
235
|
+
if (restored && restored !== fallback && this.currentKey !== previousKey) queueMicrotask(() => this.announceRestored(restored));
|
|
236
|
+
}
|
|
237
|
+
select(item) {
|
|
238
|
+
const items = this.dataSource.items;
|
|
239
|
+
this.currentActive = item;
|
|
240
|
+
this.currentKey = this.urlKeys(items)[items.indexOf(item)];
|
|
241
|
+
this.cdr.markForCheck();
|
|
242
|
+
}
|
|
243
|
+
announceRestored(item) {
|
|
244
|
+
if (this.destroyed || this.currentActive !== item) return;
|
|
245
|
+
item.onClick?.();
|
|
246
|
+
this.activeChange.emit(item);
|
|
247
|
+
}
|
|
248
|
+
activateUrlKey(key) {
|
|
249
|
+
const items = this.dataSource?.items;
|
|
250
|
+
if (!key || !items?.length) return;
|
|
251
|
+
const item = items[this.urlKeys(items).indexOf(key)];
|
|
252
|
+
if (!item || item === this.currentActive) return;
|
|
253
|
+
this.activate(item);
|
|
254
|
+
}
|
|
255
|
+
urlParam() {
|
|
256
|
+
if (!this.router || !this.route) return void 0;
|
|
257
|
+
const param = this.dataSource?.urlParam ?? DEFAULT_TAB_URL_PARAM;
|
|
258
|
+
return param === false || param === "" ? void 0 : param;
|
|
259
|
+
}
|
|
260
|
+
itemFromUrl(items) {
|
|
261
|
+
const param = this.urlParam();
|
|
262
|
+
if (!param) return void 0;
|
|
263
|
+
const key = this.pendingKey ?? this.route?.snapshot.queryParamMap.get(param);
|
|
264
|
+
if (!key) return void 0;
|
|
265
|
+
const index = this.urlKeys(items).indexOf(key);
|
|
266
|
+
return index === -1 ? void 0 : items[index];
|
|
267
|
+
}
|
|
268
|
+
writeUrl(item) {
|
|
269
|
+
const param = this.urlParam();
|
|
270
|
+
if (!param || !this.router) return;
|
|
271
|
+
const items = this.dataSource.items;
|
|
272
|
+
const key = this.urlKeys(items)[items.indexOf(item)];
|
|
273
|
+
if (!key) return;
|
|
274
|
+
this.pendingKey = key;
|
|
275
|
+
this.router.navigate([], {
|
|
276
|
+
queryParams: { [param]: key },
|
|
277
|
+
queryParamsHandling: "merge",
|
|
278
|
+
replaceUrl: true
|
|
279
|
+
}).catch(() => void 0).then(() => {
|
|
280
|
+
if (this.pendingKey === key) this.pendingKey = void 0;
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
urlKeys(items) {
|
|
284
|
+
if (this.urlKeyCache?.items === items) return this.urlKeyCache.keys;
|
|
285
|
+
const used = /* @__PURE__ */ new Map();
|
|
286
|
+
const keys = items.map((item) => {
|
|
287
|
+
const base = item.id ?? tabUrlKey(item.label);
|
|
288
|
+
const taken = used.get(base) ?? 0;
|
|
289
|
+
used.set(base, taken + 1);
|
|
290
|
+
return taken === 0 ? base : `${base}-${taken + 1}`;
|
|
291
|
+
});
|
|
292
|
+
this.urlKeyCache = {
|
|
293
|
+
items,
|
|
294
|
+
keys
|
|
295
|
+
};
|
|
296
|
+
return keys;
|
|
297
|
+
}
|
|
298
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
299
|
+
minVersion: "12.0.0",
|
|
300
|
+
version: "22.2.2",
|
|
301
|
+
ngImport: i0,
|
|
302
|
+
type: MnTabComponent,
|
|
303
|
+
deps: [],
|
|
304
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
305
|
+
});
|
|
306
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
307
|
+
minVersion: "17.0.0",
|
|
308
|
+
version: "22.2.2",
|
|
309
|
+
type: MnTabComponent,
|
|
310
|
+
isStandalone: true,
|
|
311
|
+
selector: "mn-tab",
|
|
312
|
+
inputs: {
|
|
313
|
+
dataSource: "dataSource",
|
|
314
|
+
scrollable: "scrollable",
|
|
315
|
+
justified: "justified"
|
|
316
|
+
},
|
|
317
|
+
outputs: { activeChange: "activeChange" },
|
|
318
|
+
viewQueries: [
|
|
319
|
+
{
|
|
320
|
+
propertyName: "scrollContainer",
|
|
321
|
+
first: true,
|
|
322
|
+
predicate: ["scrollContainer"],
|
|
323
|
+
descendants: true
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
propertyName: "tabList",
|
|
327
|
+
first: true,
|
|
328
|
+
predicate: ["tabList"],
|
|
329
|
+
descendants: true
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
propertyName: "indicator",
|
|
333
|
+
first: true,
|
|
334
|
+
predicate: ["indicator"],
|
|
335
|
+
descendants: true
|
|
336
|
+
}
|
|
337
|
+
],
|
|
338
|
+
ngImport: i0,
|
|
339
|
+
template: "<div class=\"relative\">\n <!--\n Scroll chevrons, one per edge that hides tabs. They sit in the 2rem strip the edge fade\n dissolves, so they cover nothing still legible. aria-hidden and out of the Tab order: the\n arrow keys already move between tabs (and scroll them into view), and a screen reader reads\n every tab whether scrolled into view or not. mousedown is cancelled so a press does not\n take focus away from the active tab.\n -->\n @if (canScrollStart()) {\n <button\n (click)=\"scrollTabs(-1)\"\n (mousedown)=\"$event.preventDefault()\"\n aria-hidden=\"true\"\n class=\"absolute inset-y-0 left-0 z-10 flex w-8 cursor-pointer items-center justify-start text-base-content hover:text-primary\"\n data-mn-tab-scroll=\"start\"\n tabindex=\"-1\"\n type=\"button\"\n >\n <svg [size]=\"18\" [lucideIcon]=\"icons.ChevronLeft\"></svg>\n </button>\n }\n @if (canScrollEnd()) {\n <button\n (click)=\"scrollTabs(1)\"\n (mousedown)=\"$event.preventDefault()\"\n aria-hidden=\"true\"\n class=\"absolute inset-y-0 right-0 z-10 flex w-8 cursor-pointer items-center justify-end text-base-content hover:text-primary\"\n data-mn-tab-scroll=\"end\"\n tabindex=\"-1\"\n type=\"button\"\n >\n <svg [size]=\"18\" [lucideIcon]=\"icons.ChevronRight\"></svg>\n </button>\n }\n <div\n #scrollContainer\n (scroll)=\"updateEdgeFades()\"\n class=\"flex justify-start scrollbar-hide\"\n [class.overflow-x-auto]=\"scrollable\"\n [class.overflow-y-hidden]=\"scrollable\"\n >\n <div\n #tabList\n role=\"tablist\"\n class=\"tabs relative flex flex-nowrap -mb-[1px] border-b border-base-300\"\n [class.w-full]=\"justified\"\n >\n <!--\n Shared sliding indicator: a single underline that travels to the active\n tab, rather than each tab flipping its own border on/off (which snaps).\n Pinned to left-0/top-auto so offsetLeft maps 1:1 regardless of the\n flex justify-content or the justified full-width layout; position and\n width are measured and set from TS. Sits on the same baseline as the\n hover ::after so hover → select reads as one continuous underline.\n -->\n <div\n #indicator\n aria-hidden=\"true\"\n class=\"pointer-events-none absolute left-0 top-auto bottom-0 h-[2px] w-0 bg-primary opacity-0 transition-[transform,width] duration-300 ease-out motion-reduce:transition-none\"\n ></div>\n @if (isLoadingState) {\n @for (i of skeletonTabs; track i) {\n <div\n [class.flex-1]=\"justified\"\n class=\"tab px-4 py-2 border-b-2 border-transparent flex items-center justify-center\"\n >\n <mn-skeleton [data]=\"{ shape: 'rectangle', width: '4.5rem', height: '1rem' }\"></mn-skeleton>\n </div>\n }\n } @else {\n @for (item of dataSource.items; track item.label) {\n <!-- One Tab stop per bar (the active tab); the arrow keys, Home and End move between\n tabs and activate them, the WAI-ARIA tabs pattern. Every tab used to be its own\n Tab stop with no arrow keys, so crossing an eight-tab bar took eight presses. -->\n <div\n (click)=\"setActive(item)\"\n (keydown)=\"onTabKeydown($event, item)\"\n [attr.aria-selected]=\"currentActive === item\"\n [attr.tabindex]=\"isTabStop(item) ? 0 : -1\"\n [class.hover:after:scale-x-100]=\"currentActive !== item\"\n [class.flex-1]=\"justified\"\n [class.font-bold]=\"currentActive === item\"\n [class.text-base-content]=\"currentActive !== item\"\n [class.text-primary]=\"currentActive === item\"\n class=\"tab relative px-4 py-2 border-b-2 border-transparent cursor-pointer select-none transition-colors whitespace-nowrap text-center flex items-center gap-2 after:content-[''] after:absolute after:inset-x-0 after:-bottom-[2px] after:h-[2px] after:bg-primary/60 after:origin-center after:scale-x-0 after:transition-transform after:duration-300 after:ease-out\"\n role=\"tab\"\n >\n {{ item.label | mnTranslate }}\n @let badge = getBadge(item);\n @if (badge && badge > 0) {\n <span [data]=\"{ size: 'sm', color: 'accent', variant: 'fill' }\" mnBadge>{{ badge }}</span>\n }\n </div>\n }\n }\n </div>\n </div>\n</div>\n",
|
|
340
|
+
dependencies: [
|
|
341
|
+
{
|
|
342
|
+
kind: "ngmodule",
|
|
343
|
+
type: CommonModule
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
kind: "component",
|
|
347
|
+
type: MnBadge,
|
|
348
|
+
selector: "span[mnBadge]",
|
|
349
|
+
inputs: ["data"]
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
kind: "component",
|
|
353
|
+
type: MnSkeleton,
|
|
354
|
+
selector: "mn-skeleton",
|
|
355
|
+
inputs: ["data"]
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
kind: "component",
|
|
359
|
+
type: LucideDynamicIcon,
|
|
360
|
+
selector: "svg[lucideIcon]",
|
|
361
|
+
inputs: ["lucideIcon"]
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
kind: "pipe",
|
|
365
|
+
type: MnTranslatePipe,
|
|
366
|
+
name: "mnTranslate"
|
|
367
|
+
}
|
|
368
|
+
]
|
|
369
|
+
});
|
|
370
|
+
};
|
|
371
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
372
|
+
minVersion: "12.0.0",
|
|
373
|
+
version: "22.2.2",
|
|
374
|
+
ngImport: i0,
|
|
375
|
+
type: MnTabComponent,
|
|
376
|
+
decorators: [{
|
|
377
|
+
type: Component,
|
|
378
|
+
args: [{
|
|
379
|
+
selector: "mn-tab",
|
|
380
|
+
standalone: true,
|
|
381
|
+
imports: [
|
|
382
|
+
MnTranslatePipe,
|
|
383
|
+
CommonModule,
|
|
384
|
+
MnBadge,
|
|
385
|
+
MnSkeleton,
|
|
386
|
+
LucideDynamicIcon
|
|
387
|
+
],
|
|
388
|
+
template: "<div class=\"relative\">\n <!--\n Scroll chevrons, one per edge that hides tabs. They sit in the 2rem strip the edge fade\n dissolves, so they cover nothing still legible. aria-hidden and out of the Tab order: the\n arrow keys already move between tabs (and scroll them into view), and a screen reader reads\n every tab whether scrolled into view or not. mousedown is cancelled so a press does not\n take focus away from the active tab.\n -->\n @if (canScrollStart()) {\n <button\n (click)=\"scrollTabs(-1)\"\n (mousedown)=\"$event.preventDefault()\"\n aria-hidden=\"true\"\n class=\"absolute inset-y-0 left-0 z-10 flex w-8 cursor-pointer items-center justify-start text-base-content hover:text-primary\"\n data-mn-tab-scroll=\"start\"\n tabindex=\"-1\"\n type=\"button\"\n >\n <svg [size]=\"18\" [lucideIcon]=\"icons.ChevronLeft\"></svg>\n </button>\n }\n @if (canScrollEnd()) {\n <button\n (click)=\"scrollTabs(1)\"\n (mousedown)=\"$event.preventDefault()\"\n aria-hidden=\"true\"\n class=\"absolute inset-y-0 right-0 z-10 flex w-8 cursor-pointer items-center justify-end text-base-content hover:text-primary\"\n data-mn-tab-scroll=\"end\"\n tabindex=\"-1\"\n type=\"button\"\n >\n <svg [size]=\"18\" [lucideIcon]=\"icons.ChevronRight\"></svg>\n </button>\n }\n <div\n #scrollContainer\n (scroll)=\"updateEdgeFades()\"\n class=\"flex justify-start scrollbar-hide\"\n [class.overflow-x-auto]=\"scrollable\"\n [class.overflow-y-hidden]=\"scrollable\"\n >\n <div\n #tabList\n role=\"tablist\"\n class=\"tabs relative flex flex-nowrap -mb-[1px] border-b border-base-300\"\n [class.w-full]=\"justified\"\n >\n <!--\n Shared sliding indicator: a single underline that travels to the active\n tab, rather than each tab flipping its own border on/off (which snaps).\n Pinned to left-0/top-auto so offsetLeft maps 1:1 regardless of the\n flex justify-content or the justified full-width layout; position and\n width are measured and set from TS. Sits on the same baseline as the\n hover ::after so hover → select reads as one continuous underline.\n -->\n <div\n #indicator\n aria-hidden=\"true\"\n class=\"pointer-events-none absolute left-0 top-auto bottom-0 h-[2px] w-0 bg-primary opacity-0 transition-[transform,width] duration-300 ease-out motion-reduce:transition-none\"\n ></div>\n @if (isLoadingState) {\n @for (i of skeletonTabs; track i) {\n <div\n [class.flex-1]=\"justified\"\n class=\"tab px-4 py-2 border-b-2 border-transparent flex items-center justify-center\"\n >\n <mn-skeleton [data]=\"{ shape: 'rectangle', width: '4.5rem', height: '1rem' }\"></mn-skeleton>\n </div>\n }\n } @else {\n @for (item of dataSource.items; track item.label) {\n <!-- One Tab stop per bar (the active tab); the arrow keys, Home and End move between\n tabs and activate them, the WAI-ARIA tabs pattern. Every tab used to be its own\n Tab stop with no arrow keys, so crossing an eight-tab bar took eight presses. -->\n <div\n (click)=\"setActive(item)\"\n (keydown)=\"onTabKeydown($event, item)\"\n [attr.aria-selected]=\"currentActive === item\"\n [attr.tabindex]=\"isTabStop(item) ? 0 : -1\"\n [class.hover:after:scale-x-100]=\"currentActive !== item\"\n [class.flex-1]=\"justified\"\n [class.font-bold]=\"currentActive === item\"\n [class.text-base-content]=\"currentActive !== item\"\n [class.text-primary]=\"currentActive === item\"\n class=\"tab relative px-4 py-2 border-b-2 border-transparent cursor-pointer select-none transition-colors whitespace-nowrap text-center flex items-center gap-2 after:content-[''] after:absolute after:inset-x-0 after:-bottom-[2px] after:h-[2px] after:bg-primary/60 after:origin-center after:scale-x-0 after:transition-transform after:duration-300 after:ease-out\"\n role=\"tab\"\n >\n {{ item.label | mnTranslate }}\n @let badge = getBadge(item);\n @if (badge && badge > 0) {\n <span [data]=\"{ size: 'sm', color: 'accent', variant: 'fill' }\" mnBadge>{{ badge }}</span>\n }\n </div>\n }\n }\n </div>\n </div>\n</div>\n"
|
|
389
|
+
}]
|
|
390
|
+
}],
|
|
391
|
+
ctorParameters: () => [],
|
|
392
|
+
propDecorators: {
|
|
393
|
+
scrollContainer: [{
|
|
394
|
+
type: ViewChild,
|
|
395
|
+
args: ["scrollContainer"]
|
|
396
|
+
}],
|
|
397
|
+
tabList: [{
|
|
398
|
+
type: ViewChild,
|
|
399
|
+
args: ["tabList"]
|
|
400
|
+
}],
|
|
401
|
+
indicator: [{
|
|
402
|
+
type: ViewChild,
|
|
403
|
+
args: ["indicator"]
|
|
404
|
+
}],
|
|
405
|
+
dataSource: [{ type: Input }],
|
|
406
|
+
scrollable: [{ type: Input }],
|
|
407
|
+
justified: [{ type: Input }],
|
|
408
|
+
activeChange: [{ type: Output }]
|
|
409
|
+
}
|
|
410
|
+
});
|
|
645
411
|
export { MnTabComponent };
|
|
646
|
-
|
|
412
|
+
|
|
413
|
+
//# sourceMappingURL=mn-angular-lib-tab.mjs.map
|