@evermade/overflow-slider 3.3.1 → 4.1.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 (119) hide show
  1. package/.nvmrc +1 -1
  2. package/README.md +158 -33
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.esm.js +645 -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/classnames/index.d.ts +14 -0
  16. package/dist/plugins/classnames/index.esm.js +108 -0
  17. package/dist/plugins/classnames/index.min.js +1 -0
  18. package/dist/plugins/core/index.d.ts +76 -0
  19. package/dist/plugins/core/index.d2.ts +23 -0
  20. package/dist/plugins/dots/index.d.ts +16 -0
  21. package/dist/plugins/dots/index.min.js +1 -1
  22. package/dist/plugins/drag-scrolling/index.d.ts +9 -0
  23. package/dist/plugins/drag-scrolling/index.esm.js +2 -2
  24. package/dist/plugins/drag-scrolling/index.min.js +1 -1
  25. package/dist/plugins/fade/index.d.ts +16 -0
  26. package/dist/plugins/fade/index.min.js +1 -1
  27. package/dist/plugins/full-width/index.d.ts +11 -0
  28. package/dist/plugins/full-width/index.esm.js +37 -9
  29. package/dist/plugins/full-width/index.min.js +1 -1
  30. package/dist/plugins/infinite-scroll/index.d.ts +25 -0
  31. package/dist/plugins/infinite-scroll/index.esm.js +75 -0
  32. package/dist/plugins/infinite-scroll/index.min.js +1 -0
  33. package/dist/plugins/scroll-indicator/index.d.ts +14 -0
  34. package/dist/plugins/scroll-indicator/index.esm.js +3 -1
  35. package/dist/plugins/scroll-indicator/index.min.js +1 -1
  36. package/dist/plugins/skip-links/index.d.ts +17 -0
  37. package/dist/plugins/skip-links/index.esm.js +7 -1
  38. package/dist/plugins/skip-links/index.min.js +1 -1
  39. package/dist/plugins/thumbnails/index.d.ts +9 -0
  40. package/dist/plugins/thumbnails/index.min.js +1 -1
  41. package/dist/{core/utils.min.js → utils-Sxwcz8zp.js} +1 -1
  42. package/dist/{core/utils.esm.js → utils-ayDxlweP.js} +1 -1
  43. package/docs/assets/demo.css +156 -0
  44. package/docs/assets/demo.js +92 -8
  45. package/docs/dist/index.d.ts +1 -0
  46. package/docs/dist/index.esm.js +645 -1
  47. package/docs/dist/index.esm.js.map +1 -0
  48. package/docs/dist/index.min.js +2 -1
  49. package/docs/dist/index.min.js.map +1 -0
  50. package/docs/dist/mixins.scss +14 -0
  51. package/docs/dist/overflow-slider.css +1 -1
  52. package/docs/dist/plugins/arrows/index.d.ts +26 -0
  53. package/docs/dist/plugins/arrows/index.min.js +1 -1
  54. package/docs/dist/plugins/autoplay/index.d.ts +41 -0
  55. package/docs/dist/plugins/autoplay/index.esm.js +233 -0
  56. package/docs/dist/plugins/autoplay/index.min.js +1 -0
  57. package/docs/dist/plugins/classnames/index.d.ts +14 -0
  58. package/docs/dist/plugins/classnames/index.esm.js +108 -0
  59. package/docs/dist/plugins/classnames/index.min.js +1 -0
  60. package/docs/dist/plugins/core/index.d.ts +76 -0
  61. package/docs/dist/plugins/core/index.d2.ts +23 -0
  62. package/docs/dist/plugins/dots/index.d.ts +16 -0
  63. package/docs/dist/plugins/dots/index.min.js +1 -1
  64. package/docs/dist/plugins/drag-scrolling/index.d.ts +9 -0
  65. package/docs/dist/plugins/drag-scrolling/index.esm.js +2 -2
  66. package/docs/dist/plugins/drag-scrolling/index.min.js +1 -1
  67. package/docs/dist/plugins/fade/index.d.ts +16 -0
  68. package/docs/dist/plugins/fade/index.min.js +1 -1
  69. package/docs/dist/plugins/full-width/index.d.ts +11 -0
  70. package/docs/dist/plugins/full-width/index.esm.js +37 -9
  71. package/docs/dist/plugins/full-width/index.min.js +1 -1
  72. package/docs/dist/plugins/infinite-scroll/index.d.ts +25 -0
  73. package/docs/dist/plugins/infinite-scroll/index.esm.js +75 -0
  74. package/docs/dist/plugins/infinite-scroll/index.min.js +1 -0
  75. package/docs/dist/plugins/scroll-indicator/index.d.ts +14 -0
  76. package/docs/dist/plugins/scroll-indicator/index.esm.js +3 -1
  77. package/docs/dist/plugins/scroll-indicator/index.min.js +1 -1
  78. package/docs/dist/plugins/skip-links/index.d.ts +17 -0
  79. package/docs/dist/plugins/skip-links/index.esm.js +7 -1
  80. package/docs/dist/plugins/skip-links/index.min.js +1 -1
  81. package/docs/dist/plugins/thumbnails/index.d.ts +9 -0
  82. package/docs/dist/plugins/thumbnails/index.min.js +1 -1
  83. package/docs/dist/{core/utils.min.js → utils-Sxwcz8zp.js} +1 -1
  84. package/docs/dist/{core/utils.esm.js → utils-ayDxlweP.js} +1 -1
  85. package/docs/index-rtl.html +78 -2
  86. package/docs/index.html +86 -1
  87. package/package.json +50 -27
  88. package/rollup.config.js +90 -66
  89. package/src/core/details.ts +4 -0
  90. package/src/core/overflow-slider.ts +4 -2
  91. package/src/core/slider.ts +127 -62
  92. package/src/core/types.ts +30 -1
  93. package/src/mixins.scss +14 -0
  94. package/src/overflow-slider.scss +12 -10
  95. package/src/plugins/arrows/index.ts +2 -2
  96. package/src/plugins/autoplay/index.ts +276 -0
  97. package/src/plugins/autoplay/styles.scss +11 -0
  98. package/src/plugins/classnames/index.ts +147 -0
  99. package/src/plugins/dots/index.ts +2 -2
  100. package/src/plugins/drag-scrolling/index.ts +4 -4
  101. package/src/plugins/fade/index.ts +2 -2
  102. package/src/plugins/full-width/index.ts +43 -11
  103. package/src/plugins/scroll-indicator/index.ts +5 -3
  104. package/src/plugins/skip-links/index.ts +2 -2
  105. package/src/plugins/thumbnails/index.ts +2 -2
  106. package/tsconfig.json +4 -2
  107. package/changelog.md +0 -5
  108. package/dist/core/details.esm.js +0 -35
  109. package/dist/core/details.min.js +0 -1
  110. package/dist/core/overflow-slider.esm.js +0 -29
  111. package/dist/core/overflow-slider.min.js +0 -1
  112. package/dist/core/slider.esm.js +0 -499
  113. package/dist/core/slider.min.js +0 -1
  114. package/docs/dist/core/details.esm.js +0 -35
  115. package/docs/dist/core/details.min.js +0 -1
  116. package/docs/dist/core/overflow-slider.esm.js +0 -29
  117. package/docs/dist/core/overflow-slider.min.js +0 -1
  118. package/docs/dist/core/slider.esm.js +0 -499
  119. 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
