@evermade/overflow-slider 3.3.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/.nvmrc +1 -1
  2. package/README.md +120 -29
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.esm.js +609 -1
  5. package/dist/index.esm.js.map +1 -0
  6. package/dist/index.min.js +2 -1
  7. package/dist/index.min.js.map +1 -0
  8. package/dist/mixins.scss +14 -0
  9. package/dist/overflow-slider.css +1 -1
  10. package/dist/plugins/arrows/index.d.ts +26 -0
  11. package/dist/plugins/arrows/index.min.js +1 -1
  12. package/dist/plugins/autoplay/index.d.ts +41 -0
  13. package/dist/plugins/autoplay/index.esm.js +233 -0
  14. package/dist/plugins/autoplay/index.min.js +1 -0
  15. package/dist/plugins/core/index.d.ts +75 -0
  16. package/dist/plugins/core/index.d2.ts +23 -0
  17. package/dist/plugins/dots/index.d.ts +16 -0
  18. package/dist/plugins/dots/index.min.js +1 -1
  19. package/dist/plugins/drag-scrolling/index.d.ts +9 -0
  20. package/dist/plugins/drag-scrolling/index.esm.js +2 -2
  21. package/dist/plugins/drag-scrolling/index.min.js +1 -1
  22. package/dist/plugins/fade/index.d.ts +16 -0
  23. package/dist/plugins/fade/index.min.js +1 -1
  24. package/dist/plugins/full-width/index.d.ts +11 -0
  25. package/dist/plugins/full-width/index.esm.js +15 -4
  26. package/dist/plugins/full-width/index.min.js +1 -1
  27. package/dist/plugins/infinite-scroll/index.d.ts +25 -0
  28. package/dist/plugins/infinite-scroll/index.esm.js +75 -0
  29. package/dist/plugins/infinite-scroll/index.min.js +1 -0
  30. package/dist/plugins/scroll-indicator/index.d.ts +14 -0
  31. package/dist/plugins/scroll-indicator/index.esm.js +3 -1
  32. package/dist/plugins/scroll-indicator/index.min.js +1 -1
  33. package/dist/plugins/skip-links/index.d.ts +17 -0
  34. package/dist/plugins/skip-links/index.esm.js +7 -1
  35. package/dist/plugins/skip-links/index.min.js +1 -1
  36. package/dist/plugins/thumbnails/index.d.ts +9 -0
  37. package/dist/plugins/thumbnails/index.min.js +1 -1
  38. package/dist/{core/utils.min.js → utils-Sxwcz8zp.js} +1 -1
  39. package/dist/{core/utils.esm.js → utils-ayDxlweP.js} +1 -1
  40. package/docs/assets/demo.css +115 -0
  41. package/docs/assets/demo.js +68 -0
  42. package/docs/dist/index.d.ts +1 -0
  43. package/docs/dist/index.esm.js +609 -1
  44. package/docs/dist/index.esm.js.map +1 -0
  45. package/docs/dist/index.min.js +2 -1
  46. package/docs/dist/index.min.js.map +1 -0
  47. package/docs/dist/mixins.scss +14 -0
  48. package/docs/dist/overflow-slider.css +1 -1
  49. package/docs/dist/plugins/arrows/index.d.ts +26 -0
  50. package/docs/dist/plugins/arrows/index.min.js +1 -1
  51. package/docs/dist/plugins/autoplay/index.d.ts +41 -0
  52. package/docs/dist/plugins/autoplay/index.esm.js +233 -0
  53. package/docs/dist/plugins/autoplay/index.min.js +1 -0
  54. package/docs/dist/plugins/core/index.d.ts +23 -0
  55. package/docs/dist/plugins/core/index.d2.ts +75 -0
  56. package/docs/dist/plugins/dots/index.d.ts +16 -0
  57. package/docs/dist/plugins/dots/index.min.js +1 -1
  58. package/docs/dist/plugins/drag-scrolling/index.d.ts +9 -0
  59. package/docs/dist/plugins/drag-scrolling/index.esm.js +2 -2
  60. package/docs/dist/plugins/drag-scrolling/index.min.js +1 -1
  61. package/docs/dist/plugins/fade/index.d.ts +16 -0
  62. package/docs/dist/plugins/fade/index.min.js +1 -1
  63. package/docs/dist/plugins/full-width/index.d.ts +11 -0
  64. package/docs/dist/plugins/full-width/index.esm.js +15 -4
  65. package/docs/dist/plugins/full-width/index.min.js +1 -1
  66. package/docs/dist/plugins/infinite-scroll/index.d.ts +25 -0
  67. package/docs/dist/plugins/infinite-scroll/index.esm.js +75 -0
  68. package/docs/dist/plugins/infinite-scroll/index.min.js +1 -0
  69. package/docs/dist/plugins/scroll-indicator/index.d.ts +14 -0
  70. package/docs/dist/plugins/scroll-indicator/index.esm.js +3 -1
  71. package/docs/dist/plugins/scroll-indicator/index.min.js +1 -1
  72. package/docs/dist/plugins/skip-links/index.d.ts +17 -0
  73. package/docs/dist/plugins/skip-links/index.esm.js +7 -1
  74. package/docs/dist/plugins/skip-links/index.min.js +1 -1
  75. package/docs/dist/plugins/thumbnails/index.d.ts +9 -0
  76. package/docs/dist/plugins/thumbnails/index.min.js +1 -1
  77. package/docs/dist/{core/utils.min.js → utils-Sxwcz8zp.js} +1 -1
  78. package/docs/dist/{core/utils.esm.js → utils-ayDxlweP.js} +1 -1
  79. package/docs/index-rtl.html +78 -2
  80. package/docs/index.html +77 -1
  81. package/package.json +50 -27
  82. package/rollup.config.js +90 -66
  83. package/src/core/details.ts +4 -0
  84. package/src/core/overflow-slider.ts +4 -2
  85. package/src/core/slider.ts +91 -64
  86. package/src/core/types.ts +29 -1
  87. package/src/mixins.scss +14 -0
  88. package/src/overflow-slider.scss +12 -10
  89. package/src/plugins/arrows/index.ts +2 -2
  90. package/src/plugins/autoplay/index.ts +276 -0
  91. package/src/plugins/autoplay/styles.scss +11 -0
  92. package/src/plugins/dots/index.ts +2 -2
  93. package/src/plugins/drag-scrolling/index.ts +4 -4
  94. package/src/plugins/fade/index.ts +2 -2
  95. package/src/plugins/full-width/index.ts +18 -6
  96. package/src/plugins/infinite-scroll/index.ts +109 -0
  97. package/src/plugins/scroll-indicator/index.ts +5 -3
  98. package/src/plugins/skip-links/index.ts +2 -2
  99. package/src/plugins/thumbnails/index.ts +2 -2
  100. package/tsconfig.json +4 -2
  101. package/changelog.md +0 -5
  102. package/dist/core/details.esm.js +0 -35
  103. package/dist/core/details.min.js +0 -1
  104. package/dist/core/overflow-slider.esm.js +0 -29
  105. package/dist/core/overflow-slider.min.js +0 -1
  106. package/dist/core/slider.esm.js +0 -499
  107. package/dist/core/slider.min.js +0 -1
  108. package/docs/dist/core/details.esm.js +0 -35
  109. package/docs/dist/core/details.min.js +0 -1
  110. package/docs/dist/core/overflow-slider.esm.js +0 -29
  111. package/docs/dist/core/overflow-slider.min.js +0 -1
  112. package/docs/dist/core/slider.esm.js +0 -499
  113. package/docs/dist/core/slider.min.js +0 -1
