@salesforcedevs/dx-components 1.20.0 → 1.20.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dx-components",
3
- "version": "1.20.0",
3
+ "version": "1.20.4",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -46,5 +46,5 @@
46
46
  "volta": {
47
47
  "node": "20.19.0"
48
48
  },
49
- "gitHead": "3ff1ef723b233e63fa9227f127856714a363edac"
49
+ "gitHead": "6a754f7876a57aa5528d47716844c827670e4f76"
50
50
  }
@@ -1,6 +1,10 @@
1
1
  @import "dxHelpers/reset";
2
2
  @import "dxHelpers/text";
3
3
 
4
+ :host {
5
+ --dx-c-toc-padding-bottom: 80px;
6
+ }
7
+
4
8
  .toc {
5
9
  display: flex;
6
10
  flex-direction: row;
@@ -25,12 +29,35 @@
25
29
  margin-bottom: var(--dx-g-spacing-md);
26
30
  }
27
31
 
32
+ .toc-content-header {
33
+ width: 100%;
34
+ }
35
+
36
+ .toc-content-header[show-shadow="true"] {
37
+ box-shadow: 0 4px 4px -2px var(--dx-g-gray-90);
38
+ }
39
+
40
+ .toc-content-header[show-shadow="true"] .toc_title {
41
+ margin-bottom: var(--dx-g-spacing-sm);
42
+ }
43
+
44
+ .toc-items {
45
+ overflow-y: auto;
46
+ padding-bottom: var(--dx-c-toc-padding-bottom);
47
+ padding-right: var(--dx-g-spacing-smd);
48
+ }
49
+
50
+ .toc-items[show-bottom-shadow="true"] {
51
+ box-shadow: 0 4px 4px -2px var(--dx-g-gray-90);
52
+ }
53
+
28
54
  .dx-text-display-8 {
29
55
  padding-top: var(--dx-g-spacing-sm);
30
56
  transition: var(--dx-g-transition-hue-1x);
31
57
  }
32
58
 
