@telus-uds/components-community.sticky 1.1.2 → 1.1.4

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.json CHANGED
@@ -2,7 +2,67 @@
2
2
  "name": "@telus-uds/components-community.sticky",
3
3
  "entries": [
4
4
  {
5
- "date": "Tue, 30 May 2023 02:42:51 GMT",
5
+ "date": "Tue, 06 Jun 2023 20:37:42 GMT",
6
+ "tag": "@telus-uds/components-community.sticky_v1.1.4",
7
+ "version": "1.1.4",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "oscar.palencia@telus.com",
12
+ "package": "@telus-uds/components-community.sticky",
13
+ "commit": "9f6bf985b27789c4b8d35af0dbeb581d95a00a2c",
14
+ "comment": "Fixing support for nesting container (overflows)"
15
+ },
16
+ {
17
+ "author": "beachball",
18
+ "package": "@telus-uds/components-community.sticky",
19
+ "comment": "Bump @telus-uds/components-base to v1.48.0",
20
+ "commit": "9f6bf985b27789c4b8d35af0dbeb581d95a00a2c"
21
+ },
22
+ {
23
+ "author": "beachball",
24
+ "package": "@telus-uds/components-community.sticky",
25
+ "comment": "Bump @telus-uds/system-theme-tokens to v2.30.0",
26
+ "commit": "9f6bf985b27789c4b8d35af0dbeb581d95a00a2c"
27
+ },
28
+ {
29
+ "author": "beachball",
30
+ "package": "@telus-uds/components-community.sticky",
31
+ "comment": "Bump @telus-uds/components-web to v2.6.0",
32
+ "commit": "9f6bf985b27789c4b8d35af0dbeb581d95a00a2c"
33
+ }
34
+ ]
35
+ }
36
+ },
37
+ {
38
+ "date": "Fri, 02 Jun 2023 00:34:55 GMT",
39
+ "tag": "@telus-uds/components-community.sticky_v1.1.3",
40
+ "version": "1.1.3",
41
+ "comments": {
42
+ "patch": [
43
+ {
44
+ "author": "beachball",
45
+ "package": "@telus-uds/components-community.sticky",
46
+ "comment": "Bump @telus-uds/components-base to v1.47.0",
47
+ "commit": "daa853cc53ed0fa547f7a4d219bd15760890d348"
48
+ },
49
+ {
50
+ "author": "beachball",
51
+ "package": "@telus-uds/components-community.sticky",
52
+ "comment": "Bump @telus-uds/system-theme-tokens to v2.29.0",
53
+ "commit": "daa853cc53ed0fa547f7a4d219bd15760890d348"
54
+ },
55
+ {
56
+ "author": "beachball",
57
+ "package": "@telus-uds/components-community.sticky",
58
+ "comment": "Bump @telus-uds/components-web to v2.5.0",
59
+ "commit": "daa853cc53ed0fa547f7a4d219bd15760890d348"
60
+ }
61
+ ]
62
+ }
63
+ },
64
+ {
65
+ "date": "Tue, 30 May 2023 02:46:46 GMT",
6
66
  "tag": "@telus-uds/components-community.sticky_v1.1.2",
7
67
  "version": "1.1.2",
8
68
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,33 @@
1
1
  # Change Log - @telus-uds/components-community.sticky
2
2
 
3
- This log was last generated on Tue, 30 May 2023 02:42:51 GMT and should not be manually modified.
3
+ This log was last generated on Tue, 06 Jun 2023 20:37:42 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 1.1.4
8
+
9
+ Tue, 06 Jun 2023 20:37:42 GMT
10
+
11
+ ### Patches
12
+
13
+ - Fixing support for nesting container (overflows) (oscar.palencia@telus.com)
14
+ - Bump @telus-uds/components-base to v1.48.0
15
+ - Bump @telus-uds/system-theme-tokens to v2.30.0
16
+ - Bump @telus-uds/components-web to v2.6.0
17
+
18
+ ## 1.1.3
19
+
20
+ Fri, 02 Jun 2023 00:34:55 GMT
21
+
22
+ ### Patches
23
+
24
+ - Bump @telus-uds/components-base to v1.47.0
25
+ - Bump @telus-uds/system-theme-tokens to v2.29.0
26
+ - Bump @telus-uds/components-web to v2.5.0
27
+
7
28
  ## 1.1.2
8
29
 
9
- Tue, 30 May 2023 02:42:51 GMT
30
+ Tue, 30 May 2023 02:46:46 GMT
10
31
 
11
32
  ### Patches
12
33
 
@@ -33,6 +33,24 @@ describe('Sticky', () => {
33
33
  expect(titleElement).toBeInTheDocument()
34
34
  })
35
35
 
36
+ it("is rendered without checking for container's y position", () => {
37
+ const { getByText, container } = render(
38
+ <Theme>
39
+ <Sticky workWithViewport={false}>
40
+ <Typography>Sticky Content</Typography>
41
+ </Sticky>
42
+ </Theme>
43
+ )
44
+ const sentinelTop = container.querySelector('.sentinelTop')
45
+ const sentinelBottom = container.querySelector('.sentinelBottom')
46
+ const stickyElement = container.querySelector('.sticky-element')
47
+ const titleElement = getByText(/Sticky Content/i)
48
+ expect(sentinelTop).toBeInTheDocument()
49
+ expect(sentinelBottom).toBeInTheDocument()
50
+ expect(stickyElement).toBeInTheDocument()
51
+ expect(titleElement).toBeInTheDocument()
52
+ })
53
+
36
54
  it('is rendered with children using alternate variant', () => {
37
55
  const { getByText, container } = render(
38
56
  <Theme>
package/lib/Sticky.js CHANGED
@@ -22,13 +22,23 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
22
22
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
23
 
24
24
  function createObserver(ref, callback) {
25
+ let workWithViewport = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
25
26
  const options = {
26
27
  threshold: [1]
27
28
  };
28
29
  const observer = new IntersectionObserver(_ref => {
29
30
  let [e] = _ref;
30
31
  const isNotVisibleInViewport = e.intersectionRatio < 1;
31
- callback(isNotVisibleInViewport);
32
+ let correctYPosition = true;
33
+
34
+ if (workWithViewport) {
35
+ const {
36
+ y
37
+ } = e.boundingClientRect;
38
+ correctYPosition = y < 0;
39
+ }
40
+
41
+ callback(isNotVisibleInViewport && correctYPosition);
32
42
  }, options);
33
43
  observer.observe(ref.current);
34
44
  return observer;
@@ -49,7 +59,8 @@ const Sticky = _ref2 => {
49
59
  sm: 0,
50
60
  lg: 0,
51
61
  xl: 0
52
- }
62
+ },
63
+ workWithViewport = true
53
64
  } = _ref2;
54
65
  const sentinelTopRef = (0, _react.useRef)();
55
66
  const sentinelBottomRef = (0, _react.useRef)();
@@ -66,7 +77,7 @@ const Sticky = _ref2 => {
66
77
 
67
78
  (_stickyWrapperRef$cur = stickyWrapperRef.current) === null || _stickyWrapperRef$cur === void 0 ? void 0 : _stickyWrapperRef$cur.classList.toggle('sticky-mode', intersected);
68
79
  (_stickyWrapperRef$cur2 = stickyWrapperRef.current) === null || _stickyWrapperRef$cur2 === void 0 ? void 0 : _stickyWrapperRef$cur2.classList.toggle('top', intersected);
69
- }));
80
+ }, workWithViewport));
70
81
  }
