UNPKG

2.76 kBTypeScriptView Raw
1import BaseComponent, { GetInstanceFactory, GetOrCreateInstanceFactory } from './base-component';
2
3declare class Offcanvas extends BaseComponent {
4 /**
5 * Static method which allows you to get the offcanvas instance associated with a DOM element
6 */
7 static getInstance: GetInstanceFactory<Offcanvas>;
8
9 /**
10 * Static method which allows you to get the offcanvas instance associated with
11 * a DOM element, or create a new one in case it wasn’t initialised
12 */
13 static getOrCreateInstance: GetOrCreateInstanceFactory<Offcanvas, Partial<Offcanvas.Options>>;
14
15 static jQueryInterface: Offcanvas.jQueryInterface;
16
17 constructor(element: string | Element, options?: Partial<Offcanvas.Options>);
18
19 /**
20 * Toggles an offcanvas element to shown or hidden. Returns to the caller before the offcanvas element has actually
21 * been shown or hidden (i.e. before the shown.bs.offcanvas or hidden.bs.offcanvas event occurs).
22 */
23 toggle(relatedTarget?: HTMLElement): void;
24
25 /**
26 * Shows an offcanvas element. Returns to the caller before the offcanvas element has actually been shown
27 * (i.e. before the shown.bs.offcanvas event occurs).
28 */
29 show(relatedTarget?: HTMLElement): void;
30
31 /**
32 * Hides an offcanvas element. Returns to the caller before the offcanvas element has actually been hidden
33 * (i.e. before the hidden.bs.offcanvas event occurs).
34 */
35 hide(): void;
36}
37
38declare namespace Offcanvas {
39 interface Options {
40 /**
41 * Apply a backdrop on body while offcanvas is open
42 *
43 * @default true
44 */
45 backdrop: boolean;
46
47 /**
48 * Closes the offcanvas when escape key is pressed
49 *
50 * @default true
51 */
52 keyboard: boolean;
53
54 /**
55 * Allow body scrolling while offcanvas is open
56 *
57 * @default false
58 */
59 scroll: boolean;
60 }
61
62 enum Events {
63 /**
64 * This event fires immediately when the show instance method is called.
65 */
66 show = 'show.bs.offcanvas',
67
68 /**
69 * This event is fired when an offcanvas element has been made visible to the user (will wait for CSS transitions to complete).
70 */
71 shown = 'shown.bs.offcanvas',
72
73 /**
74 * This event is fired immediately when the hide method has been called.
75 */
76 hide = 'hide.bs.offcanvas',
77
78 /**
79 * This event is fired when an offcanvas element has been hidden from the user (will wait for CSS transitions to complete).
80 */
81 hidden = 'hidden.bs.offcanvas',
82 }
83
84 type jQueryInterface = (config?: 'toggle' | 'show' | 'hide') => void;
85}
86
87export default Offcanvas;