From 4de6078be5014e8183f092dc69fe425c658e46a0 Mon Sep 17 00:00:00 2001 From: Artyom Zaporozhets Date: Fri, 15 Aug 2025 19:22:01 +0300 Subject: [PATCH] add small hint --- src/components/ui/data-table.tsx | 65 ++++++++++++++++++++++++-- src/components/ui/velocity-display.tsx | 3 ++ 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/components/ui/data-table.tsx b/src/components/ui/data-table.tsx index 48597eb..4a14104 100644 --- a/src/components/ui/data-table.tsx +++ b/src/components/ui/data-table.tsx @@ -1,8 +1,9 @@ -import React from "react"; +import React, { useState, useRef, useEffect } from "react"; interface DataTableProps { data: Array<{ label: string; + hint?: string; value: string | number; unit?: string; error?: string | number; @@ -12,12 +13,70 @@ interface DataTableProps { } export const DataTable: React.FC = ({ data, className = "" }) => { + const [activeHint, setActiveHint] = useState(null); + const [isHovering, setIsHovering] = useState(null); + const tableRef = useRef(null); + + useEffect(() => { + const handleClickOutside = (event: MouseEvent) => { + if (tableRef.current && !tableRef.current.contains(event.target as Node)) { + setActiveHint(null); + } + }; + + document.addEventListener('mousedown', handleClickOutside); + return () => { + document.removeEventListener('mousedown', handleClickOutside); + }; + }, []); + + const handleQuestionMarkClick = (index: number) => { + setActiveHint(activeHint === index ? null : index); + }; + + const handleQuestionMarkMouseEnter = (index: number) => { + setIsHovering(index); + }; + + const handleQuestionMarkMouseLeave = () => { + setIsHovering(null); + }; + return ( - +
{data.map((item, index) => ( - +
{item.label} + {item.label} + {item.hint && ( +
+ + {(isHovering === index || activeHint === index) && ( +
+ {item.hint} +
+
+ )} +
+ )} +
{item.value} {item.unit && ` ${item.unit}`} diff --git a/src/components/ui/velocity-display.tsx b/src/components/ui/velocity-display.tsx index d612d02..9af93de 100644 --- a/src/components/ui/velocity-display.tsx +++ b/src/components/ui/velocity-display.tsx @@ -45,6 +45,7 @@ export const VelocityDisplay: React.FC = ({ velocities, un }, { label: "Local group", + hint: "Source: https://ui.adsabs.harvard.edu/abs/2025A%26A...698A.178M/abstract", value: velocities["local_group"].v.toFixed(2), unit: units["local_group"].v, error: velocities["local_group"].e_v.toFixed(2), @@ -52,6 +53,7 @@ export const VelocityDisplay: React.FC = ({ velocities, un }, { label: "CMB (old)", + hint: "Source: https://ui.adsabs.harvard.edu/abs/1996ApJ...473..576F/abstract", value: velocities["cmb_old"].v.toFixed(2), unit: units["cmb_old"].v, error: velocities["cmb_old"].e_v.toFixed(2), @@ -59,6 +61,7 @@ export const VelocityDisplay: React.FC = ({ velocities, un }, { label: "CMB", + hint: "Source: https://ui.adsabs.harvard.edu/abs/2016A%26A...594A...8P/abstract", value: velocities["cmb"].v.toFixed(2), unit: units["cmb"].v, error: velocities["cmb"].e_v.toFixed(2),