Enable captcha and refactor popup

astro
Kamran Ahmed 2 years ago
parent 577613132b
commit d7b201c7f7
  1. 1
      package.json
  2. 2
      src/components/Captcha/captcha.js
  3. 2
      src/components/DownloadPopup.astro
  4. 8
      src/components/Popup/Popup.astro
  5. 120
      src/components/Popup/popup.js
  6. 4
      src/components/RoadmapHeader.astro
  7. 2
      src/components/SubscribePopup.astro
  8. 2
      src/pages/signup.astro

@ -5,6 +5,7 @@
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "astro dev", "dev": "astro dev",
"dev:verbose": "astro dev --verbose",
"start": "astro dev", "start": "astro dev",
"build": "astro build", "build": "astro build",
"preview": "astro preview", "preview": "astro preview",

@ -25,7 +25,7 @@ class Captcha {
target.querySelector('.recaptcha-response').value = captchaResponse; target.querySelector('.recaptcha-response').value = captchaResponse;
} }
target.closest('.modal').classList.add('hidden'); target.closest('.popup').classList.add('hidden');
return true; return true;
} }

@ -25,7 +25,7 @@ import Captcha from './Captcha/Captcha.astro';
placeholder='Enter your Email' placeholder='Enter your Email'
/> />
<!-- <Captcha /> --> <Captcha />
<input type='hidden' name='list' value='tTqz1w7nexY3cWDpLnI88Q' /> <input type='hidden' name='list' value='tTqz1w7nexY3cWDpLnI88Q' />
<input type='hidden' name='subform' value='yes' /> <input type='hidden' name='subform' value='yes' />

@ -15,17 +15,17 @@ const { id, title, subtitle } = Astro.props;
<div <div
id={id} id={id}
tabindex='-1' tabindex='-1'
class='hidden bg-black/50 overflow-y-auto overflow-x-hidden fixed top-0 right-0 left-0 z-50 h-full flex items-center justify-center modal' class='hidden bg-black/50 overflow-y-auto overflow-x-hidden fixed top-0 right-0 left-0 z-50 h-full items-center justify-center popup'
> >
<div class='relative p-4 w-full max-w-md h-full md:h-auto'> <div class='relative p-4 w-full max-w-md h-full md:h-auto'>
<div class='relative bg-white rounded-lg shadow modal-body'> <div class='relative bg-white rounded-lg shadow popup-body'>
<button <button
type='button' type='button'
class='absolute top-3 right-2.5 text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm p-1.5 ml-auto inline-flex items-center' class='absolute top-3 right-2.5 text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm p-1.5 ml-auto inline-flex items-center'
onclick='this.closest(".modal").classList.add("hidden")' onclick='this.closest(".popup").classList.add("hidden")'
> >
<Icon icon='close' /> <Icon icon='close' />
<span class='sr-only'>Close modal</span> <span class='sr-only'>Close popup</span>
</button> </button>
<div class='p-5'> <div class='p-5'>
<h3 class='text-2xl mb-0.5 font-medium'> <h3 class='text-2xl mb-0.5 font-medium'>

