-
Notifications
You must be signed in to change notification settings - Fork 76
/
flow-item.tsx
357 lines (293 loc) · 11.9 KB
/
flow-item.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
import { PropertyValues } from "lit";
import { LitElement, property, createEvent, h, method, JsxNode } from "@arcgis/lumina";
import { getElementDir } from "../../utils/dom";
import {
InteractiveComponent,
InteractiveContainer,
updateHostInteraction,
} from "../../utils/interactive";
import {
componentFocusable,
LoadableComponent,
setComponentLoaded,
setUpLoadableComponent,
} from "../../utils/loadable";
import { HeadingLevel } from "../functional/Heading";
import { SLOTS as PANEL_SLOTS } from "../panel/resources";
import { OverlayPositioning } from "../../utils/floating-ui";
import { CollapseDirection, Scale } from "../interfaces";
import { useT9n } from "../../controllers/useT9n";
import type { Panel } from "../panel/panel";
import type { Action } from "../action/action";
import T9nStrings from "./assets/t9n/flow-item.t9n.en.json";
import { CSS, ICONS, SLOTS } from "./resources";
import { styles } from "./flow-item.scss";
declare global {
interface DeclareElements {
"calcite-flow-item": FlowItem;
}
}
/**
* @slot - A slot for adding custom content.
* @slot action-bar - A slot for adding a `calcite-action-bar` to the component.
* @slot alerts - A slot for adding `calcite-alert`s to the component.
* @slot content-top - A slot for adding content above the unnamed (default) slot and below the action-bar slot (if populated).
* @slot content-bottom - A slot for adding content below the unnamed (default) slot and above the footer slot (if populated)
* @slot header-actions-start - A slot for adding `calcite-action`s or content to the start side of the component's header.
* @slot header-actions-end - A slot for adding `calcite-action`s or content to the end side of the component's header.
* @slot header-content - A slot for adding custom content to the component's header.
* @slot header-menu-actions - A slot for adding an overflow menu with `calcite-action`s inside a `calcite-dropdown`.
* @slot fab - A slot for adding a `calcite-fab` (floating action button) to perform an action.
* @slot footer - A slot for adding custom content to the component's footer. Should not be used with the `"footer-start"` or `"footer-end"` slots.
* @slot footer-actions - [Deprecated] Use the `"footer"` slot instead. A slot for adding `calcite-button`s to the component's footer.
* @slot footer-end - A slot for adding a trailing footer custom content. Should not be used with the `"footer"` slot.
* @slot footer-start - A slot for adding a leading footer custom content. Should not be used with the `"footer"` slot.
*/
export class FlowItem extends LitElement implements InteractiveComponent, LoadableComponent {
// #region Static Members
static override styles = styles;
// #endregion
// #region Private Properties
private backButtonEl: Action["el"];
private containerEl: Panel["el"];
// #endregion
// #region Public Properties
/** When provided, the method will be called before it is removed from its parent `calcite-flow`. */
@property() beforeBack: () => Promise<void>;
/** Passes a function to run before the component closes. */
@property() beforeClose: () => Promise<void>;
/** When `true`, displays a close button in the trailing side of the component's header. */
@property({ reflect: true }) closable = false;
/** When `true`, the component will be hidden. */
@property({ reflect: true }) closed = false;
/**
* Specifies the direction of the collapse.
*
* @private
*/
@property() collapseDirection: CollapseDirection = "down";
/** When `true`, hides the component's content area. */
@property({ reflect: true }) collapsed = false;
/** When `true`, the component is collapsible. */
@property({ reflect: true }) collapsible = false;
/** A description for the component. */
@property() description: string;
/** When `true`, interaction is prevented and the component is displayed with lower opacity. */
@property({ reflect: true }) disabled = false;
/** The component header text. */
@property() heading: string;
/** Specifies the heading level of the component's `heading` for proper document structure, without affecting visual styling. */
@property({ type: Number, reflect: true }) headingLevel: HeadingLevel;
/** When `true`, a busy indicator is displayed. */
@property({ reflect: true }) loading = false;
/** When `true`, the action menu items in the `header-menu-actions` slot are open. */
@property({ reflect: true }) menuOpen = false;
/** Use this property to override individual strings used by the component. */
@property() messageOverrides?: typeof this.messages._overrides;
/**
* Made into a prop for testing purposes only
*
* @private
*/
messages = useT9n<typeof T9nStrings>();
/**
* Determines the type of positioning to use for the overlaid content.
*
* Using `"absolute"` will work for most cases. The component will be positioned inside of overflowing parent containers and will affect the container's layout.
*
* `"fixed"` should be used to escape an overflowing parent container, or when the reference element's `position` CSS property is `"fixed"`.
*/
@property({ reflect: true }) overlayPositioning: OverlayPositioning = "absolute";
/** Specifies the size of the component. */
@property({ reflect: true }) scale: Scale = "m";
/** When true, flow-item is displayed within a parent flow. */
@property({ reflect: true }) selected = false;
/**
* When `true`, displays a back button in the component's header.
*
* @private
*/
@property() showBackButton = false;
// #endregion
// #region Public Methods
/**
* Scrolls the component's content to a specified set of coordinates.
*
* @example
* myCalciteFlowItem.scrollContentTo({
* left: 0, // Specifies the number of pixels along the X axis to scroll the window or element.
* top: 0, // Specifies the number of pixels along the Y axis to scroll the window or element
* behavior: "auto" // Specifies whether the scrolling should animate smoothly (smooth), or happen instantly in a single jump (auto, the default value).
* });
* @param options - allows specific coordinates to be defined.
* @returns - promise that resolves once the content is scrolled to.
*/
@method()
async scrollContentTo(options?: ScrollToOptions): Promise<void> {
await this.containerEl?.scrollContentTo(options);
}
/**
* Sets focus on the component.
*
* @returns promise.
*/
@method()
async setFocus(): Promise<void> {
await componentFocusable(this);
const { backButtonEl, containerEl } = this;
if (backButtonEl) {
return backButtonEl.setFocus();
} else if (containerEl) {
return containerEl.setFocus();
}
}
// #endregion
// #region Events
/** Fires when the back button is clicked. */
calciteFlowItemBack = createEvent();
/** Fires when the close button is clicked. */
calciteFlowItemClose = createEvent({ cancelable: false });
/** Fires when the content is scrolled. */
calciteFlowItemScroll = createEvent({ cancelable: false });
/** Fires when the collapse button is clicked. */
calciteFlowItemToggle = createEvent({ cancelable: false });
/** @private */
calciteInternalFlowItemChange = createEvent({ cancelable: false });
// #endregion
// #region Lifecycle
async load(): Promise<void> {
setUpLoadableComponent(this);
}
override willUpdate(changes: PropertyValues<this>): void {
/* TODO: [MIGRATION] First time Lit calls willUpdate(), changes will include not just properties provided by the user, but also any default values your component set.
To account for this semantics change, the checks for (this.hasUpdated || value != defaultValue) was added in this method
Please refactor your code to reduce the need for this check.
Docs: https://qawebgis.esri.com/arcgis-components/?path=/docs/lumina-transition-from-stencil--docs#watching-for-property-changes */
if (changes.has("selected") && (this.hasUpdated || this.selected !== false)) {
this.calciteInternalFlowItemChange.emit();
}
}
override updated(): void {
updateHostInteraction(this);
}
loaded(): void {
setComponentLoaded(this);
}
// #endregion
// #region Private Methods
private handleInternalPanelScroll(event: CustomEvent<void>): void {
if (event.target !== this.containerEl) {
return;
}
event.stopPropagation();
this.calciteFlowItemScroll.emit();
}
private handleInternalPanelClose(event: CustomEvent<void>): void {
if (event.target !== this.containerEl) {
return;
}
event.stopPropagation();
this.closed = true;
this.calciteFlowItemClose.emit();
}
private handleInternalPanelToggle(event: CustomEvent<void>): void {
if (event.target !== this.containerEl) {
return;
}
event.stopPropagation();
this.collapsed = (event.target as Panel["el"]).collapsed;
this.calciteFlowItemToggle.emit();
}
private backButtonClick(): void {
this.calciteFlowItemBack.emit();
}
private setBackRef(node: Action["el"]): void {
this.backButtonEl = node;
}
private setContainerRef(node: Panel["el"]): void {
this.containerEl = node;
}
// #endregion
// #region Rendering
private renderBackButton(): JsxNode {
const { el } = this;
const rtl = getElementDir(el) === "rtl";
const { showBackButton, backButtonClick, messages } = this;
const label = messages.back;
const icon = rtl ? ICONS.backRight : ICONS.backLeft;
return showBackButton ? (
<calcite-action
ariaLabel={label}
class={CSS.backButton}
icon={icon}
key="flow-back-button"
onClick={backButtonClick}
ref={this.setBackRef}
scale="s"
slot="header-actions-start"
text={label}
title={label}
/>
) : null;
}
override render(): JsxNode {
const {
collapsed,
collapseDirection,
collapsible,
closable,
closed,
description,
disabled,
heading,
headingLevel,
loading,
menuOpen,
messages,
overlayPositioning,
beforeClose,
} = this;
return (
<InteractiveContainer disabled={disabled}>
<calcite-panel
beforeClose={beforeClose}
closable={closable}
closed={closed}
collapseDirection={collapseDirection}
collapsed={collapsed}
collapsible={collapsible}
description={description}
disabled={disabled}
heading={heading}
headingLevel={headingLevel}
loading={loading}
menuOpen={menuOpen}
messageOverrides={messages}
oncalcitePanelClose={this.handleInternalPanelClose}
oncalcitePanelScroll={this.handleInternalPanelScroll}
oncalcitePanelToggle={this.handleInternalPanelToggle}
overlayPositioning={overlayPositioning}
ref={this.setContainerRef}
scale={this.scale}
>
{this.renderBackButton()}
<slot name={SLOTS.actionBar} slot={PANEL_SLOTS.actionBar} />
<slot name={SLOTS.alerts} slot={PANEL_SLOTS.alerts} />
<slot name={SLOTS.headerActionsStart} slot={PANEL_SLOTS.headerActionsStart} />
<slot name={SLOTS.headerActionsEnd} slot={PANEL_SLOTS.headerActionsEnd} />
<slot name={SLOTS.headerContent} slot={PANEL_SLOTS.headerContent} />
<slot name={SLOTS.headerMenuActions} slot={PANEL_SLOTS.headerMenuActions} />
<slot name={SLOTS.fab} slot={PANEL_SLOTS.fab} />
<slot name={SLOTS.contentTop} slot={PANEL_SLOTS.contentTop} />
<slot name={SLOTS.contentBottom} slot={PANEL_SLOTS.contentBottom} />
<slot name={SLOTS.footerStart} slot={PANEL_SLOTS.footerStart} />
<slot name={SLOTS.footer} slot={PANEL_SLOTS.footer} />
<slot name={SLOTS.footerEnd} slot={PANEL_SLOTS.footerEnd} />
<slot name={SLOTS.footerActions} slot={PANEL_SLOTS.footerActions} />
<slot />
</calcite-panel>
</InteractiveContainer>
);
}
// #endregion
}