107
+ If you are using SCSS, you can use these helpers.
110
108
 
111
- Set fixed width for slides: `width: 200px;`. Note you can freely change this with media queries.
112
-
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
 
@@ -289,6 +327,42 @@ const slider = new OverflowSlider(
289
327
  );
290
328
  ```
291
329
 
330
+ ### ClassNamesPlugin
331
+
332
+ Adds CSS classes to each slide based on its visibility inside the slider's target width (or the container width when no target width is supplied). Useful for animating only the slides that are currently in view.
333
+
334
+ ```ts
335
+ import ClassNamesPlugin from '@evermade/overflow-slider/plugins/classnames';
336
+
337
+ const slider = new OverflowSlider(
338
+ document.querySelector( '.slider-container-here' ),
339
+ {},
340
+ [
341
+ ClassNamesPlugin({
342
+ freezeStateOnVisible: true,
343
+ classNames: {
344
+ visible: 'is-visible',
345
+ partlyVisible: 'is-partly-visible',
346
+ hidden: 'is-hidden',
347
+ },
348
+ }),
349
+ ]
350
+ );
351
+ ```
352
+
353
+ All options are optional.
354
+
355
+ ```ts
356
+ type ClassnameOptions = {
357
+ classNames: {
358
+ visible: string;
359
+ partlyVisible: string;
360
+ hidden: string;
361
+ };
362
+ freezeStateOnVisible: boolean; // keep slides in "visible" state once they have been fully seen
363
+ };
364
+ ```
365
+
292
366
  All options are optional.
293
367
 
294
368
  ```ts
