@npm_leadtech/legal-lib-components 7.17.23 → 7.19.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.
@@ -18,7 +18,7 @@ export const NavBarDropDown: FC<NavBarDropDownProps> = ({
18
18
  setEnableScrollbarOnClose,
19
19
  setIsOpen
20
20
  }): React.ReactElement | null => {
21
- const [ref, isIntersectingWithElement] = useIntersectionObserver({
21
+ const [ref, isIntersectingWithElement] = useIntersectionObserver<HTMLDivElement>({
22
22
  options: { threshold: 0.15 }
23
23
  })
24
24
 
@@ -1,5 +1,9 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { SocialList } from './SocialLinks.styled';
3
+ import { useIntersectionObserver } from '../../../hooks';
3
4
  export const SocialLinks = ({ links }) => {
4
- return (_jsx(SocialList, { children: links.map((social) => (_jsx("li", { children: _jsx("a", { href: social.url, rel: 'noopener noreferrer', target: '_blank', children: _jsx("img", { src: social.iconSrc, alt: social.alt, width: '20', height: '20' }) }) }, social.url))) }));
5
+ return (_jsx(SocialList, { children: links.map((social) => {
6
+ const [ref, isIntersecting] = useIntersectionObserver({});
7
+ return (_jsx("li", { children: _jsx("a", { href: social.url, rel: 'noopener noreferrer', target: '_blank', children: _jsx("img", { ref: ref, src: isIntersecting ? social.iconSrc : '', alt: social.alt, width: '20', height: '20' }) }) }, social.url));
8
+ }) }));
5
9
  };
@@ -1,17 +1,21 @@
1
1
  import React from 'react'
2
2
  import { SocialLinksProps } from './SocialLinksProps.types'
3
3
  import { SocialList } from './SocialLinks.styled'
4
+ import { useIntersectionObserver } from '../../../hooks'
4
5
 
5
6
  export const SocialLinks: React.FC<SocialLinksProps> = ({ links }) => {
6
7
  return (
7
8
  <SocialList>
8
- {links.map((social) => (
9
- <li key={social.url}>
10
- <a href={social.url} rel='noopener noreferrer' target='_blank'>
11
- <img src={social.iconSrc} alt={social.alt} width='20' height='20' />
12
- </a>
13
- </li>
14
- ))}
9
+ {links.map((social) => {
10
+ const [ref, isIntersecting] = useIntersectionObserver<HTMLImageElement>({})
11
+ return (
12
+ <li key={social.url}>
13
+ <a href={social.url} rel='noopener noreferrer' target='_blank'>
14
+ <img ref={ref} src={isIntersecting ? social.iconSrc : ''} alt={social.alt} width='20' height='20' />
15
+ </a>
16
+ </li>
17
+ )
18
+ })}
15
19
  </SocialList>
16
20
  )
17
21
  }
@@ -1,5 +1,7 @@
1
- import { type LegacyRef } from 'react';
2
- export declare function useIntersectionObserver({ options, defaultIntersecting }: {
3
- options?: {} | undefined;
4
- defaultIntersecting?: boolean | undefined;
5
- }): [LegacyRef<HTMLDivElement> | undefined, boolean];
1
+ import { RefObject } from 'react';
2
+ interface UseIntersectionObserverParams {
3
+ options?: IntersectionObserverInit;
4
+ defaultIntersecting?: boolean;
5
+ }
6
+ export declare function useIntersectionObserver<T extends HTMLElement>({ options, defaultIntersecting }?: UseIntersectionObserverParams): [RefObject<T | null>, boolean];
7
+ export {};
@@ -1,21 +1,19 @@
1
1
  import { useEffect, useRef, useState } from 'react';
2
- export function useIntersectionObserver({ options = {}, defaultIntersecting = false }) {
2
+ export function useIntersectionObserver({ options = {}, defaultIntersecting = false } = {}) {
3
3
  const [isIntersecting, setIsIntersecting] = useState(defaultIntersecting);
4
4
  const elementRef = useRef(null);
5
5
  useEffect(() => {
6
6
  const currentElement = elementRef.current;
7
+ if (!currentElement)
8
+ return;
7
9
  const observer = new IntersectionObserver((entries) => {
8
10
  entries.forEach((entry) => {
9
11
  setIsIntersecting(entry.isIntersecting);
10
12
  });
11
13
  }, options);
12
- if (currentElement != null) {
13
- observer.observe(currentElement);
14
- }
14
+ observer.observe(currentElement);
15
15
  return () => {
16
- if (currentElement != null) {
17
- observer.unobserve(currentElement);
18
- }
16
+ observer.disconnect();
19
17
  };
20
18
  }, [options]);
21
19
  return [elementRef, isIntersecting];
@@ -1,14 +1,20 @@
1
- import { type LegacyRef, useEffect, useRef, useState } from 'react'
1
+ import { RefObject, useEffect, useRef, useState } from 'react'
2
2
 
3
- export function useIntersectionObserver({
3
+ interface UseIntersectionObserverParams {
4
+ options?: IntersectionObserverInit
5
+ defaultIntersecting?: boolean
6
+ }
7
+
8
+ export function useIntersectionObserver<T extends HTMLElement>({
4
9
  options = {},
5
10
  defaultIntersecting = false
6
- }): [LegacyRef<HTMLDivElement> | undefined, boolean] {
11
+ }: UseIntersectionObserverParams = {}): [RefObject<T | null>, boolean] {
7
12
  const [isIntersecting, setIsIntersecting] = useState(defaultIntersecting)
8
- const elementRef = useRef<HTMLDivElement>(null)
13
+ const elementRef = useRef<T>(null)
9
14
 
10
15
  useEffect(() => {
11
16
  const currentElement = elementRef.current
17
+ if (!currentElement) return
12
18
 
13
19
  const observer = new IntersectionObserver((entries) => {
14
20
  entries.forEach((entry) => {
@@ -16,14 +22,10 @@ export function useIntersectionObserver({
16
22
  })
17
23
  }, options)
18
24
 
19
- if (currentElement != null) {
20
- observer.observe(currentElement)
21
- }
25
+ observer.observe(currentElement)
22
26
 
23
27
  return () => {
24
- if (currentElement != null) {
25
- observer.unobserve(currentElement)
26
- }
28
+ observer.disconnect()
27
29
  }
28
30
  }, [options])
29
31
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@npm_leadtech/legal-lib-components",
3
- "version": "7.17.23",
3
+ "version": "7.19.0",
4
4
  "license": "ISC",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",