@salesforcedevs/docs-components 1.3.325-rnbtab-alpha → 1.3.325-rnbtab-alpha2

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
@@ -9,6 +9,7 @@
9
9
  "doc/breadcrumbs",
10
10
  "doc/content",
11
11
  "doc/contentCallout",
12
+ "doc/doDont",
12
13
  "doc/contentLayout",
13
14
  "doc/contentMedia",
14
15
  "doc/docXmlContent",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/docs-components",
3
- "version": "1.3.325-rnbtab-alpha",
3
+ "version": "1.3.325-rnbtab-alpha2",
4
4
  "description": "Docs Lightning web components for DSC",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -134,7 +134,7 @@ export default class Content extends LightningElement {
134
134
  // ! Hot fix for incoming html tags from couchdb for xml blocks, fix me soon please
135
135
  language: LANGUAGE_MAP[language] || language,
136
136
  theme: this.codeBlockTheme,
137
- title: "", // Default no title.
137
+ header: "", // Default no title.
138
138
  variant: this.codeBlockType,
139
139
  isEncoded: true
140
140
  });
@@ -173,7 +173,7 @@ export default class Content extends LightningElement {
173
173
  const type = calloutEl.querySelector("h4")!.textContent!;
174
174
  const typeLower = type.toLowerCase();
175
175
  Object.assign(calloutCompEl, {
176
- title: type,
176
+ header: type,
177
177
  variant: typeLower
178
178
  });
179
179
  // eslint-disable-next-line no-use-before-define
@@ -104,7 +104,7 @@ export default class ContentLayout extends LightningElement {
104
104
  }
105
105
 
106
106
  get showTabBasedRNB() {
107
- const tabPanelListItem: any = this.selectTabElement();
107
+ const tabPanelListItem: any = this.getTabPanelItems();
108
108
  return tabPanelListItem?.id === RNB_BY_TAB ? true : false;
109
109
  }
110
110
 
@@ -112,7 +112,7 @@ export default class ContentLayout extends LightningElement {
112
112
  this.updateRNB();
113
113
  };
114
114
 
115
- private selectTabElement() {
115
+ private getTabPanelItems() {
116
116
  return document.querySelector("dx-tab-panel-list");
117
117
  }
118
118
 
@@ -127,17 +127,14 @@ export default class ContentLayout extends LightningElement {
127
127
  private getHeadingElements() {
128
128
  let headingElements = document.querySelectorAll(TOC_HEADER_TAG);
129
129
  if (this.showTabBasedRNB) {
130
- const tabPanelListItem: any = this.selectTabElement();
131
- // for (const tabPanelListItem of tabPanelListItems) {
132
- if (tabPanelListItem.id === RNB_BY_TAB) {
133
- const tabPanels =
134
- tabPanelListItem.querySelectorAll("dx-tab-panel");
135
- for (const tabPanelItem of tabPanels) {
136
- if (tabPanelItem.active) {
137
- headingElements =
138
- tabPanelItem.querySelectorAll(TOC_HEADER_TAG);
139
- break;
140
- }
130
+ const tabPanelListItem: any = this.getTabPanelItems();
131
+ const tabPanels =
132
+ tabPanelListItem?.querySelectorAll("dx-tab-panel");
133
+ for (const tabPanelItem of tabPanels) {
134
+ if (tabPanelItem.active) {
135
+ headingElements =
136
+ tabPanelItem.querySelectorAll(TOC_HEADER_TAG);
137
+ break;
141
138
  }
142
139
  }
143
140
  }
@@ -145,68 +142,19 @@ export default class ContentLayout extends LightningElement {
145
142
  }
146
143
 
147
144
  private updateURL() {
148
- const tabPanelListItem: any = this.selectTabElement();
149
- if (tabPanelListItem?.id === RNB_BY_TAB) {
150
- const tabPanelItems: any =
151
- tabPanelListItem?.shadowRoot.querySelectorAll(
152
- "dx-tab-panel-item"
153
- );
154
- if (tabPanelItems) {
155
- for (const tabPanelItem of tabPanelItems as any) {
156
- const tab = tabPanelItem.shadowRoot.querySelector("button");
157
- const url = new URL(window.location.href);
158
- const previousTabID = url.searchParams.get("type");
145
+ const tabs = this.getAllTabs();
146
+ if (tabs.length > 0) {
147
+ tabs.forEach((tab: any) => {
148
+ if (tab?.getAttribute("aria-selected") === "true") {
159
149
  const tabID = tab?.getAttribute("aria-label");
160
- if (
161
- tab?.getAttribute("aria-selected") === "true" &&
162
- previousTabID !== tabID
163
- ) {
150
+ const url = new URL(window.location.href);
151
+ if (url.searchParams.get("type") !== tabID) {
164
152
  url.searchParams.set("type", tabID);
165
153
  url.hash = "";
166
154
  window.history.pushState({}, "", url.toString());
167
- break;
168
155
  }
169
156
  }
170
- }
171
- }
172
- }
173
-
174
- private tabOnPageLoad() {
175
- const url = new URL(window.location.href);
176
- const previousTabID = url.searchParams.get("type");
177
-
178
- if (!previousTabID) {
179
- this.updateURL();
180
- } else {
181
- const tabPanelListItem: any = this.selectTabElement();
182
- const tabPanelItems: any =
183
- tabPanelListItem?.shadowRoot.querySelectorAll(
184
- "dx-tab-panel-item"
185
- );
186
- const tabPanels = tabPanelListItem.querySelectorAll("dx-tab-panel");
187
- if (tabPanelItems) {
188
- let tabIndex = 0;
189
- for (const tabPanelItem of tabPanelItems as any) {
190
- const tab = tabPanelItem.shadowRoot.querySelector("button");
191
- const activeTab =
192
- tabPanels[tabIndex]?.shadowRoot.querySelector(
193
- ".tabpanel"
194
- );
195
- if (tab?.getAttribute("aria-label") === previousTabID) {
196
- if (activeTab) {
197
- activeTab.classList.add("tabpanel-active");
198
- }
199
- tab.active = true;
200
- this.initialIndex = tabIndex;
201
- } else {
202
- if (activeTab) {
203
- activeTab.classList.remove("tabpanel-active");
204
- }
205
- tab.active = false;
206
- }
207
- tabIndex++;
208
- }
209
- }
157
+ });
210
158
  }
211
159
  }
212
160
 
@@ -260,8 +208,44 @@ export default class ContentLayout extends LightningElement {
260
208
 
261
209
  if (this.showTabBasedRNB) {
262
210
  window.addEventListener("tabchanged", this.onTabChanged);
263
- this.tabOnPageLoad();
211
+ this.restoreTabSelection();
212
+ }
213
+ }
214
+
215
+ private restoreTabSelection() {
216
+ const urlParams = new URLSearchParams(window.location.search);
217
+ const selectedTabId = urlParams.get("type");
218
+
219
+ if (selectedTabId) {
220
+ this.selectTabById(selectedTabId);
221
+ }
222
+ }
223
+
224
+ private getAllTabs(): any[] {
225
+ const tabPanelListItem: any = this.getTabPanelItems();
226
+ if (tabPanelListItem?.shadowRoot) {
227
+ return Array.from(
228
+ tabPanelListItem.shadowRoot.querySelectorAll(
229
+ "dx-tab-panel-item"
230
+ )
231
+ ).map((tabPanelItem: any) =>
232
+ tabPanelItem.shadowRoot.querySelector("button")
233
+ );
264
234
  }
235
+ return [];
236
+ }
237
+
238
+ private selectTabById(tabId: string) {
239
+ requestAnimationFrame(() => {
240
+ const tabs = this.getAllTabs();
241
+ if (tabs.length > 0) {
242
+ tabs.forEach((tab: any) => {
243
+ if (tab?.getAttribute("aria-label") === tabId) {
244
+ tab?.click();
245
+ }
246
+ });
247
+ }
248
+ });
265
249
  }
266
250
 
267
251
  renderedCallback(): void {
@@ -439,7 +423,12 @@ export default class ContentLayout extends LightningElement {
439
423
 
440
424
  // Note: We are doing document.querySelectorAll as a quick fix as we are not getting heading elements reference this.querySelectorAll
441
425
  const headingElements = this.getHeadingElements();
442
- this.updateURL();
426
+
427
+ // We only need to update URL in case of /docs and ignore if tabs are used anywhere else in DSC
428
+ if (this.showTabBasedRNB) {
429
+ this.updateURL();
430
+ }
431
+
443
432
  for (const headingElement of headingElements as any) {
444
433
  // Add headingElements to intersectionObserver for highlighting respective RNB item when user scroll
445
434
  const id = headingElement.getAttribute("id")!;
@@ -0,0 +1,47 @@
1
+ @import "dxHelpers/reset";
2
+ @import "dxHelpers/text";
3
+
4
+ .container {
5
+ display: flex;
6
+ flex-direction: column;
7
+ gap: var(--dx-g-spacing-md);
8
+ flex: 1;
9
+ }
10
+
11
+ .doc-do-dont-header {
12
+ display: flex;
13
+ align-items: center;
14
+ gap: var(--dx-g-spacing-sm);
15
+ }
16
+
17
+ .doc-do-dont-label {
18
+ font-family: var(--dx-g-font-display);
19
+ font-size: var(--dx-g-spacing-md);
20
+ font-weight: var(--dx-g-font-demi);
21
+ line-height: var(--dx-g-spacing-lg);
22
+ }
23
+
24
+ .doc-do-color {
25
+ color: var(--dx-g-green-vibrant-50);
26
+ }
27
+
28
+ .doc-dont-color {
29
+ color: var(--dx-g-red-vibrant-30);
30
+ }
31
+
32
+ .do-dont-image-container {
33
+ display: flex;
34
+ max-height: 480px;
35
+ min-height: 140px;
36
+ padding: var(--dx-g-spacing-3xl) var(--dx-g-spacing-2xl);
37
+ flex-direction: column;
38
+ justify-content: center;
39
+ align-items: center;
40
+ flex: 1;
41
+ border-radius: var(--dx-g-spacing-sm);
42
+ border: 1px solid var(--dx-g-brand-default-color-border-2);
43
+ }
44
+
45
+ .doc-do-dont-img {
46
+ object-fit: contain;
47
+ }
@@ -0,0 +1,27 @@
1
+ <template>
2
+ <div class="container">
3
+ <div class="doc-do-dont-header">
4
+ <template lwc:if={isDo}>
5
+ <dx-icon
6
+ symbol="success"
7
+ size="large"
8
+ color="green-vibrant-50"
9
+ ></dx-icon>
10
+ <div class="doc-do-dont-label doc-do-color">Do</div>
11
+ </template>
12
+ <template lwc:else>
13
+ <dx-icon
14
+ symbol="clear"
15
+ size="large"
16
+ color="red-vibrant-30"
17
+ class="doc-do-dont-icon"
18
+ ></dx-icon>
19
+ <div class="doc-do-dont-label doc-dont-color">Don't</div>
20
+ </template>
21
+ </div>
22
+ <div class="do-dont-image-container">
23
+ <img class="doc-do-dont-img" src={src} alt={caption} />
24
+ </div>
25
+ <div class="dx-text-body-4">{caption}</div>
26
+ </div>
27
+ </template>
@@ -0,0 +1,17 @@
1
+ import { LightningElement, api } from "lwc";
2
+ import { normalizeBoolean } from "dxUtils/normalizers";
3
+
4
+ export default class DoDont extends LightningElement {
5
+ @api caption: string = "";
6
+ @api src!: string;
7
+ _isDo: boolean = false;
8
+
9
+ @api
10
+ get isDo(): boolean {
11
+ return this._isDo;
12
+ }
13
+
14
+ set isDo(value) {
15
+ this._isDo = normalizeBoolean(value);
16
+ }
17
+ }