@salesforcedevs/dx-components 0.43.2-alpha2 → 0.43.3-tree-selected-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,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dx-components",
3
- "version": "0.43.2-alpha2",
3
+ "version": "0.43.3-tree-selected-scroll-2",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -0,0 +1,25 @@
1
+ import { LightningElement } from "lwc";
2
+
3
+ const HEIGHT_OF_SIDEBAR_ITEM = 32;
4
+
5
+ export class SidebarBase extends LightningElement {
6
+ /*Scroll to selected tree item */
7
+ private onSelectedItemRendered(event: CustomEvent) {
8
+ event.preventDefault();
9
+ const selectedTreeItem = event.detail.element;
10
+ if (selectedTreeItem) {
11
+ const sidebarContent = this.template.querySelector(
12
+ ".sidebar-content-tree"
13
+ );
14
+ if (sidebarContent) {
15
+ sidebarContent.scrollTo({
16
+ top:
17
+ selectedTreeItem.offsetTop +
18
+ HEIGHT_OF_SIDEBAR_ITEM + // add height of sidebar item
19
+ HEIGHT_OF_SIDEBAR_ITEM * 2, // add height of 2 more items so that user can see at least two more items after selected item
20
+ behavior: "smooth"
21
+ });
22
+ }
23
+ }
24
+ }
25
+ }
@@ -4,7 +4,7 @@ dx-card-content {
4
4
  --dx-c-body-max-lines: 3;
5
5
  }
6
6
 
