@oslokommune/punkt-elements 13.22.0 → 14.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,852 @@
1
+ import { P as _, E as c, x as n, n as s, a as M } from "./element-CRDRygXu.js";
2
+ import { P as S } from "./pkt-slot-controller-BPGj-LC5.js";
3
+ import { o as $ } from "./if-defined-BWZGb3bh.js";
4
+ import { e as k, n as v } from "./ref-Xa5dbh--.js";
5
+ import { r as f } from "./state-DS_kr2Fy.js";
6
+ import { e as m } from "./class-map-wy7PUk0P.js";
7
+ import "./button-D99MF5nV.js";
8
+ import "./icon-1dy7UZcu.js";
9
+ import "./link-DzZCw8j2.js";
10
+ import "./textinput-B3Q13J8H.js";
11
+ const d = {
12
+ fromAttribute(e) {
13
+ return e == null ? !1 : e === "" || e === "true" || e === !0 ? !0 : e === "false" || e === !1 ? !1 : !!e;
14
+ },
15
+ toAttribute(e) {
16
+ return e ? "true" : "false";
17
+ }
18
+ }, C = (e) => typeof e.target == "string" ? { title: e.title, iconName: e.iconName, href: e.target } : { title: e.title, iconName: e.iconName, onClick: e.target }, L = (e) => {
19
+ if (!e) return;
20
+ const t = typeof e == "string" ? new Date(e) : e;
21
+ if (!isNaN(t.getTime()))
22
+ return t.toLocaleDateString("nb-NO", {
23
+ day: "numeric",
24
+ month: "long",
25
+ year: "numeric",
26
+ hour: "2-digit",
27
+ minute: "2-digit"
28
+ });
29
+ };
30
+ var w = Object.defineProperty, O = Object.getOwnPropertyDescriptor, y = (e, t, i, l) => {
31
+ for (var r = l > 1 ? void 0 : l ? O(t, i) : t, p = e.length - 1, g; p >= 0; p--)
32
+ (g = e[p]) && (r = (l ? g(t, i, r) : g(r)) || r);
33
+ return l && r && w(t, i, r), r;
34
+ };
35
+ let b = class extends _ {
36
+ constructor() {
37
+ super(...arguments), this.canChangeRepresentation = !1, this.logoutOnClick = !1;
38
+ }
39
+ handleChangeRepresentation() {
40
+ this.dispatchEvent(
41
+ new CustomEvent("change-representation", {
42
+ bubbles: !0,
43
+ composed: !0
44
+ })
45
+ );
46
+ }
47
+ handleLogout() {
48
+ this.dispatchEvent(
49
+ new CustomEvent("log-out", {
50
+ bubbles: !0,
51
+ composed: !0
52
+ })
53
+ );
54
+ }
55
+ handleMenuItemClick(e) {
56
+ "onClick" in e && typeof e.onClick == "function" && e.onClick();
57
+ }
58
+ renderLinkOrButton(e, t) {
59
+ const i = "href" in e, l = m({
60
+ "pkt-user-menu__link": !0,
61
+ "pkt-link-button": !i,
62
+ "pkt-link": !i,
63
+ "pkt-link--icon-left": !i,
64
+ [t || ""]: !!t
65
+ });
66
+ return i ? n`
67
+ <pkt-link
68
+ icon-name=${e.iconName || c}
69
+ href=${e.href}
70
+ aria-hidden="true"
71
+ class="pkt-user-menu__link ${t || ""}"
72
+ >
73
+ ${e.title}
74
+ </pkt-link>
75
+ ` : n`
76
+ <button class=${l} type="button" @click=${() => this.handleMenuItemClick(e)}>
77
+ ${e.iconName ? n`<pkt-icon
78
+ name=${e.iconName}
79
+ class="pkt-link__icon"
80
+ aria-hidden="true"
81
+ ></pkt-icon>` : c}
82
+ ${e.title}
83
+ </button>
84
+ `;
85
+ }
86
+ renderLinkSection(e) {
87
+ return n`
88
+ <ul class="pkt-user-menu__sublist">
89
+ ${e.map(
90
+ (t) => n`
91
+ <li class="pkt-user-menu__subitem">${this.renderLinkOrButton(t)}</li>
92
+ `
93
+ )}
94
+ </ul>
95
+ `;
96
+ }
97
+ render() {
98
+ var t;
99
+ const e = (t = this.userMenu) == null ? void 0 : t.map(C);
100
+ return n`
101
+ <nav class="pkt-user-menu" aria-label="Meny for innlogget bruker">
102
+ <ul class="pkt-user-menu__list">
103
+ <!-- User section -->
104
+ ${this.user ? n`
105
+ <li class="pkt-user-menu__item">
106
+ <div class="pkt-user-menu__label">Pålogget som</div>
107
+ <div class="pkt-user-menu__name" translate="no">${this.user.name}</div>
108
+ ${this.formattedLastLoggedIn ? n`
109
+ <div class="pkt-user-menu__last-logged-in">
110
+ Sist pålogget: <time>${this.formattedLastLoggedIn}</time>
111
+ </div>
112
+ ` : c}
113
+ </li>
114
+ ` : c}
115
+
116
+ <!-- User menu items -->
117
+ ${e && e.length > 0 ? n`
118
+ <li class="pkt-user-menu__item">${this.renderLinkSection(e)}</li>
119
+ ` : c}
120
+
121
+ <!-- Representing section -->
122
+ ${this.representing ? n`
123
+ <li class="pkt-user-menu__item">
124
+ <div class="pkt-user-menu__label">Representerer</div>
125
+ <div class="pkt-user-menu__name" translate="no">${this.representing.name}</div>
126
+ ${this.representing.orgNumber ? n`<div class="pkt-user-menu__org-number">
127
+ Org.nr. ${this.representing.orgNumber}
128
+ </div>` : c}
129
+ ${this.canChangeRepresentation ? n`
130
+ <ul class="pkt-user-menu__sublist mt-size-16">
131
+ <li class="pkt-user-menu__subitem">
132
+ ${this.renderLinkOrButton({
133
+ title: "Endre organisasjon",
134
+ iconName: "cogwheel",
135
+ onClick: () => this.handleChangeRepresentation()
136
+ })}
137
+ </li>
138
+ </ul>
139
+ ` : c}
140
+ </li>
141
+ ` : c}
142
+
143
+ <!-- Change representation without representing object -->
144
+ ${!this.representing && this.canChangeRepresentation ? n`
145
+ <li class="pkt-user-menu__item">
146
+ <ul class="pkt-user-menu__sublist">
147
+ <li class="pkt-user-menu__subitem">
148
+ ${this.renderLinkOrButton({
149
+ title: "Endre organisasjon",
150
+ iconName: "cogwheel",
151
+ onClick: () => this.handleChangeRepresentation()
152
+ })}
153
+ </li>
154
+ </ul>
155
+ </li>
156
+ ` : c}
157
+
158
+ <!-- Logout -->
159
+ ${this.logoutOnClick ? n`
160
+ <li class="pkt-user-menu__item">
161
+ ${this.renderLinkOrButton({
162
+ title: "Logg ut",
163
+ iconName: "exit",
164
+ onClick: () => this.handleLogout()
165
+ })}
166
+ </li>
167
+ ` : c}
168
+ </ul>
169
+ </nav>
170
+ `;
171
+ }
172
+ };
173
+ y([
174
+ s({ type: Object })
175
+ ], b.prototype, "user", 2);
176
+ y([
177
+ s({ type: String, attribute: "formatted-last-logged-in" })
178
+ ], b.prototype, "formattedLastLoggedIn", 2);
179
+ y([
180
+ s({ type: Object })
181
+ ], b.prototype, "representing", 2);
182
+ y([
183
+ s({ type: Array, attribute: "user-menu" })
184
+ ], b.prototype, "userMenu", 2);
185
+ y([
186
+ s({
187
+ type: Boolean,
188
+ attribute: "can-change-representation",
189
+ converter: d
190
+ })
191
+ ], b.prototype, "canChangeRepresentation", 2);
192
+ y([
193
+ s({ type: Boolean, attribute: "logout-on-click", converter: d })
194
+ ], b.prototype, "logoutOnClick", 2);
195
+ b = y([
196
+ M("pkt-header-user-menu")
197
+ ], b);
198
+ var R = Object.defineProperty, B = Object.getOwnPropertyDescriptor, a = (e, t, i, l) => {
199
+ for (var r = l > 1 ? void 0 : l ? B(t, i) : t, p = e.length - 1, g; p >= 0; p--)
200
+ (g = e[p]) && (r = (l ? g(t, i, r) : g(r)) || r);
201
+ return l && r && R(t, i, r), r;
202
+ };
203
+ const E = "https://punkt-cdn.oslo.kommune.no/latest/logos/";
204
+ let o = class extends _ {
205
+ constructor() {
206
+ super(), this.searchPlaceholder = "Søk", this.searchValue = "", this.mobileBreakpoint = 768, this.tabletBreakpoint = 1280, this.openedMenu = "none", this.logOutButtonPlacement = "none", this.position = "fixed", this.scrollBehavior = "hide", this.hideLogo = !1, this.compact = !1, this.showSearch = !1, this.canChangeRepresentation = !1, this.hasLogOut = !1, this.isMobile = !1, this.isTablet = !1, this.openMenu = "none", this.isHidden = !1, this.componentWidth = typeof window < "u" ? window.innerWidth : 0, this.hasSlotContent = !1, this.alignSlotRight = !1, this.alignSearchRight = !1, this.defaultSlot = k(), this.headerRef = k(), this.userContainerRef = k(), this.slotContainerRef = k(), this.searchContainerRef = k(), this.slotContentRef = k(), this.searchMenuRef = k(), this.lastScrollPosition = 0, this.savedScrollY = 0, this.lastFocusedElement = null, this.shouldRestoreFocus = !1, this.handleScroll = () => {
207
+ if (!this.shouldHideOnScroll) return;
208
+ const e = window.pageYOffset || document.documentElement.scrollTop;
209
+ e < 0 || Math.abs(e - this.lastScrollPosition) < 60 || (this.isHidden = e > this.lastScrollPosition, this.lastScrollPosition = e);
210
+ }, this.handleClickOutside = (e) => {
211
+ const t = e.target;
212
+ this.user && this.openMenu === "user" && !t.closest(".pkt-header-service__user-container") && (this.openMenu = "none"), this.openMenu === "slot" && !t.closest(".pkt-header-service__slot-container") && (this.openMenu = "none"), this.openMenu === "search" && !t.closest(".pkt-header-service__search-container") && !t.closest(".pkt-header-service__search-input") && (this.openMenu = "none");
213
+ }, this.handleFocusOut = (e, t) => {
214
+ const i = e.relatedTarget;
215
+ let l;
216
+ switch (t) {
217
+ case "user":
218
+ l = this.userContainerRef;
219
+ break;
220
+ case "slot":
221
+ l = this.slotContainerRef;
222
+ break;
223
+ case "search":
224
+ l = this.searchContainerRef;
225
+ break;
226
+ default:
227
+ return;
228
+ }
229
+ const r = l.value;
230
+ r && (!i || !r.contains(i)) && (this.openMenu = "none");
231
+ }, this.handleEscapeKey = (e) => {
232
+ e.key === "Escape" && this.openMenu !== "none" && (e.preventDefault(), this.shouldRestoreFocus = !0, this.openMenu = "none");
233
+ }, this.slotController = new S(this, this.defaultSlot);
234
+ }
235
+ updateSlots(e) {
236
+ this.hasSlotContent = e.has(null) || e.has(void 0);
237
+ }
238
+ connectedCallback() {
239
+ super.connectedCallback(), this.setupScrollListener();
240
+ }
241
+ disconnectedCallback() {
242
+ var e;
243
+ super.disconnectedCallback(), (e = this.resizeObserver) == null || e.disconnect(), window.removeEventListener("scroll", this.handleScroll), this.unlockScroll();
244
+ }
245
+ firstUpdated() {
246
+ this.setupResizeObserver();
247
+ }
248
+ updated(e) {
249
+ if (super.updated(e), e.has("openedMenu") && this.openedMenu !== this.openMenu && (this.openMenu = this.openedMenu), (e.has("mobileBreakpoint") || e.has("tabletBreakpoint")) && (this.updateIsMobile(), this.updateIsTablet()), e.has("openMenu")) {
250
+ const t = e.get("openMenu");
251
+ this.openMenu !== "none" && (t === "none" || t === void 0) ? (document.addEventListener("mousedown", this.handleClickOutside), document.addEventListener("keydown", this.handleEscapeKey), (this.openMenu === "slot" || this.openMenu === "search") && requestAnimationFrame(() => {
252
+ this.checkDropdownAlignment(this.openMenu);
253
+ })) : this.openMenu === "none" && t !== "none" && (document.removeEventListener("mousedown", this.handleClickOutside), document.removeEventListener("keydown", this.handleEscapeKey), this.restoreFocus());
254
+ }
255
+ (e.has("openMenu") || e.has("isMobile")) && this.updateScrollLock();
256
+ }
257
+ setupResizeObserver() {
258
+ const e = this.headerRef.value;
259
+ e && (this.componentWidth = e.offsetWidth, this.updateIsMobile(), this.updateIsTablet(), this.resizeObserver = new ResizeObserver((t) => {
260
+ for (const i of t)
261
+ i.borderBoxSize && i.borderBoxSize.length > 0 ? this.componentWidth = i.borderBoxSize[0].inlineSize : this.componentWidth = i.contentRect.width, this.updateIsMobile(), this.updateIsTablet();
262
+ }), this.resizeObserver.observe(e));
263
+ }
264
+ updateIsMobile() {
265
+ this.isMobile = this.componentWidth < this.mobileBreakpoint;
266
+ }
267
+ updateIsTablet() {
268
+ this.isTablet = this.componentWidth < this.tabletBreakpoint;
269
+ }
270
+ updateScrollLock() {
271
+ this.position === "fixed" && this.isMobile && this.openMenu !== "none" ? this.lockScroll() : this.unlockScroll();
272
+ }
273
+ lockScroll() {
274
+ const e = document.body, t = document.documentElement;
275
+ this.savedScrollY = window.scrollY || window.pageYOffset;
276
+ const i = window.innerWidth - t.clientWidth;
277
+ i > 0 && (e.style.paddingRight = `${i}px`), e.style.position = "fixed", e.style.top = `-${this.savedScrollY}px`, e.style.left = "0", e.style.right = "0", e.style.width = "100%", e.style.overflow = "hidden", t.classList.add("is-scroll-locked");
278
+ }
279
+ unlockScroll() {
280
+ const e = document.body, t = document.documentElement;
281
+ t.classList.contains("is-scroll-locked") && (e.style.removeProperty("position"), e.style.removeProperty("top"), e.style.removeProperty("left"), e.style.removeProperty("right"), e.style.removeProperty("width"), e.style.removeProperty("overflow"), e.style.removeProperty("padding-right"), t.classList.remove("is-scroll-locked"), window.scrollTo({ top: this.savedScrollY }));
282
+ }
283
+ setupScrollListener() {
284
+ window.addEventListener("scroll", this.handleScroll);
285
+ }
286
+ restoreFocus() {
287
+ this.shouldRestoreFocus && this.lastFocusedElement && document.contains(this.lastFocusedElement) && this.lastFocusedElement.focus(), this.lastFocusedElement = null, this.shouldRestoreFocus = !1;
288
+ }
289
+ checkDropdownAlignment(e) {
290
+ const t = e === "slot" ? this.slotContainerRef : this.searchContainerRef, i = e === "slot" ? this.slotContentRef : this.searchMenuRef;
291
+ if (!t.value || !i.value || !this.isTablet || this.isMobile) return;
292
+ const l = t.value.getBoundingClientRect(), r = i.value.offsetWidth, p = l.left + r > window.innerWidth;
293
+ e === "slot" ? this.alignSlotRight = p : this.alignSearchRight = p;
294
+ }
295
+ handleMenuToggle(e) {
296
+ this.openMenu !== "none" ? this.openMenu = "none" : (this.lastFocusedElement = document.activeElement, this.openMenu = e);
297
+ }
298
+ handleLogoClick(e) {
299
+ this.dispatchEvent(
300
+ new CustomEvent("logo-click", {
301
+ bubbles: !0,
302
+ composed: !0,
303
+ detail: { originalEvent: e }
304
+ })
305
+ );
306
+ }
307
+ handleServiceClick(e) {
308
+ this.dispatchEvent(
309
+ new CustomEvent("service-click", {
310
+ bubbles: !0,
311
+ composed: !0,
312
+ detail: { originalEvent: e }
313
+ })
314
+ );
315
+ }
316
+ handleLogout() {
317
+ this.dispatchEvent(
318
+ new CustomEvent("log-out", {
319
+ bubbles: !0,
320
+ composed: !0
321
+ })
322
+ );
323
+ }
324
+ handleSearch(e) {
325
+ this.dispatchEvent(
326
+ new CustomEvent("search", {
327
+ detail: { query: e },
328
+ bubbles: !0,
329
+ composed: !0
330
+ })
331
+ );
332
+ }
333
+ handleSearchChange(e) {
334
+ this.dispatchEvent(
335
+ new CustomEvent("search-change", {
336
+ detail: { query: e },
337
+ bubbles: !0,
338
+ composed: !0
339
+ })
340
+ );
341
+ }
342
+ handleSearchInputChange(e) {
343
+ const t = e.target.value;
344
+ this.handleSearchChange(t);
345
+ }
346
+ handleSearchKeyDown(e) {
347
+ e.key === "Enter" && this.handleSearch(e.target.value);
348
+ }
349
+ get formattedLastLoggedIn() {
350
+ var e;
351
+ return L((e = this.user) == null ? void 0 : e.lastLoggedIn);
352
+ }
353
+ get isFixed() {
354
+ return this.position === "fixed";
355
+ }
356
+ get shouldHideOnScroll() {
357
+ return this.scrollBehavior === "hide";
358
+ }
359
+ get showLogoutInHeader() {
360
+ return this.hasLogOut && (this.logOutButtonPlacement === "header" || this.logOutButtonPlacement === "both");
361
+ }
362
+ get showLogoutInUserMenu() {
363
+ return this.hasLogOut && (this.logOutButtonPlacement === "userMenu" || this.logOutButtonPlacement === "both");
364
+ }
365
+ renderLogo() {
366
+ if (this.hideLogo) return c;
367
+ const e = n`
368
+ <pkt-icon name="oslologo" aria-hidden="true" path=${E}></pkt-icon>
369
+ `;
370
+ return this.logoLink && typeof this.logoLink == "string" ? n`
371
+ <span class="pkt-header-service__logo">
372
+ <a href=${this.logoLink} aria-label="Tilbake til forside" @click=${this.handleLogoClick}>
373
+ ${e}
374
+ </a>
375
+ </span>
376
+ ` : this.hasAttribute("logo-link") ? n`
377
+ <span class="pkt-header-service__logo">
378
+ <button
379
+ aria-label="Tilbake til forside"
380
+ class="pkt-link-button pkt-link pkt-header-service__logo-link"
381
+ @click=${this.handleLogoClick}
382
+ >
383
+ ${e}
384
+ </button>
385
+ </span>
386
+ ` : n`
387
+ <span class="pkt-header-service__logo" @click=${this.handleLogoClick}>${e}</span>
388
+ `;
389
+ }
390
+ renderServiceName() {
391
+ return this.serviceName ? this.serviceLink && typeof this.serviceLink == "string" ? n`
392
+ <span class="pkt-header-service__service-name">
393
+ <pkt-link
394
+ href=${this.serviceLink}
395
+ class="pkt-header-service__service-link"
396
+ @click=${this.handleServiceClick}
397
+ >
398
+ ${this.serviceName}
399
+ </pkt-link>
400
+ </span>
401
+ ` : this.hasAttribute("service-link") ? n`
402
+ <span class="pkt-header-service__service-name">
403
+ <button
404
+ class="pkt-link-button pkt-link pkt-header-service__service-link"
405
+ @click=${this.handleServiceClick}
406
+ >
407
+ ${this.serviceName}
408
+ </button>
409
+ </span>
410
+ ` : n`
411
+ <span class="pkt-header-service__service-name" @click=${this.handleServiceClick}>
412
+ <span class="pkt-header-service__service-link">${this.serviceName}</span>
413
+ </span>
414
+ ` : c;
415
+ }
416
+ renderSlotContainer() {
417
+ const e = m({
418
+ "pkt-header-service__slot-container": !0,
419
+ "is-open": this.openMenu === "slot"
420
+ }), t = m({
421
+ "pkt-header-service__slot-content": !0,
422
+ "align-right": this.alignSlotRight
423
+ });
424
+ return n`
425
+ <div
426
+ class=${e}
427
+ @focusout=${(i) => this.handleFocusOut(i, "slot")}
428
+ ${v(this.slotContainerRef)}
429
+ >
430
+ ${this.isTablet && this.hasSlotContent ? n`
431
+ <pkt-button
432
+ skin="secondary"
433
+ variant="icon-only"
434
+ iconName="menu"
435
+ size=${this.isMobile ? "small" : "medium"}
436
+ state=${this.openMenu === "slot" ? "active" : "normal"}
437
+ @click=${() => this.handleMenuToggle("slot")}
438
+ aria-expanded=${this.openMenu === "slot"}
439
+ aria-controls="mobile-slot-menu"
440
+ aria-label="Åpne meny"
441
+ >
442
+ Meny
443
+ </pkt-button>
444
+ ` : c}
445
+ <div
446
+ class=${t}
447
+ id="mobile-slot-menu"
448
+ role=${this.isTablet ? "menu" : c}
449
+ aria-label=${this.isTablet ? "Meny" : c}
450
+ ${v(this.slotContentRef)}
451
+ ${v(this.defaultSlot)}
452
+ ></div>
453
+ </div>
454
+ `;
455
+ }
456
+ renderSearch() {
457
+ if (!this.showSearch) return c;
458
+ if (this.isTablet) {
459
+ const e = m({
460
+ "pkt-header-service__search-container": !0,
461
+ "is-open": this.openMenu === "search"
462
+ }), t = m({
463
+ "pkt-header-service__mobile-menu": !0,
464
+ "is-open": this.openMenu === "search",
465
+ "align-right": this.alignSearchRight
466
+ });
467
+ return n`
468
+ <div
469
+ class=${e}
470
+ @focusout=${(i) => this.handleFocusOut(i, "search")}
471
+ ${v(this.searchContainerRef)}
472
+ >
473
+ <pkt-button
474
+ skin="secondary"
475
+ variant="icon-only"
476
+ iconName="magnifying-glass-big"
477
+ size=${this.isMobile ? "small" : "medium"}
478
+ @click=${() => this.handleMenuToggle("search")}
479
+ state=${this.openMenu === "search" ? "active" : "normal"}
480
+ aria-expanded=${this.openMenu === "search"}
481
+ aria-controls="mobile-search-menu"
482
+ aria-label="Åpne søkefelt"
483
+ >
484
+ Søk
485
+ </pkt-button>
486
+ <div class=${t} ${v(this.searchMenuRef)}>
487
+ ${this.openMenu === "search" ? n`
488
+ <pkt-textinput
489
+ id="mobile-search-menu"
490
+ class="pkt-header-service__search-input"
491
+ type="search"
492
+ label="Søk"
493
+ useWrapper="false"
494
+ placeholder=${this.searchPlaceholder}
495
+ value=${this.searchValue}
496
+ autofocus
497
+ fullwidth
498
+ @input=${this.handleSearchInputChange}
499
+ @keydown=${(i) => {
500
+ i.key === "Enter" && this.handleSearch(i.target.value);
501
+ }}
502
+ ></pkt-textinput>
503
+ ` : c}
504
+ </div>
505
+ </div>
506
+ `;
507
+ }
508
+ return n`
509
+ <pkt-textinput
510
+ id="header-service-search"
511
+ class="pkt-header-service__search-input"
512
+ type="search"
513
+ label="Søk"
514
+ useWrapper="false"
515
+ placeholder=${this.searchPlaceholder}
516
+ value=${this.searchValue}
517
+ @input=${this.handleSearchInputChange}
518
+ @keydown=${this.handleSearchKeyDown}
519
+ ></pkt-textinput>
520
+ `;
521
+ }
522
+ renderUserButton() {
523
+ var t;
524
+ if (!this.user) return c;
525
+ const e = m({
526
+ "pkt-header-service__user-menu": this.isMobile === !1,
527
+ "pkt-header-service__mobile-menu": this.isMobile === !0,
528
+ "is-open": this.openMenu === "user"
529
+ });
530
+ return n`
531
+ <div
532
+ class="pkt-header-service__user-container"
533
+ @focusout=${(i) => this.handleFocusOut(i, "user")}
534
+ ${v(this.userContainerRef)}
535
+ >
536
+ <pkt-button
537
+ class=${m({
538
+ "pkt-header-service__user-button": !0,
539
+ "pkt-header-service__user-button--mobile": this.isMobile
540
+ })}
541
+ skin="secondary"
542
+ size=${this.isMobile ? "small" : "medium"}
543
+ state=${this.openMenu === "user" ? "active" : "normal"}
544
+ variant="icons-right-and-left"
545
+ iconName="user"
546
+ secondIconName=${this.openMenu === "user" ? "chevron-thin-up" : "chevron-thin-down"}
547
+ @click=${() => this.handleMenuToggle("user")}
548
+ >
549
+ <span class="pkt-sr-only">Brukermeny: </span>
550
+ ${((t = this.representing) == null ? void 0 : t.name) || this.user.name}
551
+ </pkt-button>
552
+ ${this.openMenu === "user" && this.user ? n`
553
+ <div class=${e}>
554
+ <pkt-header-user-menu
555
+ .user=${this.user}
556
+ formatted-last-logged-in=${this.formattedLastLoggedIn || c}
557
+ .representing=${this.representing}
558
+ .userMenu=${this.userMenu}
559
+ ?can-change-representation=${this.canChangeRepresentation}
560
+ ?logout-on-click=${this.showLogoutInUserMenu}
561
+ @change-representation=${() => this.dispatchEvent(
562
+ new CustomEvent("change-representation", { bubbles: !0, composed: !0 })
563
+ )}
564
+ @log-out=${this.handleLogout}
565
+ ></pkt-header-user-menu>
566
+ </div>
567
+ ` : c}
568
+ </div>
569
+ `;
570
+ }
571
+ renderHeader() {
572
+ const e = m({
573
+ "pkt-header-service": !0,
574
+ "pkt-header-service--compact": this.compact,
575
+ "pkt-header-service--mobile": this.isMobile,
576
+ "pkt-header-service--tablet": this.isTablet,
577
+ "pkt-header-service--fixed": this.isFixed,
578
+ "pkt-header-service--scroll-to-hide": this.shouldHideOnScroll,
579
+ "pkt-header-service--hidden": this.isHidden
580
+ }), t = m({
581
+ "pkt-header-service__logo-area": !0,
582
+ "pkt-header-service__logo-area--without-service": !this.serviceName
583
+ });
584
+ return n`
585
+ <header class=${e} ${v(this.headerRef)}>
586
+ <div class=${t}>${this.renderLogo()} ${this.renderServiceName()}</div>
587
+
588
+ <div class="pkt-header-service__content">
589
+ ${this.renderSlotContainer()} ${this.renderSearch()}
590
+ ${this.isTablet && this.showLogoutInHeader ? n`
591
+ <pkt-button
592
+ skin="secondary"
593
+ size=${this.isMobile ? "small" : "medium"}
594
+ variant="icon-only"
595
+ iconName="exit"
596
+ @click=${this.handleLogout}
597
+ >
598
+ Logg ut
599
+ </pkt-button>
600
+ ` : c}
601
+ </div>
602
+
603
+ <div class="pkt-header-service__user">
604
+ ${this.renderUserButton()}
605
+ ${!this.isTablet && this.showLogoutInHeader ? n`
606
+ <pkt-button
607
+ skin="tertiary"
608
+ size="medium"
609
+ variant="icon-right"
610
+ iconName="exit"
611
+ @click=${this.handleLogout}
612
+ >
613
+ Logg ut
614
+ </pkt-button>
615
+ ` : c}
616
+ </div>
617
+ </header>
618
+ `;
619
+ }
620
+ render() {
621
+ const e = this.renderHeader();
622
+ if (this.isFixed) {
623
+ const t = m({
624
+ "pkt-header-service-spacer": !0,
625
+ "pkt-header-service-spacer--compact": this.compact,
626
+ "pkt-header-service-spacer--has-user": !!this.user,
627
+ "pkt-header-service-spacer--mobile": this.isMobile
628
+ });
629
+ return n`
630
+ <div class="pkt-header-service-wrapper">
631
+ ${e}
632
+ <div class=${t}></div>
633
+ </div>
634
+ `;
635
+ }
636
+ return e;
637
+ }
638
+ };
639
+ a([
640
+ s({ type: String, attribute: "service-name" })
641
+ ], o.prototype, "serviceName", 2);
642
+ a([
643
+ s({ type: String, attribute: "service-link" })
644
+ ], o.prototype, "serviceLink", 2);
645
+ a([
646
+ s({ type: String, attribute: "logo-link" })
647
+ ], o.prototype, "logoLink", 2);
648
+ a([
649
+ s({ type: String, attribute: "search-placeholder" })
650
+ ], o.prototype, "searchPlaceholder", 2);
651
+ a([
652
+ s({ type: String, attribute: "search-value" })
653
+ ], o.prototype, "searchValue", 2);
654
+ a([
655
+ s({ type: Number, attribute: "mobile-breakpoint" })
656
+ ], o.prototype, "mobileBreakpoint", 2);
657
+ a([
658
+ s({ type: Number, attribute: "tablet-breakpoint" })
659
+ ], o.prototype, "tabletBreakpoint", 2);
660
+ a([
661
+ s({ type: String, attribute: "opened-menu" })
662
+ ], o.prototype, "openedMenu", 2);
663
+ a([
664
+ s({ type: String, attribute: "log-out-button-placement" })
665
+ ], o.prototype, "logOutButtonPlacement", 2);
666
+ a([
667
+ s({ type: String })
668
+ ], o.prototype, "position", 2);
669
+ a([
670
+ s({ type: String, attribute: "scroll-behavior" })
671
+ ], o.prototype, "scrollBehavior", 2);
672
+ a([
673
+ s({ type: Boolean, attribute: "hide-logo", converter: d })
674
+ ], o.prototype, "hideLogo", 2);
675
+ a([
676
+ s({ type: Boolean, converter: d })
677
+ ], o.prototype, "compact", 2);
678
+ a([
679
+ s({ type: Boolean, attribute: "show-search", converter: d })
680
+ ], o.prototype, "showSearch", 2);
681
+ a([
682
+ s({
683
+ type: Boolean,
684
+ attribute: "can-change-representation",
685
+ converter: d
686
+ })
687
+ ], o.prototype, "canChangeRepresentation", 2);
688
+ a([
689
+ s({ type: Boolean, attribute: "has-log-out", converter: d })
690
+ ], o.prototype, "hasLogOut", 2);
691
+ a([
692
+ s({ type: Object })
693
+ ], o.prototype, "user", 2);
694
+ a([
695
+ s({ type: Array, attribute: "user-menu" })
696
+ ], o.prototype, "userMenu", 2);
697
+ a([
698
+ s({ type: Object })
699
+ ], o.prototype, "representing", 2);
700
+ a([
701
+ f()
702
+ ], o.prototype, "isMobile", 2);
703
+ a([
704
+ f()
705
+ ], o.prototype, "isTablet", 2);
706
+ a([
707
+ f()
708
+ ], o.prototype, "openMenu", 2);
709
+ a([
710
+ f()
711
+ ], o.prototype, "isHidden", 2);
712
+ a([
713
+ f()
714
+ ], o.prototype, "componentWidth", 2);
715
+ a([
716
+ f()
717
+ ], o.prototype, "hasSlotContent", 2);
718
+ a([
719
+ f()
720
+ ], o.prototype, "alignSlotRight", 2);
721
+ a([
722
+ f()
723
+ ], o.prototype, "alignSearchRight", 2);
724
+ o = a([
725
+ M("pkt-header-service")
726
+ ], o);
727
+ var P = Object.defineProperty, N = Object.getOwnPropertyDescriptor, u = (e, t, i, l) => {
728
+ for (var r = l > 1 ? void 0 : l ? N(t, i) : t, p = e.length - 1, g; p >= 0; p--)
729
+ (g = e[p]) && (r = (l ? g(t, i, r) : g(r)) || r);
730
+ return l && r && P(t, i, r), r;
731
+ };
732
+ let h = class extends _ {
733
+ constructor() {
734
+ super(), this.defaultSlot = k(), this.searchPlaceholder = "Søk", this.searchValue = "", this.mobileBreakpoint = 768, this.tabletBreakpoint = 1280, this.openedMenu = "none", this.logOutButtonPlacement = "none", this.position = "fixed", this.scrollBehavior = "hide", this.hideLogo = !1, this.compact = !1, this.showSearch = !1, this.canChangeRepresentation = !1, this.hasLogOut = !1, this.slotController = new S(this, this.defaultSlot);
735
+ }
736
+ firstUpdated(e) {
737
+ super.firstUpdated(e), this.emitDeprecationWarnings();
738
+ }
739
+ emitDeprecationWarnings() {
740
+ this.userMenuFooter !== void 0 && console.warn("[PktHeader] userMenuFooter is deprecated. Use userMenu instead."), this.userOptions !== void 0 && console.warn("[PktHeader] userOptions is deprecated. Use userMenu instead.");
741
+ }
742
+ /**
743
+ * Convert deprecated props to new props
744
+ */
745
+ get effectiveUserMenu() {
746
+ const e = this.userMenu || [], t = this.userMenuFooter || [], i = this.userOptions || [];
747
+ return t.length || i.length ? [...e, ...i, ...t] : this.userMenu;
748
+ }
749
+ render() {
750
+ return n`
751
+ <pkt-header-service
752
+ service-name=${$(this.serviceName)}
753
+ service-link=${$(this.serviceLink)}
754
+ logo-link=${$(this.logoLink)}
755
+ search-placeholder=${this.searchPlaceholder}
756
+ search-value=${this.searchValue}
757
+ mobile-breakpoint=${this.mobileBreakpoint}
758
+ tablet-breakpoint=${this.tabletBreakpoint}
759
+ opened-menu=${this.openedMenu}
760
+ log-out-button-placement=${this.logOutButtonPlacement}
761
+ position=${this.position}
762
+ scroll-behavior=${this.scrollBehavior}
763
+ .hideLogo=${this.hideLogo}
764
+ .compact=${this.compact}
765
+ .showSearch=${this.showSearch}
766
+ .canChangeRepresentation=${this.canChangeRepresentation}
767
+ .hasLogOut=${this.hasLogOut}
768
+ .user=${this.user}
769
+ .userMenu=${this.effectiveUserMenu}
770
+ .representing=${this.representing}
771
+ >
772
+ <div class="pkt-contents" ${v(this.defaultSlot)}></div>
773
+ </pkt-header-service>
774
+ `;
775
+ }
776
+ };
777
+ u([
778
+ s({ type: String, attribute: "service-name" })
779
+ ], h.prototype, "serviceName", 2);
780
+ u([
781
+ s({ type: String, attribute: "service-link" })
782
+ ], h.prototype, "serviceLink", 2);
783
+ u([
784
+ s({ type: String, attribute: "logo-link" })
785
+ ], h.prototype, "logoLink", 2);
786
+ u([
787
+ s({ type: String, attribute: "search-placeholder" })
788
+ ], h.prototype, "searchPlaceholder", 2);
789
+ u([
790
+ s({ type: String, attribute: "search-value" })
791
+ ], h.prototype, "searchValue", 2);
792
+ u([
793
+ s({ type: Number, attribute: "mobile-breakpoint" })
794
+ ], h.prototype, "mobileBreakpoint", 2);
795
+ u([
796
+ s({ type: Number, attribute: "tablet-breakpoint" })
797
+ ], h.prototype, "tabletBreakpoint", 2);
798
+ u([
799
+ s({ type: String, attribute: "opened-menu" })
800
+ ], h.prototype, "openedMenu", 2);
801
+ u([
802
+ s({ type: String, attribute: "log-out-button-placement" })
803
+ ], h.prototype, "logOutButtonPlacement", 2);
804
+ u([
805
+ s({ type: String })
806
+ ], h.prototype, "position", 2);
807
+ u([
808
+ s({ type: String, attribute: "scroll-behavior" })
809
+ ], h.prototype, "scrollBehavior", 2);
810
+ u([
811
+ s({ type: Boolean, attribute: "hide-logo", converter: d })
812
+ ], h.prototype, "hideLogo", 2);
813
+ u([
814
+ s({ type: Boolean, converter: d })
815
+ ], h.prototype, "compact", 2);
816
+ u([
817
+ s({ type: Boolean, attribute: "show-search", converter: d })
818
+ ], h.prototype, "showSearch", 2);
819
+ u([
820
+ s({
821
+ type: Boolean,
822
+ attribute: "can-change-representation",
823
+ converter: d
824
+ })
825
+ ], h.prototype, "canChangeRepresentation", 2);
826
+ u([
827
+ s({ type: Boolean, attribute: "has-log-out", converter: d })
828
+ ], h.prototype, "hasLogOut", 2);
829
+ u([
830
+ s({ type: Object })
831
+ ], h.prototype, "user", 2);
832
+ u([
833
+ s({ type: Array, attribute: "user-menu" })
834
+ ], h.prototype, "userMenu", 2);
835
+ u([
836
+ s({ type: Object })
837
+ ], h.prototype, "representing", 2);
838
+ u([
839
+ s({ type: Array, attribute: "user-menu-footer" })
840
+ ], h.prototype, "userMenuFooter", 2);
841
+ u([
842
+ s({ type: Array, attribute: "user-options" })
843
+ ], h.prototype, "userOptions", 2);
844
+ h = u([
845
+ M("pkt-header")
846
+ ], h);
847
+ export {
848
+ h as PktHeader,
849
+ o as PktHeaderService,
850
+ b as PktHeaderUserMenu,
851
+ L as formatLastLoggedIn
852
+ };