Skip to content
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): split up custom flow item interfaces #7666

Merged
merged 3 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 45 additions & 9 deletions packages/calcite-components/conventions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,51 @@ For such cases, the following pattern will enable developers to create custom ch
#### Parent component

- Must provide a `customItemSelectors` property to allow querying for custom elements in addition to their expected children.
- 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.
**`parent/interfaces.d.ts`**
```ts
type ChildComponentLike = Pick<HTMLCalciteChildElement, "required" | "props" | "from" | "parent"> & HTMLElement;
```
**`parent/parent.tsx`**
```tsx
@Prop() selectedItem: HTMLChildComponentElement | ChildComponentLike;
```
- 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.

**Example**

**`parent/interfaces.d.ts`**

```ts
type ChildComponentLike = Pick<Components.CalciteChild, "required" | "props" | "from" | "parent">;
type ChildComponentLikeElement = ChilcComponentLike & HTMLElement;
```

**`parent/parent.tsx`**

```tsx
@Prop() selectedItem: HTMLChildComponentElement | ChildComponentLikeElement;
```

**`custom-item/custom-item.tsx`**

```tsx
export class CustomItem implements ChildComponentLike {
private childComponentEl: HTMLChildComponentLikeElement;

@Prop() required: boolean;
@Prop() props: string;
@Prop() from: number;

@Method() async parent(): Promise<string> {
await this.childComponentEl.parent();
}

render(): VNode {
return (
<Host>
<child-component
required={this.required}
props={this.props}
from={this.from}
ref={(el) => (this.childComponentEl = el)}
/>
</Host>
);
}
}
```

#### Custom child component

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export type FlowDirection = "advancing" | "retreating";

export type FlowItemLikeElement = Pick<
HTMLCalciteFlowItemElement,
"beforeBack" | "menuOpen" | "setFocus" | "showBackButton"
> &
HTMLElement;
export type FlowItemLike = Pick<HTMLCalciteFlowItemElement, "beforeBack" | "menuOpen" | "setFocus" | "showBackButton">;

export type FlowItemLikeElement = FlowItemLike & HTMLElement;