const btns = document.querySelectorAll('.btn'); const toastContainer = document.querySelector('.toast'); const buttonYes = document.querySelector('#buttonsYes'); const buttonNo = document.querySelector('#buttonsNo'); const buttonsContainer = document.querySelector('#buttonsDiv'); const options = { regular: { heading: 'This is a Regular notification', paragraph: 'This toast message notifies you of something. Whatever that may be.', svg: '' }, success: { heading: 'This is a Success notification', paragraph: 'This toast message notifies you of all your great successes. You rock!', svg: '
' }, error: { heading: 'This is an Error notification', paragraph: 'This toast message notifies you of an Error. Don\'t worry it\'s probably not your fault.', svg: '
' }, warning: { heading: 'This is a Warning notification', paragraph: 'This toast message notifies you of a Warning. Who knows what might have happened.', svg: '
' } } function createToast({type='regular', buttons='false', close='true', heading='', paragraph='', button1='', button2=''}) { const html = `
${options[type].svg}

${heading ? heading : options[type].heading}

${paragraph ? paragraph : options[type].paragraph}

${close === 'true' ? `×` : ''}
`; toastContainer.insertAdjacentHTML('beforeend', html); const toast = toastContainer.lastElementChild; toast.addEventListener('animationend', () => toast.remove()); } function resetForm() { document.querySelector('#heading').value = ''; document.querySelector('#paragraph').value = ''; } btns.forEach(btn => btn.addEventListener('click', function(e) { e.preventDefault(); const close = document.querySelector('input[name=close]:checked').value; const heading = document.querySelector('#heading').value; const paragraph = document.querySelector('#paragraph').value; resetForm(); createToast({type: this.value, close, heading, paragraph}); }));