Skip to content

Commit

Permalink
chore: strict types renderPopup.js
Browse files Browse the repository at this point in the history
  • Loading branch information
limonte committed May 30, 2023
1 parent 770ecc9 commit f715a9d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/utils/dom/domUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,18 @@ export const applyNumericalStyle = (elem, property, value) => {
}

/**
* @param {HTMLElement} elem
* @param {HTMLElement | null} elem
* @param {string} display
*/
export const show = (elem, display = 'flex') => {
elem.style.display = display
elem && (elem.style.display = display)
}

/**
* @param {HTMLElement} elem
* @param {HTMLElement | null} elem
*/
export const hide = (elem) => {
elem.style.display = 'none'
elem && (elem.style.display = 'none')
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/utils/dom/renderers/renderPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ import * as dom from '../../dom/index.js'
export const renderPopup = (instance, params) => {
const container = dom.getContainer()
const popup = dom.getPopup()
if (!container || !popup) {
return
}

// Width
// https://github.com/sweetalert2/sweetalert2/issues/2170
if (params.toast) {
dom.applyNumericalStyle(container, 'width', params.width)
popup.style.width = '100%'
popup.insertBefore(dom.getLoader(), dom.getIcon())
const loader = dom.getLoader()
loader && popup.insertBefore(loader, dom.getIcon())
} else {
dom.applyNumericalStyle(popup, 'width', params.width)
}
Expand Down Expand Up @@ -44,7 +48,7 @@ export const renderPopup = (instance, params) => {
*/
const addClasses = (popup, params) => {
// Default Class + showClass when updating Swal.update({})
popup.className = `${swalClasses.popup} ${dom.isVisible(popup) ? params.showClass.popup : ''}`
popup.className = `${swalClasses.popup} ${dom.isVisible(popup) ? params.showClass?.popup : ''}`

if (params.toast) {
dom.addClass([document.documentElement, document.body], swalClasses['toast-shown'])
Expand Down

0 comments on commit f715a9d

Please sign in to comment.