I am currently working on creating a customizable animated progress bar that can be utilized as follows:
<bar [type]="'health'" [percentage]="'80'"></bar>
It is functional up to the point where I need to adjust different percentages. It doesn't have to be completely dynamic, just when the page loads it should fill up the bar to the percentage specified above.
*bar.component.html*
<div class="bar-wrapper">
<div class="bar-label">CSS</div>
<div class="bar-container">
<div class="bar-fill" [style.width.%]="percentage" [@barAnimation]="state"></div> <!-- I've tried various methods to set the CSS, but it remains as defined in the SCSS file. -->
<div class="bar-percentage">{{percentage}}</div>
</div>
</div>
bar.component.ts
@Component({
selector: 'bar',
templateUrl: './bar.component.html',
styleUrls: ['./bar.component.scss'],
animations: [
trigger('barAnimation', [
state('collapsed, void', style({ width: '0%'})),
state('expanded', style({ width: '*'})), // <--- the width needs to be altered for each component.
transition('* => expanded', [animate("4s cubic-bezier(0, -0.75, 0.25, 1)")])
])]
})
export class BarComponent implements OnInit {
public state = "expanded";
@Input() public type: String;
@Input() public percentage: String;
constructor() { }
ngOnInit() {
console.log(this.type + ", " + this.percentage);
}
public startAnimation() {
this.state = "expanded";
}
}
After spending quite some time experimenting with this, I realized using *
might be the solution for adjusting the width property. Manually changing my scss
file makes the bar function correctly. So, I guess the challenge lies in somehow setting the CSS width property.