custom alignment makes no sense without a tail

This commit is contained in:
Juan Edi 2021-05-20 19:17:04 -03:00
parent c760a6bc7e
commit cc3d3e4305

View File

@ -106,7 +106,6 @@ type Attribute msg
type alias Tooltip msg = type alias Tooltip msg =
{ direction : Direction { direction : Direction
, alignment : Alignment
, tail : Tail , tail : Tail
, content : List (Html msg) , content : List (Html msg)
, attributes : List (Html.Attribute Never) , attributes : List (Html.Attribute Never)
@ -127,8 +126,7 @@ buildAttributes =
defaultTooltip : Tooltip msg defaultTooltip : Tooltip msg
defaultTooltip = defaultTooltip =
{ direction = OnTop { direction = OnTop
, alignment = Middle , tail = WithTail Middle
, tail = WithTail
, content = [] , content = []
, attributes = [] , attributes = []
, containerStyles = , containerStyles =
@ -162,15 +160,10 @@ html content =
type Tail type Tail
= WithTail = WithTail Alignment
| WithoutTail | WithoutTail
withoutTail : Attribute msg
withoutTail =
Attribute (\config -> { config | tail = WithoutTail })
{-| Where should the tail be positioned relative to the tooltip? {-| Where should the tail be positioned relative to the tooltip?
-} -}
type Alignment type Alignment
@ -179,9 +172,24 @@ type Alignment
| End Px | End Px
withoutTail : Attribute msg
withoutTail =
Attribute (\config -> { config | tail = WithoutTail })
withAligment : Alignment -> Attribute msg withAligment : Alignment -> Attribute msg
withAligment alignment = withAligment alignment =
Attribute (\config -> { config | alignment = alignment }) Attribute (\config -> { config | tail = WithTail alignment })
tailAlignment : Tail -> Alignment
tailAlignment tail =
case tail of
WithTail alignment ->
alignment
WithoutTail ->
Middle
{-| Put the tail at the "start" of the tooltip. {-| Put the tail at the "start" of the tooltip.
@ -650,7 +658,7 @@ viewOpenTooltip tooltipId config =
Html.div Html.div
[ Attributes.css [ Attributes.css
[ Css.position Css.absolute [ Css.position Css.absolute
, positionTooltip config.direction config.alignment , positionTooltip config.direction (tailAlignment config.tail)
, Css.boxSizing Css.borderBox , Css.boxSizing Css.borderBox
] ]
] ]
@ -670,7 +678,7 @@ viewOpenTooltip tooltipId config =
] ]
++ config.tooltipStyleOverrides ++ config.tooltipStyleOverrides
) )
, pointerBox config.tail config.direction config.alignment , pointerBox config.tail config.direction (tailAlignment config.tail)
-- We need to keep this animation in tests to make it pass: check out -- We need to keep this animation in tests to make it pass: check out
-- the NoAnimations middleware. So if you change the name here, please -- the NoAnimations middleware. So if you change the name here, please
@ -757,7 +765,7 @@ pointerBox tail direction alignment =
, Css.border3 (Css.px 1) Css.solid Colors.navy , Css.border3 (Css.px 1) Css.solid Colors.navy
, positioning direction alignment , positioning direction alignment
, case tail of , case tail of
WithTail -> WithTail _ ->
tailForDirection direction tailForDirection direction
WithoutTail -> WithoutTail ->