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(block): add loading status to block header #3158

Merged
merged 5 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/components/calcite-block/calcite-block.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,23 @@ describe("calcite-block", () => {
expect(statusIcon).not.toBeNull();
});

it("displays a loading icon when `loading` is set to true and `open` is set to false", async () => {
const page = await newE2EPage();
await page.setContent(
`<calcite-block status="invalid" loading>
<div class="header-icon" slot=${SLOTS.icon} /></calcite-block>
</calcite-block>`
);

const headerIcon = await page.find("calcite-block >>> .header-icon");
anveshmekala marked this conversation as resolved.
Show resolved Hide resolved
expect(headerIcon).toBeNull();

const statusIcon = await page.find(`calcite-block >>> .${CSS.statusIcon}`);
const loadingIcon = await page.find(`calcite-block >>> .loading`);
anveshmekala marked this conversation as resolved.
Show resolved Hide resolved
expect(statusIcon).not.toBeNull();
expect(loadingIcon).not.toBeNull();
});

it("allows users to slot in actions in a header menu", async () => {
const page = await newE2EPage({
html: html` <calcite-block heading="With header actions" summary="has header actions">
Expand Down
16 changes: 16 additions & 0 deletions src/components/calcite-block/calcite-block.scss
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,22 @@ calcite-handle {
color: theme("colors.danger");
}

.status-icon.loading {
anveshmekala marked this conversation as resolved.
Show resolved Hide resolved
animation: spin 2s linear infinite;
}

@keyframes spin {
0% {
transform: rotate(0deg);
}
50% {
transform: rotate(180deg);
}
100% {
transform: rotate(360deg);
}
}

.toggle-icon {
@apply mr-4
self-center
Expand Down
7 changes: 5 additions & 2 deletions src/components/calcite-block/calcite-block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ export class CalciteBlock {
renderIcon(): VNode[] {
const { el, status } = this;

const icon = ICONS[status] ?? false;
const loadingStatus = this.loading && !this.open;
anveshmekala marked this conversation as resolved.
Show resolved Hide resolved

const icon = loadingStatus ? ICONS.refresh : ICONS[status] ?? false;
anveshmekala marked this conversation as resolved.
Show resolved Hide resolved

const hasIcon = getSlotted(el, SLOTS.icon) || icon;

Expand All @@ -146,7 +148,8 @@ export class CalciteBlock {
class={{
[CSS.statusIcon]: true,
[CSS.valid]: status == "valid",
[CSS.invalid]: status == "invalid"
[CSS.invalid]: status == "invalid",
[CSS.loading]: loadingStatus
}}
icon={icon}
scale="m"
Expand Down
6 changes: 4 additions & 2 deletions src/components/calcite-block/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export const CSS = {
summary: "summary",
controlContainer: "control-container",
valid: "valid",
invalid: "invalid"
invalid: "invalid",
loading: "loading"
};

export const TEXT = {
Expand All @@ -33,7 +34,8 @@ export const ICONS = {
opened: "chevron-up",
closed: "chevron-down",
valid: "check-circle",
invalid: "exclamation-mark-triangle"
invalid: "exclamation-mark-triangle",
refresh: "refresh"
};

export const HEADING_LEVEL = 4;
20 changes: 20 additions & 0 deletions src/demos/calcite-block.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,26 @@
</div>
</div>

<!-- switch collapsible + no controls + loading -->
<div class="parent">
<div class="child right-aligned-text">switch collapsible + no controls + loading</div>

<div class="child">
<calcite-block heading="Heading" summary="summary" loading collapsible>
<calcite-block-section text="input block-section w/ switch" toggle-display="switch">
<calcite-input
icon="form-field"
placeholder="This is an input field... enter something here"
></calcite-input>
</calcite-block-section>

<calcite-block-section text="a block-section w/ button">
<calcite-input icon="form-field" placeholder="This is another input field"></calcite-input>
</calcite-block-section>
</calcite-block>
</div>
</div>

<hr />

<!-- collapsible + controls + icons -->
Expand Down