2020-03-31 22:43:32 +03:00
|
|
|
module Examples.Tooltip exposing (example, State, Msg)
|
2019-08-17 01:26:51 +03:00
|
|
|
|
|
|
|
{-|
|
|
|
|
|
2020-03-31 22:43:32 +03:00
|
|
|
@docs example, State, Msg
|
2019-08-17 01:26:51 +03:00
|
|
|
|
|
|
|
-}
|
|
|
|
|
2020-09-03 20:26:48 +03:00
|
|
|
import Accessibility.Styled as Html exposing (Html)
|
2021-11-06 00:35:09 +03:00
|
|
|
import Accessibility.Styled.Key as Key
|
2020-03-24 03:33:42 +03:00
|
|
|
import Category exposing (Category(..))
|
2022-03-18 03:30:50 +03:00
|
|
|
import CommonControls
|
2019-08-17 01:26:51 +03:00
|
|
|
import Css
|
2020-09-03 20:33:31 +03:00
|
|
|
import Debug.Control as Control exposing (Control)
|
2021-10-28 18:57:25 +03:00
|
|
|
import Debug.Control.Extra as ControlExtra
|
2022-03-18 03:25:51 +03:00
|
|
|
import Debug.Control.View as ControlView
|
2022-03-29 20:19:32 +03:00
|
|
|
import EllieLink
|
2020-03-31 23:20:03 +03:00
|
|
|
import Example exposing (Example)
|
2022-03-18 04:07:25 +03:00
|
|
|
import Html.Styled.Attributes exposing (css, href)
|
2021-05-28 04:59:03 +03:00
|
|
|
import Nri.Ui.ClickableSvg.V2 as ClickableSvg
|
2020-09-05 01:42:53 +03:00
|
|
|
import Nri.Ui.ClickableText.V3 as ClickableText
|
2019-08-17 01:26:51 +03:00
|
|
|
import Nri.Ui.Heading.V2 as Heading
|
2021-10-27 20:42:23 +03:00
|
|
|
import Nri.Ui.Text.V6 as Text
|
2022-04-26 01:42:25 +03:00
|
|
|
import Nri.Ui.Tooltip.V3 as Tooltip
|
2020-09-03 20:50:42 +03:00
|
|
|
import Nri.Ui.UiIcon.V1 as UiIcon
|
2019-08-17 01:26:51 +03:00
|
|
|
|
|
|
|
|
2022-03-23 23:24:19 +03:00
|
|
|
version : Int
|
|
|
|
version =
|
2022-04-26 01:42:25 +03:00
|
|
|
3
|
|
|
|
|
|
|
|
|
|
|
|
moduleName : String
|
|
|
|
moduleName =
|
|
|
|
"Tooltip"
|
2022-03-23 23:24:19 +03:00
|
|
|
|
|
|
|
|
2020-09-03 20:26:48 +03:00
|
|
|
example : Example State Msg
|
|
|
|
example =
|
2022-03-23 23:13:19 +03:00
|
|
|
{ name = moduleName
|
2022-03-23 23:24:19 +03:00
|
|
|
, version = version
|
2021-11-12 01:54:56 +03:00
|
|
|
, categories = [ Messaging ]
|
2020-09-03 20:26:48 +03:00
|
|
|
, keyboardSupport = []
|
|
|
|
, state = init
|
|
|
|
, update = update
|
|
|
|
, subscriptions = \_ -> Sub.none
|
2021-11-06 00:17:14 +03:00
|
|
|
, preview =
|
|
|
|
[ Html.div
|
|
|
|
[ css
|
|
|
|
[ Css.marginTop (Css.px 60)
|
|
|
|
, Css.alignSelf Css.center
|
|
|
|
]
|
|
|
|
]
|
|
|
|
[ Tooltip.view
|
|
|
|
{ id = "preview-tooltip"
|
|
|
|
, trigger =
|
|
|
|
\attributes ->
|
|
|
|
ClickableSvg.button "example-preview-tooltip-icon"
|
|
|
|
UiIcon.gear
|
|
|
|
[ ClickableSvg.custom attributes
|
|
|
|
, ClickableSvg.small
|
2021-11-06 00:35:09 +03:00
|
|
|
, ClickableSvg.custom [ Key.tabbable False ]
|
2021-11-06 00:17:14 +03:00
|
|
|
]
|
|
|
|
}
|
|
|
|
[ Tooltip.plaintext "This is a tooltip."
|
|
|
|
, Tooltip.open True
|
|
|
|
, Tooltip.onTop
|
|
|
|
, Tooltip.smallPadding
|
|
|
|
, Tooltip.fitToContent
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
2020-09-03 20:26:48 +03:00
|
|
|
, view = view
|
|
|
|
}
|
2019-08-17 01:26:51 +03:00
|
|
|
|
|
|
|
|
|
|
|
type alias State =
|
|
|
|
{ openTooltip : Maybe TooltipType
|
2022-03-18 03:48:48 +03:00
|
|
|
, staticExampleSettings : Control (List ( String, Tooltip.Attribute Never ))
|
2019-08-17 01:26:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
init : State
|
|
|
|
init =
|
2020-09-03 20:26:48 +03:00
|
|
|
{ openTooltip = Nothing
|
2020-09-03 20:33:31 +03:00
|
|
|
, staticExampleSettings = initStaticExampleSettings
|
2020-09-03 20:26:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type TooltipType
|
2020-09-05 01:02:16 +03:00
|
|
|
= PrimaryLabel
|
2020-09-03 20:26:48 +03:00
|
|
|
| AuxillaryDescription
|
2020-09-05 01:02:16 +03:00
|
|
|
| LearnMore
|
2019-08-17 01:26:51 +03:00
|
|
|
|
|
|
|
|
|
|
|
type Msg
|
|
|
|
= ToggleTooltip TooltipType Bool
|
2022-03-18 03:48:48 +03:00
|
|
|
| SetControl (Control (List ( String, Tooltip.Attribute Never )))
|
2019-08-17 01:26:51 +03:00
|
|
|
|
|
|
|
|
2020-03-31 22:43:32 +03:00
|
|
|
update : Msg -> State -> ( State, Cmd Msg )
|
2019-08-17 01:26:51 +03:00
|
|
|
update msg model =
|
|
|
|
case msg of
|
|
|
|
ToggleTooltip type_ isOpen ->
|
|
|
|
if isOpen then
|
2020-03-31 22:43:32 +03:00
|
|
|
( { model | openTooltip = Just type_ }, Cmd.none )
|
2019-08-17 01:26:51 +03:00
|
|
|
|
|
|
|
else
|
2020-03-31 22:43:32 +03:00
|
|
|
( { model | openTooltip = Nothing }, Cmd.none )
|
2019-08-17 01:26:51 +03:00
|
|
|
|
2022-03-18 03:25:51 +03:00
|
|
|
SetControl settings ->
|
2020-09-03 20:33:31 +03:00
|
|
|
( { model | staticExampleSettings = settings }, Cmd.none )
|
|
|
|
|
2019-08-17 01:26:51 +03:00
|
|
|
|
2022-03-29 20:19:32 +03:00
|
|
|
view : EllieLink.Config -> State -> List (Html Msg)
|
|
|
|
view ellieLinkConfig model =
|
2022-04-14 23:38:33 +03:00
|
|
|
[ Heading.h2 [ Heading.style Heading.Subhead ] [ Html.text "Using the Tooltip module" ]
|
2021-10-27 21:54:14 +03:00
|
|
|
, Text.mediumBody
|
|
|
|
[ Text.html
|
|
|
|
[ Html.text "Label the Tooltip as either being the "
|
|
|
|
, viewPrimaryLabelTooltip model.openTooltip
|
|
|
|
, Html.text " or the "
|
|
|
|
, viewAuxillaryDescriptionToolip model.openTooltip
|
|
|
|
, Html.text " for the trigger content."
|
|
|
|
, viewToggleTip model.openTooltip
|
|
|
|
]
|
2020-09-03 20:26:48 +03:00
|
|
|
]
|
2022-03-29 20:19:32 +03:00
|
|
|
, viewCustomizableExample ellieLinkConfig model.staticExampleSettings
|
2020-09-05 01:02:16 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
viewPrimaryLabelTooltip : Maybe TooltipType -> Html Msg
|
|
|
|
viewPrimaryLabelTooltip openTooltip =
|
|
|
|
Tooltip.view
|
|
|
|
{ id = "tooltip__primaryLabel"
|
2020-09-05 01:42:53 +03:00
|
|
|
, trigger =
|
|
|
|
\eventHandlers ->
|
|
|
|
ClickableText.button "primaryLabel"
|
|
|
|
[ ClickableText.custom eventHandlers
|
|
|
|
]
|
2020-09-03 20:26:48 +03:00
|
|
|
}
|
2020-09-05 01:02:16 +03:00
|
|
|
[ Tooltip.html
|
|
|
|
[ Html.text "A primary label is used when the tooltip content serves as the main label for its trigger content"
|
|
|
|
, Html.br []
|
|
|
|
, Html.text "e.g. when the trigger content is an icon with no text."
|
|
|
|
]
|
2020-09-03 20:26:48 +03:00
|
|
|
, Tooltip.auxillaryDescription
|
2020-09-05 01:02:16 +03:00
|
|
|
, Tooltip.onHover (ToggleTooltip PrimaryLabel)
|
|
|
|
, Tooltip.open (openTooltip == Just PrimaryLabel)
|
|
|
|
, Tooltip.onBottom
|
2020-09-03 20:26:48 +03:00
|
|
|
]
|
2020-09-05 01:02:16 +03:00
|
|
|
|
|
|
|
|
|
|
|
viewAuxillaryDescriptionToolip : Maybe TooltipType -> Html Msg
|
|
|
|
viewAuxillaryDescriptionToolip openTooltip =
|
|
|
|
Tooltip.view
|
|
|
|
{ id = "tooltip__auxillaryDescription"
|
2020-09-05 01:42:53 +03:00
|
|
|
, trigger =
|
|
|
|
\eventHandlers ->
|
|
|
|
ClickableText.button "auxillaryDescription"
|
|
|
|
[ ClickableText.custom eventHandlers
|
|
|
|
]
|
2020-09-05 01:02:16 +03:00
|
|
|
}
|
|
|
|
[ Tooltip.html
|
|
|
|
[ Html.text "An auxillary description is used when the tooltip content provides supplementary information about its trigger content"
|
|
|
|
, Html.br []
|
|
|
|
, Html.text "e.g. when the trigger content is a word in the middle of a body of text that requires additional explanation."
|
2020-09-03 20:26:48 +03:00
|
|
|
]
|
2020-09-05 01:02:16 +03:00
|
|
|
, Tooltip.auxillaryDescription
|
|
|
|
, Tooltip.onHover (ToggleTooltip AuxillaryDescription)
|
|
|
|
, Tooltip.open (openTooltip == Just AuxillaryDescription)
|
|
|
|
, Tooltip.onBottom
|
2020-09-03 20:26:48 +03:00
|
|
|
]
|
2020-09-05 01:02:16 +03:00
|
|
|
|
|
|
|
|
|
|
|
viewToggleTip : Maybe TooltipType -> Html Msg
|
|
|
|
viewToggleTip openTooltip =
|
|
|
|
Tooltip.toggleTip { label = "tooltip__learn-more" }
|
2022-04-26 02:08:30 +03:00
|
|
|
[ Tooltip.plaintext "There's also a convenient `toggleTip` helper, for when you want to add some helpful extra info."
|
2020-09-05 01:02:16 +03:00
|
|
|
, Tooltip.primaryLabel
|
|
|
|
, Tooltip.onHover (ToggleTooltip LearnMore)
|
|
|
|
, Tooltip.open (openTooltip == Just LearnMore)
|
|
|
|
, Tooltip.smallPadding
|
|
|
|
, Tooltip.fitToContent
|
2020-09-03 20:26:48 +03:00
|
|
|
]
|
2020-09-03 20:33:31 +03:00
|
|
|
|
|
|
|
|
2022-03-18 03:48:48 +03:00
|
|
|
initStaticExampleSettings : Control (List ( String, Tooltip.Attribute Never ))
|
2020-09-03 20:33:31 +03:00
|
|
|
initStaticExampleSettings =
|
2021-10-28 18:57:25 +03:00
|
|
|
ControlExtra.list
|
|
|
|
|> ControlExtra.listItem "content" controlContent
|
2022-03-18 03:35:47 +03:00
|
|
|
|> ControlExtra.optionalListItem "direction" controlDirection
|
|
|
|
|> ControlExtra.optionalListItem "alignment" controlAlignment
|
2022-03-18 03:45:16 +03:00
|
|
|
|> ControlExtra.optionalBoolListItem "withoutTail" ( "Tooltip.withoutTail", Tooltip.withoutTail )
|
2022-03-18 03:35:47 +03:00
|
|
|
|> ControlExtra.optionalListItem "width" controlWidth
|
|
|
|
|> ControlExtra.optionalListItem "padding" controlPadding
|
2020-09-03 20:50:42 +03:00
|
|
|
|
|
|
|
|
2022-03-18 03:45:16 +03:00
|
|
|
controlContent : Control ( String, Tooltip.Attribute Never )
|
2020-09-03 20:50:42 +03:00
|
|
|
controlContent =
|
2022-03-18 03:30:50 +03:00
|
|
|
CommonControls.content
|
|
|
|
{ moduleName = "Tooltip"
|
|
|
|
, plaintext = Tooltip.plaintext
|
|
|
|
, markdown = Nothing
|
|
|
|
, html = Tooltip.html
|
|
|
|
, httpError = Nothing
|
|
|
|
}
|
2020-09-03 20:33:31 +03:00
|
|
|
|
|
|
|
|
2022-03-18 03:45:16 +03:00
|
|
|
controlDirection : Control ( String, Tooltip.Attribute Never )
|
2020-09-03 20:52:46 +03:00
|
|
|
controlDirection =
|
2022-03-18 03:45:16 +03:00
|
|
|
CommonControls.choice "Tooltip"
|
|
|
|
[ ( "onTop", Tooltip.onTop )
|
|
|
|
, ( "onBottom", Tooltip.onBottom )
|
|
|
|
, ( "onLeft", Tooltip.onLeft )
|
|
|
|
, ( "onRight", Tooltip.onRight )
|
2020-09-03 20:52:46 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2022-03-18 03:45:16 +03:00
|
|
|
controlAlignment : Control ( String, Tooltip.Attribute Never )
|
2020-09-04 01:28:58 +03:00
|
|
|
controlAlignment =
|
|
|
|
Control.choice
|
2022-03-18 03:45:16 +03:00
|
|
|
[ ( "alignMiddle (default)", Control.value ( "Tooltip.alignMiddle", Tooltip.alignMiddle ) )
|
|
|
|
, ( "alignStart"
|
|
|
|
, Control.map
|
|
|
|
(\float ->
|
|
|
|
( "Tooltip.alignStart (Css.px " ++ String.fromFloat float ++ ")"
|
|
|
|
, Tooltip.alignStart (Css.px float)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
(ControlExtra.float 0)
|
|
|
|
)
|
|
|
|
, ( "alignEnd"
|
|
|
|
, Control.map
|
|
|
|
(\float ->
|
|
|
|
( "Tooltip.alignEnd (Css.px " ++ String.fromFloat float ++ ")"
|
|
|
|
, Tooltip.alignEnd (Css.px float)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
(ControlExtra.float 0)
|
|
|
|
)
|
2020-09-04 01:28:58 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2022-03-18 03:45:16 +03:00
|
|
|
controlWidth : Control ( String, Tooltip.Attribute Never )
|
2020-09-03 20:56:07 +03:00
|
|
|
controlWidth =
|
|
|
|
Control.choice
|
2022-03-18 03:45:16 +03:00
|
|
|
[ ( "exactWidth (default is 320)"
|
|
|
|
, Control.map
|
|
|
|
(\int ->
|
|
|
|
( "Tooltip.exactWidth " ++ String.fromInt int, Tooltip.exactWidth int )
|
|
|
|
)
|
|
|
|
(ControlExtra.int 320)
|
|
|
|
)
|
|
|
|
, ( "fitToContent", Control.value ( "Tooltip.fitToContent", Tooltip.fitToContent ) )
|
2020-09-03 20:56:07 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2022-03-18 03:45:16 +03:00
|
|
|
controlPadding : Control ( String, Tooltip.Attribute Never )
|
2020-09-03 20:57:55 +03:00
|
|
|
controlPadding =
|
|
|
|
Control.choice
|
2022-03-18 03:45:16 +03:00
|
|
|
[ ( "normalPadding (default)", Control.value ( "Tooltip.normalPadding", Tooltip.normalPadding ) )
|
|
|
|
, ( "smallPadding", Control.value ( "Tooltip.smallPadding", Tooltip.smallPadding ) )
|
|
|
|
, ( "customPadding"
|
|
|
|
, Control.map
|
|
|
|
(\float ->
|
|
|
|
( "Tooltip.customPadding " ++ String.fromFloat float
|
|
|
|
, Tooltip.customPadding float
|
|
|
|
)
|
|
|
|
)
|
|
|
|
(ControlExtra.float 0)
|
|
|
|
)
|
2020-09-03 20:57:55 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2022-03-29 20:19:32 +03:00
|
|
|
viewCustomizableExample : EllieLink.Config -> Control (List ( String, Tooltip.Attribute Never )) -> Html Msg
|
|
|
|
viewCustomizableExample ellieLinkConfig controlSettings =
|
2020-09-03 20:33:31 +03:00
|
|
|
Html.div []
|
2022-03-18 03:25:51 +03:00
|
|
|
[ ControlView.view
|
2022-03-29 20:19:32 +03:00
|
|
|
{ ellieLinkConfig = ellieLinkConfig
|
|
|
|
, name = moduleName
|
2022-03-23 23:24:19 +03:00
|
|
|
, version = version
|
2022-03-23 23:13:19 +03:00
|
|
|
, update = SetControl
|
2022-03-18 03:25:51 +03:00
|
|
|
, settings = controlSettings
|
2022-04-13 03:08:59 +03:00
|
|
|
, mainType = "RootHtml.Html msg"
|
2022-04-13 03:32:46 +03:00
|
|
|
, extraImports = []
|
2022-03-18 03:25:51 +03:00
|
|
|
, toExampleCode =
|
|
|
|
\controls ->
|
|
|
|
[ { sectionName = "Example"
|
|
|
|
, code =
|
|
|
|
String.join "\n"
|
|
|
|
[ "Tooltip.view"
|
|
|
|
, " { trigger ="
|
|
|
|
, " \\popupTriggerAttributes ->"
|
|
|
|
, " ClickableSvg.button \"Up\""
|
|
|
|
, " UiIcon.arrowTop"
|
|
|
|
, " [ ClickableSvg.custom popupTriggerAttributes"
|
|
|
|
, " ]"
|
|
|
|
, " , id = \"an-id-for-the-tooltip\""
|
|
|
|
, " }"
|
|
|
|
, " [ "
|
|
|
|
++ String.join "\n , "
|
2022-03-18 03:48:48 +03:00
|
|
|
("Tooltip.open True" :: List.map Tuple.first controls)
|
2022-03-18 03:25:51 +03:00
|
|
|
, " ]"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2020-09-04 01:28:58 +03:00
|
|
|
, Html.div
|
|
|
|
[ css
|
|
|
|
[ Css.displayFlex
|
|
|
|
, Css.justifyContent Css.center
|
|
|
|
, Css.alignItems Css.center
|
|
|
|
, Css.height (Css.px 300)
|
|
|
|
]
|
|
|
|
]
|
2020-09-03 20:50:42 +03:00
|
|
|
[ Tooltip.view
|
2020-09-05 01:42:53 +03:00
|
|
|
{ trigger =
|
|
|
|
\eventHandlers ->
|
2022-03-18 03:25:51 +03:00
|
|
|
ClickableSvg.button "Up"
|
2020-09-05 01:42:53 +03:00
|
|
|
UiIcon.arrowTop
|
|
|
|
[ ClickableSvg.custom eventHandlers
|
|
|
|
]
|
2022-03-18 03:25:51 +03:00
|
|
|
, id = "an-id-for-the-tooltip"
|
2020-09-03 20:50:42 +03:00
|
|
|
}
|
2022-03-18 03:48:48 +03:00
|
|
|
(Tooltip.open True
|
|
|
|
:: List.map Tuple.second (Control.currentValue controlSettings)
|
|
|
|
)
|
2020-09-03 20:50:42 +03:00
|
|
|
|> Html.map never
|
|
|
|
]
|
2020-09-03 20:33:31 +03:00
|
|
|
]
|