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.

DocumentationTooltip.tsx 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 React from 'react';
  21. import { Link } from 'react-router';
  22. import { isWebUri } from 'valid-url';
  23. import HelpTooltip from '../../components/controls/HelpTooltip';
  24. import DetachIcon from '../../components/icons/DetachIcon';
  25. export interface DocumentationTooltipProps {
  26. children?: React.ReactNode;
  27. className?: string;
  28. content?: React.ReactNode;
  29. links?: Array<{ href: string; label: string; inPlace?: boolean }>;
  30. title?: string;
  31. }
  32. export default function DocumentationTooltip(props: DocumentationTooltipProps) {
  33. const { className, content, links, title } = props;
  34. return (
  35. <HelpTooltip
  36. className={className}
  37. overlay={
  38. <div className="big-padded-top big-padded-bottom">
  39. {title && (
  40. <div className="spacer-bottom">
  41. <strong>{title}</strong>
  42. </div>
  43. )}
  44. {content && <p>{content}</p>}
  45. {links && (
  46. <>
  47. <hr className="big-spacer-top big-spacer-bottom" />
  48. {links.map(({ href, label, inPlace }) => (
  49. <div className="little-spacer-bottom" key={label}>
  50. {inPlace ? (
  51. <Link to={href}>
  52. <span>{label}</span>
  53. </Link>
  54. ) : (
  55. <Link
  56. className="display-inline-flex-center link-with-icon"
  57. to={href}
  58. rel="noopener noreferrer"
  59. target="_blank">
  60. {isWebUri(href) && <DetachIcon size={14} className="spacer-right" />}
  61. <span>{label}</span>
  62. </Link>
  63. )}
  64. </div>
  65. ))}
  66. </>
  67. )}
  68. </div>
  69. }>
  70. {props.children}
  71. </HelpTooltip>
  72. );
  73. }