-
Notifications
You must be signed in to change notification settings - Fork 614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace JavaScript alert/confirmations with sweetalert2 #1035
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good to me.
@sacr3dc0w overall it looks good to me. my concern is the file size: i see nearly 50k for this. however, it turns out sweetalert2's package main is pointing to can you please add another alias in
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall LGTM - just need to update the webpack resolve to use the minified version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @sacr3dc0w, nice work. Thank you for the screenshots. The alert does look better! I just have few minor comments I want you to look at 😄
@@ -57,7 +58,10 @@ export default function (urlContext) { | |||
const productsToCompare = $this.find('input[name="products\[\]"]:checked'); | |||
|
|||
if (productsToCompare.length <= 1) { | |||
alert('You must select at least two products to compare'); | |||
swal({ | |||
text: 'You must select at least two products to compare', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an existing problem. So you probably don't need to fix it in this PR. Just pointing it out that the warning message needs to come from the language file, not hard-coded in here.
assets/js/theme/cart.js
Outdated
const delta = new Date() - openTime; | ||
|
||
// Delta workaround for Chrome's "prevent popup" | ||
if (!result && delta > 10) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A question. Do we need this hack anymore? It looks like sweetalert2
is just a regular modal. Unlike window.confirm
, the browser might not interfer.
$swal-font-headingsColor: stencilColor("color-textHeading"); | ||
|
||
// Modal stylings | ||
$swal-modal-bgColor: stencilColor("navUser-dropdown-backgroundColor") !important; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably introduce a new variable instead of using navUser-dropdown-backgroundColor
? It looks like navUser-dropdown-backgroundColor
is intended to used for navigation dropdowns only.
$swal-button-wrapperMargin: 25px 0 0; | ||
|
||
// Confirm button | ||
$swal-button-bgColor: stencilColor("button--primary-backgroundColor") !important; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you really need to use !important
here? If the styles are cascaded properly, you shouldn't need to increase their specificity.
@@ -129,7 +130,10 @@ export default function (stateElement, context = {}, options, callback) { | |||
|
|||
utils.api.country.getByName(countryName, (err, response) => { | |||
if (err) { | |||
alert(context.state_error); | |||
swal({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to only execute the callback after dismissing the alert? I think sweetalert2
is non-blocking, unlike alert
, which stops the execution the script until it is dismissed.
This is nice but I have been thinking if it makes sense to move this functionality to https://github.com/bigcommerce/stencil-utils so we can build a wrapper around it. It will make it much more easier to change the underlying library in the future & also to upgrade the lib in the future to propagate the changes across the board by just updating the package version. |
i like @junedkazi 's idea of abstracting it as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@junedkazi good idea! I'm not against moving the alert
function in stencil-utils
which internally invokes sweetalert2
, if you think it will be useful for all theme developers. I'm also fine leaving it here for now and moving it out later when there's a need.
Anyway, when you create the facade, make sure it is well encapsulated so that it doesn't leak implementation details (i.e.: any references to sweetalert2
cannot be exposed, including CSS classes).
PS: A question. It seems stencil-utils
doesn't really have a clear responsibility. Is it just a general purpose package?
config.json
Outdated
@@ -177,6 +177,7 @@ | |||
"checkRadio-color": "#4f4f4f", | |||
"checkRadio-backgroundColor": "#ffffff", | |||
"checkRadio-borderColor": "#dfdfdf", | |||
"sweetAlert-backgroundColor": "#ffffff", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use a more generic config name? This name ties to a specific vendor library. Maybe just alert-backgroundColor
.
// ----------------------------------------------------------------------------- | ||
|
||
// Font color, size, family | ||
$swal-font-body: stencilFontFamily("body-font"), Arial, Helvetica, sans-serif; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these variables can probably be generalised as well. i.e.: $alert-font-body
assets/js/theme/account.js
Outdated
@@ -105,7 +107,10 @@ export default class Account extends PageManager { | |||
|
|||
if (!submitForm) { | |||
event.preventDefault(); | |||
alert('Please select one or more items to reorder.'); | |||
swal({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a intention-revealing function name? swal
doesn't communicate anything.
@@ -5,6 +5,7 @@ import Wishlist from './wishlist'; | |||
import validation from './common/form-validation'; | |||
import stateCountry from './common/state-country'; | |||
import { classifyForm, Validators, insertStateHiddenField } from './common/form-utils'; | |||
import swal from 'sweetalert2'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may choose to not import the vendor library directly. Instead, create a facade so that it's easier to change its implementation later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing the changes 👍. I'm happy with the current state. And do refactoring later.
@sacr3dc0w - could you please update the changelog to include an entry for these changes in the drafts section - i'll merge it in after that |
this link is outdated, here's the correct one https://sweetalert2.github.io/ |
What?
I’ve used this for a few projects and wanted to make it accessible to the community. I’ve cleaned it up and done my best to make it conform to Cornerstone stylings but maybe some additional eyes can fill in any missing blanks. SweetAlert2 is described by their webpage as:
Documentation
The project’s webpage goes into deeper detail on it’s usage.
Screen Recordings
Example
Remove item from cart, desktop (all theme variations)
Remove item from cart, tablet (all theme variations)
Remove item from cart, mobile (all theme variations)
Compare page error
Compare product error on category page