Skip to content

Add Tooltip component #360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2018
Merged

Add Tooltip component #360

merged 1 commit into from
Jun 25, 2018

Conversation

kevva
Copy link
Contributor

@kevva kevva commented Jun 14, 2018

  • Add margin to the tooltip
  • Add styles to the arrow for other positions than top
  • Fine tune styles (maybe some border and shadow)
  • Add animation while fading in (from top and down)

kapture 2018-06-14 at 15 29 59

For #175

@kevva kevva requested review from sindresorhus and lukechilds June 14, 2018 13:39
}
}

export default Tooltip;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add prop-types too? I've been too lazy to do this on the other components, but in hindsight, I should have.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I didn't because no other components had it. Will add!

&__arrow {
position: absolute;
width: 16px;
height: 24px;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will make these variables.

@kevva kevva changed the title WIP: Add Tooltip component [WIP]: Add Tooltip component Jun 20, 2018
<Manager>
<Reference>
{({ref}) => (
<div
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really bothers me that we have to wrap the children in a div since it won't wrap elements with absolute position correctly. I'd really like to be able to pass a ref to children directly. React.forwardRef() only works for components.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's kinda cool. Doesn't seem to work though. See the screenshot below (don't mind the positioning of the elements inside the seed phrase box, it's just for testing):

screen shot 2018-06-21 at 16 28 56

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it's only available in Chrome 65, but Electron 2 is at 61. We'll be able to use this when Electron 3 is stable. #374

Copy link
Contributor Author

@kevva kevva Jun 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the flag to blinkFeatures, but it didn't work regardless, i.e. instead of getting the wrong position it got no position at all (which the screenshot shows).

@@ -5,43 +5,67 @@ import ReloadButton from 'components/ReloadButton';
import CopyButton from 'components/CopyButton';
Copy link
Contributor Author

@kevva kevva Jun 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to rewrite this file to use flex inside generated-seed-phrase-container because we currently can't use absolutely positioned targets for our tooltips. flex is nicer than using position: absolute anyway :).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better! No idea why I didn't use flexbox in the first place...

@kevva
Copy link
Contributor Author

kevva commented Jun 21, 2018

@sindresorhus, tried to, but didn't come up with any nice border or shadows. Does the animation look good though? Also, should the content animation be in this component or should we pass another component that animates the text as content prop? Depends on how magical we want to make the tooltip.

kapture 2018-06-21 at 2 32 10

@sindresorhus
Copy link
Contributor

tried to, but didn't come up with any nice border or shadows.

I think it needs something so it doesn't bleed into the background. Try with a slight shadow.

Does the animation look good though?

The animation looks good.

Also, should the content animation be in this component or should we pass another component that animates the text as content prop? Depends on how magical we want to make the tooltip.

What you have now is good. We don't need that kind of manual control.

@sindresorhus
Copy link
Contributor

@kevva I noticed that if I hover over the copy button, the click, then take my mouse somewhere else and then hover again, it still shows Copied!. I think it should revert back to the initial value when it's being hidden.

return (
<button
{...props}
type="button"
className={`${className} CopyButton`}
onClick={() => {
onClick={e => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e => event

@@ -0,0 +1,109 @@
.Tooltip {
--color: var(--border-color);
--arrow-height: 8px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make this 7px. It feels a tad bit too tall with 8px.

<Manager>
<Reference>
{({ref}) => (
<div
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -5,43 +5,67 @@ import ReloadButton from 'components/ReloadButton';
import CopyButton from 'components/CopyButton';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better! No idea why I didn't use flexbox in the first place...

class CreatePortfolioStep2 extends React.Component {
state = {
isCopied: false,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, check out https://github.com/hyperdexapp/hyperdex/blob/7d996b46533bc965409f53150b9b037731bc040c/app/renderer/containers/SuperContainer.js#L63-L74 It lets us add state to functional components. No more class mess when you only need a little bit of state.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet. Didn't notice that!

package.json Outdated
"qrcode.react": "^0.8.0",
"randoma": "^1.2.0",
"react": "^16.3.2",
"react-dom": "^16.3.2",
"react-extras": "^0.6.0",
"react-popper": "1.0.0-beta.6",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.0.0 final is out

@kevva
Copy link
Contributor Author

kevva commented Jun 22, 2018

Added a slight shadow to it:

screen shot 2018-06-22 at 11 16 05

@kevva I noticed that if I hover over the copy button, the click, then take my mouse somewhere else and then hover again, it still shows Copied!. I think it should revert back to the initial value when it's being hidden.

Should be fixed. Added an onClose handler to it to reset the state.

@kevva kevva changed the title [WIP]: Add Tooltip component Add Tooltip component Jun 22, 2018
<div
ref={arrowProps.ref}
className="Tooltip__arrow"
style={arrowProps.style}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would've wanted to put these into styled-jsx too, but that'd require converting them to a CSS string. Decided not to bother with it.

@sindresorhus sindresorhus merged commit 5167d76 into master Jun 25, 2018
@sindresorhus
Copy link
Contributor

This looks and works perfectly now. Nice work Kevin :)

@sindresorhus sindresorhus deleted the tooltips branch June 25, 2018 04:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants