@integreat-app/react-sticky-headroom 1.2.2 → 1.2.3
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/README.md +3 -0
- package/index.d.ts +18 -18
- package/index.js +22 -68
- package/package.json +10 -11
package/README.md
CHANGED
|
@@ -59,4 +59,7 @@ You can read about the browser support for that on [caniuse.com](https://caniuse
|
|
|
59
59
|
|
|
60
60
|
ReactStickyHeadroom offers types for both TypeScript and FlowJS which should work out of the box.
|
|
61
61
|
|
|
62
|
+
ReactStickyHeadroom is a client-side library and hence does not support Server Side Rendering (SSR) a priori.
|
|
63
|
+
For NextJS you can find more information on how to embed this library [here](https://nextjs.org/docs/advanced-features/dynamic-import#with-no-ssr).
|
|
64
|
+
|
|
62
65
|
If there are any problems, please don't hesitate to open an issue on GitHub.
|
package/index.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import React, { ReactNode } from 'react'
|
|
2
|
-
|
|
3
|
-
declare type PropsType = {
|
|
4
|
-
children: ReactNode,
|
|
5
|
-
scrollHeight: number,
|
|
6
|
-
pinStart?: number,
|
|
7
|
-
height?: number,
|
|
8
|
-
onStickyTopChanged?: (number) => void,
|
|
9
|
-
positionStickyDisabled?: boolean,
|
|
10
|
-
parent?: HTMLElement,
|
|
11
|
-
zIndex?: number,
|
|
12
|
-
className?: string
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
declare class Headroom extends React.Component<PropsType> {
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export default Headroom
|
|
1
|
+
import React, { ReactNode } from 'react'
|
|
2
|
+
|
|
3
|
+
declare type PropsType = {
|
|
4
|
+
children: ReactNode,
|
|
5
|
+
scrollHeight: number,
|
|
6
|
+
pinStart?: number,
|
|
7
|
+
height?: number,
|
|
8
|
+
onStickyTopChanged?: (number) => void,
|
|
9
|
+
positionStickyDisabled?: boolean,
|
|
10
|
+
parent?: HTMLElement,
|
|
11
|
+
zIndex?: number,
|
|
12
|
+
className?: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare class Headroom extends React.Component<PropsType> {
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default Headroom
|
package/index.js
CHANGED
|
@@ -1,42 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var React = _interopRequireWildcard(require("react"));
|
|
11
|
-
|
|
12
9
|
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
13
|
-
|
|
14
10
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
|
-
|
|
16
11
|
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; }
|
|
17
|
-
|
|
18
12
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
19
|
-
|
|
20
13
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
21
|
-
|
|
22
14
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
23
|
-
|
|
24
15
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
25
|
-
|
|
26
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
27
|
-
|
|
16
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
28
17
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
29
|
-
|
|
30
18
|
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
31
|
-
|
|
32
19
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
33
|
-
|
|
34
20
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
35
|
-
|
|
36
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
37
|
-
|
|
21
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
38
22
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
39
|
-
|
|
40
23
|
var UPWARDS = 'up';
|
|
41
24
|
var DOWNWARDS = 'down';
|
|
42
25
|
var UNPINNED = 'unpinned';
|
|
@@ -45,7 +28,6 @@ var STATIC = 'static';
|
|
|
45
28
|
var NO_TRANSITION = 'none';
|
|
46
29
|
var NORMAL_TRANSITION = 'normal';
|
|
47
30
|
var PINNED_TO_STATIC = 'pinned-to-static';
|
|
48
|
-
|
|
49
31
|
var HeaderWrapper = _styledComponents.default.div.withConfig({
|
|
50
32
|
displayName: "Headroom__HeaderWrapper",
|
|
51
33
|
componentId: "sc-16d3zk-0"
|
|
@@ -64,74 +46,54 @@ var HeaderWrapper = _styledComponents.default.div.withConfig({
|
|
|
64
46
|
}, function (props) {
|
|
65
47
|
return props.static ? 'transition: none;' : '';
|
|
66
48
|
});
|
|
67
|
-
|
|
68
49
|
var keyframesMoveUpFrom = function keyframesMoveUpFrom(from) {
|
|
69
50
|
return (0, _styledComponents.keyframes)(["from{transform:translateY(", "px)}to{transform:translateY(0)}"], Math.max(from, 0));
|
|
70
51
|
};
|
|
71
|
-
|
|
72
52
|
var Headroom = /*#__PURE__*/function (_React$PureComponent) {
|
|
73
53
|
_inherits(Headroom, _React$PureComponent);
|
|
74
|
-
|
|
75
54
|
var _super = _createSuper(Headroom);
|
|
76
|
-
|
|
77
55
|
function Headroom() {
|
|
78
56
|
var _this;
|
|
79
|
-
|
|
80
57
|
_classCallCheck(this, Headroom);
|
|
81
|
-
|
|
82
58
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
83
59
|
args[_key] = arguments[_key];
|
|
84
60
|
}
|
|
85
|
-
|
|
86
61
|
_this = _super.call.apply(_super, [this].concat(args));
|
|
87
|
-
|
|
88
62
|
_defineProperty(_assertThisInitialized(_this), "state", {
|
|
89
63
|
mode: STATIC,
|
|
90
64
|
transition: NO_TRANSITION,
|
|
91
65
|
animateUpFrom: null
|
|
92
66
|
});
|
|
93
|
-
|
|
94
67
|
_defineProperty(_assertThisInitialized(_this), "lastKnownScrollTop", 0);
|
|
95
|
-
|
|
96
68
|
_defineProperty(_assertThisInitialized(_this), "update", function () {
|
|
97
69
|
var currentScrollTop = _this.getScrollTop();
|
|
98
|
-
|
|
99
70
|
var newState = {};
|
|
100
|
-
|
|
101
71
|
if (currentScrollTop === _this.lastKnownScrollTop) {
|
|
102
72
|
return;
|
|
103
73
|
}
|
|
104
|
-
|
|
105
74
|
var direction = _this.lastKnownScrollTop < currentScrollTop ? DOWNWARDS : UPWARDS;
|
|
106
75
|
newState.mode = _this.determineMode(currentScrollTop, direction);
|
|
107
76
|
newState.transition = _this.determineTransition(newState.mode, direction);
|
|
108
77
|
var _this$props = _this.props,
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
78
|
+
onStickyTopChanged = _this$props.onStickyTopChanged,
|
|
79
|
+
height = _this$props.height,
|
|
80
|
+
scrollHeight = _this$props.scrollHeight,
|
|
81
|
+
pinStart = _this$props.pinStart;
|
|
114
82
|
if (_this.state.mode === PINNED && newState.mode === STATIC) {
|
|
115
83
|
// animation in the special case from pinned to static
|
|
116
84
|
newState.animateUpFrom = currentScrollTop - pinStart;
|
|
117
85
|
}
|
|
118
|
-
|
|
119
86
|
if (onStickyTopChanged && newState.mode !== _this.state.mode && height) {
|
|
120
87
|
onStickyTopChanged(Headroom.calcStickyTop(newState.mode, height, scrollHeight));
|
|
121
88
|
}
|
|
122
|
-
|
|
123
89
|
_this.setState(newState);
|
|
124
|
-
|
|
125
90
|
_this.lastKnownScrollTop = currentScrollTop;
|
|
126
91
|
});
|
|
127
|
-
|
|
128
92
|
_defineProperty(_assertThisInitialized(_this), "handleEvent", function () {
|
|
129
93
|
window.requestAnimationFrame(_this.update);
|
|
130
94
|
});
|
|
131
|
-
|
|
132
95
|
return _this;
|
|
133
96
|
}
|
|
134
|
-
|
|
135
97
|
_createClass(Headroom, [{
|
|
136
98
|
key: "getScrollTop",
|
|
137
99
|
value:
|
|
@@ -140,15 +102,12 @@ var Headroom = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
140
102
|
*/
|
|
141
103
|
function getScrollTop() {
|
|
142
104
|
var parent = this.props.parent;
|
|
143
|
-
|
|
144
105
|
if (parent && parent.scrollTop !== undefined && parent !== document.documentElement) {
|
|
145
106
|
return parent.scrollTop;
|
|
146
107
|
}
|
|
147
|
-
|
|
148
108
|
if (parent !== document.documentElement) {
|
|
149
109
|
console.warn('Could not find parent for StickyHeadroom. Defaulting to window, documentElement or body.');
|
|
150
110
|
}
|
|
151
|
-
|
|
152
111
|
if (window.pageYOffset !== undefined) {
|
|
153
112
|
return window.pageYOffset;
|
|
154
113
|
} else if (window.scrollTop !== undefined) {
|
|
@@ -199,6 +158,7 @@ var Headroom = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
199
158
|
value: function componentWillUnmount() {
|
|
200
159
|
this.removeScrollListener(this.props.parent);
|
|
201
160
|
}
|
|
161
|
+
|
|
202
162
|
/**
|
|
203
163
|
* If we're already static and pinStart + scrollHeight >= scrollTop, then we should stay static.
|
|
204
164
|
* If we're not already static, then we should set the header static, only when pinStart >= scrollTop (regardless of
|
|
@@ -208,7 +168,6 @@ var Headroom = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
208
168
|
* @param direction the current direction
|
|
209
169
|
* @returns {boolean} if we should set the header static
|
|
210
170
|
*/
|
|
211
|
-
|
|
212
171
|
}, {
|
|
213
172
|
key: "shouldSetStatic",
|
|
214
173
|
value: function shouldSetStatic(scrollTop, direction) {
|
|
@@ -218,13 +177,13 @@ var Headroom = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
218
177
|
return this.props.pinStart >= scrollTop;
|
|
219
178
|
}
|
|
220
179
|
}
|
|
180
|
+
|
|
221
181
|
/**
|
|
222
182
|
* Determines the mode depending on the scrollTop position and the current direction
|
|
223
183
|
* @param {number} scrollTop
|
|
224
184
|
* @param {string} direction
|
|
225
185
|
* @returns {string} the next mode of Headroom
|
|
226
186
|
*/
|
|
227
|
-
|
|
228
187
|
}, {
|
|
229
188
|
key: "determineMode",
|
|
230
189
|
value: function determineMode(scrollTop, direction) {
|
|
@@ -234,44 +193,42 @@ var Headroom = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
234
193
|
return direction === UPWARDS ? PINNED : UNPINNED;
|
|
235
194
|
}
|
|
236
195
|
}
|
|
196
|
+
|
|
237
197
|
/**
|
|
238
198
|
* @returns {TransitionType} determines the kind of transition
|
|
239
199
|
*/
|
|
240
|
-
|
|
241
200
|
}, {
|
|
242
201
|
key: "determineTransition",
|
|
243
202
|
value: function determineTransition(mode, direction) {
|
|
244
203
|
// Handle special case: If we're pinned and going to static, we need a special transition using css animation
|
|
245
204
|
if (this.state.mode === PINNED && mode === STATIC) {
|
|
246
205
|
return PINNED_TO_STATIC;
|
|
247
|
-
}
|
|
206
|
+
}
|
|
207
|
+
// If mode is static, then no transition, because we're already in the right spot
|
|
248
208
|
// (and want to change transform and top properties seamlessly)
|
|
249
|
-
|
|
250
|
-
|
|
251
209
|
if (mode === STATIC) {
|
|
252
210
|
return this.state.transition === NO_TRANSITION ? NO_TRANSITION : PINNED_TO_STATIC;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
|
|
211
|
+
}
|
|
212
|
+
// mode is not static, transition when moving upwards or when we've lastly did the transition
|
|
256
213
|
return direction === UPWARDS || this.state.transition === NORMAL_TRANSITION ? NORMAL_TRANSITION : NO_TRANSITION;
|
|
257
214
|
}
|
|
215
|
+
|
|
258
216
|
/**
|
|
259
217
|
* Checks the current scrollTop position and updates the state accordingly
|
|
260
218
|
*/
|
|
261
|
-
|
|
262
219
|
}, {
|
|
263
220
|
key: "render",
|
|
264
221
|
value: function render() {
|
|
265
222
|
var _this$props2 = this.props,
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
223
|
+
children = _this$props2.children,
|
|
224
|
+
scrollHeight = _this$props2.scrollHeight,
|
|
225
|
+
positionStickyDisabled = _this$props2.positionStickyDisabled,
|
|
226
|
+
zIndex = _this$props2.zIndex,
|
|
227
|
+
className = _this$props2.className;
|
|
271
228
|
var _this$state = this.state,
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
229
|
+
mode = _this$state.mode,
|
|
230
|
+
transition = _this$state.transition,
|
|
231
|
+
animateUpFrom = _this$state.animateUpFrom;
|
|
275
232
|
var transform = mode === UNPINNED ? -scrollHeight : 0;
|
|
276
233
|
var ownStickyTop = mode === STATIC ? -scrollHeight : 0;
|
|
277
234
|
return /*#__PURE__*/React.createElement(HeaderWrapper, {
|
|
@@ -291,15 +248,12 @@ var Headroom = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
291
248
|
return mode === PINNED ? height : height - scrollHeight;
|
|
292
249
|
}
|
|
293
250
|
}]);
|
|
294
|
-
|
|
295
251
|
return Headroom;
|
|
296
252
|
}(React.PureComponent);
|
|
297
|
-
|
|
298
253
|
_defineProperty(Headroom, "defaultProps", {
|
|
299
254
|
pinStart: 0,
|
|
300
255
|
zIndex: 1,
|
|
301
256
|
parent: window.document.documentElement
|
|
302
257
|
});
|
|
303
|
-
|
|
304
258
|
var _default = Headroom;
|
|
305
259
|
exports.default = _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@integreat-app/react-sticky-headroom",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=6.9",
|
|
6
6
|
"npm": ">=3.8"
|
|
@@ -42,13 +42,13 @@
|
|
|
42
42
|
"test:coverage": "jest --config jest.config.json --coverage",
|
|
43
43
|
"test:watch": "jest --config jest.config.json --watchAll",
|
|
44
44
|
"test:update": "jest --config jest.config.json -u",
|
|
45
|
-
"lint": "
|
|
46
|
-
"lint:fix": "
|
|
45
|
+
"lint": "npm run eslint && npm run stylelint",
|
|
46
|
+
"lint:fix": "npm run eslint --fix && npm run stylelint",
|
|
47
47
|
"eslint": "eslint .",
|
|
48
48
|
"stylelint": "stylelint './src/**/*.js'",
|
|
49
49
|
"flow:check-now": "flow check",
|
|
50
50
|
"flow:install-types": "flow-typed install --skip",
|
|
51
|
-
"prepublishOnly": "
|
|
51
|
+
"prepublishOnly": "npm run build && npm run build:demo && npm run test && npm run lint && npm run flow:check-now"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"react": "16.x.x || 17.x.x || 18.x.x",
|
|
@@ -77,6 +77,7 @@
|
|
|
77
77
|
"@babel/preset-flow": "^7.16.7",
|
|
78
78
|
"@babel/preset-react": "^7.16.7",
|
|
79
79
|
"@babel/runtime": "^7.17.8",
|
|
80
|
+
"@stylelint/postcss-css-in-js": "^0.38.0",
|
|
80
81
|
"babel-jest": "^27.5.1",
|
|
81
82
|
"babel-loader": "^8.2.4",
|
|
82
83
|
"babel-plugin-styled-components": "^2.0.6",
|
|
@@ -84,8 +85,8 @@
|
|
|
84
85
|
"enzyme": "^3.11.0",
|
|
85
86
|
"enzyme-adapter-react-16": "^1.15.6",
|
|
86
87
|
"enzyme-to-json": "^3.6.2",
|
|
87
|
-
"eslint": "^8.
|
|
88
|
-
"eslint-config-standard": "^
|
|
88
|
+
"eslint": "^8.25.0",
|
|
89
|
+
"eslint-config-standard": "^17.0.0",
|
|
89
90
|
"eslint-plugin-flowtype": "^8.0.3",
|
|
90
91
|
"eslint-plugin-import": "^2.25.4",
|
|
91
92
|
"eslint-plugin-jest": "^26.1.3",
|
|
@@ -94,7 +95,7 @@
|
|
|
94
95
|
"eslint-plugin-react": "^7.29.4",
|
|
95
96
|
"flow-bin": "~0.174.1",
|
|
96
97
|
"flow-copy-source": "^2.0.9",
|
|
97
|
-
"flow-typed": "^3.
|
|
98
|
+
"flow-typed": "^3.8.0",
|
|
98
99
|
"jest": "^27.5.1",
|
|
99
100
|
"jest-junit": "^13.0.0",
|
|
100
101
|
"jest-styled-components": "^7.0.8",
|
|
@@ -103,11 +104,9 @@
|
|
|
103
104
|
"react-dom": "^16.14.0",
|
|
104
105
|
"rimraf": "^3.0.2",
|
|
105
106
|
"styled-components": "^5.3.3",
|
|
106
|
-
"stylelint": "^14.
|
|
107
|
+
"stylelint": "^14.13.0",
|
|
107
108
|
"stylelint-config-recommended": "^7.0.0",
|
|
108
109
|
"stylelint-config-styled-components": "^0.1.1",
|
|
109
|
-
"stylelint-processor-styled-components": "^1.10.0",
|
|
110
110
|
"webpack": "^5.70.0"
|
|
111
|
-
}
|
|
112
|
-
"packageManager": "yarn@3.2.0"
|
|
111
|
+
}
|
|
113
112
|
}
|