I currently have two components in my project. The first component is responsible for setting colors which are then used in the second component. However, I find it tedious to set each color individually and am looking for a more efficient solution. I am considering using an array to store all the colors instead of adding them one by one.
Below is the code snippet:
Component 1 HTML
<div [ngClass]="{'brand-error-image-banner': data?.redImageBanner, 'graphite-grey-image-banner': data?.greyImageBanner, 'graphite-orange-image-banner': data?.orangeDarkImageBanner}</div>
Component 1 SCSS
.brand-error-image-banner {
background-color: $brand-error;
height: 164px;
margin: -24px -24px 24px;
}
.graphite-grey-image-banner {
background-color: $graphite-3;
height: 164px;
margin: -24px -24px 24px;
}
.graphite-orange-image-banner {
background-color: $brand-orange-light;
height: 164px;
margin: -24px -24px 24px;
}
Component 1 Modal
export class Component1{
public redImageBanner: boolean = false;
public greyImageBanner: boolean = false;
public orangeDarkImageBanner: boolean = false;
constructor(args) {
this.redImageBanner = args.redImageBanner;
this.greyImageBanner = args.greyImageBanner;
this.orangeDarkImageBanner = args.orangeDarkImageBanner;
}
}
Component 2 HTML
<component1 [data]="{orangeDarkImageBanner: false, redImageBanner: true, greyImageBanner: false}"></component1>
In essence, I want to avoid specifying each color separately as shown in the example above. Is there a way to make it more generic so that I can simply add a color like this?
<component1 [data]="{color: graphite-orange-image-banner}"></component1>