From d8a21cdf31db9cd2ffedfcfd4f4f131dcebeb27b Mon Sep 17 00:00:00 2001 From: Nelly Haglund Date: Thu, 8 Aug 2019 11:01:16 +0200 Subject: [PATCH 1/2] Add custom display value option in progress bar Fixes #978 --- src/components/progressbar/ProgressBar.js | 8 +++++++- src/showcase/progressbar/ProgressBarDemo.js | 22 +++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/components/progressbar/ProgressBar.js b/src/components/progressbar/ProgressBar.js index c8a95d72a7..8ce8cfec8e 100644 --- a/src/components/progressbar/ProgressBar.js +++ b/src/components/progressbar/ProgressBar.js @@ -18,6 +18,7 @@ export class ProgressBar extends Component { id: PropTypes.string, value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), showValue: PropTypes.bool, + displayValue: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), unit: PropTypes.string, style: PropTypes.object, className: PropTypes.string, @@ -25,7 +26,12 @@ export class ProgressBar extends Component { }; renderLabel() { - if (this.props.showValue && this.props.value) { + if (this.props.showValue && 'displayValue' in this.props) { + return ( +
{this.props.displayValue}
+ ); + } + else if (this.props.showValue && this.props.value) { return (
{this.props.value + this.props.unit}
); diff --git a/src/showcase/progressbar/ProgressBarDemo.js b/src/showcase/progressbar/ProgressBarDemo.js index ebca46b3c4..d824606dad 100644 --- a/src/showcase/progressbar/ProgressBarDemo.js +++ b/src/showcase/progressbar/ProgressBarDemo.js @@ -11,7 +11,10 @@ export class ProgressBarDemo extends Component { super(); this.state = { value1: 0, - value2: 50 + value2: 50, + value3: 40, + totalItems: 5, + completedItems: 2 }; } @@ -58,6 +61,9 @@ export class ProgressBarDemo extends Component {

Static

+

Custom display value

+ +

Indeterminate

@@ -132,6 +138,12 @@ import {ProgressBar} from 'primereact/progressbar'; true Show or hide progress bar value. + + displayValue + string + null + Custom display value + unit string @@ -215,7 +227,10 @@ export class ProgressBarDemo extends Component { super(); this.state = { value1: 0, - value2: 50 + value2: 50, + value3: 40, + totalItems: 5, + completedItems: 2 }; } @@ -262,6 +277,9 @@ export class ProgressBarDemo extends Component {

Static

+

Custom display value

+ +

Indeterminate

From 82026ab58bf78765a67c5140499896539df59f19 Mon Sep 17 00:00:00 2001 From: Nelly Haglund Date: Thu, 8 Aug 2019 14:20:21 +0200 Subject: [PATCH 2/2] Show progress bar value when zero Fixes #973 --- src/components/progressbar/ProgressBar.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/progressbar/ProgressBar.js b/src/components/progressbar/ProgressBar.js index 8ce8cfec8e..13ae75bb74 100644 --- a/src/components/progressbar/ProgressBar.js +++ b/src/components/progressbar/ProgressBar.js @@ -6,7 +6,6 @@ export class ProgressBar extends Component { static defaultProps = { id: null, - value: null, showValue: true, unit: '%', style: null, @@ -31,7 +30,7 @@ export class ProgressBar extends Component {
{this.props.displayValue}
); } - else if (this.props.showValue && this.props.value) { + else if (this.props.showValue && 'value' in this.props) { return (
{this.props.value + this.props.unit}
);