@salesforcedevs/dx-components 1.20.0-rnb-scroll → 1.20.0-rnb-scroll-3

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-rnb-scroll",
3
+ "version": "1.20.0-rnb-scroll-3",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -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;
@@ -39,17 +43,12 @@
39
43
 
40
44
  .toc-items {
41
45
  overflow-y: auto;
42
- padding-bottom: 80px;
43
- padding-right: 10px;
46
+ padding-bottom: var(--dx-c-toc-padding-bottom);
47
+ padding-right: var(--dx-g-spacing-smd);
44
48
  }
45
49
 
46
- .scroll-shadow {
47
- position: sticky;
48
- bottom: -80px; /* to maintain padding given to toc-items */
49
- height: 5px;
50
- background: linear-gradient(to bottom, transparent, var(--dx-g-gray-90));
51
- transition: opacity 0.3s;
52
- opacity: 0;
50
+ .toc-items[show-bottom-shadow="true"] {
51
+ box-shadow: 0 4px 4px -2px var(--dx-g-gray-90);
53
52
  }
54
53
 
55
54
  .dx-text-display-8 {
@@ -4,7 +4,11 @@
4
4
  <div class="toc-content-header" show-shadow={showBoxShadow}>
5
5
  <h2 class="dx-text-display-8 toc_title">{header}</h2>
6
6
  </div>
7
- <div class="toc-items" onscroll={handleScroll}>
7
+ <div
8
+ class="toc-items"
9
+ show-bottom-shadow={showBottomShadow}
10
+ onscroll={handleScroll}
11
+ >
8
12
  <template for:each={options} for:item="option">
9
13
  <a
10
14
  href={option.anchor}
@@ -17,7 +21,6 @@
17
21
  {option.label}
18
22
  </a>
19
23
  </template>
20
- <div class="scroll-shadow"></div>
21
24
  </div>
22
25
  </div>
23
26
  </div>
@@ -6,9 +6,16 @@ import { track as sendGtm } from "dxUtils/analytics";
6
6
  import { handleScroll } from "dxUtils/handleScroll";
7
7
 
8
8
  export default class Toc extends LightningElement {
9
- showBoxShadow: boolean = false;
9
+ // For showing shadow at the top
10
+ private showBoxShadow: boolean = false;
11
+ private scrolling: boolean = false;
12
+
10
13
  handleScroll = handleScroll.bind(this);
11
14
 
15
+ // For showing shadow at the bottom
16
+ private showBottomShadow: boolean = false;
17
+ private scrollingToTop: boolean = false;
18
+
12
19
  @api header!: string;
13
20
 
14
21
  @api
@@ -42,6 +49,43 @@ export default class Toc extends LightningElement {
42
49
 
43
50
  @track _options!: Array<ContentElement>;
44
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
+
45
89
  private onClick(e: Event) {
46
90
  const target = e.currentTarget as HTMLElement;
47
91
  const id = target.getAttribute("contentid");
@@ -18,6 +18,7 @@ export class SidebarBase extends LightningElement {
18
18
  expanded: boolean = true;
19
19
  _value?: string = undefined;
20
20
  showBoxShadow: boolean = false;
21
+ private scrolling: boolean = false;
21
22
  _devCenter!: DevCenterConfig;
22
23
 
23
24
  @api langValuePath: string = "id";
@@ -1,17 +1,20 @@
1
+ /**
2
+ * This generic method is to handle the scroll event and show box shadow below header
3
+ * @param scrollEvent
4
+ */
1
5
  export function handleScroll(this: any, scrollEvent: any) {
2
- const { scrollTop, scrollHeight, clientHeight } = scrollEvent.target;
6
+ const listContainer = scrollEvent.target;
3
7
 
4
- // to show shadow box at bottom of list container
5
- const shadow = this.template.querySelector(".scroll-shadow");
6
-
7
- if (shadow) {
8
- const isScrollable = scrollHeight > clientHeight;
9
- const isAtBottom = scrollTop + clientHeight >= scrollHeight - 75; //subtracting to maintain the padding given to toc-items
10
-
11
- shadow.style.opacity = isScrollable && !isAtBottom ? 1 : 0;
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);
12
19
  }
13
-
14
- setTimeout(() => {
15
- this.showBoxShadow = scrollTop > 0 && scrollHeight > clientHeight;
16
- }, 200);
17
20
  }