UNPKG

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