@salesforcedevs/dx-components 1.20.0-rnb-scroll → 1.20.0-rnb-scroll-2
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,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:
|
|
43
|
-
padding-right:
|
|
46
|
+
padding-bottom: var(--dx-c-toc-padding-bottom);
|
|
47
|
+
padding-right: var(--dx-g-spacing-smd);
|
|
44
48
|
}
|
|
45
49
|
|
|
46
|
-
.
|
|
47
|
-
|
|
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
|
|
7
|
+
<div
|
|
8
|
+
class="toc-items"
|
|
9
|
+
show-bottom-shadow={showBoxShadowBottom}
|
|
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>
|
|
@@ -7,6 +7,9 @@ import { handleScroll } from "dxUtils/handleScroll";
|
|
|
7
7
|
|
|
8
8
|
export default class Toc extends LightningElement {
|
|
9
9
|
showBoxShadow: boolean = false;
|
|
10
|
+
showBoxShadowBottom: boolean = false;
|
|
11
|
+
private scrolling: boolean = false;
|
|
12
|
+
private scrollToBottom: boolean = false;
|
|
10
13
|
handleScroll = handleScroll.bind(this);
|
|
11
14
|
|
|
12
15
|
@api header!: string;
|
|
@@ -42,6 +45,37 @@ export default class Toc extends LightningElement {
|
|
|
42
45
|
|
|
43
46
|
@track _options!: Array<ContentElement>;
|
|
44
47
|
|
|
48
|
+
// to show shadow box at bottom of list container
|
|
49
|
+
private showShadowAtBottom = (event: any) => {
|
|
50
|
+
const list = event.target;
|
|
51
|
+
|
|
52
|
+
if (!this.scrollToBottom) {
|
|
53
|
+
this.scrollToBottom = true;
|
|
54
|
+
// Set a timeout to handle scroll event after a delay
|
|
55
|
+
setTimeout(() => {
|
|
56
|
+
const isScrollable = list.scrollHeight > list.clientHeight;
|
|
57
|
+
const isAtBottom =
|
|
58
|
+
list.scrollTop + list.clientHeight >=
|
|
59
|
+
list.scrollHeight - 75;
|
|
60
|
+
|
|
61
|
+
this.showBoxShadowBottom = isScrollable && !isAtBottom;
|
|
62
|
+
|
|
63
|
+
// Reset scrolling back to false after handling the scroll
|
|
64
|
+
this.scrollToBottom = false;
|
|
65
|
+
}, 100);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
renderedCallback(): void {
|
|
70
|
+
const list = this.template.querySelector(".toc-items");
|
|
71
|
+
list?.addEventListener("scroll", this.showShadowAtBottom);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
disconnectedCallback(): void {
|
|
75
|
+
const list = this.template.querySelector(".toc-items");
|
|
76
|
+
list?.removeEventListener("scroll", this.showShadowAtBottom);
|
|
77
|
+
}
|
|
78
|
+
|
|
45
79
|
private onClick(e: Event) {
|
|
46
80
|
const target = e.currentTarget as HTMLElement;
|
|
47
81
|
const id = target.getAttribute("contentid");
|
|
@@ -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
|
|
6
|
+
const listContainer = scrollEvent.target;
|
|
3
7
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
}
|