@jump-section/react 1.0.0 → 1.0.1
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 +127 -0
- package/package.json +3 -2
package/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# @jump-section/react
|
|
2
|
+
|
|
3
|
+
React hooks for jump-section scroll management. Easily add scroll-to-section navigation to your React applications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @jump-section/react
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @jump-section/react
|
|
11
|
+
# or
|
|
12
|
+
yarn add @jump-section/react
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### Basic Example
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { ScrollSectionProvider, useScrollSection } from '@jump-section/react';
|
|
21
|
+
|
|
22
|
+
function App() {
|
|
23
|
+
return (
|
|
24
|
+
<ScrollSectionProvider offset={-80} behavior="smooth">
|
|
25
|
+
<Navigation />
|
|
26
|
+
<Content />
|
|
27
|
+
</ScrollSectionProvider>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function Navigation() {
|
|
32
|
+
const { scrollTo, activeId } = useScrollSection();
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<nav>
|
|
36
|
+
<button
|
|
37
|
+
onClick={() => scrollTo('section-1')}
|
|
38
|
+
className={activeId === 'section-1' ? 'active' : ''}
|
|
39
|
+
>
|
|
40
|
+
Section 1
|
|
41
|
+
</button>
|
|
42
|
+
<button
|
|
43
|
+
onClick={() => scrollTo('section-2')}
|
|
44
|
+
className={activeId === 'section-2' ? 'active' : ''}
|
|
45
|
+
>
|
|
46
|
+
Section 2
|
|
47
|
+
</button>
|
|
48
|
+
</nav>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function Content() {
|
|
53
|
+
const { registerRef: ref1 } = useScrollSection('section-1');
|
|
54
|
+
const { registerRef: ref2 } = useScrollSection('section-2');
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<main>
|
|
58
|
+
<section ref={ref1}>
|
|
59
|
+
<h2>Section 1</h2>
|
|
60
|
+
<p>Content for section 1...</p>
|
|
61
|
+
</section>
|
|
62
|
+
<section ref={ref2}>
|
|
63
|
+
<h2>Section 2</h2>
|
|
64
|
+
<p>Content for section 2...</p>
|
|
65
|
+
</section>
|
|
66
|
+
</main>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### With Active State
|
|
72
|
+
|
|
73
|
+
```tsx
|
|
74
|
+
function Section({ id, title, children }) {
|
|
75
|
+
const { registerRef, isActive } = useScrollSection(id);
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<section ref={registerRef} className={isActive ? 'active' : ''}>
|
|
79
|
+
<h2>{title}</h2>
|
|
80
|
+
{children}
|
|
81
|
+
</section>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## API
|
|
87
|
+
|
|
88
|
+
### `ScrollSectionProvider`
|
|
89
|
+
|
|
90
|
+
Provides scroll management context to child components.
|
|
91
|
+
|
|
92
|
+
**Props:**
|
|
93
|
+
|
|
94
|
+
- `offset?: number` - Vertical offset in pixels (useful for fixed headers)
|
|
95
|
+
- `behavior?: ScrollBehavior` - Scroll behavior: `'smooth'` | `'instant'` | `'auto'`
|
|
96
|
+
- `children: ReactNode` - Child components
|
|
97
|
+
|
|
98
|
+
### `useScrollSection(sectionId?: string)`
|
|
99
|
+
|
|
100
|
+
Hook for managing scroll sections.
|
|
101
|
+
|
|
102
|
+
**Parameters:**
|
|
103
|
+
|
|
104
|
+
- `sectionId?: string` - Optional section ID to register
|
|
105
|
+
|
|
106
|
+
**Returns:**
|
|
107
|
+
|
|
108
|
+
- `registerRef: (element: HTMLElement | null) => void` - Ref callback to register the section element
|
|
109
|
+
- `scrollTo: (id: string) => void` - Function to scroll to a specific section
|
|
110
|
+
- `activeId: string | null` - Currently active section ID
|
|
111
|
+
- `isActive: boolean` - Whether this section is currently active (only if sectionId provided)
|
|
112
|
+
|
|
113
|
+
### `useScrollManager()`
|
|
114
|
+
|
|
115
|
+
Hook to access the underlying ScrollManager instance directly.
|
|
116
|
+
|
|
117
|
+
**Returns:**
|
|
118
|
+
|
|
119
|
+
- `ScrollManager` - The scroll manager instance
|
|
120
|
+
|
|
121
|
+
## TypeScript
|
|
122
|
+
|
|
123
|
+
This package includes TypeScript definitions.
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
|
|
127
|
+
ISC
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jump-section/react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "React hooks for jump-section scroll management",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"scroll",
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"types": "dist/index.d.ts",
|
|
23
23
|
"sideEffects": false,
|
|
24
24
|
"files": [
|
|
25
|
-
"dist"
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md"
|
|
26
27
|
],
|
|
27
28
|
"dependencies": {
|
|
28
29
|
"@jump-section/core": "workspace:*"
|