Overwrite scss variables doesn't work
See original GitHub issueWhen I try to overwrite the SCSS variables for the sweetalert2.scss file, it doesn’t work.
I have my .scss file in this way:
$swal2-confirm-button-background-color: #a12125; // like red color
@import '~sweetalert2/src/sweetalert2';
I have the module config in this way:
@NgModule({
imports: [
CommonModule,
SweetAlert2Module.forRoot({
buttonsStyling: false //even without this, it doesn't work 😔
})
],
declarations: [PopupComponent],
entryComponents: [PopupComponent]
})
And the component (HTML):
<swal
#swalDialog
title="{{ title }}"
text="{{ text }}"
type="question"
[showCancelButton]="true"
[focusCancel]="true"
(confirm)="confirmButtonClicked()"
>
</swal>
However the Sweetalert is showed without changes in the colors:
I checked Sweetalert2 issues, and they advise that you must import the js file instead of from barrel file, but in ngx-sweetalert2 I don’t know if we can do that (reference: https://github.com/sweetalert2/sweetalert2/issues/1137#issuecomment-400239982).
Thanks!.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
How to overwrite SCSS variables when compiling to CSS
You're setting the color after it has already been used. Basically, what you're trying to do is this: $color: red; .foo { background:...
Read more >A story about overriding SASS variables and the '!default ...
This article describes how to use the !default keyword in SCSS when overriding variables. It will also save you a few hours of...
Read more >Sass & Overriding Bootstrap Variables > Webpack Encore
Listen, it looks like you're trying to load a Sass file. That's super! To do that, enable the feature in Encore and install...
Read more >Overriding variables - best practice [#3260038] | Drupal.org
I tried overwriting a variable ($input-btn-padding-y-sm) in my SUBTHEME/scss/variables.scss file, but it doesn't work. Thanks.
Read more >Sass: @use
For starters, you don't have to explicitly write out the extension of the file you want to load; @use "variables" will automatically load...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello! Good news! v6.0.0 is out and allows you to load an arbitrary build of SweetAlert2, here we’re interested in the unstyled one.
To use a theme, import SweetAlert2 like this:
Here I’m importing SweetAlert2 directly from the original source. If you want to be safer you may want to choose to import from the prebuilt
sweetalert2/dist/sweetalert2.js
bundle instead.Then, import the theme you prefer, for example, in SASS:
Or in your
angular.json
:Actually, it is also possible to override to which file
^sweetalert2$
resolves in your webpack configuration and replace it with the unstyled one. The problem is that today, Angular CLI hides the webpack config behind angular.json. You can have a custom setup that lets you modify it, but I’ll not document that here.And yes indeed, this was a very conscious choice. Back in the days, sweetalert2 did not inject styles by default, and we were regularly getting issues with people forgetting to include the SCSS/CSS, despite it was documented. This ceased since when we started producing a JS build embedding the styles.
If I can find time and motivation to release a new version of ngx-sweetalert2 soonish, I will address this problem by letting you pass the sweetalert2 module yourself in the module configuration, so you’ll be able to pass the unstyled JavaScript instead and use the SCSS sources.