@salesforcedevs/dx-components 1.3.136 → 1.3.139

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
@@ -77,6 +77,8 @@
77
77
  "dx/skipNavLink",
78
78
  "dx/socials",
79
79
  "dx/spinner",
80
+ "dx/stepSequence",
81
+ "dx/stepSequenceStep",
80
82
  "dx/tabPanel",
81
83
  "dx/tabPanelList",
82
84
  "dx/tbidAvatarButton",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dx-components",
3
- "version": "1.3.136",
3
+ "version": "1.3.139",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -40,5 +40,5 @@
40
40
  "eventsourcemock": "^2.0.0",
41
41
  "luxon": "^3.1.0"
42
42
  },
43
- "gitHead": "c076bf146988d61bedc4710e6443a18d7e27b1ca"
43
+ "gitHead": "0b5ea068f074b865e1f5e35a92ddd97af21fe6a4"
44
44
  }
@@ -11,7 +11,7 @@
11
11
  {title}
12
12
  </h3>
13
13
  <div class="content-body-container">
14
- <img if:true={hasQuote} src="/assets/svg/quotes.svg" alt="" />
14
+ <img if:true={hasQuote} src={quoteGraphicSrc} alt="" />
15
15
  <div class={quoteContentStyle}>
16
16
  <p class={contentBodyStyle}>{body}</p>
17
17
  <p if:true={footNote} class="foot-note dx-text-display-7">
