Skip to content

Commit

Permalink
tooltip abre no click
Browse files Browse the repository at this point in the history
  • Loading branch information
wkiane committed Oct 15, 2019
1 parent 4e332c6 commit 903052d
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 33 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
"netlify-cli": "^1.2.3",
"prop-types": "^15.5.4",
"query-string": "5",
"react": "^16.4.0",
"react": "^16.7.0",
"react-avatar-editor": "^11.0.4",
"react-credit-cards": "^0.7.0",
"react-dom": "^16.4.0",
"react-dom": "^16.7.0",
"react-dropzone": "^4.2.13",
"react-helmet": "^5.2.0",
"react-input-mask": "^2.0.4",
Expand Down
4 changes: 4 additions & 0 deletions src/questionnaires/list/renderQuestion.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.button-tip {
padding: 0;
margin: 0;
}
81 changes: 60 additions & 21 deletions src/questionnaires/list/renderQuestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,73 @@ import FormGroup from '@material-ui/core/FormGroup'
import FormControl from '@material-ui/core/FormControl'
import RadioGroup from '@material-ui/core/RadioGroup'
import Typography from '@material-ui/core/Typography'
import Button from '@material-ui/core/Button'
import HelperIcon from '@material-ui/icons/Help'
import Tooltip from '@material-ui/core/Tooltip'
import ClickAwayListener from '@material-ui/core/ClickAwayListener'

import renderOption from './renderOption'
import findAnswer from './findAnswer'
import findOption from './findOption'

const HelperText = ({ helperText }) =>
!!helperText && (
<Media query="(min-width: 991px)">
{matches =>
matches ? (
<Tooltip title={helperText}>
<HelperIcon
color="primary"
style={{
margin: '0px 0 -3px 6px',
fontSize: '18px',
}}
/>
</Tooltip>
) : (
<Typography variant="caption" style={{ color: '#757575' }}>
{helperText}
</Typography>
)
}
</Media>
const HelperText = ({ helperText }) => {
const [open, setOpen] = React.useState(false)
const [title, setTitle] = React.useState(null)

const handleTooltipClose = () => {
setOpen(false)
}

const handleTooltipOpen = () => {
if (open) {
setOpen(false)
setTimeout(() => {
setTitle(null)
}, 100)
} else {
setTitle(helperText)
setOpen(true)
}
}

return (
!!helperText && (
<Media query="(min-width: 991px)">
{matches =>
matches ? (
<ClickAwayListener onClickAway={handleTooltipClose}>
<Tooltip
PopperProps={{
disablePortal: true,
}}
onClose={handleTooltipClose}
open={open}
disableFocusListener
disableHoverListener
disableTouchListener
title={title}
>
<span className="button-tip" onClick={handleTooltipOpen}>
<HelperIcon
color="primary"
style={{
margin: '0px 0 -3px 6px',
fontSize: '18px',
}}
/>
</span>
</Tooltip>
</ClickAwayListener>
) : (
<Typography variant="caption" style={{ color: '#757575' }}>
{helperText}
</Typography>
)
}
</Media>
)
)
}

export default props => question => {
const { options, description, helperText } = question
Expand Down
55 changes: 45 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4667,6 +4667,11 @@ js-tokens@^3.0.0, js-tokens@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"

"js-tokens@^3.0.0 || ^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==

js-yaml@^3.4.3, js-yaml@^3.7.0, js-yaml@^3.9.1:
version "3.11.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.11.0.tgz#597c1a8bd57152f26d622ce4117851a51f5ebaef"
Expand Down Expand Up @@ -5036,6 +5041,13 @@ loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.2.0, loose-envify@^1.3
dependencies:
js-tokens "^3.0.0"

loose-envify@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
dependencies:
js-tokens "^3.0.0 || ^4.0.0"

loud-rejection@^1.0.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/loud-rejection/-/loud-rejection-1.6.0.tgz#5b46f80147edee578870f086d04821cf998e551f"
Expand Down Expand Up @@ -6318,6 +6330,15 @@ prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.8, prop-types@^15.6.0,
loose-envify "^1.3.1"
object-assign "^4.1.1"

prop-types@^15.6.2:
version "15.7.2"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
dependencies:
loose-envify "^1.4.0"
object-assign "^4.1.1"
react-is "^16.8.1"

proxy-addr@~2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-2.0.3.tgz#355f262505a621646b3130a728eb647e22055341"
Expand Down Expand Up @@ -6486,14 +6507,15 @@ react-dev-utils@^5.0.1:
strip-ansi "3.0.1"
text-table "0.2.0"

react-dom@^16.4.0:
version "16.4.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.4.0.tgz#099f067dd5827ce36a29eaf9a6cdc7cbf6216b1e"
react-dom@^16.7.0:
version "16.10.2"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.10.2.tgz#4840bce5409176bc3a1f2bd8cb10b92db452fda6"
integrity sha512-kWGDcH3ItJK4+6Pl9DZB16BXYAZyrYQItU4OMy0jAkv5aNqc+mAKb4TpFtAteI6TJZu+9ZlNhaeNQSVQDHJzkw==
dependencies:
fbjs "^0.8.16"
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.0"
prop-types "^15.6.2"
scheduler "^0.16.2"

react-dropzone@^4.2.13:
version "4.2.13"
Expand Down Expand Up @@ -6538,6 +6560,11 @@ react-is@^16.4.0:
version "16.4.0"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.4.0.tgz#cc9fdc855ac34d2e7d9d2eb7059bbc240d35ffcf"

react-is@^16.8.1:
version "16.10.2"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.10.2.tgz#984120fd4d16800e9a738208ab1fba422d23b5ab"
integrity sha512-INBT1QEgtcCCgvccr5/86CfD71fw9EPmDxgiJX4I2Ddr6ZsV6iFXsuby+qWJPtmNuMY0zByTsG4468P7nHuNWA==

react-lifecycles-compat@^3.0.2, react-lifecycles-compat@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"
Expand Down Expand Up @@ -6681,14 +6708,14 @@ react-waypoint@^8.0.3:
consolidated-events "^1.1.0 || ^2.0.0"
prop-types "^15.0.0"

react@^16.4.0:
version "16.4.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.4.0.tgz#402c2db83335336fba1962c08b98c6272617d585"
react@^16.7.0:
version "16.10.2"
resolved "https://registry.yarnpkg.com/react/-/react-16.10.2.tgz#a5ede5cdd5c536f745173c8da47bda64797a4cf0"
integrity sha512-MFVIq0DpIhrHFyqLU0S3+4dIcBhhOvBE8bJ/5kHPVOVaGdo0KuiQzpcjCPsf585WvhypqtrMILyoE2th6dT+Lw==
dependencies:
fbjs "^0.8.16"
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.0"
prop-types "^15.6.2"

read-all-stream@^3.0.0:
version "3.1.0"
Expand Down Expand Up @@ -7184,6 +7211,14 @@ sax@>=0.6.0, sax@^1.2.1, sax@^1.2.4, sax@~1.2.1:
version "1.2.4"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"

scheduler@^0.16.2:
version "0.16.2"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.16.2.tgz#f74cd9d33eff6fc554edfb79864868e4819132c1"
integrity sha512-BqYVWqwz6s1wZMhjFvLfVR5WXP7ZY32M/wYPo04CcuPM7XZEbV2TBNW7Z0UkguPTl0dWMA59VbNXxK6q+pHItg==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"

schema-utils@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-0.3.0.tgz#f5877222ce3e931edae039f17eb3716e7137f8cf"
Expand Down

0 comments on commit 903052d

Please sign in to comment.