Skip to content

Commit 47da4a1

Browse files
feat(ui5-card): add properties loading and loadingDelay (#9558)
Fixes: #9437
1 parent a6ca403 commit 47da4a1

File tree

5 files changed

+74
-9
lines changed

5 files changed

+74
-9
lines changed

packages/main/src/Card.hbs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,21 @@
33
role="region"
44
aria-label="{{_getAriaLabel}}"
55
part="root">
6-
{{#if _hasHeader}}
7-
<div class="ui5-card-header-root">
8-
<slot name="header"></slot>
6+
<ui5-busy-indicator
7+
id="{{_id}}-busyIndicator"
8+
delay="{{loadingDelay}}"
9+
?active="{{loading}}"
10+
class="ui5-card-busy-indicator"
11+
>
12+
<div class="ui5-card-inner">
13+
{{#if _hasHeader}}
14+
<div class="ui5-card-header-root">
15+
<slot name="header"></slot>
16+
</div>
17+
{{/if}}
18+
<div role="group" aria-label="{{_ariaCardContentLabel}}" part="content">
19+
<slot></slot>
20+
</div>
921
</div>
10-
{{/if}}
11-
<div role="group" aria-label="{{_ariaCardContentLabel}}" part="content">
12-
<slot></slot>
13-
</div>
22+
</ui5-busy-indicator>
1423
</div>

packages/main/src/Card.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import type I18nBundle from "@ui5/webcomponents-base/dist/i18nBundle.js";
88
import { getEffectiveAriaLabelText } from "@ui5/webcomponents-base/dist/util/AriaLabelHelper.js";
99
import CardTemplate from "./generated/templates/CardTemplate.lit.js";
1010
import Icon from "./Icon.js";
11+
import BusyIndicator from "./BusyIndicator.js";
12+
1113
import {
1214
ARIA_ROLEDESCRIPTION_CARD,
1315
ARIA_LABEL_CARD_CONTENT,
@@ -45,7 +47,7 @@ import cardCss from "./generated/themes/Card.css.js";
4547
renderer: litRender,
4648
template: CardTemplate,
4749
styles: cardCss,
48-
dependencies: [Icon],
50+
dependencies: [Icon, BusyIndicator],
4951
})
5052
class Card extends UI5Element {
5153
/**
@@ -85,6 +87,24 @@ class Card extends UI5Element {
8587
@slot({ type: HTMLElement, invalidateOnChildChange: true })
8688
header!: Array<CardHeader>;
8789

90+
/**
91+
* Defines if a loading indicator would be displayed over the card.
92+
* @default false
93+
* @public
94+
* @since 2.1.0
95+
*/
96+
@property({ type: Boolean })
97+
loading = false;
98+
99+
/**
100+
* Defines the delay in milliseconds, after which the loading indicator will show up for this card.
101+
* @default 1000
102+
* @public
103+
* @since 2.1.0
104+
*/
105+
@property({ type: Number })
106+
loadingDelay = 1000;
107+
88108
static i18nBundle: I18nBundle;
89109

90110
get classes() {

packages/main/src/themes/Card.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@
1919
box-sizing: border-box;
2020
}
2121

22+
.ui5-card-busy-indicator {
23+
width: 100%;
24+
height: 100%;
25+
border-radius: var(--_ui5_card_border-radius);
26+
}
27+
28+
.ui5-card-inner {
29+
width: 100%;
30+
height: 100%;
31+
}
32+
2233
.ui5-card-root.ui5-card--interactive:hover {
2334
box-shadow: var(--_ui5_card_hover_box_shadow);
2435
}

packages/main/test/pages/Card.html

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,30 @@
331331
<div id="cont" class="myContent">I am the content</div>
332332
</ui5-card>
333333

334+
<ui5-card
335+
id="loadingCard"
336+
loading
337+
loading-delay="500"
338+
accessible-name="My Card">
339+
<ui5-card-header
340+
id="loadingCardHeader"
341+
slot="header"
342+
interactive
343+
title-text="Interactive Header">
344+
<ui5-button slot="action">Header Button</ui5-button>
345+
</ui5-card-header>
346+
<div class="myContent">
347+
<ui5-button>Content Button</ui5-button>
348+
</div>
349+
</ui5-card>
350+
334351
<script>
335352
function onClick(event) {
336353
console.log(event);
337354
field.value = `${parseInt(field.value) + 1}`;
338355
}
339356

340-
[cardHeader, cardHeader2, cardHeader3].forEach(function (el) {
357+
[cardHeader, cardHeader2, cardHeader3, loadingCardHeader].forEach(function (el) {
341358
el.addEventListener("ui5-click", onClick);
342359
});
343360
</script>

packages/main/test/specs/Card.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ describe("Card general interaction", () => {
9696
await cardHeaderTitle.setAttribute("aria-level", 4);
9797
assert.strictEqual(await cardHeader.shadow$(".ui5-card-header .ui5-card-header-title").getAttribute("aria-level"), "4");
9898
});
99+
100+
it("tests loading", async () => {
101+
const card = await browser.$("#loadingCard");
102+
const busyIndicator = card.shadow$("ui5-busy-indicator");
103+
104+
assert.ok(await busyIndicator.hasAttribute("active"), "The busy indicator is active.");
105+
assert.strictEqual(await busyIndicator.getAttribute("delay"), "500", "The delay is correct.");
106+
});
99107
});
100108

101109
describe("CardHeader", () => {

0 commit comments

Comments
 (0)