UNPKG

2.88 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. Alternatively, specify `static` for a backdrop which
42 * doesn’t close the offcanvas when clicked.
43 *
44 * @default true
45 */
46 backdrop: boolean | 'static';
47
48 /**
49 * Closes the offcanvas when escape key is pressed
50 *
51 * @default true
52 */
53 keyboard: boolean;
54
55 /**
56 * Allow body scrolling while offcanvas is open
57 *
58 * @default false
59 */
60 scroll: boolean;
61 }
62
63 enum Events {
64 /**
65 * This event fires immediately when the show instance method is called.
66 */
67 show = 'show.bs.offcanvas',
68
69 /**
70 * This event is fired when an offcanvas element has been made visible to the user (will wait for CSS transitions to complete).
71 */
72 shown = 'shown.bs.offcanvas',
73
74 /**
75 * This event is fired immediately when the hide method has been called.
76 */
77 hide = 'hide.bs.offcanvas',
78
79 /**
80 * This event is fired when an offcanvas element has been hidden from the user (will wait for CSS transitions to complete).
81 */
82 hidden = 'hidden.bs.offcanvas',
83 }
84
85 type jQueryInterface = (config?: 'toggle' | 'show' | 'hide') => JQuery;
86}
87
88export default Offcanvas;