@telus-uds/components-community.sticky 1.6.4 → 1.7.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/CHANGELOG.md CHANGED
@@ -1,12 +1,34 @@
1
1
  # Change Log - @telus-uds/components-community.sticky
2
2
 
3
- This log was last generated on Sat, 12 Oct 2024 00:31:05 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 13 Nov 2024 17:18:39 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 1.7.1
8
+
9
+ Wed, 13 Nov 2024 17:18:39 GMT
10
+
11
+ ### Patches
12
+
13
+ - Bump @telus-uds/components-web to v2.44.0
14
+
15
+ ## 1.7.0
16
+
17
+ Thu, 31 Oct 2024 05:09:12 GMT
18
+
19
+ ### Minor changes
20
+
21
+ - Bump @telus-uds/components-base to v1.97.0
22
+ - Bump @telus-uds/system-theme-tokens to v2.66.0
23
+ - Bump @telus-uds/components-web to v2.43.0
24
+
25
+ ### Patches
26
+
27
+ - `Sticky`: Ability for the stickiness to start when the “top” or “bottom” comes off the screen, so that the stickiness is uniform regardless of whether the Sticky component is stuck to the top or bottom of a page. (patti.perlock2@telus.com)
28
+
7
29
  ## 1.6.4
8
30
 
9
- Sat, 12 Oct 2024 00:31:05 GMT
31
+ Sat, 12 Oct 2024 00:40:49 GMT
10
32
 
11
33
  ### Patches
12
34
 
package/lib/Sticky.js CHANGED
@@ -13,9 +13,6 @@ var _jsxRuntime = require("react/jsx-runtime");
13
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
14
  function createObserver(ref, callback) {
15
15
  let workWithViewport = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
16
- const options = {
17
- threshold: [1]
18
- };
19
16
  const observer = new IntersectionObserver(_ref => {
20
17
  let [e] = _ref;
21
18
  const isNotVisibleInViewport = e.intersectionRatio < 1;
@@ -27,7 +24,7 @@ function createObserver(ref, callback) {
27
24
  correctYPosition = y < 0;
28
25
  }
29
26
  callback(isNotVisibleInViewport && correctYPosition);
30
- }, options);
27
+ });
31
28
  observer.observe(ref.current);
32
29
  return observer;
33
30
  }
