From ad0169976e0eefd6648751bc553c3a36ed97233b Mon Sep 17 00:00:00 2001 From: Andy Cohen Date: Thu, 2 Feb 2023 15:52:37 -0600 Subject: [PATCH] improve documentation + some clean up. --- README.md | 37 +++++++++++++++++++++++++++---- package.json | 2 +- src/lib/ConfirmationController.js | 9 ++++---- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 1fde4b8..e7357b9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Drop-in upgrade for rails `data-turbo-confirm` to support custom HTML dialogs and multiple content _slots_. -## Installation +### Installation ```Bash npm install @rolemodel/confirm @@ -14,7 +14,7 @@ or yarn add @rolemodel/confirm ``` -## Usage +### Usage In your applications JavaScript entrypoint file. (e.g. _app/javascript/application.js_) @@ -27,7 +27,7 @@ Turbo.setConfirmMethod(RoleModelConfirm.confirm) RoleModelConfirm.init() ``` -## Configuration +### Configuration RoleModel confirm is entirely configurable. Override default configuration by passing an object into `init()`. @@ -55,7 +55,7 @@ const contentSlots = { RoleModelConfirm.init({contentSlots}) ``` -### default configuration +### Default Config ```JS { @@ -75,4 +75,33 @@ RoleModelConfirm.init({contentSlots}) } } } +``` + +### Example Template + +Based on default configuration, the following template is suitable. + +```HTML + + + RoleModel Turbo-Confirm + + + + + + + ``` \ No newline at end of file diff --git a/package.json b/package.json index 746b593..4c0f364 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@rolemodel/turbo-confirm", "type": "module", - "version": "0.1.1", + "version": "0.1.2", "description": "Drop-in upgrade for Rails' data-turbo-confirm feature to support custom HTML dialogs.", "main": "src/index.js", "directories": { diff --git a/src/lib/ConfirmationController.js b/src/lib/ConfirmationController.js index f92524e..f886cb6 100644 --- a/src/lib/ConfirmationController.js +++ b/src/lib/ConfirmationController.js @@ -86,13 +86,12 @@ export default class ConfirmationController { } #clearSlots() { - const slots = [] - for(const [slotName, _slotConfig] of Object.entries(this.#config.contentSlots)) { - slots.push(this.#slotTarget(slotName)) - } // allow for hide animation to complete before removing content setTimeout(()=> { - slots.forEach(slot => slot.innerHTML = '') + for(const slotName of Object.keys(this.#config.contentSlots)) { + const slotTarget = this.#slotTarget(slotName) + if (slotTarget) slotTarget.innerHTML = '' + } }, this.#config.animationDuration) }