@koine/react 1.1.6 → 1.1.8

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.
@@ -1,2 +1,8 @@
1
+ /**
2
+ *
3
+ * @param disregardAutomaticFixedOffset When the `to` scroll argument is a DOM
4
+ * selector we will keep into account the _fixedOffset_ despite this option.
5
+ * @returns
6
+ */
1
7
  export declare function useSmoothScroll(disregardAutomaticFixedOffset?: boolean): (to?: number | string, customOffset?: number, callback?: () => void, fallbackTimeout?: number, behavior?: ScrollBehavior) => void;
2
8
  export default useSmoothScroll;
@@ -2,24 +2,34 @@ import { useCallback } from "react";
2
2
  import { isNumber } from "@koine/utils";
3
3
  import { getOffsetTopSlim, scrollTo } from "@koine/dom";
4
4
  import { useFixedOffset } from "./useFixedOffset";
5
+ /**
6
+ *
7
+ * @param disregardAutomaticFixedOffset When the `to` scroll argument is a DOM
8
+ * selector we will keep into account the _fixedOffset_ despite this option.
9
+ * @returns
10
+ */
5
11
  export function useSmoothScroll(disregardAutomaticFixedOffset) {
6
12
  var fixedOffset = useFixedOffset();
7
13
  var scroll = useCallback(function (to, customOffset, callback, fallbackTimeout, behavior) {
8
14
  var top = undefined;
15
+ var toIsElement = false;
9
16
  if (isNumber(to)) {
10
17
  top = to;
11
18
  }
12
19
  else if (to) {
13
20
  var el = document.getElementById(to);
14
21
  if (el) {
15
- top = getOffsetTopSlim(el);
22
+ top = getOffsetTopSlim(el) - fixedOffset.current;
23
+ toIsElement = true;
16
24
  }
17
25
  }
18
26
  if (isNumber(top)) {
19
27
  top =
20
28
  top +
21
29
  (customOffset || 0) +
22
- (disregardAutomaticFixedOffset ? 0 : fixedOffset.current);
30
+ (disregardAutomaticFixedOffset || toIsElement
31
+ ? 0
32
+ : fixedOffset.current);
23
33
  scrollTo(top, callback, fallbackTimeout, behavior);
24
34
  }
25
35
  }, [disregardAutomaticFixedOffset, fixedOffset]);
@@ -5,24 +5,34 @@ var react_1 = require("react");
5
5
  var utils_1 = require("@koine/utils");
6
6
  var dom_1 = require("@koine/dom");
7
7
  var useFixedOffset_1 = require("./useFixedOffset");
8
+ /**
9
+ *
10
+ * @param disregardAutomaticFixedOffset When the `to` scroll argument is a DOM
11
+ * selector we will keep into account the _fixedOffset_ despite this option.
12
+ * @returns
13
+ */
8
14
  function useSmoothScroll(disregardAutomaticFixedOffset) {
9
15
  var fixedOffset = (0, useFixedOffset_1.useFixedOffset)();
10
16
  var scroll = (0, react_1.useCallback)(function (to, customOffset, callback, fallbackTimeout, behavior) {
11
17
  var top = undefined;
18
+ var toIsElement = false;
12
19
  if ((0, utils_1.isNumber)(to)) {
13
20
  top = to;
14
21
  }
15
22
  else if (to) {
16
23
  var el = document.getElementById(to);
17
24
  if (el) {
18
- top = (0, dom_1.getOffsetTopSlim)(el);
25
+ top = (0, dom_1.getOffsetTopSlim)(el) - fixedOffset.current;
26
+ toIsElement = true;
19
27
  }
20
28
  }
21
29
  if ((0, utils_1.isNumber)(top)) {
22
30
  top =
23
31
  top +
24
32
  (customOffset || 0) +
25
- (disregardAutomaticFixedOffset ? 0 : fixedOffset.current);
33
+ (disregardAutomaticFixedOffset || toIsElement
34
+ ? 0
35
+ : fixedOffset.current);
26
36
  (0, dom_1.scrollTo)(top, callback, fallbackTimeout, behavior);
27
37
  }
28
38
  }, [disregardAutomaticFixedOffset, fixedOffset]);
package/package.json CHANGED
@@ -50,7 +50,7 @@
50
50
  "framer-motion": "8.5.5",
51
51
  "react": "18.2.0",
52
52
  "@mui/base": "5.0.0-alpha.115",
53
- "@koine/utils": "1.1.6",
53
+ "@koine/utils": "1.1.8",
54
54
  "ts-debounce": "4.0.0",
55
55
  "type-fest": "3.5.3",
56
56
  "react-icons": "4.7.1",
@@ -60,10 +60,10 @@
60
60
  "@tiptap/starter-kit": "2.0.0-beta.209",
61
61
  "@kuus/yup": "1.0.0-beta.7",
62
62
  "react-hook-form": "7.42.1",
63
- "@koine/dom": "1.1.6",
63
+ "@koine/dom": "1.1.8",
64
64
  "react-popper": "2.3.0",
65
65
  "tslib": "2.5.0"
66
66
  },
67
- "version": "1.1.6",
67
+ "version": "1.1.8",
68
68
  "module": "./index.js"
69
69
  }