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

feat: migrate Tooltip component #801

Merged
merged 15 commits into from
Jan 25, 2022
Merged

feat: migrate Tooltip component #801

merged 15 commits into from
Jan 25, 2022

Conversation

jinlee93
Copy link
Contributor

@jinlee93 jinlee93 commented Jan 21, 2022

Summary:

[sc-169594]

Copies over Tooltip from traject EDSCandidates.
Converts to Typescript and CSF storybook format.

Test Plan:

  • Stories match traject stories
  • Publish alpha release 0.5.1-alpha.2 for Traject testing
    • left window local storybook with alpha release, right window main
HorizontalBar.mov
RecommendedStatusTag.mov

@shortcut-integration
Copy link

This pull request has been linked to Shortcut Story #169594: Tooltip: move to EDS.

@@ -0,0 +1,88 @@
/* stylelint-disable selector-pseudo-class-no-unknown */
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Better way via stylelintrc? Or would this be the only file with :global use?

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 this is fine. 🤷

Or would this be the only file with :global use?

My guess is that we'll eventually end up doing it again as we start building on top of other components that are not from Headless UI and require us to dig in and target a specific element that's not exposed to us. But I don't have any specific examples; it's just a feeling.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, I think we can add to stylelint when we have to get across that bridge

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

size-limit report

Path Size
components 65.39 KB (+1.82% 🔺)
styles 4.39 KB (+0.34% 🔺)

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

size-limit report

Path Size
components 65.41 KB (+1.85% 🔺)
styles 4.39 KB (+0.34% 🔺)

@codecov
Copy link

codecov bot commented Jan 22, 2022

Codecov Report

Merging #801 (966f690) into main (55181ec) will increase coverage by 0.03%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #801      +/-   ##
==========================================
+ Coverage   95.80%   95.83%   +0.03%     
==========================================
  Files         130      132       +2     
  Lines         905      937      +32     
  Branches      121      125       +4     
==========================================
+ Hits          867      898      +31     
- Misses         38       39       +1     
Impacted Files Coverage Δ
src/Tooltip/Tooltip.stories.tsx 100.00% <0.00%> (ø)
src/Tooltip/Tooltip.tsx 92.85% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 55181ec...966f690. Read the comment docs.

* stored in state or a ref. Most cases will use `children` and not
* `reference`.
*/
reference?: React.RefObject<Element> | Element;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was React.Node in traject, but React.ReactNode not compatible with TippyProp's reference: React.RefObject<Element> | Element | null.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

size-limit report

Path Size
components 65.4 KB (+1.84% 🔺)
styles 4.39 KB (+0.34% 🔺)

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

size-limit report

Path Size
components 65.4 KB (+1.84% 🔺)
styles 4.44 KB (+1.46% 🔺)

@jinlee93 jinlee93 force-pushed the jlee/moveTooltipToEDS branch from c965493 to 686fe82 Compare January 22, 2022 02:15
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

size-limit report

Path Size
components 65.4 KB (+1.84% 🔺)
styles 4.44 KB (+1.52% 🔺)

@jinlee93
Copy link
Contributor Author

All storybook styling changes were made to avoid issues Chromatic snaps cut off the tooltip, e.g.:
Screen Shot 2022-01-21 at 6 23 33 PM
Screen Shot 2022-01-21 at 6 23 13 PM

This happens because Chromatic snaps element <div id="root"> and Tippy mounts the tooltip in document.body, a sibling element

@jinlee93 jinlee93 requested a review from a team January 22, 2022 02:28
Comment on lines 107 to 118
exports[`<Tooltip /> Interactive story renders snapshot 1`] = `
<body>
<div>
<button
class="mx-32 my-32 button sizeLarge variantFlat colorBrand"
type="button"
>
Tooltip trigger
</button>
</div>
</body>
`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, I just realized that the Interactive story isn't producing a useful snapshot because it's originally closed. I added it for manual interactive testing, so I feel like we should just tell this story to not make a snapshot. But I can also see the argument that we could use this story to verify that the tooltip does appear on hover or focus by adding a test that makes it appear on hover or focus and getting the snapshot. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm, I'll mess around with the play function to see if I can get a meaningful snapshot while keeping it interactive, but if too much of a struggle, I can "unsnap" this

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good 👍

