Skip to content

Commit 6c22e7c

Browse files
authored
feat(flow): split up custom flow item interfaces (#7666)
**Related Issue:** #7608 ## Summary Splits up interfaces for custom flow item class and elements. This also updates the conventions doc with info on interface usage.
1 parent 4b4c43c commit 6c22e7c

File tree

2 files changed

+48
-14
lines changed

2 files changed

+48
-14
lines changed

packages/calcite-components/conventions/README.md

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -419,15 +419,51 @@ For such cases, the following pattern will enable developers to create custom ch
419419
#### Parent component
420420
421421
- Must provide a `customItemSelectors` property to allow querying for custom elements in addition to their expected children.
422-
- An interface for `HTML<ChildComponentItem>Element` must be created in the parent's `interfaces.d.ts` file, where the necessary child APIs must be extracted.
423-
**`parent/interfaces.d.ts`**
424-
```ts
425-
type ChildComponentLike = Pick<HTMLCalciteChildElement, "required" | "props" | "from" | "parent"> & HTMLElement;
426-
```
427-
**`parent/parent.tsx`**
428-
```tsx
429-
@Prop() selectedItem: HTMLChildComponentElement | ChildComponentLike;
430-
```
422+
- An interface for the class (used by custom item classes) and element (used by parent component APIs) must be created in the parent's `interfaces.d.ts` file, where the necessary child APIs must be extracted.
423+
424+
**Example**
425+
426+
**`parent/interfaces.d.ts`**
427+
428+
```ts
429+
type ChildComponentLike = Pick<Components.CalciteChild, "required" | "props" | "from" | "parent">;
430+
type ChildComponentLikeElement = ChilcComponentLike & HTMLElement;
431+
```
432+
433+
**`parent/parent.tsx`**
434+
435+
```tsx
436+
@Prop() selectedItem: HTMLChildComponentElement | ChildComponentLikeElement;
437+
```
438+
439+
**`custom-item/custom-item.tsx`**
440+
441+
```tsx
442+
export class CustomItem implements ChildComponentLike {
443+
private childComponentEl: HTMLChildComponentLikeElement;
444+
445+
@Prop() required: boolean;
446+
@Prop() props: string;
447+
@Prop() from: number;
448+
449+
@Method() async parent(): Promise<string> {
450+
await this.childComponentEl.parent();
451+
}
452+
453+
render(): VNode {
454+
return (
455+
<Host>
456+
<child-component
457+
required={this.required}
458+
props={this.props}
459+
from={this.from}
460+
ref={(el) => (this.childComponentEl = el)}
461+
/>
462+
</Host>
463+
);
464+
}
465+
}
466+
```
431467
432468
#### Custom child component
433469
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
export type FlowDirection = "advancing" | "retreating";
22

3-
export type FlowItemLikeElement = Pick<
4-
HTMLCalciteFlowItemElement,
5-
"beforeBack" | "menuOpen" | "setFocus" | "showBackButton"
6-
> &
7-
HTMLElement;
3+
export type FlowItemLike = Pick<HTMLCalciteFlowItemElement, "beforeBack" | "menuOpen" | "setFocus" | "showBackButton">;
4+
5+
export type FlowItemLikeElement = FlowItemLike & HTMLElement;

0 commit comments

Comments
 (0)