Skip to content

Commit 588af24

Browse files
authored
Merge pull request #457 from AllenInstitute/feature/filelist-scrollable-styling
Update scroll styling for file lists
2 parents dc3dddc + 785b510 commit 588af24

File tree

5 files changed

+108
-19
lines changed

5 files changed

+108
-19
lines changed

packages/core/components/DirectoryTree/DirectoryTree.module.css

+17
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
list-style: none;
3333
}
3434

35+
/* Add padding to emphasize at end of list */
36+
.scroll-container li:last-of-type {
37+
padding-bottom: 30px;
38+
}
39+
3540
.error-message {
3641
position: absolute;
3742
top: 50%;
@@ -46,3 +51,15 @@
4651
.error-message p {
4752
margin: 0;
4853
}
54+
55+
.vertical-gradient {
56+
background-image: linear-gradient(to bottom, transparent, var(--secondary-background-color));
57+
position: absolute;
58+
height: 60px;
59+
width: 100%;
60+
pointer-events: none;
61+
opacity: 1;
62+
/* Should cover FileList gradient (10) but not file count (99) or aggregate info (999)*/
63+
z-index: 50;
64+
bottom: 0;
65+
}

packages/core/components/DirectoryTree/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export default function DirectoryTree(props: FileListProps) {
7575
return (
7676
<div className={classNames(props.className, styles.container)}>
7777
<RootLoadingIndicator visible={isLoading} />
78+
<div className={styles.verticalGradient} />
7879
<ul
7980
className={styles.scrollContainer}
8081
role="tree"

packages/core/components/FileList/FileList.module.css

+59-12
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,7 @@
88

99
.list {
1010
height: calc(100% - 3px);
11-
}
12-
13-
.horizontal-overflow::after {
14-
background-image: linear-gradient(to right, transparent, var(--secondary-background-color));
15-
bottom: 0;
16-
content: " ";
17-
height: 100%;
18-
right: 0;
19-
position: absolute;
20-
pointer-events: none;
21-
width: 60px;
22-
z-index: 11;
11+
position: relative;
2312
}
2413

2514
.row-count-display {
@@ -35,3 +24,61 @@
3524
margin-top: var(--row-count-margin-top);
3625
margin-block-end: 0;
3726
}
27+
28+
.horizontal-gradient {
29+
background-image: linear-gradient(to right, transparent, rgba(0, 0, 0, 0.9));
30+
position: absolute;
31+
height: calc(100% - var(--scrollbar-size));
32+
width: 60px;
33+
pointer-events: none;
34+
opacity: 1;
35+
z-index: 10;
36+
right: 0;
37+
}
38+
39+
/* For browsers that always show scrollbar, adjust shadow to avoid covering */
40+
@supports selector(::-webkit-scrollbar) {
41+
.vertical-gradient {
42+
background-image: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.9));
43+
position: absolute;
44+
height: 50px;
45+
width: calc(100% - var(--scrollbar-size));
46+
pointer-events: none;
47+
opacity: 1;
48+
z-index: 10;
49+
bottom: 0;
50+
}
51+
52+
.vertical-gradient-cropped {
53+
bottom: var(--scrollbar-size) !important;
54+
}
55+
56+
.horizontal-gradient-cropped {
57+
right: calc(var(--scrollbar-size)) !important;
58+
}
59+
}
60+
61+
@supports (scrollbar-color: auto) {
62+
.vertical-gradient {
63+
background-image: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.9));
64+
position: absolute;
65+
height: 50px;
66+
width: 100%;
67+
pointer-events: none;
68+
opacity: 1;
69+
z-index: 10;
70+
bottom: 0;
71+
}
72+
73+
.vertical-gradient-cropped {
74+
position: absolute;
75+
bottom: 0 !important;
76+
width: 100% !important;
77+
}
78+
79+
.horizontal-gradient-cropped {
80+
position: absolute;
81+
right: 0 !important;
82+
height: 100% !important;
83+
}
84+
}

packages/core/components/FileList/index.tsx