package/.nvmrc CHANGED
@@ -1 +1 @@
1
- v16.16.0
1
+ v20
package/README.md CHANGED
@@ -95,57 +95,95 @@ const slider = new OverflowSlider(
95
95
  You can import base styles from the library to get started. The base styles include basic styles for the slider and some plugins.
96
96
 
97
97
  ```scss
98
- @import "@evermade/overflow-slider/style.css";
98
+ @use "@evermade/overflow-slider/style.css";
99
99
  ```
100
100
 
101
101
  You can use the CSS variables to override some values easily.
102
102
 
103
103
  Note that you can easily write styles from scratch if you want to. See source code from `src/overflow-slider.scss` for reference.
104
104
 
105
- ## Slides per view
106
-
107
- You control slides per view in CSS. Set gap between slides via `gap` to slider. Slide layout/size is controlled by `width` property. You can use others but `width` is the most stable.
105
+ ## Mixins
108
106
 
109
- ### A) Fixed width
110
-
111
- Set fixed width for slides: `width: 200px;`. Note you can freely change this with media queries.
107
+ If you are using SCSS, you can use these helpers.
112
108
 
113
- ### B) Relative width
109
+ ```scss
110
+ @use "@evermade/overflow-slider/mixins";
111
+ ```
114
112
 
115
- Set relative width for slides: `width: 100vw;`. Note that you cannot use percentages because they are relative to the container and not the viewport.
113
+ ### slide-width
116
114
 
117
- ### C) Variable based width
115
+ ```scss
116
+ @mixin os-slide-width($slidesPerView: 3, $gap: var(--slide-gap, 1rem), $containerWidth: var(--slider-container-width, 90vw)) {
117
+ width: calc( ( #{$containerWidth} / #{$slidesPerView} ) - calc( #{$slidesPerView} - 1 ) / #{$slidesPerView} * #{$gap});
118
+ }
119
+ ```
118
120
 
119
- This is most practical approach if you want to make sure exactly 3 slides are visible at all times or so. Or you want to display like 1.5 slides in mobile per view.
121
+ Set slide width based on slides per view (more below)
120
122
 
121
- This is based on getting the container width and dividing it by the number of slides you want to show and subtracting the gap. It's recommended to add SCSS mixin for this in case you are using SCSS.
123
+ ### os-break-out-full-width
122
124
 
123
- Mixin:
125
+ Make slider container full width via breaking out of the container that has max-width set.
124
126
 
125
127
  ```scss
126
- @mixin slideWidth($slidesPerView: 3, $gap: var(--slide-gap, 1rem), $containerWidth: var(--slider-container-width, 90vw)) {
127
- width: calc( ( #{$containerWidth} / #{$slidesPerView} ) - calc( #{$slidesPerView} - 1 ) / #{$slidesPerView} * #{$gap});
128
+ @mixin os-break-out-full-width {
129
+ position: relative;
130
+ left: 50%;
131
+ width: 100vw;
132
+ margin-left: -50vw;
128
133
  }
129
134
  ```
130
135
 
131
- Usage:
136
+ ## Slides per view
137
+
138
+ You control slides per view in CSS. Set gap between slides via `gap` to slider element. Note that you cannot use percentages (like 33.33%) for width because they are relative to the container and not the viewport.
139
+
140
+ ### A) Slides per view approach
141
+
142
+ This is most practical approach and relies on some calculations. Setting target width for slider container is recommended as that makes the calculations more stable as otherwise container width can depend on slides and if slides then depend on container width that can lead some issues.
143
+
144
+ Setting target width can be done for example referencing another HTML element in page and copying its width:
145
+
146
+ ```js
147
+ const blockWrapper = document.querySelector( '.block-wrapper' );
148
+ OverflowSlider(
149
+ sliderContainer,
150
+ {
151
+ targetWidth: () => {
152
+ return (blockWrapper).offsetWidth;
153
+ },
154
+ }
155
+ );
156
+ ```
157
+
158
+ This creates a `--slider-container-target-width` variable that is now stable.
159
+
160
+ Use mixin `os-slide-width`
132
161
 
133
162
  ```scss
134
163
  .overflow-slider {
135
164
  --gap: 1.5rem;
136
165
  gap: var(--gap);
137
166
  > * {
138
- --slides-per-view: 3;
139
- @include slideWidth(
167
+ --slides-per-view: 1.5;
168
+ @include os-slide-width(
140
169
  var(--slides-per-view),
141
170
  var(--gap),
142
- var(--slider-container-width)
171
+ var(--slider-container-target-width)
143
172
  );
173
+ @meadia (min-width: 768px) {
174
+ --slides-per-view: 3;
175
+ }
144
176
  }
145
177
  }
146
178
  ```
147
179
 
148
- Note that if you are using FullWidthPlugin, you should use container width from `--slider-container-target-width` instead of `--slider-container-width`.
180
+ ### B) Fixed width
181
+
182
+ Set fixed width for slides: `width: 200px;`. Note you can freely change this with media queries.
183
+
184
+ ### C) Relative width
185
+
186
+ Set relative width for slides: `width: 100vw;`. Note that you cannot use percentages because they are relative to the container and not the viewport.
149
187
 
150
188
  ## Plugins
151
189
 
@@ -209,6 +247,7 @@ type ArrowsOptions = {
209
247
  container: HTMLElement | null, // container for both arrows
210
248
  containerPrev: HTMLElement | null, // container for previous arrow
211
249
  containerNext: HTMLElement | null, // container for next arrow
250
+ movementType: 'view' | 'slide', // default 'view', how much to move when arrow is clicked
212
251
  };
213
252
  ```
214
253
 
@@ -424,6 +463,46 @@ const thumbnailsSlider = new OverflowSlider(
424
463
  );
425
464
  ```
426
465
 
466
+ ### AutoplayPlugin
467
+
468
+ This plugin allows you to automatically scroll the slider. It can be used to create a hero slider that scrolls automatically.
469
+
470
+ This includes play/pause button and for users that prefer reduced motion, autoplay plugin will not execute.
471
+
472
+ ```ts
473
+ import AutoplayPlugin from '@evermade/overflow-slider/plugins/autoplay';
474
+ const slider = new OverflowSlider(
475
+ document.querySelector( '.slider-container-here' ),
476
+ {},
477
+ [
478
+ AutoplayPlugin(), // add options here or don't
479
+ ]
480
+ );
481
+ ```
482
+
483
+ All options are optional.
484
+
485
+ ```ts
486
+ export type AutoplayPluginOptions = {
487
+ delayInMs: number;
488
+ texts: {
489
+ play: string;
490
+ pause: string;
491
+ };
492
+ icons: {
493
+ play: string;
494
+ pause: string;
495
+ };
496
+ classNames: {
497
+ autoplayButton: string;
498
+ };
499
+ container: HTMLElement | null;
500
+ movementType: 'view' | 'slide';
501
+ stopOnHover: boolean;
502
+ loop: boolean;
503
+ };
504
+ ```
505
+
427
506
  ## Known issues
428
507
 
429
508
  ### CSS grids and Overflow Slider
@@ -438,24 +517,36 @@ If you are using `scroll-snap-type` CSS property, you might encounter some bugs
438
517
 
439
518
  ### Vertical scrolling
440
519
 
441
- The library is designed to work with horizontal scrolling. Vertical scrolling is not supported and likely never will because it is not a common use case for sliders.
520
+ The library is designed to work with horizontal scrolling. Vertical scrolling is not supported at the moment. Maybe some day but it's much rarer use case.
442
521
 
443
- ### Looping slides
522
+ ### Infinite scroll
444
523
 
445
- Looping slides is not supported and likely never will be. It is a feature that is not very common and it is not very accessible.
446
-
447
- ### Auto-play
448
-
449
- Auto-play is not supported at the moment but can probably be implemented as a plugin. It is not very accessible and should be avoided if possible.
524
+ Infinite scroll is not supported and likely never will be. It is a feature that is not very common and it is not very accessible.
450
525
 
451
526
  ## To-do
452
527
 
453
- * Maybe split styles to separate files for plugins (but keep offering bundle as well)
454
528
  * Maybe add plugin that adds class for visible slides
455
- * Document all plugins and their parameters here
529
+ * Experiment on infinite scroll
456
530
 
457
531
  ## Changelog
458
532
 
533
+ ### 4.0.0
534
+
535
+ * Add: AutoPlayPlugin to allow auto-playing slides
536
+ * Add: Mixins that can be imported to SCSS projects
537
+ * Add: CSS variable: `--slider-container-height`
538
+ * Add: CSS variable: `--slider-x-offset`
539
+ * Add: Option `cssVariableContainer` to expose CSS variables for example higher container
540
+ * Add: `canMoveToSlide` method to check if slider can move to a specific slide (does it exist, is it already in view)
541
+ * Add: `targetWidth` to slider options as relying on `--slider-container-target-width` can be more solid to calculate fractional slide widths on (at least when there is only few slides)
542
+ * Fix: Export TypeScript types properly from core and plugins to be available automatically
543
+ * Fix: ScrollIndicatorPlugin click to scroll bar didn't always detect click position correctly
544
+ * Fix: snapToClosestSlide method edge cases on DragScrollingPlugin sometimes not snapping on right slide
545
+
546
+ ### 3.3.1
547
+
548
+ * Fix: FullWidthPlugin margin calculation not being run if there's too few slides for overflow and you resize screen without container width changing
549
+
459
550
  ### 3.3.0
460
551
 
461
552
  * Add: Ability to move each direction by one slide at a time via `moveToSlideInDirection` prev/next
@@ -0,0 +1 @@
1
+ export { default as OverflowSlider } from './plugins/core/index.d2.ts';