71
82
 
72
83
  if (variant === 'alternate') {
@@ -75,7 +86,7 @@ const Sticky = _ref2 => {
75
86
 
76
87
  (_stickyWrapperRef$cur3 = stickyWrapperRef.current) === null || _stickyWrapperRef$cur3 === void 0 ? void 0 : _stickyWrapperRef$cur3.classList.toggle('sticky-mode', intersected);
77
88
  (_stickyWrapperRef$cur4 = stickyWrapperRef.current) === null || _stickyWrapperRef$cur4 === void 0 ? void 0 : _stickyWrapperRef$cur4.classList.toggle('bottom', intersected);
78
- }));
89
+ }, workWithViewport));
79
90
  } // eslint-disable-next-line react-hooks/exhaustive-deps
80
91
 
81
92
  }, [variant]);
@@ -114,6 +125,12 @@ Sticky.propTypes = {
114
125
  */
115
126
  horizontal: _componentsBase.spacingProps.types.spacingValue,
116
127
 
128
+ /**
129
+ * Whether the sticky should wait to cross the viewport to stick or not
130
+ * Defaults to true. Set to false for nested container (using overflow)
131
+ */
132
+ workWithViewport: _propTypes.default.bool,
133
+
117
134
  /**
118
135
  * Sticky accepts any content as children.
119
136
  */
package/package.json CHANGED
@@ -4,14 +4,14 @@
4
4
  "extends @telus-uds/browserslist-config"
5
5
  ],
