Skip to content

Commit 82c92ca

Browse files
author
Amineta Lo
committed
fix(pfCard): Add loading state for pfCard
1 parent db1b797 commit 82c92ca

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

src/card/basic/card.component.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* @param {boolean=} showTopBorder Show/Hide the blue top border. True shows top border, false (default) hides top border
99
* @param {boolean=} showTitlesSeparator Show/Hide the grey line between the title and sub-title.
1010
* True (default) shows the line, false hides the line
11+
* @param {boolean=} showSpinner Show/Hide the spinner for loading state. True shows the spinner, false (default) hides the spinner
1112
* @param {object=} footer footer configuration properties:<br/>
1213
* <ul style='list-style-type: none'>
1314
* <li>.iconClass - (optional) the icon to show on the bottom left of the footer panel
@@ -91,6 +92,7 @@ angular.module('patternfly.card').component('pfCard', {
9192
subTitle: '@?',
9293
showTopBorder: '@?',
9394
showTitlesSeparator: '@?',
95+
showSpinner: '@?',
9496
footer: '=?',
9597
filter: '=?'
9698
},
@@ -104,11 +106,9 @@ angular.module('patternfly.card').component('pfCard', {
104106
ctrl.currentFilter = ctrl.filter.filters[0];
105107
}
106108
}
107-
108109
ctrl.footerCallBackFn = function () {
109110
ctrl.footerCallBackResult = ctrl.footer.callBackFn();
110111
};
111-
112112
ctrl.filterCallBackFn = function (f) {
113113
ctrl.currentFilter = f;
114114
if (ctrl.filter.callBackFn) {
@@ -130,6 +130,9 @@ angular.module('patternfly.card').component('pfCard', {
130130

131131
ctrl.$onInit = function () {
132132
ctrl.shouldShowTitlesSeparator = (!ctrl.showTitlesSeparator || ctrl.showTitlesSeparator === 'true');
133+
if (angular.isUndefined(ctrl.showSpinner)) {
134+
ctrl.showSpinner = 'false';
135+
}
133136
};
134137
}
135138
});

src/card/basic/card.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
<div ng-if="$ctrl.showFilterInHeader()" ng-include="'card/basic/card-filter.html'"></div>
44
<h2 class="card-pf-title">{{$ctrl.headTitle}}</h2>
55
</div>
6-
7-
<span ng-if="$ctrl.subTitle" class="card-pf-subtitle">{{$ctrl.subTitle}}</span>
6+
<span ng-class="{'hide': $ctrl.showSpinner === 'true'}" ng-if="$ctrl.subTitle" class="card-pf-subtitle">{{$ctrl.subTitle}}</span>
87

98
<div class="card-pf-body">
9+
<div ng-class="{'spinner spinner-lg': $ctrl.showSpinner === 'true'}"></div>
1010
<div ng-transclude></div>
1111
</div>
1212
<div ng-if="$ctrl.footer" class="card-pf-footer">

src/card/examples/card-timeframe.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* @param {boolean=} showTopBorder Show/Hide the blue top border. True shows top border, false (default) hides top border
99
* @param {boolean=} showTitlesSeparator Show/Hide the grey line between the title and sub-title.
1010
* True (default) shows the line, false hides the line
11+
* @param {boolean=} showSpinner Show/Hide the spinner for loading state. True shows the spinner, false (default) hides the spinner
1112
* @param {object=} footer footer configuration properties:<br/>
1213
* <ul style='list-style-type: none'>
1314
* <li>.iconClass - (optional) the icon to show on the bottom left of the footer panel
@@ -40,6 +41,9 @@
4041
<pf-card head-title="Card Title" sub-title="Card Subtitle" show-top-border="true" filter="filterConfigHeader" style="width: 50%">
4142
Card Contents
4243
</pf-card>
44+
<label class="label-title">Timeframe filter in header & loading state</label>
45+
<pf-card show-spinner="true" head-title="Card Title" sub-title="Card Subtitle" show-top-border="true" filter="filterConfigHeader" style="width: 50%">
46+
</pf-card>
4347
<label class="label-title">Footer with Link & Timeframe filter</label>
4448
<pf-card head-title="Card Title" sub-title="Card Subtitle" show-top-border="true"
4549
footer="footerConfig" filter="filterConfig" style="width: 50%">

test/card/basic/card.spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,19 @@ describe('Component: pfCard', function() {
8585

8686
});
8787

88+
it("should show and hide the spinner", function() {
89+
90+
// by default, spinner should be hidden
91+
element = compileCard('<pf-card head-title="My card title" sub-title="My card subtitle title" show-top-border="false">Inner content goes here</pf-card>', $scope);
92+
cardClass = angular.element(element).find('.spinner-lg');
93+
expect(cardClass.length).toBe(0);
94+
95+
// setting to true should show spinner
96+
element = compileCard('<pf-card head-title="My card title" show-spinner="true" sub-title="My card subtitle title" show-top-border="false">Inner content goes here</pf-card>', $scope);
97+
cardClass = angular.element(element).find('.spinner-lg');
98+
expect(cardClass.length).toBe(1);
99+
});
100+
88101
it("should hide the action bar footer by default", function() {
89102

90103
// by default, if footer not defined, footer should not be shown

0 commit comments

Comments
 (0)