Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

Commit

Permalink
feat(flow-item): added slot that hydrates header-leading-content of c…
Browse files Browse the repository at this point in the history
…alcite-panel

* preliminary addition

* Updated slot name. (#958)

* Added test for leading-actions slot. (#958)

* added new slot example to demo

* added overloaded slot example

* Moved class to CSS const. (#958)

* Added e2e for empty leading-actions. (#958)

* Added additional e2e test. (#958)
  • Loading branch information
asangma authored May 12, 2020
1 parent 713b8b9 commit e894d55
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
25 changes: 25 additions & 0 deletions src/components/calcite-flow-item/calcite-flow-item.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,31 @@ describe("calcite-flow-item", () => {
expect(singleActionContainer).toBeNull();
});

it("should not render leading actions container when there are no leading actions", async () => {
const page = await newE2EPage();

await page.setContent("<calcite-flow-item></calcite-flow-item>");

const actionsContainer = await page.find(`calcite-flow-item >>> .${CSS.leadingActions}`);

expect(actionsContainer).toBeNull();
});

it("should render leading actions container when there are leading actions", async () => {
const page = await newE2EPage();

const pageContent = `
<calcite-flow-item>
<calcite-action slot="${SLOTS.leadingActions}" text="hello"></calcite-action>
</calcite-flow-item>`;

await page.setContent(pageContent);

const actionsContainer = await page.find(`calcite-flow-item >>> .${CSS.leadingActions}`);

expect(actionsContainer).not.toBeNull();
});

it("should not show menu button when actions are inside blacklisted component", async () => {
const page = await newE2EPage();

Expand Down
4 changes: 4 additions & 0 deletions src/components/calcite-flow-item/calcite-flow-item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ calcite-panel {
height: 100%;
}

.leading-actions {
display: flex;
}

.header-content {
display: block;
.heading {
Expand Down
10 changes: 10 additions & 0 deletions src/components/calcite-flow-item/calcite-flow-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,15 @@ export class CalciteFlowItem {
);
}

renderHeaderLeadingContent(): VNode {
const hasLeadingActions = getSlotted(this.el, SLOTS.leadingActions);
return hasLeadingActions ? (
<div slot={PANEL_SLOTS.headerLeadingContent} class={CSS.leadingActions}>
<slot name={SLOTS.leadingActions}></slot>
</div>
) : null;
}

renderHeaderActions(): VNode {
const menuActions = getSlotted(this.el, SLOTS.menuActions, { all: true });

Expand Down Expand Up @@ -368,6 +377,7 @@ export class CalciteFlowItem {
dir={dir}
>
{this.renderBackButton(dir === "rtl")}
{this.renderHeaderLeadingContent()}
{this.renderHeader()}
{this.renderHeaderActions()}
<slot />
Expand Down
2 changes: 2 additions & 0 deletions src/components/calcite-flow-item/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const CSS = {
backButton: "back-button",
footerActions: "footer-actions",
headerActions: "header-actions",
leadingActions: "leading-actions",
singleActionContainer: "single-action-container",
menuContainer: "menu-container",
menuButton: "menu-button",
Expand All @@ -16,6 +17,7 @@ export const CSS = {
};

export const SLOTS = {
leadingActions: "leading-actions",
menuActions: "menu-actions",
fab: "fab",
footerActions: "footer-actions"
Expand Down
19 changes: 17 additions & 2 deletions src/demos/flow/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,19 @@ <h1>calcite-flow</h1>
<h2>Basic</h2>
<calcite-flow>
<calcite-flow-item heading="Item One">
<calcite-action icon="caret-down" slot="leading-actions"></calcite-action>
<button slot="menu-actions">Reset</button>
<button slot="menu-actions">Rename</button>
<img src="https://via.placeholder.com/300x200" alt="placeholder" />
</calcite-flow-item>
<calcite-flow-item heading="Item Two">
<img src="http://www.fillmurray.com/100/100" height="40" slot="leading-actions" />
<button slot="menu-actions">Reset</button>
<button slot="menu-actions">Rename</button>
<img src="https://via.placeholder.com/400x300" alt="placeholder" />
<calcite-fab slot="fab"></calcite-fab>
</calcite-flow-item>
<calcite-flow-item heading="Item Three">
<button slot="menu-actions">Reset</button>
<button slot="menu-actions">Rename</button>
<img src="https://via.placeholder.com/400x300" alt="placeholder" />
Expand All @@ -47,16 +55,23 @@ <h2>Flow RTL</h2>
<h3>Basic</h3>
<calcite-flow>
<calcite-flow-item heading="Item One">
<calcite-action icon="caret-down" slot="leading-actions"></calcite-action>
<button slot="menu-actions">Reset</button>
<button slot="menu-actions">Rename</button>

<img src="https://via.placeholder.com/300x200" alt="placeholder" />
</calcite-flow-item>
<calcite-flow-item heading="Item Two">
<img src="http://www.fillmurray.com/100/100" height="40" slot="leading-actions" />
<button slot="menu-actions">Reset</button>
<button slot="menu-actions">Rename</button>
<img src="https://via.placeholder.com/400x300" alt="placeholder" />
<calcite-fab slot="fab"></calcite-fab>
</calcite-flow-item>
<calcite-flow-item heading="Item Three">
<button slot="menu-actions">Reset</button>
<button slot="menu-actions">Rename</button>

<img src="https://via.placeholder.com/400x300" alt="placeholder" />
<calcite-fab slot="fab"></calcite-fab>
</calcite-flow-item>
</calcite-flow>

Expand Down

0 comments on commit e894d55

Please sign in to comment.