@triptease/tt-navbar 0.0.17 → 0.0.18
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/dist/src/TtNavbar.d.ts +4 -1
- package/dist/src/TtNavbar.js +51 -3
- package/dist/src/TtNavbar.js.map +1 -1
- package/dist/test/tt-navbar.test.js +17 -0
- package/dist/test/tt-navbar.test.js.map +1 -1
- package/dist/web/TtNavbar.js +52 -4
- package/dist/web/TtNavbar.js.map +2 -2
- package/dist/web/index.js +52 -4
- package/dist/web/index.js.map +2 -2
- package/dist/web/styles.js +1 -1
- package/dist/web/triptease-logo.js +1 -1
- package/dist/web/tt-navbar.js +52 -4
- package/dist/web/tt-navbar.js.map +2 -2
- package/package.json +1 -1
- package/src/TtNavbar.ts +57 -2
- package/test/tt-navbar.test.ts +24 -0
package/dist/web/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @triptease/tt-navbar v0.0.
|
|
2
|
+
* @triptease/tt-navbar v0.0.18
|
|
3
3
|
*/
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -1064,6 +1064,48 @@ var TtNavbar = class extends i4 {
|
|
|
1064
1064
|
constructor() {
|
|
1065
1065
|
super(...arguments);
|
|
1066
1066
|
this.sidebarOpen = true;
|
|
1067
|
+
/*
|
|
1068
|
+
* Set the active state for the current page.
|
|
1069
|
+
*
|
|
1070
|
+
* This function iterates over all nav links and compares the current URL path with the href of each link.
|
|
1071
|
+
* If the current URL path starts with the href of a link, the link is marked as active. If multiple links
|
|
1072
|
+
* share the same prefix, the longest prefix is used as it is more specific.
|
|
1073
|
+
*
|
|
1074
|
+
* Example:
|
|
1075
|
+
* - Current URL: /channels/123
|
|
1076
|
+
* - Nav links:
|
|
1077
|
+
* - /channels
|
|
1078
|
+
* - /channels/123
|
|
1079
|
+
* - /channels/456
|
|
1080
|
+
*
|
|
1081
|
+
* Loop 1: currentPath = /channels/123, linkPath = /channels, bestMatch = /channels
|
|
1082
|
+
* Loop 2: currentPath = /channels/123, linkPath = /channels/123, bestMatch = /channels/123
|
|
1083
|
+
* Loop 3: currentPath = /channels/123, linkPath = /channels/456, bestMatch = /channels/123
|
|
1084
|
+
* Result: /channels/123 is marked as active
|
|
1085
|
+
*
|
|
1086
|
+
*/
|
|
1087
|
+
this.setActiveState = () => {
|
|
1088
|
+
const currentPath = window.location.pathname;
|
|
1089
|
+
let bestMatch;
|
|
1090
|
+
let bestMatchLength = 0;
|
|
1091
|
+
for (const link of this.allNavLinks) {
|
|
1092
|
+
link.classList.remove("current-page");
|
|
1093
|
+
if (link.hasAttribute("aria-current")) {
|
|
1094
|
+
link.attributes.removeNamedItem("aria-current");
|
|
1095
|
+
}
|
|
1096
|
+
const linkPath = new URL(link.href).pathname;
|
|
1097
|
+
if (currentPath.startsWith(linkPath)) {
|
|
1098
|
+
if (linkPath.length > bestMatchLength) {
|
|
1099
|
+
bestMatch = link;
|
|
1100
|
+
bestMatchLength = linkPath.length;
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
if (bestMatch) {
|
|
1105
|
+
bestMatch.classList.add("current-page");
|
|
1106
|
+
bestMatch.setAttribute("aria-current", "page");
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1067
1109
|
this.closeAllDetails = (element) => {
|
|
1068
1110
|
this.allDetailsElements.forEach((detail) => {
|
|
1069
1111
|
if (element && !detail.contains(element)) {
|
|
@@ -1099,6 +1141,9 @@ var TtNavbar = class extends i4 {
|
|
|
1099
1141
|
}
|
|
1100
1142
|
};
|
|
1101
1143
|
}
|
|
1144
|
+
firstUpdated() {
|
|
1145
|
+
this.setActiveState();
|
|
1146
|
+
}
|
|
1102
1147
|
render() {
|
|
1103
1148
|
return x`
|
|
1104
1149
|
<nav id=${this.id} class="${this.sidebarOpen ? "" : "sidebar-closed"}">
|
|
@@ -1284,12 +1329,15 @@ __decorateClass([
|
|
|
1284
1329
|
__decorateClass([
|
|
1285
1330
|
n4({ type: String, attribute: "client-key" })
|
|
1286
1331
|
], TtNavbar.prototype, "clientKey", 2);
|
|
1287
|
-
__decorateClass([
|
|
1288
|
-
r5()
|
|
1289
|
-
], TtNavbar.prototype, "sidebarOpen", 2);
|
|
1290
1332
|
__decorateClass([
|
|
1291
1333
|
r6("details")
|
|
1292
1334
|
], TtNavbar.prototype, "allDetailsElements", 2);
|
|
1335
|
+
__decorateClass([
|
|
1336
|
+
r6("a")
|
|
1337
|
+
], TtNavbar.prototype, "allNavLinks", 2);
|
|
1338
|
+
__decorateClass([
|
|
1339
|
+
r5()
|
|
1340
|
+
], TtNavbar.prototype, "sidebarOpen", 2);
|
|
1293
1341
|
export {
|
|
1294
1342
|
TtNavbar
|
|
1295
1343
|
};
|