@salesforcedevs/dx-components 1.30.6 → 1.31.1-alpha-gh

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/lwc.config.json CHANGED
@@ -59,6 +59,7 @@
59
59
  "dx/footerMfe",
60
60
  "dx/formattedDateTime",
61
61
  "dx/formattedRichText",
62
+ "dx/globalHeader",
62
63
  "dx/grid",
63
64
  "dx/groupText",
64
65
  "dx/headerMobileNavMenu",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dx-components",
3
- "version": "1.30.6",
3
+ "version": "1.31.1-alpha-gh",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -0,0 +1,5 @@
1
+ <template lwc:render-mode="light">
2
+ <div lwc:ref="globalNavContainer" part="container">
3
+ <dx-skip-nav-link></dx-skip-nav-link>
4
+ </div>
5
+ </template>
@@ -0,0 +1,84 @@
1
+ import kebabCase from "lodash.kebabcase";
2
+ import { LightningElement, api } from "lwc";
3
+
4
+ const defaultDomain = "https://developer.salesforce.com";
5
+ const defaultLocale = "en-us";
6
+ const defaultHeaderSettingsBasePath = "/c/public/header-settings";
7
+ const headerSettingsJsonKeys = [
8
+ "regionSelectorOverride",
9
+ "contactLinksOverride"
10
+ ];
11
+
12
+ export default class DevExNavigation extends LightningElement {
13
+ static renderMode = "light";
14
+
15
+ @api locale: string = defaultLocale;
16
+ @api path: string = defaultHeaderSettingsBasePath;
17
+ @api domain: string = defaultDomain;
18
+
19
+ async connectedCallback(): Promise<void> {
20
+ try {
21
+ const headerSettingsResponse = await fetch(
22
+ `${this.domain}${this.path}/${this.locale}.json`,
23
+ {
24
+ headers: {
25
+ "Content-Type": "application/json"
26
+ }
27
+ }
28
+ );
29
+ if (headerSettingsResponse.ok) {
30
+ this.createFullNav(await headerSettingsResponse.json());
31
+ } else {
32
+ this.createBarebonesNav();
33
+ }
34
+ } catch (ex) {
35
+ console.error(`Navigation error: ${ex}`);
36
+ this.createBarebonesNav();
37
+ }
38
+ }
39
+
40
+ private createGlobalNav(globalNavSettings: any): HTMLElement {
41
+ const hgfNav = document.createElement("hgf-c360nav");
42
+
43
+ Object.entries(globalNavSettings).forEach(([key, value]) => {
44
+ if (headerSettingsJsonKeys.includes(key)) {
45
+ value = JSON.stringify(value);
46
+ }
47
+ hgfNav.setAttribute(kebabCase(key), value as string);
48
+ });
49
+
50
+ return hgfNav;
51
+ }
52
+
53
+ private createContextNav(contextNavData: any): HTMLElement {
54
+ const hgfNavContext = document.createElement("hgf-c360contextnav");
55
+ hgfNavContext.setAttribute("data", JSON.stringify(contextNavData));
56
+ return hgfNavContext;
57
+ }
58
+
59
+ private createFullNav(headerData: any): void {
60
+ const hgfNav = this.createGlobalNav(headerData.headerSettings);
61
+ const hgfNavContext = this.createContextNav(headerData.navItems);
62
+ const containerEl = this.refs.globalNavContainer as Element;
63
+ containerEl.appendChild(hgfNav);
64
+ containerEl.appendChild(hgfNavContext);
65
+ }
66
+
67
+ private createBarebonesNav(): void {
68
+ const hgfNav = this.createGlobalNav({
69
+ origin: "",
70
+ contextNavEnabled: "true"
71
+ });
72
+ const hgfNavContext = this.createContextNav({
73
+ variation: "static",
74
+ propertyTitle: {
75
+ label: "Developers",
76
+ url: "/"
77
+ },
78
+ menuGroup: {}
79
+ });
80
+ const containerEl = this.refs.globalNavContainer as Element;
81
+ containerEl.appendChild(hgfNav);
82
+ containerEl.appendChild(hgfNavContext);
83
+ }
84
+ }