Skip to content
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

fix(CodeSnippet): use tooltip styles for feedback and add animation #4741

Merged

Conversation

emyarod
Copy link
Member

@emyarod emyarod commented Nov 21, 2019

Closes #4604

Closes #4954

ref #4711 #4715

This PR styles the code snippet and <Copy /> component to use tooltip visual style rules along with the tooltip fade animations

Testing / Reviewing

Ensure each code snippet variant looks and functions as expected

@netlify
Copy link

netlify bot commented Nov 21, 2019

Deploy preview for the-carbon-components ready!

Built with commit 8be5b17

https://deploy-preview-4741--the-carbon-components.netlify.com

@netlify
Copy link

netlify bot commented Nov 21, 2019

Deploy preview for carbon-elements ready!

Built with commit 8be5b17

https://deploy-preview-4741--carbon-elements.netlify.com

@netlify
Copy link

netlify bot commented Nov 21, 2019

Deploy preview for carbon-components-react ready!

Built with commit 8be5b17

https://deploy-preview-4741--carbon-components-react.netlify.com

Copy link
Member

@laurenmrice laurenmrice left a comment

Choose a reason for hiding this comment

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

The hover color change is not showing up on the single line and multi line code snippets in react and vanilla.

Copy link
Contributor

@asudoh asudoh left a comment

Choose a reason for hiding this comment

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

Just a couple of things - Thanks @emyarod!

packages/react/src/components/Copy/Copy.js Outdated Show resolved Hide resolved
packages/react/src/components/Copy/Copy.js Outdated Show resolved Hide resolved
@emyarod emyarod force-pushed the 4604-code-snippet-inherit-tooltip branch from 086aee1 to 8e388de Compare November 22, 2019 05:45
Copy link
Contributor

@asudoh asudoh left a comment

Choose a reason for hiding this comment

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

Thank you for your quick update @emyarod!

packages/react/src/components/Copy/Copy.js Outdated Show resolved Hide resolved
Copy link
Member

@laurenmrice laurenmrice left a comment

Choose a reason for hiding this comment

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

lgtm 👍

packages/components/src/globals/scss/_keyframes.scss Outdated Show resolved Hide resolved
packages/react/src/components/Copy/Copy.js Outdated Show resolved Hide resolved
},
[onClick, handleFadeOut]
);
const handleAnimationEnd = event => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Style-nit: use function declarations for event handlers

Copy link
Member Author

Choose a reason for hiding this comment

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

just wondering is there a reason behind this? a function declaration would be hoisted, so in that case we might as well be advocating for all function declarations to be made at the top of their scopes

Copy link
Contributor

Choose a reason for hiding this comment

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

I think at this point it's just as a style consistency point tbh, if we have hard numbers one way or another could definitely update the style guide!

Copy link
Member Author

Choose a reason for hiding this comment

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

if it isn't part of the style guide yet I think there should be a discussion about that rule. I lean more towards function expressions in these cases to avoid function hoisting

Copy link
Contributor

Choose a reason for hiding this comment

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

@emyarod it is in the style guide over in: https://github.com/carbon-design-system/carbon/blob/master/docs/style.md#writing-a-component

Feel free to bring up reasons against it in our Slack channel or a PR! We only use this style since it's what React is currently using in their official documentation and there weren't any glaring reasons to stray from it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't see anything about avoiding function expressions for event handlers in the style guide or the React documentation. can you elaborate on that?

