-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(flow): add support for custom flow-item elements #7608
Changes from all commits
97ea77d
3e2d8f8
d712724
e87200c
5587256
4651af9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { Component, Element, h, Listen, Method, State, VNode } from "@stencil/core"; | ||
import { Component, Element, h, Listen, Method, Prop, State, VNode } from "@stencil/core"; | ||
import { createObserver } from "../../utils/observers"; | ||
import { FlowDirection } from "./interfaces"; | ||
import { FlowDirection, FlowItemLikeElement } from "./interfaces"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like your name suggestion better, but the interface only requires the props expected by the parent and not all from |
||
import { CSS } from "./resources"; | ||
import { | ||
componentFocusable, | ||
|
@@ -28,7 +28,7 @@ export class Flow implements LoadableComponent { | |
* Removes the currently active `calcite-flow-item`. | ||
*/ | ||
@Method() | ||
async back(): Promise<HTMLCalciteFlowItemElement> { | ||
async back(): Promise<HTMLCalciteFlowItemElement | FlowItemLikeElement> { | ||
const { items } = this; | ||
|
||
const lastItem = items[items.length - 1]; | ||
|
@@ -61,6 +61,19 @@ export class Flow implements LoadableComponent { | |
return activeItem?.setFocus(); | ||
} | ||
|
||
// -------------------------------------------------------------------------- | ||
// | ||
// Public Properties | ||
// | ||
// -------------------------------------------------------------------------- | ||
|
||
/** | ||
* This property enables the component to consider other custom elements implementing flow-item's interface. | ||
* | ||
* @internal | ||
*/ | ||
@Prop() customItemSelectors: string; | ||
|
||
// -------------------------------------------------------------------------- | ||
// | ||
// Private Properties | ||
|
@@ -73,7 +86,7 @@ export class Flow implements LoadableComponent { | |
|
||
@State() itemCount = 0; | ||
|
||
@State() items: HTMLCalciteFlowItemElement[] = []; | ||
@State() items: FlowItemLikeElement[] = []; | ||
|
||
itemMutationObserver = createObserver("mutation", () => this.updateFlowProps()); | ||
|
||
|
@@ -124,11 +137,13 @@ export class Flow implements LoadableComponent { | |
}; | ||
|
||
updateFlowProps = (): void => { | ||
const { el, items } = this; | ||
const { customItemSelectors, el, items } = this; | ||
|
||
const newItems: HTMLCalciteFlowItemElement[] = Array.from( | ||
el.querySelectorAll("calcite-flow-item") | ||
).filter((flowItem) => flowItem.closest("calcite-flow") === el) as HTMLCalciteFlowItemElement[]; | ||
const newItems = Array.from<FlowItemLikeElement>( | ||
el.querySelectorAll( | ||
`calcite-flow-item${customItemSelectors ? `,${customItemSelectors}` : ""}` | ||
) | ||
).filter((flowItem) => flowItem.closest("calcite-flow") === el); | ||
driskull marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const oldItemCount = items.length; | ||
const newItemCount = newItems.length; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
export type FlowDirection = "advancing" | "retreating"; | ||
|
||
export type FlowItemLikeElement = Pick< | ||
HTMLCalciteFlowItemElement, | ||
"beforeBack" | "menuOpen" | "setFocus" | "showBackButton" | ||
> & | ||
HTMLElement; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plurality of
customItemSelectors
threw me off a little because its a single string. Would it make more sense ascustomItemSelector
? I guess technically it can be a single or multiple selectors but its a single string. 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess its fine since its referred to as
selectors
here: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorJust ignore my comment then:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I feel the same way about the name. 😅