Document optional delay parameter for addClass, removeClass, remove (#820)

thank you!
This commit is contained in:
mayowa 2022-02-17 14:16:35 +01:00 committed by GitHub
parent c49ce64d2d
commit bda02d0d66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 3 deletions

9
src/htmx.d.ts vendored
View File

@ -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

View File

@ -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);
```
### <a name="ajax"></a> 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);
```
### <a name="removeClass"></a> 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);
```
### <a name="removeExtension"></a> Method - [`htmx.removeExtension()`](#removeExtension)