@telus-uds/components-community.sticky 1.3.2 → 1.4.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.
- package/CHANGELOG.md +12 -2
- package/lib/Sticky.js +23 -2
- package/lib-module/Sticky.js +23 -2
- package/package.json +4 -3
- package/src/Sticky.jsx +23 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
# Change Log - @telus-uds/components-community.sticky
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Wed, 07 Feb 2024 19:09:40 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 1.4.0
|
|
8
|
+
|
|
9
|
+
Wed, 07 Feb 2024 19:09:40 GMT
|
|
10
|
+
|
|
11
|
+
### Minor changes
|
|
12
|
+
|
|
13
|
+
- The onStick prop is a callback function that gets triggered when the sticky behavior changes i.e., when the element becomes sticky or stops being sticky. ThrottleTime prop that specifies the time interval (in milliseconds) during which the onStick callback is throttled. The throttleConfig prop allows you to customize the behavior of the throttling, such as whether the throttled function is called immediately (leading) or after the specified time interval (trailing). (victor.morales@telus.com)
|
|
14
|
+
- Bump @telus-uds/components-base to v1.76.0
|
|
15
|
+
- Bump @telus-uds/components-web to v2.31.0
|
|
16
|
+
|
|
7
17
|
## 1.3.2
|
|
8
18
|
|
|
9
|
-
Mon, 29 Jan 2024 18:
|
|
19
|
+
Mon, 29 Jan 2024 18:41:50 GMT
|
|
10
20
|
|
|
11
21
|
### Patches
|
|
12
22
|
|
package/lib/Sticky.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
9
|
var _componentsBase = require("@telus-uds/components-base");
|
|
10
|
+
var _lodash = _interopRequireDefault(require("lodash.throttle"));
|
|
10
11
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
11
12
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -50,7 +51,12 @@ const Sticky = _ref2 => {
|
|
|
50
51
|
},
|
|
51
52
|
workWithViewport = true,
|
|
52
53
|
position = 'top',
|
|
53
|
-
shadow = true
|
|
54
|
+
shadow = true,
|
|
55
|
+
onStick = () => {},
|
|
56
|
+
throttleTime = 100,
|
|
57
|
+
throttleConfig = {
|
|
58
|
+
trailing: true
|
|
59
|
+
}
|
|
54
60
|
} = _ref2;
|
|
55
61
|
// Position "bottom" does not support the "hidden" variant.
|
|
56
62
|
if (variant === 'hidden' && position === 'bottom') {
|
|
@@ -61,6 +67,7 @@ const Sticky = _ref2 => {
|
|
|
61
67
|
const sentinelBottomRef = (0, _react.useRef)();
|
|
62
68
|
const stickyWrapperRef = (0, _react.useRef)();
|
|
63
69
|
const [observer, setObserver] = (0, _react.useState)();
|
|
70
|
+
const onStickThrottled = (0, _lodash.default)(onStick, throttleTime, throttleConfig);
|
|
64
71
|
(0, _react.useEffect)(() => {
|
|
65
72
|
if (observer) {
|
|
66
73
|
observer.disconnect();
|
|
@@ -74,6 +81,7 @@ const Sticky = _ref2 => {
|
|
|
74
81
|
var _stickyWrapperRef$cur3;
|
|
75
82
|
(_stickyWrapperRef$cur3 = stickyWrapperRef.current) === null || _stickyWrapperRef$cur3 === void 0 ? void 0 : _stickyWrapperRef$cur3.classList.remove('pristine');
|
|
76
83
|
}
|
|
84
|
+
onStickThrottled(intersected);
|
|
77
85
|
}, workWithViewport));
|
|
78
86
|
}
|
|
79
87
|
if (variant === 'alternate') {
|
|
@@ -81,6 +89,7 @@ const Sticky = _ref2 => {
|
|
|
81
89
|
var _stickyWrapperRef$cur4, _stickyWrapperRef$cur5;
|
|
82
90
|
(_stickyWrapperRef$cur4 = stickyWrapperRef.current) === null || _stickyWrapperRef$cur4 === void 0 ? void 0 : _stickyWrapperRef$cur4.classList.toggle('sticky-mode', intersected);
|
|
83
91
|
(_stickyWrapperRef$cur5 = stickyWrapperRef.current) === null || _stickyWrapperRef$cur5 === void 0 ? void 0 : _stickyWrapperRef$cur5.classList.toggle('bottom', intersected);
|
|
92
|
+
onStickThrottled(intersected);
|
|
84
93
|
}, workWithViewport));
|
|
85
94
|
}
|
|
86
95
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -137,7 +146,19 @@ Sticky.propTypes = {
|
|
|
137
146
|
/**
|
|
138
147
|
* Adds shadow to sticky component.
|
|
139
148
|
*/
|
|
140
|
-
shadow: _propTypes.default.bool
|
|
149
|
+
shadow: _propTypes.default.bool,
|
|
150
|
+
/**
|
|
151
|
+
* Callback when sticky is stuck to top or bottom of page.
|
|
152
|
+
*/
|
|
153
|
+
onStick: _propTypes.default.func,
|
|
154
|
+
/**
|
|
155
|
+
* Time in milliseconds to throttle the onStick callback.
|
|
156
|
+
*/
|
|
157
|
+
throttleTime: _propTypes.default.number,
|
|
158
|
+
/**
|
|
159
|
+
* Throttle configuration.
|
|
160
|
+
*/
|
|
161
|
+
throttleConfig: _propTypes.default.object
|
|
141
162
|
};
|
|
142
163
|
var _default = Sticky;
|
|
143
164
|
exports.default = _default;
|
package/lib-module/Sticky.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { useEffect, useRef, useState } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { spacingProps, Box } from '@telus-uds/components-base';
|
|
4
|
+
import throttle from 'lodash.throttle';
|
|
4
5
|
import StickyWrapper from './styles';
|
|
5
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
7
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
@@ -43,7 +44,12 @@ const Sticky = _ref2 => {
|
|
|
43
44
|
},
|
|
44
45
|
workWithViewport = true,
|
|
45
46
|
position = 'top',
|
|
46
|
-
shadow = true
|
|
47
|
+
shadow = true,
|
|
48
|
+
onStick = () => {},
|
|
49
|
+
throttleTime = 100,
|
|
50
|
+
throttleConfig = {
|
|
51
|
+
trailing: true
|
|
52
|
+
}
|
|
47
53
|
} = _ref2;
|
|
48
54
|
// Position "bottom" does not support the "hidden" variant.
|
|
49
55
|
if (variant === 'hidden' && position === 'bottom') {
|
|
@@ -54,6 +60,7 @@ const Sticky = _ref2 => {
|
|
|
54
60
|
const sentinelBottomRef = useRef();
|
|
55
61
|
const stickyWrapperRef = useRef();
|
|
56
62
|
const [observer, setObserver] = useState();
|
|
63
|
+
const onStickThrottled = throttle(onStick, throttleTime, throttleConfig);
|
|
57
64
|
useEffect(() => {
|
|
58
65
|
if (observer) {
|
|
59
66
|
observer.disconnect();
|
|
@@ -67,6 +74,7 @@ const Sticky = _ref2 => {
|
|
|
67
74
|
var _stickyWrapperRef$cur3;
|
|
68
75
|
(_stickyWrapperRef$cur3 = stickyWrapperRef.current) === null || _stickyWrapperRef$cur3 === void 0 ? void 0 : _stickyWrapperRef$cur3.classList.remove('pristine');
|
|
69
76
|
}
|
|
77
|
+
onStickThrottled(intersected);
|
|
70
78
|
}, workWithViewport));
|
|
71
79
|
}
|
|
72
80
|
if (variant === 'alternate') {
|
|
@@ -74,6 +82,7 @@ const Sticky = _ref2 => {
|
|
|
74
82
|
var _stickyWrapperRef$cur4, _stickyWrapperRef$cur5;
|
|
75
83
|
(_stickyWrapperRef$cur4 = stickyWrapperRef.current) === null || _stickyWrapperRef$cur4 === void 0 ? void 0 : _stickyWrapperRef$cur4.classList.toggle('sticky-mode', intersected);
|
|
76
84
|
(_stickyWrapperRef$cur5 = stickyWrapperRef.current) === null || _stickyWrapperRef$cur5 === void 0 ? void 0 : _stickyWrapperRef$cur5.classList.toggle('bottom', intersected);
|
|
85
|
+
onStickThrottled(intersected);
|
|
77
86
|
}, workWithViewport));
|
|
78
87
|
}
|
|
79
88
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -130,6 +139,18 @@ Sticky.propTypes = {
|
|
|
130
139
|
/**
|
|
131
140
|
* Adds shadow to sticky component.
|
|
132
141
|
*/
|
|
133
|
-
shadow: PropTypes.bool
|
|
142
|
+
shadow: PropTypes.bool,
|
|
143
|
+
/**
|
|
144
|
+
* Callback when sticky is stuck to top or bottom of page.
|
|
145
|
+
*/
|
|
146
|
+
onStick: PropTypes.func,
|
|
147
|
+
/**
|
|
148
|
+
* Time in milliseconds to throttle the onStick callback.
|
|
149
|
+
*/
|
|
150
|
+
throttleTime: PropTypes.number,
|
|
151
|
+
/**
|
|
152
|
+
* Throttle configuration.
|
|
153
|
+
*/
|
|
154
|
+
throttleConfig: PropTypes.object
|
|
134
155
|
};
|
|
135
156
|
export default Sticky;
|
package/package.json
CHANGED
|
@@ -4,14 +4,15 @@
|
|
|
4
4
|
"extends @telus-uds/browserslist-config"
|
|
5
5
|
],
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@telus-uds/components-base": "1.
|
|
7
|
+
"@telus-uds/components-base": "1.76.0",
|
|
8
8
|
"@telus-uds/system-constants": "^1.3.0",
|
|
9
9
|
"@telus-uds/system-theme-tokens": "^2.50.1",
|
|
10
|
+
"lodash.throttle": "^4.1.1",
|
|
10
11
|
"prop-types": "^15.7.2",
|
|
11
12
|
"styled-components": "^5.3.10"
|
|
12
13
|
},
|
|
13
14
|
"devDependencies": {
|
|
14
|
-
"@telus-uds/components-web": "^2.
|
|
15
|
+
"@telus-uds/components-web": "^2.31.0",
|
|
15
16
|
"@telus-uds/browserslist-config": "^1.0.5",
|
|
16
17
|
"@testing-library/jest-dom": "^5.16.1",
|
|
17
18
|
"@testing-library/react": "^13.3.0",
|
|
@@ -45,5 +46,5 @@
|
|
|
45
46
|
"standard-engine": {
|
|
46
47
|
"skip": true
|
|
47
48
|
},
|
|
48
|
-
"version": "1.
|
|
49
|
+
"version": "1.4.0"
|
|
49
50
|
}
|
package/src/Sticky.jsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { useEffect, useRef, useState } from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import { spacingProps, Box } from '@telus-uds/components-base'
|
|
4
|
+
import throttle from 'lodash.throttle'
|
|
4
5
|
import StickyWrapper from './styles'
|
|
5
6
|
|
|
6
7
|
function createObserver(ref, callback, workWithViewport = true) {
|
|
@@ -25,7 +26,10 @@ const Sticky = ({
|
|
|
25
26
|
horizontal = { xs: 0, sm: 0, lg: 0, xl: 0 },
|
|
26
27
|
workWithViewport = true,
|
|
27
28
|
position = 'top',
|
|
28
|
-
shadow = true
|
|
29
|
+
shadow = true,
|
|
30
|
+
onStick = () => {},
|
|
31
|
+
throttleTime = 100,
|
|
32
|
+
throttleConfig = { trailing: true }
|
|
29
33
|
}) => {
|
|
30
34
|
// Position "bottom" does not support the "hidden" variant.
|
|
31
35
|
if (variant === 'hidden' && position === 'bottom') {
|
|
@@ -37,6 +41,9 @@ const Sticky = ({
|
|
|
37
41
|
const sentinelBottomRef = useRef()
|
|
38
42
|
const stickyWrapperRef = useRef()
|
|
39
43
|
const [observer, setObserver] = useState()
|
|
44
|
+
|
|
45
|
+
const onStickThrottled = throttle(onStick, throttleTime, throttleConfig)
|
|
46
|
+
|
|
40
47
|
useEffect(() => {
|
|
41
48
|
if (observer) {
|
|
42
49
|
observer.disconnect()
|
|
@@ -51,6 +58,7 @@ const Sticky = ({
|
|
|
51
58
|
if (intersected) {
|
|
52
59
|
stickyWrapperRef.current?.classList.remove('pristine')
|
|
53
60
|
}
|
|
61
|
+
onStickThrottled(intersected)
|
|
54
62
|
},
|
|
55
63
|
workWithViewport
|
|
56
64
|
)
|
|
@@ -63,6 +71,7 @@ const Sticky = ({
|
|
|
63
71
|
(intersected) => {
|
|
64
72
|
stickyWrapperRef.current?.classList.toggle('sticky-mode', intersected)
|
|
65
73
|
stickyWrapperRef.current?.classList.toggle('bottom', intersected)
|
|
74
|
+
onStickThrottled(intersected)
|
|
66
75
|
},
|
|
67
76
|
workWithViewport
|
|
68
77
|
)
|
|
@@ -120,7 +129,19 @@ Sticky.propTypes = {
|
|
|
120
129
|
/**
|
|
121
130
|
* Adds shadow to sticky component.
|
|
122
131
|
*/
|
|
123
|
-
shadow: PropTypes.bool
|
|
132
|
+
shadow: PropTypes.bool,
|
|
133
|
+
/**
|
|
134
|
+
* Callback when sticky is stuck to top or bottom of page.
|
|
135
|
+
*/
|
|
136
|
+
onStick: PropTypes.func,
|
|
137
|
+
/**
|
|
138
|
+
* Time in milliseconds to throttle the onStick callback.
|
|
139
|
+
*/
|
|
140
|
+
throttleTime: PropTypes.number,
|
|
141
|
+
/**
|
|
142
|
+
* Throttle configuration.
|
|
143
|
+
*/
|
|
144
|
+
throttleConfig: PropTypes.object
|
|
124
145
|
}
|
|
125
146
|
|
|
126
147
|
export default Sticky
|