mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-23 16:09:11 +00:00
style hover (#525)
* refactor: render if in view * style: add hover indicator on row
This commit is contained in:
@@ -61,6 +61,11 @@ $table-header-font-size: calc(1rem - 3px);
|
|||||||
.eventRow {
|
.eventRow {
|
||||||
vertical-align: top;
|
vertical-align: top;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
outline: 1px solid $blue-700;
|
||||||
|
outline-offset: -1px;
|
||||||
|
}
|
||||||
|
|
||||||
td {
|
td {
|
||||||
background-color: $gray-1250;
|
background-color: $gray-1250;
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { memo, MutableRefObject, PropsWithChildren } from 'react';
|
import { memo, MutableRefObject, PropsWithChildren, useLayoutEffect, useRef, useState } from 'react';
|
||||||
|
|
||||||
import { getAccessibleColour } from '../../../common/utils/styleUtils';
|
import { getAccessibleColour } from '../../../common/utils/styleUtils';
|
||||||
|
|
||||||
@@ -16,21 +16,50 @@ interface EventRowProps {
|
|||||||
|
|
||||||
function EventRow(props: PropsWithChildren<EventRowProps>) {
|
function EventRow(props: PropsWithChildren<EventRowProps>) {
|
||||||
const { children, eventIndex, isPast, selectedRef, skip, colour } = props;
|
const { children, eventIndex, isPast, selectedRef, skip, colour } = props;
|
||||||
|
const ownRef = useRef<HTMLTableRowElement>(null);
|
||||||
|
const [isVisible, setIsVisible] = useState(false);
|
||||||
|
|
||||||
const bgFallback = 'transparent';
|
const bgFallback = 'transparent';
|
||||||
const bgColour = colour || bgFallback;
|
const bgColour = colour || bgFallback;
|
||||||
const textColour = bgColour === bgFallback ? undefined : getAccessibleColour(bgColour);
|
const textColour = bgColour === bgFallback ? undefined : getAccessibleColour(bgColour);
|
||||||
|
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
const observer = new IntersectionObserver(
|
||||||
|
([entry]) => {
|
||||||
|
if (entry.isIntersecting) {
|
||||||
|
setIsVisible(true);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
root: null,
|
||||||
|
threshold: 0.01,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleRefCurrent = ownRef.current;
|
||||||
|
if (selectedRef) {
|
||||||
|
setIsVisible(true);
|
||||||
|
} else if (handleRefCurrent) {
|
||||||
|
observer.observe(handleRefCurrent);
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (handleRefCurrent) {
|
||||||
|
observer.unobserve(handleRefCurrent);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [ownRef, selectedRef]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tr
|
<tr
|
||||||
className={`${style.eventRow} ${skip ? style.skip : ''}`}
|
className={`${style.eventRow} ${skip ? style.skip : ''}`}
|
||||||
style={{ opacity: `${isPast ? pastOpacity : '1'}` }}
|
style={{ opacity: `${isPast ? pastOpacity : '1'}` }}
|
||||||
ref={selectedRef}
|
ref={selectedRef ?? ownRef}
|
||||||
>
|
>
|
||||||
<td className={style.indexColumn} style={{ backgroundColor: bgColour, color: textColour?.color }}>
|
<td className={style.indexColumn} style={{ backgroundColor: bgColour, color: textColour?.color }}>
|
||||||
{eventIndex}
|
{eventIndex}
|
||||||
</td>
|
</td>
|
||||||
{children}
|
{isVisible ? children : null}
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user