UNPKG

4.4 kBTypeScriptView Raw
1import BaseComponent from "./base-component";
2
3declare class Carousel extends BaseComponent {
4 constructor(element: string | Element, options?: Partial<Carousel.Options>);
5
6 /**
7 * Cycles through the carousel items from left to right.
8 */
9 cycle(): void;
10
11 /**
12 * Stops the carousel from cycling through items.
13 */
14 pause(event?: any): void;
15
16 /**
17 * Cycles to the previous item. Returns to the caller before the previous
18 * item has been shown (e.g., before the slid.bs.carousel event occurs).
19 */
20 prev(): void;
21
22 /**
23 * Cycles to the next item. Returns to the caller before the next item has
24 * been shown (e.g., before the slid.bs.carousel event occurs).
25 */
26 next(): void;
27
28 /**
29 * Cycles the carousel to a particular frame (0 based, similar to an array).
30 * Returns to the caller before the target item has been shown (e.g., before
31 * the slid.bs.carousel event occurs).
32 */
33 nextWhenVisible(): void;
34
35 /**
36 * Cycles the carousel to a particular frame (0 based, similar to an array).
37 * Returns to the caller before the target item has been shown (e.g., before
38 * the slid.bs.carousel event occurs).
39 */
40 to(index: number): void;
41
42 /**
43 * Static method which allows you to get the carousel instance associated
44 * with a DOM element.
45 */
46 static getInstance(element: Element, options?: Partial<Carousel.Options>): Carousel;
47
48 static jQueryInterface: Carousel.jQueryInterface;
49
50 // static NAME: 'carousel';
51
52 /**
53 * Default settings of this plugin
54 *
55 * @link https://getbootstrap.com/docs/5.0/getting-started/javascript/#default-settings
56 */
57 static Default: Carousel.Options;
58}
59
60declare namespace Carousel {
61 interface Options {
62 /**
63 * The amount of time to delay between automatically cycling an item. If
64 * false, carousel will not automatically cycle.
65 *
66 * @default 5000
67 */
68 interval: number;
69
70 /**
71 * Whether the carousel should react to keyboard events.
72 *
73 * @default true
74 */
75 keyboard: boolean;
76
77 /**
78 * If set to "hover", pauses the cycling of the carousel on mouseenter and
79 * resumes the cycling of the carousel on mouseleave. If set to false,
80 * hovering over the carousel won't pause it. On touch-enabled devices, when
81 * set to "hover", cycling will pause on touchend (once the user finished
82 * interacting with the carousel) for two intervals, before automatically
83 * resuming. Note that this is in addition to the above mouse behavior.
84 *
85 * @default "hover"
86 */
87 pause: string | boolean;
88
89 /**
90 * Autoplays the carousel after the user manually cycles the first item. If
91 * "carousel", autoplays the carousel on load.
92 *
93 * @default false
94 */
95 slide: string | boolean;
96
97 /**
98 * Whether the carousel should cycle continuously or have hard stops.
99 *
100 * @default true
101 */
102 wrap: boolean;
103
104 /**
105 * Whether the carousel should support left/right swipe interactions on
106 * touchscreen devices.
107 *
108 * @default true
109 */
110 touch: boolean;
111 }
112
113 enum Events {
114 /**
115 * Fires immediately when the slide instance method is invoked.
116 */
117 slide = "slide.bs.carousel",
118
119 /**
120 * Fired when the carousel has completed its slide transition.
121 */
122 slid = "slid.bs.carousel",
123 }
124
125 type Direction = "left" | "right";
126
127 interface Event {
128 /**
129 * The direction in which the carousel is sliding (either "left" or
130 * "right").
131 */
132 readonly direction: Direction;
133
134 /**
135 * The DOM element that is being slid into place as the active item.
136 */
137 readonly relatedTarget: Element;
138
139 /**
140 * The index of the current item
141 */
142 readonly from: number;
143
144 /**
145 * The index of the next item
146 */
147 readonly to: number;
148 }
149
150 type jQueryInterface = (
151 config?: Partial<Options> | number | "cycle" | "pause" | "prev" | "next" | "nextWhenVisible" | "dispose",
152 ) => void;
153}
154
155export default Carousel;