packages/react/src/components/Copy/Copy.js Show resolved Hide resolved
packages/react/src/components/Copy/Copy.js Show resolved Hide resolved
packages/react/src/components/Copy/Copy.js Outdated Show resolved Hide resolved
packages/react/src/components/Copy/Copy.js Outdated Show resolved Hide resolved
[`${prefix}--copy-btn--animating`]: animation,
[`${prefix}--copy-btn--${animation}`]: animation,
});
const handleFadeOut = useCallback(
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense for this work to be in an effect parameterized by animation changing? Something like:

useEffect(() => {
  if (animation !== 'fade-in') {
    return;
  }

  const timeoutId = window.setTimeout(() => {
    setAnimation('fade-out');
  }, [feedbackTimeout]);

  return () => {
    window.clearTimeout(timeoutId);
  };
}, [animation, feedbackTimeout]);

Copy link
Member Author

Choose a reason for hiding this comment

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

does this eliminate our debouncing then? I moved towards using debounce to eliminate the need for managing timers and refs

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, is handleFadeOut called multiple time which is why we need debounce here?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah the tooltip needs to persist if the button is clicked again and should fade out after the timeout expires for the most recent click of the button. with useEffect all clicks following the first click are ignored until the tooltip fades out (based on the timeout from the very first click). so we debounce the click and fadeout handlers because they can fire multiple times

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, this seems like a use-case we could achieve with useEffect, right? What would make the clicks become ignored? It seemed like on click we want to update the animation state and then enqueue a timeout, cancelling it if the button is clicked and creating a new one. Is there something else that I'm missing here? 👀

Copy link
Member Author

Choose a reason for hiding this comment

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

if the timeout management occurs in useEffect doesn't that require another render? patching with useEffect results in clearTimeout firing after the timeout has already completed

gif

@emyarod emyarod force-pushed the 4604-code-snippet-inherit-tooltip branch from 69298b8 to fb6c6fa Compare November 25, 2019 09:18
Copy link
Contributor

@asudoh asudoh left a comment

Choose a reason for hiding this comment

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

LGTM 👍 - Thanks @emyarod!

Copy link
Contributor

@aledavila aledavila left a comment

Choose a reason for hiding this comment

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

lgtm

@stale
Copy link

stale bot commented Jan 4, 2020

We've marked this issue as stale because there hasn't been any activity for a couple of weeks. If there's no further activity on this issue in the next three days then we'll close it. You can keep the conversation going with just a short comment. Thanks for your contributions.

@stale stale bot added the status: inactive Will close if there's no further activity within a given time label Jan 4, 2020
@asudoh asudoh removed the status: inactive Will close if there's no further activity within a given time label Jan 6, 2020
@emyarod emyarod force-pushed the 4604-code-snippet-inherit-tooltip branch 2 times, most recently from 8692aa9 to c449668 Compare January 7, 2020 15:48
@emyarod emyarod force-pushed the 4604-code-snippet-inherit-tooltip branch from 9d6d9da to a84ee82 Compare January 7, 2020 23:12
@emyarod emyarod force-pushed the 4604-code-snippet-inherit-tooltip branch from a84ee82 to 273a241 Compare January 8, 2020 00:24
@asudoh asudoh dismissed joshblack’s stale review January 8, 2020 00:24

Resetting the review status as all review comments seem to have been addressed.

@asudoh asudoh merged commit 83a7cf2 into carbon-design-system:master Jan 9, 2020
@joshblack
Copy link
Contributor

joshblack commented Jan 10, 2020

@asudoh Please confirm if review comments have been addressed before dismissing a review. The most recent comments were from 2 days ago when the previous interaction was a month back and I had not had a chance to respond yet. Feel free to reach out on Slack in our squad channel 👍

@asudoh
Copy link
Contributor

asudoh commented Jan 10, 2020

I expect responses to review comments are treated as request for re-reviews, and expect that reviewers respond in timely manner. Otherwise reviews are seen as stale.

@vpicone
Copy link
Contributor

vpicone commented Jan 15, 2020

@joshblack @asudoh i think clicking the “request re-review” button should count as requesting a re-review.

We all get a lot of notifications, missing a single reply shouldn’t count as an implicit approval.

@asudoh
Copy link
Contributor

asudoh commented Jan 15, 2020

I read through all notifications of this repo.

@alisonjoseph
Copy link
Member

Just wanted to quickly jump in here and say that yes we should all be timely in reviewing and responding to PRs/comments, but we should also feel empowered to reach out on slack and poke someone if it seems they’ve missed something. (especially around the holidays when notifications could easily get missed) 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants