@triptease/tt-navbar 0.0.20 → 0.0.21

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @triptease/tt-navbar v0.0.20
2
+ * @triptease/tt-navbar v0.0.21
3
3
  */
4
4
 
5
5
  // src/urlMappings.ts
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Webcomponent tt-navbar following open-wc recommendations",
4
4
  "license": "MIT",
5
5
  "author": "tt-navbar",
6
- "version": "0.0.20",
6
+ "version": "0.0.21",
7
7
  "type": "module",
8
8
  "main": "dist/src/index.js",
9
9
  "module": "dist/src/index.js",
package/src/Routes.ts ADDED
@@ -0,0 +1,5 @@
1
+ const Routes = {
2
+ CampaignManager: 'CampaignManager',
3
+ };
4
+
5
+ export { Routes };
package/src/TtNavbar.ts CHANGED
@@ -17,6 +17,7 @@ import {
17
17
  import { styles } from './styles.js';
18
18
  import { tripteaseLogo } from './triptease-logo.js';
19
19
  import { urlMappings } from './urlMappings.js';
20
+ import { Routes } from './Routes.js';
20
21
 
21
22
  export class TtNavbar extends LitElement {
22
23
  static styles = styles;
@@ -33,6 +34,9 @@ export class TtNavbar extends LitElement {
33
34
  @property({ type: String, attribute: 'client-key' })
34
35
  clientKey?: string;
35
36
 
37
+ @property({ type: String, attribute: 'active-route' })
38
+ activeRoute?: keyof typeof Routes;
39
+
36
40
  @queryAll('details')
37
41
  protected allDetailsElements!: Array<HTMLDetailsElement>;
38
42
 
@@ -73,12 +77,9 @@ export class TtNavbar extends LitElement {
73
77
  let bestMatchLength = 0;
74
78
 
75
79
  // Check special cases first, as everything will always match on / and return Dashboard
76
-
77
- if (this.campaignManagerUrl.includes(window.location.host)) {
80
+ if (this.activeRoute === Routes.CampaignManager) {
78
81
  const links = Object.values(this.allNavLinks);
79
- bestMatch = links.find(link =>
80
- link.href.includes(this.campaignManagerUrl),
81
- );
82
+ bestMatch = links.find(link => link.id === Routes.CampaignManager);
82
83
  }
83
84
 
84
85
  if (!bestMatch && this.clientKey) {
@@ -184,7 +185,7 @@ export class TtNavbar extends LitElement {
184
185
  @click=${this.onAnchorClick}
185
186
  >${unsafeSVG(home)}<span>Dashboard</span></a
186
187
  >
187
- <a class="nav-item" href=${this.campaignManagerUrl}
188
+ <a id="${Routes.CampaignManager}" class="nav-item" href=${this.campaignManagerUrl}
188
189
  >${unsafeSVG(campaigns)}<span>Campaigns</span></a
189
190
  >
190
191
  <a
package/src/index.ts CHANGED
@@ -1 +1,2 @@
1
1
  export { TtNavbar } from './TtNavbar.js';
2
+ export { Routes } from './Routes.js';
@@ -7,6 +7,7 @@ import {
7
7
  waitUntil,
8
8
  } from '@open-wc/testing';
9
9
  import { TtNavbar } from '../src/index.js';
10
+ import { Routes } from '../src/Routes.js';
10
11
 
11
12
  // eslint-disable-next-line no-undef
12
13
  const getLinkByHref = (links: NodeListOf<HTMLAnchorElement>, href: string) => {
@@ -267,7 +268,7 @@ describe('TtNavbar', () => {
267
268
  const campaignManagerUrl = 'http://localhost:8000';
268
269
 
269
270
  const navbar = await fixture<TtNavbar>(
270
- `<tt-navbar client-key=${CLIENT_KEY} platform-url=${platformUrl} campaign-manager-url=${campaignManagerUrl}></tt-navbar>`,
271
+ `<tt-navbar client-key=${CLIENT_KEY} platform-url=${platformUrl} campaign-manager-url=${campaignManagerUrl} active-route="${Routes.CampaignManager}"></tt-navbar>`,
271
272
  );
272
273
  const anchor = navbar.shadowRoot!.querySelector('a[aria-current="page"]');
273
274
  expect(anchor).to.exist;