Skip to content

Commit

Permalink
chore: move reverseButton logic to renderActions()
Browse files Browse the repository at this point in the history
  • Loading branch information
limonte committed Jul 20, 2019
1 parent 6a3c759 commit 10b6790
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 33 deletions.
5 changes: 0 additions & 5 deletions src/instanceMethods/_main.js
Expand Up @@ -85,11 +85,6 @@ const swalPromise = (instance, domCache, innerParams) => {

handlePopupClick(domCache, innerParams, dismissWith)

// Reverse buttons (Confirm on the right side)
if (innerParams.reverseButtons) {
domCache.confirmButton.parentNode.insertBefore(domCache.cancelButton, domCache.confirmButton)
}

addKeydownHandler(instance, globalState, innerParams, dismissWith)

if (innerParams.toast && (innerParams.input || innerParams.footer || innerParams.showCloseButton)) {
Expand Down
60 changes: 32 additions & 28 deletions src/utils/dom/renderers/renderActions.js
@@ -1,34 +1,6 @@
import { swalClasses } from '../../classes.js'
import * as dom from '../../dom/index.js'

function handleButtonsStyling (confirmButton, cancelButton, params) {
dom.addClass([confirmButton, cancelButton], swalClasses.styled)

// Buttons background colors
if (params.confirmButtonColor) {
confirmButton.style.backgroundColor = params.confirmButtonColor
}
if (params.cancelButtonColor) {
cancelButton.style.backgroundColor = params.cancelButtonColor
}

// Loading state
const confirmButtonBackgroundColor = window.getComputedStyle(confirmButton).getPropertyValue('background-color')
confirmButton.style.borderLeftColor = confirmButtonBackgroundColor
confirmButton.style.borderRightColor = confirmButtonBackgroundColor
}

function renderButton (button, buttonType, params) {
dom.toggle(button, params['showC' + buttonType.substring(1) + 'Button'], 'inline-block')
button.innerHTML = params[buttonType + 'ButtonText'] // Set caption text
button.setAttribute('aria-label', params[buttonType + 'ButtonAriaLabel']) // ARIA label

// Add buttons custom classes
button.className = swalClasses[buttonType]
dom.applyCustomClass(button, params.customClass, buttonType + 'Button')
dom.addClass(button, params[buttonType + 'ButtonClass'])
}

export const renderActions = (instance, params) => {
const actions = dom.getActions()
const confirmButton = dom.getConfirmButton()
Expand Down Expand Up @@ -56,4 +28,36 @@ export const renderActions = (instance, params) => {
confirmButton.style.backgroundColor = confirmButton.style.borderLeftColor = confirmButton.style.borderRightColor = ''
cancelButton.style.backgroundColor = cancelButton.style.borderLeftColor = cancelButton.style.borderRightColor = ''
}

if (params.reverseButtons) {
confirmButton.parentNode.insertBefore(cancelButton, confirmButton)
}
}

function handleButtonsStyling (confirmButton, cancelButton, params) {
dom.addClass([confirmButton, cancelButton], swalClasses.styled)

// Buttons background colors
if (params.confirmButtonColor) {
confirmButton.style.backgroundColor = params.confirmButtonColor
}
if (params.cancelButtonColor) {
cancelButton.style.backgroundColor = params.cancelButtonColor
}

// Loading state
const confirmButtonBackgroundColor = window.getComputedStyle(confirmButton).getPropertyValue('background-color')
confirmButton.style.borderLeftColor = confirmButtonBackgroundColor
confirmButton.style.borderRightColor = confirmButtonBackgroundColor
}

function renderButton (button, buttonType, params) {
dom.toggle(button, params['showC' + buttonType.substring(1) + 'Button'], 'inline-block')
button.innerHTML = params[buttonType + 'ButtonText'] // Set caption text
button.setAttribute('aria-label', params[buttonType + 'ButtonAriaLabel']) // ARIA label

// Add buttons custom classes
button.className = swalClasses[buttonType]
dom.applyCustomClass(button, params.customClass, buttonType + 'Button')
dom.addClass(button, params[buttonType + 'ButtonClass'])
}

0 comments on commit 10b6790

Please sign in to comment.