Skip to content

Commit 208898e

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

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
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 = ctrl.showSpinner === true;
135+
}
133136
};
134137
}
135138
});

src/card/basic/card.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<div ng-class="$ctrl.showTopBorder === 'true' ? 'card-pf card-pf-accented' : 'card-pf'">
22
<div ng-if="$ctrl.showHeader()" ng-class="$ctrl.shouldShowTitlesSeparator ? 'card-pf-heading' : 'card-pf-heading-no-bottom'">
3-
<div ng-if="$ctrl.showFilterInHeader()" ng-include="'card/basic/card-filter.html'"></div>
3+
<div ng-class="{'hide': $ctrl.showSpinner === true}" 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-show="$ctrl.showSpinner" ng-class="{'spinner spinner-lg': $ctrl.showSpinner}"></div>
1010
<div ng-transclude></div>
1111
</div>
12-
<div ng-if="$ctrl.footer" class="card-pf-footer">
12+
<div ng-class="{'hide': $ctrl.showSpinner === true}" ng-if="$ctrl.footer" class="card-pf-footer">
1313
<div ng-if="$ctrl.showFilterInFooter()" ng-include="'card/basic/card-filter.html'"></div>
1414
<p>
1515
<a ng-if="$ctrl.footer.href" href="{{$ctrl.footer.href}}" ng-class="{'card-pf-link-with-icon':$ctrl.footer.iconClass,'card-pf-link':!$ctrl.footer.iconClass}">

src/card/examples/card-timeframe.js

Lines changed: 11 additions & 1 deletion
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
@@ -45,10 +46,19 @@
4546
footer="footerConfig" filter="filterConfig" style="width: 50%">
4647
Card Contents
4748
</pf-card>
49+
<label class="label-title">Loading State</label>
50+
<pf-card show-spinner="dataLoading" head-title="Card Title" sub-title="Card Subtitle" show-top-border="true" filter="filterConfigHeader" style="width: 50%">
51+
</pf-card>
4852
</div>
4953
</file>
5054
<file name="script.js">
51-
angular.module( 'demo', ['patternfly.charts', 'patternfly.card'] ).controller( 'ChartCtrl', function( $scope ) {
55+
angular.module( 'demo', ['patternfly.charts', 'patternfly.card'] ).controller( 'ChartCtrl', function( $scope, $timeout ) {
56+
57+
$scope.dataLoading = true;
58+
59+
$timeout(function () {
60+
$scope.dataLoading = false;
61+
}, 3000 );
5262
5363
$scope.footerConfig = {
5464
'iconClass' : 'fa fa-flag',

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)