UNPKG

@sv-use/core

Version:

A collection of Svelte 5 utilities.

31 lines (30 loc) 1.27 kB
import { type ConfigurableWindow } from '../__internal__/configurable.js'; import type { Arrayable, CleanupFunction, Getter } from '../__internal__/types.js'; interface OnClickOutsideOptions extends ConfigurableWindow { /** * Whether to auto-cleanup the event listeners or not. * * If set to `true`, it must run in the component initialization lifecycle. * @default false */ autoCleanup?: boolean; /** * Use capturing phase for internal event listener. * @default true */ capture?: boolean; /** * Element(s) that will not trigger the event. * @default [] */ ignore?: Arrayable<Getter<HTMLElement | null | undefined>>; } /** * Runs a callback when a click occurs outside the element or its ignore list. * @param element The main element on which not to trigger a click. * @param callback The callback to run when an outside click is valid. * @param options Additional options to customize the behavior. * @see https://svelte-librarian.github.io/sv-use/docs/core/on-click-outside */ export declare function onClickOutside<T extends HTMLElement>(element: Getter<T | null | undefined>, callback: (event: PointerEvent) => void, options?: OnClickOutsideOptions): CleanupFunction; export {};