import { useRef, useState } from "react"; import { Badge } from "@calcom/ui/components/badge"; import type { IconName } from "@calcom/ui/components/icon"; import { Icon } from "@calcom/ui/components/icon"; import { Tooltip } from "@calcom/ui/components/tooltip"; type DisplayInfoType = { label: string; icon?: IconName; value: string | string[]; coloredBadges?: boolean; labelClassname?: string; valueClassname?: string; }; const badgeColors = ["warning", "success", "green", "gray", "blue", "red", "error"] as const; const valueDefaultClassname = "text-emphasis inline-flex items-center gap-1 font-medium leading-5"; export function DisplayInfo({ label, icon, value, coloredBadges, labelClassname, valueClassname = valueDefaultClassname, }: DisplayInfoType) { const displayAsBadges = Array.isArray(value); const scrollContainerRef = useRef(null); const [showLeftGradient, setShowLeftGradient] = useState(false); const [showRightGradient, setShowRightGradient] = useState(true); const handleScroll = () => { const element = scrollContainerRef.current; if (!element) return; setShowLeftGradient(element.scrollLeft > 0); const isAtEnd = Math.abs(element.scrollWidth - element.clientWidth - element.scrollLeft) < 1; setShowRightGradient(!isAtEnd); }; return (
{icon ? : null}
{displayAsBadges ? (
{value.map((v, idx) => { return coloredBadges ? ( {v} ) : ( {v} ); })}
) : (
{value}
{showLeftGradient && (
)} {showRightGradient && (
)}
)}
); }