Skip to content

Commit be2adc3

Browse files
authored
Make plots ribbon sticky on scroll (#2759)
* feat/2731: make plots ribbon sticky on scroll * adress PR feedback
1 parent a6cbc2f commit be2adc3

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

webview/src/plots/components/ribbon/Ribbon.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import cx from 'classnames'
12
import { MessageFromWebviewType } from 'dvc/src/webview/contract'
23
import React, { useEffect, useState } from 'react'
34
import { useSelector } from 'react-redux'
45
import { performOrderedUpdate, reorderObjectList } from 'dvc/src/util/array'
6+
import { useInView } from 'react-intersection-observer'
57
import styles from './styles.module.scss'
68
import { RibbonBlock } from './RibbonBlock'
79
import { sendMessage } from '../../../shared/vscode'
@@ -12,6 +14,12 @@ import { Lines, Refresh } from '../../../shared/components/icons'
1214
const MAX_NB_EXP = 7
1315

1416
export const Ribbon: React.FC = () => {
17+
const [ref, needsShadow] = useInView({
18+
root: document.querySelector('#webview-wrapper'),
19+
rootMargin: '-5px',
20+
threshold: 0.95
21+
})
22+
1523
const revisions = useSelector(
1624
(state: PlotsState) => state.webview.selectedRevisions
1725
)
@@ -42,7 +50,11 @@ export const Ribbon: React.FC = () => {
4250
}
4351

4452
return (
45-
<ul className={styles.list} data-testid="ribbon">
53+
<ul
54+
ref={ref}
55+
data-testid="ribbon"
56+
className={cx(styles.list, needsShadow && styles.withShadow)}
57+
>
4658
<li className={styles.buttonWrapper}>
4759
<IconButton
4860
onClick={selectRevisions}

webview/src/plots/components/ribbon/styles.module.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,22 @@
7373

7474
.list {
7575
display: flex;
76+
position: sticky;
7677
align-items: center;
7778
gap: 6px;
7879
border-bottom: 1px solid $border-color;
7980
padding: 10px 15px;
8081
margin: 0;
8182
flex-wrap: wrap;
83+
top: 0;
84+
width: 100%;
85+
z-index: 100;
86+
background-color: $bg-color;
87+
transition: box-shadow 0.25s;
88+
89+
&.withShadow {
90+
box-shadow: 0 5px 8px -2px $shadow;
91+
}
8292
}
8393

8494
.buttonWrapper {

webview/src/shared/components/webviewWrapper/WebviewWrapper.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const WebviewWrapper = ({
1414

1515
return (
1616
<div
17+
id="webview-wrapper"
1718
className={cx(styles.webviewWrapper, className)}
1819
style={themeVariables}
1920
onContextMenu={e => {
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.webviewWrapper {
22
width: 100%;
3-
height: 100%;
3+
height: auto;
4+
min-height: 100%;
45
}

0 commit comments

Comments
 (0)