@evermade/overflow-slider 4.1.0 → 4.2.1
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.
- package/README.md +10 -0
- package/dist/index.esm.js +8 -3
- package/dist/index.esm.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/overflow-slider.css +1 -1
- package/dist/plugins/classnames/index.esm.js +0 -1
- package/dist/plugins/classnames/index.min.js +1 -1
- package/dist/plugins/core/index.d.ts +2 -0
- package/dist/plugins/core/index.d2.ts +2 -0
- package/dist/plugins/dots/index.d.ts +1 -0
- package/dist/plugins/dots/index.esm.js +39 -19
- package/dist/plugins/dots/index.min.js +1 -1
- package/docs/assets/demo.css +7 -0
- package/docs/assets/demo.js +40 -0
- package/docs/dist/index.esm.js +8 -3
- package/docs/dist/index.esm.js.map +1 -1
- package/docs/dist/index.min.js +1 -1
- package/docs/dist/index.min.js.map +1 -1
- package/docs/dist/overflow-slider.css +1 -1
- package/docs/dist/plugins/classnames/index.esm.js +0 -1
- package/docs/dist/plugins/classnames/index.min.js +1 -1
- package/docs/dist/plugins/core/index.d.ts +2 -0
- package/docs/dist/plugins/core/index.d2.ts +2 -0
- package/docs/dist/plugins/dots/index.d.ts +1 -0
- package/docs/dist/plugins/dots/index.esm.js +39 -19
- package/docs/dist/plugins/dots/index.min.js +1 -1
- package/docs/index.html +29 -1
- package/package.json +1 -1
- package/src/core/details.ts +6 -3
- package/src/core/slider.ts +2 -0
- package/src/core/types.ts +2 -0
- package/src/plugins/classnames/index.ts +0 -2
- package/src/plugins/dots/index.ts +39 -16
- package/src/plugins/dots/styles.scss +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Slider, DeepPartial } from '../../core/types';
|
|
2
2
|
|
|
3
3
|
export type DotsOptions = {
|
|
4
|
+
type: 'view' | 'slide';
|
|
4
5
|
texts: {
|
|
5
6
|
dotDescription: string;
|
|
6
7
|
},
|
|
@@ -23,6 +24,7 @@ const DEFAULT_CLASS_NAMES = {
|
|
|
23
24
|
export default function DotsPlugin( args?: DeepPartial<DotsOptions> ) {
|
|
24
25
|
return ( slider: Slider ) => {
|
|
25
26
|
const options = <DotsOptions>{
|
|
27
|
+
type: args?.type ?? 'slide',
|
|
26
28
|
texts: {
|
|
27
29
|
...DEFAULT_TEXTS,
|
|
28
30
|
...args?.texts || []
|
|
@@ -43,22 +45,24 @@ export default function DotsPlugin( args?: DeepPartial<DotsOptions> ) {
|
|
|
43
45
|
dots.setAttribute( 'data-has-content', slider.details.hasOverflow.toString() );
|
|
44
46
|
dots.innerHTML = '';
|
|
45
47
|
|
|
48
|
+
console.log('buildDots');
|
|
49
|
+
|
|
46
50
|
const dotsList = document.createElement( 'ul' );
|
|
47
51
|
|
|
48
|
-
const
|
|
49
|
-
const
|
|
52
|
+
const count = options.type === 'view' ? slider.details.amountOfPages : slider.details.slideCount;
|
|
53
|
+
const currentIndex = options.type === 'view' ? slider.details.currentPage : slider.activeSlideIdx;
|
|
50
54
|
|
|
51
|
-
if (
|
|
55
|
+
if ( count <= 1 ) {
|
|
52
56
|
return;
|
|
53
57
|
}
|
|
54
58
|
|
|
55
|
-
for ( let i = 0; i <
|
|
59
|
+
for ( let i = 0; i < count; i++ ) {
|
|
56
60
|
const dotListItem = document.createElement( 'li' );
|
|
57
61
|
const dot = document.createElement( 'button' );
|
|
58
62
|
dot.setAttribute( 'type', 'button' );
|
|
59
63
|
dot.setAttribute( 'class', options.classNames.dotsItem );
|
|
60
|
-
dot.setAttribute( 'aria-label', options.texts.dotDescription.replace( '%d', ( i + 1 ).toString() ).replace( '%d',
|
|
61
|
-
dot.setAttribute( 'aria-pressed', ( i ===
|
|
64
|
+
dot.setAttribute( 'aria-label', options.texts.dotDescription.replace( '%d', ( i + 1 ).toString() ).replace( '%d', count.toString() ) );
|
|
65
|
+
dot.setAttribute( 'aria-pressed', ( i === currentIndex ).toString() );
|
|
62
66
|
dot.setAttribute( 'data-item', ( i + 1 ).toString() );
|
|
63
67
|
dotListItem.appendChild( dot );
|
|
64
68
|
dotsList.appendChild( dotListItem );
|
|
@@ -71,23 +75,23 @@ export default function DotsPlugin( args?: DeepPartial<DotsOptions> ) {
|
|
|
71
75
|
}
|
|
72
76
|
const currentItem = parseInt( currentItemItem.getAttribute( 'data-item' ) ?? '1' );
|
|
73
77
|
if ( e.key === 'ArrowLeft' ) {
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
76
|
-
const matchingDot = dots.querySelector( `[data-item="${
|
|
78
|
+
const previousIndex = currentItem - 1;
|
|
79
|
+
if ( previousIndex > 0 ) {
|
|
80
|
+
const matchingDot = dots.querySelector( `[data-item="${previousIndex}"]` );
|
|
77
81
|
if ( matchingDot ) {
|
|
78
82
|
( <HTMLElement>matchingDot ).focus();
|
|
79
83
|
}
|
|
80
|
-
activateDot(
|
|
84
|
+
activateDot( previousIndex );
|
|
81
85
|
}
|
|
82
86
|
}
|
|
83
87
|
if ( e.key === 'ArrowRight' ) {
|
|
84
|
-
const
|
|
85
|
-
if (
|
|
86
|
-
const matchingDot = dots.querySelector( `[data-item="${
|
|
88
|
+
const nextIndex = currentItem + 1;
|
|
89
|
+
if ( nextIndex <= count ) {
|
|
90
|
+
const matchingDot = dots.querySelector( `[data-item="${nextIndex}"]` );
|
|
87
91
|
if ( matchingDot ) {
|
|
88
92
|
( <HTMLElement>matchingDot ).focus();
|
|
89
93
|
}
|
|
90
|
-
activateDot(
|
|
94
|
+
activateDot( nextIndex );
|
|
91
95
|
}
|
|
92
96
|
}
|
|
93
97
|
} );
|
|
@@ -103,9 +107,27 @@ export default function DotsPlugin( args?: DeepPartial<DotsOptions> ) {
|
|
|
103
107
|
}
|
|
104
108
|
}
|
|
105
109
|
};
|
|
110
|
+
const activateDot = ( index: number ) => {
|
|
111
|
+
console.log('activateDot', index, 'slider.details', slider.details);
|
|
112
|
+
|
|
113
|
+
if ( options.type === 'view' ) {
|
|
114
|
+
const count = slider.details.amountOfPages;
|
|
115
|
+
let targetPosition = slider.details.containerWidth * ( index - 1 );
|
|
116
|
+
|
|
117
|
+
// For the last page, scroll to the maximum scroll position to ensure it activates
|
|
118
|
+
if ( index === count ) {
|
|
119
|
+
const maxScroll = slider.details.scrollableAreaWidth - slider.details.containerWidth;
|
|
120
|
+
targetPosition = maxScroll;
|
|
121
|
+
}
|
|
106
122
|
|
|
107
|
-
|
|
108
|
-
|
|
123
|
+
const scrollLeft = slider.options.rtl ? -targetPosition : targetPosition;
|
|
124
|
+
slider.container.scrollTo({
|
|
125
|
+
left: scrollLeft,
|
|
126
|
+
behavior: slider.options.scrollBehavior as ScrollBehavior
|
|
127
|
+
});
|
|
128
|
+
} else {
|
|
129
|
+
slider.moveToSlide( index - 1 );
|
|
130
|
+
}
|
|
109
131
|
};
|
|
110
132
|
|
|
111
133
|
buildDots();
|
|
@@ -119,5 +141,6 @@ export default function DotsPlugin( args?: DeepPartial<DotsOptions> ) {
|
|
|
119
141
|
slider.on( 'scrollEnd', buildDots );
|
|
120
142
|
slider.on( 'contentsChanged', buildDots );
|
|
121
143
|
slider.on( 'containerSizeChanged', buildDots );
|
|
144
|
+
slider.on( 'detailsChanged', buildDots );
|
|
122
145
|
};
|
|
123
146
|
};
|