DocsHelper.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import React, { Component, useState } from "react";
  2. import styled, { createGlobalStyle } from "styled-components";
  3. import Button from "@material-ui/core/Button";
  4. import Tooltip from "@material-ui/core/Tooltip";
  5. import { ClickAwayListener, TooltipProps } from "@material-ui/core";
  6. type Props = {
  7. tooltipText: string;
  8. link: string;
  9. };
  10. const DocsHelper: React.FC<Props> = ({ tooltipText, link }) => {
  11. const [open, setOpen] = React.useState(false);
  12. const handleTooltipClose = () => {
  13. setOpen(false);
  14. };
  15. const handleTooltipOpen = () => {
  16. setOpen(true);
  17. };
  18. const handleTooltipToggle = () => {
  19. setOpen(!open);
  20. };
  21. return (
  22. <DocsHelperContainer>
  23. <ClickAwayListener
  24. onClickAway={() => {
  25. handleTooltipClose();
  26. }}
  27. >
  28. <div>
  29. <Tooltip
  30. PopperProps={{
  31. disablePortal: true,
  32. placement: "top-end",
  33. }}
  34. onClose={handleTooltipClose}
  35. open={open}
  36. interactive
  37. disableFocusListener
  38. disableHoverListener
  39. disableTouchListener
  40. title={
  41. <StyledContent onClick={handleTooltipOpen}>
  42. {tooltipText}
  43. <A target="_blank" href={link}>
  44. Documentation {">"}
  45. </A>
  46. </StyledContent>
  47. }
  48. >
  49. <HelperButton onClick={handleTooltipToggle}>
  50. <i className="material-icons">help_outline</i>
  51. </HelperButton>
  52. </Tooltip>
  53. </div>
  54. </ClickAwayListener>
  55. <TooltipStyle />
  56. </DocsHelperContainer>
  57. );
  58. };
  59. export default DocsHelper;
  60. const StyledContent = styled.div`
  61. font-family: "Work Sans", sans-serif;
  62. font-size: 12px;
  63. font-weight: normal;
  64. padding: 12px 14px;
  65. line-height: 1.5em;
  66. user-select: text;
  67. width: calc(100% + 14px);
  68. height: calc(100% + 10px);
  69. margin-left: -7px;
  70. height: 100%;
  71. background: #2e3135;
  72. border: 1px solid #aaaabb;
  73. border-radius: 5px;
  74. `;
  75. const HelperButton = styled.div`
  76. cursor: pointer;
  77. display: flex;
  78. align-items: center;
  79. margin-left: 10px;
  80. justify-content: center;
  81. > i {
  82. color: #aaaabb;
  83. width: 24px;
  84. height: 24px;
  85. font-size: 20px;
  86. border-radius: 20px;
  87. }
  88. `;
  89. const TooltipStyle = createGlobalStyle`
  90. .MuiTooltip-tooltip {
  91. background-color: #00000000 !important;
  92. font-size: 12px !important;
  93. padding: 0px;
  94. max-width: 300px !important;
  95. }
  96. `;
  97. const A = styled.a`
  98. display: inline-block;
  99. height: 20px;
  100. color: #8590ff;
  101. text-decoration: underline;
  102. cursor: pointer;
  103. width: 100%;
  104. text-align: right;
  105. user-select: none;
  106. `;
  107. const DocsHelperContainer = styled.div`
  108. margin-left: auto;
  109. `;