/* * 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 classNames from 'classnames'; import * as React from 'react'; import { colors } from '../../app/theme'; import ChevronRightIcon from '../icons/ChevronRightIcon'; import ClearIcon, { ClearIconProps } from '../icons/ClearIcon'; import DeleteIcon from '../icons/DeleteIcon'; import EditIcon from '../icons/EditIcon'; import { IconProps } from '../icons/Icon'; import './buttons.css'; import Tooltip, { TooltipProps } from './Tooltip'; type AllowedButtonAttributes = Pick< React.ButtonHTMLAttributes, | 'aria-label' | 'className' | 'disabled' | 'id' | 'style' | 'title' | 'onFocus' | 'onBlur' | 'onMouseOver' | 'onMouseLeave' | 'tabIndex' | 'role' >; interface ButtonProps extends AllowedButtonAttributes { autoFocus?: boolean; children?: React.ReactNode; innerRef?: React.Ref; name?: string; onClick?: () => void; preventDefault?: boolean; stopPropagation?: boolean; type?: 'button' | 'submit' | 'reset'; } export class Button extends React.PureComponent { handleClick = (event: React.MouseEvent) => { const { disabled, onClick, preventDefault = true, stopPropagation = false } = this.props; if (preventDefault || disabled) { event.preventDefault(); } if (stopPropagation) { event.stopPropagation(); } if (onClick && !disabled) { onClick(); } }; render() { const { className, disabled, innerRef, onClick, preventDefault, stopPropagation, type = 'button', ...props } = this.props; // Instead of undoing button style we simply not apply the class. const isPlain = className && className.indexOf('button-plain') !== -1; return ( ); }