From cf89624747b0544b8147991f0c5c245e24d13437 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Fri, 27 Jan 2023 11:05:57 +0200 Subject: [PATCH] docs: fixed mobile usability of tooltips (#3124) --- www/docs/package.json | 1 + www/docs/src/css/_code.css | 4 ++ www/docs/src/css/_tooltip.css | 52 +++++-------------- www/docs/src/css/_variables.css | 3 ++ .../src/theme/CodeBlock/Content/String.js | 2 +- www/docs/src/theme/CopyButton/index.js | 13 +++-- www/docs/src/theme/Tooltip/index.js | 30 ++++++----- www/docs/yarn.lock | 32 +++++++++++- 8 files changed, 81 insertions(+), 56 deletions(-) diff --git a/www/docs/package.json b/www/docs/package.json index 5f35efa9f1..70ecb285ca 100644 --- a/www/docs/package.json +++ b/www/docs/package.json @@ -31,6 +31,7 @@ "prism-react-renderer": "^1.3.1", "react": "^17.0.1", "react-dom": "^17.0.1", + "react-tooltip": "^5.7.0", "react-transition-group": "^4.4.5", "react-uuid": "^2.0.0", "redocusaurus": "^1.4.0", diff --git a/www/docs/src/css/_code.css b/www/docs/src/css/_code.css index 04d104721f..5e36501b68 100644 --- a/www/docs/src/css/_code.css +++ b/www/docs/src/css/_code.css @@ -98,6 +98,10 @@ html[data-theme="dark"] .docusaurus-highlight-code-line { border-radius: var(--ifm-code-border-radius); } +.code-action-copy { + display: flex; +} + .code-action { background-color: transparent; border: none; diff --git a/www/docs/src/css/_tooltip.css b/www/docs/src/css/_tooltip.css index 35c6ab9e95..5dd33d6f99 100644 --- a/www/docs/src/css/_tooltip.css +++ b/www/docs/src/css/_tooltip.css @@ -1,45 +1,19 @@ -.tooltip-container { - position: relative; +.react-tooltip { + border: 1px solid var(--ifm-tooltip-border-color) !important; + border-radius: 8px !important; + font-size: 12px !important; + font-weight: 500 !important; + line-height: 20px !important; + box-shadow: 0px 2px 16px var(--ifm-tooltip-box-shadow-color) !important; + padding: 8px 16px !important; } -.tooltip-box { - position: absolute; - top: calc(-100% - 17px); - z-index: 100000; - padding: 8px 16px; - max-width: 170px; - width: max-content; - text-align: center; - - background-color: var(--ifm-tooltip-background-color); - border: 1px solid var(--ifm-tooltip-border-color); - border-radius: 8px; - color: var(--ifm-color-content); - font-size: 12px; - font-weight: 500; - line-height: 20px; - box-shadow: 0px 2px 16px var(--ifm-tooltip-box-shadow-color); - - opacity: 0; - transition: all .1s; -} - -.tooltip-box:not(.visible) { +.react-tooltip-arrow { display: none; } -.tooltip-box.visible { - opacity: 1; -} - -.inline-tooltip { - display: inline-block; -} - -.tooltip-container:not(.inline-tooltip) .tooltip-box { - left: calc(-50% - 30px); -} - -.inline-tooltip .tooltip-box { - left: 0; +@media screen and (max-width: 875px) { + .react-tooltip { + display: none; + } } \ No newline at end of file diff --git a/www/docs/src/css/_variables.css b/www/docs/src/css/_variables.css index 01c1bfe1a4..57a9045c70 100644 --- a/www/docs/src/css/_variables.css +++ b/www/docs/src/css/_variables.css @@ -95,6 +95,9 @@ --ifm-tooltip-background-color: #fff; --ifm-tooltip-border-color: #E5E7EB; --ifm-tooltip-box-shadow-color: rgba(17, 24, 39, 0.08); + --rt-opacity: 1 !important; + --rt-color-dark: var(--ifm-tooltip-background-color) !important; + --rt-color-white: var(--ifm-color-content) !important; /* Buttons */ --ifm-primary-btn-background-color: #fff; diff --git a/www/docs/src/theme/CodeBlock/Content/String.js b/www/docs/src/theme/CodeBlock/Content/String.js index 48e918776e..5b6799793d 100644 --- a/www/docs/src/theme/CodeBlock/Content/String.js +++ b/www/docs/src/theme/CodeBlock/Content/String.js @@ -103,7 +103,7 @@ export default function CodeBlockString({ )} {!noCopy && ( - + () => window.clearTimeout(copyTimeout.current), []); return ( - - + ) } \ No newline at end of file diff --git a/www/docs/src/theme/Tooltip/index.js b/www/docs/src/theme/Tooltip/index.js index 8445a36f4b..4d8c6f2015 100644 --- a/www/docs/src/theme/Tooltip/index.js +++ b/www/docs/src/theme/Tooltip/index.js @@ -1,20 +1,26 @@ -import React from 'react'; +import React, { useState, useEffect } from 'react'; +import { Tooltip as ReactTooltip } from 'react-tooltip' +import uuid from 'react-uuid'; +import 'react-tooltip/dist/react-tooltip.css' -export default function Tooltip ({ children, text, tooltipClassName, ...rest }) { - const [show, setShow] = React.useState(false); +export default function Tooltip ({ children, text, tooltipClassName }) { + const [elementId, setElementId] = useState(null) + + useEffect(() => { + if (!elementId) { + setElementId(uuid()) + } + }, [elementId]) return ( - - - {text} - - setShow(true)} - onMouseLeave={() => setShow(false)} - {...rest} + <> + {children} - + + ); }; \ No newline at end of file diff --git a/www/docs/yarn.lock b/www/docs/yarn.lock index 3090bd6535..d02a2472a9 100644 --- a/www/docs/yarn.lock +++ b/www/docs/yarn.lock @@ -2574,6 +2574,22 @@ __metadata: languageName: node linkType: hard +"@floating-ui/core@npm:^1.0.5": + version: 1.1.0 + resolution: "@floating-ui/core@npm:1.1.0" + checksum: 427c95953f99c58647c3eee50d75770fddc19416cea152403010527135e8c88479352a8cbb4aeb09949cf283522861d815bf77dff5207b64dc8dd3b623bf57a3 + languageName: node + linkType: hard + +"@floating-ui/dom@npm:^1.0.4": + version: 1.1.0 + resolution: "@floating-ui/dom@npm:1.1.0" + dependencies: + "@floating-ui/core": ^1.0.5 + checksum: 8cae2d59f32bce8d742a414477ee62854affbcb7ae318598adebadec36d43c01dccaf5004d73a9dd26683d393bb69fb1e8181970b8d7939f529512ab1ad672d2 + languageName: node + linkType: hard + "@gar/promisify@npm:^1.1.3": version: 1.1.3 resolution: "@gar/promisify@npm:1.1.3" @@ -4641,7 +4657,7 @@ __metadata: languageName: node linkType: hard -"classnames@npm:^2.3.1": +"classnames@npm:^2.3.1, classnames@npm:^2.3.2": version: 2.3.2 resolution: "classnames@npm:2.3.2" checksum: cd50ead57b4f97436aaa9f9885c6926323efc7c2bea8e3d4eb10e4e972aa6a1cfca1c7a0e06f8a199ca7498d4339e30bb6002e589e61c9f21248cbf3e8b0b18d @@ -5527,6 +5543,7 @@ __metadata: prism-react-renderer: ^1.3.1 react: ^17.0.1 react-dom: ^17.0.1 + react-tooltip: ^5.7.0 react-transition-group: ^4.4.5 react-uuid: ^2.0.0 redocusaurus: ^1.4.0 @@ -9878,6 +9895,19 @@ __metadata: languageName: node linkType: hard +"react-tooltip@npm:^5.7.0": + version: 5.7.0 + resolution: "react-tooltip@npm:5.7.0" + dependencies: + "@floating-ui/dom": ^1.0.4 + classnames: ^2.3.2 + peerDependencies: + react: ">=16.14.0" + react-dom: ">=16.14.0" + checksum: b9bbf50fe227ef478d98512f075b5dabc02f020256dcb825a36b8b7aa905764ce838f0dc382ca7f16279ab99327f8106fc38c14e619db07d937a5f0c37bc83fe + languageName: node + linkType: hard + "react-transition-group@npm:^4.4.5": version: 4.4.5 resolution: "react-transition-group@npm:4.4.5"