You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BackButton.tsx 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import * as classNames from 'classnames';
  21. import * as React from 'react';
  22. import { translate } from '../../helpers/l10n';
  23. import { ThemeConsumer } from '../theme';
  24. import Tooltip from './Tooltip';
  25. interface Props {
  26. className?: string;
  27. disabled?: boolean;
  28. onClick: () => void;
  29. tooltip?: string;
  30. }
  31. export default class BackButton extends React.PureComponent<Props> {
  32. handleClick = (event: React.SyntheticEvent<HTMLAnchorElement>) => {
  33. event.preventDefault();
  34. event.currentTarget.blur();
  35. if (!this.props.disabled) {
  36. this.props.onClick();
  37. }
  38. };
  39. renderIcon = () => (
  40. <ThemeConsumer>
  41. {(theme) => (
  42. <svg height="24" viewBox="0 0 21 24" width="21">
  43. <path
  44. d="M3.845 12.9992l5.993 5.993.052.056c.049.061.093.122.129.191.082.159.121.339.111.518-.006.102-.028.203-.064.298-.149.39-.537.652-.954.644-.102-.002-.204-.019-.301-.052-.148-.05-.273-.135-.387-.241l-8.407-8.407 8.407-8.407.056-.052c.061-.048.121-.092.19-.128.116-.06.237-.091.366-.108.076-.004.075-.004.153-.003.155.015.3.052.437.129.088.051.169.115.239.19.246.266.33.656.214.999-.051.149-.135.273-.241.387l-5.983 5.984c5.287-.044 10.577-.206 15.859.013.073.009.091.009.163.027.187.047.359.15.49.292.075.081.136.175.18.276.044.101.072.209.081.319.032.391-.175.775-.521.962-.097.052-.202.089-.311.107-.073.012-.091.01-.165.013H3.845z"
  45. fill={this.props.disabled ? theme.colors.disableGrayText : theme.colors.secondFontColor}
  46. />
  47. </svg>
  48. )}
  49. </ThemeConsumer>
  50. );
  51. render() {
  52. const { tooltip = translate('issues.return_to_list') } = this.props;
  53. return (
  54. <Tooltip overlay={tooltip}>
  55. <a
  56. className={classNames(
  57. 'link-no-underline',
  58. { 'cursor-not-allowed': this.props.disabled },
  59. this.props.className
  60. )}
  61. href="#"
  62. onClick={this.handleClick}>
  63. {this.renderIcon()}
  64. </a>
  65. </Tooltip>
  66. );
  67. }
  68. }