From bda02d0d66afc50a04563a7186f2351c339d4c9c Mon Sep 17 00:00:00 2001 From: mayowa Date: Thu, 17 Feb 2022 14:16:35 +0100 Subject: [PATCH] Document optional delay parameter for addClass, removeClass, remove (#820) thank you! --- src/htmx.d.ts | 9 ++++++--- www/api.md | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/htmx.d.ts b/src/htmx.d.ts index 45fc9781..1090aa81 100644 --- a/src/htmx.d.ts +++ b/src/htmx.d.ts @@ -7,8 +7,9 @@ * * @param elt the element to add the class to * @param clazz the class to add + * @param delay the delay (in milliseconds before class is added) */ -export function addClass(elt: Element, clazz: string): void; +export function addClass(elt: Element, clazz: string, delay?: number): void; /** * Issues an htmx-style AJAX request @@ -219,8 +220,9 @@ export function process(element: Element): void; * https://htmx.org/api/#remove * * @param elt element to remove + * @param delay the delay (in milliseconds before element is removed) */ -export function remove(elt: Element): void; +export function remove(elt: Element, delay?: number): void; /** * Removes a class from the given element @@ -229,8 +231,9 @@ export function remove(elt: Element): void; * * @param elt element to remove the class from * @param clazz the class to remove + * @param delay the delay (in milliseconds before class is removed) */ -export function removeClass(elt: Element, clazz: string): void; +export function removeClass(elt: Element, clazz: string, delay?: number): void; /** * Removes the given extension from htmx diff --git a/www/api.md b/www/api.md index d3c4fa50..994799d4 100644 --- a/www/api.md +++ b/www/api.md @@ -19,11 +19,20 @@ This method adds a class to the given element. * `elt` - the element to add the class to * `class` - the class to add +or + +* `elt` - the element to add the class to +* `class` - the class to add +* `delay` - delay (in milliseconds ) before class is added + ##### Example ```js // add the class 'myClass' to the element with the id 'demo' htmx.addClass(htmx.find('#demo'), 'myClass'); + + // add the class 'myClass' to the element with the id 'demo' after 1 second + htmx.addClass(htmx.find('#demo'), 'myClass', 1000); ``` ### Method - [`htmx.ajax()`](#ajax) @@ -363,11 +372,19 @@ Removes an element from the DOM * `elt` - element to remove +or + +* `elt` - element to remove +* `delay` - delay (in milliseconds ) before element is removed + ##### Example ```js // removes my-div from the DOM htmx.remove(htmx.find("#my-div")); + + // removes my-div from the DOM after a delay of 2 seconds + htmx.remove(htmx.find("#my-div"), 2000); ``` ### Method - [`htmx.removeClass()`](#removeClass) @@ -379,11 +396,20 @@ Removes a class from the given element * `elt` - element to remove the class from * `class` - the class to remove +or + +* `elt` - element to remove the class from +* `class` - the class to remove +* `delay` - delay (in milliseconds ) before class is removed + ##### Example ```js // removes .myClass from my-div htmx.removeClass(htmx.find("#my-div"), "myClass"); + + // removes .myClass from my-div after 6 seconds + htmx.removeClass(htmx.find("#my-div"), "myClass", 6000); ``` ### Method - [`htmx.removeExtension()`](#removeExtension)