morphing-scroll 1.5.19 → 1.5.21
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 +1039 -938
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,686 +35,757 @@ npm install morphing-scroll
|
|
|
35
35
|
|
|
36
36
|
- ### Props:
|
|
37
37
|
|
|
38
|
+
<div>
|
|
39
|
+
|
|
38
40
|
#### GENERAL SETTINGS:
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
<
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
<br />
|
|
67
|
-
<
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
42
|
+
<details>
|
|
43
|
+
<summary><strong><code>className</code></strong>: <em>Additional classes for the component.</em></summary><br />
|
|
44
|
+
<ul>
|
|
45
|
+
<strong>Type:</strong> string<br />
|
|
46
|
+
<br />
|
|
47
|
+
<strong>Description:</strong> <em><br />
|
|
48
|
+
This parameter allows you to apply custom CSS classes to the <code>MorphScroll</code> component, enabling further customization and styling to fit your design needs.</em><br />
|
|
49
|
+
<br />
|
|
50
|
+
<strong>Example:</strong>
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
<MorphScroll
|
|
54
|
+
className="your-class"
|
|
55
|
+
// another props
|
|
56
|
+
>
|
|
57
|
+
{children}
|
|
58
|
+
</MorphScroll>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
</ul>
|
|
62
|
+
|
|
63
|
+
</details>
|
|
64
|
+
|
|
65
|
+
<h2></h2>
|
|
66
|
+
|
|
67
|
+
<details>
|
|
68
|
+
<summary><strong><code>children</code></strong>: <em>Custom user content.</em></summary><br />
|
|
69
|
+
<ul>
|
|
70
|
+
<strong>Type:</strong> React.ReactNode<br />
|
|
71
|
+
<br />
|
|
72
|
+
<strong>Description:</strong> <em><br />
|
|
73
|
+
This is where you can pass your list elements.<br />
|
|
74
|
+
Make sure to provide unique keys for each list item, as per React's rules. The <code>MorphScroll</code> component ensures that the cells it generates will use the same keys as your list items, allowing it to render the correct cells for the current list.<br />
|
|
75
|
+
Additionally, <code>MorphScroll</code> handles a passed <code>null</code> value the same way as <code>undefined</code>, rendering nothing in both cases.</em><br />
|
|
76
|
+
<br />
|
|
77
|
+
<strong>Example:</strong>
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
<MorphScroll
|
|
81
|
+
// props
|
|
82
|
+
>
|
|
83
|
+
{children}
|
|
84
|
+
</MorphScroll>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
</ul>
|
|
88
|
+
|
|
89
|
+
</details>
|
|
90
|
+
|
|
91
|
+
<h2></h2>
|
|
84
92
|
|
|
85
93
|
#### SCROLL SETTINGS:
|
|
86
94
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
</ul>
|
|
111
|
-
</details>
|
|
112
|
-
|
|
113
|
-
<details>
|
|
114
|
-
<summary><strong><code>direction</code></strong> : <em>Scrolling direction.</em></summary><br />
|
|
115
|
-
<ul>
|
|
116
|
-
<strong>Type:</strong> "x" | "y"<br />
|
|
117
|
-
<br />
|
|
118
|
-
<strong>Default:</strong> "y"<br />
|
|
119
|
-
<br />
|
|
120
|
-
<strong>Description:</strong> <em><br />
|
|
121
|
-
This parameter changes the scroll or slider type direction based on the provided value.<br />
|
|
122
|
-
You can set it to horizontal or vertical to customize the component according to your needs.</em><br />
|
|
123
|
-
<br />
|
|
124
|
-
<strong>Example:</strong>
|
|
125
|
-
|
|
126
|
-
```tsx
|
|
127
|
-
<MorphScroll
|
|
128
|
-
direction="x"
|
|
129
|
-
// another props
|
|
130
|
-
>
|
|
131
|
-
{children}
|
|
132
|
-
</MorphScroll>
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
</ul>
|
|
136
|
-
</details>
|
|
137
|
-
|
|
138
|
-
<details>
|
|
139
|
-
<summary><strong><code>scrollTop</code></strong> : <em>Scroll position and animation duration.</em></summary><br />
|
|
140
|
-
<ul>
|
|
141
|
-
<strong>Type:</strong> {<br />
|
|
142
|
-
value: number | "end";<br />
|
|
143
|
-
duration?: number;<br />
|
|
144
|
-
updater?: boolean;<br />
|
|
145
|
-
}<br />
|
|
146
|
-
<br />
|
|
147
|
-
<strong>Default:</strong> { value: 0; duration: 200; updater: false }<br />
|
|
148
|
-
<br />
|
|
149
|
-
<strong>Description:</strong> <em><br />
|
|
150
|
-
This parameter allows you to set custom scroll values.<br />
|
|
151
|
-
<br />
|
|
152
|
-
The <code>value</code> property accepts numerical pixel values.<br />
|
|
153
|
-
The <code>"end"</code> option scrolls to the bottom of the list upon loading, which is useful for scenarios like chat message lists. When new elements are appended to the list, the scroll position will update automatically. However, to prevent unwanted scrolling when adding elements to the beginning of the list, this property will not trigger.<br />
|
|
154
|
-
<br />
|
|
155
|
-
The <code>duration</code> property determines the animation speed for scrolling in ms.</em><br />
|
|
156
|
-
<br />
|
|
157
|
-
The <code>updater</code> property is a helper for the <code>value</code> property. When setting the same scroll value repeatedly (e.g., clicking a button to scroll to the top), React does not register the update. To force an update, toggle updater within setState, e.g.,<br />
|
|
158
|
-
<code>setScroll((prev) => ({ ...prev, value: 0, updater: !prev.updater }))</code></em><br />
|
|
159
|
-
<br />
|
|
160
|
-
<strong>Example:</strong>
|
|
161
|
-
|
|
162
|
-
```tsx
|
|
163
|
-
<MorphScroll
|
|
164
|
-
scrollTop={{ value: 100; duration: 100 }}
|
|
165
|
-
// another props
|
|
166
|
-
>
|
|
167
|
-
{children}
|
|
168
|
-
</MorphScroll>
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
</ul>
|
|
172
|
-
</details>
|
|
173
|
-
|
|
174
|
-
<details>
|
|
175
|
-
<summary><strong><code>stopLoadOnScroll</code></strong> : <em>Stop loading when scrolling.</em></summary><br />
|
|
176
|
-
<ul>
|
|
177
|
-
<strong>Type:</strong> boolean<br />
|
|
178
|
-
<br />
|
|
179
|
-
<strong>Default:</strong> false<br />
|
|
180
|
-
<br />
|
|
181
|
-
<strong>Description:</strong> <em><br />
|
|
182
|
-
This parameter helps optimize list performance during scrolling. When set to <code>true</code>, new items will not load while the list is being scrolled and will only load after scrolling stops. This can be particularly useful for lists with a large number of items.</em><br />
|
|
183
|
-
<br />
|
|
184
|
-
<strong>Example:</strong>
|
|
185
|
-
|
|
186
|
-
```tsx
|
|
187
|
-
<MorphScroll
|
|
188
|
-
stopLoadOnScroll
|
|
189
|
-
// another props
|
|
190
|
-
>
|
|
191
|
-
{children}
|
|
192
|
-
</MorphScroll>
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
</ul>
|
|
196
|
-
</details>
|
|
197
|
-
|
|
198
|
-
<details>
|
|
199
|
-
<summary><strong><code>onScrollValue</code></strong> : <em>Callback for scroll value.</em></summary><br />
|
|
200
|
-
<ul>
|
|
201
|
-
<strong>Type:</strong> (scroll: number) => void<br />
|
|
202
|
-
<br />
|
|
203
|
-
<strong>Description:</strong> <em><br />
|
|
204
|
-
This parameter accepts a callback function that is triggered on every scroll event. The callback receives the current scroll position as a number. The return value of the callback can be used to determine custom behavior based on the scroll value.</em><br />
|
|
205
|
-
<br />
|
|
206
|
-
<strong>Example:</strong>
|
|
207
|
-
|
|
208
|
-
```tsx
|
|
209
|
-
<MorphScroll
|
|
210
|
-
onScrollValue={
|
|
211
|
-
(scroll) => {
|
|
212
|
-
console.log("Scroll position:", scroll);
|
|
213
|
-
return scroll > 100;
|
|
214
|
-
},
|
|
215
|
-
}
|
|
216
|
-
// another props
|
|
217
|
-
>
|
|
218
|
-
{children}
|
|
219
|
-
</MorphScroll>
|
|
220
|
-
```
|
|
95
|
+
<details>
|
|
96
|
+
<summary><strong><code>type</code></strong>: <em>Type of progress element.</em></summary><br />
|
|
97
|
+
<ul>
|
|
98
|
+
<strong>Type:</strong> "scroll" | "slider"<br />
|
|
99
|
+
<br />
|
|
100
|
+
<strong>Default:</strong> "scroll"<br />
|
|
101
|
+
<br />
|
|
102
|
+
<strong>Description:</strong> <em><br />
|
|
103
|
+
This parameter defines how the provided <code>progressElement</code> behaves within <code>progressTrigger</code> and how you interact with it.<br />
|
|
104
|
+
With the default <code>type="scroll"</code>, it functions as a typical scrollbar. However, with <code>type="slider"</code>, it displays distinct elements indicating the number of full scroll steps within the list.<br />
|
|
105
|
+
For More details, refer to <code>progressTrigger/progressElement</code>.</em><br />
|
|
106
|
+
<br />
|
|
107
|
+
<strong>Example:</strong>
|
|
108
|
+
|
|
109
|
+
```tsx
|
|
110
|
+
<MorphScroll
|
|
111
|
+
type="slider"
|
|
112
|
+
// another props
|
|
113
|
+
>
|
|
114
|
+
{children}
|
|
115
|
+
</MorphScroll>
|
|
116
|
+
```
|
|
221
117
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
<
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
<br />
|
|
230
|
-
<
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
118
|
+
</ul>
|
|
119
|
+
|
|
120
|
+
</details>
|
|
121
|
+
|
|
122
|
+
<h2></h2>
|
|
123
|
+
|
|
124
|
+
<details>
|
|
125
|
+
<summary><strong><code>direction</code></strong>: <em>Scrolling direction.</em></summary><br />
|
|
126
|
+
<ul>
|
|
127
|
+
<strong>Type:</strong> "x" | "y"<br />
|
|
128
|
+
<br />
|
|
129
|
+
<strong>Default:</strong> "y"<br />
|
|
130
|
+
<br />
|
|
131
|
+
<strong>Description:</strong> <em><br />
|
|
132
|
+
This parameter changes the scroll or slider type direction based on the provided value.<br />
|
|
133
|
+
You can set it to horizontal or vertical to customize the component according to your needs.</em><br />
|
|
134
|
+
<br />
|
|
135
|
+
<strong>Example:</strong>
|
|
136
|
+
|
|
137
|
+
```tsx
|
|
138
|
+
<MorphScroll
|
|
139
|
+
direction="x"
|
|
140
|
+
// another props
|
|
141
|
+
>
|
|
142
|
+
{children}
|
|
143
|
+
</MorphScroll>
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
</ul>
|
|
147
|
+
|
|
148
|
+
</details>
|
|
149
|
+
|
|
150
|
+
<h2></h2>
|
|
151
|
+
|
|
152
|
+
<details>
|
|
153
|
+
<summary><strong><code>scrollTop</code></strong>: <em>Scroll position and animation duration.</em></summary><br />
|
|
154
|
+
<ul>
|
|
155
|
+
<strong>Type:</strong> {<br />
|
|
156
|
+
value: number | "end";<br />
|
|
157
|
+
duration?: number;<br />
|
|
158
|
+
updater?: boolean;<br />
|
|
159
|
+
}<br />
|
|
160
|
+
<br />
|
|
161
|
+
<strong>Default:</strong> { value: 0; duration: 200; updater: false }<br />
|
|
162
|
+
<br />
|
|
163
|
+
<strong>Description:</strong> <em><br />
|
|
164
|
+
This parameter allows you to set custom scroll values.<br />
|
|
165
|
+
<br />
|
|
166
|
+
The <code>value</code> property accepts numerical pixel values.<br />
|
|
167
|
+
The <code>"end"</code> option scrolls to the bottom of the list upon loading, which is useful for scenarios like chat message lists. When new elements are appended to the list, the scroll position will update automatically. However, to prevent unwanted scrolling when adding elements to the beginning of the list, this property will not trigger.<br />
|
|
168
|
+
<br />
|
|
169
|
+
The <code>duration</code> property determines the animation speed for scrolling in ms.</em><br />
|
|
170
|
+
<br />
|
|
171
|
+
The <code>updater</code> property is a helper for the <code>value</code> property. When setting the same scroll value repeatedly (e.g., clicking a button to scroll to the top), React does not register the update. To force an update, toggle updater within setState, e.g.,<br />
|
|
172
|
+
<code>setScroll((prev) => ({ ...prev, value: 0, updater: !prev.updater }))</code></em><br />
|
|
173
|
+
<br />
|
|
174
|
+
<strong>Example:</strong>
|
|
175
|
+
|
|
176
|
+
```tsx
|
|
177
|
+
<MorphScroll
|
|
178
|
+
scrollTop={{ value: 100; duration: 100 }}
|
|
179
|
+
// another props
|
|
180
|
+
>
|
|
181
|
+
{children}
|
|
182
|
+
</MorphScroll>
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
</ul>
|
|
186
|
+
|
|
187
|
+
</details>
|
|
188
|
+
|
|
189
|
+
<h2></h2>
|
|
190
|
+
|
|
191
|
+
<details>
|
|
192
|
+
<summary><strong><code>stopLoadOnScroll</code></strong>: <em>Stop loading when scrolling.</em></summary><br />
|
|
193
|
+
<ul>
|
|
194
|
+
<strong>Type:</strong> boolean<br />
|
|
195
|
+
<br />
|
|
196
|
+
<strong>Default:</strong> false<br />
|
|
197
|
+
<br />
|
|
198
|
+
<strong>Description:</strong> <em><br />
|
|
199
|
+
This parameter helps optimize list performance during scrolling. When set to <code>true</code>, new items will not load while the list is being scrolled and will only load after scrolling stops. This can be particularly useful for lists with a large number of items.</em><br />
|
|
200
|
+
<br />
|
|
201
|
+
<strong>Example:</strong>
|
|
202
|
+
|
|
203
|
+
```tsx
|
|
204
|
+
<MorphScroll
|
|
205
|
+
stopLoadOnScroll
|
|
206
|
+
// another props
|
|
207
|
+
>
|
|
208
|
+
{children}
|
|
209
|
+
</MorphScroll>
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
</ul>
|
|
213
|
+
|
|
214
|
+
</details>
|
|
215
|
+
|
|
216
|
+
<h2></h2>
|
|
217
|
+
|
|
218
|
+
<details>
|
|
219
|
+
<summary><strong><code>onScrollValue</code></strong>: <em>Callback for scroll value.</em></summary><br />
|
|
220
|
+
<ul>
|
|
221
|
+
<strong>Type:</strong> (scroll: number) => void<br />
|
|
222
|
+
<br />
|
|
223
|
+
<strong>Description:</strong> <em><br />
|
|
224
|
+
This parameter accepts a callback function that is triggered on every scroll event. The callback receives the current scroll position as a number. The return value of the callback can be used to determine custom behavior based on the scroll value.</em><br />
|
|
225
|
+
<br />
|
|
226
|
+
<strong>Example:</strong>
|
|
227
|
+
|
|
228
|
+
```tsx
|
|
229
|
+
<MorphScroll
|
|
230
|
+
onScrollValue={
|
|
231
|
+
(scroll) => {
|
|
232
|
+
console.log("Scroll position:", scroll);
|
|
233
|
+
return scroll > 100;
|
|
234
|
+
},
|
|
235
|
+
}
|
|
236
|
+
// another props
|
|
237
|
+
>
|
|
238
|
+
{children}
|
|
239
|
+
</MorphScroll>
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
</ul>
|
|
243
|
+
|
|
244
|
+
</details>
|
|
245
|
+
|
|
246
|
+
<h2></h2>
|
|
247
|
+
|
|
248
|
+
<details>
|
|
249
|
+
<summary><strong><code>isScrolling</code></strong>: <em>Callback function for scroll status.</em></summary><br />
|
|
250
|
+
<ul>
|
|
251
|
+
<strong>Type:</strong> (motion: boolean) => void<br />
|
|
252
|
+
<br />
|
|
253
|
+
<strong>Description:</strong> <em><br />
|
|
254
|
+
This parameter accepts a callback function that is triggered whenever the scroll status changes. The callback receives a boolean value, where <code>true</code> indicates that scrolling is in progress, and <code>false</code> indicates that scrolling has stopped. This can be useful for triggering additional actions, such as pausing animations or loading indicators based on the scroll state.</em><br />
|
|
255
|
+
<br />
|
|
256
|
+
<strong>Example:</strong>
|
|
257
|
+
|
|
258
|
+
```tsx
|
|
259
|
+
<MorphScroll
|
|
260
|
+
isScrolling={(motion) => {
|
|
261
|
+
console.log(motion ? "Scrolling..." : "Scroll stopped.");
|
|
262
|
+
}}
|
|
263
|
+
// another props
|
|
264
|
+
>
|
|
265
|
+
{children}
|
|
266
|
+
</MorphScroll>
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
</ul>
|
|
270
|
+
|
|
271
|
+
</details>
|
|
245
272
|
|
|
246
|
-
|
|
247
|
-
</details>
|
|
273
|
+
<h2></h2>
|
|
248
274
|
|
|
249
275
|
#### VISUAL SETTINGS:
|
|
250
276
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
<ul>
|
|
254
|
-
<strong>Type:</strong> number[]<br />
|
|
255
|
-
<br />
|
|
256
|
-
<strong>Description:</strong> <em><br />
|
|
257
|
-
This parameter sets the width and height of the <code>MorphScroll</code> component as an array of two numbers. These values help define the visual container for the scrollable area.<br />
|
|
258
|
-
<br />
|
|
259
|
-
If this parameter is not specified, <code>MorphScroll</code> will use the <code>ResizeTracker</code> component to measure the width and height of the area where <code>MorphScroll</code> is added. The dimensions will automatically adjust when the container changes.<br />
|
|
260
|
-
<br />
|
|
261
|
-
⚠ Note:<br />
|
|
277
|
+
<details>
|
|
278
|
+
<summary><strong><code>size</code></strong>: <em>MorphScroll width and height.</em></summary><br />
|
|
262
279
|
<ul>
|
|
263
|
-
<
|
|
264
|
-
<
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
<br />
|
|
296
|
-
<strong>Example:</strong>
|
|
297
|
-
|
|
298
|
-
```tsx
|
|
299
|
-
<MorphScroll
|
|
300
|
-
objectsSize={[40, 40]}
|
|
301
|
-
// objectsSize={["none", "none"]}
|
|
302
|
-
// objectsSize={["firstChild", "firstChild"]}
|
|
303
|
-
// another props
|
|
304
|
-
>
|
|
305
|
-
{children}
|
|
306
|
-
</MorphScroll>
|
|
307
|
-
```
|
|
308
|
-
|
|
309
|
-
</ul>
|
|
310
|
-
</details>
|
|
311
|
-
|
|
312
|
-
<details>
|
|
313
|
-
<summary><strong><code>gap</code></strong> : <em>Gap between cells.</em></summary><br />
|
|
314
|
-
<ul>
|
|
315
|
-
<strong>Type:</strong> number[] | number<br />
|
|
316
|
-
<br />
|
|
317
|
-
<strong>Description:</strong> <em><br />
|
|
318
|
-
This parameter allows you to set spacing between list items both horizontally and vertically. You can provide a single value, which will apply to both directions, or an array of two numbers to define separate spacing values.<br />
|
|
319
|
-
<br />
|
|
320
|
-
⚠ Note:<br />
|
|
321
|
-
The values are specified following the <code>horizontal/vertical</code> rule in pixels, regardless of the <code>direction</code>.</em><br />
|
|
322
|
-
<br />
|
|
323
|
-
<strong>Example:</strong>
|
|
324
|
-
|
|
325
|
-
```tsx
|
|
326
|
-
<MorphScroll
|
|
327
|
-
gap={10}
|
|
328
|
-
// gap={[10, 10]}
|
|
329
|
-
// another props
|
|
330
|
-
>
|
|
331
|
-
{children}
|
|
332
|
-
</MorphScroll>
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
</ul>
|
|
336
|
-
</details>
|
|
337
|
-
|
|
338
|
-
<details>
|
|
339
|
-
<summary><strong><code>padding</code></strong> : <em>Padding for the <code>objectsWrapper</code>.</em></summary><br />
|
|
340
|
-
<ul>
|
|
341
|
-
<strong>Type:</strong> number[] | number<br />
|
|
342
|
-
<br />
|
|
343
|
-
<strong>Description:</strong> <em><br />
|
|
344
|
-
This parameter defines the spacing between the list items and their wrapper, effectively increasing the width or height of the scrollable area. You can provide a single number, which will apply to all sides, or an array of two or four numbers to specify spacing for specific directions.<br />
|
|
345
|
-
<br />
|
|
346
|
-
⚠ Note:<br />
|
|
280
|
+
<strong>Type:</strong> number[]<br />
|
|
281
|
+
<br />
|
|
282
|
+
<strong>Description:</strong> <em><br />
|
|
283
|
+
This parameter sets the width and height of the <code>MorphScroll</code> component as an array of two numbers. These values help define the visual container for the scrollable area.<br />
|
|
284
|
+
<br />
|
|
285
|
+
If this parameter is not specified, <code>MorphScroll</code> will use the <code>ResizeTracker</code> component to measure the width and height of the area where <code>MorphScroll</code> is added. The dimensions will automatically adjust when the container changes.<br />
|
|
286
|
+
<br />
|
|
287
|
+
⚠ Note:<br />
|
|
288
|
+
<ul>
|
|
289
|
+
<li>The values are specified following the <code>width/height</code> rule in pixels, regardless of the <code>direction</code>.</li>
|
|
290
|
+
<li>See the <code>ResizeTracker</code> section for more details.</li>
|
|
291
|
+
</ul></em><br />
|
|
292
|
+
<br />
|
|
293
|
+
<strong>Example:</strong>
|
|
294
|
+
|
|
295
|
+
```tsx
|
|
296
|
+
<MorphScroll
|
|
297
|
+
size={[100, 400]}
|
|
298
|
+
// another props
|
|
299
|
+
>
|
|
300
|
+
{children}
|
|
301
|
+
</MorphScroll>
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
</ul>
|
|
305
|
+
|
|
306
|
+
</details>
|
|
307
|
+
|
|
308
|
+
<h2></h2>
|
|
309
|
+
|
|
310
|
+
<details>
|
|
311
|
+
<summary><strong><code>objectsSize</code> (required)</strong>: <em>Required: Size of cells for each object.</em></summary><br />
|
|
347
312
|
<ul>
|
|
348
|
-
<
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
<
|
|
356
|
-
<
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
<
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
]<br />
|
|
382
|
-
<strong>Description:</strong> <em><br />
|
|
383
|
-
This parameter aligns the `objectsWrapper`, which contains all the provided elements, relative to the scroll or the `size`.<br />
|
|
384
|
-
<br />
|
|
385
|
-
⚠ Note:<br />
|
|
313
|
+
<strong>Type:</strong> (number | "none" | "firstChild")[]<br />
|
|
314
|
+
<br />
|
|
315
|
+
<strong>Description:</strong> <em><br />
|
|
316
|
+
This parameter is the only required one. It defines the size of cells for each of your objects. <code>ObjectsSize</code> use an array of values.<br />
|
|
317
|
+
<br />
|
|
318
|
+
If you pass <code>"none"</code>, cells will still be created, but <code>MorphScroll</code> will not calculate their sizes-they will simply wrap your objects. In this case, for example, you won’t be able to use the <code>infiniteScroll</code> feature, as it requires specific cell sizes for absolute positioning.. However, this is not a drawback if you are building something like a chat or a news feed, where the content can have varying heights, and it’s better to load new content as the user approaches the end of the existing list.<br />
|
|
319
|
+
<br />
|
|
320
|
+
If you specify the value <code>"firstChild"</code>, a <code>ResizeTracker</code> wrapper will be created for the first child of your list. This wrapper will calculate the size of the first child, and these dimensions will be applied to all cells in the list.<br />
|
|
321
|
+
<br />
|
|
322
|
+
⚠ Note:<br />
|
|
323
|
+
The numbers are specified following the <code>width/height</code> rule, regardless of the <code>direction</code>.</em><br />
|
|
324
|
+
<br />
|
|
325
|
+
<strong>Example:</strong>
|
|
326
|
+
|
|
327
|
+
```tsx
|
|
328
|
+
<MorphScroll
|
|
329
|
+
objectsSize={[40, 40]}
|
|
330
|
+
// objectsSize={["none", "none"]}
|
|
331
|
+
// objectsSize={["firstChild", "firstChild"]}
|
|
332
|
+
// another props
|
|
333
|
+
>
|
|
334
|
+
{children}
|
|
335
|
+
</MorphScroll>
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
</ul>
|
|
339
|
+
|
|
340
|
+
</details>
|
|
341
|
+
|
|
342
|
+
<h2></h2>
|
|
343
|
+
|
|
344
|
+
<details>
|
|
345
|
+
<summary><strong><code>gap</code></strong>: <em>Gap between cells.</em></summary><br />
|
|
386
346
|
<ul>
|
|
387
|
-
<
|
|
388
|
-
|
|
389
|
-
<
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
<MorphScroll
|
|
416
|
-
elementsAlign="center"
|
|
417
|
-
// another props
|
|
418
|
-
>
|
|
419
|
-
{children}
|
|
420
|
-
</MorphScroll>
|
|
421
|
-
```
|
|
422
|
-
|
|
423
|
-
</ul>
|
|
424
|
-
</details>
|
|
425
|
-
|
|
426
|
-
<details>
|
|
427
|
-
<summary><strong><code>edgeGradient</code></strong> : <em>Gradient when scrolling overflows.</em></summary><br />
|
|
428
|
-
<ul>
|
|
429
|
-
<strong>Type:</strong> boolean | { color?: string; size?: number }<br />
|
|
430
|
-
<br />
|
|
431
|
-
<strong>Default:</strong> When using true or color, the default size will be 40<br />
|
|
432
|
-
<br />
|
|
433
|
-
<strong>Description:</strong> <em><br />
|
|
434
|
-
This parameter creates two edge elements responsible for darkening the edges of the scroll when it overflows.<br />
|
|
435
|
-
<br />
|
|
436
|
-
The color property accepts any valid color format. If specified, the library will generate a gradient transitioning from the custom color to transparent. If omitted, the edge elements will have no color, allowing for custom styling via CSS classes.<br />
|
|
437
|
-
<br />
|
|
438
|
-
⚠ Note:<br />
|
|
439
|
-
The size property, measured in pixels, adjusts the dimensions of the edge elements.</em><br />
|
|
440
|
-
<br />
|
|
441
|
-
<strong>Example:</strong>
|
|
442
|
-
|
|
443
|
-
```tsx
|
|
444
|
-
<MorphScroll
|
|
445
|
-
edgeGradient={{ color: "rgba(0, 0, 0, 0.5)" }}
|
|
446
|
-
// edgeGradient={{ color: "rgba(0, 0, 0, 0.5)", size: 20 }}
|
|
447
|
-
// edgeGradient
|
|
448
|
-
// another props
|
|
449
|
-
>
|
|
450
|
-
{children}
|
|
451
|
-
</MorphScroll>
|
|
452
|
-
```
|
|
453
|
-
|
|
454
|
-
</ul>
|
|
455
|
-
</details>
|
|
456
|
-
|
|
457
|
-
<details>
|
|
458
|
-
<summary><strong><code>progressReverse</code></strong> : <em>Reverse the progress bar position.</em></summary><br />
|
|
459
|
-
<ul>
|
|
460
|
-
<strong>Type:</strong> boolean<br />
|
|
461
|
-
<br />
|
|
462
|
-
<strong>Default:</strong> false<br />
|
|
463
|
-
<br />
|
|
464
|
-
<strong>Description:</strong> <em><br />
|
|
465
|
-
This parameter changes the position of the progress bar based on the direction property.<br />
|
|
347
|
+
<strong>Type:</strong> number[] | number<br />
|
|
348
|
+
<br />
|
|
349
|
+
<strong>Description:</strong> <em><br />
|
|
350
|
+
This parameter allows you to set spacing between list items both horizontally and vertically. You can provide a single value, which will apply to both directions, or an array of two numbers to define separate spacing values.<br />
|
|
351
|
+
<br />
|
|
352
|
+
⚠ Note:<br />
|
|
353
|
+
The values are specified following the <code>horizontal/vertical</code> rule in pixels, regardless of the <code>direction</code>.</em><br />
|
|
354
|
+
<br />
|
|
355
|
+
<strong>Example:</strong>
|
|
356
|
+
|
|
357
|
+
```tsx
|
|
358
|
+
<MorphScroll
|
|
359
|
+
gap={10}
|
|
360
|
+
// gap={[10, 10]}
|
|
361
|
+
// another props
|
|
362
|
+
>
|
|
363
|
+
{children}
|
|
364
|
+
</MorphScroll>
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
</ul>
|
|
368
|
+
|
|
369
|
+
</details>
|
|
370
|
+
|
|
371
|
+
<h2></h2>
|
|
372
|
+
|
|
373
|
+
<details>
|
|
374
|
+
<summary><strong><code>padding</code></strong>: <em>Padding for the <code>objectsWrapper</code>.</em></summary><br />
|
|
466
375
|
<ul>
|
|
467
|
-
<
|
|
468
|
-
<
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
progressVisibility="hover"
|
|
500
|
-
// another props
|
|
501
|
-
>
|
|
502
|
-
{children}
|
|
503
|
-
</MorphScroll>
|
|
504
|
-
```
|
|
505
|
-
|
|
506
|
-
</ul>
|
|
507
|
-
</details>
|
|
508
|
-
|
|
509
|
-
<details>
|
|
510
|
-
<summary><strong><code>objectsWrapFullMinSize</code></strong> : <em>Sets the <code>min-height</code> CSS property of the <code>objectsWrapper</code> to match the height of the MorphScroll.</em></summary><br />
|
|
511
|
-
<ul>
|
|
512
|
-
<strong>Type:</strong> boolean<br /><br />
|
|
513
|
-
<strong>Default:</strong> false<br /><br />
|
|
514
|
-
<strong>Description:</strong> <em><br />
|
|
515
|
-
In process of development</em><br />
|
|
516
|
-
<br />
|
|
517
|
-
<strong>Example:</strong>
|
|
518
|
-
|
|
519
|
-
```tsx
|
|
520
|
-
<MorphScroll
|
|
521
|
-
objectsWrapFullMinSize
|
|
522
|
-
// another props
|
|
523
|
-
>
|
|
524
|
-
{children}
|
|
525
|
-
</MorphScroll>
|
|
526
|
-
```
|
|
376
|
+
<strong>Type:</strong> number[] | number<br />
|
|
377
|
+
<br />
|
|
378
|
+
<strong>Description:</strong> <em><br />
|
|
379
|
+
This parameter defines the spacing between the list items and their wrapper, effectively increasing the width or height of the scrollable area. You can provide a single number, which will apply to all sides, or an array of two or four numbers to specify spacing for specific directions.<br />
|
|
380
|
+
<br />
|
|
381
|
+
⚠ Note:<br />
|
|
382
|
+
<ul>
|
|
383
|
+
<li>
|
|
384
|
+
This parameter accepts either a single number or an array of numbers
|
|
385
|
+
<ul>
|
|
386
|
+
<li>If a two-number array is provided, the values follow the <code>horizontal/vertical</code> rule.</li>
|
|
387
|
+
<li>If a four-number array is provided, the values follow the <code>top/right/bottom/left</code> rule.</li>
|
|
388
|
+
</ul>
|
|
389
|
+
</li>
|
|
390
|
+
<li>All values are in pixels and apply regardless of the <code>direction</code>.</li>
|
|
391
|
+
<li>This is not a CSS property, even though its name might suggest otherwise. It specifically refers to modifying the width and height of the scrollable wrapper, affecting the dimensions of the scrollable area.</li>
|
|
392
|
+
</ul></em><br />
|
|
393
|
+
<br />
|
|
394
|
+
<strong>Example:</strong>
|
|
395
|
+
|
|
396
|
+
```tsx
|
|
397
|
+
<MorphScroll
|
|
398
|
+
padding={10}
|
|
399
|
+
// padding={[10, 10]}
|
|
400
|
+
// padding={[10, 10, 10, 10]}
|
|
401
|
+
// another props
|
|
402
|
+
>
|
|
403
|
+
{children}
|
|
404
|
+
</MorphScroll>
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
</ul>
|
|
527
408
|
|
|
528
|
-
</
|
|
529
|
-
|
|
409
|
+
</details>
|
|
410
|
+
|
|
411
|
+
<h2></h2>
|
|
412
|
+
|
|
413
|
+
<details>
|
|
414
|
+
<summary><strong><code>contentAlign</code></strong>: <em>Aligns the content when it is smaller than the MorphScroll <code>size</code>.</em></summary><br />
|
|
415
|
+
<ul>
|
|
416
|
+
<strong>Type:</strong> [<br />
|
|
417
|
+
"start" | "center" | "end",<br />
|
|
418
|
+
"start" | "center" | "end"<br />
|
|
419
|
+
]<br />
|
|
420
|
+
<strong>Description:</strong> <em><br />
|
|
421
|
+
This parameter aligns the `objectsWrapper`, which contains all the provided elements, relative to the scroll or the `size`.<br />
|
|
422
|
+
<br />
|
|
423
|
+
⚠ Note:<br />
|
|
424
|
+
<ul>
|
|
425
|
+
<li>Only takes effect when `objectsWrapper` is smaller than the scroll container.
|
|
426
|
+
</li>
|
|
427
|
+
<li>The values are specified following the horizontal/vertical rule, regardless of the direction.
|
|
428
|
+
</li>
|
|
429
|
+
</ul></em><br />
|
|
430
|
+
<br />
|
|
431
|
+
<strong>Example:</strong>
|
|
432
|
+
|
|
433
|
+
```tsx
|
|
434
|
+
<MorphScroll
|
|
435
|
+
contentAlign={["center", "center"]}
|
|
436
|
+
// another props
|
|
437
|
+
>
|
|
438
|
+
{children}
|
|
439
|
+
</MorphScroll>
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
</ul>
|
|
443
|
+
|
|
444
|
+
</details>
|
|
445
|
+
|
|
446
|
+
<h2></h2>
|
|
447
|
+
|
|
448
|
+
<details>
|
|
449
|
+
<summary><strong><code>elementsAlign</code></strong>: <em>Aligns the objects within the <code>objectsWrapper</code>.</em></summary><br />
|
|
450
|
+
<ul>
|
|
451
|
+
<strong>Type:</strong> "start" | "center" | "end"<br />
|
|
452
|
+
<br />
|
|
453
|
+
<strong>Example:</strong>
|
|
454
|
+
|
|
455
|
+
```tsx
|
|
456
|
+
<MorphScroll
|
|
457
|
+
elementsAlign="center"
|
|
458
|
+
// another props
|
|
459
|
+
>
|
|
460
|
+
{children}
|
|
461
|
+
</MorphScroll>
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
</ul>
|
|
465
|
+
|
|
466
|
+
</details>
|
|
467
|
+
|
|
468
|
+
<h2></h2>
|
|
469
|
+
|
|
470
|
+
<details>
|
|
471
|
+
<summary><strong><code>edgeGradient</code></strong>: <em>Gradient when scrolling overflows.</em></summary><br />
|
|
472
|
+
<ul>
|
|
473
|
+
<strong>Type:</strong> boolean | { color?: string; size?: number }<br />
|
|
474
|
+
<br />
|
|
475
|
+
<strong>Default:</strong> When using true or color, the default size will be 40<br />
|
|
476
|
+
<br />
|
|
477
|
+
<strong>Description:</strong> <em><br />
|
|
478
|
+
This parameter creates two edge elements responsible for darkening the edges of the scroll when it overflows.<br />
|
|
479
|
+
<br />
|
|
480
|
+
The color property accepts any valid color format. If specified, the library will generate a gradient transitioning from the custom color to transparent. If omitted, the edge elements will have no color, allowing for custom styling via CSS classes.<br />
|
|
481
|
+
<br />
|
|
482
|
+
⚠ Note:<br />
|
|
483
|
+
The size property, measured in pixels, adjusts the dimensions of the edge elements.</em><br />
|
|
484
|
+
<br />
|
|
485
|
+
<strong>Example:</strong>
|
|
486
|
+
|
|
487
|
+
```tsx
|
|
488
|
+
<MorphScroll
|
|
489
|
+
edgeGradient={{ color: "rgba(0, 0, 0, 0.5)" }}
|
|
490
|
+
// edgeGradient={{ color: "rgba(0, 0, 0, 0.5)", size: 20 }}
|
|
491
|
+
// edgeGradient
|
|
492
|
+
// another props
|
|
493
|
+
>
|
|
494
|
+
{children}
|
|
495
|
+
</MorphScroll>
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
</ul>
|
|
499
|
+
|
|
500
|
+
</details>
|
|
501
|
+
|
|
502
|
+
<h2></h2>
|
|
503
|
+
|
|
504
|
+
<details>
|
|
505
|
+
<summary><strong><code>progressReverse</code></strong>: <em>Reverse the progress bar position.</em></summary><br />
|
|
506
|
+
<ul>
|
|
507
|
+
<strong>Type:</strong> boolean<br />
|
|
508
|
+
<br />
|
|
509
|
+
<strong>Default:</strong> false<br />
|
|
510
|
+
<br />
|
|
511
|
+
<strong>Description:</strong> <em><br />
|
|
512
|
+
This parameter changes the position of the progress bar based on the direction property.<br />
|
|
513
|
+
<ul>
|
|
514
|
+
<li>If <code>direction="x"</code>, the progress bar is on the left by default and moves to the right when <code>progressReverse</code> is enabled.</li>
|
|
515
|
+
<li>If <code>direction="y"</code>, the progress bar is at the top by default and moves to the bottom when <code>progressReverse</code> is enabled.</li>
|
|
516
|
+
</ul></em><br />
|
|
517
|
+
<br />
|
|
518
|
+
<strong>Example:</strong>
|
|
519
|
+
|
|
520
|
+
```tsx
|
|
521
|
+
<MorphScroll
|
|
522
|
+
progressReverse
|
|
523
|
+
// another props
|
|
524
|
+
>
|
|
525
|
+
{children}
|
|
526
|
+
</MorphScroll>
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
</ul>
|
|
530
|
+
|
|
531
|
+
</details>
|
|
532
|
+
|
|
533
|
+
<h2></h2>
|
|
534
|
+
|
|
535
|
+
<details>
|
|
536
|
+
<summary><strong><code>progressVisibility</code></strong>: <em>Visibility of the progress bar.</em></summary><br />
|
|
537
|
+
<ul>
|
|
538
|
+
<strong>Type:</strong> "visible" | "hover" | "hidden"<br />
|
|
539
|
+
<br />
|
|
540
|
+
<strong>Default:</strong> "visible"<br />
|
|
541
|
+
<br />
|
|
542
|
+
<strong>Description:</strong> <em><br />
|
|
543
|
+
This parameter controls the visibility of the progress bar regardless of the <code>type</code> value.</em><br />
|
|
544
|
+
<br />
|
|
545
|
+
<strong>Example:</strong>
|
|
546
|
+
|
|
547
|
+
```tsx
|
|
548
|
+
<MorphScroll
|
|
549
|
+
progressVisibility="hover"
|
|
550
|
+
// another props
|
|
551
|
+
>
|
|
552
|
+
{children}
|
|
553
|
+
</MorphScroll>
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
</ul>
|
|
557
|
+
|
|
558
|
+
</details>
|
|
559
|
+
|
|
560
|
+
<h2></h2>
|
|
561
|
+
|
|
562
|
+
<details>
|
|
563
|
+
<summary><strong><code>objectsWrapFullMinSize</code></strong>: <em>Sets the <code>min-height</code> CSS property of the <code>objectsWrapper</code> to match the height of the MorphScroll.</em></summary><br />
|
|
564
|
+
<ul>
|
|
565
|
+
<strong>Type:</strong> boolean<br /><br />
|
|
566
|
+
<strong>Default:</strong> false<br /><br />
|
|
567
|
+
<strong>Description:</strong> <em><br />
|
|
568
|
+
In process of development</em><br />
|
|
569
|
+
<br />
|
|
570
|
+
<strong>Example:</strong>
|
|
571
|
+
|
|
572
|
+
```tsx
|
|
573
|
+
<MorphScroll
|
|
574
|
+
objectsWrapFullMinSize
|
|
575
|
+
// another props
|
|
576
|
+
>
|
|
577
|
+
{children}
|
|
578
|
+
</MorphScroll>
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
</ul>
|
|
582
|
+
|
|
583
|
+
</details>
|
|
584
|
+
|
|
585
|
+
<h2></h2>
|
|
530
586
|
|
|
531
587
|
#### PROGRESS AND RENDERING:
|
|
532
588
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
<ul>
|
|
536
|
-
<strong>Type:</strong> {<br />
|
|
537
|
-
wheel?: boolean;<br />
|
|
538
|
-
content?: boolean;<br />
|
|
539
|
-
progressElement?: boolean | React.ReactNode;<br />
|
|
540
|
-
arrows?: boolean | { size?: number; element?: React.ReactNode };<br />
|
|
541
|
-
}<br />
|
|
542
|
-
<br />
|
|
543
|
-
<strong>Default:</strong> { wheel: true }<br />
|
|
544
|
-
<br />
|
|
545
|
-
<strong>Description:</strong> <em><br />
|
|
546
|
-
This is one of the most important parameters, allowing you to define how users interact with the progress bar and customize its appearance.<br />
|
|
547
|
-
<br />
|
|
589
|
+
<details>
|
|
590
|
+
<summary><strong><code>progressTrigger</code></strong>: <em>Triggers for the progress bar.</em></summary><br />
|
|
548
591
|
<ul>
|
|
549
|
-
<
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
592
|
+
<strong>Type:</strong> {<br />
|
|
593
|
+
wheel?: boolean;<br />
|
|
594
|
+
content?: boolean;<br />
|
|
595
|
+
progressElement?: boolean | React.ReactNode;<br />
|
|
596
|
+
arrows?: boolean | { size?: number; element?: React.ReactNode };<br />
|
|
597
|
+
}<br />
|
|
598
|
+
<br />
|
|
599
|
+
<strong>Default:</strong> { wheel: true }<br />
|
|
600
|
+
<br />
|
|
601
|
+
<strong>Description:</strong> <em><br />
|
|
602
|
+
This is one of the most important parameters, allowing you to define how users interact with the progress bar and customize its appearance.<br />
|
|
603
|
+
<br />
|
|
604
|
+
<ul>
|
|
605
|
+
<li>The <code>wheel</code> property determines whether the progress bar responds to mouse wheel scrolling.</li>
|
|
606
|
+
<li>The <code>content</code> property enables interaction by clicking and dragging anywhere within the scrollable content to move it.</li>
|
|
607
|
+
<li>The <code>progressElement</code> property defines whether the progress bar is controlled by a custom element. If your custom scroll element is not ready yet, you can simply pass <code>true</code>, which will display the browser's default scrollbar when <code>type="scroll"</code> is used. Alternatively, if <code>type="slider"</code> is set, a <code>sliderBar</code> element will be created, containing multiple <code>sliderElem</code> elements representing progress. Depending on the position, one of these elements will always have the <code>active</code> class.</li>
|
|
608
|
+
<li>The <code>arrows</code> property allows you to add custom arrows to the progress bar. You can either specify a <code>size</code> for the arrows and provide a custom <code>element</code>.</li>
|
|
609
|
+
</ul></em><br />
|
|
610
|
+
<br />
|
|
611
|
+
<strong>Example:</strong>
|
|
612
|
+
|
|
613
|
+
```tsx
|
|
614
|
+
<MorphScroll
|
|
615
|
+
progressTrigger={{
|
|
616
|
+
wheel: true,
|
|
617
|
+
progressElement: <div className="your-scroll-thumb" />,
|
|
618
|
+
}}
|
|
619
|
+
// another props
|
|
620
|
+
>
|
|
621
|
+
{children}
|
|
622
|
+
</MorphScroll>
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
</ul>
|
|
626
|
+
|
|
627
|
+
</details>
|
|
628
|
+
|
|
629
|
+
<h2></h2>
|
|
630
|
+
|
|
631
|
+
<details>
|
|
632
|
+
<summary><strong><code>render</code></strong>: <em>Types of rendering for optimization.</em></summary><br />
|
|
585
633
|
<ul>
|
|
586
|
-
<
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
634
|
+
<strong>Type:</strong><br />
|
|
635
|
+
| { type: "default" }<br />
|
|
636
|
+
| { type: "lazy"; rootMargin?: number | number[]; onVisible?: (key: string) => void }<br />
|
|
637
|
+
| { type: "virtual"; rootMargin?: number | number[] }<br />
|
|
638
|
+
<br />
|
|
639
|
+
<strong>Default:</strong> { type: "default" }<br />
|
|
640
|
+
<br />
|
|
641
|
+
<strong>Description:</strong> <em><br />
|
|
642
|
+
This parameter defines the rendering type for optimization.<br />
|
|
643
|
+
<br />
|
|
644
|
+
<ul>
|
|
645
|
+
<li>With <code>default</code>, no optimizations are applied.</li>
|
|
646
|
+
<li>With <code>lazy</code>, containers are created but do not load content until they enter the viewport. The <code>rootMargin</code> property controls the threshold for loading, and the <code>onVisible</code> callback function can be used to trigger actions when a container becomes visible for each scrollable object and provides the key of the first element in the container.</li>
|
|
647
|
+
<li>With <code>virtual</code>, a container is created for each scrollable object, and its absolute positioning is calculated based on <code>scrollTop</code> and scroll area dimensions. Rendering is dynamically adjusted according to the scroll position. The <code>rootMargin</code> property can also be used to extend the rendering area.</li>
|
|
648
|
+
</ul><br />
|
|
649
|
+
<br />
|
|
650
|
+
⚠ Note:<br />
|
|
651
|
+
<ul>
|
|
652
|
+
<li>The <code>onVisible</code> property is the same as in <code>IntersectionTracker/onVisible</code>.</li>
|
|
653
|
+
<li>
|
|
654
|
+
The <code>rootMargin</code> property accepts either a single number or an array of numbers.
|
|
655
|
+
<ul>
|
|
656
|
+
<li>If a two-number array is provided, the values follow the <code>horizontal/vertical</code> rule.</li>
|
|
657
|
+
<li>If a four-number array is provided, the values follow the <code>top/right/bottom/left</code> rule.</li>
|
|
658
|
+
</ul>
|
|
659
|
+
</li>
|
|
660
|
+
<li>All values are in pixels and apply regardless of the <code>direction</code>.</li>
|
|
661
|
+
</ul></em><br />
|
|
662
|
+
<br />
|
|
663
|
+
<strong>Example:</strong>
|
|
664
|
+
|
|
665
|
+
```tsx
|
|
666
|
+
<MorphScroll
|
|
667
|
+
render={{ type: "virtual" }}
|
|
668
|
+
// render={{
|
|
669
|
+
// type: "lazy",
|
|
670
|
+
// rootMargin: [0, 100],
|
|
671
|
+
// onVisible: () => console.log("visible"))
|
|
672
|
+
// }}
|
|
673
|
+
// another props
|
|
674
|
+
>
|
|
675
|
+
{children}
|
|
676
|
+
</MorphScroll>
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
</ul>
|
|
680
|
+
|
|
681
|
+
</details>
|
|
682
|
+
|
|
683
|
+
<h2></h2>
|
|
684
|
+
|
|
685
|
+
<details>
|
|
686
|
+
<summary><strong><code>emptyElements</code></strong>: <em>Handling of empty scroll elements.</em></summary><br />
|
|
592
687
|
<ul>
|
|
593
|
-
<
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
<
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
688
|
+
<strong>Type:</strong><br />
|
|
689
|
+
| {
|
|
690
|
+
mode: "clear";
|
|
691
|
+
clickTrigger?: { selector: string; delay?: number };
|
|
692
|
+
}<br />
|
|
693
|
+
| {
|
|
694
|
+
mode: "fallback";
|
|
695
|
+
element?: React.ReactNode;
|
|
696
|
+
clickTrigger?: { selector: string; delay?: number };
|
|
697
|
+
}<br /><br />
|
|
698
|
+
<strong>Description:</strong> <em><br />
|
|
699
|
+
If certain components might return nothing during rendering, this parameter helps manage them. The check and subsequent replacement with a fallback element or removal occur after the scroll elements are rendered. Due to this, when dynamically displaying elements in different <code>render</code> modes, you may notice slight position shifts during fast scrolling, as empty elements are removed, causing subsequent elements to reposition.<br />
|
|
700
|
+
<br />
|
|
701
|
+
<ul>
|
|
702
|
+
<li><code>mode: "clear"</code> – automatically removes empty elements, eliminating unnecessary gaps in the scroll list.</li>
|
|
703
|
+
<li><code>mode: "fallback"</code> – replaces empty elements with a specified fallback component. By default, it uses the <code>fallback</code> props value, but you can also pass a separate placeholder to <code>element</code>.</li>
|
|
704
|
+
</ul><br />
|
|
705
|
+
<br />
|
|
706
|
+
<code>clickTrigger</code> – if elements are removed via a click action, this property ensures cleanup is triggered accordingly. It accepts an object with a <code>selector</code> (such as a delete button’s class) and an optional <code>delay</code> (a delay in milliseconds to accommodate animations or complex removals).<br />
|
|
707
|
+
<br />
|
|
708
|
+
⚠ Note:<br />
|
|
709
|
+
For clarification, the cleanup will occur on the initial render, when the number of passed elements changes, on scroll, and on click if you use <code>clickTrigger</code>.</em><br />
|
|
710
|
+
<br />
|
|
711
|
+
<strong>Example:</strong>
|
|
712
|
+
|
|
713
|
+
```tsx
|
|
714
|
+
<MorphScroll
|
|
715
|
+
emptyElements={{
|
|
716
|
+
mode: "clear",
|
|
717
|
+
clickTrigger: { selector: ".close-button" },
|
|
718
|
+
}}
|
|
719
|
+
// emptyElements={{
|
|
720
|
+
// mode: "fallback",
|
|
721
|
+
// clickTrigger: {
|
|
722
|
+
// selector: ".close-button",
|
|
723
|
+
// delay: 100,
|
|
724
|
+
// },
|
|
725
|
+
// }}
|
|
726
|
+
// another props
|
|
727
|
+
>
|
|
728
|
+
{children}
|
|
729
|
+
</MorphScroll>
|
|
730
|
+
```
|
|
731
|
+
|
|
732
|
+
</ul>
|
|
733
|
+
|
|
734
|
+
</details>
|
|
735
|
+
|
|
736
|
+
<h2></h2>
|
|
737
|
+
|
|
738
|
+
<details>
|
|
739
|
+
<summary><strong><code>suspending</code></strong>: <em>Adds React Suspense.</em></summary><br />
|
|
639
740
|
<ul>
|
|
640
|
-
<
|
|
641
|
-
<
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
// delay: 100,
|
|
662
|
-
// },
|
|
663
|
-
// }}
|
|
664
|
-
// another props
|
|
665
|
-
>
|
|
666
|
-
{children}
|
|
667
|
-
</MorphScroll>
|
|
668
|
-
```
|
|
669
|
-
|
|
670
|
-
</ul>
|
|
671
|
-
</details>
|
|
672
|
-
|
|
673
|
-
<details>
|
|
674
|
-
<summary><strong><code>suspending</code></strong> : <em>Adds React Suspense.</em></summary><br />
|
|
675
|
-
<ul>
|
|
676
|
-
<strong>Type:</strong> boolean<br />
|
|
677
|
-
<br />
|
|
678
|
-
<strong>Default:</strong> false<br />
|
|
679
|
-
<br />
|
|
680
|
-
<strong>Description:</strong> <em><br />
|
|
681
|
-
This parameter adds React Suspense to the MorphScroll component for asynchronous rendering.</em><br />
|
|
682
|
-
<br />
|
|
683
|
-
<strong>Example:</strong>
|
|
684
|
-
|
|
685
|
-
```tsx
|
|
686
|
-
<MorphScroll
|
|
687
|
-
suspending
|
|
688
|
-
// another props
|
|
689
|
-
>
|
|
690
|
-
{children}
|
|
691
|
-
</MorphScroll>
|
|
692
|
-
```
|
|
693
|
-
|
|
694
|
-
</ul>
|
|
695
|
-
</details>
|
|
696
|
-
|
|
697
|
-
<details>
|
|
698
|
-
<summary><strong><code>fallback</code></strong> : <em>Fallback element.</em></summary><br />
|
|
699
|
-
<ul>
|
|
700
|
-
<strong>Type:</strong> React.ReactNode<br />
|
|
701
|
-
<br />
|
|
702
|
-
<strong>Description:</strong> <em><br />
|
|
703
|
-
This parameter sets the fallback element for custom element. It will be used for <code>emptyElements</code> in <code>mode: "fallback"</code> or when <code>suspending</code> is enabled.</em><br />
|
|
704
|
-
<br />
|
|
705
|
-
<strong>Example:</strong>
|
|
706
|
-
|
|
707
|
-
```tsx
|
|
708
|
-
<MorphScroll
|
|
709
|
-
fallback={<div>Loading...</div>}
|
|
710
|
-
// another props
|
|
711
|
-
>
|
|
712
|
-
{children}
|
|
713
|
-
</MorphScroll>
|
|
714
|
-
```
|
|
741
|
+
<strong>Type:</strong> boolean<br />
|
|
742
|
+
<br />
|
|
743
|
+
<strong>Default:</strong> false<br />
|
|
744
|
+
<br />
|
|
745
|
+
<strong>Description:</strong> <em><br />
|
|
746
|
+
This parameter adds React Suspense to the MorphScroll component for asynchronous rendering.</em><br />
|
|
747
|
+
<br />
|
|
748
|
+
<strong>Example:</strong>
|
|
749
|
+
|
|
750
|
+
```tsx
|
|
751
|
+
<MorphScroll
|
|
752
|
+
suspending
|
|
753
|
+
// another props
|
|
754
|
+
>
|
|
755
|
+
{children}
|
|
756
|
+
</MorphScroll>
|
|
757
|
+
```
|
|
758
|
+
|
|
759
|
+
</ul>
|
|
760
|
+
|
|
761
|
+
</details>
|
|
715
762
|
|
|
716
|
-
|
|
717
|
-
|
|
763
|
+
<h2></h2>
|
|
764
|
+
|
|
765
|
+
<details>
|
|
766
|
+
<summary><strong><code>fallback</code></strong>: <em>Fallback element.</em></summary><br />
|
|
767
|
+
<ul>
|
|
768
|
+
<strong>Type:</strong> React.ReactNode<br />
|
|
769
|
+
<br />
|
|
770
|
+
<strong>Description:</strong> <em><br />
|
|
771
|
+
This parameter sets the fallback element for custom element. It will be used for <code>emptyElements</code> in <code>mode: "fallback"</code> or when <code>suspending</code> is enabled.</em><br />
|
|
772
|
+
<br />
|
|
773
|
+
<strong>Example:</strong>
|
|
774
|
+
|
|
775
|
+
```tsx
|
|
776
|
+
<MorphScroll
|
|
777
|
+
fallback={<div>Loading...</div>}
|
|
778
|
+
// another props
|
|
779
|
+
>
|
|
780
|
+
{children}
|
|
781
|
+
</MorphScroll>
|
|
782
|
+
```
|
|
783
|
+
|
|
784
|
+
</ul>
|
|
785
|
+
|
|
786
|
+
</details>
|
|
787
|
+
|
|
788
|
+
</div>
|
|
718
789
|
|
|
719
790
|
<h2></h2>
|
|
720
791
|
|
|
@@ -724,121 +795,133 @@ npm install morphing-scroll
|
|
|
724
795
|
|
|
725
796
|
- ### Props:
|
|
726
797
|
|
|
727
|
-
<
|
|
728
|
-
|
|
729
|
-
<
|
|
730
|
-
<strong>
|
|
731
|
-
<br />
|
|
732
|
-
<strong>Description:</strong> <em><br />
|
|
733
|
-
Instead of a standard <code>children</code> prop, this component uses a <strong>render-prop function</strong> to pass size updates to its children. You can use it similarly to a regular <code>children</code> prop inside the component.<br />
|
|
734
|
-
<br />
|
|
735
|
-
The function receives an object of type <code>DOMRectReadOnly</code> with the following properties:
|
|
798
|
+
<div>
|
|
799
|
+
|
|
800
|
+
<details>
|
|
801
|
+
<summary><strong><code>children</code></strong>: <em>Render-prop function for size updates and adding content.</em></summary><br />
|
|
736
802
|
<ul>
|
|
737
|
-
<
|
|
738
|
-
<
|
|
739
|
-
<
|
|
740
|
-
<
|
|
741
|
-
<
|
|
742
|
-
|
|
743
|
-
<
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
<
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
803
|
+
<strong>Type:</strong> (rect: DOMRectReadOnly) => React.ReactNode<br />
|
|
804
|
+
<br />
|
|
805
|
+
<strong>Description:</strong> <em><br />
|
|
806
|
+
Instead of a standard <code>children</code> prop, this component uses a <strong>render-prop function</strong> to pass size updates to its children. You can use it similarly to a regular <code>children</code> prop inside the component.<br />
|
|
807
|
+
<br />
|
|
808
|
+
The function receives an object of type <code>DOMRectReadOnly</code> with the following properties:
|
|
809
|
+
<ul>
|
|
810
|
+
<li><code>x</code> - The X-coordinate of the top-left corner of the element.</li>
|
|
811
|
+
<li><code>y</code> - The Y-coordinate of the top-left corner of the element.</li>
|
|
812
|
+
<li><code>width</code> - The width of the observed element’s content box.</li>
|
|
813
|
+
<li><code>height</code> - The height of the observed element’s content box.</li>
|
|
814
|
+
<li><code>top</code> - The distance from the top of the element to its parent's top. Equal to <code>y</code>.</li>
|
|
815
|
+
<li><code>left</code> - The distance from the left of the element to its parent's left. Equal to <code>x</code>.</li>
|
|
816
|
+
<li><code>right</code> - The distance from the left of the parent to the right edge of the element (<code>left</code> + <code>width</code>).</li>
|
|
817
|
+
<li><code>bottom</code> - The distance from the top of the parent to the bottom edge of the element (<code>top</code> + <code>height</code>).</li>
|
|
818
|
+
</ul><br />
|
|
819
|
+
<br />
|
|
820
|
+
⚠ This is a non-standard prop that you might be used to using this is render-prop function receiving the container's size.</em><br />
|
|
821
|
+
<br />
|
|
822
|
+
<strong>Example:</strong>
|
|
823
|
+
|
|
824
|
+
```tsx
|
|
825
|
+
<ResizeTracker
|
|
826
|
+
// another props
|
|
827
|
+
>
|
|
828
|
+
{(rect) => (
|
|
829
|
+
<p>
|
|
830
|
+
Width: {rect.width}, Height: {rect.height}
|
|
831
|
+
</p>
|
|
832
|
+
)}
|
|
833
|
+
</ResizeTracker>
|
|
834
|
+
```
|
|
835
|
+
|
|
836
|
+
</ul>
|
|
837
|
+
|
|
838
|
+
</details>
|
|
839
|
+
|
|
840
|
+
<h2></h2>
|
|
841
|
+
|
|
842
|
+
<details>
|
|
843
|
+
<summary><strong><code>style</code></strong>: <em>Applies inline styles to the container.</em></summary><br />
|
|
844
|
+
<ul>
|
|
845
|
+
<strong>Type:</strong> React.CSSProperties<br />
|
|
846
|
+
<br />
|
|
847
|
+
<strong>Example:</strong>
|
|
848
|
+
|
|
849
|
+
```tsx
|
|
850
|
+
<ResizeTracker style={{ backgroundColor: "blue" }}>
|
|
851
|
+
{(rect) => (
|
|
852
|
+
// content
|
|
853
|
+
)}
|
|
854
|
+
</ResizeTracker>
|
|
855
|
+
```
|
|
856
|
+
|
|
857
|
+
</ul>
|
|
858
|
+
|
|
859
|
+
</details>
|
|
860
|
+
|
|
861
|
+
<h2></h2>
|
|
862
|
+
|
|
863
|
+
<details>
|
|
864
|
+
<summary><strong><code>measure</code></strong>: <em>Defines the measurement strategy.</em></summary><br />
|
|
865
|
+
<ul>
|
|
866
|
+
<strong>Type:</strong> "inner" | "outer" | "all"<br />
|
|
867
|
+
<br />
|
|
868
|
+
<strong>Default:</strong> "inner"<br />
|
|
869
|
+
<br />
|
|
870
|
+
<strong>Description:</strong><br />
|
|
871
|
+
<em>This prop determines what is being measured by automatically applying inline styles that affect width and height.<br />
|
|
872
|
+
<br />
|
|
873
|
+
- The default value <code>"inner"</code> sets <code>width: "max-content"</code> and <code>height: "max-content"</code>, measuring the size of child elements.<br />
|
|
874
|
+
- The <code>"outer"</code> value measures the parent element by setting <code>minWidth: "100%"</code> and <code>minHeight: "100%"</code>.<br />
|
|
875
|
+
- The <code>"all"</code> value combines the styles of both <code>"inner"</code> and <code>"outer"</code>, allowing measurement of both the parent and child elements.<br />
|
|
876
|
+
<br />
|
|
877
|
+
⚠ Note: Be cautious when overriding styles via the <code>style</code> prop, as it may interfere with the styles applied by <code>measure</code>, leading to unexpected behavior.</em><br />
|
|
878
|
+
<br />
|
|
879
|
+
<strong>Example:</strong>
|
|
880
|
+
|
|
881
|
+
```tsx
|
|
882
|
+
<ResizeTracker measure="all">
|
|
883
|
+
{(rect) => (
|
|
884
|
+
// content
|
|
885
|
+
)}
|
|
886
|
+
</ResizeTracker>
|
|
887
|
+
```
|
|
888
|
+
|
|
889
|
+
</ul>
|
|
890
|
+
|
|
891
|
+
</details>
|
|
892
|
+
|
|
893
|
+
<h2></h2>
|
|
894
|
+
|
|
895
|
+
<details>
|
|
896
|
+
<summary><strong><code>onResize</code></strong>: <em>Callback triggered on size changes.</em></summary><br />
|
|
897
|
+
<ul>
|
|
898
|
+
<strong>Type:</strong> (rect: Partial<DOMRectReadOnly>) => void<br />
|
|
899
|
+
<br />
|
|
900
|
+
<strong>Description:</strong><br />
|
|
901
|
+
<em>A callback function that is triggered whenever the observed element's dimensions change.<br />
|
|
902
|
+
The function receives an object containing the updated size properties.</em><br />
|
|
903
|
+
<br />
|
|
904
|
+
<strong>Example:</strong>
|
|
905
|
+
|
|
906
|
+
```tsx
|
|
907
|
+
<ResizeTracker
|
|
908
|
+
onResize={(rect) => {
|
|
909
|
+
console.log("New size:", rect);
|
|
910
|
+
}}
|
|
911
|
+
>
|
|
912
|
+
{(rect) => (
|
|
913
|
+
// content
|
|
914
|
+
)}
|
|
915
|
+
</ResizeTracker>
|
|
916
|
+
```
|
|
917
|
+
|
|
918
|
+
</ul>
|
|
919
|
+
|
|
920
|
+
</details>
|
|
921
|
+
|
|
922
|
+
<h2></h2>
|
|
923
|
+
|
|
924
|
+
</div>
|
|
842
925
|
|
|
843
926
|
- ### Link:
|
|
844
927
|
|
|
@@ -852,179 +935,197 @@ npm install morphing-scroll
|
|
|
852
935
|
|
|
853
936
|
- ### Props:
|
|
854
937
|
|
|
855
|
-
<
|
|
856
|
-
|
|
857
|
-
<
|
|
858
|
-
<strong>
|
|
859
|
-
<br />
|
|
860
|
-
<strong>Example:</strong>
|
|
861
|
-
|
|
862
|
-
```tsx
|
|
863
|
-
<IntersectionTracker>{children}</IntersectionTracker>
|
|
864
|
-
```
|
|
865
|
-
|
|
866
|
-
</ul>
|
|
867
|
-
|
|
868
|
-
</details>
|
|
869
|
-
|
|
870
|
-
<details>
|
|
871
|
-
<summary><strong><code>style</code></strong> : <em>Applies inline styles to the container.</em></summary><br />
|
|
872
|
-
<ul>
|
|
873
|
-
<strong>Type:</strong> React.CSSProperties<br />
|
|
874
|
-
<br />
|
|
875
|
-
<strong>Example:</strong>
|
|
876
|
-
|
|
877
|
-
```tsx
|
|
878
|
-
<IntersectionTracker style={{ backgroundColor: "blue" }}>
|
|
879
|
-
{children}
|
|
880
|
-
</IntersectionTracker>
|
|
881
|
-
```
|
|
882
|
-
|
|
883
|
-
</ul>
|
|
884
|
-
|
|
885
|
-
</details>
|
|
886
|
-
|
|
887
|
-
<details>
|
|
888
|
-
<summary><strong><code>root</code></strong> : <em>Defines the observation area.</em></summary><br />
|
|
889
|
-
<ul>
|
|
890
|
-
<strong>Type:</strong> Element | null<br />
|
|
891
|
-
<br />
|
|
892
|
-
<strong>Default:</strong> null (window)<br />
|
|
893
|
-
<br />
|
|
894
|
-
<strong>Description:</strong> <em><br />
|
|
895
|
-
Specifies the element that serves as the bounding box for the intersection observation.
|
|
896
|
-
If provided, it must be an ancestor of the observed element.<br />
|
|
897
|
-
<br />
|
|
898
|
-
If set to <code>null</code> (default), the window is used as the observation area.</em><br />
|
|
899
|
-
<br />
|
|
900
|
-
<strong>Example:</strong>
|
|
901
|
-
|
|
902
|
-
```tsx
|
|
903
|
-
<IntersectionTracker root={document.getElementById("root")}>
|
|
904
|
-
{children}
|
|
905
|
-
</IntersectionTracker>
|
|
906
|
-
```
|
|
907
|
-
|
|
908
|
-
</ul>
|
|
909
|
-
|
|
910
|
-
</details>
|
|
911
|
-
|
|
912
|
-
<details>
|
|
913
|
-
<summary><strong><code>rootMargin</code></strong> : <em>Sets the margin around the root element.</em></summary><br />
|
|
914
|
-
<ul>
|
|
915
|
-
<strong>Type:</strong> number | number[]<br />
|
|
916
|
-
<br />
|
|
917
|
-
<strong>Description:</strong> <em><br />
|
|
918
|
-
Defines an offset around the root element, expanding or shrinking the observed area.<br />
|
|
919
|
-
<br />
|
|
920
|
-
Accepts a single number or an array for fine-tuned control:<br />
|
|
938
|
+
<div>
|
|
939
|
+
|
|
940
|
+
<details>
|
|
941
|
+
<summary><strong><code>children</code></strong>: <em>Custom user content.</em></summary><br />
|
|
921
942
|
<ul>
|
|
922
|
-
<
|
|
923
|
-
<
|
|
924
|
-
<
|
|
943
|
+
<strong>Type:</strong> React.ReactNode<br />
|
|
944
|
+
<br />
|
|
945
|
+
<strong>Example:</strong>
|
|
946
|
+
|
|
947
|
+
```tsx
|
|
948
|
+
<IntersectionTracker>{children}</IntersectionTracker>
|
|
949
|
+
```
|
|
950
|
+
|
|
925
951
|
</ul>
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
<
|
|
933
|
-
rootMargin={10}
|
|
934
|
-
// rootMargin={[10, 20]}
|
|
935
|
-
// rootMargin={[10, 20, 10, 20]}
|
|
936
|
-
>
|
|
937
|
-
{children}
|
|
938
|
-
</IntersectionTracker>
|
|
939
|
-
```
|
|
940
|
-
|
|
941
|
-
</ul>
|
|
942
|
-
|
|
943
|
-
</details>
|
|
944
|
-
|
|
945
|
-
<details>
|
|
946
|
-
<summary><strong><code>threshold</code></strong> : <em>Defines when the callback is triggered.</em></summary><br />
|
|
947
|
-
<ul>
|
|
948
|
-
<strong>Type:</strong> number | number[]<br />
|
|
949
|
-
<br />
|
|
950
|
-
<strong>Description:</strong> <em><br />
|
|
951
|
-
.Specifies at what percentage of the observed element’s visibility the callback should be executed.<br />
|
|
952
|
-
<br />
|
|
952
|
+
|
|
953
|
+
</details>
|
|
954
|
+
|
|
955
|
+
<h2></h2>
|
|
956
|
+
|
|
957
|
+
<details>
|
|
958
|
+
<summary><strong><code>style</code></strong>: <em>Applies inline styles to the container.</em></summary><br />
|
|
953
959
|
<ul>
|
|
954
|
-
<
|
|
955
|
-
<
|
|
960
|
+
<strong>Type:</strong> React.CSSProperties<br />
|
|
961
|
+
<br />
|
|
962
|
+
<strong>Example:</strong>
|
|
963
|
+
|
|
964
|
+
```tsx
|
|
965
|
+
<IntersectionTracker style={{ backgroundColor: "blue" }}>
|
|
966
|
+
{children}
|
|
967
|
+
</IntersectionTracker>
|
|
968
|
+
```
|
|
969
|
+
|
|
956
970
|
</ul>
|
|
957
|
-
<br />
|
|
958
|
-
A value of <code>0</code> means the callback fires when any part of the element appears, while <code>1</code> means the element must be fully visible.</em><br />
|
|
959
|
-
<br />
|
|
960
|
-
<strong>Example:</strong>
|
|
961
|
-
|
|
962
|
-
```tsx
|
|
963
|
-
<IntersectionTracker
|
|
964
|
-
threshold={0.5}
|
|
965
|
-
// threshold={[0, 0.5, 1]}
|
|
966
|
-
>
|
|
967
|
-
{children}
|
|
968
|
-
</IntersectionTracker>
|
|
969
|
-
```
|
|
970
|
-
|
|
971
|
-
</ul>
|
|
972
|
-
|
|
973
|
-
</details>
|
|
974
|
-
|
|
975
|
-
<details>
|
|
976
|
-
<summary><strong><code>visibleContent</code></strong> : <em>Makes all elements always visible.</em></summary><br />
|
|
977
|
-
<ul>
|
|
978
|
-
<strong>Type:</strong> boolean<br />
|
|
979
|
-
<br />
|
|
980
|
-
<strong>Default:</strong> false<br />
|
|
981
|
-
<br />
|
|
982
|
-
<strong>Description:</strong> <em><br />
|
|
983
|
-
If set to `true`, the tracked elements will always be visible, regardless of their actual intersection status.
|
|
984
|
-
<br />
|
|
985
|
-
This can be useful for testing purposes or when using the <code>onVisible</code> callback, ensuring it continues to trigger whenever the element enters the viewport.</em><br />
|
|
986
|
-
<br />
|
|
987
|
-
<strong>Example:</strong>
|
|
988
|
-
|
|
989
|
-
```tsx
|
|
990
|
-
<IntersectionTracker visibleContent>{children}</IntersectionTracker>
|
|
991
|
-
```
|
|
992
|
-
|
|
993
|
-
</ul>
|
|
994
|
-
|
|
995
|
-
</details>
|
|
996
|
-
|
|
997
|
-
<details>
|
|
998
|
-
<summary><strong><code>onVisible</code></strong> : <em>Callback function triggered when the element becomes visible.</em></summary><br />
|
|
999
|
-
<ul>
|
|
1000
|
-
<strong>Type:</strong> (key: string) => void<br />
|
|
1001
|
-
<br />
|
|
1002
|
-
<strong>Description:</strong> <em><br />
|
|
1003
|
-
A callback function that is invoked when the observed element enters the viewport or the defined observation area.<br />
|
|
1004
|
-
<br />
|
|
1005
|
-
The callback receives the <code>key</code> of the first child element as a parameter.<br />
|
|
1006
|
-
This can be useful for lazy loading, analytics tracking, animations, or any other action that needs to be triggered when an element becomes visible.<br />
|
|
1007
|
-
<br />
|
|
1008
|
-
⚠ Note:<br />
|
|
1009
|
-
Instead of checking if <code>key</code> equals the element’s key name, use <code>includes</code> for verification. React may modify key names by prefixing them with special characters like <code>.$</code>, making direct equality checks unreliable and more expensive 💵.</em><br />
|
|
1010
|
-
<br />
|
|
1011
|
-
<strong>Example:</strong>
|
|
1012
|
-
|
|
1013
|
-
```tsx
|
|
1014
|
-
<IntersectionTracker
|
|
1015
|
-
onVisible={(key) => {
|
|
1016
|
-
if (key.includes("elementId")) {
|
|
1017
|
-
// do something
|
|
1018
|
-
}
|
|
1019
|
-
}}
|
|
1020
|
-
>
|
|
1021
|
-
{children}
|
|
1022
|
-
</IntersectionTracker>
|
|
1023
|
-
```
|
|
1024
971
|
|
|
1025
|
-
</
|
|
972
|
+
</details>
|
|
973
|
+
|
|
974
|
+
<h2></h2>
|
|
975
|
+
|
|
976
|
+
<details>
|
|
977
|
+
<summary><strong><code>root</code></strong>: <em>Defines the observation area.</em></summary><br />
|
|
978
|
+
<ul>
|
|
979
|
+
<strong>Type:</strong> Element | null<br />
|
|
980
|
+
<br />
|
|
981
|
+
<strong>Default:</strong> null (window)<br />
|
|
982
|
+
<br />
|
|
983
|
+
<strong>Description:</strong> <em><br />
|
|
984
|
+
Specifies the element that serves as the bounding box for the intersection observation.
|
|
985
|
+
If provided, it must be an ancestor of the observed element.<br />
|
|
986
|
+
<br />
|
|
987
|
+
If set to <code>null</code> (default), the window is used as the observation area.</em><br />
|
|
988
|
+
<br />
|
|
989
|
+
<strong>Example:</strong>
|
|
990
|
+
|
|
991
|
+
```tsx
|
|
992
|
+
<IntersectionTracker root={document.getElementById("root")}>
|
|
993
|
+
{children}
|
|
994
|
+
</IntersectionTracker>
|
|
995
|
+
```
|
|
996
|
+
|
|
997
|
+
</ul>
|
|
998
|
+
|
|
999
|
+
</details>
|
|
1000
|
+
|
|
1001
|
+
<h2></h2>
|
|
1002
|
+
|
|
1003
|
+
<details>
|
|
1004
|
+
<summary><strong><code>rootMargin</code></strong>: <em>Sets the margin around the root element.</em></summary><br />
|
|
1005
|
+
<ul>
|
|
1006
|
+
<strong>Type:</strong> number | number[]<br />
|
|
1007
|
+
<br />
|
|
1008
|
+
<strong>Description:</strong> <em><br />
|
|
1009
|
+
Defines an offset around the root element, expanding or shrinking the observed area.<br />
|
|
1010
|
+
<br />
|
|
1011
|
+
Accepts a single number or an array for fine-tuned control:<br />
|
|
1012
|
+
<ul>
|
|
1013
|
+
<li>A <strong>single number</strong> sets the same margin on all sides.</li>
|
|
1014
|
+
<li>A <strong>two-value array</strong> <code>[topBottom, leftRight]</code> applies margins vertically and horizontally.</li>
|
|
1015
|
+
<li>A <strong>four-value array</strong> <code>[top, right, bottom, left]</code> allows full control over each side.</li>
|
|
1016
|
+
</ul>
|
|
1017
|
+
<br />
|
|
1018
|
+
Margins are converted to <code>px</code> values internally.</em><br />
|
|
1019
|
+
<br />
|
|
1020
|
+
<strong>Example:</strong>
|
|
1021
|
+
|
|
1022
|
+
```tsx
|
|
1023
|
+
<IntersectionTracker
|
|
1024
|
+
rootMargin={10}
|
|
1025
|
+
// rootMargin={[10, 20]}
|
|
1026
|
+
// rootMargin={[10, 20, 10, 20]}
|
|
1027
|
+
>
|
|
1028
|
+
{children}
|
|
1029
|
+
</IntersectionTracker>
|
|
1030
|
+
```
|
|
1031
|
+
|
|
1032
|
+
</ul>
|
|
1033
|
+
|
|
1034
|
+
</details>
|
|
1035
|
+
|
|
1036
|
+
<h2></h2>
|
|
1037
|
+
|
|
1038
|
+
<details>
|
|
1039
|
+
<summary><strong><code>threshold</code></strong>: <em>Defines when the callback is triggered.</em></summary><br />
|
|
1040
|
+
<ul>
|
|
1041
|
+
<strong>Type:</strong> number | number[]<br />
|
|
1042
|
+
<br />
|
|
1043
|
+
<strong>Description:</strong> <em><br />
|
|
1044
|
+
.Specifies at what percentage of the observed element’s visibility the callback should be executed.<br />
|
|
1045
|
+
<br />
|
|
1046
|
+
<ul>
|
|
1047
|
+
<li>A <strong>single number</strong> (e.g., <code>0.5</code>) triggers when that fraction of the element is visible.</li>
|
|
1048
|
+
<li>A <strong>array of numbers</strong> (e.g., <code>[0, 0.5, 1]</code>) triggers the callback multiple times at different visibility levels.</li>
|
|
1049
|
+
</ul>
|
|
1050
|
+
<br />
|
|
1051
|
+
A value of <code>0</code> means the callback fires when any part of the element appears, while <code>1</code> means the element must be fully visible.</em><br />
|
|
1052
|
+
<br />
|
|
1053
|
+
<strong>Example:</strong>
|
|
1054
|
+
|
|
1055
|
+
```tsx
|
|
1056
|
+
<IntersectionTracker
|
|
1057
|
+
threshold={0.5}
|
|
1058
|
+
// threshold={[0, 0.5, 1]}
|
|
1059
|
+
>
|
|
1060
|
+
{children}
|
|
1061
|
+
</IntersectionTracker>
|
|
1062
|
+
```
|
|
1063
|
+
|
|
1064
|
+
</ul>
|
|
1065
|
+
|
|
1066
|
+
</details>
|
|
1067
|
+
|
|
1068
|
+
<h2></h2>
|
|
1069
|
+
|
|
1070
|
+
<details>
|
|
1071
|
+
<summary><strong><code>visibleContent</code></strong>: <em>Makes all elements always visible.</em></summary><br />
|
|
1072
|
+
<ul>
|
|
1073
|
+
<strong>Type:</strong> boolean<br />
|
|
1074
|
+
<br />
|
|
1075
|
+
<strong>Default:</strong> false<br />
|
|
1076
|
+
<br />
|
|
1077
|
+
<strong>Description:</strong> <em><br />
|
|
1078
|
+
If set to `true`, the tracked elements will always be visible, regardless of their actual intersection status.
|
|
1079
|
+
<br />
|
|
1080
|
+
This can be useful for testing purposes or when using the <code>onVisible</code> callback, ensuring it continues to trigger whenever the element enters the viewport.</em><br />
|
|
1081
|
+
<br />
|
|
1082
|
+
<strong>Example:</strong>
|
|
1083
|
+
|
|
1084
|
+
```tsx
|
|
1085
|
+
<IntersectionTracker visibleContent>{children}</IntersectionTracker>
|
|
1086
|
+
```
|
|
1087
|
+
|
|
1088
|
+
</ul>
|
|
1089
|
+
|
|
1090
|
+
</details>
|
|
1091
|
+
|
|
1092
|
+
<h2></h2>
|
|
1093
|
+
|
|
1094
|
+
<details>
|
|
1095
|
+
<summary><strong><code>onVisible</code></strong>: <em>Callback function triggered when the element becomes visible.</em></summary><br />
|
|
1096
|
+
<ul>
|
|
1097
|
+
<strong>Type:</strong> (key: string) => void<br />
|
|
1098
|
+
<br />
|
|
1099
|
+
<strong>Description:</strong> <em><br />
|
|
1100
|
+
A callback function that is invoked when the observed element enters the viewport or the defined observation area.<br />
|
|
1101
|
+
<br />
|
|
1102
|
+
The callback receives the <code>key</code> of the first child element as a parameter.<br />
|
|
1103
|
+
This can be useful for lazy loading, analytics tracking, animations, or any other action that needs to be triggered when an element becomes visible.<br />
|
|
1104
|
+
<br />
|
|
1105
|
+
⚠ Note:<br />
|
|
1106
|
+
Instead of checking if <code>key</code> equals the element’s key name, use <code>includes</code> for verification. React may modify key names by prefixing them with special characters like <code>.$</code>, making direct equality checks unreliable and more expensive 💵.</em><br />
|
|
1107
|
+
<br />
|
|
1108
|
+
<strong>Example:</strong>
|
|
1109
|
+
|
|
1110
|
+
```tsx
|
|
1111
|
+
<IntersectionTracker
|
|
1112
|
+
onVisible={(key) => {
|
|
1113
|
+
if (key.includes("elementId")) {
|
|
1114
|
+
// do something
|
|
1115
|
+
}
|
|
1116
|
+
}}
|
|
1117
|
+
>
|
|
1118
|
+
{children}
|
|
1119
|
+
</IntersectionTracker>
|
|
1120
|
+
```
|
|
1121
|
+
|
|
1122
|
+
</ul>
|
|
1123
|
+
|
|
1124
|
+
</details>
|
|
1125
|
+
|
|
1126
|
+
<h2></h2>
|
|
1026
1127
|
|
|
1027
|
-
</
|
|
1128
|
+
</div>
|
|
1028
1129
|
|
|
1029
1130
|
- ### Link:
|
|
1030
1131
|
|