Skip to content

Commit

Permalink
Merge 2b93491 into ca9d197
Browse files Browse the repository at this point in the history
  • Loading branch information
limonte committed Jan 18, 2019
2 parents ca9d197 + 2b93491 commit be0b17a
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/instanceMethods.js
Expand Up @@ -5,4 +5,4 @@ export * from './instanceMethods/enable-disable-elements.js'
export * from './instanceMethods/show-reset-validation-error.js'
export * from './instanceMethods/progress-steps.js'
export * from './instanceMethods/_main.js'

export * from './instanceMethods/update.js'
44 changes: 44 additions & 0 deletions src/instanceMethods/update.js
@@ -0,0 +1,44 @@
import * as dom from '../../src/utils/dom/index'
import { warn } from '../../src/utils/utils'
import sweetAlert from '../sweetalert2'
import privateProps from '../privateProps'

/**
* Updates popup options.
*/
export function update (params) {
const validUpdatableParams = {}

// assign valid params from `params` to `defaults`
Object.keys(params).forEach(param => {
if (sweetAlert.isUpdatableParameter(param)) {
validUpdatableParams[param] = params[param]
} else {
warn(`Invalid parameter to update: "${param}". Updatable params are listed here: TODO (@limonte) add link`)
}
})

const innerParams = privateProps.innerParams.get(this)
const updatedParams = Object.assign({}, innerParams, validUpdatableParams)

// Actions
dom.renderActions(updatedParams)

// Content
dom.renderContent(updatedParams)

// Icon
dom.renderIcon(updatedParams)

// Image
dom.renderImage(updatedParams)

// Progress steps
dom.renderProgressSteps(updatedParams)

// Title
dom.renderTitle(updatedParams)


privateProps.innerParams.set(this, updatedParams)
}
1 change: 1 addition & 0 deletions src/staticMethods.js
Expand Up @@ -7,5 +7,6 @@ export * from './staticMethods/showLoading.js'
export * from './staticMethods/timer.js'
export {
isValidParameter,
isUpdatableParameter,
isDeprecatedParameter
} from './utils/params.js'
33 changes: 33 additions & 0 deletions src/utils/params.js
Expand Up @@ -86,6 +86,39 @@ export const isValidParameter = (paramName) => {
return defaultParams.hasOwnProperty(paramName)
}

/**
* Is valid parameter for Swal.update() method
* @param {String} paramName
*/
export const isUpdatableParameter = (paramName) => {
return [
'title',
'titleText',
'text',
'html',
'type',
'showConfirmButton',
'showCancelButton',
'confirmButtonText',
'confirmButtonAriaLabel',
'confirmButtonColor',
'confirmButtonClass',
'cancelButtonText',
'cancelButtonAriaLabel',
'cancelButtonColor',
'cancelButtonClass',
'buttonsStyling',
'reverseButtons',
'imageUrl',
'imageWidth',
'imageHeigth',
'imageAlt',
'imageClass',
'progressSteps',
'currentProgressStep'
].indexOf(paramName) !== -1
}

/**
* Is deprecated parameter
* @param {String} paramName
Expand Down
18 changes: 18 additions & 0 deletions sweetalert2.d.ts
Expand Up @@ -49,6 +49,17 @@ declare module 'sweetalert2' {
*/
function isVisible(): boolean;

/**
* Updates popup options.
* See the SweetAlertOptions interface for the list of accepted fields and values.
*
* ex.
* swal.update({
* type: 'error'
* })
*/
function update(newSettings: SweetAlertOptions): void;

/**
* Closes the currently open SweetAlert2 modal programmatically.
*
Expand Down Expand Up @@ -280,6 +291,13 @@ declare module 'sweetalert2' {
*/
function isValidParameter(paramName: string): boolean;

/**
* Determines if a given parameter name is valid for Swal.update() method.
*
* @param paramName The parameter to check
*/
function isUpdatableParameter(paramName: string): boolean;

/**
* Normalizes the arguments you can give to Swal.fire() in an object of type SweetAlertOptions.
* ex:
Expand Down

0 comments on commit be0b17a

Please sign in to comment.