/* * SonarQube * Copyright (C) 2009-2024 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import { useTheme } from '@emotion/react'; import styled from '@emotion/styled'; import React, { memo } from 'react'; import tw from 'twin.macro'; import { PopupPlacement } from '../../helpers/positioning'; import { themeColor } from '../../helpers/theme'; import { Tooltip } from '../Tooltip'; import { LineMeta } from './LineStyles'; interface Props { coverageStatus?: 'uncovered' | 'partially-covered' | 'covered'; lineNumber: number; scrollToUncoveredLine?: boolean; status: string | undefined; } function LineCoverageFunc({ lineNumber, coverageStatus, status, scrollToUncoveredLine }: Props) { const coverageMarker = React.useRef(null); React.useEffect(() => { if (scrollToUncoveredLine && coverageMarker.current) { coverageMarker.current.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'center', }); } }, [scrollToUncoveredLine, coverageMarker]); if (!coverageStatus) { return ; } return ( {coverageStatus === 'covered' && } {coverageStatus === 'uncovered' && } {coverageStatus === 'partially-covered' && } ); } export const LineCoverage = memo(LineCoverageFunc); const CoverageBlock = styled.div` ${tw`sw-w-1 sw-h-full`} ${tw`sw-ml-1/2`} &, & svg { outline: none; } `; const CoveredBlock = styled(CoverageBlock)` background-color: ${themeColor('codeLineCovered')}; `; const UncoveredBlock = styled(CoverageBlock)` background-color: ${themeColor('codeLineUncovered')}; `; function PartiallyCoveredBlock(htmlProps: React.HTMLAttributes) { const theme = useTheme(); return ( ); }