@@ -11,6 +11,7 @@ export default class SectionBanner extends LightningElement {
11
11
  @api hideTopGraphic = false;
12
12
  @api backgroundColor = "indigo-vibrant-20";
13
13
  @api hasQuote = false;
14
+ @api quoteGraphicSrc?: string;
14
15
 
15
16
  get containerStyle() {
16
17
  return cx("container", !this.hideTopGraphic && "top-margin");
@@ -0,0 +1,46 @@
1
+ /*
2
+ This CSS will automatically handle the displaying of child dx-step-sequence-step components,
3
+ including animations, if they are enabled. There is no other UI for this component.
4
+ */
5
+ ::slotted(*) {
6
+ position: absolute;
7
+ top: 0;
8
+ transition: transform 0.4s ease, opacity 0.4s ease;
9
+ width: 100%;
10
+ }
11
+
12
+ .hidden {
13
+ visibility: hidden;
14
+ }
15
+
16
+ .no-animations ::slotted(*) {
17
+ display: none;
18
+ }
19
+
20
+ ::slotted(.visible) {
21
+ display: block;
22
+ }
23
+
24
+ ::slotted(.active-step) {
25
+ position: relative;
26
+ }
27
+
28
+ ::slotted(.animate-left-out) {
29
+ opacity: 0;
30
+ transform: translateX(-100%);
31
+ }
32
+
33
+ ::slotted(.animate-in) {
34
+ opacity: 1;
35
+ transform: translateX(0);
36
+ }
37
+
38
+ ::slotted(.animate-right-out) {
39
+ opacity: 0;
40
+ transform: translateX(100%);
41
+ }
42
+
43
+ .step-sequence-container {
44
+ overflow: hidden;
45
+ position: relative;
46
+ }
@@ -0,0 +1,9 @@
1
+ <template>
2
+ <div class={containerClassName}>
3
+ <slot
4
+ onslotchange={handleSlotChange}
5
+ onstepincrement={handleStepIncrement}
6
+ onstepdecrement={handleStepDecrement}
7
+ ></slot>
8
+ </div>
9
+ </template>
@@ -0,0 +1,197 @@
1
+ /* eslint-disable no-restricted-globals */
2
+ import { api, LightningElement } from "lwc";
3
+ import cx from "classnames";
4
+
5
+ // This is a UI-agnostic wrapper component that turns its children components into a sequence of
6
+ // of steps. The children must be dx-step-sequence-step components. Navigation works both via the browser's
7
+ // forward/back buttons and via any action buttons defined in the dx-step-sequence-step components (see that
8
+ // component for details on the action buttons).
9
+ export default class StepSequence extends LightningElement {
10
+ @api initialStepIndex: string | undefined;
11
+ @api animateTransitions = false;
12
+
13
+ private currentStepIndex = 0;
14
+ private steps: Array<HTMLElement> = [];
15
+ private isHiddenForInitialAnimation = true;
16
+
17
+ private get containerClassName() {
18
+ return cx("step-sequence-container", {
19
+ "no-animations": !this.animateTransitions,
20
+ hidden: this.isHiddenForInitialAnimation
21
+ });
22
+ }
23
+
24
+ connectedCallback() {
25
+ const initialStepIndex = parseInt(this.initialStepIndex as string, 10);
26
+ if (!isNaN(initialStepIndex)) {
27
+ this.currentStepIndex = initialStepIndex;
28
+ }
29
+ history.replaceState(
30
+ {
31
+ currentStepIndex: this.currentStepIndex
32
+ },
33
+ ""
34
+ );
35
+ window.addEventListener("popstate", this.handleHistoryPopstate);
36
+ if (this.animateTransitions) {
37
+ this.addEventListener("transitionend", this.handleTransitionEnd);
38
+ } else {
39
+ this.isHiddenForInitialAnimation = false;
40
+ }
41
+ }
42
+
43
+ disconnectedCallback() {
44
+ window.removeEventListener("popstate", this.handleHistoryPopstate);
45
+ this.removeEventListener("transitionend", this.handleTransitionEnd);
46
+ }
47
+
48
+ // Used only if this.animateTransitions is truthy
49
+ private handleTransitionEnd = ({ target }: Event) => {
50
+ if (
51
+ (target as HTMLElement).tagName?.toLowerCase() !==
52
+ "dx-step-sequence-step"
53
+ ) {
54
+ // Ignore transitions of other nested elements
55
+ return;
56
+ }
57
+
58
+ if (this.isHiddenForInitialAnimation) {
59
+ this.isHiddenForInitialAnimation = false;
60
+ }
61
+
62
+ // Ensure subsequent steps are no longer visible:
63
+ const prevStep = this.steps[this.currentStepIndex - 1];
64
+ const nextStep = this.steps[this.currentStepIndex + 1];
65
+ if (prevStep?.classList.contains("visible")) {
66
+ prevStep.classList.remove("visible");
67
+ }
68
+ if (nextStep?.classList.contains("visible")) {
69
+ nextStep.classList.remove("visible");
70
+ }
71
+
72
+ // Mark the current step as fully active:
73
+ this.steps[this.currentStepIndex].classList.add("active-step");
74
+ };
75
+
76
+ private changeActiveStep(nextStepIndex: number, updateHistory = true) {
77
+ if (nextStepIndex === this.currentStepIndex) {
78
+ // Should never happen, but covering all logical bases. Nothing to do here.
79
+ return;
80
+ }
81
+
82
+ if (!this.animateTransitions) {
83
+ this.steps[this.currentStepIndex].className = "";
84
+ this.steps[nextStepIndex].className = "visible active-step";
85
+ } else {
86
+ // If animations are enabled, we need to animate in the correct directions:
87
+ if (nextStepIndex > this.currentStepIndex) {
88
+ this.steps[this.currentStepIndex].className =
89
+ "visible animate-left-out";
90
+ this.steps[nextStepIndex].className = "visible animate-in";
91
+ } else {
92
+ this.steps[this.currentStepIndex].className =
93
+ "visible animate-right-out";
94
+ this.steps[nextStepIndex].className = "visible animate-in";
95
+ }
96
+ }
97
+
98
+ if (updateHistory) {
99
+ history.pushState(
100
+ {
101
+ currentStepIndex: nextStepIndex
102
+ },
103
+ ""
104
+ );
105
+ }
106
+ this.currentStepIndex = nextStepIndex;
107
+ }
108
+
109
+ private initializeStepAnimationClasses(
110
+ currentStepIndex: number,
111
+ step: HTMLElement,
112
+ stepIndex: number
113
+ ) {
114
+ // All steps to the "left" of the current step are treated as though they've already
115
+ // animated out in that direction, and similarly for all steps to the "right." Only
116
+ // the current step is initialized as visible and active.
117
+ if (stepIndex < currentStepIndex) {
118
+ step.className = "animate-left-out";
119
+ } else if (stepIndex > currentStepIndex) {
120
+ step.className = "animate-right-out";
121
+ } else {
122
+ step.className = "visible active-step";
123
+ }
124
+ }
125
+
126
+ // This method is available in case there are scenarios where a sequence needs to "jump" in some cases
127
+ @api
128
+ public jumpToStep(stepIndex: number) {
129
+ if (stepIndex < 0 || stepIndex >= this.steps.length) {
130
+ // illegal value; ignore
131
+ return;
132
+ }
133
+
134
+ this.changeActiveStep(stepIndex);
135
+
136
+ if (this.animateTransitions) {
137
+ this.steps.forEach((step, index) =>
138
+ this.initializeStepAnimationClasses(stepIndex, step, index)
139
+ );
140
+ }
141
+ }
142
+
143
+ handleHistoryPopstate = ({ state }: PopStateEvent) => {
144
+ if (typeof state.currentStepIndex === "number") {
145
+ this.changeActiveStep(state.currentStepIndex, false);
146
+ }
147
+ };
148
+
149
+ handleStepDecrement(e: CustomEvent) {
150
+ e.stopPropagation();
151
+ if (this.currentStepIndex <= 0) {
152
+ return;
153
+ }
154
+ this.changeActiveStep(this.currentStepIndex - 1);
155
+ }
156
+
157
+ handleStepIncrement(e: CustomEvent) {
158
+ e.stopPropagation();
159
+ if (this.currentStepIndex >= this.steps.length - 1) {
160
+ return;
161
+ }
162
+ this.changeActiveStep(this.currentStepIndex + 1);
163
+ }
164
+
165
+ // Assign steps and appropriate classNames when slots are loaded. This component was built on
166
+ // the assumption that the slotChange will only happen at initial load, though it SHOULD still
167
+ // work even if the slots are changed later (though note that the value of
168
+ // `this.currentStepIndex` will be applied to the new slotted elements; call `jumpToStep` to
169
+ // change it).
170
+ handleSlotChange(e: Event) {
171
+ const slot = e.target as HTMLSlotElement;
172
+ this.steps = slot.assignedElements() as HTMLElement[];
173
+ if (!this.animateTransitions) {
174
+ this.steps[this.currentStepIndex].className = "visible active-step";
175
+ } else {
176
+ // For transition animations to be visible, the container must have a height that will
177
+ // keep the components visible as they transition in and out. Currently this component
178
+ // will have at least the height of the "tallest" slotted element.
179
+ let minHeight = 0;
180
+ this.steps.forEach((step, index) => {
181
+ if (step.clientHeight > minHeight) {
182
+ minHeight = step.clientHeight;
183
+ }
184
+ this.initializeStepAnimationClasses(
185
+ this.currentStepIndex,
186
+ step,
187
+ index
188
+ );
189
+ });
190
+ if (minHeight > 0) {
191
+ this.template.querySelector(
192
+ ".step-sequence-container"
193
+ )!.style.minHeight = `${minHeight}px`;
194
+ }
195
+ }
196
+ }
197
+ }
@@ -0,0 +1,3 @@
1
+ <template>
2
+ <slot onslotchange={handleSlotChange}></slot>
3
+ </template>
@@ -0,0 +1,60 @@
1
+ import { LightningElement } from "lwc";
2
+
3
+ // A UI-agnostic component meant to be used as a child of dx-step-sequence. The component
4
+ // automatically enables "go forward" and "go back" functionality for any slotted element's
5
+ // ".primary-action" child and ".secondary-action" child, respectively. If the
6
+ // dx-step-sequence has `animateTransitions` set to `true`, the transitions will auto-animate.
7
+ // Child component action buttons can still perform whatever actions they want before the
8
+ // step proceeds.
9
+ export default class StepSequenceStep extends LightningElement {
10
+ handleSlotChange(e: Event) {
11
+ const slot = e.target as HTMLSlotElement;
12
+ const rootElement = slot.assignedElements()[0];
13
+ const primaryActionElement = rootElement.querySelector(
14
+ ".primary-action"
15
+ ) as HTMLElement | undefined;
16
+ const secondaryActionElement = rootElement.querySelector(
17
+ ".secondary-action"
18
+ ) as HTMLElement | undefined;
19
+
20
+ if (primaryActionElement) {
21
+ const assignedOnClick = primaryActionElement.onclick;
22
+ primaryActionElement.onclick = (event: MouseEvent) => {
23
+ assignedOnClick?.call(primaryActionElement, event);
24
+ // Child elements can prevent the default "go forward" action.
25
+ if (!event.defaultPrevented) {
26
+ this.goForward();
27
+ }
28
+ };
29
+ }
30
+
31
+ if (secondaryActionElement) {
32
+ const assignedOnClick = secondaryActionElement.onclick;
33
+ secondaryActionElement.onclick = (event: MouseEvent) => {
34
+ assignedOnClick?.call(secondaryActionElement, event);
35
+ // Child elements can prevent the default "go back" action.
36
+ if (!event.defaultPrevented) {
37
+ this.goBack();
38
+ }
39
+ };
40
+ }
41
+ }
42
+
43
+ goForward() {
44
+ this.dispatchEvent(
45
+ new CustomEvent("stepincrement", {
46
+ bubbles: true,
47
+ composed: true
48
+ })
49
+ );
50
+ }
51
+
52
+ goBack() {
53
+ this.dispatchEvent(
54
+ new CustomEvent("stepdecrement", {
55
+ bubbles: true,
56
+ composed: true
57
+ })
58
+ );
59
+ }
60
+ }