ublo-lib 1.3.2 → 1.3.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.
@@ -9,26 +9,30 @@ const ScrollSpy = ({
9
9
  currentClassName,
10
10
  Tag = "div",
11
11
  onUpdate,
12
- unsetCurrent
12
+ container
13
13
  }) => {
14
14
  const [current, setCurrent] = React.useState();
15
15
  const callback = React.useCallback(entries => {
16
16
  for (const entry of entries) {
17
- if (entry.isIntersecting) {
17
+ if (container === entry.target) {
18
+ if (!entry.isIntersecting) {
19
+ setCurrent(undefined);
20
+ onUpdate?.(undefined);
21
+ }
22
+ } else if (entry.isIntersecting) {
18
23
  const index = items.indexOf(entry.target.id);
19
24
  setCurrent(index);
20
25
  onUpdate?.(entry.target);
21
- } else if (unsetCurrent && !entry.isVisible) {
22
- setCurrent(undefined);
23
- onUpdate?.(undefined);
24
26
  }
25
27
  }
26
- }, [items, onUpdate, unsetCurrent]);
28
+ }, [container, items, onUpdate]);
27
29
  React.useEffect(() => {
30
+ const defaultTargets = container ? [container] : [];
28
31
  const targets = items.length ? items.reduce((acc, item) => {
29
32
  const element = document.getElementById(item);
30
33
  return element ? [...acc, element] : acc;
31
- }, []) : [];
34
+ }, defaultTargets) : defaultTargets;
35
+ console.log(targets);
32
36
  const observer = new IntersectionObserver(callback, {
33
37
  rootMargin: "-50% 0px"
34
38
  });
@@ -36,7 +40,7 @@ const ScrollSpy = ({
36
40
  return () => {
37
41
  observer.disconnect();
38
42
  };
39
- }, [callback, items]);
43
+ }, [callback, container, items]);
40
44
  return _jsx(Tag, {
41
45
  className: className,
42
46
  children: children.map(({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ublo-lib",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "peerDependencies": {
5
5
  "dt-design-system": "^2.1.0",
6
6
  "next": "^12.0.0",