options.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. import { I18N } from '../constants/i18n';
  2. /**
  3. * The interface for options.
  4. *
  5. * @since 3.0.0
  6. */
  7. export interface Options extends ResponsiveOptions {
  8. /**
  9. * The type of the slider.
  10. * - 'slide': A slider with the slide transition
  11. * - 'loop' : A carousel slider
  12. * - 'fade' : A slider with the fade transition. This does not support the perPage option.
  13. */
  14. type?: string;
  15. /**
  16. * The `role` attribute for the root element.
  17. * If the tag is `<section>`, this value will not be used. The default value is `'region'`.
  18. */
  19. role?: string;
  20. /**
  21. * Determines whether to disable any actions while the slider is transitioning.
  22. * Even if `false`, the slider forcibly waits for transition on the loop points.
  23. */
  24. waitForTransition?: boolean;
  25. /**
  26. * If `true`, the width of slides are determined by their width.
  27. * The `perPage` and `perMove` options should be `1`.
  28. */
  29. autoWidth?: boolean;
  30. /**
  31. * If `true`, the height of slides are determined by their height.
  32. * The `perPage` and `perMove` options should be `1`.
  33. */
  34. autoHeight?: boolean;
  35. /**
  36. * The start index.
  37. */
  38. start?: number;
  39. /**
  40. * Changes the arrow SVG path, like 'm7.61 0.807-2.12...'.
  41. */
  42. arrowPath?: string;
  43. /**
  44. * Determines whether to activate autoplay or not.
  45. * If `paused`, it will not begin when the slider becomes active.
  46. * You need to provided play/pause buttons or manually start it by `Autoplay#play()`.
  47. */
  48. autoplay?: boolean | 'pause';
  49. /**
  50. * The autoplay interval in milliseconds.
  51. */
  52. interval?: number;
  53. /**
  54. * Determines whether to pause autoplay on mouseover.
  55. */
  56. pauseOnHover?: boolean;
  57. /**
  58. * Determines whether to pause autoplay when the slider contains the active element (focused element).
  59. * This should be `true` for accessibility.
  60. */
  61. pauseOnFocus?: boolean;
  62. /**
  63. * Determines whether to reset the autoplay progress when it is requested to start again.
  64. */
  65. resetProgress?: boolean;
  66. /**
  67. * Enables lazy loading.
  68. * Provide the `src` by the `data-splide-lazy` or the `srcset` by the `data-splide-lazy-srcset`.
  69. * You may also provide `src` for the placeholder, but the value must be different with the data.
  70. *
  71. * - `false`: Disables lazy loading
  72. * - `'nearby'`: Starts loading only images around the active slide (page)
  73. * - `'sequential'`: Loads images sequentially
  74. */
  75. lazyLoad?: boolean | 'nearby' | 'sequential';
  76. /**
  77. * Determine how many pages (not slides) around the active slide should be loaded beforehand.
  78. * This only works when the `lazyLoad` option is `'nearby'`.
  79. */
  80. preloadPages?: number;
  81. /**
  82. * Enables keyboard shortcuts for the slider control.
  83. * - `true` or `'global'`: Listens to the `keydown` event of the document.
  84. * - 'focused': Listens to the `keydown` event of the slider root element with adding `tabindex="0"` to it.
  85. * - `false`: Disables keyboard shortcuts (default).
  86. */
  87. keyboard?: boolean | 'global' | 'focused';
  88. /**
  89. * Enables navigation by the mouse wheel.
  90. * Set `waitForTransition` to `ture` or provide the `wheelSleep` duration.
  91. */
  92. wheel?: boolean;
  93. /**
  94. * The threshold to cut off the small delta produced by inertia scroll.
  95. */
  96. wheelMinThreshold?: number;
  97. /**
  98. * The sleep time in milliseconds until accepting next wheel.
  99. * The timer starts when the transition begins.
  100. */
  101. wheelSleep?: number;
  102. /**
  103. * Determines whether to release the wheel event when the carousel reaches the first or last slide.
  104. */
  105. releaseWheel?: boolean;
  106. /**
  107. * Determines whether to release the touch event when the carousel reaches the first or last slide.
  108. * If `true`, the bounce effect will not play.
  109. * Note that this does not affect mouse drag events.
  110. */
  111. releaseTouch?: boolean;
  112. /**
  113. * The direction of the slider.
  114. * - 'ltr': Left to right
  115. * - 'rtl': Right to left
  116. * - 'ttb': Top to bottom
  117. */
  118. direction?: 'ltr' | 'rtl' | 'ttb';
  119. /**
  120. * Determines whether to add `tabindex="0"` to visible slides or not.
  121. */
  122. slideFocus?: boolean;
  123. /**
  124. * If `true`, the slider makes slides clickable to navigate another slider.
  125. * Use `Splide#sync()` to sync multiple sliders.
  126. */
  127. isNavigation?: boolean;
  128. /**
  129. * Determines whether to trim spaces before/after the slider if the `focus` option is available.
  130. * - `true`: Trims spaces. The slider may stay on the same location even when requested to move.
  131. * - `'move'`: Trims spaces and forces to move the slider when requested.
  132. */
  133. trimSpace?: boolean | 'move';
  134. /**
  135. * If `true` and the `focus` option is available:
  136. * - Disables the next arrow when a carousel reaches the last page even if the active slide is not the last slide.
  137. * - Omits redundant pagination dots which just change the active slide and do not move a carousel.
  138. */
  139. omitEnd?: boolean;
  140. /**
  141. * Updates the `is-active` status of slides just before moving the slider.
  142. */
  143. updateOnMove?: boolean;
  144. /**
  145. * If `min`, the media query for breakpoints will be `min-width`, or otherwise, `max-width`.
  146. */
  147. mediaQuery?: 'min' | 'max';
  148. /**
  149. * The selector to find focusable elements
  150. * where `tabindex="-1"` will be assigned when their ascendant slide is hidden.
  151. */
  152. focusableNodes?: string;
  153. /**
  154. * The selector for nodes that cannot be dragged.
  155. */
  156. noDrag?: string;
  157. /**
  158. * Enables the live region by `aria-live`.
  159. * If `true`, screen readers will read a content of each slide whenever slide changes.
  160. */
  161. live?: boolean;
  162. /**
  163. * Determines whether to use the Transition component or not.
  164. */
  165. useScroll?: boolean;
  166. /**
  167. * Options for specific breakpoints.
  168. *
  169. * @example
  170. * ```ts
  171. * {
  172. * 1000: {
  173. * perPage: 3,
  174. * gap : 20
  175. * },
  176. * 600: {
  177. * perPage: 1,
  178. * gap : 5,
  179. * },
  180. * }
  181. * ```
  182. */
  183. breakpoints?: Record<string | number, ResponsiveOptions>,
  184. /**
  185. * Options used when the `(prefers-reduced-motion: reduce)` is detected.
  186. */
  187. reducedMotion?: Options;
  188. /**
  189. * The collection of class names.
  190. */
  191. classes?: Record<string, string>;
  192. /**
  193. * The collection of i18n strings.
  194. */
  195. i18n?: Record<keyof typeof I18N | string, string>;
  196. }
  197. /**
  198. * The interface for options that can correspond with breakpoints.
  199. *
  200. * @since 3.0.0
  201. */
  202. export interface ResponsiveOptions {
  203. /**
  204. * Accepts arbitrary properties for extensions, although it's not ideal typing.
  205. */
  206. [ key: string ]: any;
  207. /**
  208. * The label for the root element.
  209. * Use `labelledby` instead if there is a visible label.
  210. */
  211. label?: string;
  212. /**
  213. * The ID for the element that used as the label of the carousel.
  214. */
  215. labelledby?: string;
  216. /**
  217. * The transition speed in milliseconds.
  218. */
  219. speed?: number;
  220. /**
  221. * Determines whether to rewind the carousel or not.
  222. * This is ignored when the `type` option is `'loop'`.
  223. */
  224. rewind?: boolean;
  225. /**
  226. * The transition speed on rewind in milliseconds.
  227. */
  228. rewindSpeed?: number;
  229. /**
  230. * Allows to rewind a carousel by drag if the `rewind` option is enabled.
  231. */
  232. rewindByDrag?: boolean;
  233. /**
  234. * Defines the slider max width, accepting the CSS format such as 10em, 80vw.
  235. */
  236. width?: number | string;
  237. /**
  238. * Defines the slider height, accepting the CSS format.
  239. */
  240. height?: number | string;
  241. /**
  242. * Fixes width of slides, accepting the CSS format.
  243. * The slider will ignore the `perPage` option if you provide this value.
  244. */
  245. fixedWidth?: number | string;
  246. /**
  247. * Fixes height of slides, accepting the CSS format.
  248. * The slider will ignore the `heightRatio` option if you provide this value.
  249. */
  250. fixedHeight?: number | string;
  251. /**
  252. * Determines height of slides by the ratio to the slider width.
  253. * For example, when the slider width is `1000` and the ratio is `0.5`, the height will be `500`.
  254. */
  255. heightRatio?: number;
  256. /**
  257. * Determines the number of slides to display in a page.
  258. */
  259. perPage?: number;
  260. /**
  261. * Determines the number of slides to move at once.
  262. */
  263. perMove?: number;
  264. /**
  265. * Determine the number of clones on each side of the slider.
  266. * In most cases, you don't need to provide this value.
  267. */
  268. clones?: number;
  269. /**
  270. * Determines whether to clone status classes for clones or not.
  271. */
  272. cloneStatus?: boolean;
  273. /**
  274. * Determines which slide should be active if there are multiple slides in a page.
  275. * Numbers and `'center'` are acceptable.
  276. */
  277. focus?: number | 'center';
  278. /**
  279. * The gap between slides. The CSS format is acceptable, such as `1em`.
  280. */
  281. gap?: number | string;
  282. /**
  283. * Sets padding left/right or top/bottom of the slider.
  284. * The CSS format is acceptable, such as `1em`.
  285. *
  286. * @example
  287. * ```ts
  288. * // By number
  289. * padding: 10,
  290. *
  291. * // By the CSS format
  292. * padding: '1rem',
  293. *
  294. * // Specifies each value for a horizontal slider
  295. * padding: { left: 10, right: 20 },
  296. * padding: { left: '1rem', right: '2rem' },
  297. *
  298. * // Specified each value for a vertical slider
  299. * padding: { top: 10, bottom: 20 },
  300. * ```
  301. */
  302. padding?:
  303. | number
  304. | string
  305. | { left?: number | string, right?: number | string }
  306. | { top?: number | string, bottom?: number | string };
  307. /**
  308. * Determines whether to create/find arrows or not.
  309. */
  310. arrows?: boolean;
  311. /**
  312. * Determines whether to create pagination (indicator dots) or not.
  313. */
  314. pagination?: boolean;
  315. /**
  316. * Determines whether to enable keyboard shortcuts for pagination when it contains focus.
  317. * The default value is `true`.
  318. */
  319. paginationKeyboard?: boolean;
  320. /**
  321. * Explicitly sets the pagination direction that does not only affect appearance but also shortcuts and ARIA attributes.
  322. * The default value is same with the carousel direction.
  323. */
  324. paginationDirection?: Options['direction'];
  325. /**
  326. * The timing function for the CSS transition. For example, `linear`, ease or `cubic-bezier()`.
  327. */
  328. easing?: string;
  329. /**
  330. * The easing function for the drag free mode.
  331. * The default function is the `easeOutQuart` interpolation.
  332. */
  333. easingFunc?: ( t: number ) => number;
  334. /**
  335. * Allows to drag the slider by a mouse or swipe.
  336. * If `free`, the slider does not snap to a slide after drag.
  337. */
  338. drag?: boolean | 'free';
  339. /**
  340. * Snaps the closest slide in the drag-free mode.
  341. */
  342. snap?: boolean;
  343. /**
  344. * The required distance to start moving the slider by the touch action.
  345. * If you want to define the threshold for the mouse, provide an object.
  346. */
  347. dragMinThreshold?: number | { mouse: number, touch: number };
  348. /**
  349. * Determine the power of "flick". The larger number this is, the farther the slider runs.
  350. * Around 500 is recommended.
  351. */
  352. flickPower?: number;
  353. /**
  354. * Limits the number of pages to move by "flick".
  355. */
  356. flickMaxPages?: number;
  357. /**
  358. * Destroys the slider.
  359. */
  360. destroy?: boolean | 'completely';
  361. }