@jump-section/vue 1.0.20 → 1.0.22
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 +94 -78
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<img src="https://raw.githubusercontent.com/bae080311/jump-section/main/docs/public/logo.png" alt="Jump Section Logo" width="200" />
|
|
5
5
|
</div>
|
|
6
6
|
|
|
7
|
-
Vue composables for jump-section scroll management.
|
|
7
|
+
Vue composables for jump-section scroll management.
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
@@ -16,125 +16,141 @@ pnpm add @jump-section/vue
|
|
|
16
16
|
yarn add @jump-section/vue
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
+
## Requirements
|
|
20
|
+
|
|
21
|
+
- Vue 3.0.0 or higher
|
|
22
|
+
|
|
19
23
|
## Usage
|
|
20
24
|
|
|
21
25
|
### Basic Example
|
|
22
26
|
|
|
23
27
|
```vue
|
|
24
|
-
<script setup>
|
|
28
|
+
<script setup lang="ts">
|
|
29
|
+
import { ScrollSectionProvider } from '@jump-section/vue';
|
|
30
|
+
import Navigation from './Navigation.vue';
|
|
31
|
+
import Content from './Content.vue';
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<template>
|
|
35
|
+
<ScrollSectionProvider :offset="-80" behavior="smooth">
|
|
36
|
+
<Navigation />
|
|
37
|
+
<Content />
|
|
38
|
+
</ScrollSectionProvider>
|
|
39
|
+
</template>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**Navigation.vue**
|
|
43
|
+
|
|
44
|
+
```vue
|
|
45
|
+
<script setup lang="ts">
|
|
25
46
|
import { useScrollSection } from '@jump-section/vue';
|
|
26
47
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
48
|
+
const { scrollTo, activeId } = useScrollSection();
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<template>
|
|
52
|
+
<nav>
|
|
53
|
+
<button @click="scrollTo('section-1')" :class="{ active: activeId === 'section-1' }">
|
|
54
|
+
Section 1
|
|
55
|
+
</button>
|
|
56
|
+
<button @click="scrollTo('section-2')" :class="{ active: activeId === 'section-2' }">
|
|
57
|
+
Section 2
|
|
58
|
+
</button>
|
|
59
|
+
</nav>
|
|
60
|
+
</template>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**Content.vue**
|
|
64
|
+
|
|
65
|
+
```vue
|
|
66
|
+
<script setup lang="ts">
|
|
67
|
+
import { useScrollSection } from '@jump-section/vue';
|
|
32
68
|
|
|
33
|
-
// Register sections
|
|
34
69
|
const { registerRef: section1Ref } = useScrollSection('section-1');
|
|
35
70
|
const { registerRef: section2Ref } = useScrollSection('section-2');
|
|
36
71
|
</script>
|
|
37
72
|
|
|
38
73
|
<template>
|
|
39
|
-
<
|
|
40
|
-
<
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
</button>
|
|
44
|
-
<button @click="scrollTo('section-2')" :class="{ active: activeId === 'section-2' }">
|
|
45
|
-
Section 2
|
|
46
|
-
</button>
|
|
47
|
-
</nav>
|
|
48
|
-
|
|
49
|
-
<main>
|
|
50
|
-
<section :ref="section1Ref">
|
|
51
|
-
<h2>Section 1</h2>
|
|
52
|
-
<p>Content for section 1...</p>
|
|
53
|
-
</section>
|
|
54
|
-
<section :ref="section2Ref">
|
|
55
|
-
<h2>Section 2</h2>
|
|
56
|
-
<p>Content for section 2...</p>
|
|
57
|
-
</section>
|
|
58
|
-
</main>
|
|
59
|
-
</div>
|
|
74
|
+
<main>
|
|
75
|
+
<section :ref="section1Ref"><h2>Section 1</h2></section>
|
|
76
|
+
<section :ref="section2Ref"><h2>Section 2</h2></section>
|
|
77
|
+
</main>
|
|
60
78
|
</template>
|
|
61
79
|
```
|
|
62
80
|
|
|
63
|
-
###
|
|
81
|
+
### Scroll Progress
|
|
64
82
|
|
|
65
83
|
```vue
|
|
66
|
-
<script setup>
|
|
67
|
-
import {
|
|
84
|
+
<script setup lang="ts">
|
|
85
|
+
import { useScrollProgress } from '@jump-section/vue';
|
|
68
86
|
|
|
69
|
-
const props = defineProps(
|
|
70
|
-
|
|
71
|
-
title: String,
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
const { registerRef, isActive } = useScrollSection(props.id);
|
|
87
|
+
const props = defineProps<{ id: string }>();
|
|
88
|
+
const progress = useScrollProgress(props.id);
|
|
75
89
|
</script>
|
|
76
90
|
|
|
77
91
|
<template>
|
|
78
|
-
<
|
|
79
|
-
<h2>{{ title }}</h2>
|
|
80
|
-
<slot />
|
|
81
|
-
</section>
|
|
92
|
+
<div :style="{ width: `${progress * 100}%` }" />
|
|
82
93
|
</template>
|
|
83
94
|
```
|
|
84
95
|
|
|
85
|
-
### Composition API
|
|
96
|
+
### Composition API (without `ScrollSectionProvider`)
|
|
86
97
|
|
|
87
98
|
```vue
|
|
88
|
-
<script setup>
|
|
89
|
-
import { useScrollSection } from '@jump-section/vue';
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// Watch for active section changes
|
|
98
|
-
watch(activeId, (newId) => {
|
|
99
|
-
console.log('Active section changed to:', newId);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
// Programmatic scroll
|
|
103
|
-
const handleClick = () => {
|
|
104
|
-
scrollTo('target-section');
|
|
105
|
-
};
|
|
99
|
+
<script setup lang="ts">
|
|
100
|
+
import { provideScrollManager, useScrollSection } from '@jump-section/vue';
|
|
101
|
+
|
|
102
|
+
// Call in the root component instead of using ScrollSectionProvider
|
|
103
|
+
provideScrollManager({ offset: -80, behavior: 'smooth', hash: true });
|
|
104
|
+
|
|
105
|
+
const { activeId, scrollTo } = useScrollSection();
|
|
106
106
|
</script>
|
|
107
107
|
```
|
|
108
108
|
|
|
109
109
|
## API
|
|
110
110
|
|
|
111
|
-
### `
|
|
111
|
+
### `ScrollSectionProvider`
|
|
112
|
+
|
|
113
|
+
Component that provides scroll management context to descendants.
|
|
114
|
+
|
|
115
|
+
**Props:**
|
|
112
116
|
|
|
113
|
-
|
|
117
|
+
| Prop | Type | Default | Description |
|
|
118
|
+
| ---------- | --------------------- | ---------- | ---------------------------------------------------------- |
|
|
119
|
+
| `offset` | `number` | `0` | Vertical offset in pixels (useful for fixed headers) |
|
|
120
|
+
| `behavior` | `ScrollBehavior` | `'smooth'` | Scroll behavior: `'smooth'` \| `'instant'` \| `'auto'` |
|
|
121
|
+
| `hash` | `boolean` | `false` | Sync active section with URL hash |
|
|
122
|
+
| `keyboard` | `boolean` | `false` | Enable `Alt+ArrowDown` / `Alt+ArrowUp` keyboard navigation |
|
|
123
|
+
| `root` | `HTMLElement \| null` | `null` | Custom scroll container (defaults to `window`) |
|
|
114
124
|
|
|
115
|
-
|
|
125
|
+
### `useScrollSection(sectionId?: string)`
|
|
116
126
|
|
|
117
|
-
|
|
118
|
-
- If `string`: Section ID to register
|
|
119
|
-
- If `ScrollOptions`: Configuration object
|
|
120
|
-
- `offset?: number` - Vertical offset in pixels
|
|
121
|
-
- `behavior?: ScrollBehavior` - Scroll behavior: `'smooth'` | `'instant'` | `'auto'`
|
|
127
|
+
Composable for registering a section and accessing scroll controls.
|
|
122
128
|
|
|
123
129
|
**Returns:**
|
|
124
130
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
131
|
+
| Property | Type | Description |
|
|
132
|
+
| --------------- | --------------------------------------- | ----------------------------------------------------------------------------- |
|
|
133
|
+
| `registerRef` | `(el: Element \| undefined) => void` | Ref callback to register the section element |
|
|
134
|
+
| `scrollTo` | `(id: string) => Promise<void>` | Scroll to a specific section |
|
|
135
|
+
| `scrollToNext` | `() => Promise<void>` | Scroll to the next section |
|
|
136
|
+
| `scrollToPrev` | `() => Promise<void>` | Scroll to the previous section |
|
|
137
|
+
| `scrollToFirst` | `() => Promise<void>` | Scroll to the first section |
|
|
138
|
+
| `scrollToLast` | `() => Promise<void>` | Scroll to the last section |
|
|
139
|
+
| `activeId` | `Readonly<Ref<string \| null>>` | Currently active section ID (reactive) |
|
|
140
|
+
| `isActive` | `ComputedRef<boolean>` | Whether this section is active (only meaningful when `sectionId` is provided) |
|
|
141
|
+
| `direction` | `Readonly<Ref<'up' \| 'down' \| null>>` | Current scroll direction |
|
|
130
142
|
|
|
131
|
-
|
|
143
|
+
### `useScrollProgress(sectionId: string): Readonly<Ref<number>>`
|
|
132
144
|
|
|
133
|
-
|
|
145
|
+
Returns a reactive scroll progress value (0–1) for a specific section.
|
|
134
146
|
|
|
135
|
-
|
|
147
|
+
### `provideScrollManager(options?: ScrollOptions): ScrollManager`
|
|
136
148
|
|
|
137
|
-
|
|
149
|
+
Alternative to `ScrollSectionProvider` for Composition API usage. Call in a parent component's `setup` to provide a `ScrollManager` instance to all descendants.
|
|
150
|
+
|
|
151
|
+
### `useScrollManager(): ScrollManager`
|
|
152
|
+
|
|
153
|
+
Returns the underlying `ScrollManager` instance for advanced use cases.
|
|
138
154
|
|
|
139
155
|
## License
|
|
140
156
|
|