33
59
  .content-button {
60
+ display: block;
34
61
  line-height: var(--dx-g-text-lg);
35
62
  color: var(--dx-g-blue-vibrant-20);
36
63
  font-family: var(--dx-g-font-sans);
@@ -1,19 +1,27 @@
1
1
  <template>
2
2
  <div class="toc" role="navigation">
3
3
  <div class="toc toc_content">
4
- <h2 class="dx-text-display-8 toc_title">{header}</h2>
5
- <template for:each={options} for:item="option">
6
- <a
7
- href={option.anchor}
8
- class={option.className}
9
- onclick={onClick}
10
- contentid={option.id}
11
- data-text={option.label}
12
- key={option.id}
13
- >
14
- {option.label}
15
- </a>
16
- </template>
4
+ <div class="toc-content-header" show-shadow={showBoxShadow}>
5
+ <h2 class="dx-text-display-8 toc_title">{header}</h2>
6
+ </div>
7
+ <div
8
+ class="toc-items"
9
+ show-bottom-shadow={showBottomShadow}
10
+ onscroll={handleScroll}
11
+ >
12
+ <template for:each={options} for:item="option">
13
+ <a
14
+ href={option.anchor}
15
+ class={option.className}
16
+ onclick={onClick}
17
+ contentid={option.id}
18
+ data-text={option.label}
19
+ key={option.id}
20
+ >
21
+ {option.label}
22
+ </a>
23
+ </template>
24
+ </div>
17
25
  </div>
18
26
  </div>
19
27
  <div>
@@ -3,8 +3,19 @@ import cx from "classnames";
3
3
  import { ContentElement } from "typings/custom";
4
4
  import { toJson } from "dxUtils/normalizers";
5
5
  import { track as sendGtm } from "dxUtils/analytics";
6
+ import { handleScroll } from "dxUtils/handleScroll";
6
7
 
7
8
  export default class Toc extends LightningElement {
9
+ // For showing shadow at the top
10
+ private showBoxShadow: boolean = false;
11
+ private scrolling: boolean = false;
12
+
13
+ handleScroll = handleScroll.bind(this);
14
+
15
+ // For showing shadow at the bottom
16
+ private showBottomShadow: boolean = false;
17
+ private scrollingToTop: boolean = false;
18
+
8
19
  @api header!: string;
9
20
 
10
21
  @api
@@ -38,6 +49,43 @@ export default class Toc extends LightningElement {
38
49
 
39
50
  @track _options!: Array<ContentElement>;
40
51
 
52
+ // to show shadow box at bottom of list container
53
+ private showShadowAtBottom = (event: any) => {
54
+ const list = event.target;
55
+
56
+ if (!this.scrollingToTop) {
57
+ this.scrollingToTop = true;
58
+ // Set a timeout to handle scroll event after a delay
59
+ setTimeout(() => {
60
+ const isScrollable = list.scrollHeight > list.clientHeight;
61
+ const isAtBottom =
62
+ list.scrollTop + list.clientHeight >=
63
+ list.scrollHeight -
64
+ parseInt(
65
+ getComputedStyle(
66
+ this.template.host
67
+ ).getPropertyValue("--dx-c-toc-padding-bottom"),
68
+ 10
69
+ );
70
+
71
+ this.showBottomShadow = isScrollable && !isAtBottom;
72
+
73
+ // Reset scrolling back to false after handling the scroll
74
+ this.scrollingToTop = false;
75
+ }, 200);
76
+ }
77
+ };
78
+
79
+ renderedCallback(): void {
80
+ const list = this.template.querySelector(".toc-items");
81
+ list?.addEventListener("scroll", this.showShadowAtBottom);
82
+ }
83
+
84
+ disconnectedCallback(): void {
85
+ const list = this.template.querySelector(".toc-items");
86
+ list?.removeEventListener("scroll", this.showShadowAtBottom);
87
+ }
88
+
41
89
  private onClick(e: Event) {
42
90
  const target = e.currentTarget as HTMLElement;
43
91
  const id = target.getAttribute("contentid");
@@ -2,12 +2,14 @@ import { LightningElement, api } from "lwc";
2
2
  import type { OptionWithLink } from "typings/custom";
3
3
  import { toJson } from "dxUtils/normalizers";
4
4
  import { Brand, DevCenterConfig } from "typings/custom";
5
+ import { handleScroll } from "dxUtils/handleScroll";
5
6
 
6
7
  export const HEIGHT_OF_SIDEBAR_ITEM = 32;
7
8
  export const WAIT_TIME_BEFORE_SCROLL_IN_MS = 500;
8
9
 
9
10
  export class SidebarBase extends LightningElement {
10
11
  _sidebarContent: HTMLElement | null = null;
12
+ handleScroll = handleScroll.bind(this);
11
13
 
12
14
  selectedElement: HTMLElement | null = null;
13
15
  timerId: ReturnType<typeof setTimeout> | null = null;
@@ -61,29 +63,6 @@ export class SidebarBase extends LightningElement {
61
63
  return this._sidebarContent;
62
64
  }
63
65
 
64
- /**
65
- * This method is to handle the scroll event for LNB and show box shadow
66
- * @param scrollEvent
67
- */
68
- handleScroll(scrollEvent: any) {
69
- const lnb = scrollEvent.target;
70
-
71
- if (!this.scrolling) {
72
- this.scrolling = true;
73
- // Set a timeout to handle scroll event after a delay
74
- setTimeout(() => {
75
- // Check if lnb is scrolled
76
- if (lnb.scrollTop > 0 && lnb.scrollHeight > lnb.clientHeight) {
77
- this.showBoxShadow = true;
78
- } else {
79
- this.showBoxShadow = false;
80
- }
81
- // Reset scrolling back to false after handling the scroll
82
- this.scrolling = false;
83
- }, 200);
84
- }
85
- }
86
-
87
66
  renderedCallback(): void {
88
67
  /**
89
68
  * Implementing debouncing kind of logic here to scroll to selected element once tree rendering is done
@@ -115,6 +115,7 @@ span {
115
115
  object-fit: cover;
116
116
  transition: var(--dx-g-transition-filter-2x),
117
117
  var(--dx-g-transition-box-shadow-2x);
118
+ width: 100%;
118
119
  }
119
120
 
120
121
  .dx-card-base_borderless-image {
@@ -0,0 +1,20 @@
1
+ /**
2
+ * This generic method is to handle the scroll event and show box shadow below header
3
+ * @param scrollEvent
4
+ */
5
+ export function handleScroll(this: any, scrollEvent: any) {
6
+ const listContainer = scrollEvent.target;
7
+
8
+ if (!this.scrolling) {
9
+ this.scrolling = true;
10
+ // Set a timeout to handle scroll event after a delay
11
+ setTimeout(() => {
12
+ // Check if scrolled
13
+ this.showBoxShadow =
14
+ listContainer.scrollTop > 0 &&
15
+ listContainer.scrollHeight > listContainer.clientHeight;
16
+ // Reset scrolling back to false after handling the scroll
17
+ this.scrolling = false;
18
+ }, 200);
19
+ }
20
+ }