How to change ProgressBar color

UI Components for React
Post Reply
RyanKwan
Posts: 10
Joined: 17 Jan 2017, 11:20

06 May 2018, 08:29

Hi,

May I know is it possible to dynamic change the progress bar color? e.g. show the progress bar color as green if the progress is below 70%, show yellow if it's above 70%, and show red if it reaches 100%.
I tried to play with the style attribute, but seems it just affect the outer <div> which failed to modify the color in the inner div which is the actual progress bar style.

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

10 May 2018, 13:26

Please try;

Code: Select all

//CSS
.greenBar.ui-progressbar .ui-progressbar-value {
   background: green;
}

.yellowBar.ui-progressbar .ui-progressbar-value {
   background: yellow;
}

.redBar.ui-progressbar .ui-progressbar-value {
   background: red;
}

//js
render() {
        let progressBarClass = classNames({
            'greenBar': this.state.value < 70,
            'yellowBar': this.state.value >= 70 && this.state.value !== 100,
            'redBar': this.state.value === 100
        });
        
        return (
            <div>
               ...
               <ProgressBar value={this.state.value} className={progressBarClass}></ProgressBar>
               ...
            </div>
        );

Post Reply

Return to “PrimeReact”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 4 guests