8000 MWPW-164227 add checkmark animation on successful form submit by vhargrave · Pull Request #3397 · adobecom/milo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

MWPW-164227 add checkmark animation on successful form submit #3397

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

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions libs/blocks/faas/faas.css
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,25 @@ input[type="checkbox"] + label {
line-height: 1.375em;
}

.dialog-modal .faas-form-confirm-overlay {
position: absolute;
height: 100%;
width: 100%;
background-color: #FBFBFB;
opacity: 0.5;
top: 0;
display: flex;
align-items: center;
justify-content: center;
animation: fade-in-to-opaque .5s ease-in;
}

.dialog-modal .faas-form-confirm-overlay .icon-milo.checkmark-green {
height: 44px;
animation: pulse 2s ease;
}


/* for mobile */
@media (max-width:799.99px) {
.faas-form label,
Expand Down Expand Up @@ -450,3 +469,28 @@ input[type="checkbox"] + label {
width: 100%;
}
}


@keyframes pulse {
0% {
transform: scale(0.7);
}

50% {
transform: scale(1);
}

100% {
transform: scale(0.7);
}
}

@keyframes fade-in-to-opaque {
0% {
opacity: 0;
}

100% {
opacity: 0.5;
}
}
27 changes: 27 additions & 0 deletions libs/blocks/faas/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,32 @@ const beforeSubmitCallback = () => {
};
/* c8 ignore stop */

export const afterSubmitCallback = (e) => {
const config = getConfig();
if (!e.success || !(config.faasCloseModalAfterSubmit === 'on')) return;
const faasForms = document.querySelectorAll('.dialog-modal .faas');
if (faasForms.length !== 1) return;
const faas = faasForms[0];
const dialogModal = faas.closest('.dialog-modal');
if (!dialogModal) return;
const closeBtn = dialogModal.querySelector('.dialog-close');
const faasFormWrapper = dialogModal.querySelector('.faas-form-wrapper');
if (!faasFormWrapper) return;
const overlay = createTag('div', { class: 'faas-form-confirm-overlay' });
const checkIcon = createTag('img', {
class: 'icon-milo checkmark-green',
src: `${config.miloLibs || config.codeRoot}/ui/img/checkmark-green.svg`,
alt: 'checkmark-green',
});
overlay.append(checkIcon);
faasFormWrapper.append(overlay);

checkIcon.addEventListener('animationend', () => {
if (faas.reset) faas.reset();
if (closeBtn) closeBtn.click();
}, { passive: true, once: true });
};

export const makeFaasConfig = (targetState) => {
if (!targetState) {
state = defaultState;
Expand Down Expand Up @@ -293,6 +319,7 @@ export const makeFaasConfig = (targetState) => {
e: {
afterYiiLoadedCallback,
beforeSubmitCallback,
afterSubmitCallback,
},
style_backgroundTheme: targetState.style_backgroundTheme || 'white',
style_layout: targetState.style_layout || 'column1',
Expand Down
3 changes: 3 additions & 0 deletions libs/ui/img/checkmark-green.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions test/blocks/faas/faas.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import { expect } from '@esm-bundle/chai';
import sinon from 'sinon';
import { waitForElement } from '../../helpers/waitfor.js';
import { setConfig } from '../../../libs/utils/utils.js';
import { getModal } from '../../../libs/blocks/modal/modal.js';

const config = {
imsClientId: 'milo',
codeRoot: '/libs',
locales: { '': { ietf: 'en-US', tk: 'hah7vzn.css' } },
faasCloseModalAfterSubmit: 'on',
};
setConfig(config);

const { afterSubmitCallback } = await import('../../../libs/blocks/faas/utils.js');
document.body.innerHTML = await readFile({ path: './mocks/body.html' });
const { default: init } = await import('../../../libs/blocks/faas/faas.js');

Expand All @@ -37,4 +40,31 @@ describe('Faas', () => {
const faas = await waitForElement('.faas-form-wrapper');
expect(faas).to.exist;
});

it('FaaS closes dialog if config set', async () => {
const dialogModal = await getModal(null, { id: 'dialog-modal', closeEvent: 'close', content: a });
await init(a);
await waitForElement('.dialog-modal .faas-form-wrapper');
const closeBtn = dialogModal.querySelector('.dialog-close');
const closeClickSpy = sinon.spy(closeBtn, 'click');
afterSubmitCallback({ success: true });
const overlay = await waitForElement('.faas-form-confirm-overlay');

expect(overlay).to.exist;
expect(overlay.querySelector('img.checkmark-green')).to.exist;

// Simulate animationend
const checkIcon = overlay.querySelector('img.checkmark-green');
const animationEndEvent = new Event('animationend');
const awaitAnimationEnd = new Promise((resolve) => {
checkIcon.addEventListener('animationend', () => {
resolve();
});
});

checkIcon.dispatchEvent(animationEndEvent);

await awaitAnimationEnd;
expect(closeClickSpy.calledOnce).to.be.true;
});
});
Loading
0