Add stimulus tooltip controller #1065
Reference in New Issue
Block a user
Delete Branch "1051-add-stimulus-tooltip-controller"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Close #1051
https://github.com/user-attachments/assets/594f5a08-0591-4678-bc15-24587bc914c6
Awesome work here, looks great and well organized! Just left a few comments around Popper and some of its global styling.
Would the components layer be a better spot for this?
https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes
I think we'd be okay with what you have given you're not using any Tailwind classes, but I usually throw these types of things in the components layer so we can use modifiers like
hover:with the custom styles.@@ -46,3 +46,7 @@ pin "d3-zoom" # @3.0.0pin "delaunator" # @5.0.1Is there a reason you chose PopperJS over the newer
@floating-uipackage? I've found it to be a bit more lightweight and more predictable in some projects I've implemented it with.https://floating-ui.com/docs/motivation
@@ -0,0 +22,4 @@endfind("body").clickassert find("#tooltip", visible: false)endNice!
@@ -46,3 +46,7 @@ pin "d3-zoom" # @3.0.0pin "delaunator" # @5.0.1Done in 158007e
Done in 1d4ab25
Thanks for the update with the Floating UI, looks good.
Once the notes are addressed on the Stimulus controller I think we'll be good to merge.
@@ -0,0 +1,74 @@import { Controller } from '@hotwired/stimulus'With Stimulus we can provide default values for the value targets, which would allow us to remove this method and replace the option variables with the targets.
Here and in
showTooltip, we're callingtooltipas a global variable. This works because there is an element in the DOM with an id oftooltip, but creates a tight coupling between the view and this controller. We'll eventually need to support multiple tooltips on the same page, so this will break when we do that.I think we should use
this.tooltipTargethere for stability moving forwardWe can remove
elementfrom this targets array. By default, Stimulus controllers set thethis.elementproperty which we can use.Furthermore, I think we should introduce
arrowas a target here. We're heavily depending on the arrow to have anidofarrowwhich will have to be extracted when we start introducing multiple tooltips per page.So the effect of these changes would be:
Think we can remove this method. When the controller disconnects it should wipe out any tooltip content.
@@ -0,0 +1,26 @@<%# locals: (account:) -%>@@ -52,7 +52,12 @@<div class="bg-white shadow-xs rounded-xl border border-alpha-black-25 rounded-lg">@@ -0,0 +1,74 @@import { Controller } from '@hotwired/stimulus'03344a2
@@ -0,0 +1,74 @@import { Controller } from '@hotwired/stimulus'62fd745
@@ -0,0 +1,74 @@import { Controller } from '@hotwired/stimulus'79f6ab0
@@ -0,0 +1,74 @@import { Controller } from '@hotwired/stimulus'32ed87a
Awesome!