-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add include and exclude filters
- Loading branch information
Showing
1 changed file
with
27 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,30 @@ | ||
// common filters for global events | ||
|
||
export function excludeElements() { | ||
// TODO: implement | ||
/** | ||
* Creates a filter than can be passed to `<GlobalEvents />` to exclude events from elements with the given tag names. | ||
* | ||
* @param tagNames - array of tag names to exclude | ||
*/ | ||
export function excludeElements(tagNames: Array<Uppercase<_HTMLElementNames>>) { | ||
return (event: Event) => { | ||
const target = event.target as HTMLElement | ||
return !(tagNames as string[]).includes(target.tagName) | ||
} | ||
} | ||
|
||
/** | ||
* Creates a filter than can be passed to `<GlobalEvents />` to include events from elements with the given tag names. | ||
* | ||
* @see excludeElements | ||
* | ||
* @param tagNames - array of tag names to include | ||
*/ | ||
export function includeElements(tagNames: Array<Uppercase<_HTMLElementNames>>) { | ||
return (event: Event) => { | ||
const target = event.target as HTMLElement | ||
return (tagNames as string[]).includes(target.tagName) | ||
} | ||
} | ||
|
||
// @internal | ||
export type _HTMLElementNames = keyof HTMLElementTagNameMap |