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.

LineFinding.tsx 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2023 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 styled from '@emotion/styled';
  21. import { forwardRef, Ref } from 'react';
  22. import tw from 'twin.macro';
  23. import { themeBorder, themeColor, themeContrast, themeShadow } from '../../helpers/theme';
  24. import { BareButton } from '../buttons';
  25. interface Props {
  26. className?: string;
  27. issueKey: string;
  28. message: React.ReactNode;
  29. onIssueSelect?: (issueKey: string) => void;
  30. selected?: boolean;
  31. }
  32. function LineFindingFunc(
  33. { message, issueKey, selected = true, className, onIssueSelect }: Props,
  34. ref: Ref<HTMLButtonElement>,
  35. ) {
  36. return (
  37. <LineFindingStyled
  38. className={className}
  39. data-issue={issueKey}
  40. onClick={() => {
  41. if (onIssueSelect) {
  42. onIssueSelect(issueKey);
  43. }
  44. }}
  45. ref={ref}
  46. selected={selected}
  47. >
  48. {message}
  49. </LineFindingStyled>
  50. );
  51. }
  52. export const LineFinding = forwardRef<HTMLElement, Props>(LineFindingFunc);
  53. const LineFindingStyled = styled(BareButton)<{ selected: boolean }>`
  54. ${tw`sw-flex sw-gap-2 sw-items-center`}
  55. ${tw`sw-my-3 sw-mx-1`}
  56. ${tw`sw-p-3`}
  57. ${tw`sw-body-md-highlight`}
  58. ${tw`sw-rounded-1`}
  59. ${tw`sw-w-full`}
  60. ${tw`sw-box-border`}
  61. border: ${(props) =>
  62. props.selected
  63. ? themeBorder('default', 'issueBoxSelectedBorder')
  64. : themeBorder('default', 'issueBoxBorder')};
  65. color: ${themeContrast('pageBlock')};
  66. font-weight: ${(props) => (props.selected ? 600 : 400)};
  67. word-break: break-word;
  68. background-color: ${themeColor('pageBlock')};
  69. :hover {
  70. box-shadow: ${themeShadow('sm')};
  71. }
  72. `;