mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-09 17:33:55 +00:00
1343818917
* fix: jsdoc comments * more human casting of string values to boolean * add coerceColour to get named colors to work * cue can't pass isKeyOfType event check * dont mutate value * alloow cue in eventDef * lint * css named or hex formatting * "sideEffects": false * test colour hex regex * roll eventDef back to master * parse property * don't export cssColour names * remove import * only allow string types to colour * handle transparent colour * mix alpha with bg colour * only allow updating events * descriptive names * add test for getAccessibleColour * readability * move isColourHex to regex-utils * simplify and add test
67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
import { memo, MutableRefObject, PropsWithChildren, useLayoutEffect, useRef, useState } from 'react';
|
|
|
|
import { getAccessibleColour } from '../../../common/utils/styleUtils';
|
|
|
|
import style from '../Cuesheet.module.scss';
|
|
|
|
const pastOpacity = '0.2';
|
|
|
|
interface EventRowProps {
|
|
eventIndex: number;
|
|
isPast?: boolean;
|
|
selectedRef?: MutableRefObject<HTMLTableRowElement | null>;
|
|
skip?: boolean;
|
|
colour?: string;
|
|
}
|
|
|
|
function EventRow(props: PropsWithChildren<EventRowProps>) {
|
|
const { children, eventIndex, isPast, selectedRef, skip, colour } = props;
|
|
const ownRef = useRef<HTMLTableRowElement>(null);
|
|
const [isVisible, setIsVisible] = useState(false);
|
|
|
|
const textColour = getAccessibleColour(colour);
|
|
const bgColour = textColour.backgroundColor;
|
|
|
|
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 (
|
|
<tr
|
|
className={`${style.eventRow} ${skip ? style.skip : ''}`}
|
|
style={{ opacity: `${isPast ? pastOpacity : '1'}` }}
|
|
ref={selectedRef ?? ownRef}
|
|
>
|
|
<td className={style.indexColumn} style={{ backgroundColor: bgColour, color: textColour.color }}>
|
|
{eventIndex}
|
|
</td>
|
|
{isVisible ? children : null}
|
|
</tr>
|
|
);
|
|
}
|
|
|
|
export default memo(EventRow);
|