@integreat-app/react-sticky-headroom 1.2.2 → 2.0.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/README.md CHANGED
@@ -53,10 +53,16 @@ The component generally supports:
53
53
  * Firefox >= 40
54
54
  * Safari >= 6.2
55
55
 
56
+ However, if you want to support non-modern browsers, you are responsible for transpiling the code for your preferred target.
57
+
56
58
  For hiding and revealing the header, the browser needs to support the css-property `position: sticky`.
57
59
  You can read about the browser support for that on [caniuse.com](https://caniuse.com/#feat=css-sticky).
58
60
  'Partial-Support' is enough for ReactStickyHeadroom to work in most cases.
59
61
 
60
- ReactStickyHeadroom offers types for both TypeScript and FlowJS which should work out of the box.
62
+ Since version 2.x.x, ReactStickyHeadroom is written in TypeScript.
63
+ Support for FlowJS types were dropped in version 2.0.0.
64
+
65
+ ReactStickyHeadroom is a client-side library and hence does not support Server Side Rendering (SSR) a priori.
66
+ 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).
61
67
 
62
68
  If there are any problems, please don't hesitate to open an issue on GitHub.
package/index.d.ts CHANGED
@@ -1,18 +1,86 @@
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 from 'react';
2
+ declare const DIRECTION_UP = "up";
3
+ declare const DIRECTION_DOWN = "down";
4
+ declare const MODE_UNPINNED = "unpinned";
5
+ declare const MODE_PINNED = "pinned";
6
+ declare const MODE_STATIC = "static";
7
+ declare const TRANSITION_NONE = "none";
8
+ declare const TRANSITION_NORMAL = "normal";
9
+ declare const TRANSITION_PINNED_TO_STATIC = "pinned-to-static";
10
+ type ModeType = typeof MODE_PINNED | typeof MODE_UNPINNED | typeof MODE_STATIC;
11
+ type DirectionType = typeof DIRECTION_UP | typeof DIRECTION_DOWN;
12
+ type TransitionType = typeof TRANSITION_NONE | typeof TRANSITION_NORMAL | typeof TRANSITION_PINNED_TO_STATIC;
13
+ type PropsType = {
14
+ /** The child node to be displayed as a header */
15
+ children: React.ReactNode;
16
+ /** The maximum amount of px the header should move up when scrolling */
17
+ scrollHeight: number;
18
+ /** The minimum scrollTop position where the transform should start */
19
+ pinStart: number;
20
+ /** Used for calculating the stickyTop position of an ancestor */
21
+ height?: number;
22
+ /** Fired, when Headroom changes its state. Passes stickyTop of the ancestor. */
23
+ onStickyTopChanged?: (stickyTop: number) => void;
24
+ /** True, if sticky position should be disabled (e.g. for edge 16 support) */
25
+ positionStickyDisabled?: boolean;
26
+ /** The parent element firing the scroll event. Defaults to document.documentElement */
27
+ parent?: HTMLElement | null;
28
+ /** The z-index used by the wrapper. Defaults to 1. */
29
+ zIndex?: number;
30
+ /** A classname for applying custom styles to the wrapper. Use at your own risk. */
31
+ className?: string;
32
+ };
33
+ type StateType = {
34
+ mode: ModeType;
35
+ transition: TransitionType;
36
+ animateUpFrom: number | null;
37
+ };
38
+ declare class Headroom extends React.PureComponent<PropsType, StateType> {
39
+ static defaultProps: {
40
+ pinStart: number;
41
+ zIndex: number;
42
+ parent: HTMLElement | null;
43
+ };
44
+ state: StateType;
45
+ /** the very last scrollTop which we know about (to determine direction changes) */
46
+ lastKnownScrollTop: number;
47
+ /**
48
+ * @returns {number} the current scrollTop position of the window
49
+ */
50
+ getScrollTop(): number;
51
+ componentDidMount(): void;
52
+ addScrollListener(parent?: HTMLElement | null): void;
53
+ removeScrollListener(parent?: HTMLElement | null): void;
54
+ componentDidUpdate(prevProps: PropsType): void;
55
+ componentWillUnmount(): void;
56
+ /**
57
+ * If we're already static and pinStart + scrollHeight >= scrollTop, then we should stay static.
58
+ * If we're not already static, then we should set the header static, only when pinStart >= scrollTop (regardless of
59
+ * scrollHeight, so the header doesn't jump up, when scrolling upwards to the trigger).
60
+ * Else we shouldn't set it static.
61
+ * @param scrollTop the currentScrollTop position
62
+ * @param direction the current direction
63
+ * @returns {boolean} if we should set the header static
64
+ */
65
+ shouldSetStatic(scrollTop: number, direction: DirectionType): boolean;
66
+ /**
67
+ * Determines the mode depending on the scrollTop position and the current direction
68
+ * @param {number} scrollTop
69
+ * @param {string} direction
70
+ * @returns {string} the next mode of Headroom
71
+ */
72
+ determineMode(scrollTop: number, direction: DirectionType): ModeType;
73
+ /**
74
+ * @returns {TransitionType} determines the kind of transition
75
+ */
76
+ determineTransition(mode: ModeType, direction: DirectionType): TransitionType;
77
+ /**
78
+ * Checks the current scrollTop position and updates the state accordingly
79
+ */
80
+ update: () => void;
81
+ handleEvent: () => void;
82
+ static calcStickyTop(mode: ModeType, height: number, scrollHeight: number): number;
83
+ render(): React.ReactElement;
84
+ }
85
+ export default Headroom;
86
+ //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,QAAA,MAAM,YAAY,OAAO,CAAA;AACzB,QAAA,MAAM,cAAc,SAAS,CAAA;AAE7B,QAAA,MAAM,aAAa,aAAa,CAAA;AAChC,QAAA,MAAM,WAAW,WAAW,CAAA;AAC5B,QAAA,MAAM,WAAW,WAAW,CAAA;AAE5B,QAAA,MAAM,eAAe,SAAS,CAAA;AAC9B,QAAA,MAAM,iBAAiB,WAAW,CAAA;AAClC,QAAA,MAAM,2BAA2B,qBAAqB,CAAA;AAEtD,KAAK,QAAQ,GAAG,OAAO,WAAW,GAAG,OAAO,aAAa,GAAG,OAAO,WAAW,CAAA;AAC9E,KAAK,aAAa,GAAG,OAAO,YAAY,GAAG,OAAO,cAAc,CAAA;AAChE,KAAK,cAAc,GAAG,OAAO,eAA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OxC,oBAAoB;IAIpB;;;;;;;;OAQG;IACH,eAAe,CAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,GAAG,OAAO;IAWtE;;;;;OAKG;IACH,aAAa,CAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,GAAG,QAAQ;IAQrE;;OAEG;IACH,mBAAmB,CAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,GAAG,cAAc;IAmB9E;;OAEG;IACH,MAAM,EAAE,MAAM,IAAI,CAqBjB;IAED,WAAW,EAAE,MAAM,IAAI,CAEtB;IAED,MAAM,CAAC,aAAa,CAClB,IAAI,EAAE,QAAQ,EACd,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,GACnB,MAAM;IAIT,MAAM,IAAK,KAAK,CAAC,YAAY;CA2B9B;AAED,eAAe,QAAQ,CAAA"}
package/index.js CHANGED
@@ -1,305 +1,172 @@
1
- "use strict";
2
-
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
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = void 0;
9
-
10
- var React = _interopRequireWildcard(require("react"));
11
-
12
- var _styledComponents = _interopRequireWildcard(require("styled-components"));
13
-
14
- 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
- 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
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
19
-
20
- 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
- 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
- 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
-
28
- 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
- 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
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
33
-
34
- 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
-
38
- 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
- var UPWARDS = 'up';
41
- var DOWNWARDS = 'down';
42
- var UNPINNED = 'unpinned';
43
- var PINNED = 'pinned';
44
- var STATIC = 'static';
45
- var NO_TRANSITION = 'none';
46
- var NORMAL_TRANSITION = 'normal';
47
- var PINNED_TO_STATIC = 'pinned-to-static';
48
-
49
- var HeaderWrapper = _styledComponents.default.div.withConfig({
50
- displayName: "Headroom__HeaderWrapper",
51
- componentId: "sc-16d3zk-0"
52
- })(["position:", ";top:", "px;z-index:", ";transform:translateY(", "px);animation-duration:0.2s;animation-timing-function:ease-out;", " ", " ", ""], function (props) {
53
- return props.positionStickyDisabled ? 'static' : 'sticky';
54
- }, function (props) {
55
- return props.top;
56
- }, function (props) {
57
- return props.zIndex;
58
- }, function (props) {
59
- return props.translateY;
60
- }, function (props) {
61
- return props.transition === NORMAL_TRANSITION && !props.static ? 'transition: transform 0.2s ease-out;' : '';
62
- }, function (props) {
63
- return props.transition === PINNED_TO_STATIC ? (0, _styledComponents.css)(["animation-name:", ";"], keyframesMoveUpFrom(props.animateUpFrom)) : '';
64
- }, function (props) {
65
- return props.static ? 'transition: none;' : '';
66
- });
67
-
68
- var keyframesMoveUpFrom = function keyframesMoveUpFrom(from) {
69
- return (0, _styledComponents.keyframes)(["from{transform:translateY(", "px)}to{transform:translateY(0)}"], Math.max(from, 0));
70
- };
71
-
72
- var Headroom = /*#__PURE__*/function (_React$PureComponent) {
73
- _inherits(Headroom, _React$PureComponent);
74
-
75
- var _super = _createSuper(Headroom);
76
-
77
- function Headroom() {
78
- var _this;
79
-
80
- _classCallCheck(this, Headroom);
81
-
82
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
83
- args[_key] = arguments[_key];
84
- }
85
-
86
- _this = _super.call.apply(_super, [this].concat(args));
87
-
88
- _defineProperty(_assertThisInitialized(_this), "state", {
89
- mode: STATIC,
90
- transition: NO_TRANSITION,
91
- animateUpFrom: null
92
- });
93
-
94
- _defineProperty(_assertThisInitialized(_this), "lastKnownScrollTop", 0);
95
-
96
- _defineProperty(_assertThisInitialized(_this), "update", function () {
97
- var currentScrollTop = _this.getScrollTop();
98
-
99
- var newState = {};
100
-
101
- if (currentScrollTop === _this.lastKnownScrollTop) {
102
- return;
103
- }
104
-
105
- var direction = _this.lastKnownScrollTop < currentScrollTop ? DOWNWARDS : UPWARDS;
106
- newState.mode = _this.determineMode(currentScrollTop, direction);
107
- newState.transition = _this.determineTransition(newState.mode, direction);
108
- var _this$props = _this.props,
109
- onStickyTopChanged = _this$props.onStickyTopChanged,
110
- height = _this$props.height,
111
- scrollHeight = _this$props.scrollHeight,
112
- pinStart = _this$props.pinStart;
113
-
114
- if (_this.state.mode === PINNED && newState.mode === STATIC) {
115
- // animation in the special case from pinned to static
116
- newState.animateUpFrom = currentScrollTop - pinStart;
117
- }
118
-
119
- if (onStickyTopChanged && newState.mode !== _this.state.mode && height) {
120
- onStickyTopChanged(Headroom.calcStickyTop(newState.mode, height, scrollHeight));
121
- }
122
-
123
- _this.setState(newState);
124
-
125
- _this.lastKnownScrollTop = currentScrollTop;
126
- });
127
-
128
- _defineProperty(_assertThisInitialized(_this), "handleEvent", function () {
129
- window.requestAnimationFrame(_this.update);
130
- });
131
-
132
- return _this;
133
- }
134
-
135
- _createClass(Headroom, [{
136
- key: "getScrollTop",
137
- value:
1
+ import React from 'react';
2
+ import styled, { css, keyframes } from 'styled-components';
3
+ const DIRECTION_UP = 'up';
4
+ const DIRECTION_DOWN = 'down';
5
+ const MODE_UNPINNED = 'unpinned';
6
+ const MODE_PINNED = 'pinned';
7
+ const MODE_STATIC = 'static';
8
+ const TRANSITION_NONE = 'none';
9
+ const TRANSITION_NORMAL = 'normal';
10
+ const TRANSITION_PINNED_TO_STATIC = 'pinned-to-static';
11
+ const HeaderWrapper = styled.div([
12
+ "position:",
13
+ ";top:",
14
+ "px;z-index:",
15
+ ";transform:translateY(",
16
+ "px);animation-duration:0.2s;animation-timing-function:ease-out;",
17
+ " ",
18
+ " ",
19
+ ""
20
+ ], (props)=>props.$positionStickyDisabled ? 'static' : 'sticky', (props)=>props.$top, (props)=>props.$zIndex, (props)=>props.$translateY, (props)=>props.$transition === TRANSITION_NORMAL && !props.$static ? 'transition: transform 0.2s ease-out;' : '', (props)=>props.$transition === TRANSITION_PINNED_TO_STATIC && props.$animateUpFrom !== null ? css([
21
+ "animation-name:",
22
+ ";"
23
+ ], keyframesMoveUpFrom(props.$animateUpFrom)) : '', (props)=>props.$static ? 'transition: none;' : '');
24
+ const keyframesMoveUpFrom = (from)=>keyframes([
25
+ "from{transform:translateY(",
26
+ "px)}to{transform:translateY(0)}"
27
+ ], Math.max(from, 0));
28
+ class Headroom extends React.PureComponent {
29
+ static defaultProps = {
30
+ pinStart: 0,
31
+ zIndex: 1,
32
+ parent: window.document.documentElement
33
+ };
34
+ state = {
35
+ mode: MODE_STATIC,
36
+ transition: TRANSITION_NONE,
37
+ animateUpFrom: null
38
+ };
39
+ /** the very last scrollTop which we know about (to determine direction changes) */ lastKnownScrollTop = 0;
138
40
  /**
139
- * @returns {number} the current scrollTop position of the window
140
- */
141
- function getScrollTop() {
142
- var parent = this.props.parent;
143
-
144
- if (parent && parent.scrollTop !== undefined && parent !== document.documentElement) {
145
- return parent.scrollTop;
146
- }
147
-
148
- if (parent !== document.documentElement) {
149
- console.warn('Could not find parent for StickyHeadroom. Defaulting to window, documentElement or body.');
150
- }
151
-
152
- if (window.pageYOffset !== undefined) {
41
+ * @returns {number} the current scrollTop position of the window
42
+ */ getScrollTop() {
43
+ const parent = this.props.parent;
44
+ if (parent && parent.scrollTop !== undefined && parent !== document.documentElement) {
45
+ return parent.scrollTop;
46
+ }
47
+ if (parent !== document.documentElement) {
48
+ console.warn('Could not determine scrollTop from parent for StickyHeadroom. Defaulting to window.pageYOffset.');
49
+ }
50
+ if (window.pageYOffset === undefined) {
51
+ console.error('window.pageYOffset is undefined. Defaulting to 0.');
52
+ return 0;
53
+ }
153
54
  return window.pageYOffset;
154
- } else if (window.scrollTop !== undefined) {
155
- return window.scrollTop;
156
- } else if (document.documentElement) {
157
- return document.documentElement.scrollTop;
158
- } else if (document.body) {
159
- return document.body.scrollTop;
160
- } else {
161
- throw new Error('Could not determine scrollTop!');
162
- }
163
55
  }
164
- }, {
165
- key: "componentDidMount",
166
- value: function componentDidMount() {
167
- this.addScrollListener(this.props.parent);
56
+ componentDidMount() {
57
+ this.addScrollListener(this.props.parent);
168
58
  }
169
- }, {
170
- key: "addScrollListener",
171
- value: function addScrollListener(parent) {
172
- if (parent === window.document.documentElement) {
173
- window.addEventListener('scroll', this.handleEvent);
174
- } else if (parent) {
175
- parent.addEventListener('scroll', this.handleEvent);
176
- } else {
177
- console.debug('Property parent of Headroom is null. Assuming, parent will be set soon...');
178
- }
59
+ addScrollListener(parent) {
60
+ if (parent === window.document.documentElement) {
61
+ window.addEventListener('scroll', this.handleEvent);
62
+ } else if (parent) {
63
+ parent.addEventListener('scroll', this.handleEvent);
64
+ } else {
65
+ console.debug("'parent' prop of Headroom is null. Assuming, it will be set soon...");
66
+ }
179
67
  }
180
- }, {
181
- key: "removeScrollListener",
182
- value: function removeScrollListener(parent) {
183
- if (parent === window.document.documentElement) {
184
- window.removeEventListener('scroll', this.handleEvent);
185
- } else if (parent) {
186
- parent.removeEventListener('scroll', this.handleEvent);
187
- }
68
+ removeScrollListener(parent) {
69
+ if (parent === window.document.documentElement) {
70
+ window.removeEventListener('scroll', this.handleEvent);
71
+ } else if (parent) {
72
+ parent.removeEventListener('scroll', this.handleEvent);
73
+ }
188
74
  }
189
- }, {
190
- key: "componentDidUpdate",
191
- value: function componentDidUpdate(prevProps) {
192
- if (prevProps.parent !== this.props.parent) {
193
- this.removeScrollListener(prevProps.parent);
194
- this.addScrollListener(this.props.parent);
195
- }
75
+ componentDidUpdate(prevProps) {
76
+ if (prevProps.parent !== this.props.parent) {
77
+ this.removeScrollListener(prevProps.parent);
78
+ this.addScrollListener(this.props.parent);
79
+ }
196
80
  }
197
- }, {
198
- key: "componentWillUnmount",
199
- value: function componentWillUnmount() {
200
- this.removeScrollListener(this.props.parent);
81
+ componentWillUnmount() {
82
+ this.removeScrollListener(this.props.parent);
201
83
  }
202
84
  /**
203
- * If we're already static and pinStart + scrollHeight >= scrollTop, then we should stay static.
204
- * If we're not already static, then we should set the header static, only when pinStart >= scrollTop (regardless of
205
- * scrollHeight, so the header doesn't jump up, when scrolling upwards to the trigger).
206
- * Else we shouldn't set it static.
207
- * @param scrollTop the currentScrollTop position
208
- * @param direction the current direction
209
- * @returns {boolean} if we should set the header static
210
- */
211
-
212
- }, {
213
- key: "shouldSetStatic",
214
- value: function shouldSetStatic(scrollTop, direction) {
215
- if (this.state.mode === STATIC || this.state.mode === PINNED && direction === DOWNWARDS) {
216
- return this.props.pinStart + this.props.scrollHeight >= scrollTop;
217
- } else {
218
- return this.props.pinStart >= scrollTop;
219
- }
85
+ * If we're already static and pinStart + scrollHeight >= scrollTop, then we should stay static.
86
+ * If we're not already static, then we should set the header static, only when pinStart >= scrollTop (regardless of
87
+ * scrollHeight, so the header doesn't jump up, when scrolling upwards to the trigger).
88
+ * Else we shouldn't set it static.
89
+ * @param scrollTop the currentScrollTop position
90
+ * @param direction the current direction
91
+ * @returns {boolean} if we should set the header static
92
+ */ shouldSetStatic(scrollTop, direction) {
93
+ if (this.state.mode === MODE_STATIC || this.state.mode === MODE_PINNED && direction === DIRECTION_DOWN) {
94
+ return this.props.pinStart + this.props.scrollHeight >= scrollTop;
95
+ } else {
96
+ return this.props.pinStart >= scrollTop;
97
+ }
220
98
  }
221
99
  /**
222
- * Determines the mode depending on the scrollTop position and the current direction
223
- * @param {number} scrollTop
224
- * @param {string} direction
225
- * @returns {string} the next mode of Headroom
226
- */
227
-
228
- }, {
229
- key: "determineMode",
230
- value: function determineMode(scrollTop, direction) {
231
- if (this.shouldSetStatic(scrollTop, direction)) {
232
- return STATIC;
233
- } else {
234
- return direction === UPWARDS ? PINNED : UNPINNED;
235
- }
100
+ * Determines the mode depending on the scrollTop position and the current direction
101
+ * @param {number} scrollTop
102
+ * @param {string} direction
103
+ * @returns {string} the next mode of Headroom
104
+ */ determineMode(scrollTop, direction) {
105
+ if (this.shouldSetStatic(scrollTop, direction)) {
106
+ return MODE_STATIC;
107
+ } else {
108
+ return direction === DIRECTION_UP ? MODE_PINNED : MODE_UNPINNED;
109
+ }
236
110
  }
237
111
  /**
238
- * @returns {TransitionType} determines the kind of transition
239
- */
240
-
241
- }, {
242
- key: "determineTransition",
243
- value: function determineTransition(mode, direction) {
244
- // Handle special case: If we're pinned and going to static, we need a special transition using css animation
245
- if (this.state.mode === PINNED && mode === STATIC) {
246
- return PINNED_TO_STATIC;
247
- } // If mode is static, then no transition, because we're already in the right spot
248
- // (and want to change transform and top properties seamlessly)
249
-
250
-
251
- if (mode === STATIC) {
252
- return this.state.transition === NO_TRANSITION ? NO_TRANSITION : PINNED_TO_STATIC;
253
- } // mode is not static, transition when moving upwards or when we've lastly did the transition
254
-
255
-
256
- return direction === UPWARDS || this.state.transition === NORMAL_TRANSITION ? NORMAL_TRANSITION : NO_TRANSITION;
112
+ * @returns {TransitionType} determines the kind of transition
113
+ */ determineTransition(mode, direction) {
114
+ // Handle special case: If we're pinned and going to static, we need a special transition using css animation
115
+ if (this.state.mode === MODE_PINNED && mode === MODE_STATIC) {
116
+ return TRANSITION_PINNED_TO_STATIC;
117
+ }
118
+ // If mode is static, then no transition, because we're already in the right spot
119
+ // (and want to change transform and top properties seamlessly)
120
+ if (mode === MODE_STATIC) {
121
+ return this.state.transition === TRANSITION_NONE ? TRANSITION_NONE : TRANSITION_PINNED_TO_STATIC;
122
+ }
123
+ // mode is not static, transition when moving upwards or when we've lastly did the transition
124
+ return direction === DIRECTION_UP || this.state.transition === TRANSITION_NORMAL ? TRANSITION_NORMAL : TRANSITION_NONE;
257
125
  }
258
126
  /**
259
- * Checks the current scrollTop position and updates the state accordingly
260
- */
261
-
262
- }, {
263
- key: "render",
264
- value: function render() {
265
- var _this$props2 = this.props,
266
- children = _this$props2.children,
267
- scrollHeight = _this$props2.scrollHeight,
268
- positionStickyDisabled = _this$props2.positionStickyDisabled,
269
- zIndex = _this$props2.zIndex,
270
- className = _this$props2.className;
271
- var _this$state = this.state,
272
- mode = _this$state.mode,
273
- transition = _this$state.transition,
274
- animateUpFrom = _this$state.animateUpFrom;
275
- var transform = mode === UNPINNED ? -scrollHeight : 0;
276
- var ownStickyTop = mode === STATIC ? -scrollHeight : 0;
277
- return /*#__PURE__*/React.createElement(HeaderWrapper, {
278
- className: className,
279
- translateY: transform,
280
- top: ownStickyTop,
281
- transition: transition,
282
- positionStickyDisabled: positionStickyDisabled,
283
- static: mode === STATIC,
284
- animateUpFrom: animateUpFrom,
285
- zIndex: zIndex
286
- }, children);
127
+ * Checks the current scrollTop position and updates the state accordingly
128
+ */ update = ()=>{
129
+ const currentScrollTop = this.getScrollTop();
130
+ const newState = {};
131
+ if (currentScrollTop === this.lastKnownScrollTop) {
132
+ return;
133
+ }
134
+ const direction = this.lastKnownScrollTop < currentScrollTop ? DIRECTION_DOWN : DIRECTION_UP;
135
+ newState.mode = this.determineMode(currentScrollTop, direction);
136
+ newState.transition = this.determineTransition(newState.mode, direction);
137
+ const { onStickyTopChanged, height, scrollHeight, pinStart } = this.props;
138
+ if (this.state.mode === MODE_PINNED && newState.mode === MODE_STATIC) {
139
+ // animation in the special case from pinned to static
140
+ newState.animateUpFrom = currentScrollTop - pinStart;
141
+ }
142
+ if (onStickyTopChanged && newState.mode !== this.state.mode && height) {
143
+ onStickyTopChanged(Headroom.calcStickyTop(newState.mode, height, scrollHeight));
144
+ }
145
+ this.setState(newState);
146
+ this.lastKnownScrollTop = currentScrollTop;
147
+ };
148
+ handleEvent = ()=>{
149
+ window.requestAnimationFrame(this.update);
150
+ };
151
+ static calcStickyTop(mode, height, scrollHeight) {
152
+ return mode === MODE_PINNED ? height : height - scrollHeight;
287
153
  }
288
- }], [{
289
- key: "calcStickyTop",
290
- value: function calcStickyTop(mode, height, scrollHeight) {
291
- return mode === PINNED ? height : height - scrollHeight;
154
+ render() {
155
+ const { children, scrollHeight, positionStickyDisabled, zIndex, className } = this.props;
156
+ const { mode, transition, animateUpFrom } = this.state;
157
+ const transform = mode === MODE_UNPINNED ? -scrollHeight : 0;
158
+ const ownStickyTop = mode === MODE_STATIC ? -scrollHeight : 0;
159
+ return /*#__PURE__*/ React.createElement(HeaderWrapper, {
160
+ className: className,
161
+ $translateY: transform,
162
+ $top: ownStickyTop,
163
+ $transition: transition,
164
+ $positionStickyDisabled: !!positionStickyDisabled,
165
+ $static: mode === MODE_STATIC,
166
+ $animateUpFrom: animateUpFrom,
167
+ $zIndex: zIndex
168
+ }, children);
292
169
  }
293
- }]);
294
-
295
- return Headroom;
296
- }(React.PureComponent);
297
-
298
- _defineProperty(Headroom, "defaultProps", {
299
- pinStart: 0,
300
- zIndex: 1,
301
- parent: window.document.documentElement
302
- });
303
-
304
- var _default = Headroom;
305
- exports.default = _default;
170
+ }
171
+ export default Headroom;
172
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.tsx"],"sourcesContent":["import React from 'react'\nimport styled, { css, keyframes } from 'styled-components'\n\nconst DIRECTION_UP = 'up'\nconst DIRECTION_DOWN = 'down'\n\nconst MODE_UNPINNED = 'unpinned'\nconst MODE_PINNED = 'pinned'\nconst MODE_STATIC = 'static'\n\nconst TRANSITION_NONE = 'none'\nconst TRANSITION_NORMAL = 'normal'\nconst TRANSITION_PINNED_TO_STATIC = 'pinned-to-static'\n\ntype ModeType = typeof MODE_PINNED | typeof MODE_UNPINNED | typeof MODE_STATIC\ntype DirectionType = typeof DIRECTION_UP | typeof DIRECTION_DOWN\ntype TransitionType = typeof TRANSITION_NONE | typeof TRANSITION_NORMAL | typeof TRANSITION_PINNED_TO_STATIC\n\ntype PropsType = {\n /** The child node to be displayed as a header */\n children: React.ReactNode,\n /** The maximum amount of px the header should move up when scrolling */\n scrollHeight: number,\n /** The minimum scrollTop position where the transform should start */\n pinStart: number,\n /** Used for calculating the stickyTop position of an ancestor */\n height?: number,\n /** Fired, when Headroom changes its state. Passes stickyTop of the ancestor. */\n onStickyTopChanged?: (stickyTop: number) => void,\n /** True, if sticky position should be disabled (e.g. for edge 16 support) */\n positionStickyDisabled?: boolean,\n /** The parent element firing the scroll event. Defaults to document.documentElement */\n parent?: HTMLElement | null,\n /** The z-index used by the wrapper. Defaults to 1. */\n zIndex?: number,\n /** A classname for applying custom styles to the wrapper. Use at your own risk. */\n className?: string\n}\n\ntype StateType = {\n mode: ModeType,\n transition: TransitionType,\n animateUpFrom: number | null\n}\n\nconst HeaderWrapper = styled.div<{\n $positionStickyDisabled: boolean,\n $translateY: number,\n $transition: TransitionType,\n $animateUpFrom: number | null,\n $zIndex?: number,\n $top: number,\n $static: boolean\n}>`\n position: ${props => props.$positionStickyDisabled ? 'static' : 'sticky'};\n top: ${props => props.$top}px;\n z-index: ${props => props.$zIndex};\n transform: translateY(${props => props.$translateY}px);\n animation-duration: 0.2s;\n animation-timing-function: ease-out;\n ${props => props.$transition === TRANSITION_NORMAL && !props.$static\n ? 'transition: transform 0.2s ease-out;'\n : ''}\n ${props => props.$transition === TRANSITION_PINNED_TO_STATIC && props.$animateUpFrom !== null\n ? css`\n animation-name: ${keyframesMoveUpFrom(props.$animateUpFrom)};\n `\n : ''}\n ${props => props.$static ? 'transition: none;' : ''}\n`\n\nconst keyframesMoveUpFrom = (from: number) => keyframes`\n from {\n transform: translateY(${Math.max(from, 0)}px)\n }\n\n to {\n transform: translateY(0)\n }\n`\n\nclass Headroom extends React.PureComponent<PropsType, StateType> {\n static defaultProps: { pinStart: number, zIndex: number, parent: HTMLElement | null } = {\n pinStart: 0,\n zIndex: 1,\n parent: window.document.documentElement\n }\n\n state: StateType = {\n mode: MODE_STATIC,\n transition: TRANSITION_NONE,\n animateUpFrom: null\n }\n\n /** the very last scrollTop which we know about (to determine direction changes) */\n lastKnownScrollTop: number = 0\n\n /**\n * @returns {number} the current scrollTop position of the window\n */\n getScrollTop (): number {\n const parent = this.props.parent\n if (parent && parent.scrollTop !== undefined && parent !== document.documentElement) {\n return parent.scrollTop\n }\n if (parent !== document.documentElement) {\n console.warn('Could not determine scrollTop from parent for StickyHeadroom. Defaulting to window.pageYOffset.')\n }\n if (window.pageYOffset === undefined) {\n console.error('window.pageYOffset is undefined. Defaulting to 0.')\n return 0\n }\n return window.pageYOffset\n }\n\n componentDidMount () {\n this.addScrollListener(this.props.parent)\n }\n\n addScrollListener (parent?: HTMLElement | null) {\n if (parent === window.document.documentElement) {\n window.addEventListener('scroll', this.handleEvent)\n } else if (parent) {\n parent.addEventListener('scroll', this.handleEvent)\n } else {\n console.debug(\"'parent' prop of Headroom is null. Assuming, it will be set soon...\")\n }\n }\n\n removeScrollListener (parent?: HTMLElement | null) {\n if (parent === window.document.documentElement) {\n window.removeEventListener('scroll', this.handleEvent)\n } else if (parent) {\n parent.removeEventListener('scroll', this.handleEvent)\n }\n }\n\n componentDidUpdate (prevProps: PropsType) {\n if (prevProps.parent !== this.props.parent) {\n this.removeScrollListener(prevProps.parent)\n this.addScrollListener(this.props.parent)\n }\n }\n\n componentWillUnmount () {\n this.removeScrollListener(this.props.parent)\n }\n\n /**\n * If we're already static and pinStart + scrollHeight >= scrollTop, then we should stay static.\n * If we're not already static, then we should set the header static, only when pinStart >= scrollTop (regardless of\n * scrollHeight, so the header doesn't jump up, when scrolling upwards to the trigger).\n * Else we shouldn't set it static.\n * @param scrollTop the currentScrollTop position\n * @param direction the current direction\n * @returns {boolean} if we should set the header static\n */\n shouldSetStatic (scrollTop: number, direction: DirectionType): boolean {\n if (\n this.state.mode === MODE_STATIC ||\n (this.state.mode === MODE_PINNED && direction === DIRECTION_DOWN)\n ) {\n return this.props.pinStart + this.props.scrollHeight >= scrollTop\n } else {\n return this.props.pinStart >= scrollTop\n }\n }\n\n /**\n * Determines the mode depending on the scrollTop position and the current direction\n * @param {number} scrollTop\n * @param {string} direction\n * @returns {string} the next mode of Headroom\n */\n determineMode (scrollTop: number, direction: DirectionType): ModeType {\n if (this.shouldSetStatic(scrollTop, direction)) {\n return MODE_STATIC\n } else {\n return direction === DIRECTION_UP ? MODE_PINNED : MODE_UNPINNED\n }\n }\n\n /**\n * @returns {TransitionType} determines the kind of transition\n */\n determineTransition (mode: ModeType, direction: DirectionType): TransitionType {\n // Handle special case: If we're pinned and going to static, we need a special transition using css animation\n if (this.state.mode === MODE_PINNED && mode === MODE_STATIC) {\n return TRANSITION_PINNED_TO_STATIC\n }\n // If mode is static, then no transition, because we're already in the right spot\n // (and want to change transform and top properties seamlessly)\n if (mode === MODE_STATIC) {\n return this.state.transition === TRANSITION_NONE\n ? TRANSITION_NONE\n : TRANSITION_PINNED_TO_STATIC\n }\n // mode is not static, transition when moving upwards or when we've lastly did the transition\n return direction === DIRECTION_UP ||\n this.state.transition === TRANSITION_NORMAL\n ? TRANSITION_NORMAL\n : TRANSITION_NONE\n }\n\n /**\n * Checks the current scrollTop position and updates the state accordingly\n */\n update: () => void = () => {\n const currentScrollTop = this.getScrollTop()\n const newState: Partial<StateType> = {}\n if (currentScrollTop === this.lastKnownScrollTop) {\n return\n }\n const direction =\n this.lastKnownScrollTop < currentScrollTop ? DIRECTION_DOWN : DIRECTION_UP\n newState.mode = this.determineMode(currentScrollTop, direction)\n newState.transition = this.determineTransition(newState.mode, direction)\n\n const { onStickyTopChanged, height, scrollHeight, pinStart } = this.props\n if (this.state.mode === MODE_PINNED && newState.mode === MODE_STATIC) {\n // animation in the special case from pinned to static\n newState.animateUpFrom = currentScrollTop - pinStart\n }\n if (onStickyTopChanged && newState.mode !== this.state.mode && height) {\n onStickyTopChanged(Headroom.calcStickyTop(newState.mode, height, scrollHeight))\n }\n this.setState(newState as StateType)\n this.lastKnownScrollTop = currentScrollTop\n }\n\n handleEvent: () => void = () => {\n window.requestAnimationFrame(this.update)\n }\n\n static calcStickyTop (\n mode: ModeType,\n height: number,\n scrollHeight: number\n ): number {\n return mode === MODE_PINNED ? height : height - scrollHeight\n }\n\n render (): React.ReactElement {\n const {\n children,\n scrollHeight,\n positionStickyDisabled,\n zIndex,\n className\n } = this.props\n const {\n mode,\n transition,\n animateUpFrom\n } = this.state\n const transform = mode === MODE_UNPINNED ? -scrollHeight : 0\n const ownStickyTop = mode === MODE_STATIC ? -scrollHeight : 0\n return <HeaderWrapper\n className={className}\n $translateY={transform}\n $top={ownStickyTop}\n $transition={transition}\n $positionStickyDisabled={!!positionStickyDisabled}\n $static={mode === MODE_STATIC}\n $animateUpFrom={animateUpFrom}\n $zIndex={zIndex}>\n {children}\n </HeaderWrapper>\n }\n}\n\nexport default Headroom\n"],"names":["React","styled","css","keyframes","DIRECTION_UP","DIRECTION_DOWN","MODE_UNPINNED","MODE_PINNED","MODE_STATIC","TRANSITION_NONE","TRANSITION_NORMAL","TRANSITION_PINNED_TO_STATIC","HeaderWrapper","div","props","$positionStickyDisabled","$top","$zIndex","$translateY","$transition","$static","$animateUpFrom","keyframesMoveUpFrom","from","Math","max","Headroom","PureComponent","defaultProps","pinStart","zIndex","parent","window","document","documentElement","state","mode","transition","animateUpFrom","lastKnownScrollTop","getScrollTop","scrollTop","undefined","console","warn","pageYOffset","error","componentDidMount","addScrollListener","addEventListener","handleEvent","debug","removeScrollListener","removeEventListener","componentDidUpdate","prevProps","componentWillUnmount","shouldSetStatic","direction","scrollHeight","determineMode","determineTransition","update","currentScrollTop","newState","onStickyTopChanged","height","calcStickyTop","setState","requestAnimationFrame","render","children","positionStickyDisabled","className","transform","ownStickyTop"],"mappings":"AAAA,OAAOA,WAAW,QAAO;AACzB,OAAOC,UAAUC,GAAG,EAAEC,SAAS,QAAQ,oBAAmB;AAE1D,MAAMC,eAAe;AACrB,MAAMC,iBAAiB;AAEvB,MAAMC,gBAAgB;AACtB,MAAMC,cAAc;AACpB,MAAMC,cAAc;AAEpB,MAAMC,kBAAkB;AACxB,MAAMC,oBAAoB;AAC1B,MAAMC,8BAA8B;AAiCpC,MAAMC,gBAAgBX,OAAOY,GAAG;;;;;;;;;GASlBC,CAAAA,QAASA,MAAMC,uBAAuB,GAAG,WAAW,UACzDD,CAAAA,QAASA,MAAME,IAAI,EACfF,CAAAA,QAASA,MAAMG,OAAO,EACTH,CAAAA,QAASA,MAAMI,WAAW,EAGhDJ,CAAAA,QAASA,MAAMK,WAAW,KAAKT,qBAAqB,CAACI,MAAMM,OAAO,GAClE,yCACA,IACAN,CAAAA,QAASA,MAAMK,WAAW,KAAKR,+BAA+BG,MAAMO,cAAc,KAAK,OACvFnB;;;OACkBoB,oBAAoBR,MAAMO,cAAc,KAE1D,IACAP,CAAAA,QAASA,MAAMM,OAAO,GAAG,sBAAsB;AAGnD,MAAME,sBAAsB,CAACC,OAAiBpB;;;OAEhBqB,KAAKC,GAAG,CAACF,MAAM;AAQ7C,MAAMG,iBAAiB1B,MAAM2B,aAAa;IACxC,OAAOC,eAAiF;QACtFC,UAAU;QACVC,QAAQ;QACRC,QAAQC,OAAOC,QAAQ,CAACC,eAAe;IACzC,EAAC;IAEDC,QAAmB;Q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,WAAWA;YACXvD,aAAawD;YACb1D,MAAM2D;YACNxD,aAAakB;YACbtB,yBAAyB,CAAC,CAACyD;YAC3BpD,SAASgB,SAAS5B;YAClBa,gBAAgBiB;YAChBrB,SAASa;WACRyC;IAEL;AACF;AAEA,eAAe7C,SAAQ"}
@@ -1,28 +1,24 @@
1
- // @flow
2
-
3
- import type { Node } from 'react'
4
- import * as React from 'react'
5
- import type { StyledComponent } from 'styled-components'
1
+ import React from 'react'
6
2
  import styled, { css, keyframes } from 'styled-components'
7
3
 
8
- const UPWARDS = 'up'
9
- const DOWNWARDS = 'down'
4
+ const DIRECTION_UP = 'up'
5
+ const DIRECTION_DOWN = 'down'
10
6
 
11
- const UNPINNED = 'unpinned'
12
- const PINNED = 'pinned'
13
- const STATIC = 'static'
7
+ const MODE_UNPINNED = 'unpinned'
8
+ const MODE_PINNED = 'pinned'
9
+ const MODE_STATIC = 'static'
14
10
 
15
- const NO_TRANSITION = 'none'
16
- const NORMAL_TRANSITION = 'normal'
17
- const PINNED_TO_STATIC = 'pinned-to-static'
11
+ const TRANSITION_NONE = 'none'
12
+ const TRANSITION_NORMAL = 'normal'
13
+ const TRANSITION_PINNED_TO_STATIC = 'pinned-to-static'
18
14
 
19
- type ModeType = 'pinned' | 'unpinned' | 'static'
20
- type DirectionType = 'up' | 'down'
21
- type TransitionType = 'none' | 'normal' | 'pinned-to-static'
15
+ type ModeType = typeof MODE_PINNED | typeof MODE_UNPINNED | typeof MODE_STATIC
16
+ type DirectionType = typeof DIRECTION_UP | typeof DIRECTION_DOWN
17
+ type TransitionType = typeof TRANSITION_NONE | typeof TRANSITION_NORMAL | typeof TRANSITION_PINNED_TO_STATIC
22
18
 
23
- type PropsType = $ReadOnly<{|
19
+ type PropsType = {
24
20
  /** The child node to be displayed as a header */
25
- children: Node,
21
+ children: React.ReactNode,
26
22
  /** The maximum amount of px the header should move up when scrolling */
27
23
  scrollHeight: number,
28
24
  /** The minimum scrollTop position where the transform should start */
@@ -30,45 +26,47 @@ type PropsType = $ReadOnly<{|
30
26
  /** Used for calculating the stickyTop position of an ancestor */
31
27
  height?: number,
32
28
  /** Fired, when Headroom changes its state. Passes stickyTop of the ancestor. */
33
- onStickyTopChanged?: (number) => void,
29
+ onStickyTopChanged?: (stickyTop: number) => void,
34
30
  /** True, if sticky position should be disabled (e.g. for edge 16 support) */
35
31
  positionStickyDisabled?: boolean,
36
32
  /** The parent element firing the scroll event. Defaults to document.documentElement */
37
- parent: ?HTMLElement,
33
+ parent?: HTMLElement | null,
38
34
  /** The z-index used by the wrapper. Defaults to 1. */
39
35
  zIndex?: number,
40
36
  /** A classname for applying custom styles to the wrapper. Use at your own risk. */
41
37
  className?: string
42
- |}>
38
+ }
43
39
 
44
- type StateType = $ReadOnly<{|
40
+ type StateType = {
45
41
  mode: ModeType,
46
42
  transition: TransitionType,
47
- animateUpFrom: ?number
48
- |}>
43
+ animateUpFrom: number | null
44
+ }
49
45
 
50
- const HeaderWrapper: StyledComponent<{|
51
- positionStickyDisabled: boolean,
52
- translateY: number,
53
- transition: TransitionType,
54
- animateUpFrom: ?number,
55
- zIndex: number
56
- |}, *, *, *> = styled.div`
57
- position: ${props => props.positionStickyDisabled ? 'static' : 'sticky'};
58
- top: ${props => props.top}px;
59
- z-index: ${props => props.zIndex};
60
- transform: translateY(${props => props.translateY}px);
46
+ const HeaderWrapper = styled.div<{
47
+ $positionStickyDisabled: boolean,
48
+ $translateY: number,
49
+ $transition: TransitionType,
50
+ $animateUpFrom: number | null,
51
+ $zIndex?: number,
52
+ $top: number,
53
+ $static: boolean
54
+ }>`
55
+ position: ${props => props.$positionStickyDisabled ? 'static' : 'sticky'};
56
+ top: ${props => props.$top}px;
57
+ z-index: ${props => props.$zIndex};
58
+ transform: translateY(${props => props.$translateY}px);
61
59
  animation-duration: 0.2s;
62
60
  animation-timing-function: ease-out;
63
- ${props => props.transition === NORMAL_TRANSITION && !props.static
61
+ ${props => props.$transition === TRANSITION_NORMAL && !props.$static
64
62
  ? 'transition: transform 0.2s ease-out;'
65
63
  : ''}
66
- ${props => props.transition === PINNED_TO_STATIC
64
+ ${props => props.$transition === TRANSITION_PINNED_TO_STATIC && props.$animateUpFrom !== null
67
65
  ? css`
68
- animation-name: ${keyframesMoveUpFrom(props.animateUpFrom)};
66
+ animation-name: ${keyframesMoveUpFrom(props.$animateUpFrom)};
69
67
  `
70
68
  : ''}
71
- ${props => props.static ? 'transition: none;' : ''}
69
+ ${props => props.$static ? 'transition: none;' : ''}
72
70
  `
73
71
 
74
72
  const keyframesMoveUpFrom = (from: number) => keyframes`
@@ -79,18 +77,18 @@ const keyframesMoveUpFrom = (from: number) => keyframes`
79
77
  to {
80
78
  transform: translateY(0)
81
79
  }
82
- `
80
+ `
83
81
 
84
82
  class Headroom extends React.PureComponent<PropsType, StateType> {
85
- static defaultProps: {| pinStart: number, zIndex: number, parent: ?HTMLElement |} = {
83
+ static defaultProps: { pinStart: number, zIndex: number, parent: HTMLElement | null } = {
86
84
  pinStart: 0,
87
85
  zIndex: 1,
88
86
  parent: window.document.documentElement
89
87
  }
90
88
 
91
89
  state: StateType = {
92
- mode: STATIC,
93
- transition: NO_TRANSITION,
90
+ mode: MODE_STATIC,
91
+ transition: TRANSITION_NONE,
94
92
  animateUpFrom: null
95
93
  }
96
94
 
@@ -106,36 +104,30 @@ class Headroom extends React.PureComponent<PropsType, StateType> {
106
104
  return parent.scrollTop
107
105
  }
108
106
  if (parent !== document.documentElement) {
109
- console.warn('Could not find parent for StickyHeadroom. Defaulting to window, documentElement or body.')
107
+ console.warn('Could not determine scrollTop from parent for StickyHeadroom. Defaulting to window.pageYOffset.')
110
108
  }
111
- if (window.pageYOffset !== undefined) {
112
- return window.pageYOffset
113
- } else if (window.scrollTop !== undefined) {
114
- return window.scrollTop
115
- } else if (document.documentElement) {
116
- return document.documentElement.scrollTop
117
- } else if (document.body) {
118
- return document.body.scrollTop
119
- } else {
120
- throw new Error('Could not determine scrollTop!')
109
+ if (window.pageYOffset === undefined) {
110
+ console.error('window.pageYOffset is undefined. Defaulting to 0.')
111
+ return 0
121
112
  }
113
+ return window.pageYOffset
122
114
  }
123
115
 
124
116
  componentDidMount () {
125
117
  this.addScrollListener(this.props.parent)
126
118
  }
127
119
 
128
- addScrollListener (parent: ?HTMLElement) {
120
+ addScrollListener (parent?: HTMLElement | null) {
129
121
  if (parent === window.document.documentElement) {
130
122
  window.addEventListener('scroll', this.handleEvent)
131
123
  } else if (parent) {
132
124
  parent.addEventListener('scroll', this.handleEvent)
133
125
  } else {
134
- console.debug('Property parent of Headroom is null. Assuming, parent will be set soon...')
126
+ console.debug("'parent' prop of Headroom is null. Assuming, it will be set soon...")
135
127
  }
136
128
  }
137
129
 
138
- removeScrollListener (parent: ?HTMLElement) {
130
+ removeScrollListener (parent?: HTMLElement | null) {
139
131
  if (parent === window.document.documentElement) {
140
132
  window.removeEventListener('scroll', this.handleEvent)
141
133
  } else if (parent) {
@@ -164,8 +156,10 @@ class Headroom extends React.PureComponent<PropsType, StateType> {
164
156
  * @returns {boolean} if we should set the header static
165
157
  */
166
158
  shouldSetStatic (scrollTop: number, direction: DirectionType): boolean {
167
- if (this.state.mode === STATIC || (this.state.mode === PINNED && direction ===
168
- DOWNWARDS)) {
159
+ if (
160
+ this.state.mode === MODE_STATIC ||
161
+ (this.state.mode === MODE_PINNED && direction === DIRECTION_DOWN)
162
+ ) {
169
163
  return this.props.pinStart + this.props.scrollHeight >= scrollTop
170
164
  } else {
171
165
  return this.props.pinStart >= scrollTop
@@ -180,9 +174,9 @@ class Headroom extends React.PureComponent<PropsType, StateType> {
180
174
  */
181
175
  determineMode (scrollTop: number, direction: DirectionType): ModeType {
182
176
  if (this.shouldSetStatic(scrollTop, direction)) {
183
- return STATIC
177
+ return MODE_STATIC
184
178
  } else {
185
- return direction === UPWARDS ? PINNED : UNPINNED
179
+ return direction === DIRECTION_UP ? MODE_PINNED : MODE_UNPINNED
186
180
  }
187
181
  }
188
182
 
@@ -191,20 +185,21 @@ class Headroom extends React.PureComponent<PropsType, StateType> {
191
185
  */
192
186
  determineTransition (mode: ModeType, direction: DirectionType): TransitionType {
193
187
  // Handle special case: If we're pinned and going to static, we need a special transition using css animation
194
- if (this.state.mode === PINNED && mode === STATIC) {
195
- return PINNED_TO_STATIC
188
+ if (this.state.mode === MODE_PINNED && mode === MODE_STATIC) {
189
+ return TRANSITION_PINNED_TO_STATIC
196
190
  }
197
191
  // If mode is static, then no transition, because we're already in the right spot
198
192
  // (and want to change transform and top properties seamlessly)
199
- if (mode === STATIC) {
200
- return this.state.transition === NO_TRANSITION
201
- ? NO_TRANSITION
202
- : PINNED_TO_STATIC
193
+ if (mode === MODE_STATIC) {
194
+ return this.state.transition === TRANSITION_NONE
195
+ ? TRANSITION_NONE
196
+ : TRANSITION_PINNED_TO_STATIC
203
197
  }
204
198
  // mode is not static, transition when moving upwards or when we've lastly did the transition
205
- return direction === UPWARDS || this.state.transition === NORMAL_TRANSITION
206
- ? NORMAL_TRANSITION
207
- : NO_TRANSITION
199
+ return direction === DIRECTION_UP ||
200
+ this.state.transition === TRANSITION_NORMAL
201
+ ? TRANSITION_NORMAL
202
+ : TRANSITION_NONE
208
203
  }
209
204
 
210
205
  /**
@@ -212,30 +207,24 @@ class Headroom extends React.PureComponent<PropsType, StateType> {
212
207
  */
213
208
  update: () => void = () => {
214
209
  const currentScrollTop = this.getScrollTop()
215
- const newState = {}
210
+ const newState: Partial<StateType> = {}
216
211
  if (currentScrollTop === this.lastKnownScrollTop) {
217
212
  return
218
213
  }
219
- const direction = this.lastKnownScrollTop < currentScrollTop
220
- ? DOWNWARDS
221
- : UPWARDS
214
+ const direction =
215
+ this.lastKnownScrollTop < currentScrollTop ? DIRECTION_DOWN : DIRECTION_UP
222
216
  newState.mode = this.determineMode(currentScrollTop, direction)
223
217
  newState.transition = this.determineTransition(newState.mode, direction)
224
218
 
225
- const {
226
- onStickyTopChanged,
227
- height,
228
- scrollHeight,
229
- pinStart
230
- } = this.props
231
- if (this.state.mode === PINNED && newState.mode === STATIC) {
219
+ const { onStickyTopChanged, height, scrollHeight, pinStart } = this.props
220
+ if (this.state.mode === MODE_PINNED && newState.mode === MODE_STATIC) {
232
221
  // animation in the special case from pinned to static
233
222
  newState.animateUpFrom = currentScrollTop - pinStart
234
223
  }
235
224
  if (onStickyTopChanged && newState.mode !== this.state.mode && height) {
236
225
  onStickyTopChanged(Headroom.calcStickyTop(newState.mode, height, scrollHeight))
237
226
  }
238
- this.setState(newState)
227
+ this.setState(newState as StateType)
239
228
  this.lastKnownScrollTop = currentScrollTop
240
229
  }
241
230
 
@@ -248,10 +237,10 @@ class Headroom extends React.PureComponent<PropsType, StateType> {
248
237
  height: number,
249
238
  scrollHeight: number
250
239
  ): number {
251
- return mode === PINNED ? height : height - scrollHeight
240
+ return mode === MODE_PINNED ? height : height - scrollHeight
252
241
  }
253
242
 
254
- render (): * {
243
+ render (): React.ReactElement {
255
244
  const {
256
245
  children,
257
246
  scrollHeight,
@@ -264,17 +253,17 @@ class Headroom extends React.PureComponent<PropsType, StateType> {
264
253
  transition,
265
254
  animateUpFrom
266
255
  } = this.state
267
- const transform = mode === UNPINNED ? -scrollHeight : 0
268
- const ownStickyTop = mode === STATIC ? -scrollHeight : 0
256
+ const transform = mode === MODE_UNPINNED ? -scrollHeight : 0
257
+ const ownStickyTop = mode === MODE_STATIC ? -scrollHeight : 0
269
258
  return <HeaderWrapper
270
259
  className={className}
271
- translateY={transform}
272
- top={ownStickyTop}
273
- transition={transition}
274
- positionStickyDisabled={positionStickyDisabled}
275
- static={mode === STATIC}
276
- animateUpFrom={animateUpFrom}
277
- zIndex={zIndex}>
260
+ $translateY={transform}
261
+ $top={ownStickyTop}
262
+ $transition={transition}
263
+ $positionStickyDisabled={!!positionStickyDisabled}
264
+ $static={mode === MODE_STATIC}
265
+ $animateUpFrom={animateUpFrom}
266
+ $zIndex={zIndex}>
278
267
  {children}
279
268
  </HeaderWrapper>
280
269
  }
package/package.json CHANGED
@@ -1,25 +1,23 @@
1
1
  {
2
2
  "name": "@integreat-app/react-sticky-headroom",
3
- "version": "1.2.2",
3
+ "version": "2.0.0",
4
4
  "engines": {
5
- "node": ">=6.9",
6
- "npm": ">=3.8"
5
+ "node": ">=18",
6
+ "npm": ">=10"
7
7
  },
8
- "browserslist": [
9
- "ie >= 11",
10
- "edge >= 16",
11
- "chrome >= 41",
12
- "firefox >= 40",
13
- "safari >= 6.2"
14
- ],
15
8
  "license": "MIT",
16
9
  "description": "ReactStickyHeadroom is a React Component for hiding the header when scrolling.",
17
10
  "author": "Michael Markl <marklmichael98@gmail.com>",
18
- "repository": "https://github.com/integreat/react-sticky-headroom",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/integreat/react-sticky-headroom.git"
14
+ },
19
15
  "files": [
20
16
  "index.js",
21
- "index.js.flow",
22
- "index.d.ts"
17
+ "index.js.map",
18
+ "index.d.ts",
19
+ "index.d.ts.map",
20
+ "index.tsx"
23
21
  ],
24
22
  "publishConfig": {
25
23
  "access": "public"
@@ -31,83 +29,74 @@
31
29
  "hide",
32
30
  "header",
33
31
  "styled-components",
34
- "typescript",
35
- "flow"
32
+ "typescript"
36
33
  ],
37
- "module": "index.js",
34
+ "module": "./index.js",
38
35
  "scripts": {
39
- "build": "node tools/build.js",
40
- "build:demo": "node tools/build.demo.js",
36
+ "build": "ts-node tools/build.ts",
37
+ "build:demo": "webpack --config tools/demo.webpack.config.ts",
41
38
  "test": "jest --config jest.config.json",
42
39
  "test:coverage": "jest --config jest.config.json --coverage",
43
40
  "test:watch": "jest --config jest.config.json --watchAll",
44
41
  "test:update": "jest --config jest.config.json -u",
45
- "lint": "yarn run eslint && yarn run stylelint",
46
- "lint:fix": "yarn run eslint --fix && yarn run stylelint",
42
+ "lint": "npm run eslint && npm run stylelint",
43
+ "lint:fix": "eslint . --fix && npm run stylelint",
47
44
  "eslint": "eslint .",
48
- "stylelint": "stylelint './src/**/*.js'",
49
- "flow:check-now": "flow check",
50
- "flow:install-types": "flow-typed install --skip",
51
- "prepublishOnly": "yarn build && yarn build:demo && yarn test && yarn lint && yarn flow:check-now"
45
+ "stylelint": "stylelint './src/**/*.{ts,tsx}'",
46
+ "ts:check": "tsc",
47
+ "prepublishOnly": "npm run build && npm run build:demo && npm run test && npm run lint && npm run ts:check"
52
48
  },
49
+ "//": "browserslist only affects the build of the demo app, not the library itself.",
50
+ "browserslist": [
51
+ "ie >= 11",
52
+ "edge >= 16",
53
+ "chrome >= 41",
54
+ "firefox >= 40",
55
+ "safari >= 6.2"
56
+ ],
53
57
  "peerDependencies": {
54
58
  "react": "16.x.x || 17.x.x || 18.x.x",
55
- "styled-components": "4.x.x || 5.x.x"
59
+ "styled-components": "4.x.x || 5.x.x || 6.x.x"
56
60
  },
57
61
  "devDependencies": {
58
- "@babel/cli": "^7.17.6",
59
- "@babel/core": "^7.17.8",
60
- "@babel/eslint-parser": "^7.17.0",
61
- "@babel/plugin-proposal-class-properties": "^7.16.7",
62
- "@babel/plugin-proposal-do-expressions": "^7.16.7",
63
- "@babel/plugin-proposal-export-default-from": "^7.16.7",
64
- "@babel/plugin-proposal-export-namespace-from": "^7.16.7",
65
- "@babel/plugin-proposal-json-strings": "^7.16.7",
66
- "@babel/plugin-proposal-logical-assignment-operators": "^7.16.7",
67
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.7",
68
- "@babel/plugin-proposal-numeric-separator": "^7.16.7",
69
- "@babel/plugin-proposal-optional-chaining": "^7.16.7",
70
- "@babel/plugin-proposal-pipeline-operator": "^7.17.6",
71
- "@babel/plugin-proposal-throw-expressions": "^7.16.7",
72
- "@babel/plugin-syntax-dynamic-import": "^7.8.3",
73
- "@babel/plugin-syntax-import-meta": "^7.10.4",
74
- "@babel/plugin-transform-react-jsx": "^7.17.3",
75
- "@babel/plugin-transform-runtime": "^7.17.0",
76
- "@babel/preset-env": "^7.16.11",
77
- "@babel/preset-flow": "^7.16.7",
78
- "@babel/preset-react": "^7.16.7",
79
- "@babel/runtime": "^7.17.8",
80
- "babel-jest": "^27.5.1",
81
- "babel-loader": "^8.2.4",
82
- "babel-plugin-styled-components": "^2.0.6",
83
- "browserslist": "^4.20.2",
62
+ "@stylelint/postcss-css-in-js": "^0.38.0",
63
+ "@swc/core": "^1.3.100",
64
+ "@swc/jest": "^0.2.29",
65
+ "@swc/plugin-styled-components": "^1.5.105",
66
+ "@types/enzyme": "^3.10.15",
67
+ "@types/enzyme-adapter-react-16": "^1.0.8",
68
+ "@types/jest": "^29.5.6",
69
+ "@types/node": "^20.8.7",
70
+ "@types/react": "16",
71
+ "@types/react-dom": "^18.2.13",
72
+ "@types/styled-components": "^5.1.34",
73
+ "@typescript-eslint/eslint-plugin": "6.8.0",
74
+ "@typescript-eslint/parser": "^6.8.0",
75
+ "browserslist": "^4.22.2",
84
76
  "enzyme": "^3.11.0",
85
77
  "enzyme-adapter-react-16": "^1.15.6",
86
78
  "enzyme-to-json": "^3.6.2",
87
- "eslint": "^8.11.0",
88
- "eslint-config-standard": "^16.0.3",
89
- "eslint-plugin-flowtype": "^8.0.3",
90
- "eslint-plugin-import": "^2.25.4",
91
- "eslint-plugin-jest": "^26.1.3",
79
+ "eslint": "^8.51.0",
80
+ "eslint-config-standard": "^17.1.0",
81
+ "eslint-plugin-import": "^2.28.1",
82
+ "eslint-plugin-jest": "^27.4.2",
92
83
  "eslint-plugin-node": "^11.1.0",
93
- "eslint-plugin-promise": "^6.0.0",
94
- "eslint-plugin-react": "^7.29.4",
95
- "flow-bin": "~0.174.1",
96
- "flow-copy-source": "^2.0.9",
97
- "flow-typed": "^3.7.0",
84
+ "eslint-plugin-promise": "^6.1.1",
85
+ "eslint-plugin-react": "^7.33.2",
98
86
  "jest": "^27.5.1",
99
87
  "jest-junit": "^13.0.0",
100
88
  "jest-styled-components": "^7.0.8",
101
89
  "raf": "^3.4.1",
102
90
  "react": "^16.14.0",
103
91
  "react-dom": "^16.14.0",
104
- "rimraf": "^3.0.2",
105
- "styled-components": "^5.3.3",
106
- "stylelint": "^14.6.0",
107
- "stylelint-config-recommended": "^7.0.0",
92
+ "styled-components": "^6.1.2",
93
+ "stylelint": "^15.6.0",
94
+ "stylelint-config-recommended": "^12.0.0",
108
95
  "stylelint-config-styled-components": "^0.1.1",
109
- "stylelint-processor-styled-components": "^1.10.0",
110
- "webpack": "^5.70.0"
111
- },
112
- "packageManager": "yarn@3.2.0"
96
+ "swc-loader": "^0.2.3",
97
+ "ts-node": "^10.9.1",
98
+ "typescript": "^5.2.2",
99
+ "webpack": "^5.70.0",
100
+ "webpack-cli": "^5.1.4"
101
+ }
113
102
  }