From 29c2b6bc7f8d063e09201d924dbbb0dffdf1852e Mon Sep 17 00:00:00 2001 From: sawka Date: Fri, 14 Jun 2024 10:46:03 -0700 Subject: [PATCH] working on a hover state for the headers --- frontend/app/block/block.less | 23 ++++++++++++++ frontend/app/block/block.tsx | 60 +++++++++++++++++++++++++++++++++-- frontend/app/theme.less | 3 ++ 3 files changed, 84 insertions(+), 2 deletions(-) diff --git a/frontend/app/block/block.less b/frontend/app/block/block.less index 711b13834..96ce017a2 100644 --- a/frontend/app/block/block.less +++ b/frontend/app/block/block.less @@ -10,6 +10,7 @@ height: 100%; overflow: hidden; min-height: 0; + position: relative; .block-content { display: flex; @@ -19,6 +20,23 @@ min-height: 0; padding: 5px; } + + .block-header-animation-wrap { + max-height: 0; + transition: + max-height 0.3s ease-out, + opacity 0.3s ease-out; + overflow: hidden; + position: absolute; + top: 0; + width: 100%; + height: 30px; + z-index: var(--zindex-header-hover); + + &.is-showing { + max-height: 30px; + } + } } .block-header { @@ -34,6 +52,11 @@ -webkit-user-select: none; cursor: default; + .block-header-icon { + font-size: 20px; + padding: 0 5px; + } + .block-header-text { padding: 0 5px; flex-grow: 1; diff --git a/frontend/app/block/block.tsx b/frontend/app/block/block.tsx index 3b7fa5d05..68756488e 100644 --- a/frontend/app/block/block.tsx +++ b/frontend/app/block/block.tsx @@ -8,10 +8,14 @@ import { TerminalView } from "@/app/view/term"; import { ErrorBoundary } from "@/element/errorboundary"; import { CenteredDiv } from "@/element/quickelems"; import * as WOS from "@/store/wos"; +import clsx from "clsx"; import * as React from "react"; import "./block.less"; +const HoverPixels = 15; +const HoverTimeoutMs = 100; + interface BlockProps { blockId: string; onClose?: () => void; @@ -34,8 +38,45 @@ const BlockHeader = ({ blockId, onClose }: BlockProps) => { ); }; +const hoverStateOff = "off"; +const hoverStatePending = "pending"; +const hoverStateOn = "on"; + const Block = ({ blockId, onClose }: BlockProps) => { const blockRef = React.useRef(null); + const hoverState = React.useRef(hoverStateOff); + const [showHeader, setShowHeader] = React.useState(false); + + React.useEffect(() => { + const block = blockRef.current; + let hoverTimeout: NodeJS.Timeout = null; + const handleMouseMove = (event) => { + const rect = block.getBoundingClientRect(); + if (event.clientY - rect.top <= HoverPixels) { + if (hoverState.current == hoverStateOff) { + hoverTimeout = setTimeout(() => { + if (hoverState.current == hoverStatePending) { + hoverState.current = hoverStateOn; + setShowHeader(true); + } + }, HoverTimeoutMs); + hoverState.current = hoverStatePending; + } + } else { + if (hoverTimeout) { + if (hoverState.current == hoverStatePending) { + hoverState.current = hoverStateOff; + } + clearTimeout(hoverTimeout); + hoverTimeout = null; + } + } + }; + block.addEventListener("mousemove", handleMouseMove); + return () => { + block.removeEventListener("mousemove", handleMouseMove); + }; + }); let blockElem: JSX.Element = null; const [blockData, blockDataLoading] = WOS.useWaveObjectValue(WOS.makeORef("block", blockId)); @@ -52,8 +93,23 @@ const Block = ({ blockId, onClose }: BlockProps) => { blockElem = ; } return ( -
- +
{ + setShowHeader(false); + hoverState.current = hoverStateOff; + }} + > +
{ + setShowHeader(false); + hoverState.current = hoverStateOff; + }} + > + +
Loading...}>{blockElem} diff --git a/frontend/app/theme.less b/frontend/app/theme.less index 7b55e1d19..5bf864211 100644 --- a/frontend/app/theme.less +++ b/frontend/app/theme.less @@ -22,4 +22,7 @@ --scrollbar-background-color: var(--main-bg-color); --scrollbar-thumb-color: rgba(255, 255, 255, 0.3); --scrollbar-thumb-hover-color: rgba(255, 255, 255, 0.5); + + /* z-index values */ + --zindex-header-hover: 100; }