dce-reactkit 3.5.8 → 3.5.9
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 +18 -24
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +18 -24
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/AutoscrollToBottomContainer.tsx +21 -22
package/package.json
CHANGED
|
@@ -128,10 +128,10 @@ type State = {
|
|
|
128
128
|
|
|
129
129
|
// Types of actions
|
|
130
130
|
enum ActionType {
|
|
131
|
-
//
|
|
132
|
-
|
|
133
|
-
//
|
|
134
|
-
|
|
131
|
+
// Hide the "jump to bottom" button
|
|
132
|
+
HideJumpToBottomButton = 'HideJumpToBottomButton',
|
|
133
|
+
// Show the "jump to bottom" button
|
|
134
|
+
ShowJumpToBottomButton = 'ShowJumpToBottomButton',
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
// Action definitions
|
|
@@ -139,8 +139,8 @@ type Action = (
|
|
|
139
139
|
| {
|
|
140
140
|
// Action type
|
|
141
141
|
type: (
|
|
142
|
-
| ActionType.
|
|
143
|
-
| ActionType.
|
|
142
|
+
| ActionType.HideJumpToBottomButton
|
|
143
|
+
| ActionType.ShowJumpToBottomButton
|
|
144
144
|
),
|
|
145
145
|
}
|
|
146
146
|
);
|
|
@@ -153,17 +153,15 @@ type Action = (
|
|
|
153
153
|
*/
|
|
154
154
|
const reducer = (state: State, action: Action): State => {
|
|
155
155
|
switch (action.type) {
|
|
156
|
-
case ActionType.
|
|
156
|
+
case ActionType.HideJumpToBottomButton: {
|
|
157
157
|
return {
|
|
158
158
|
...state,
|
|
159
|
-
// Hide the "jump to bottom" button
|
|
160
159
|
jumpToBottomButtonVisible: false,
|
|
161
160
|
};
|
|
162
161
|
}
|
|
163
|
-
case ActionType.
|
|
162
|
+
case ActionType.ShowJumpToBottomButton: {
|
|
164
163
|
return {
|
|
165
164
|
...state,
|
|
166
|
-
// Show the "jump to bottom" button
|
|
167
165
|
jumpToBottomButtonVisible: true,
|
|
168
166
|
};
|
|
169
167
|
}
|
|
@@ -235,6 +233,8 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
235
233
|
// Get info about container
|
|
236
234
|
const {
|
|
237
235
|
scrollTop,
|
|
236
|
+
scrollHeight,
|
|
237
|
+
clientHeight,
|
|
238
238
|
} = container.current;
|
|
239
239
|
|
|
240
240
|
// Distance to bottom
|
|
@@ -242,7 +242,9 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
242
242
|
getComputedStyle(document.documentElement).fontSize,
|
|
243
243
|
10,
|
|
244
244
|
);
|
|
245
|
-
const distanceToBottomRems = Math.abs(
|
|
245
|
+
const distanceToBottomRems = Math.abs(
|
|
246
|
+
(scrollTop + clientHeight - scrollHeight) / rootFontSizePx,
|
|
247
|
+
);
|
|
246
248
|
|
|
247
249
|
// Figure out if we're scrolled to the bottom
|
|
248
250
|
return (distanceToBottomRems < SCROLLED_TO_BOTTOM_THRESHOLD_REMS);
|
|
@@ -260,11 +262,11 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
260
262
|
|
|
261
263
|
// Update state
|
|
262
264
|
dispatch({
|
|
263
|
-
type: ActionType.
|
|
265
|
+
type: ActionType.HideJumpToBottomButton,
|
|
264
266
|
});
|
|
265
267
|
|
|
266
268
|
// Scroll to bottom
|
|
267
|
-
container.current.scrollTop =
|
|
269
|
+
container.current.scrollTop = container.current.scrollHeight;
|
|
268
270
|
};
|
|
269
271
|
|
|
270
272
|
/*----------------------------------------*/
|
|
@@ -281,13 +283,10 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
281
283
|
return;
|
|
282
284
|
}
|
|
283
285
|
|
|
284
|
-
//
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
// Remember if now no longer scrolled to bottom
|
|
288
|
-
if (nowScrolledToBottom) {
|
|
286
|
+
// If scrolled to bottom, hide the button
|
|
287
|
+
if (isScrolledToBottom()) {
|
|
289
288
|
dispatch({
|
|
290
|
-
type: ActionType.
|
|
289
|
+
type: ActionType.HideJumpToBottomButton,
|
|
291
290
|
});
|
|
292
291
|
}
|
|
293
292
|
};
|
|
@@ -318,7 +317,7 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
318
317
|
const currentItemIds = getItemIds(items);
|
|
319
318
|
|
|
320
319
|
// Check if new content appeared at bottom
|
|
321
|
-
const
|
|
320
|
+
const newContentAppeared = (
|
|
322
321
|
currentItemIds.length > 0
|
|
323
322
|
&& (
|
|
324
323
|
currentItemIds[currentItemIds.length - 1]
|
|
@@ -327,7 +326,7 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
327
326
|
);
|
|
328
327
|
|
|
329
328
|
// Do nothing if no new content
|
|
330
|
-
if (!
|
|
329
|
+
if (!newContentAppeared) {
|
|
331
330
|
return;
|
|
332
331
|
}
|
|
333
332
|
|
|
@@ -338,7 +337,7 @@ const AutoscrollToBottomContainer: React.FC<Props> = (props) => {
|
|
|
338
337
|
} else {
|
|
339
338
|
// Not scrolled to bottom. Show "jump to bottom" button.
|
|
340
339
|
dispatch({
|
|
341
|
-
type: ActionType.
|
|
340
|
+
type: ActionType.ShowJumpToBottomButton,
|
|
342
341
|
});
|
|
343
342
|
}
|
|
344
343
|
|