dce-reactkit 3.5.9 → 3.5.11
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/dist/cjs/index.js +28 -20
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/components/AutoscrollToBottomContainer.d.ts +2 -0
- package/dist/esm/index.js +28 -20
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/AutoscrollToBottomContainer.d.ts +2 -0
- package/dist/index.d.ts +2 -0
- package/package.json +1 -1
- package/src/components/AutoscrollToBottomContainer.tsx +36 -16
package/dist/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -35,6 +35,10 @@ type Props = {
|
|
|
35
35
|
items: AutoScrollItem[],
|
|
36
36
|
// Custom variant for the "Jump to Bottom" button
|
|
37
37
|
jumpToBottomButtonVariant?: Variant,
|
|
38
|
+
// Optional element to display before last item (but within the scrollpane)
|
|
39
|
+
messageBeforeItems?: React.ReactNode,
|
|
40
|
+
// Optional element to display after the last item (but within the scrollpane)
|
|
41
|
+
messageAfterItems?: React.ReactNode,
|
|
38
42
|
};
|
|
39
43
|
|
|
40
44
|
// AutoScrollItem definition
|
|
@@ -187,6 +191,8 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
187
191
|
itemsName,
|
|
188
192
|
items,
|
|
189
193
|
jumpToBottomButtonVariant = Variant.Danger,
|
|
194
|
+
messageBeforeItems,
|
|
195
|
+
messageAfterItems,
|
|
190
196
|
} = props;
|
|
191
197
|
|
|
192
198
|
/* -------------- State ------------- */
|
|
@@ -209,7 +215,7 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
209
215
|
// Initialize refs
|
|
210
216
|
const lastItemIds = useRef<(string | number)[]>([]);
|
|
211
217
|
const container = useRef<HTMLDivElement | null>(null);
|
|
212
|
-
const
|
|
218
|
+
const wasLastScrolledToBottom = useRef<boolean>(true);
|
|
213
219
|
|
|
214
220
|
/*------------------------------------------------------------------------*/
|
|
215
221
|
/* ------------------------- Component Functions ------------------------ */
|
|
@@ -247,7 +253,12 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
247
253
|
);
|
|
248
254
|
|
|
249
255
|
// Figure out if we're scrolled to the bottom
|
|
250
|
-
|
|
256
|
+
const atBottom = (distanceToBottomRems < SCROLLED_TO_BOTTOM_THRESHOLD_REMS);
|
|
257
|
+
|
|
258
|
+
// Remember if we scrolled to the bottom
|
|
259
|
+
wasLastScrolledToBottom.current = atBottom;
|
|
260
|
+
|
|
261
|
+
return atBottom;
|
|
251
262
|
};
|
|
252
263
|
|
|
253
264
|
/**
|
|
@@ -266,7 +277,13 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
266
277
|
});
|
|
267
278
|
|
|
268
279
|
// Scroll to bottom
|
|
269
|
-
container.current.scrollTop =
|
|
280
|
+
container.current.scrollTop = (
|
|
281
|
+
container.current.scrollHeight
|
|
282
|
+
- container.current.clientHeight
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
// Remember that we scrolled to the bottom
|
|
286
|
+
wasLastScrolledToBottom.current = true;
|
|
270
287
|
};
|
|
271
288
|
|
|
272
289
|
/*----------------------------------------*/
|
|
@@ -283,8 +300,9 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
283
300
|
return;
|
|
284
301
|
}
|
|
285
302
|
|
|
286
|
-
// If scrolled to bottom, hide the button
|
|
303
|
+
// If scrolled to bottom, hide the button and remember position
|
|
287
304
|
if (isScrolledToBottom()) {
|
|
305
|
+
// Hide button
|
|
288
306
|
dispatch({
|
|
289
307
|
type: ActionType.HideJumpToBottomButton,
|
|
290
308
|
});
|
|
@@ -318,20 +336,24 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
318
336
|
|
|
319
337
|
// Check if new content appeared at bottom
|
|
320
338
|
const newContentAppeared = (
|
|
339
|
+
// There are items
|
|
321
340
|
currentItemIds.length > 0
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
341
|
+
// The last item is new
|
|
342
|
+
&& !lastItemIds.current.includes(
|
|
343
|
+
currentItemIds[currentItemIds.length - 1],
|
|
325
344
|
)
|
|
326
345
|
);
|
|
327
346
|
|
|
347
|
+
// Update last item ids
|
|
348
|
+
lastItemIds.current = currentItemIds;
|
|
349
|
+
|
|
328
350
|
// Do nothing if no new content
|
|
329
351
|
if (!newContentAppeared) {
|
|
330
352
|
return;
|
|
331
353
|
}
|
|
332
354
|
|
|
333
355
|
// Check if used to be scrolled to the bottom
|
|
334
|
-
if (
|
|
356
|
+
if (wasLastScrolledToBottom.current) {
|
|
335
357
|
// Was scrolled to the bottom! Autoscroll.
|
|
336
358
|
scrollToBottom();
|
|
337
359
|
} else {
|
|
@@ -340,14 +362,6 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
340
362
|
type: ActionType.ShowJumpToBottomButton,
|
|
341
363
|
});
|
|
342
364
|
}
|
|
343
|
-
|
|
344
|
-
// Update last item ids
|
|
345
|
-
lastItemIds.current = currentItemIds;
|
|
346
|
-
|
|
347
|
-
// Remember if we were scrolled to the bottom before the update
|
|
348
|
-
return () => {
|
|
349
|
-
wasScrolledToBottomBeforeItemsUpdate.current = isScrolledToBottom();
|
|
350
|
-
};
|
|
351
365
|
},
|
|
352
366
|
[items],
|
|
353
367
|
);
|
|
@@ -400,6 +414,9 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
400
414
|
onScroll={handleScroll}
|
|
401
415
|
ref={container}
|
|
402
416
|
>
|
|
417
|
+
{/* Message before items */}
|
|
418
|
+
{messageBeforeItems}
|
|
419
|
+
|
|
403
420
|
{/* Items */}
|
|
404
421
|
{
|
|
405
422
|
items
|
|
@@ -415,6 +432,9 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
415
432
|
);
|
|
416
433
|
})
|
|
417
434
|
}
|
|
435
|
+
|
|
436
|
+
{/* Message after items */}
|
|
437
|
+
{messageAfterItems}
|
|
418
438
|
</div>
|
|
419
439
|
</div>
|
|
420
440
|
);
|