@salesforcedevs/dx-components 1.3.136 → 1.3.137-j2s

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.
@@ -166,6 +166,7 @@ export default class ScrollManager extends LightningElement {
166
166
  saveScroll = throttle(100, () => {
167
167
  window.history.replaceState(
168
168
  {
169
+ ...window.history.state,
169
170
  scroll: {
170
171
  value: document.body.scrollTop,
171
172
  docSize: document.body.scrollHeight
@@ -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,42 @@
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
+ .no-animations ::slotted(*) {
13
+ display: none;
14
+ }
15
+
16
+ ::slotted(.visible) {
17
+ display: block;
18
+ }
19
+
20
+ ::slotted(.active-step) {
21
+ position: relative;
22
+ }
23
+
24
+ ::slotted(.animate-left-out) {
25
+ opacity: 0;
26
+ transform: translateX(-100%);
27
+ }
28
+
29
+ ::slotted(.animate-in) {
30
+ opacity: 1;
31
+ transform: translateX(0);
32
+ }
33
+
34
+ ::slotted(.animate-right-out) {
35
+ opacity: 0;
36
+ transform: translateX(100%);
37
+ }
38
+
39
+ .step-sequence-container {
40
+ overflow: hidden;
41
+ position: relative;
42
+ }
@@ -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,271 @@
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 animateTransitions = false;
11
+ @api communicateStepChanges = false;
12
+ @api initialStepIndex: string | undefined;
13
+ @api sessionStorageId = "";
14
+ @api useHistory = false;
15
+
16
+ private currentStepIndex = 0;
17
+ private defaultScrollRestorationValue = history.scrollRestoration;
18
+ private isHiddenForInitialAnimation = true;
19
+ private numPendingInitialTransitions = 0;
20
+ private steps: Array<HTMLElement> = [];
21
+
22
+ private get containerClassName() {
23
+ return cx("step-sequence-container", {
24
+ "no-animations": !this.animateTransitions,
25
+ hidden: this.isHiddenForInitialAnimation
26
+ });
27
+ }
28
+
29
+ connectedCallback() {
30
+ const initialStepIndex = parseInt(this.initialStepIndex as string, 10);
31
+
32
+ if (!isNaN(initialStepIndex)) {
33
+ this.currentStepIndex = initialStepIndex;
34
+ }
35
+
36
+ if (this.useHistory) {
37
+ this.defaultScrollRestorationValue = history.scrollRestoration;
38
+ history.scrollRestoration = "manual";
39
+ history.replaceState(
40
+ {
41
+ ...window.history.state,
42
+ currentStepIndex: this.currentStepIndex
43
+ },
44
+ ""
45
+ );
46
+ window.addEventListener("popstate", this.handleHistoryPopstate);
47
+ }
48
+
49
+ if (this.sessionStorageId) {
50
+ sessionStorage.setItem(
51
+ this.sessionStorageId,
52
+ JSON.stringify({
53
+ currentStepIndex: this.currentStepIndex
54
+ })
55
+ );
56
+ }
57
+
58
+ if (this.animateTransitions) {
59
+ this.addEventListener("transitionend", this.handleTransitionEnd);
60
+ } else {
61
+ this.isHiddenForInitialAnimation = false;
62
+ }
63
+ }
64
+
65
+ disconnectedCallback() {
66
+ window.removeEventListener("popstate", this.handleHistoryPopstate);
67
+ this.removeEventListener("transitionend", this.handleTransitionEnd);
68
+ history.scrollRestoration = this.defaultScrollRestorationValue;
69
+ }
70
+
71
+ private scrollToStepTop() {
72
+ this.template.host.scrollIntoView();
73
+ }
74
+
75
+ // Used only if this.animateTransitions is truthy
76
+ private handleTransitionEnd = ({ target }: Event) => {
77
+ if (
78
+ (target as HTMLElement).tagName?.toLowerCase() !==
79
+ "dx-step-sequence-step"
80
+ ) {
81
+ // Ignore transitions of other nested elements
82
+ return;
83
+ }
84
+
85
+ // Ensure subsequent steps are no longer visible:
86
+ const prevStep = this.steps[this.currentStepIndex - 1];
87
+ const nextStep = this.steps[this.currentStepIndex + 1];
88
+ if (prevStep?.classList.contains("visible")) {
89
+ prevStep.classList.remove("visible");
90
+ }
91
+ if (nextStep?.classList.contains("visible")) {
92
+ nextStep.classList.remove("visible");
93
+ }
94
+
95
+ // Mark the current step as fully active:
96
+ this.steps[this.currentStepIndex].classList.add("active-step");
97
+
98
+ if (
99
+ this.isHiddenForInitialAnimation &&
100
+ this.numPendingInitialTransitions > 0
101
+ ) {
102
+ // Initial animation; allow subsequent animations to be visible when ready
103
+ this.numPendingInitialTransitions =
104
+ this.numPendingInitialTransitions - 1;
105
+ if (this.numPendingInitialTransitions === 0) {
106
+ this.isHiddenForInitialAnimation = false;
107
+ }
108
+ }
109
+ };
110
+
111
+ private changeActiveStep(nextStepIndex: number, updateHistory = true) {
112
+ if (
113
+ nextStepIndex === this.currentStepIndex ||
114
+ !this.isStepIndexWithinBounds(nextStepIndex)
115
+ ) {
116
+ // Should never happen, but covering all logical bases. Nothing to do here.
117
+ return;
118
+ }
119
+
120
+ this.scrollToStepTop();
121
+
122
+ if (!this.animateTransitions) {
123
+ this.steps[this.currentStepIndex].className = "";
124
+ this.steps[nextStepIndex].className = "visible active-step";
125
+ } else {
126
+ this.template.querySelector(
127
+ ".step-sequence-container"
128
+ )!.style.minHeight = `${this.steps[nextStepIndex].clientHeight}px`;
129
+ // If animations are enabled, we need to animate in the correct directions:
130
+ if (nextStepIndex > this.currentStepIndex) {
131
+ this.steps[this.currentStepIndex].className =
132
+ "visible animate-left-out";
133
+ this.steps[nextStepIndex].className = "visible animate-in";
134
+ } else {
135
+ this.steps[this.currentStepIndex].className =
136
+ "visible animate-right-out";
137
+ this.steps[nextStepIndex].className = "visible animate-in";
138
+ }
139
+ }
140
+
141
+ if (this.useHistory && updateHistory) {
142
+ history.pushState(
143
+ {
144
+ currentStepIndex: nextStepIndex
145
+ },
146
+ ""
147
+ );
148
+ }
149
+
150
+ if (this.sessionStorageId) {
151
+ sessionStorage.setItem(
152
+ this.sessionStorageId,
153
+ JSON.stringify({
154
+ currentStepIndex: nextStepIndex
155
+ })
156
+ );
157
+ }
158
+
159
+ this.currentStepIndex = nextStepIndex;
160
+
161
+ if (this.communicateStepChanges) {
162
+ this.dispatchEvent(
163
+ new CustomEvent("stepsequencechange", {
164
+ detail: {
165
+ stepIndex: this.currentStepIndex
166
+ },
167
+ composed: true,
168
+ bubbles: true
169
+ })
170
+ );
171
+ }
172
+ }
173
+
174
+ private initializeStepAnimationClasses(
175
+ currentStepIndex: number,
176
+ step: HTMLElement,
177
+ stepIndex: number
178
+ ) {
179
+ // All steps to the "left" of the current step are treated as though they've already
180
+ // animated out in that direction, and similarly for all steps to the "right." Only
181
+ // the current step is initialized as visible and active.
182
+ if (stepIndex < currentStepIndex) {
183
+ step.className = "animate-left-out";
184
+ } else if (stepIndex > currentStepIndex) {
185
+ step.className = "animate-right-out";
186
+ } else {
187
+ step.className = "visible active-step";
188
+ }
189
+ }
190
+
191
+ @api
192
+ public getCurrentStepIndex(): number {
193
+ return this.currentStepIndex;
194
+ }
195
+
196
+ // This method is available in case there are scenarios where a sequence needs to "jump" in some cases
197
+ @api
198
+ public jumpToStep(stepIndex: number) {
199
+ if (!this.isStepIndexWithinBounds(stepIndex)) {
200
+ // illegal value; ignore
201
+ return;
202
+ }
203
+
204
+ this.changeActiveStep(stepIndex);
205
+
206
+ if (this.animateTransitions) {
207
+ this.steps.forEach((step, index) =>
208
+ this.initializeStepAnimationClasses(stepIndex, step, index)
209
+ );
210
+ }
211
+ }
212
+
213
+ private isStepIndexWithinBounds(stepIndex: number) {
214
+ return stepIndex >= 0 && stepIndex < this.steps.length;
215
+ }
216
+
217
+ handleHistoryPopstate = ({ state }: PopStateEvent) => {
218
+ if (typeof state.currentStepIndex === "number") {
219
+ this.changeActiveStep(state.currentStepIndex, false);
220
+ }
221
+ };
222
+
223
+ handleStepDecrement(e: CustomEvent) {
224
+ e.stopPropagation();
225
+ if (this.currentStepIndex <= 0) {
226
+ return;
227
+ }
228
+ this.changeActiveStep(this.currentStepIndex - 1);
229
+ }
230
+
231
+ handleStepIncrement(e: CustomEvent) {
232
+ e.stopPropagation();
233
+ if (this.currentStepIndex >= this.steps.length - 1) {
234
+ return;
235
+ }
236
+ this.changeActiveStep(this.currentStepIndex + 1);
237
+ }
238
+
239
+ // Assign steps and appropriate classNames when slots are loaded. This component was built on
240
+ // the assumption that the slotChange will only happen at initial load, though it SHOULD still
241
+ // work even if the slots are changed later (though note that the value of
242
+ // `this.currentStepIndex` will be applied to the new slotted elements; call `jumpToStep` to
243
+ // change it).
244
+ handleSlotChange(e: Event) {
245
+ const slot = e.target as HTMLSlotElement;
246
+ this.steps = slot.assignedElements() as HTMLElement[];
247
+ let numPendingInitialTransitions = 0;
248
+
249
+ this.steps.forEach((step, index) => {
250
+ if (this.animateTransitions) {
251
+ this.initializeStepAnimationClasses(
252
+ this.currentStepIndex,
253
+ step,
254
+ index
255
+ );
256
+ if (index !== this.currentStepIndex) {
257
+ const numTransitionsForStep =
258
+ getComputedStyle(step)?.transition?.split(",").length;
259
+ if (numTransitionsForStep) {
260
+ numPendingInitialTransitions =
261
+ numPendingInitialTransitions +
262
+ numTransitionsForStep;
263
+ }
264
+ }
265
+ }
266
+ });
267
+
268
+ this.numPendingInitialTransitions = numPendingInitialTransitions;
269
+ this.steps[this.currentStepIndex].className = "visible active-step";
270
+ }
271
+ }
@@ -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
+ }
@@ -0,0 +1,93 @@
1
+ import { LightningElement, track } from "lwc";
2
+
3
+ /**
4
+ * This is a helper class for when you want your LWC component to have state
5
+ * that is automatically tracked _along with_ its previous state, in a React-
6
+ * like fashion, so that you can compare current state with previous state
7
+ * after a render (like React's `commponentDidUpdate`). One benefit of doing
8
+ * things this way is that you can put all of your reactions to state changes
9
+ * in one place, in `renderedCallback`, rather than having them in various
10
+ * places throughout the component.
11
+ *
12
+ * The API consists in `this.prevState`, `this.state`, and `this.setState`.
13
+ *
14
+ * Usage:
15
+ *
16
+ * ```
17
+ * type MyState = {
18
+ * isFetchingContent: boolean;
19
+ * };
20
+ *
21
+ * class MyFetchingComponent extends LightningElementWithState<MyState> {
22
+ * constructor() {
23
+ * // `this.state` can only be initialized once
24
+ * this.state = {
25
+ * isFetchingContent: false
26
+ * };
27
+ * }
28
+ *
29
+ * // Queued for execution whenever a `setState` call completes
30
+ * renderedCallback() {
31
+ * if (this.prevState.isFetchingContent && !this.state.isFetchingContent) {
32
+ * // Do something knowing that we just finished fetching.
33
+ * notifyFetchSuccessful();
34
+ * }
35
+ * }
36
+ *
37
+ * fetchSomething() {
38
+ * this.setState({
39
+ * isFetchingContent: true
40
+ * });
41
+ *
42
+ * fetch(whatever).then(() => {
43
+ * this.setState({
44
+ * isFetching: false
45
+ * }
46
+ * });
47
+ * }
48
+ * }
49
+ * ```
50
+ */
51
+ export abstract class LightningElementWithState<
52
+ T extends { [key: string]: unknown }
53
+ > extends LightningElement {
54
+ private _prevState = {} as T;
55
+ @track private _state = {} as T;
56
+
57
+ private _didInitializeState = false;
58
+
59
+ protected get prevState(): T {
60
+ return Object.freeze({
61
+ ...this._prevState
62
+ });
63
+ }
64
+
65
+ protected get state(): T {
66
+ return Object.freeze({
67
+ ...this._state
68
+ });
69
+ }
70
+
71
+ protected set state(initialState: T) {
72
+ if (!this._didInitializeState) {
73
+ this._state = {
74
+ ...initialState
75
+ };
76
+ this._didInitializeState = true;
77
+ } else {
78
+ throw new Error(
79
+ "To mutate state after initialization, use `this.setState`."
80
+ );
81
+ }
82
+ }
83
+
84
+ protected setState = (state: Partial<T>): void => {
85
+ this._prevState = {
86
+ ...this._state
87
+ };
88
+ this._state = {
89
+ ...this._state,
90
+ ...state
91
+ };
92
+ };
93
+ }
@@ -0,0 +1,11 @@
1
+ import { v4 as createUuid } from "uuid";
2
+
3
+ export const getListWithUuids = <T extends object>(
4
+ list: T[],
5
+ idKey?: string
6
+ ) => {
7
+ return list.map((listItem) => ({
8
+ ...listItem,
9
+ [idKey || "id"]: createUuid()
10
+ }));
11
+ };