@ -1,65 +1,69 @@
export class Modal { export class Popup {
constructor() { constructor() {
this.triggerModal = this.triggerModal.bind(this); this.triggerPopup = this.triggerPopup.bind(this);
this.onDOMLoaded = this.onDOMLoaded.bind(this); this.onDOMLoaded = this.onDOMLoaded.bind(this);
this.handleCloseModal = this.handleCloseModal.bind(this); this.handleClosePopup = this.handleClosePopup.bind(this);
this.handleKeydown = this.handleKeydown.bind(this); this.handleKeydown = this.handleKeydown.bind(this);
}
/**
* Triggers the popup on target elements
* @param {Event} e
*/
triggerPopup(e) {
const popupToShow =
e?.target?.closest('[data-popup]')?.dataset?.popup || 'unknown-popup';
const popupEl = document.querySelector(`#${popupToShow}`);
if (!popupEl) {
return;
} }
/** popupEl.classList.remove('hidden');
* Triggers the modal on target elements popupEl.classList.add('flex');
* @param {Event} e const focusEl = popupEl.querySelector('[autofocus]');
*/ if (focusEl) {
triggerModal(e) { focusEl.focus();
const modalToShow = e?.target?.closest('[data-modal]')?.dataset?.modal || 'unknown-modal';
const modalEl = document.querySelector(`#${modalToShow}`);
if (!modalEl) {
return;
}
modalEl.classList.remove('hidden');
const focusEl = modalEl.querySelector('[autofocus]');
if (focusEl) {
focusEl.focus();
}
} }
}
handleCloseModal(e) {
const target = e.target; handleClosePopup(e) {
const modalBody = target.closest('.modal-body'); const target = e.target;
const closestModal = target.closest('.modal'); const popupBody = target.closest('.popup-body');
const closestPopup = target.closest('.popup');
if (modalBody) {
return; if (popupBody) {
} return;
if (closestModal) {
closestModal.classList.add('hidden');
}
} }
handleKeydown(e) { if (closestPopup) {
if (e.key !== 'Escape') { closestPopup.classList.add('hidden');
return; closestPopup.classList.remove('flex');
}
const modal = document.querySelector('.modal:not(.hidden)');
if (modal) {
modal.classList.add('hidden');
}
} }
}
onDOMLoaded() {
document.addEventListener('click', this.triggerModal); handleKeydown(e) {
document.addEventListener('click', this.handleCloseModal); if (e.key !== 'Escape') {
document.addEventListener('keydown', this.handleKeydown); return;
} }
init() { const popup = document.querySelector('.popup:not(.hidden)');
window.addEventListener('DOMContentLoaded', this.onDOMLoaded); if (popup) {
popup.classList.add('hidden');
popup.classList.remove('flex');
} }
} }
const modalRef = new Modal(); onDOMLoaded() {
modalRef.init(); document.addEventListener('click', this.triggerPopup);
document.addEventListener('click', this.handleClosePopup);
document.addEventListener('keydown', this.handleKeydown);
}
init() {
window.addEventListener('DOMContentLoaded', this.onDOMLoaded);
}
}
const popupRef = new Popup();
popupRef.init();

@ -48,7 +48,7 @@ const isRoadmapReady = !isUpcoming;
{isRoadmapReady && ( {isRoadmapReady && (
<button <button
data-modal="download-popup" data-popup="download-popup"
class="inline-flex items-center justify-center bg-yellow-400 py-1.5 px-3 text-xs sm:text-sm font-medium rounded-md hover:bg-yellow-500" class="inline-flex items-center justify-center bg-yellow-400 py-1.5 px-3 text-xs sm:text-sm font-medium rounded-md hover:bg-yellow-500"
aria-label="Download Roadmap" aria-label="Download Roadmap"
> >
@ -58,7 +58,7 @@ const isRoadmapReady = !isUpcoming;
)} )}
<button <button
data-modal="subscribe-popup" data-popup="subscribe-popup"
class="inline-flex items-center justify-center bg-yellow-400 py-1.5 px-3 text-xs sm:text-sm font-medium rounded-md hover:bg-yellow-500" class="inline-flex items-center justify-center bg-yellow-400 py-1.5 px-3 text-xs sm:text-sm font-medium rounded-md hover:bg-yellow-500"
aria-label="Subscribe for Updates" aria-label="Subscribe for Updates"
> >

@ -24,7 +24,7 @@ import Captcha from './Captcha/Captcha.astro';
placeholder='Enter your Email' placeholder='Enter your Email'
/> />
<!-- <Captcha /> --> <Captcha />
<input type='hidden' name='list' value='tTqz1w7nexY3cWDpLnI88Q' /> <input type='hidden' name='list' value='tTqz1w7nexY3cWDpLnI88Q' />
<input type='hidden' name='subform' value='yes' /> <input type='hidden' name='subform' value='yes' />

@ -36,7 +36,7 @@ import BaseLayout from '../layouts/BaseLayout.astro';
placeholder='Enter your email' placeholder='Enter your email'
/> />
<!-- <Captcha /> --> <Captcha />
<input type='hidden' name='list' value='tTqz1w7nexY3cWDpLnI88Q' /> <input type='hidden' name='list' value='tTqz1w7nexY3cWDpLnI88Q' />
<input type='hidden' name='subform' value='yes' /> <input type='hidden' name='subform' value='yes' />

Loading…
Cancel
Save