sweetalert2
Version:
A beautiful, responsive, customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes, supported fork of sweetalert
120 lines (112 loc) • 2.65 kB
JavaScript
import { warn, warnOnce } from '../utils/utils'
const defaultParams = {
title: '',
titleText: '',
text: '',
html: '',
footer: '',
type: null,
toast: false,
customClass: '',
target: 'body',
backdrop: true,
animation: true,
heightAuto: true,
allowOutsideClick: true,
allowEscapeKey: true,
allowEnterKey: true,
stopKeydownPropagation: true,
keydownListenerCapture: false,
showConfirmButton: true,
showCancelButton: false,
preConfirm: null,
confirmButtonText: 'OK',
confirmButtonAriaLabel: '',
confirmButtonColor: null,
confirmButtonClass: null,
cancelButtonText: 'Cancel',
cancelButtonAriaLabel: '',
cancelButtonColor: null,
cancelButtonClass: null,
buttonsStyling: true,
reverseButtons: false,
focusConfirm: true,
focusCancel: false,
showCloseButton: false,
closeButtonAriaLabel: 'Close this dialog',
showLoaderOnConfirm: false,
imageUrl: null,
imageWidth: null,
imageHeight: null,
imageAlt: '',
imageClass: null,
timer: null,
width: null,
padding: null,
background: null,
input: null,
inputPlaceholder: '',
inputValue: '',
inputOptions: {},
inputAutoTrim: true,
inputClass: null,
inputAttributes: {},
inputValidator: null,
grow: false,
position: 'center',
progressSteps: [],
currentProgressStep: null,
progressStepsDistance: null,
onBeforeOpen: null,
onAfterClose: null,
onOpen: null,
onClose: null,
useRejections: false,
expectRejections: false
}
export const deprecatedParams = [
'useRejections',
'expectRejections'
]
const toastIncompatibleParams = [
'allowOutsideClick',
'allowEnterKey',
'backdrop',
'focusConfirm',
'focusCancel',
'heightAuto',
'keydownListenerCapture'
]
/**
* Is valid parameter
* @param {String} paramName
*/
export const isValidParameter = (paramName) => {
return defaultParams.hasOwnProperty(paramName) || paramName === 'extraParams'
}
/**
* Is deprecated parameter
* @param {String} paramName
*/
export const isDeprecatedParameter = (paramName) => {
return deprecatedParams.includes(paramName)
}
/**
* Show relevant warnings for given params
*
* @param params
*/
export const showWarningsForParams = (params) => {
for (const param in params) {
if (!isValidParameter(param)) {
warn(`Unknown parameter "${param}"`)
}
if (params.toast && toastIncompatibleParams.includes(param)) {
warn(`The parameter "${param}" is incompatible with toasts`)
}
if (isDeprecatedParameter(param)) {
warnOnce(`The parameter "${param}" is deprecated and will be removed in the next major release.`)
}
}
}
export default defaultParams