7
- @media screen and (max-width: 768px) {
7
+ @media screen and (max-width: 1024px) {
8
8
  dx-card-content::part(body),
9
9
  dx-card-content::part(datetime) {
10
10
  display: none;
@@ -26,7 +26,7 @@
26
26
 
27
27
  /* mobile responsiveness */
28
28
 
29
- @media screen and (max-width: 768px) {
29
+ @media screen and (max-width: 1024px) {
30
30
  .card-content:not(.dx-card-base_featured) {
31
31
  flex-direction: row;
32
32
  }
@@ -12,7 +12,7 @@
12
12
  z-index: 1;
13
13
  }
14
14
 
15
- @media screen and (max-width: 768px) {
15
+ @media screen and (max-width: 1024px) {
16
16
  .badge {
17
17
  --badge-size: 56px;
18
18
  }
@@ -7,7 +7,7 @@
7
7
  z-index: 1;
8
8
  }
9
9
 
10
- @media screen and (max-width: 768px) {
10
+ @media screen and (max-width: 1024px) {
11
11
  dx-card-content::part(datetime) {
12
12
  display: block;
13
13
  }
@@ -16,7 +16,6 @@
16
16
  slot="image-badge"
17
17
  ></dx-icon-badge>
18
18
  <dx-formatted-date-time
19
- if:true={datetime}
20
19
  slot="datetime"
21
20
  day="2-digit"
22
21
  month="long"
@@ -2,7 +2,7 @@ import { LightningElement, api } from "lwc";
2
2
 
3
3
  export default class CardVideoPreview extends LightningElement {
4
4
  @api body?: string | null = null;
5
- @api datetime?: string;
5
+ @api datetime!: string;
6
6
  @api featured?: boolean = false;
7
7
  @api href!: string;
8
8
  @api imgAlt?: string;
@@ -69,7 +69,7 @@
69
69
  margin-bottom: var(--dx-g-spacing-md);
70
70
  }
71
71
 
72
- .text > .label:not(:last-child) {
72
+ .text > .label {
73
73
  margin-bottom: var(--dx-g-spacing-lg);
74
74
  }
75
75
 
@@ -3,16 +3,16 @@ import cx from "classnames";
3
3
  import { toDxColor } from "utils/css";
4
4
 
5
5
  export default class Section extends LightningElement {
6
- @api backgroundColor: string = "transparent";
7
- @api dark: boolean = false;
6
+ @api backgroundColor?: string | null = "transparent";
7
+ @api dark?: boolean = false;
8
8
  @api headingLevel: "1" | "2" | "3" | "4" | "5" = "3";
9
- @api label?: string;
10
- @api subtitle?: string;
11
- @api textAlign: "center" | "left" = "left";
12
- @api title?: string;
13
- @api topGraphic: boolean = false;
14
- @api graphicOverlap: boolean = false;
15
- @api bottomGraphic: boolean = false;
9
+ @api label?: string | null = null;
10
+ @api subtitle?: string | null = null;
11
+ @api textAlign?: "center" | "left" = "left";
12
+ @api title?: string | null = null;
13
+ @api topGraphic?: boolean = false;
14
+ @api graphicOverlap?: boolean = false;
15
+ @api bottomGraphic?: boolean = false;
16
16
 
17
17
  private get style(): string {
18
18
  return `--dx-c-section-background-color: ${toDxColor(
@@ -88,6 +88,7 @@
88
88
  tree-root={tree.tree}
89
89
  onselect={onSelect}
90
90
  value={value}
91
+ onselecteditemrendered={onSelectedItemRendered}
91
92
  ></dx-tree>
92
93
  </div>
93
94
  </div>
@@ -1,6 +1,6 @@
1
1
  import cx from "classnames";
2
2
  import { track as trackAnalytics } from "dx/instrumentation";
3
- import { LightningElement, api, track } from "lwc";
3
+ import { api, track } from "lwc";
4
4
  import {
5
5
  TreeNode,
6
6
  SidebarGtmAction,
@@ -9,11 +9,12 @@ import {
9
9
  import { getSidebarSearchParams } from "utils/coveo";
10
10
  import { toJson } from "utils/normalizers";
11
11
  import SidebarSearch from "dx/sidebarSearch";
12
+ import { SidebarBase } from "base-elements/sidebarBase";
12
13
 
13
14
  const MOBILE_SIZE_MATCH = "768px";
14
15
  const TOGGLE_BUTTON_LABEL = "Toggle Sidebar";
15
16
 
16
- export default class Sidebar extends LightningElement {
17
+ export default class Sidebar extends SidebarBase {
17
18
  @api coveoOrganizationId!: string;
18
19
  @api coveoPublicAccessToken!: string;
19
20
  @api coveoSearchHub!: string;
@@ -49,7 +49,7 @@
49
49
  ></dx-input>
50
50
  </div>
51
51
  </div>
52
- <div class="sidebar-content" if:true={anyResultMatch}>
52
+ <div class="sidebar-content sidebar-content-tree" if:true={anyResultMatch}>
53
53
  <dx-tree
54
54
  for:each={filteredTrees}
55
55
  for:item="tree"
@@ -57,6 +57,7 @@
57
57
  tree-root={tree.tree}
58
58
  onselect={onSelect}
59
59
  value={value}
60
+ onselecteditemrendered={onSelectedItemRendered}
60
61
  ></dx-tree>
61
62
  </div>
62
63
  <dx-empty-state
@@ -1,15 +1,16 @@
1
1
  import cx from "classnames";
2
2
  import { track } from "dx/instrumentation";
3
- import { LightningElement, api } from "lwc";
3
+ import { api } from "lwc";
4
4
 
5
5
  import { TreeNode, SidebarGtmAction } from "typings/custom";
6
6
  import { toJson } from "utils/normalizers";
7
+ import { SidebarBase } from "base-elements/sidebarBase";
7
8
 
8
9
  const WAIT_TIME = 500;
9
10
  const MOBILE_SIZE_MATCH = "768px";
10
11
  const TOGGLE_BUTTON_LABEL = "Toggle Sidebar";
11
12
 
12
- export default class Sidebar extends LightningElement {
13
+ export default class Sidebar extends SidebarBase {
13
14
  @api header: string = "";
14
15
 
15
16
  @api
@@ -2,6 +2,7 @@ import { LightningElement, api } from "lwc";
2
2
  import { InternalTreeNode } from "typings/custom";
3
3
  import { track } from "dx/instrumentation";
4
4
  import { SidebarGtmAction } from "typings/custom";
5
+ import { isInViewport } from "utils/browser";
5
6
 
6
7
  const DEFAULT_TARGET = "_self";
7
8
 
@@ -61,6 +62,25 @@ export default class TreeItem extends LightningElement {
61
62
  }
62
63
  }
63
64
 
65
+ renderedCallback(): void {
66
+ this.sendEventToParentIfSelected();
67
+ }
68
+
69
+ private sendEventToParentIfSelected(): void {
70
+ /**
71
+ * This is to send selected element reference to parent if it's not visible in the viewport
72
+ * Parent component will use the elements offsetTop scrollTo that element's position
73
+ */
74
+ if (this.isSelected) {
75
+ const element = this.template.querySelector("dx-tree-tile");
76
+ if (element && !isInViewport(element)) {
77
+ this.fireEvent("selecteditemrendered", {
78
+ element
79
+ });
80
+ }
81
+ }
82
+ }
83
+
64
84
  private onIconClick(event: CustomEvent): void {
65
85
  const isSelectAction = false;
66
86
  this.doExpand(isSelectAction);
@@ -1,3 +1,3 @@
1
1
  <template>
2
- <div class="video-container" lwc:dom="manual"></div>
2
+ <div class="video-container"></div>
3
3
  </template>
@@ -184,6 +184,18 @@ a.dx-card-base:hover dx-card-title {
184
184
 
185
185
  /* Desktop Only */
186
186
  @media screen and (min-width: 1024px) {
187
+ .dx-card-base_layout-horizontal .dx-card-base_borderless-image_link {
188
+ align-self: flex-start;
189
+ flex-shrink: 0;
190
+ width: 0;
191
+ height: unset;
192
+ margin-right: var(--dx-g-card-img-spacing);
193
+ margin-bottom: unset;
194
+ padding-top: unset;
195
+ padding-right: 45%;
196
+ padding-bottom: 22.5%;
197
+ }
198
+
187
199
  .dx-card-base_featured dx-card-title {
188
200
  --dx-c-card-title-letter-spacing: -0.6px;
189
201
  --dx-c-card-title-font-size: 32px;
@@ -204,21 +216,6 @@ a.dx-card-base:hover dx-card-title {
204
216
  }
205
217
  }
206
218
 
207
- /* Tablet + Desktop Only */
208
- @media screen and (min-width: 764px) {
209
- .dx-card-base_layout-horizontal .dx-card-base_borderless-image_link {
210
- align-self: flex-start;
211
- flex-shrink: 0;
212
- width: 0;
213
- height: unset;
214
- margin-right: var(--dx-g-card-img-spacing);
215
- margin-bottom: unset;
216
- padding-top: unset;
217
- padding-right: 45%;
218
- padding-bottom: 22.5%;
219
- }
220
- }
221
-
222
219
  /* Tablet */
223
220
  @media screen and (max-width: 1024px) {
224
221
  :host {
@@ -226,6 +223,10 @@ a.dx-card-base:hover dx-card-title {
226
223
  --dx-g-card-img-spacing: 16px;
227
224
  }
228
225
 
226
+ .dx-card-base_borderless-image {
227
+ min-height: unset;
228
+ }
229
+
229
230
  /* text resp */
230
231
  .dx-text-body-2,
231
232
  .dx-text-body-3 {
@@ -255,9 +256,3 @@ a.dx-card-base:hover dx-card-title {
255
256
  font-size: var(--dx-g-text-sm);
256
257
  }
257
258
  }
258
-
259
- @media screen and (max-width: 764px) {
260
- .dx-card-base_borderless-image {
261
- min-height: unset;
262
- }
263
- }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Returns whether given element is in browser viewport or not
3
+ */
4
+ function isInViewport(element: HTMLElement): boolean {
5
+ if (element) {
6
+ const rect = element.getBoundingClientRect();
7
+ return (
8
+ rect.top >= 0 &&
9
+ rect.left >= 0 &&
10
+ rect.bottom <=
11
+ (window.innerHeight || document.documentElement.clientHeight) &&
12
+ rect.right <=
13
+ (window.innerWidth || document.documentElement.clientWidth)
14
+ );
15
+ }
16
+ return false;
17
+ }
18
+
19
+ export { isInViewport };