noredink-ui/styleguide-app/Examples/Tooltip.elm

145 lines
5.4 KiB
Elm
Raw Normal View History

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
-}
import Accessibility.Styled as Html
import Category exposing (Category(..))
2019-08-17 01:26:51 +03:00
import Css
2020-03-31 23:20:03 +03:00
import Example exposing (Example)
2019-12-03 03:13:14 +03:00
import Html.Styled.Attributes exposing (css, href)
2019-08-17 01:26:51 +03:00
import Nri.Ui.Heading.V2 as Heading
2019-12-03 21:43:24 +03:00
import Nri.Ui.Text.V4 as Text
2019-08-17 01:26:51 +03:00
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
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
2020-03-31 23:20:03 +03:00
example : Example State Msg
2020-03-31 22:43:32 +03:00
example =
2019-08-17 01:26:51 +03:00
{ name = "Nri.Ui.Tooltip.V1"
2020-03-31 22:43:32 +03:00
, categories = [ Widgets ]
, state = init
, update = update
2020-03-31 22:48:26 +03:00
, subscriptions = \_ -> Sub.none
2020-03-31 22:43:32 +03:00
, view =
\model ->
[ Text.mediumBody [ Html.text "These tooltips look similar, but serve different purposes when reading them via a screen-reader." ]
, Heading.h3 [] [ Html.text "primaryLabel" ]
, 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-12-03 21:43:24 +03:00
]
2020-03-31 22:43:32 +03:00
, Tooltip.tooltip [ Html.text "Tooltip" ]
|> Tooltip.primaryLabel
{ trigger = Tooltip.OnClick
, triggerHtml = Html.text "Primary Label - OnClick Trigger"
, onTrigger = ToggleTooltip PrimaryLabelOnClick
, isOpen = model.openTooltip == Just PrimaryLabelOnClick
, id = "primary label tooltip"
2019-12-03 21:43:24 +03:00
, extraButtonAttrs = []
}
2020-03-31 22:43:32 +03:00
, 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
, isOpen = model.openTooltip == Just PrimaryLabelOnHover
, id = "primary label tooltip"
, extraButtonAttrs = []
}
, Html.br [ css [ Css.marginBottom (Css.px 20) ] ]
, Heading.h3 [] [ Html.text "auxillaryDescription" ]
, 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-12-03 21:43:24 +03:00
]
2020-03-31 22:43:32 +03:00
, Tooltip.tooltip [ Html.text "Tooltip" ]
|> Tooltip.auxillaryDescription
{ trigger = Tooltip.OnClick
, triggerHtml = Html.text "Auxillary Description Trigger"
, onTrigger = ToggleTooltip AuxillaryDescription
, isOpen = model.openTooltip == Just AuxillaryDescription
, id = "Auxillary description"
2019-12-03 21:43:24 +03:00
, extraButtonAttrs = []
}
2020-03-31 22:43:32 +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." ]
, Html.div [ css [ Css.displayFlex, Css.alignItems Css.center ] ]
[ Tooltip.tooltip
[ Html.text "Tooltip On Top! "
, Html.a
[ href "/" ]
[ Html.text "Links work!" ]
]
|> Tooltip.toggleTip
{ onTrigger = ToggleTooltip ToggleTipTop
, isOpen = model.openTooltip == Just ToggleTipTop
, label = "More info"
, extraButtonAttrs = []
}
, Text.mediumBody
[ Html.text "This toggletip will open on top"
]
]
, Html.div [ css [ Css.displayFlex, Css.alignItems Css.center ] ]
[ Tooltip.tooltip
[ Html.text "Tooltip On Left! "
, Html.a
[ href "/" ]
[ Html.text "Links work!" ]
]
|> Tooltip.withPosition Tooltip.OnLeft
|> Tooltip.toggleTip
{ onTrigger = ToggleTooltip ToggleTipLeft
, isOpen = model.openTooltip == Just ToggleTipLeft
, label = "More info"
, extraButtonAttrs = []
}
, Text.mediumBody
[ Html.text "This toggletip will open on the left"
]
2019-12-03 21:43:24 +03:00
]
2019-12-03 03:13:14 +03:00
]
2019-08-17 01:26:51 +03:00
}