2020-03-31 22:43:32 +03:00
|
|
|
module Examples.ClickableText exposing (Msg, State, example)
|
2019-02-15 21:51:19 +03:00
|
|
|
|
2019-03-28 22:47:20 +03:00
|
|
|
{-|
|
|
|
|
|
2020-03-31 22:43:32 +03:00
|
|
|
@docs Msg, State, example
|
2019-03-28 22:47:20 +03:00
|
|
|
|
2019-02-15 21:51:19 +03:00
|
|
|
-}
|
|
|
|
|
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-05 01:49:45 +03:00
|
|
|
import CommonControls
|
2019-02-15 21:51:19 +03:00
|
|
|
import Css exposing (middle, verticalAlign)
|
|
|
|
import Debug.Control as Control exposing (Control)
|
2022-03-05 01:49:45 +03:00
|
|
|
import Debug.Control.Extra as ControlExtra
|
|
|
|
import Debug.Control.View as ControlView
|
2020-03-31 23:20:03 +03:00
|
|
|
import Example exposing (Example)
|
2019-02-15 21:51:19 +03:00
|
|
|
import Html.Styled exposing (..)
|
|
|
|
import Html.Styled.Attributes exposing (css, id)
|
2020-06-20 00:45:32 +03:00
|
|
|
import KeyboardSupport exposing (Direction(..), Key(..))
|
2019-07-30 22:13:09 +03:00
|
|
|
import Nri.Ui.ClickableText.V3 as ClickableText
|
2019-10-24 20:49:49 +03:00
|
|
|
import Nri.Ui.Svg.V1 as Svg exposing (Svg)
|
2021-10-27 20:42:23 +03:00
|
|
|
import Nri.Ui.Text.V6 as Text
|
2019-10-24 20:49:49 +03:00
|
|
|
import Nri.Ui.UiIcon.V1 as UiIcon
|
2019-02-15 21:51:19 +03:00
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
2020-03-31 23:20:03 +03:00
|
|
|
example : Example State Msg
|
2020-03-31 22:43:32 +03:00
|
|
|
example =
|
2020-09-09 21:43:10 +03:00
|
|
|
{ name = "ClickableText"
|
|
|
|
, version = 3
|
2020-03-31 22:43:32 +03:00
|
|
|
, state = init
|
|
|
|
, update = update
|
2020-03-31 22:48:26 +03:00
|
|
|
, subscriptions = \_ -> Sub.none
|
2021-11-05 22:16:52 +03:00
|
|
|
, preview =
|
|
|
|
[ ClickableText.link "Small"
|
|
|
|
[ ClickableText.icon UiIcon.link
|
|
|
|
, ClickableText.small
|
2021-11-06 00:35:09 +03:00
|
|
|
, ClickableText.custom [ Key.tabbable False ]
|
2021-11-05 22:16:52 +03:00
|
|
|
]
|
|
|
|
, ClickableText.link "Medium"
|
|
|
|
[ ClickableText.icon UiIcon.link
|
|
|
|
, ClickableText.medium
|
2021-11-06 00:35:09 +03:00
|
|
|
, ClickableText.custom [ Key.tabbable False ]
|
2021-11-05 22:16:52 +03:00
|
|
|
]
|
|
|
|
, ClickableText.link "Large"
|
|
|
|
[ ClickableText.icon UiIcon.link
|
|
|
|
, ClickableText.large
|
2021-11-06 00:35:09 +03:00
|
|
|
, ClickableText.custom [ Key.tabbable False ]
|
2021-11-05 22:16:52 +03:00
|
|
|
]
|
|
|
|
]
|
2020-03-31 22:43:32 +03:00
|
|
|
, view = \state -> [ viewExamples state ]
|
|
|
|
, categories = [ Buttons ]
|
2020-06-20 00:45:32 +03:00
|
|
|
, keyboardSupport = []
|
2019-02-15 21:51:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-05 01:49:45 +03:00
|
|
|
{-| -}
|
|
|
|
type State
|
|
|
|
= State (Control (Settings Msg))
|
|
|
|
|
|
|
|
|
2019-02-15 21:51:19 +03:00
|
|
|
{-| -}
|
2019-10-24 20:49:49 +03:00
|
|
|
init : State
|
|
|
|
init =
|
2022-03-05 01:49:45 +03:00
|
|
|
Control.record Settings
|
2019-02-16 01:33:26 +03:00
|
|
|
|> Control.field "label" (Control.string "Clickable Text")
|
2022-03-05 01:49:45 +03:00
|
|
|
|> Control.field "attributes"
|
|
|
|
(ControlExtra.list
|
|
|
|
|> ControlExtra.optionalListItemDefaultChecked "icon"
|
|
|
|
(Control.map (\( name, icon ) -> ClickableText.icon icon)
|
|
|
|
CommonControls.uiIcon
|
|
|
|
)
|
2019-02-15 21:51:19 +03:00
|
|
|
)
|
|
|
|
|> State
|
|
|
|
|
|
|
|
|
2022-03-05 01:49:45 +03:00
|
|
|
type alias Settings msg =
|
|
|
|
{ label : String
|
|
|
|
, attributes : List (ClickableText.Attribute msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-31 22:43:32 +03:00
|
|
|
{-| -}
|
|
|
|
type Msg
|
2022-03-05 01:49:45 +03:00
|
|
|
= SetState (Control (Settings Msg))
|
2020-03-31 22:43:32 +03:00
|
|
|
| ShowItWorked String String
|
|
|
|
|
|
|
|
|
2019-02-15 21:51:19 +03:00
|
|
|
{-| -}
|
|
|
|
update : Msg -> State -> ( State, Cmd Msg )
|
|
|
|
update msg state =
|
|
|
|
case msg of
|
2022-03-05 01:49:45 +03:00
|
|
|
SetState controls ->
|
|
|
|
( State controls, Cmd.none )
|
2019-02-15 21:51:19 +03:00
|
|
|
|
2020-03-31 22:43:32 +03:00
|
|
|
ShowItWorked group message ->
|
|
|
|
let
|
|
|
|
_ =
|
|
|
|
Debug.log group message
|
|
|
|
in
|
|
|
|
( state, Cmd.none )
|
|
|
|
|
2019-02-15 21:51:19 +03:00
|
|
|
|
|
|
|
|
|
|
|
-- INTERNAL
|
|
|
|
|
|
|
|
|
2020-03-31 22:43:32 +03:00
|
|
|
viewExamples : State -> Html Msg
|
|
|
|
viewExamples (State control) =
|
2019-02-15 21:51:19 +03:00
|
|
|
let
|
2022-03-05 01:49:45 +03:00
|
|
|
settings =
|
2019-02-15 21:51:19 +03:00
|
|
|
Control.currentValue control
|
|
|
|
in
|
2022-03-05 01:49:45 +03:00
|
|
|
[ Control.view SetState control
|
2019-02-15 21:51:19 +03:00
|
|
|
|> fromUnstyled
|
2022-03-05 01:49:45 +03:00
|
|
|
, buttons settings
|
2021-10-27 21:54:14 +03:00
|
|
|
, Text.smallBody
|
|
|
|
[ Text.html
|
|
|
|
[ text "Sometimes, we'll want our clickable links: "
|
2022-03-05 01:49:45 +03:00
|
|
|
, ClickableText.link settings.label
|
|
|
|
(ClickableText.small :: settings.attributes)
|
2021-10-27 21:54:14 +03:00
|
|
|
, text " and clickable buttons: "
|
2022-03-05 01:49:45 +03:00
|
|
|
, ClickableText.button settings.label
|
|
|
|
(ClickableText.small
|
|
|
|
:: ClickableText.onClick (ShowItWorked "ClickableText" "in-line button")
|
|
|
|
:: settings.attributes
|
|
|
|
)
|
2021-10-27 21:54:14 +03:00
|
|
|
, text " to show up in-line."
|
2019-07-30 22:28:35 +03:00
|
|
|
]
|
2019-03-28 22:47:20 +03:00
|
|
|
]
|
2019-02-15 21:51:19 +03:00
|
|
|
]
|
|
|
|
|> div []
|
|
|
|
|
|
|
|
|
2019-07-30 22:13:09 +03:00
|
|
|
sizes : List ( ClickableText.Attribute msg, String )
|
2019-02-15 21:51:19 +03:00
|
|
|
sizes =
|
2019-07-30 22:13:09 +03:00
|
|
|
[ ( ClickableText.small, "small" )
|
|
|
|
, ( ClickableText.medium, "medium" )
|
|
|
|
, ( ClickableText.large, "large" )
|
2019-02-15 21:51:19 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2022-03-05 01:49:45 +03:00
|
|
|
buttons : Settings Msg -> Html Msg
|
|
|
|
buttons settings =
|
2019-02-15 21:51:19 +03:00
|
|
|
let
|
2019-07-30 22:28:35 +03:00
|
|
|
sizeRow label render =
|
|
|
|
row label (List.map render sizes)
|
2019-02-15 21:51:19 +03:00
|
|
|
in
|
2019-07-30 22:28:35 +03:00
|
|
|
table []
|
|
|
|
[ sizeRow "" (\( size, sizeLabel ) -> th [] [ text sizeLabel ])
|
|
|
|
, sizeRow ".link"
|
|
|
|
(\( size, sizeLabel ) ->
|
2022-03-05 01:49:45 +03:00
|
|
|
ClickableText.link settings.label
|
|
|
|
(size :: settings.attributes)
|
2019-07-30 22:28:35 +03:00
|
|
|
|> exampleCell
|
|
|
|
)
|
|
|
|
, sizeRow ".button"
|
|
|
|
(\( size, sizeLabel ) ->
|
2022-03-05 01:49:45 +03:00
|
|
|
ClickableText.button settings.label
|
|
|
|
(size
|
|
|
|
:: ClickableText.onClick (ShowItWorked "ClickableText" sizeLabel)
|
|
|
|
:: settings.attributes
|
|
|
|
)
|
2019-07-30 22:28:35 +03:00
|
|
|
|> exampleCell
|
|
|
|
)
|
|
|
|
]
|
2019-03-28 22:47:20 +03:00
|
|
|
|
|
|
|
|
2019-07-30 22:28:35 +03:00
|
|
|
row : String -> List (Html msg) -> Html msg
|
|
|
|
row label tds =
|
|
|
|
tr [] (th [] [ td [] [ text label ] ] :: tds)
|
2019-07-30 22:13:09 +03:00
|
|
|
|
|
|
|
|
2019-07-30 22:28:35 +03:00
|
|
|
exampleCell : Html msg -> Html msg
|
|
|
|
exampleCell view =
|
|
|
|
td [ css [ verticalAlign middle, Css.width (Css.px 200) ] ] [ view ]
|