I am trying to create a basic JS plugin that can be called after the click event, to disable the button (so that users do not launch several API calls), and to give a backlink that something is loading / happening. Here's what it looks like:

This works fine on an individual basis, but I want to rewrite it as a plugin so that I can reuse it on the site.
Here is a clipped version of JS from loader.plugin.js file.
let originalBtnText; export function showBtnLoader(btn, loadingText) { const clickedBtn = btn; const spinner = document.createElement('div'); spinner.classList.add('spin-loader'); originalBtnText = clickedBtn.textContent; clickedBtn.textContent = loadingText; clickedBtn.appendChild(spinner); clickedBtn.setAttribute('disabled', true); clickedBtn.classList.add('loading'); return this; } export function hideBtnLoader(btn) { const clickedBtn = btn.target; clickedBtn.textContent = originalBtnText; clickedBtn.removeAttribute('disabled'); clickedBtn.classList.remove('loading'); return this; } export function btnLoader() { showBtnLoader(); hideBtnLoader(); }
And here is an example of how I would like to use it.
import btnLoader from 'loaderPlugin'; const signupBtn = document.getElementById('signup-btn'); signupBtn.addEventListener('click', function(e) { e.preventDefault(); btnLoader.showBtnLoader(signupBtn, 'Validating');
The problem is that I want to save the originalBtnText from the showBtnLoader function, and then use this variable in the hideBtnLoader function. I could, of course, achieve this in a different way (for example, by adding a value as a data attribute and capturing it later), but I wondered if there was an easy way.
Another problem is that I do not know the correct way to call each individual function and whether I import it correctly. I have tried the following.
btnLoader.showBtnLoader(signupBtn, 'Validating'); btnLoader(showBtnLoader(signupBtn, 'Validating')); showBtnLoader(signupBtn, 'Validating');
But I get the following error:
Uncaught ReferenceError: showBtnLoader is not defined at HTMLButtonElement.<anonymous>
I read some good SO articles and answers, such as http://2ality.com/2014/09/es6-modules-final.html and the default ES6 export with several functions linking to each other , but I'm a bit confused about " the right "way to do this, to make it reusable.
Any pointers would be much appreciated.