@jinlee93 jinlee93 marked this pull request as ready for review January 24, 2022 16:58
Comment on lines 23 to 36
argTypes: {
variant: {
control: {
type: "select",
options: ["light", "dark"],
},
},
placement: {
control: {
type: "radio",
options: ["left", "right", "top", "bottom"],
},
},
},
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 you don't need these in this repo. Try taking them out and see if you still see the controls on the first story on the docs tab.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohh you are right, removed

export const LightVariant: StoryObj<Args> = {};

export const DarkVariant: StoryObj<Args> = {
...LightVariant,
Copy link
Contributor

Choose a reason for hiding this comment

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

What does using the LightVariant here do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not much, oops, removed from all the stories

Comment on lines 15 to 17
* Use this instead of `children` if the trigger element is being
* stored in state or a ref. Most cases will use `children` and not
* `reference`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice prop doc!

Did the idea/reference/wording for storing an element in state come from us or from Tippy?

For my own knowledge, I'm curious as to the intended use case. Ref makes sense, but storing an element in state isn't usually necessary (and according to my own mental pattern matching would still work with children anyway).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Think @dierat deserves all the praise for the work, I'm just migrating to EDS haha. Any thought's on Andrew's question?

Copy link
Contributor

@dierat dierat Jan 24, 2022

Choose a reason for hiding this comment

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

I don't remember exactly where "state" came from here; I'm fine with dropping it. This is where we're currently using reference in the platform (and why we added this documentation): https://github.com/FB-PLP/traject/blob/7ab73ba57ce427d8d9b82ec587d89e6bd8121e8d/app/assets/javascripts/v2/teachers/schoolData/components/MetricCard/HorizontalBar.jsx#L171

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. I say lets drop reference to state.

Copy link
Contributor

@ahuth ahuth left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +99 to +100
const trigger = await screen.findByRole("button");
await userEvent.hover(trigger);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

Comment on lines 88 to 89
Tooltip trigger with hover done by storybook. <br />
Click within canvas to make interactive.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this specific to this repo? I don't have to click into the canvas in traject to get the hover to work. (You do need to have focus on that browser window though.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The story loads and immediately hovers the button to spawn to the tooltip, so it doesn't look interactive. Have to click to despawn the tooltip created by the play function.

How should I word this to make such message come across?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see. So you have to click to dismiss the tooltip, and then you can hover over it?

Copy link
Contributor Author

@jinlee93 jinlee93 Jan 24, 2022

Choose a reason for hiding this comment

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

Yup. Hovering and after hover of the button also despawns it, but basically have to interact with it a little

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 this is fine as-is, but I'll throw out a suggestion for your consideration.

I'm wondering if non-devs will understand the "canvas" part here, so I was thinking you could move the text out of the button and change it to "Click somewhere in this area to dismiss the tooltip, then hover over the button to make it reappear." and then you could change the button text to something like "Hover here to see tooltip after clicking somewhere outside".

I'm probably overthinking this, so don't spend too much time dwelling on it. Thanks for figuring out how to make this story work! ❤️

Copy link
Contributor

@ahuth ahuth Jan 25, 2022

Choose a reason for hiding this comment

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

Great point 👍

I think devs will probably be confused by this as well, since (I believe) "canvas" here refers to the Storybook "canvas" (basically the div element the story is rendered into, which excludes the Storybook UI), not an actual HTML canvas.

Most folks probably won't be that familiar with that terminology.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated story as advised, thanks!

@jinlee93 jinlee93 force-pushed the jlee/moveTooltipToEDS branch from 9d4e1b6 to 7aa5bab Compare January 25, 2022 22:43
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

size-limit report

Path Size
components 65.42 KB (+1.86% 🔺)
styles 4.44 KB (+1.52% 🔺)

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

size-limit report

Path Size
components 65.42 KB (+1.86% 🔺)
styles 4.44 KB (+1.52% 🔺)

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

size-limit report

Path Size
components 65.42 KB (+1.86% 🔺)
styles 4.44 KB (+1.52% 🔺)

@jinlee93 jinlee93 merged commit 9b68ee3 into main Jan 25, 2022
@jinlee93 jinlee93 deleted the jlee/moveTooltipToEDS branch January 25, 2022 23:07
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.

3 participants