+27-4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const TALL_ROW_HEIGHT = 19;
4747
*/
4848
export default function FileList(props: FileListProps) {
4949
const [totalCount, setTotalCount] = React.useState<number | null>(null);
50+
const [lastVisibleRowIndex, setLastVisibleRowIndex] = React.useState<number>(0);
5051
const fileView = useSelector(selection.selectors.getFileView);
5152
const fileSelection = useSelector(selection.selectors.getFileSelection);
5253
const fileGridColumnCount = useSelector(selection.selectors.getFileGridColCount);
@@ -74,6 +75,14 @@ export default function FileList(props: FileListProps) {
7475
const calculatedHeight = Math.min(MAX_NON_ROOT_HEIGHT, dataDrivenHeight);
7576
const height = isRoot ? measuredHeight : calculatedHeight;
7677

78+
const totalRows = Math.ceil(
79+
(totalCount || DEFAULT_TOTAL_COUNT) / (fileView === FileView.LIST ? 1 : fileGridColumnCount)
80+
);
81+
// complement to isColumnWidthOverflowing
82+
const isRowHeightOverflowing = totalRows * rowHeight > height;
83+
// hide overlay when we reach the bottom of the list
84+
const atEndOfList = lastVisibleRowIndex === totalRows - 1;
85+
7786
const listRef = React.useRef<FixedSizeList | null>(null);
7887
const gridRef = React.useRef<FixedSizeGrid | null>(null);
7988
const outerRef = React.useRef<HTMLDivElement | null>(null);
@@ -196,6 +205,7 @@ export default function FileList(props: FileListProps) {
196205
const overscanStopIndex =
197206
overscanRowStopIndex * (overscanColumnStopIndex + 1);
198207

208+
setLastVisibleRowIndex(visibleRowStopIndex);
199209
onItemsRendered({
200210
// call onItemsRendered from InfiniteLoader
201211
visibleStartIndex,
@@ -216,7 +226,10 @@ export default function FileList(props: FileListProps) {
216226
itemSize={rowHeight} // row height
217227
height={height} // height of the list itself; affects number of rows rendered at any given time
218228
itemCount={totalCount || DEFAULT_TOTAL_COUNT}
219-
onItemsRendered={onItemsRendered}
229+
onItemsRendered={(renderProps) => {
230+
setLastVisibleRowIndex(renderProps.visibleStopIndex);
231+
onItemsRendered(renderProps);
232+
}}
220233
outerElementType={Header}
221234
outerRef={outerRef}
222235
ref={callbackRefList}
@@ -262,14 +275,24 @@ export default function FileList(props: FileListProps) {
262275
return (
263276
<div className={classNames(styles.container, className)}>
264277
<div
265-
className={classNames(styles.list, {
266-
[styles.horizontalOverflow]: isColumnWidthOverflowing,
267-
})}
278+
className={classNames(styles.list)}
268279
style={{
269280
height: isRoot ? undefined : `${calculatedHeight}px`,
270281
}}
271282
ref={measuredNodeRef}
272283
>
284+
<div
285+
className={classNames({
286+
[styles.horizontalGradient]: isColumnWidthOverflowing,
287+
[styles.horizontalGradientCropped]: isRowHeightOverflowing,
288+
})}
289+
></div>
290+
<div
291+
className={classNames({
292+
[styles.verticalGradient]: isRowHeightOverflowing && !atEndOfList,
293+
[styles.verticalGradientCropped]: isColumnWidthOverflowing,
294+
})}
295+
></div>
273296
{content}
274297
</div>
275298
<p className={styles.rowCountDisplay}>

packages/core/styles/global.css

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ main {
3434
@supports selector(::-webkit-scrollbar) {
3535
body *::-webkit-scrollbar {
3636
background-color: var(--accent-dark);
37-
width: 12px;
38-
height: 12px;
37+
width: var(--scrollbar-size);
38+
height: var(--scrollbar-size);
3939
}
4040
body *::-webkit-scrollbar-corner {
4141
background-color: var(--accent-dark);
4242
}
4343
body *::-webkit-scrollbar-thumb {
4444
background-color: var(--medium-grey);
45-
border-radius: 8px
45+
border-radius: 8px;
4646
}
4747
}
4848

@@ -94,6 +94,7 @@ body {
9494
--margin: 12px;
9595
--transition-duration: 0.5s;
9696
--font-family: 'Open Sans', sans-serif;
97+
--scrollbar-size: 12px;
9798
}
9899

99100
h1 {

0 commit comments

Comments
 (0)