yuanqing / create-figma-plugin

:battery: The comprehensive toolkit for developing plugins and widgets for Figma and FigJam
https://yuanqing.github.io/create-figma-plugin/
MIT License
948 stars 91 forks source link

Tooltip component #65

Open saeedalipoor opened 3 years ago

saeedalipoor commented 3 years ago

I think This would be how the tooltip component can be used:

<Tooltip delay={1000} position="bottom" anchor={anchorRef}>
  Line height
</Tooltop>

or

<Tooltip delay={1000} position="bottom" content="Line height">
  /* tooltip trigger */
  <Button />
</Tooltip>

Also, Textbox components would be much more usable if tooltip properties could be passed to them.

<TextboxNumeric tooltipProps={{content: 'Line height', position: 'bottom'}} icon={<Icon />} />

Little detail about the delay: Figma tooltips behavior
While Figma's tooltips are active, other tooltips will appear immediately if you move the cursor over the anchors

A feature that keeps tooltips in the viewport while the anchor is visible would also be great.

yuanqing commented 3 years ago

@saeedalipoor I think this would be quite useful for some plugins, and it would bring the UI library even closer to Figma’s native UI.

However, the desired UX seems decidedly non-trivial to implement. A big challenge I see is how to not bloat the bundle when the component consumer chooses to not use the tooltip feature 🤔

saeedalipoor commented 3 years ago

We can ignore the idea of tooltip properties to keep the bundle lighter and just have the tooltip component that can wrap any node as an anchor point.

hikariNTU commented 2 years ago

There are some existing library handle the Tooltip part, namely the popper.js and it's relative project. Tippy.js, Floating UI best suite the Figma behavior.

But as @yuanqing said, these feature include extraneous dependencies, around 5~10KB gzip size.

As a developer I might want to handle tooltip by myself.

And if the overflow issue is not a concern, css-tooltip on data attribute might be enough for simple tooltip title.

Should this library bundle an existing solution or providing some hand-made Component?

ben-katz commented 2 years ago

Do we know how native Figma tooltips are coded? From some googling it seems like creating custom tooltips with React Portals is pretty straightforward and wouldn't require any external libs.

jcusick93 commented 1 year ago

Any updates on this? I'd love to use a tooltip

yuanqing commented 1 year ago

An interim workaround is to just add a title attribute

how to not bloat the bundle when the component consumer chooses to not use the tooltip feature

One solution to not bloat the bundle is to require the use of a Provider component at the root