johannesjo / angular-material-css-vars

Little library to use css variables with @angular/material
https://johannesjo.github.io/angular-material-css-vars/
MIT License
194 stars 32 forks source link

Is it possible to disable "isDarkTheme" specific css? #136

Closed jaetea closed 1 year ago

jaetea commented 1 year ago

On version 3.0 and setting $mat-css-dark-theme-selector to false just generates "false" as a string.

// optional
$mat-css-dark-theme-selector: false;
$mat-css-light-theme-selector: '.isLightTheme';

// init theme
@include init-material-css-vars() {

    @include app-theme($mat-css-theme);
    // If your app has any theme mixins, call them here.
    // $mat-css-theme gets set to an appropriate value before this content is called.
    // @include your-custom-component-theme($mat-css-theme);
};
false .mat-slide-toggle.mat-warn.mat-checked .mat-slide-toggle-thumb {
  background-color: rgba(var(--palette-warn-500), 1);
}
false .mat-slide-toggle.mat-warn.mat-checked .mat-slide-toggle-bar {
  background-color: rgba(var(--palette-warn-500), 0.54);
}
false .mat-slide-toggle.mat-warn.mat-checked .mat-ripple-element {
  background-color: rgba(var(--palette-warn-500), 1);
}

I tried commenting it out in the variables file and get this error.

Error: Undefined variable. ╷ 71 │ $dark-theme-selector: $mat-css-dark-theme-selector, │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ╵

Is there a way to NOT generate the additional classes for dark theme?

json-derulo commented 1 year ago

To my knowledge this isn't and has never been possible. What is the motivation behind this, do you want to optimize your bundle size? Or is there anything else?

In general this sounds like a reasonable feature. In case the dark theme styles are skipped, calls to the setDarkTheme() method should result in an error.

jaetea commented 1 year ago

We are just looking to reduce the file size and optimize the bundle size.

json-derulo commented 1 year ago

I had a deeper look. Actually most of the dark theme code is being skipped with your approach already. There were just some minor oversights, like you pointed out, with only little impact to the bundle size. Anyways, I will fix this soon for v5.