A Tooltip -> Element Msg -> Element Msg
is useless, as you will only be able to pass elements from the Tooltip
module itself.
I dont know what Tooltip
is, but you may want instead something like Tooltip -> (Tooltip.Msg -> msg) -> Element msg -> Element msg
, so that any element can be passed to it.
The Tooltip.Msg -> msg
function could be also added to the Tooltip
record (which is most likely some kind of configuration).
And the Tooltip.update
would be called in your Main
.
That’s why I said:
It does not feel right to want to use a Main
element in another module. Most likely you want it the other way: wrap the other element in your Main
using Element.map
and why I gave you a link explaining the -> msg
function pattern.
But for a tooltip, having a dedicated state and msg seems really overkill to me.
Here is a tooltip trick with elm-ui
that does not use any state nor message:
https://ellie-app.com/7bxvQpSMtLwa1
module Main exposing (main)
import Element exposing (..)
import Element.Background as Background
import Element.Border as Border
import Element.Font as Font
import Html exposing (Html)
import Html.Attributes
main : Html msg
main =
layout [ width fill, height fill ] <|
el
[ centerX
, centerY
, tooltip "tooltip"
]
(text "hello")
tooltip : String -> Attribute msg
tooltip str =
inFront <|
el
[ width fill
, height fill
, transparent True
, mouseOver [ transparent False ]
, above (tooltipHelp str)
]
none
tooltipHelp : String -> Element msg
tooltipHelp str =
el
[ Background.color (rgb 0 0 0)
, Font.color (rgb 1 1 1)
, padding 4
, Border.rounded 5
, Font.size 14
, Border.shadow
{ offset = ( 0, 3 ), blur = 6, size = 0, color = rgba 0 0 0 0.32 }
, htmlAttribute (Html.Attributes.style "pointerEvents" "none")
]
(text str)
which could be generalized with:
tooltip : Element Never -> Attribute msg
tooltip element =
inFront <|
el
[ width fill
, height fill
, transparent True
, mouseOver [ transparent False ]
, (above << Element.map never) <|
el [ htmlAttribute (Html.Attributes.style "pointerEvents" "none") ]
element
]
none
and using the Element.move*
functions to move the tooltip farther if wanted.
PS: If you want to let the user choose the position of the tooltip, you can even have:
tooltip : (Element msg -> Attribute msg) -> Element Never -> Attribute msg
tooltip usher tooltip =
inFront <|
el
[ width fill
, height fill
, transparent True
, mouseOver [ transparent False ]
, (usher << Element.map never) <|
el [ htmlAttribute (Html.Attributes.style "pointerEvents" "none") ]
tooltip
]
none
Then for example tooltip Element.above (Element.text "tooltip)
:
https://ellie-app.com/7byf7QFGMVza1.