From 1062145fe7a904fc444b2bcd57377e009cac3fbb Mon Sep 17 00:00:00 2001 From: Ivan Shcheklein Date: Fri, 11 Nov 2022 18:40:36 -0800 Subject: [PATCH] feat/2731: make plots ribbon sticky on scroll --- webview/src/plots/components/ribbon/Ribbon.tsx | 14 +++++++++++++- .../src/plots/components/ribbon/styles.module.scss | 10 ++++++++++ .../components/webviewWrapper/WebviewWrapper.tsx | 1 + .../components/webviewWrapper/styles.module.scss | 3 ++- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/webview/src/plots/components/ribbon/Ribbon.tsx b/webview/src/plots/components/ribbon/Ribbon.tsx index c81125410e..ab21c21925 100644 --- a/webview/src/plots/components/ribbon/Ribbon.tsx +++ b/webview/src/plots/components/ribbon/Ribbon.tsx @@ -1,7 +1,9 @@ +import cx from 'classnames' import { MessageFromWebviewType } from 'dvc/src/webview/contract' import React, { useEffect, useState } from 'react' import { useSelector } from 'react-redux' import { performOrderedUpdate, reorderObjectList } from 'dvc/src/util/array' +import { useInView } from 'react-intersection-observer' import styles from './styles.module.scss' import { RibbonBlock } from './RibbonBlock' import { sendMessage } from '../../../shared/vscode' @@ -12,6 +14,12 @@ import { Lines, Refresh } from '../../../shared/components/icons' const MAX_NB_EXP = 7 export const Ribbon: React.FC = () => { + const [ref, needsShadow] = useInView({ + root: document.querySelector('#webview-wrapper'), + rootMargin: '-5px', + threshold: 0.95 + }) + const revisions = useSelector( (state: PlotsState) => state.webview.selectedRevisions ) @@ -42,7 +50,11 @@ export const Ribbon: React.FC = () => { } return ( -