2019-08-17 01:26:51 +03:00
|
|
|
module Examples.Tooltip exposing (example, init, update, State, Msg)
|
|
|
|
|
|
|
|
{-|
|
|
|
|
|
|
|
|
@docs example, init, update, State, Msg
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
import Accessibility.Styled as Html
|
|
|
|
import Css
|
|
|
|
import Html.Styled.Attributes exposing (css)
|
|
|
|
import ModuleExample as ModuleExample exposing (Category(..), ModuleExample)
|
|
|
|
import Nri.Ui.Heading.V2 as Heading
|
|
|
|
import Nri.Ui.Text.V3 as Text
|
|
|
|
import Nri.Ui.Tooltip.V1 as Tooltip
|
|
|
|
|
|
|
|
|
|
|
|
type TooltipType
|
2019-09-30 22:30:12 +03:00
|
|
|
= PrimaryLabelOnClick
|
|
|
|
| PrimaryLabelOnHover
|
2019-08-17 01:26:51 +03:00
|
|
|
| AuxillaryDescription
|
2019-12-03 02:54:59 +03:00
|
|
|
| ToggleTipTop
|
|
|
|
| ToggleTipRight
|
|
|
|
| ToggleTipBottom
|
|
|
|
| ToggleTipLeft
|
2019-08-17 01:26:51 +03:00
|
|
|
|
|
|
|
|
|
|
|
type alias State =
|
|
|
|
{ openTooltip : Maybe TooltipType
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
init : State
|
|
|
|
init =
|
|
|
|
{ openTooltip = Nothing }
|
|
|
|
|
|
|
|
|
|
|
|
type Msg
|
|
|
|
= ToggleTooltip TooltipType Bool
|
|
|
|
|
|
|
|
|
|
|
|
update : Msg -> State -> State
|
|
|
|
update msg model =
|
|
|
|
case msg of
|
|
|
|
ToggleTooltip type_ isOpen ->
|
|
|
|
if isOpen then
|
|
|
|
{ model | openTooltip = Just type_ }
|
|
|
|
|
|
|
|
else
|
|
|
|
{ model | openTooltip = Nothing }
|
|
|
|
|
|
|
|
|
|
|
|
example : (Msg -> msg) -> State -> ModuleExample msg
|
|
|
|
example msg model =
|
|
|
|
{ name = "Nri.Ui.Tooltip.V1"
|
|
|
|
, category = Widgets
|
|
|
|
, content =
|
|
|
|
[ Text.mediumBody [ Html.text "These tooltips look similar, but serve different purposes when reading them via a screen-reader." ]
|
|
|
|
, Heading.h3 [] [ Html.text "primaryLabel" ]
|
2019-10-10 21:46:16 +03:00
|
|
|
, Text.smallBody
|
|
|
|
[ 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."
|
|
|
|
]
|
2019-08-17 01:26:51 +03:00
|
|
|
, Tooltip.tooltip [ Html.text "Tooltip" ]
|
|
|
|
|> Tooltip.primaryLabel
|
|
|
|
{ trigger = Tooltip.OnClick
|
2019-09-30 22:30:12 +03:00
|
|
|
, triggerHtml = Html.text "Primary Label - OnClick Trigger"
|
|
|
|
, onTrigger = ToggleTooltip PrimaryLabelOnClick >> msg
|
|
|
|
, isOpen = model.openTooltip == Just PrimaryLabelOnClick
|
|
|
|
, id = "primary label tooltip"
|
|
|
|
, extraButtonAttrs = []
|
|
|
|
}
|
|
|
|
, Html.br [ css [ Css.marginBottom (Css.px 20) ] ]
|
|
|
|
, Tooltip.tooltip [ Html.text "Tooltip" ]
|
|
|
|
|> Tooltip.primaryLabel
|
|
|
|
{ trigger = Tooltip.OnHover
|
|
|
|
, triggerHtml = Html.text "Primary Label - OnHover Trigger"
|
|
|
|
, onTrigger = ToggleTooltip PrimaryLabelOnHover >> msg
|
|
|
|
, isOpen = model.openTooltip == Just PrimaryLabelOnHover
|
2019-09-30 21:30:19 +03:00
|
|
|
, id = "primary label tooltip"
|
2019-09-30 22:26:46 +03:00
|
|
|
, extraButtonAttrs = []
|
2019-08-17 01:26:51 +03:00
|
|
|
}
|
|
|
|
, Html.br [ css [ Css.marginBottom (Css.px 20) ] ]
|
|
|
|
, Heading.h3 [] [ Html.text "auxillaryDescription" ]
|
2019-10-10 21:46:16 +03:00
|
|
|
, Text.smallBody
|
|
|
|
[ 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."
|
|
|
|
]
|
2019-08-17 01:26:51 +03:00
|
|
|
, Tooltip.tooltip [ Html.text "Tooltip" ]
|
2019-09-30 21:30:19 +03:00
|
|
|
|> Tooltip.auxillaryDescription
|
2019-08-17 01:26:51 +03:00
|
|
|
{ trigger = Tooltip.OnClick
|
|
|
|
, triggerHtml = Html.text "Auxillary Description Trigger"
|
|
|
|
, onTrigger = ToggleTooltip AuxillaryDescription >> msg
|
|
|
|
, isOpen = model.openTooltip == Just AuxillaryDescription
|
2019-09-30 21:30:19 +03:00
|
|
|
, id = "Auxillary description"
|
2019-09-30 22:26:46 +03:00
|
|
|
, extraButtonAttrs = []
|
2019-08-17 01:26:51 +03:00
|
|
|
}
|
|
|
|
, Html.br [ css [ Css.marginBottom (Css.px 20) ] ]
|
|
|
|
, Heading.h3 [] [ Html.text "toggleTip" ]
|
|
|
|
, Text.smallBody [ Html.text "A Toggle Tip is triggered by the \"?\" icon and provides supplemental information for the page." ]
|
2019-12-03 02:54:59 +03:00
|
|
|
, Tooltip.tooltip [ Html.text "Tooltip On Top" ]
|
|
|
|
|> Tooltip.toggleTip
|
|
|
|
{ onTrigger = ToggleTooltip ToggleTipTop >> msg
|
|
|
|
, isOpen = model.openTooltip == Just ToggleTipTop
|
|
|
|
, label = "More info"
|
|
|
|
, extraButtonAttrs = []
|
|
|
|
}
|
|
|
|
, Tooltip.tooltip [ Html.text "Tooltip On Left" ]
|
|
|
|
|> Tooltip.withPosition Tooltip.OnLeft
|
|
|
|
|> Tooltip.toggleTip
|
|
|
|
{ onTrigger = ToggleTooltip ToggleTipLeft >> msg
|
|
|
|
, isOpen = model.openTooltip == Just ToggleTipLeft
|
|
|
|
, label = "More info"
|
|
|
|
, extraButtonAttrs = []
|
|
|
|
}
|
|
|
|
, Tooltip.tooltip [ Html.text "Tooltip On Right" ]
|
|
|
|
|> Tooltip.withPosition Tooltip.OnRight
|
|
|
|
|> Tooltip.toggleTip
|
|
|
|
{ onTrigger = ToggleTooltip ToggleTipRight >> msg
|
|
|
|
, isOpen = model.openTooltip == Just ToggleTipRight
|
|
|
|
, label = "More info"
|
|
|
|
, extraButtonAttrs = []
|
|
|
|
}
|
|
|
|
, Tooltip.tooltip [ Html.text "Tooltip On Bottom" ]
|
|
|
|
|> Tooltip.withPosition Tooltip.OnBottom
|
2019-08-17 01:26:51 +03:00
|
|
|
|> Tooltip.toggleTip
|
2019-12-03 02:54:59 +03:00
|
|
|
{ onTrigger = ToggleTooltip ToggleTipBottom >> msg
|
|
|
|
, isOpen = model.openTooltip == Just ToggleTipBottom
|
2019-10-01 01:29:43 +03:00
|
|
|
, label = "More info"
|
2019-09-30 22:26:46 +03:00
|
|
|
, extraButtonAttrs = []
|
2019-08-17 01:26:51 +03:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|