@telus-uds/components-community.sticky 1.1.19 → 1.1.20

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,23 @@
1
1
  # Change Log - @telus-uds/components-community.sticky
2
2
 
3
- This log was last generated on Thu, 31 Aug 2023 17:58:49 GMT and should not be manually modified.
3
+ This log was last generated on Tue, 12 Sep 2023 15:31:31 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 1.1.20
8
+
9
+ Tue, 12 Sep 2023 15:31:31 GMT
10
+
11
+ ### Patches
12
+
13
+ - remove and re add npmignore files (evander.owusu@telus.com)
14
+ - Bump @telus-uds/components-base to v1.60.0
15
+ - Bump @telus-uds/system-theme-tokens to v2.41.1
16
+ - Bump @telus-uds/components-web to v2.18.0
17
+
7
18
  ## 1.1.19
8
19
 
9
- Thu, 31 Aug 2023 17:58:49 GMT
20
+ Thu, 31 Aug 2023 18:02:14 GMT
10
21
 
11
22
  ### Patches
12
23
 
@@ -0,0 +1,131 @@
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { spacingProps, Box } from '@telus-uds/components-base';
4
+ import StickyWrapper from './styles';
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ import { Fragment as _Fragment } from "react/jsx-runtime";
7
+ import { jsxs as _jsxs } from "react/jsx-runtime";
8
+
9
+ function createObserver(ref, callback) {
10
+ let workWithViewport = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
11
+ const options = {
12
+ threshold: [1]
13
+ };
14
+ const observer = new IntersectionObserver(_ref => {
15
+ let [e] = _ref;
16
+ const isNotVisibleInViewport = e.intersectionRatio < 1;
17
+ let correctYPosition = true;
18
+
19
+ if (workWithViewport) {
20
+ const {
21
+ y
22
+ } = e.boundingClientRect;
23
+ correctYPosition = y < 0;
24
+ }
25
+
26
+ callback(isNotVisibleInViewport && correctYPosition);
27
+ }, options);
28
+ observer.observe(ref.current);
29
+ return observer;
30
+ }
31
+
32
+ const Sticky = _ref2 => {
33
+ let {
34
+ children,
35
+ variant = 'default',
36
+ vertical = {
37
+ xs: 0,
38
+ sm: 0,
39
+ lg: 0,
40
+ xl: 0
41
+ },
42
+ horizontal = {
43
+ xs: 0,
44
+ sm: 0,
45
+ lg: 0,
46
+ xl: 0
47
+ },
48
+ workWithViewport = true
49
+ } = _ref2;
50
+ const sentinelTopRef = useRef();
51
+ const sentinelBottomRef = useRef();
52
+ const stickyWrapperRef = useRef();
53
+ const [observer, setObserver] = useState();
54
+ useEffect(() => {
55
+ if (observer) {
56
+ observer.disconnect();
57
+ }
58
+
59
+ if (variant === 'default' || variant === 'hidden') {
60
+ setObserver(createObserver(sentinelTopRef, intersected => {
61
+ var _stickyWrapperRef$cur, _stickyWrapperRef$cur2;
62
+
63
+ (_stickyWrapperRef$cur = stickyWrapperRef.current) === null || _stickyWrapperRef$cur === void 0 ? void 0 : _stickyWrapperRef$cur.classList.toggle('sticky-mode', intersected);
64
+ (_stickyWrapperRef$cur2 = stickyWrapperRef.current) === null || _stickyWrapperRef$cur2 === void 0 ? void 0 : _stickyWrapperRef$cur2.classList.toggle('top', intersected);
65
+
66
+ if (intersected) {
67
+ var _stickyWrapperRef$cur3;
68
+
69
+ (_stickyWrapperRef$cur3 = stickyWrapperRef.current) === null || _stickyWrapperRef$cur3 === void 0 ? void 0 : _stickyWrapperRef$cur3.classList.remove('pristine');
70
+ }
71
+ }, workWithViewport));
72
+ }
73
+
74
+ if (variant === 'alternate') {
75
+ setObserver(createObserver(sentinelBottomRef, intersected => {
76
+ var _stickyWrapperRef$cur4, _stickyWrapperRef$cur5;
77
+
78
+ (_stickyWrapperRef$cur4 = stickyWrapperRef.current) === null || _stickyWrapperRef$cur4 === void 0 ? void 0 : _stickyWrapperRef$cur4.classList.toggle('sticky-mode', intersected);
79
+ (_stickyWrapperRef$cur5 = stickyWrapperRef.current) === null || _stickyWrapperRef$cur5 === void 0 ? void 0 : _stickyWrapperRef$cur5.classList.toggle('bottom', intersected);
80
+ }, workWithViewport));
81
+ } // eslint-disable-next-line react-hooks/exhaustive-deps
82
+
83
+ }, [variant]);
84
+ return /*#__PURE__*/_jsxs(_Fragment, {
85
+ children: [/*#__PURE__*/_jsx("div", {
86
+ className: "sentinelTop",
87
+ ref: sentinelTopRef
88
+ }), /*#__PURE__*/_jsx(StickyWrapper, {
89
+ className: `${variant} ${variant === 'hidden' ? 'pristine' : ''}`,
90
+ ref: stickyWrapperRef,
91
+ children: /*#__PURE__*/_jsx("div", {
92
+ className: "sticky-element",
93
+ children: /*#__PURE__*/_jsx(Box, {
94
+ vertical: vertical,
95
+ horizontal: horizontal,
96
+ children: children
97
+ })
98
+ })
99
+ }), /*#__PURE__*/_jsx("div", {
100
+ className: "sentinelBottom",
101
+ ref: sentinelBottomRef
102
+ })]
103
+ });
104
+ };
105
+
106
+ Sticky.propTypes = {
107
+ /**
108
+ * Sets top and bottom padding using the theme's spacing scale.
109
+ *
110
+ */
111
+ vertical: spacingProps.types.spacingValue,
112
+
113
+ /**
114
+ * Sets left and right padding using the theme's spacing scale.
115
+ *
116
+ */
117
+ horizontal: spacingProps.types.spacingValue,
118
+
119
+ /**
120
+ * Whether the sticky should wait to cross the viewport to stick or not
121
+ * Defaults to true. Set to false for nested container (using overflow)
122
+ */
123
+ workWithViewport: PropTypes.bool,
124
+
125
+ /**
126
+ * Sticky accepts any content as children.
127
+ */
128
+ children: PropTypes.node.isRequired,
129
+ variant: PropTypes.oneOf(['default', 'alternate', 'hidden'])
130
+ };
131
+ export default Sticky;
@@ -0,0 +1,3 @@
1
+ import Sticky from './Sticky';
2
+ export { default as Sticky } from './Sticky';
3
+ export default Sticky;
@@ -0,0 +1,6 @@
1
+ import styled from 'styled-components';
2
+ const StickyWrapper = /*#__PURE__*/styled.div.withConfig({
3
+ displayName: "styles__StickyWrapper",
4
+ componentId: "[object Object]__sc-160gk65-0"
5
+ })(["top:0;&.sticky-mode{&.alternate,&.default{position:-webkit-sticky;position:sticky;top:0px;z-index:1;box-shadow:0px 7px 4px -3px rgb(0,0,0,0.08);}&.hidden{animation:0.3s animateIn forwards;.sticky-element{animation:0.3s shadowIn forwards;}}}&.alternate{}&.hidden{position:sticky;pointerevents:none;height:0px;min-height:0px;max-height:0px;animation:0.6s animateOut forwards;&.pristine{display:none;}.sticky-element{background:white;animation:0.6s shadowOut forwards;}}.sticky-element{background:#ffffff;}@keyframes animateIn{from{height:0%;pointerevents:none;transform:translateY(-100vh);opacity:0;z-index:-1;}to{height:100%;pointerevents:all;transform:translateY(0);opacity:1;z-index:1;}}@keyframes animateOut{from{height:100%;pointerevents:all;transform:translateY(0);opacity:1;z-index:1;}to{height:0%;pointerevents:none;transform:translateY(-100vh);opacity:0;z-index:-1;}}@keyframes shadowIn{from{box-shadow:0px 7px 4px -3px rgb(0,0,0,0);}to{box-shadow:0px 7px 4px -3px rgb(0,0,0,0.08);}}@keyframes shadowOut{from{box-shadow:0px 7px 4px -3px rgb(0,0,0,0.08);}to{box-shadow:0px 7px 4px -3px rgb(0,0,0,0);}}"]);
6
+ export default StickyWrapper;
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.59.2",
7
+ "@telus-uds/components-base": "1.60.0",
8
8
  "@telus-uds/system-constants": "^1.3.0",
9
- "@telus-uds/system-theme-tokens": "^2.41.0",
9
+ "@telus-uds/system-theme-tokens": "^2.41.1",
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.17.2",
14
+ "@telus-uds/components-web": "^2.18.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.19"
48
+ "version": "1.1.20"
49
49
  }
package/.eslintrc.js DELETED
@@ -1,21 +0,0 @@
1
- const path = require('path')
2
- const base = require('../../../../eslintrc.base')
3
-
4
- base.rules['import/no-extraneous-dependencies'] = [
5
- 'error',
6
- { packageDir: [__dirname, path.join(__dirname, '../..')] }
7
- ]
8
- base.settings = {
9
- ...base.settings,
10
- 'import/resolver': {
11
- node: {
12
- ...base.settings?.['import/resolver']?.node,
13
- moduleDirectory: [
14
- path.join(__dirname, '../../node_modules'),
15
- path.join(__dirname, '../../../../node_modules')
16
- ]
17
- }
18
- }
19
- }
20
-
21
- module.exports = base