@@ -425,6 +499,46 @@ const thumbnailsSlider = new OverflowSlider(
425
499
  );
426
500
  ```
427
501
 
502
+ ### AutoplayPlugin
503
+
504
+ This plugin allows you to automatically scroll the slider. It can be used to create a hero slider that scrolls automatically.
505
+
506
+ This includes play/pause button and for users that prefer reduced motion, autoplay plugin will not execute.
507
+
508
+ ```ts
509
+ import AutoplayPlugin from '@evermade/overflow-slider/plugins/autoplay';
510
+ const slider = new OverflowSlider(
511
+ document.querySelector( '.slider-container-here' ),
512
+ {},
513
+ [
514
+ AutoplayPlugin(), // add options here or don't
515
+ ]
516
+ );
517
+ ```
518
+
519
+ All options are optional.
520
+
521
+ ```ts
522
+ export type AutoplayPluginOptions = {
523
+ delayInMs: number;
524
+ texts: {
525
+ play: string;
526
+ pause: string;
527
+ };
528
+ icons: {
529
+ play: string;
530
+ pause: string;
531
+ };
532
+ classNames: {
533
+ autoplayButton: string;
534
+ };
535
+ container: HTMLElement | null;
536
+ movementType: 'view' | 'slide';
537
+ stopOnHover: boolean;
538
+ loop: boolean;
539
+ };
540
+ ```
541
+
428
542
  ## Known issues
429
543
 
430
544
  ### CSS grids and Overflow Slider
@@ -439,24 +553,35 @@ If you are using `scroll-snap-type` CSS property, you might encounter some bugs
439
553
 
440
554
  ### Vertical scrolling
441
555
 
442
- 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.
443
-
444
- ### Looping slides
556
+ 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.
445
557
 
446
- 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.
558
+ ### Infinite scroll
447
559
 
448
- ### Auto-play
449
-
450
- 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.
451
-
452
- ## To-do
453
-
454
- * Maybe split styles to separate files for plugins (but keep offering bundle as well)
455
- * Maybe add plugin that adds class for visible slides
456
- * Document all plugins and their parameters here
560
+ Infinite scroll is not supported and likely never will be. It is not accessible and causes really complex problems as with overflow we are bound to more "physics" than transform based sliders and there's no escape of the physics (like visible slides need to represent DOM order).
457
561
 
458
562
  ## Changelog
459
563
 
564
+ ### 4.1.0
565
+
566
+ * Add: ClassNamesPlugin to add classes to visible/partly visible/hidden slides.
567
+ * Add: targetWidth property to core level (backwards compatible with FullWidthPlugin implementation)
568
+ * Fix: Scroll snapping for FullWidthPlugin
569
+ * Fix: Possible issues where plugin changed some details and that was not applied for first render
570
+ * Fix: Rendering issue where transition on slides could prevent calculations initially from working
571
+
572
+ ### 4.0.0
573
+
574
+ * Add: AutoPlayPlugin to allow auto-playing slides
575
+ * Add: Mixins that can be imported to SCSS projects
576
+ * Add: CSS variable: `--slider-container-height`
577
+ * Add: CSS variable: `--slider-x-offset`
578
+ * Add: Option `cssVariableContainer` to expose CSS variables for example higher container
579
+ * Add: `canMoveToSlide` method to check if slider can move to a specific slide (does it exist, is it already in view)
580
+ * 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)
581
+ * Fix: Export TypeScript types properly from core and plugins to be available automatically
582
+ * Fix: ScrollIndicatorPlugin click to scroll bar didn't always detect click position correctly
583
+ * Fix: snapToClosestSlide method edge cases on DragScrollingPlugin sometimes not snapping on right slide
584
+
460
585
  ### 3.3.1
461
586
 
462
587
  * Fix: FullWidthPlugin margin calculation not being run if there's too few slides for overflow and you resize screen without container width changing
@@ -0,0 +1 @@
1
+ export { default as OverflowSlider } from './plugins/core/index.d2.ts';