6
6
  "dependencies": {
7
- "@telus-uds/components-base": "1.46.0",
7
+ "@telus-uds/components-base": "1.48.0",
8
8
  "@telus-uds/system-constants": "^1.2.1",
9
- "@telus-uds/system-theme-tokens": "^2.28.0",
9
+ "@telus-uds/system-theme-tokens": "^2.30.0",
10
10
  "prop-types": "^15.7.2",
11
11
  "styled-components": "^5.3.10"
12
12
  },
13
13
  "devDependencies": {
14
- "@telus-uds/components-web": "^2.4.0",
14
+ "@telus-uds/components-web": "^2.6.0",
15
15
  "@telus-uds/browserslist-config": "^1.0.5",
16
16
  "@testing-library/jest-dom": "^5.16.1",
17
17
  "@testing-library/react": "^13.3.0",
@@ -45,5 +45,5 @@
45
45
  "standard-engine": {
46
46
  "skip": true
47
47
  },
48
- "version": "1.1.2"
48
+ "version": "1.1.4"
49
49
  }
package/src/Sticky.jsx CHANGED
@@ -3,11 +3,16 @@ import PropTypes from 'prop-types'
3
3
  import { spacingProps, Box } from '@telus-uds/components-base'
4
4
  import StickyWrapper from './styles'
5
5
 
6
- function createObserver(ref, callback) {
6
+ function createObserver(ref, callback, workWithViewport = true) {
7
7
  const options = { threshold: [1] }
8
8
  const observer = new IntersectionObserver(([e]) => {
9
9
  const isNotVisibleInViewport = e.intersectionRatio < 1
10
- callback(isNotVisibleInViewport)
10
+ let correctYPosition = true
11
+ if (workWithViewport) {
12
+ const { y } = e.boundingClientRect
13
+ correctYPosition = y < 0
14
+ }
15
+ callback(isNotVisibleInViewport && correctYPosition)
11
16
  }, options)
12
17
  observer.observe(ref.current)
13
18
  return observer
@@ -17,7 +22,8 @@ const Sticky = ({
17
22
  children,
18
23
  variant = 'default',
19
24
  vertical = { xs: 0, sm: 0, lg: 0, xl: 0 },
20
- horizontal = { xs: 0, sm: 0, lg: 0, xl: 0 }
25
+ horizontal = { xs: 0, sm: 0, lg: 0, xl: 0 },
26
+ workWithViewport = true
21
27
  }) => {
22
28
  const sentinelTopRef = useRef()
23
29
  const sentinelBottomRef = useRef()
@@ -29,18 +35,26 @@ const Sticky = ({
29
35
  }
30
36
  if (variant === 'default' || variant === 'hidden') {
31
37
  setObserver(
32
- createObserver(sentinelTopRef, (intersected) => {
33
- stickyWrapperRef.current?.classList.toggle('sticky-mode', intersected)
34
- stickyWrapperRef.current?.classList.toggle('top', intersected)
35
- })
38
+ createObserver(
39
+ sentinelTopRef,
40
+ (intersected) => {
41
+ stickyWrapperRef.current?.classList.toggle('sticky-mode', intersected)
42
+ stickyWrapperRef.current?.classList.toggle('top', intersected)
43
+ },
44
+ workWithViewport
45
+ )
36
46
  )
37
47
  }
38
48
  if (variant === 'alternate') {
39
49
  setObserver(
40
- createObserver(sentinelBottomRef, (intersected) => {
41
- stickyWrapperRef.current?.classList.toggle('sticky-mode', intersected)
42
- stickyWrapperRef.current?.classList.toggle('bottom', intersected)
43
- })
50
+ createObserver(
51
+ sentinelBottomRef,
52
+ (intersected) => {
53
+ stickyWrapperRef.current?.classList.toggle('sticky-mode', intersected)
54
+ stickyWrapperRef.current?.classList.toggle('bottom', intersected)
55
+ },
56
+ workWithViewport
57
+ )
44
58
  )
45
59
  }
46
60
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -72,6 +86,11 @@ Sticky.propTypes = {
72
86
  *
73
87
  */
74
88
  horizontal: spacingProps.types.spacingValue,
89
+ /**
90
+ * Whether the sticky should wait to cross the viewport to stick or not
91
+ * Defaults to true. Set to false for nested container (using overflow)
92
+ */
93
+ workWithViewport: PropTypes.bool,
75
94
  /**
76
95
  * Sticky accepts any content as children.
77
96
  */
@@ -219,4 +219,4 @@ export const Default = (args) => (
219
219
  )
220
220
 
221
221
  Default.storyName = 'Sticky'
222
- Default.args = { variant: 'default' }
222
+ Default.args = { variant: 'default', checkYPostion: true }