@yoursurprise/slider 0.0.1 → 0.0.3
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 +53 -0
- package/dist/cjs/{src/Slider.d.ts → Slider.d.ts} +0 -0
- package/dist/cjs/{src/Slider.test.d.ts → Slider.test.d.ts} +0 -0
- package/dist/cjs/{src/index.d.ts → index.d.ts} +1 -1
- package/dist/cjs/index.js +173 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/{src/Slider.d.ts → Slider.d.ts} +0 -0
- package/dist/esm/{src/Slider.test.d.ts → Slider.test.d.ts} +0 -0
- package/dist/esm/{src/index.d.ts → index.d.ts} +1 -1
- package/dist/esm/index.js +171 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +8 -2
- package/src/index.ts +1 -1
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -45
- package/.github/workflows/lint.yml +0 -18
- package/.github/workflows/publish.yml +0 -23
- package/babel.config.js +0 -7
- package/dist/cjs/jest.config.d.ts +0 -3
- package/dist/esm/jest.config.d.ts +0 -3
- package/jest.config.ts +0 -54
- package/rollup.config.js +0 -38
- package/tsconfig.json +0 -17
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# React slider
|
|
2
|
+
|
|
3
|
+
This package contains a basic modern slider. The purpose of this slider is to provide a simple React component
|
|
4
|
+
which can be controlled in a userfriendly way on mobile, tablet and desktop.
|
|
5
|
+
|
|
6
|
+
This slider has the following features:
|
|
7
|
+
|
|
8
|
+
- Free scroll on mobile with native CSS scroll snapping
|
|
9
|
+
- Drag to scroll on devices with a mouse
|
|
10
|
+
- Buttons to navigate on devices with a mouse
|
|
11
|
+
- Support for multiple variable width slides
|
|
12
|
+
|
|
13
|
+
Before using this slider, please consider the following:
|
|
14
|
+
- The slider only contains styling to make it functional
|
|
15
|
+
- There is no configuration of aforementioned features (yet)
|
|
16
|
+
|
|
17
|
+
All browsers with [IntersectionObserver](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) are supported.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
### npm
|
|
22
|
+
|
|
23
|
+
`npm install @yoursurprisecom/slider --save`
|
|
24
|
+
|
|
25
|
+
### yarn
|
|
26
|
+
|
|
27
|
+
`yarn add @yoursurprisecom/slider`
|
|
28
|
+
|
|
29
|
+
### Import the CSS files
|
|
30
|
+
|
|
31
|
+
`import "@yoursurprisecom/slider/dist/index.css";`
|
|
32
|
+
|
|
33
|
+
### Implement the Slider
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
import Slider from '@yoursurprisecom/slider';
|
|
37
|
+
import '@yoursurprisecom/slider/dist/index.css';
|
|
38
|
+
|
|
39
|
+
export default function YourComponent() {
|
|
40
|
+
return (
|
|
41
|
+
<Slider>
|
|
42
|
+
<div>1</div>
|
|
43
|
+
<div>2</div>
|
|
44
|
+
<div>3</div>
|
|
45
|
+
<div>4</div>
|
|
46
|
+
</Slider>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
File without changes
|
|
File without changes
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Slider } from './Slider';
|
|
2
|
-
export
|
|
2
|
+
export { Slider };
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,2 +1,174 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
|
|
6
|
+
var Visbility;
|
|
7
|
+
(function (Visbility) {
|
|
8
|
+
Visbility[Visbility["FULL"] = 0] = "FULL";
|
|
9
|
+
Visbility[Visbility["PARTIAL"] = 1] = "PARTIAL";
|
|
10
|
+
Visbility[Visbility["NONE"] = 2] = "NONE";
|
|
11
|
+
})(Visbility || (Visbility = {}));
|
|
12
|
+
var NavigationDirection;
|
|
13
|
+
(function (NavigationDirection) {
|
|
14
|
+
NavigationDirection[NavigationDirection["PREV"] = 0] = "PREV";
|
|
15
|
+
NavigationDirection[NavigationDirection["NEXT"] = 1] = "NEXT";
|
|
16
|
+
})(NavigationDirection || (NavigationDirection = {}));
|
|
17
|
+
const Slider = ({ children }) => {
|
|
18
|
+
const slides = react.useRef([]);
|
|
19
|
+
const wrapper = react.useRef(null);
|
|
20
|
+
const visibleSlideIndices = react.useRef([]);
|
|
21
|
+
const partiallyVisibleSlideIndices = react.useRef([]);
|
|
22
|
+
const [isScrollable, setIsScrollable] = react.useState(false);
|
|
23
|
+
const [isDragging, setIsDragging] = react.useState(false);
|
|
24
|
+
const [isBlockingClicks, setIsBlockingClicks] = react.useState(false);
|
|
25
|
+
const [mousePosition, setMousePosition] = react.useState({
|
|
26
|
+
clientX: 0,
|
|
27
|
+
scrollX: 0,
|
|
28
|
+
});
|
|
29
|
+
const arrowPrevRef = react.useRef(null);
|
|
30
|
+
const arrowNextRef = react.useRef(null);
|
|
31
|
+
react.useEffect(() => {
|
|
32
|
+
const currentWrapper = wrapper.current;
|
|
33
|
+
if (!currentWrapper) {
|
|
34
|
+
return () => { };
|
|
35
|
+
}
|
|
36
|
+
const checkScrollable = () => setIsScrollable(currentWrapper.classList.toggle('is-scrollable', currentWrapper.scrollWidth > currentWrapper.clientWidth));
|
|
37
|
+
window?.addEventListener('resize', checkScrollable);
|
|
38
|
+
checkScrollable();
|
|
39
|
+
return () => {
|
|
40
|
+
window?.removeEventListener('resize', checkScrollable);
|
|
41
|
+
};
|
|
42
|
+
}, [wrapper]);
|
|
43
|
+
react.useEffect(() => {
|
|
44
|
+
wrapper.current?.classList.toggle('is-scrollable', isScrollable);
|
|
45
|
+
}, [isScrollable]);
|
|
46
|
+
react.useEffect(() => {
|
|
47
|
+
wrapper.current?.classList.toggle('is-dragging', isDragging);
|
|
48
|
+
const onDocumentMouseUp = (event) => {
|
|
49
|
+
event.stopPropagation();
|
|
50
|
+
event.preventDefault();
|
|
51
|
+
setIsBlockingClicks(false);
|
|
52
|
+
setIsDragging(false);
|
|
53
|
+
};
|
|
54
|
+
if (isDragging) {
|
|
55
|
+
document?.addEventListener('mouseup', onDocumentMouseUp);
|
|
56
|
+
}
|
|
57
|
+
return () => {
|
|
58
|
+
document?.removeEventListener('mouseup', onDocumentMouseUp);
|
|
59
|
+
};
|
|
60
|
+
}, [isDragging]);
|
|
61
|
+
const blockChildClickHandler = (event) => {
|
|
62
|
+
if (isBlockingClicks) {
|
|
63
|
+
event.stopPropagation();
|
|
64
|
+
event.preventDefault();
|
|
65
|
+
}
|
|
66
|
+
setIsBlockingClicks(false);
|
|
67
|
+
};
|
|
68
|
+
const mouseUpHandler = () => {
|
|
69
|
+
setIsDragging(false);
|
|
70
|
+
};
|
|
71
|
+
const mouseDownHandler = (event) => {
|
|
72
|
+
setMousePosition({
|
|
73
|
+
...mousePosition,
|
|
74
|
+
clientX: event.clientX,
|
|
75
|
+
scrollX: wrapper.current?.scrollLeft ?? 0,
|
|
76
|
+
});
|
|
77
|
+
setIsDragging(true);
|
|
78
|
+
};
|
|
79
|
+
const mouseMoveHandler = (event) => {
|
|
80
|
+
if (!wrapper.current || !isDragging) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (Math.abs(mousePosition.clientX - event.clientX) > 5) {
|
|
84
|
+
setIsBlockingClicks(true);
|
|
85
|
+
}
|
|
86
|
+
wrapper.current.scrollLeft = mousePosition.scrollX + mousePosition.clientX - event.clientX;
|
|
87
|
+
};
|
|
88
|
+
const addSlide = (node, index) => {
|
|
89
|
+
slides.current[index] = {
|
|
90
|
+
element: node,
|
|
91
|
+
visibility: Visbility.NONE,
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
const getFirstVisibleSlideIndex = () => visibleSlideIndices.current[0] ?? partiallyVisibleSlideIndices.current[0] ?? -1;
|
|
95
|
+
const getLastVisibleSlideIndex = () => visibleSlideIndices.current[visibleSlideIndices.current.length - 1]
|
|
96
|
+
?? partiallyVisibleSlideIndices.current[partiallyVisibleSlideIndices.current.length - 1] ?? -1;
|
|
97
|
+
const setControlsVisibility = react.useCallback(() => {
|
|
98
|
+
const lastSlideFullyVisible = getLastVisibleSlideIndex() + 1 === slides.current.length;
|
|
99
|
+
const moreContentAvailable = isScrollable && lastSlideFullyVisible === false;
|
|
100
|
+
const previousContentAvailable = getFirstVisibleSlideIndex() > 0 && isScrollable;
|
|
101
|
+
if (arrowNextRef.current && arrowPrevRef.current) {
|
|
102
|
+
arrowNextRef.current.classList.toggle('hidden', moreContentAvailable === false);
|
|
103
|
+
arrowNextRef.current.ariaHidden = String(moreContentAvailable === false);
|
|
104
|
+
arrowPrevRef.current.classList.toggle('hidden', previousContentAvailable === false);
|
|
105
|
+
arrowPrevRef.current.ariaHidden = String(previousContentAvailable === false);
|
|
106
|
+
}
|
|
107
|
+
}, [isScrollable]);
|
|
108
|
+
const getVisibilityByIntersectionRatio = (intersectionRatio) => {
|
|
109
|
+
if (intersectionRatio >= 0.9) {
|
|
110
|
+
return Visbility.FULL;
|
|
111
|
+
}
|
|
112
|
+
if (intersectionRatio >= 0.5) {
|
|
113
|
+
return Visbility.PARTIAL;
|
|
114
|
+
}
|
|
115
|
+
return Visbility.NONE;
|
|
116
|
+
};
|
|
117
|
+
react.useEffect(() => {
|
|
118
|
+
if (!wrapper.current) {
|
|
119
|
+
return () => { };
|
|
120
|
+
}
|
|
121
|
+
setControlsVisibility();
|
|
122
|
+
const intersectionCallback = (entries) => {
|
|
123
|
+
entries.forEach((entry) => {
|
|
124
|
+
const target = entry.target;
|
|
125
|
+
const index = Number(target.dataset.slideIndex);
|
|
126
|
+
if (getVisibilityByIntersectionRatio(entry.intersectionRatio) === Visbility.FULL) {
|
|
127
|
+
visibleSlideIndices.current.push(index);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
visibleSlideIndices.current = visibleSlideIndices.current.filter((slideIndex) => slideIndex !== index);
|
|
131
|
+
}
|
|
132
|
+
if (getVisibilityByIntersectionRatio(entry.intersectionRatio) === Visbility.PARTIAL) {
|
|
133
|
+
partiallyVisibleSlideIndices.current.push(index);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
partiallyVisibleSlideIndices.current = partiallyVisibleSlideIndices.current.filter((slideIndex) => slideIndex !== index);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
visibleSlideIndices.current = [...new Set(visibleSlideIndices.current)].sort((a, b) => a - b);
|
|
140
|
+
partiallyVisibleSlideIndices.current = [...new Set(partiallyVisibleSlideIndices.current)].sort((a, b) => a - b);
|
|
141
|
+
setControlsVisibility();
|
|
142
|
+
};
|
|
143
|
+
const intersectionObserver = new IntersectionObserver(intersectionCallback, {
|
|
144
|
+
root: wrapper.current,
|
|
145
|
+
threshold: [0, 0.5, 0.9],
|
|
146
|
+
});
|
|
147
|
+
slides.current.forEach(({ element }) => intersectionObserver.observe(element));
|
|
148
|
+
return () => intersectionObserver.disconnect();
|
|
149
|
+
}, [wrapper, setControlsVisibility]);
|
|
150
|
+
const navigate = (direction) => {
|
|
151
|
+
if (!wrapper.current) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const targetSlideIndex = direction === NavigationDirection.PREV ? getFirstVisibleSlideIndex() - 1 : getLastVisibleSlideIndex() + 1;
|
|
155
|
+
const targetSlide = slides.current[targetSlideIndex];
|
|
156
|
+
let scrollLeft = 0;
|
|
157
|
+
if (!targetSlide) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (direction === NavigationDirection.PREV) {
|
|
161
|
+
scrollLeft = targetSlide.element.offsetLeft - wrapper.current.offsetLeft - wrapper.current.clientWidth + targetSlide.element.clientWidth;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
scrollLeft = targetSlide.element.offsetLeft - wrapper.current.offsetLeft;
|
|
165
|
+
}
|
|
166
|
+
wrapper.current.scrollTo({ behavior: 'smooth', left: scrollLeft, top: 0 });
|
|
167
|
+
};
|
|
168
|
+
return (jsxRuntime.jsxs("div", { className: "slider", children: [jsxRuntime.jsx("div", { className: "slider__wrapper", role: "list", ref: wrapper, onMouseDown: mouseDownHandler, onMouseMove: mouseMoveHandler, onMouseUp: mouseUpHandler, onClickCapture: blockChildClickHandler, children: react.Children.map(children, (child, index) => (jsxRuntime.jsx("div", { className: "slider__wrapper__slide", role: "listitem", "data-slide-index": index, ref: (node) => { if (node) {
|
|
169
|
+
addSlide(node, index);
|
|
170
|
+
} }, children: child }, index))) }), jsxRuntime.jsx("button", { "aria-label": "Previous slide", type: "button", onClick: () => navigate(NavigationDirection.PREV), ref: arrowPrevRef, className: "slider__button slider__button--prev button button--ghost button--clean button--has-icon hidden", children: jsxRuntime.jsx("i", { className: "icon-chevron-left" }) }), jsxRuntime.jsx("button", { "aria-label": "Next slide", type: "button", onClick: () => navigate(NavigationDirection.NEXT), ref: arrowNextRef, className: "slider__button slider__button--next button button--ghost button--clean button--has-icon hidden", children: jsxRuntime.jsx("i", { className: "icon-chevron-right" }) })] }));
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
exports.Slider = Slider;
|
|
2
174
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/Slider.tsx"],"sourcesContent":[null],"names":["useRef","useState","useEffect","useCallback","_jsxs","_jsx","Children"],"mappings":";;;;;AAKA,IAAK,SAIJ,CAAA;AAJD,CAAA,UAAK,SAAS,EAAA;AACV,IAAA,SAAA,CAAA,SAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAI,CAAA;AACJ,IAAA,SAAA,CAAA,SAAA,CAAA,SAAA,CAAA,GAAA,CAAA,CAAA,GAAA,SAAO,CAAA;AACP,IAAA,SAAA,CAAA,SAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CA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AAA,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAAE,qBAAA,EAAE,EAC/I,QAAA,EAAA,KAAK,EADmD,EAAA,KAAK,CAE5D,CACT,CAAC,EACA,CAAA,EACNA,yCACe,gBAAgB,EAC3B,IAAI,EAAC,QAAQ,EACb,OAAO,EAAE,MAAM,QAAQ,CAAC,mBAAmB,CAAC,IAAI,CAAC,EACjD,GAAG,EAAE,YAAY,EACjB,SAAS,EAAC,gGAAgG,YAE1GA,cAAG,CAAA,GAAA,EAAA,EAAA,SAAS,EAAC,mBAAmB,GAAE,EAC7B,CAAA,EACTA,cACe,CAAA,QAAA,EAAA,EAAA,YAAA,EAAA,YAAY,EACvB,IAAI,EAAC,QAAQ,EACb,OAAO,EAAE,MAAM,QAAQ,CAAC,mBAAmB,CAAC,IAAI,CAAC,EACjD,GAAG,EAAE,YAAY,EACjB,SAAS,EAAC,gGAAgG,EAE1G,QAAA,EAAAA,cAAA,CAAA,GAAA,EAAA,EAAG,SAAS,EAAC,oBAAoB,GAAE,EAC9B,CAAA,CAAA,EAAA,CACP,EACR;AACN;;;;"}
|
|
File without changes
|
|
File without changes
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Slider } from './Slider';
|
|
2
|
-
export
|
|
2
|
+
export { Slider };
|
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,172 @@
|
|
|
1
|
-
import{jsxs
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useRef, useState, useEffect, useCallback, Children } from 'react';
|
|
3
|
+
|
|
4
|
+
var Visbility;
|
|
5
|
+
(function (Visbility) {
|
|
6
|
+
Visbility[Visbility["FULL"] = 0] = "FULL";
|
|
7
|
+
Visbility[Visbility["PARTIAL"] = 1] = "PARTIAL";
|
|
8
|
+
Visbility[Visbility["NONE"] = 2] = "NONE";
|
|
9
|
+
})(Visbility || (Visbility = {}));
|
|
10
|
+
var NavigationDirection;
|
|
11
|
+
(function (NavigationDirection) {
|
|
12
|
+
NavigationDirection[NavigationDirection["PREV"] = 0] = "PREV";
|
|
13
|
+
NavigationDirection[NavigationDirection["NEXT"] = 1] = "NEXT";
|
|
14
|
+
})(NavigationDirection || (NavigationDirection = {}));
|
|
15
|
+
const Slider = ({ children }) => {
|
|
16
|
+
const slides = useRef([]);
|
|
17
|
+
const wrapper = useRef(null);
|
|
18
|
+
const visibleSlideIndices = useRef([]);
|
|
19
|
+
const partiallyVisibleSlideIndices = useRef([]);
|
|
20
|
+
const [isScrollable, setIsScrollable] = useState(false);
|
|
21
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
22
|
+
const [isBlockingClicks, setIsBlockingClicks] = useState(false);
|
|
23
|
+
const [mousePosition, setMousePosition] = useState({
|
|
24
|
+
clientX: 0,
|
|
25
|
+
scrollX: 0,
|
|
26
|
+
});
|
|
27
|
+
const arrowPrevRef = useRef(null);
|
|
28
|
+
const arrowNextRef = useRef(null);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const currentWrapper = wrapper.current;
|
|
31
|
+
if (!currentWrapper) {
|
|
32
|
+
return () => { };
|
|
33
|
+
}
|
|
34
|
+
const checkScrollable = () => setIsScrollable(currentWrapper.classList.toggle('is-scrollable', currentWrapper.scrollWidth > currentWrapper.clientWidth));
|
|
35
|
+
window?.addEventListener('resize', checkScrollable);
|
|
36
|
+
checkScrollable();
|
|
37
|
+
return () => {
|
|
38
|
+
window?.removeEventListener('resize', checkScrollable);
|
|
39
|
+
};
|
|
40
|
+
}, [wrapper]);
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
wrapper.current?.classList.toggle('is-scrollable', isScrollable);
|
|
43
|
+
}, [isScrollable]);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
wrapper.current?.classList.toggle('is-dragging', isDragging);
|
|
46
|
+
const onDocumentMouseUp = (event) => {
|
|
47
|
+
event.stopPropagation();
|
|
48
|
+
event.preventDefault();
|
|
49
|
+
setIsBlockingClicks(false);
|
|
50
|
+
setIsDragging(false);
|
|
51
|
+
};
|
|
52
|
+
if (isDragging) {
|
|
53
|
+
document?.addEventListener('mouseup', onDocumentMouseUp);
|
|
54
|
+
}
|
|
55
|
+
return () => {
|
|
56
|
+
document?.removeEventListener('mouseup', onDocumentMouseUp);
|
|
57
|
+
};
|
|
58
|
+
}, [isDragging]);
|
|
59
|
+
const blockChildClickHandler = (event) => {
|
|
60
|
+
if (isBlockingClicks) {
|
|
61
|
+
event.stopPropagation();
|
|
62
|
+
event.preventDefault();
|
|
63
|
+
}
|
|
64
|
+
setIsBlockingClicks(false);
|
|
65
|
+
};
|
|
66
|
+
const mouseUpHandler = () => {
|
|
67
|
+
setIsDragging(false);
|
|
68
|
+
};
|
|
69
|
+
const mouseDownHandler = (event) => {
|
|
70
|
+
setMousePosition({
|
|
71
|
+
...mousePosition,
|
|
72
|
+
clientX: event.clientX,
|
|
73
|
+
scrollX: wrapper.current?.scrollLeft ?? 0,
|
|
74
|
+
});
|
|
75
|
+
setIsDragging(true);
|
|
76
|
+
};
|
|
77
|
+
const mouseMoveHandler = (event) => {
|
|
78
|
+
if (!wrapper.current || !isDragging) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (Math.abs(mousePosition.clientX - event.clientX) > 5) {
|
|
82
|
+
setIsBlockingClicks(true);
|
|
83
|
+
}
|
|
84
|
+
wrapper.current.scrollLeft = mousePosition.scrollX + mousePosition.clientX - event.clientX;
|
|
85
|
+
};
|
|
86
|
+
const addSlide = (node, index) => {
|
|
87
|
+
slides.current[index] = {
|
|
88
|
+
element: node,
|
|
89
|
+
visibility: Visbility.NONE,
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
const getFirstVisibleSlideIndex = () => visibleSlideIndices.current[0] ?? partiallyVisibleSlideIndices.current[0] ?? -1;
|
|
93
|
+
const getLastVisibleSlideIndex = () => visibleSlideIndices.current[visibleSlideIndices.current.length - 1]
|
|
94
|
+
?? partiallyVisibleSlideIndices.current[partiallyVisibleSlideIndices.current.length - 1] ?? -1;
|
|
95
|
+
const setControlsVisibility = useCallback(() => {
|
|
96
|
+
const lastSlideFullyVisible = getLastVisibleSlideIndex() + 1 === slides.current.length;
|
|
97
|
+
const moreContentAvailable = isScrollable && lastSlideFullyVisible === false;
|
|
98
|
+
const previousContentAvailable = getFirstVisibleSlideIndex() > 0 && isScrollable;
|
|
99
|
+
if (arrowNextRef.current && arrowPrevRef.current) {
|
|
100
|
+
arrowNextRef.current.classList.toggle('hidden', moreContentAvailable === false);
|
|
101
|
+
arrowNextRef.current.ariaHidden = String(moreContentAvailable === false);
|
|
102
|
+
arrowPrevRef.current.classList.toggle('hidden', previousContentAvailable === false);
|
|
103
|
+
arrowPrevRef.current.ariaHidden = String(previousContentAvailable === false);
|
|
104
|
+
}
|
|
105
|
+
}, [isScrollable]);
|
|
106
|
+
const getVisibilityByIntersectionRatio = (intersectionRatio) => {
|
|
107
|
+
if (intersectionRatio >= 0.9) {
|
|
108
|
+
return Visbility.FULL;
|
|
109
|
+
}
|
|
110
|
+
if (intersectionRatio >= 0.5) {
|
|
111
|
+
return Visbility.PARTIAL;
|
|
112
|
+
}
|
|
113
|
+
return Visbility.NONE;
|
|
114
|
+
};
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
if (!wrapper.current) {
|
|
117
|
+
return () => { };
|
|
118
|
+
}
|
|
119
|
+
setControlsVisibility();
|
|
120
|
+
const intersectionCallback = (entries) => {
|
|
121
|
+
entries.forEach((entry) => {
|
|
122
|
+
const target = entry.target;
|
|
123
|
+
const index = Number(target.dataset.slideIndex);
|
|
124
|
+
if (getVisibilityByIntersectionRatio(entry.intersectionRatio) === Visbility.FULL) {
|
|
125
|
+
visibleSlideIndices.current.push(index);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
visibleSlideIndices.current = visibleSlideIndices.current.filter((slideIndex) => slideIndex !== index);
|
|
129
|
+
}
|
|
130
|
+
if (getVisibilityByIntersectionRatio(entry.intersectionRatio) === Visbility.PARTIAL) {
|
|
131
|
+
partiallyVisibleSlideIndices.current.push(index);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
partiallyVisibleSlideIndices.current = partiallyVisibleSlideIndices.current.filter((slideIndex) => slideIndex !== index);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
visibleSlideIndices.current = [...new Set(visibleSlideIndices.current)].sort((a, b) => a - b);
|
|
138
|
+
partiallyVisibleSlideIndices.current = [...new Set(partiallyVisibleSlideIndices.current)].sort((a, b) => a - b);
|
|
139
|
+
setControlsVisibility();
|
|
140
|
+
};
|
|
141
|
+
const intersectionObserver = new IntersectionObserver(intersectionCallback, {
|
|
142
|
+
root: wrapper.current,
|
|
143
|
+
threshold: [0, 0.5, 0.9],
|
|
144
|
+
});
|
|
145
|
+
slides.current.forEach(({ element }) => intersectionObserver.observe(element));
|
|
146
|
+
return () => intersectionObserver.disconnect();
|
|
147
|
+
}, [wrapper, setControlsVisibility]);
|
|
148
|
+
const navigate = (direction) => {
|
|
149
|
+
if (!wrapper.current) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const targetSlideIndex = direction === NavigationDirection.PREV ? getFirstVisibleSlideIndex() - 1 : getLastVisibleSlideIndex() + 1;
|
|
153
|
+
const targetSlide = slides.current[targetSlideIndex];
|
|
154
|
+
let scrollLeft = 0;
|
|
155
|
+
if (!targetSlide) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (direction === NavigationDirection.PREV) {
|
|
159
|
+
scrollLeft = targetSlide.element.offsetLeft - wrapper.current.offsetLeft - wrapper.current.clientWidth + targetSlide.element.clientWidth;
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
scrollLeft = targetSlide.element.offsetLeft - wrapper.current.offsetLeft;
|
|
163
|
+
}
|
|
164
|
+
wrapper.current.scrollTo({ behavior: 'smooth', left: scrollLeft, top: 0 });
|
|
165
|
+
};
|
|
166
|
+
return (jsxs("div", { className: "slider", children: [jsx("div", { className: "slider__wrapper", role: "list", ref: wrapper, onMouseDown: mouseDownHandler, onMouseMove: mouseMoveHandler, onMouseUp: mouseUpHandler, onClickCapture: blockChildClickHandler, children: Children.map(children, (child, index) => (jsx("div", { className: "slider__wrapper__slide", role: "listitem", "data-slide-index": index, ref: (node) => { if (node) {
|
|
167
|
+
addSlide(node, index);
|
|
168
|
+
} }, children: child }, index))) }), jsx("button", { "aria-label": "Previous slide", type: "button", onClick: () => navigate(NavigationDirection.PREV), ref: arrowPrevRef, className: "slider__button slider__button--prev button button--ghost button--clean button--has-icon hidden", children: jsx("i", { className: "icon-chevron-left" }) }), jsx("button", { "aria-label": "Next slide", type: "button", onClick: () => navigate(NavigationDirection.NEXT), ref: arrowNextRef, className: "slider__button slider__button--next button button--ghost button--clean button--has-icon hidden", children: jsx("i", { className: "icon-chevron-right" }) })] }));
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
export { Slider };
|
|
2
172
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/Slider.tsx"],"sourcesContent":[null],"names":["_jsxs","_jsx"],"mappings":";;;AAKA,IAAK,SAIJ,CAAA;AAJD,CAAA,UAAK,SAAS,EAAA;AACV,IAAA,SAAA,CAAA,SAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAI,CAAA;AACJ,IAAA,SAAA,CAAA,SAAA,CAAA,SAAA,CAAA,GAAA,CAAA,CAAA,GAAA,SAAO,CAAA;AACP,IAAA,SAAA,CAAA,SAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAI,CAAA;AACR,CAAC,EAJI,SAAS,KAAT,SAAS,GAIb,EAAA,CAAA,CAAA,CAAA;AAED,IAAK,mBAGJ,CAAA;AAHD,CAAA,UAAK,mBAAmB,EAAA;AACpB,IAAA,mBAAA,CAAA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,OAAO,EAAE,MAAM,QAAQ,CAAC,mBAAmB,CAAC,IAAI,CAAC,EACjD,GAAG,EAAE,YAAY,EACjB,SAAS,EAAC,gGAAgG,YAE1GA,GAAG,CAAA,GAAA,EAAA,EAAA,SAAS,EAAC,mBAAmB,GAAE,EAC7B,CAAA,EACTA,GACe,CAAA,QAAA,EAAA,EAAA,YAAA,EAAA,YAAY,EACvB,IAAI,EAAC,QAAQ,EACb,OAAO,EAAE,MAAM,QAAQ,CAAC,mBAAmB,CAAC,IAAI,CAAC,EACjD,GAAG,EAAE,YAAY,EACjB,SAAS,EAAC,gGAAgG,EAE1G,QAAA,EAAAA,GAAA,CAAA,GAAA,EAAA,EAAG,SAAS,EAAC,oBAAoB,GAAE,EAC9B,CAAA,CAAA,EAAA,CACP,EACR;AACN;;;;"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yoursurprise/slider",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Basic React slider using modern Javascript and CSS",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"files": [
|
|
9
|
+
"src/*",
|
|
10
|
+
"dist/*"
|
|
11
|
+
],
|
|
7
12
|
"peerDependencies": {
|
|
8
13
|
"react": "^18.2.0"
|
|
9
14
|
},
|
|
@@ -59,7 +64,8 @@
|
|
|
59
64
|
"slider",
|
|
60
65
|
"scroll",
|
|
61
66
|
"snap",
|
|
62
|
-
"touch"
|
|
67
|
+
"touch",
|
|
68
|
+
"react"
|
|
63
69
|
],
|
|
64
70
|
"author": "YourSurprise",
|
|
65
71
|
"license": "ISC",
|
package/src/index.ts
CHANGED
package/.eslintignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
.eslintrc.js
|
package/.eslintrc.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
extends: [
|
|
3
|
-
'eslint:recommended',
|
|
4
|
-
'airbnb-typescript',
|
|
5
|
-
'airbnb/hooks',
|
|
6
|
-
'plugin:import/recommended',
|
|
7
|
-
],
|
|
8
|
-
rules: {
|
|
9
|
-
'react/jsx-indent': ['error', 4],
|
|
10
|
-
'react/jsx-indent-props': ['error', 4],
|
|
11
|
-
'react/jsx-props-no-spreading': ['error', { custom: 'ignore' }],
|
|
12
|
-
'react/prop-types': 'off',
|
|
13
|
-
'react/require-default-props': 'off',
|
|
14
|
-
'indent': ['error', 4, {SwitchCase: 1}],
|
|
15
|
-
'@typescript-eslint/indent': ['error', 4],
|
|
16
|
-
'import/no-extraneous-dependencies': [
|
|
17
|
-
'error',
|
|
18
|
-
{
|
|
19
|
-
devDependencies: [
|
|
20
|
-
'**/*.test.*',
|
|
21
|
-
'**/rollup.config.js*',
|
|
22
|
-
'**/babel.config.js*',
|
|
23
|
-
'**/jest.config.js*',
|
|
24
|
-
'**/[mM]ock[s?]/**'
|
|
25
|
-
]
|
|
26
|
-
}
|
|
27
|
-
],
|
|
28
|
-
|
|
29
|
-
},
|
|
30
|
-
plugins: ['react', "testing-library"],
|
|
31
|
-
env: {
|
|
32
|
-
browser: true,
|
|
33
|
-
es6: true,
|
|
34
|
-
node: true,
|
|
35
|
-
},
|
|
36
|
-
parser: '@typescript-eslint/parser',
|
|
37
|
-
parserOptions: {
|
|
38
|
-
project: ['./tsconfig.json'],
|
|
39
|
-
ecmaFeatures: {
|
|
40
|
-
jsx: true,
|
|
41
|
-
},
|
|
42
|
-
ecmaVersion: 'latest',
|
|
43
|
-
sourceType: 'module',
|
|
44
|
-
},
|
|
45
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
name: Lint
|
|
2
|
-
on:
|
|
3
|
-
push:
|
|
4
|
-
branches:
|
|
5
|
-
- main
|
|
6
|
-
pull_request:
|
|
7
|
-
jobs:
|
|
8
|
-
linting:
|
|
9
|
-
runs-on: ubuntu-latest
|
|
10
|
-
steps:
|
|
11
|
-
- name: Check out repository code
|
|
12
|
-
uses: actions/checkout@v3
|
|
13
|
-
- name: Install
|
|
14
|
-
run: npm ci
|
|
15
|
-
- name: Lint
|
|
16
|
-
run: npm run lint
|
|
17
|
-
- name: Test
|
|
18
|
-
run: npm run test -- --coverage
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
name: Publish
|
|
2
|
-
on:
|
|
3
|
-
release:
|
|
4
|
-
types: [created]
|
|
5
|
-
jobs:
|
|
6
|
-
publish:
|
|
7
|
-
runs-on: ubuntu-latest
|
|
8
|
-
steps:
|
|
9
|
-
- name: Check out repository code
|
|
10
|
-
uses: actions/checkout@v3
|
|
11
|
-
- name: Setup node
|
|
12
|
-
uses: actions/setup-node@v3
|
|
13
|
-
with:
|
|
14
|
-
node-version: '16.x'
|
|
15
|
-
registry-url: 'https://registry.npmjs.org'
|
|
16
|
-
- name: Install
|
|
17
|
-
run: npm ci
|
|
18
|
-
- name: Build
|
|
19
|
-
run: npm run build
|
|
20
|
-
- name: Publish
|
|
21
|
-
run: npm publish
|
|
22
|
-
env:
|
|
23
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/babel.config.js
DELETED
package/jest.config.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// For a detailed explanation regarding each configuration property, visit:
|
|
2
|
-
// https://jestjs.io/docs/en/configuration.html
|
|
3
|
-
|
|
4
|
-
import type { Config } from '@jest/types';
|
|
5
|
-
|
|
6
|
-
const config: Partial<Config.ConfigGlobals> = {
|
|
7
|
-
// Indicates whether the coverage information should be collected while executing the test
|
|
8
|
-
collectCoverage: false,
|
|
9
|
-
|
|
10
|
-
testEnvironment: 'jsdom',
|
|
11
|
-
|
|
12
|
-
// An array of glob patterns indicating a set of files for which coverage information should be collected
|
|
13
|
-
collectCoverageFrom: [
|
|
14
|
-
'src/**/*.{js,ts,tsx}',
|
|
15
|
-
],
|
|
16
|
-
|
|
17
|
-
// The directory where Jest should output its coverage files
|
|
18
|
-
coverageDirectory: 'coverage',
|
|
19
|
-
|
|
20
|
-
// A list of reporter names that Jest uses when writing coverage reports
|
|
21
|
-
coverageReporters: [
|
|
22
|
-
'cobertura',
|
|
23
|
-
'lcov',
|
|
24
|
-
'text',
|
|
25
|
-
],
|
|
26
|
-
|
|
27
|
-
coverageThreshold: {
|
|
28
|
-
global: {
|
|
29
|
-
branches: 80,
|
|
30
|
-
functions: 90,
|
|
31
|
-
lines: 90,
|
|
32
|
-
statements: 90,
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
// An array of directory names to be searched recursively up from the requiring module's location
|
|
37
|
-
moduleDirectories: [
|
|
38
|
-
'src',
|
|
39
|
-
'node_modules',
|
|
40
|
-
],
|
|
41
|
-
|
|
42
|
-
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
|
|
43
|
-
moduleNameMapper: {
|
|
44
|
-
'^.+\\.(css|scss|less|scss)$': '<rootDir>src/__mocks__/fileMock.js',
|
|
45
|
-
'^.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>src/__mocks__/fileMock.js',
|
|
46
|
-
} as unknown as Config.ProjectConfig['moduleNameMapper'],
|
|
47
|
-
|
|
48
|
-
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
|
|
49
|
-
testPathIgnorePatterns: [
|
|
50
|
-
'/node_modules/',
|
|
51
|
-
],
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export default config;
|
package/rollup.config.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import resolve from '@rollup/plugin-node-resolve';
|
|
2
|
-
import commonjs from '@rollup/plugin-commonjs';
|
|
3
|
-
import typescript from '@rollup/plugin-typescript';
|
|
4
|
-
import { terser } from 'rollup-plugin-terser';
|
|
5
|
-
import external from 'rollup-plugin-peer-deps-external';
|
|
6
|
-
import postcss from 'rollup-plugin-postcss';
|
|
7
|
-
|
|
8
|
-
const packageJson = require('./package.json');
|
|
9
|
-
|
|
10
|
-
export default {
|
|
11
|
-
input: 'src/index.ts',
|
|
12
|
-
output: [
|
|
13
|
-
{
|
|
14
|
-
file: packageJson.main,
|
|
15
|
-
format: 'cjs',
|
|
16
|
-
sourcemap: true,
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
file: packageJson.module,
|
|
20
|
-
format: 'esm',
|
|
21
|
-
sourcemap: true,
|
|
22
|
-
},
|
|
23
|
-
],
|
|
24
|
-
plugins: [
|
|
25
|
-
external(),
|
|
26
|
-
resolve(),
|
|
27
|
-
commonjs(),
|
|
28
|
-
typescript({
|
|
29
|
-
tsconfig: './tsconfig.json' }),
|
|
30
|
-
postcss({
|
|
31
|
-
extract: 'index.css',
|
|
32
|
-
minimize: true,
|
|
33
|
-
sourceMap: true,
|
|
34
|
-
}),
|
|
35
|
-
terser(),
|
|
36
|
-
],
|
|
37
|
-
};
|
|
38
|
-
|
package/tsconfig.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"sourceRoot": "./src",
|
|
4
|
-
"outDir": "dist",
|
|
5
|
-
"target": "ESNext",
|
|
6
|
-
"jsx": "react-jsx",
|
|
7
|
-
"moduleResolution": "node",
|
|
8
|
-
"module": "ESNext",
|
|
9
|
-
"noImplicitAny": true,
|
|
10
|
-
"removeComments": true,
|
|
11
|
-
"preserveConstEnums": true,
|
|
12
|
-
"sourceMap": true,
|
|
13
|
-
"allowSyntheticDefaultImports": true,
|
|
14
|
-
"emitDeclarationOnly": true,
|
|
15
|
-
"declaration": true
|
|
16
|
-
}
|
|
17
|
-
}
|