I have a Datepicker component which contains a Material Datepicker. This component receives a datepickerConfig object describing how the Datepicker should be styled. For example, this object describes what level of shadow to apply, the focus styles, hover styles, etc.
I'm quite new to Material styling so I'm wondering how I can apply these styles dynamically, during runtime?
As an example, for the shadow, I have declared the following variables in my SCSS file:
/* shadow */
$shadow-opacity: rgba(0, 0, 0, 0.3);
$dp-box-shadow-mobile: 0 30px 40px $shadow-opacity;
$dp-box-shadow-desktop-1: 0 3px 6px $shadow-opacity;
$dp-box-shadow-desktop-2: 0 6px 12px $shadow-opacity;
...
// more variables for the different styles
.mat-datepicker-content {
// dynamically apply variables to these styles
// e.g. if datepickerConfig.shadow.level === 2
// then $dp-box-shadow-desktop-2 should be applied
box-shadow: ...;
border: ...;
border-radius: ...;
...
}
During runtime, I need to check what kind of shadow level is in the datepickerConfig object and dynamically apply the correct style to the element.
My Datepicker template:
<mat-form-field appearance="fill">
<mat-label>Choose a date</mat-label>
<input matInput [matDatepicker]="picker">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker (opened)="opened()">
<mat-datepicker-actions>
<button mat-button matDatepickerCancel>CANCEL</button>
<button mat-raised-button matDatepickerApply>OK</button>
</mat-datepicker-actions>
</mat-datepicker>
</mat-form-field>
How can I achieve this, not only for the shadow but for the multiple styles I have to dynamically set? I'm wondering about a clean way to do this with Angular... or can this only be achieved targeting the class with JS?
Thanks.