/* * SonarQube * Copyright (C) 2009-2023 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 React from 'react'; import { theme as twTheme } from 'twin.macro'; import { BasePlacement, PopupPlacement } from '../helpers/positioning'; import { themeColor, themeContrast } from '../helpers/theme'; const SIZE = { sm: twTheme('spacing.4'), md: twTheme('spacing.6'), xl: twTheme('spacing.16'), }; type QGStatus = 'ERROR' | 'OK' | 'NONE' | 'NOT_COMPUTED'; interface Props { ariaLabel?: string; className?: string; size?: keyof typeof SIZE; status: QGStatus; tooltipPlacement?: BasePlacement; } const RX_4 = 4; const RX_2 = 2; export function QualityGateIndicator(props: Props) { const { className, size = 'md', status, tooltipPlacement = PopupPlacement.Right, ariaLabel, } = props; const iconProps = { className, height: SIZE[size], rx: size === 'xl' ? RX_4 : RX_2, size, tooltipPlacement, width: SIZE[size], }; let StatusComponent: React.ReactNode; switch (status) { case 'NONE': case 'NOT_COMPUTED': StatusComponent = ; break; case 'OK': StatusComponent = ; break; case 'ERROR': StatusComponent = ; break; } return (
{StatusComponent}
); } const COMMON_PROPS = { fill: 'none', role: 'status', xmlns: 'http://www.w3.org/2000/svg', }; interface IconProps { className?: string; height: string; rx: number; size: keyof typeof SIZE; tooltipPlacement?: BasePlacement; width: string; } function QGNotComputed({ className, rx, size, tooltipPlacement, ...sizeProps }: IconProps) { const theme = useTheme(); const contrastColor = themeContrast('qgIndicatorNotComputed')({ theme }); return ( { { xl: , md: , sm: , }[size] } ); } function QGPassed({ className, rx, size, tooltipPlacement, ...sizeProps }: IconProps) { const theme = useTheme(); const contrastColor = themeContrast('qgIndicatorPassed')({ theme }); return ( { { xl: ( <> ), md: ( <> ), sm: ( <> ), }[size] } ); } function QGFailed({ className, rx, size, tooltipPlacement, ...sizeProps }: IconProps) { const theme = useTheme(); const contrastColor = themeContrast('qgIndicatorFailed')({ theme }); return ( { { xl: ( <> ), md: ( <> ), sm: ( <> ), }[size] } ); }