@sveltek/attachments
Version:
A collection of custom attachments for Svelte.
90 lines (82 loc) • 2.14 kB
text/typescript
import { Attachment } from 'svelte/attachments';
declare function clickOutside(callback: (event: MouseEvent) => void, options?: ClickOutsideOptions): Attachment;
interface ClickOutsideOptions {
event?: {
/**
* @default document
*/
target?: Element | Document | Window;
};
/**
* @default undefined
*/
trigger?: Element | null | (Element | null)[];
}
declare function keyboard(callback: (event: KeyboardEvent) => void, options?: KeyboardOptions): Attachment;
interface KeyboardOptions {
event?: {
/**
* @default 'keydown'
*/
type?: 'keydown' | 'keyup';
/**
* @default this
*/
target?: Element | Document | Window;
};
/**
* @default undefined
*/
keys?: string[];
}
declare function preventScroll(options?: PreventScrollOptions): Attachment;
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[];
};
}
export { clickOutside, keyboard, preventScroll };
export type { ClickOutsideOptions, KeyboardOptions, PreventScrollOptions };