-
Notifications
You must be signed in to change notification settings - Fork 4
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
Conversation
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 */ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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% 🔺) |
There was a problem hiding this 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 Report
@@ 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
Continue to review full report at Codecov.
|
This reverts commit 81680a5.
* stored in state or a ref. Most cases will use `children` and not | ||
* `reference`. | ||
*/ | ||
reference?: React.RefObject<Element> | Element; |
There was a problem hiding this comment.
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
.
There was a problem hiding this 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% 🔺) |
There was a problem hiding this 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% 🔺) |
c965493
to
686fe82
Compare
There was a problem hiding this 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% 🔺) |
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> | ||
`; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good 👍
argTypes: { | ||
variant: { | ||
control: { | ||
type: "select", | ||
options: ["light", "dark"], | ||
}, | ||
}, | ||
placement: { | ||
control: { | ||
type: "radio", | ||
options: ["left", "right", "top", "bottom"], | ||
}, | ||
}, | ||
}, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
* 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`. |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
const trigger = await screen.findByRole("button"); | ||
await userEvent.hover(trigger); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Tooltip trigger with hover done by storybook. <br /> | ||
Click within canvas to make interactive. |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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! ❤️
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
9d4e1b6
to
7aa5bab
Compare
There was a problem hiding this 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% 🔺) |
There was a problem hiding this 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% 🔺) |
There was a problem hiding this 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% 🔺) |
Summary:
[sc-169594]
Copies over Tooltip from traject EDSCandidates.
Converts to Typescript and CSF storybook format.
Test Plan:
HorizontalBar.mov
RecommendedStatusTag.mov