diff --git a/src/index.css b/src/index.css index b7486bcb..fdbabeca 100644 --- a/src/index.css +++ b/src/index.css @@ -18,9 +18,13 @@ &-settings { display: flex; + align-items: center; .cdx-settings-button { width: 50%; } + input { + padding: 5px; + } } } diff --git a/src/index.js b/src/index.js index 4ba15a7b..2aab5357 100644 --- a/src/index.js +++ b/src/index.js @@ -6,6 +6,7 @@ require('./index.css').toString(); /** * @typedef {object} ListData * @property {string} style - can be ordered or unordered + * @property {number} [start] - optional starting number of ordered list * @property {Array} items - li elements */ @@ -82,6 +83,12 @@ class List { icon: '', default: true, }, + { + name: 'start', + title: this.api.i18n.t('Starting number'), + icon: '', + default: false, + }, ]; /** @@ -104,7 +111,7 @@ class List { * @public */ render() { - this._elements.wrapper = this.makeMainTag(this._data.style); + this._elements.wrapper = this.makeMainTag(this._data.style, this._data.start); // fill with data if (this._data.items.length) { @@ -199,23 +206,45 @@ class List { const wrapper = this._make('div', [ this.CSS.settingsWrapper ], {}); this.settings.forEach((item) => { - const itemEl = this._make('div', this.CSS.settingsButton, { - innerHTML: item.icon, - }); - itemEl.addEventListener('click', () => { - this.toggleTune(item.name); - - // clear other buttons - const buttons = itemEl.parentNode.querySelectorAll('.' + this.CSS.settingsButton); - - Array.from(buttons).forEach((button) => - button.classList.remove(this.CSS.settingsButtonActive) - ); - - // mark active - itemEl.classList.toggle(this.CSS.settingsButtonActive); - }); + let itemEl + + // check if settings item is button or number input + if (item.name === 'start') { + itemEl = this._make('input', this.CSS.settingsInput, { + type: 'number' + }); + itemEl.addEventListener('input', (e) => { + this.setStartNumber(e.target.value); + }) + itemEl.value = this._data.start; + } else { + // make buttons + itemEl = this._make('div', this.CSS.settingsButton, { + innerHTML: item.icon, + }); + + // run click eventlisteners on settings that are buttons + itemEl.addEventListener('click', () => { + + this.toggleTune(item.name); + + // clear other buttons + const buttons = itemEl.parentNode.querySelectorAll('.' + this.CSS.settingsButton); + + Array.from(buttons).forEach((button) => + button.classList.remove(this.CSS.settingsButtonActive) + ); + + // clear input value if 'unordered' is selected + if (item.name === 'unordered') { + itemEl.parentNode.querySelector('.' + this.CSS.settingsInput).value = '' + } + + // mark active + itemEl.classList.toggle(this.CSS.settingsButtonActive); + }); + } this.api.tooltip.onHover(itemEl, item.title, { placement: 'top', @@ -227,6 +256,7 @@ class List { } wrapper.appendChild(itemEl); + }); return wrapper; @@ -258,14 +288,17 @@ class List { * Creates main