dce-reactkit 3.5.7 → 3.5.8
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 +11 -33
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +11 -33
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/AutoscrollToBottomContainer.tsx +10 -36
package/package.json
CHANGED
|
@@ -58,17 +58,11 @@ const style = `
|
|
|
58
58
|
|
|
59
59
|
.AutoscrollToBottomContainer-scrollable-container {
|
|
60
60
|
/* Take up max 100% height, don't take it up if not needed */
|
|
61
|
-
/* (so column-reverse layout doesn't start at the bottom) */
|
|
62
61
|
max-height: 100%;
|
|
63
62
|
overflow-y: auto;
|
|
64
63
|
|
|
65
64
|
/* Allow children to position */
|
|
66
65
|
position: relative;
|
|
67
|
-
|
|
68
|
-
/* Reverse order of children so scroll starts at bottom */
|
|
69
|
-
/* (but children will have to be rendered in reverse order) */
|
|
70
|
-
display: flex;
|
|
71
|
-
flex-direction: column-reverse;
|
|
72
66
|
}
|
|
73
67
|
|
|
74
68
|
.AutoscrollToBottomContainer-jump-to-bottom-container {
|
|
@@ -101,7 +95,7 @@ const style = `
|
|
|
101
95
|
|
|
102
96
|
// Scrolled to bottom threshold
|
|
103
97
|
// (how close you have to be to the bottom for it to count as the bottom)
|
|
104
|
-
const SCROLLED_TO_BOTTOM_THRESHOLD_REMS =
|
|
98
|
+
const SCROLLED_TO_BOTTOM_THRESHOLD_REMS = 1.5;
|
|
105
99
|
|
|
106
100
|
/*------------------------------------------------------------------------*/
|
|
107
101
|
/* -------------------------- Static Functions -------------------------- */
|
|
@@ -126,8 +120,6 @@ const getItemIds = (items: AutoScrollItem[]): (string | number)[] => {
|
|
|
126
120
|
/* -------- State Definition -------- */
|
|
127
121
|
|
|
128
122
|
type State = {
|
|
129
|
-
// If true, the user was scrolled to the bottom after last update
|
|
130
|
-
wasScrolledToBottom: boolean,
|
|
131
123
|
// If true, the "jump to bottom" button is visible
|
|
132
124
|
jumpToBottomButtonVisible: boolean,
|
|
133
125
|
};
|
|
@@ -138,8 +130,6 @@ type State = {
|
|
|
138
130
|
enum ActionType {
|
|
139
131
|
// Identify that the user is now scrolled to the bottom
|
|
140
132
|
NowScrolledToBottom = 'NowScrolledToBottom',
|
|
141
|
-
// Identify that the user scrolled away from the bottom
|
|
142
|
-
NowScrolledAwayFromBottom = 'NowScrolledAwayFromBottom',
|
|
143
133
|
// Identify that new content appeared at the bottom but is not visible
|
|
144
134
|
NewContentAtBottom = 'NewContentAtBottom',
|
|
145
135
|
}
|
|
@@ -150,7 +140,6 @@ type Action = (
|
|
|
150
140
|
// Action type
|
|
151
141
|
type: (
|
|
152
142
|
| ActionType.NowScrolledToBottom
|
|
153
|
-
| ActionType.NowScrolledAwayFromBottom
|
|
154
143
|
| ActionType.NewContentAtBottom
|
|
155
144
|
),
|
|
156
145
|
}
|
|
@@ -167,24 +156,13 @@ const reducer = (state: State, action: Action): State => {
|
|
|
167
156
|
case ActionType.NowScrolledToBottom: {
|
|
168
157
|
return {
|
|
169
158
|
...state,
|
|
170
|
-
// Store the event
|
|
171
|
-
wasScrolledToBottom: true,
|
|
172
159
|
// Hide the "jump to bottom" button
|
|
173
160
|
jumpToBottomButtonVisible: false,
|
|
174
161
|
};
|
|
175
162
|
}
|
|
176
|
-
case ActionType.NowScrolledAwayFromBottom: {
|
|
177
|
-
return {
|
|
178
|
-
...state,
|
|
179
|
-
// Store the event
|
|
180
|
-
wasScrolledToBottom: false,
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
163
|
case ActionType.NewContentAtBottom: {
|
|
184
164
|
return {
|
|
185
165
|
...state,
|
|
186
|
-
// Store the event
|
|
187
|
-
wasScrolledToBottom: false,
|
|
188
166
|
// Show the "jump to bottom" button
|
|
189
167
|
jumpToBottomButtonVisible: true,
|
|
190
168
|
};
|
|
@@ -217,7 +195,6 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
217
195
|
|
|
218
196
|
// Initial state
|
|
219
197
|
const initialState: State = {
|
|
220
|
-
wasScrolledToBottom: true,
|
|
221
198
|
jumpToBottomButtonVisible: false,
|
|
222
199
|
};
|
|
223
200
|
|
|
@@ -226,7 +203,6 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
226
203
|
|
|
227
204
|
// Destructure common state
|
|
228
205
|
const {
|
|
229
|
-
wasScrolledToBottom,
|
|
230
206
|
jumpToBottomButtonVisible,
|
|
231
207
|
} = state;
|
|
232
208
|
|
|
@@ -235,6 +211,7 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
235
211
|
// Initialize refs
|
|
236
212
|
const lastItemIds = useRef<(string | number)[]>([]);
|
|
237
213
|
const container = useRef<HTMLDivElement | null>(null);
|
|
214
|
+
const wasScrolledToBottomBeforeItemsUpdate = useRef<boolean>(true);
|
|
238
215
|
|
|
239
216
|
/*------------------------------------------------------------------------*/
|
|
240
217
|
/* ------------------------- Component Functions ------------------------ */
|
|
@@ -312,10 +289,6 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
312
289
|
dispatch({
|
|
313
290
|
type: ActionType.NowScrolledToBottom,
|
|
314
291
|
});
|
|
315
|
-
} else {
|
|
316
|
-
dispatch({
|
|
317
|
-
type: ActionType.NowScrolledAwayFromBottom,
|
|
318
|
-
});
|
|
319
292
|
}
|
|
320
293
|
};
|
|
321
294
|
|
|
@@ -336,7 +309,7 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
336
309
|
);
|
|
337
310
|
|
|
338
311
|
/**
|
|
339
|
-
* Update (also called on mount)
|
|
312
|
+
* Update (also called on mount): autoscroll
|
|
340
313
|
* @author Gabe Abrams
|
|
341
314
|
*/
|
|
342
315
|
useEffect(
|
|
@@ -359,7 +332,7 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
359
332
|
}
|
|
360
333
|
|
|
361
334
|
// Check if used to be scrolled to the bottom
|
|
362
|
-
if (
|
|
335
|
+
if (wasScrolledToBottomBeforeItemsUpdate.current) {
|
|
363
336
|
// Was scrolled to the bottom! Autoscroll.
|
|
364
337
|
scrollToBottom();
|
|
365
338
|
} else {
|
|
@@ -371,6 +344,11 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
371
344
|
|
|
372
345
|
// Update last item ids
|
|
373
346
|
lastItemIds.current = currentItemIds;
|
|
347
|
+
|
|
348
|
+
// Remember if we were scrolled to the bottom before the update
|
|
349
|
+
return () => {
|
|
350
|
+
wasScrolledToBottomBeforeItemsUpdate.current = isScrolledToBottom();
|
|
351
|
+
};
|
|
374
352
|
},
|
|
375
353
|
[items],
|
|
376
354
|
);
|
|
@@ -420,9 +398,7 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
420
398
|
{/* Scrollable Item Container */}
|
|
421
399
|
<div
|
|
422
400
|
className="AutoscrollToBottomContainer-scrollable-container"
|
|
423
|
-
onScroll={
|
|
424
|
-
handleScroll();
|
|
425
|
-
}}
|
|
401
|
+
onScroll={handleScroll}
|
|
426
402
|
ref={container}
|
|
427
403
|
>
|
|
428
404
|
{/* Items */}
|
|
@@ -439,8 +415,6 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
439
415
|
</div>
|
|
440
416
|
);
|
|
441
417
|
})
|
|
442
|
-
// Reverse order because flex column is reverse
|
|
443
|
-
.reverse()
|
|
444
418
|
}
|
|
445
419
|
</div>
|
|
446
420
|
</div>
|