@@ -66,15 +63,16 @@ const Sticky = _ref2 => {
66
63
  const stickyWrapperRef = _react.default.useRef();
67
64
  const [observer, setObserver] = _react.default.useState();
68
65
  const onStickThrottled = (0, _lodash.default)(onStick, throttleTime, throttleConfig);
66
+ const sentinelPositionRef = position === 'top' ? sentinelTopRef : sentinelBottomRef;
69
67
  _react.default.useEffect(() => {
70
68
  if (observer) {
71
69
  observer.disconnect();
72
70
  }
73
71
  if (variant === 'default' || variant === 'hidden') {
74
- setObserver(createObserver(sentinelTopRef, intersected => {
72
+ setObserver(createObserver(sentinelPositionRef, intersected => {
75
73
  var _stickyWrapperRef$cur, _stickyWrapperRef$cur2;
76
74
  (_stickyWrapperRef$cur = stickyWrapperRef.current) === null || _stickyWrapperRef$cur === void 0 ? void 0 : _stickyWrapperRef$cur.classList.toggle('sticky-mode', intersected);
77
- (_stickyWrapperRef$cur2 = stickyWrapperRef.current) === null || _stickyWrapperRef$cur2 === void 0 ? void 0 : _stickyWrapperRef$cur2.classList.toggle('top', intersected);
75
+ (_stickyWrapperRef$cur2 = stickyWrapperRef.current) === null || _stickyWrapperRef$cur2 === void 0 ? void 0 : _stickyWrapperRef$cur2.classList.toggle(position, intersected);
78
76
  if (intersected) {
79
77
  var _stickyWrapperRef$cur3;
80
78
  (_stickyWrapperRef$cur3 = stickyWrapperRef.current) === null || _stickyWrapperRef$cur3 === void 0 ? void 0 : _stickyWrapperRef$cur3.classList.remove('pristine');
@@ -8,9 +8,6 @@ import { Fragment as _Fragment } from "react/jsx-runtime";
8
8
  import { jsxs as _jsxs } from "react/jsx-runtime";
9
9
  function createObserver(ref, callback) {
10
10
  let workWithViewport = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
11
- const options = {
12
- threshold: [1]
13
- };
14
11
  const observer = new IntersectionObserver(_ref => {
15
12
  let [e] = _ref;
16
13
  const isNotVisibleInViewport = e.intersectionRatio < 1;
@@ -22,7 +19,7 @@ function createObserver(ref, callback) {
22
19
  correctYPosition = y < 0;
23
20
  }
24
21
  callback(isNotVisibleInViewport && correctYPosition);
25
- }, options);
22
+ });
26
23
  observer.observe(ref.current);
27
24
  return observer;
28
25
  }
@@ -61,15 +58,16 @@ const Sticky = _ref2 => {
61
58
  const stickyWrapperRef = React.useRef();
62
59
  const [observer, setObserver] = React.useState();
63
60
  const onStickThrottled = throttle(onStick, throttleTime, throttleConfig);
61
+ const sentinelPositionRef = position === 'top' ? sentinelTopRef : sentinelBottomRef;
64
62
  React.useEffect(() => {
65
63
  if (observer) {
66
64
  observer.disconnect();
67
65
  }
68
66
  if (variant === 'default' || variant === 'hidden') {
69
- setObserver(createObserver(sentinelTopRef, intersected => {
67
+ setObserver(createObserver(sentinelPositionRef, intersected => {
70
68
  var _stickyWrapperRef$cur, _stickyWrapperRef$cur2;
71
69
  (_stickyWrapperRef$cur = stickyWrapperRef.current) === null || _stickyWrapperRef$cur === void 0 ? void 0 : _stickyWrapperRef$cur.classList.toggle('sticky-mode', intersected);
72
- (_stickyWrapperRef$cur2 = stickyWrapperRef.current) === null || _stickyWrapperRef$cur2 === void 0 ? void 0 : _stickyWrapperRef$cur2.classList.toggle('top', intersected);
70
+ (_stickyWrapperRef$cur2 = stickyWrapperRef.current) === null || _stickyWrapperRef$cur2 === void 0 ? void 0 : _stickyWrapperRef$cur2.classList.toggle(position, intersected);
73
71
  if (intersected) {
74
72
  var _stickyWrapperRef$cur3;
75
73
  (_stickyWrapperRef$cur3 = stickyWrapperRef.current) === null || _stickyWrapperRef$cur3 === void 0 ? void 0 : _stickyWrapperRef$cur3.classList.remove('pristine');
package/package.json CHANGED
@@ -4,15 +4,15 @@
4
4
  "extends @telus-uds/browserslist-config"
5
5
  ],
6
6
  "dependencies": {
7
- "@telus-uds/components-base": "1.96.0",
7
+ "@telus-uds/components-base": "1.97.0",
8
8
  "@telus-uds/system-constants": "^1.3.0",
9
- "@telus-uds/system-theme-tokens": "^2.65.0",
9
+ "@telus-uds/system-theme-tokens": "^2.66.0",
10
10
  "lodash.throttle": "^4.1.1",
11
11
  "prop-types": "^15.7.2",
12
12
  "styled-components": "^5.3.10"
13
13
  },
14
14
  "devDependencies": {
15
- "@telus-uds/components-web": "^2.42.0",
15
+ "@telus-uds/components-web": "^2.44.0",
16
16
  "@telus-uds/browserslist-config": "^1.0.5",
17
17
  "@testing-library/jest-dom": "^5.16.1",
18
18
  "@testing-library/react": "^13.3.0",
@@ -46,5 +46,5 @@
46
46
  "standard-engine": {
47
47
  "skip": true
48
48
  },
49
- "version": "1.6.4"
49
+ "version": "1.7.1"
50
50
  }
package/src/Sticky.jsx CHANGED
@@ -5,7 +5,6 @@ import throttle from 'lodash.throttle'
5
5
  import StickyWrapper from './styles'
6
6
 
7
7
  function createObserver(ref, callback, workWithViewport = true) {
8
- const options = { threshold: [1] }
9
8
  const observer = new IntersectionObserver(([e]) => {
10
9
  const isNotVisibleInViewport = e.intersectionRatio < 1
11
10
  let correctYPosition = true
@@ -14,7 +13,7 @@ function createObserver(ref, callback, workWithViewport = true) {
14
13
  correctYPosition = y < 0
15
14
  }
16
15
  callback(isNotVisibleInViewport && correctYPosition)
17
- }, options)
16
+ })
18
17
  observer.observe(ref.current)
19
18
  return observer
20
19
  }
@@ -44,6 +43,8 @@ const Sticky = ({
44
43
 
45
44
  const onStickThrottled = throttle(onStick, throttleTime, throttleConfig)
46
45
 
46
+ const sentinelPositionRef = position === 'top' ? sentinelTopRef : sentinelBottomRef
47
+
47
48
  React.useEffect(() => {
48
49
  if (observer) {
49
50
  observer.disconnect()
@@ -51,10 +52,10 @@ const Sticky = ({
51
52
  if (variant === 'default' || variant === 'hidden') {
52
53
  setObserver(
53
54
  createObserver(
54
- sentinelTopRef,
55
+ sentinelPositionRef,
55
56
  (intersected) => {
56
57
  stickyWrapperRef.current?.classList.toggle('sticky-mode', intersected)
57
- stickyWrapperRef.current?.classList.toggle('top', intersected)
58
+ stickyWrapperRef.current?.classList.toggle(position, intersected)
58
59
  if (intersected) {
59
60
  stickyWrapperRef.current?.classList.remove('pristine')
60
61
  }