UNPKG

@sveltek/attachments

Version:

A collection of custom attachments for Svelte.

94 lines (93 loc) 2.29 kB
import { Attachment } from "svelte/attachments"; //#region src/attachments/click-outside/attachment.d.ts declare function clickOutside(callback: (event: MouseEvent) => void, options?: ClickOutsideOptions): Attachment; //#endregion //#region src/attachments/click-outside/types.d.ts interface ClickOutsideOptions { event?: { /** * @default document */ target?: Element | Document | Window; }; /** * @default undefined */ trigger?: Element | null | (Element | null)[]; } //#endregion //#region src/attachments/keyboard/attachment.d.ts declare function keyboard(callback: (event: KeyboardEvent) => void, options?: KeyboardOptions): Attachment; //#endregion //#region src/attachments/keyboard/types.d.ts interface KeyboardOptions { event?: { /** * @default 'keydown' */ type?: 'keydown' | 'keyup'; /** * @default this */ target?: Element | Document | Window; }; /** * @default undefined */ keys?: string[]; } //#endregion //#region src/attachments/prevent-scroll/attachment.d.ts declare function preventScroll(options?: PreventScrollOptions): Attachment; //#endregion //#region src/attachments/prevent-scroll/types.d.ts interface PreventScrollOptions { /** * @default undefined */ target?: Element | Document | Window; /** * @default (e: Event): void => e.preventDefault() */ handler?: (e: Event) => void; /** * @default (e: KeyboardEvent): void => { if (keys.includes(e.key)) e.preventDefault() } */ handlerKey?: (e: KeyboardEvent) => void; wheel?: { /** * @default true */ enable?: boolean; /** * @default this */ target?: Element | Document | Window; }; touchmove?: { /** * @default true */ enable?: boolean; /** * @default this */ target?: Element | Document | Window; }; keydown?: { /** * @default true */ enable?: boolean; /** * @default document */ target?: Element | Document | Window; /** * @default ['ArrowLeft','ArrowRight','ArrowUp','ArrowDown','PageDown','PageUp','Home','End',' '], */ keys?: string[]; }; } //#endregion export { ClickOutsideOptions, KeyboardOptions, PreventScrollOptions, clickOutside, keyboard, preventScroll };