gatsby-core-theme 30.0.21 → 30.0.22

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [30.0.22](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/compare/v30.0.21...v30.0.22) (2023-11-22)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * add scroll event ([eee64c4](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/commit/eee64c4f48461b246a1420749fa2bb93d7c3f0f5))
7
+
1
8
  ## [30.0.21](https://git.ilcd.rocks/team-floyd/themes/gatsby-themes/compare/v30.0.20...v30.0.21) (2023-11-21)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gatsby-core-theme",
3
- "version": "30.0.21",
3
+ "version": "30.0.22",
4
4
  "description": "Gatsby Theme NPM Package",
5
5
  "author": "",
6
6
  "license": "ISC",
@@ -1,8 +1,14 @@
1
+ /* eslint-disable react-hooks/exhaustive-deps */
1
2
  import React, { useEffect } from 'react';
2
3
  import PropTypes from 'prop-types';
3
4
 
4
- // eslint-disable-next-line react/prop-types
5
- const ScrollX = ({ children, refTag = {}, scroll = false, stopScrolling = () => {} }) => {
5
+ const ScrollX = ({
6
+ children,
7
+ refTag = {},
8
+ scroll = false,
9
+ stopScrolling = () => {},
10
+ onScroll = () => {},
11
+ }) => {
6
12
  let pos = { top: 0, left: 0, x: 0, y: 0 };
7
13
 
8
14
  const preventDefaultEvents = (e) => {
@@ -53,14 +59,22 @@ const ScrollX = ({ children, refTag = {}, scroll = false, stopScrolling = () =>
53
59
  refTag.current.addEventListener('mouseleave', mouseUp);
54
60
  };
55
61
 
62
+ const handleScroll = () => {
63
+ onScroll(refTag.current.scrollLeft);
64
+ };
65
+
56
66
  useEffect(() => {
57
67
  if (scroll) {
58
68
  refTag.current.style.cursor = 'grab';
59
69
  refTag.current.addEventListener('mousedown', mouseDown);
70
+ refTag.current.addEventListener('scroll', handleScroll);
60
71
  }
61
72
 
62
- // eslint-disable-next-line react-hooks/exhaustive-deps
63
- }, []);
73
+ return () => {
74
+ refTag.current?.removeEventListener('mousedown', mouseDown);
75
+ refTag.current?.removeEventListener('scroll', handleScroll);
76
+ };
77
+ }, [scroll]);
64
78
 
65
79
  return <>{children}</>;
66
80
  };
@@ -69,6 +83,8 @@ ScrollX.propTypes = {
69
83
  children: PropTypes.node,
70
84
  refTag: PropTypes.shape({}),
71
85
  scroll: PropTypes.bool,
86
+ onScroll: PropTypes.func,
87
+ stopScrolling: PropTypes.func,
72
88
  };
73
89
 
74
90
  export default ScrollX;