2019-02-16 01:33:26 +03:00
|
|
|
module Examples.ClickableText exposing (Msg, State, example, init, update)
|
2019-02-15 21:51:19 +03:00
|
|
|
|
|
|
|
{- \
|
|
|
|
@docs Msg, State, example, init, update,
|
|
|
|
-}
|
|
|
|
|
|
|
|
import Css exposing (middle, verticalAlign)
|
|
|
|
import Debug.Control as Control exposing (Control)
|
|
|
|
import Headings
|
|
|
|
import Html.Styled exposing (..)
|
|
|
|
import Html.Styled.Attributes exposing (css, id)
|
|
|
|
import ModuleExample as ModuleExample exposing (Category(..), ModuleExample, ModuleMessages)
|
|
|
|
import Nri.Ui.AssetPath exposing (Asset)
|
2019-03-28 22:13:40 +03:00
|
|
|
import Nri.Ui.ClickableText.V2 as ClickableText exposing (Size(..))
|
2019-02-15 21:51:19 +03:00
|
|
|
import Nri.Ui.Icon.V4 as Icon
|
|
|
|
import Nri.Ui.Text.V2 as Text
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type Msg
|
|
|
|
= SetState State
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type State
|
|
|
|
= State (Control Model)
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type ButtonType
|
|
|
|
= Button
|
|
|
|
| Link
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
example :
|
2019-03-28 22:16:51 +03:00
|
|
|
(String -> ModuleMessages Msg parentMsg)
|
2019-02-15 21:51:19 +03:00
|
|
|
-> State
|
|
|
|
-> ModuleExample parentMsg
|
2019-03-28 22:16:51 +03:00
|
|
|
example unnamedMessages state =
|
2019-02-15 21:51:19 +03:00
|
|
|
let
|
|
|
|
messages =
|
2019-02-16 01:33:26 +03:00
|
|
|
unnamedMessages "ClickableTextExample"
|
2019-02-15 21:51:19 +03:00
|
|
|
in
|
2019-02-16 01:33:26 +03:00
|
|
|
{ filename = "Nri.Ui.ClickableText.V1"
|
2019-02-15 21:51:19 +03:00
|
|
|
, category = Buttons
|
|
|
|
, content =
|
2019-03-28 22:16:51 +03:00
|
|
|
[ viewExamples messages state ]
|
2019-02-15 21:51:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
init : { r | performance : String, lock : String } -> State
|
|
|
|
init assets =
|
|
|
|
Control.record Model
|
2019-02-16 01:33:26 +03:00
|
|
|
|> Control.field "label" (Control.string "Clickable Text")
|
2019-02-15 21:51:19 +03:00
|
|
|
|> Control.field "icon"
|
|
|
|
(Control.maybe False <|
|
|
|
|
Control.choice
|
|
|
|
( "Performance", Control.value (Icon.performance assets) )
|
|
|
|
[ ( "Lock", Control.value (Icon.lock assets) )
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|> Control.field "button type"
|
|
|
|
(Control.choice
|
2019-02-16 01:33:26 +03:00
|
|
|
( "Nri.Ui.ClickableText.V1.button", Control.value Button )
|
|
|
|
[ ( "Nri.Ui.ClickableText.V1.link", Control.value Link )
|
2019-02-15 21:51:19 +03:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|> State
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
update : Msg -> State -> ( State, Cmd Msg )
|
|
|
|
update msg state =
|
|
|
|
case msg of
|
|
|
|
SetState newState ->
|
|
|
|
( newState, Cmd.none )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- INTERNAL
|
|
|
|
|
|
|
|
|
|
|
|
type alias Model =
|
|
|
|
{ label : String
|
|
|
|
, icon : Maybe Icon.IconType
|
|
|
|
, buttonType : ButtonType
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
viewExamples :
|
2019-03-28 22:16:51 +03:00
|
|
|
ModuleMessages Msg parentMsg
|
2019-02-15 21:51:19 +03:00
|
|
|
-> State
|
|
|
|
-> Html parentMsg
|
2019-03-28 22:16:51 +03:00
|
|
|
viewExamples messages (State control) =
|
2019-02-15 21:51:19 +03:00
|
|
|
let
|
|
|
|
model =
|
|
|
|
Control.currentValue control
|
|
|
|
in
|
|
|
|
[ Control.view (State >> SetState >> messages.wrapper) control
|
|
|
|
|> fromUnstyled
|
2019-03-28 22:16:51 +03:00
|
|
|
, buttons messages model
|
2019-02-15 21:51:19 +03:00
|
|
|
]
|
|
|
|
|> div []
|
|
|
|
|
|
|
|
|
|
|
|
sizes : List Size
|
|
|
|
sizes =
|
|
|
|
[ Small
|
|
|
|
, Medium
|
|
|
|
, Large
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
buttons :
|
2019-03-28 22:16:51 +03:00
|
|
|
ModuleMessages Msg parentMsg
|
2019-02-15 21:51:19 +03:00
|
|
|
-> Model
|
|
|
|
-> Html parentMsg
|
2019-03-28 22:16:51 +03:00
|
|
|
buttons messages model =
|
2019-02-15 21:51:19 +03:00
|
|
|
let
|
|
|
|
exampleCell size =
|
|
|
|
(case model.buttonType of
|
|
|
|
Link ->
|
2019-02-16 01:33:26 +03:00
|
|
|
ClickableText.link
|
2019-02-15 21:51:19 +03:00
|
|
|
{ size = size
|
|
|
|
, label = model.label
|
|
|
|
, icon = model.icon
|
|
|
|
, url = "#"
|
|
|
|
}
|
|
|
|
[]
|
|
|
|
|
|
|
|
Button ->
|
2019-02-16 01:33:26 +03:00
|
|
|
ClickableText.button
|
2019-02-15 21:51:19 +03:00
|
|
|
{ size = size
|
|
|
|
, onClick = messages.showItWorked (Debug.toString size)
|
|
|
|
, label = model.label
|
|
|
|
, icon = model.icon
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|> List.singleton
|
|
|
|
|> td
|
|
|
|
[ css
|
|
|
|
[ verticalAlign middle
|
|
|
|
, Css.width (Css.px 200)
|
|
|
|
]
|
|
|
|
]
|
|
|
|
in
|
|
|
|
[ sizes
|
|
|
|
|> List.map (\size -> th [] [ text <| Debug.toString size ])
|
|
|
|
|> tr []
|
|
|
|
, sizes
|
|
|
|
|> List.map exampleCell
|
|
|
|
|> tr []
|
|
|
|
]
|
|
|
|
|> table []
|