@lark-apaas/client-toolkit 1.2.12 → 1.2.13

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.
@@ -0,0 +1 @@
1
+ export * from '../../hooks/useScrollReveal';
@@ -0,0 +1 @@
1
+ export * from "../../hooks/useScrollReveal.js";
@@ -2,3 +2,4 @@ export * from './useAppInfo';
2
2
  export * from './useCurrentUserProfile';
3
3
  export * from './useIsMobile';
4
4
  export * from './useLogout';
5
+ export * from './useScrollReveal';
@@ -2,3 +2,4 @@ export * from "./useAppInfo.js";
2
2
  export * from "./useCurrentUserProfile.js";
3
3
  export * from "./useIsMobile.js";
4
4
  export * from "./useLogout.js";
5
+ export * from "./useScrollReveal.js";
@@ -0,0 +1,61 @@
1
+ import { RefObject } from 'react';
2
+ /**
3
+ * Options for useScrollReveal hook
4
+ */
5
+ export interface UseScrollRevealOptions<T extends HTMLElement = HTMLElement> {
6
+ /** Ref to the container element to scope the query (default: document.body) */
7
+ containerRef?: RefObject<T | null>;
8
+ /** IntersectionObserver threshold - element visibility percentage to trigger (default: 0.1) */
9
+ threshold?: number;
10
+ /** IntersectionObserver rootMargin - margin around root (default: '0px 0px -50px 0px') */
11
+ rootMargin?: string;
12
+ /** CSS class to add when element becomes visible (default: 'visible') */
13
+ visibleClass?: string;
14
+ /** CSS selector for elements to observe (default: '.scroll-reveal') */
15
+ selector?: string;
16
+ }
17
+ /**
18
+ * Hook to enable scroll reveal animations using IntersectionObserver.
19
+ *
20
+ * Observes elements with the specified selector and adds a visibility class
21
+ * when they enter the viewport.
22
+ *
23
+ * @param options - Configuration options
24
+ *
25
+ * @example
26
+ * ```tsx
27
+ * // Usage without parameters (queries entire document.body)
28
+ * import { useScrollReveal } from '@lark-apaas/client-toolkit/hooks/useScrollReveal';
29
+ *
30
+ * function MyComponent() {
31
+ * useScrollReveal();
32
+ *
33
+ * return <div className="scroll-reveal">I will fade in on scroll!</div>;
34
+ * }
35
+ * ```
36
+ *
37
+ * @example
38
+ * ```tsx
39
+ * // Usage with container ref
40
+ * import { useRef } from 'react';
41
+ * import { useScrollReveal } from '@lark-apaas/client-toolkit/hooks/useScrollReveal';
42
+ *
43
+ * function MyComponent() {
44
+ * const containerRef = useRef<HTMLDivElement>(null);
45
+ * useScrollReveal({ containerRef });
46
+ *
47
+ * return (
48
+ * <div ref={containerRef}>
49
+ * <div className="scroll-reveal">I will fade in on scroll!</div>
50
+ * </div>
51
+ * );
52
+ * }
53
+ * ```
54
+ *
55
+ * @example
56
+ * ```tsx
57
+ * // Usage with custom options
58
+ * useScrollReveal({ threshold: 0.2, visibleClass: 'animate-in' });
59
+ * ```
60
+ */
61
+ export declare function useScrollReveal<T extends HTMLElement = HTMLElement>(options?: UseScrollRevealOptions<T>): void;
@@ -0,0 +1,37 @@
1
+ import { useEffect } from "react";
2
+ const DEFAULT_OPTIONS = {
3
+ threshold: 0.1,
4
+ rootMargin: '0px 0px -50px 0px',
5
+ visibleClass: 'visible',
6
+ selector: '.scroll-reveal'
7
+ };
8
+ function useScrollReveal(options) {
9
+ const { containerRef, threshold, rootMargin, visibleClass, selector } = {
10
+ ...DEFAULT_OPTIONS,
11
+ ...options
12
+ };
13
+ useEffect(()=>{
14
+ const container = containerRef?.current ?? document.body;
15
+ if (!container) return;
16
+ const observer = new IntersectionObserver((entries)=>{
17
+ entries.forEach((entry)=>{
18
+ if (entry.isIntersecting) entry.target.classList.add(visibleClass);
19
+ });
20
+ }, {
21
+ threshold,
22
+ rootMargin
23
+ });
24
+ const elements = container.querySelectorAll(selector);
25
+ elements.forEach((el)=>observer.observe(el));
26
+ return ()=>{
27
+ observer.disconnect();
28
+ };
29
+ }, [
30
+ containerRef,
31
+ threshold,
32
+ rootMargin,
33
+ visibleClass,
34
+ selector
35
+ ]);
36
+ }
37
+ export { useScrollReveal };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/client-toolkit",
3
- "version": "1.2.12",
3
+ "version": "1.2.13",
4
4
  "types": "./lib/index.d.ts",
5
5
  "main": "./lib/index.js",
6
6
  "files": [