mirror of
https://github.com/NoRedInk/noredink-ui.git
synced 2024-12-16 18:20:31 +03:00
160 lines
3.8 KiB
Elm
160 lines
3.8 KiB
Elm
module Examples.ClickableText exposing (Msg, State, example, init, update)
|
|
|
|
{- \
|
|
@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)
|
|
import Nri.Ui.ClickableText.V1 as ClickableText exposing (Size(..))
|
|
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 :
|
|
{ r | teach_assignments_copyWhite_svg : Asset, x : String }
|
|
-> (String -> ModuleMessages Msg parentMsg)
|
|
-> State
|
|
-> ModuleExample parentMsg
|
|
example assets unnamedMessages state =
|
|
let
|
|
messages =
|
|
unnamedMessages "ClickableTextExample"
|
|
in
|
|
{ filename = "Nri.Ui.ClickableText.V1"
|
|
, category = Buttons
|
|
, content =
|
|
[ viewExamples assets messages state ]
|
|
}
|
|
|
|
|
|
{-| -}
|
|
init : { r | performance : String, lock : String } -> State
|
|
init assets =
|
|
Control.record Model
|
|
|> Control.field "label" (Control.string "Clickable Text")
|
|
|> 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
|
|
( "Nri.Ui.ClickableText.V1.button", Control.value Button )
|
|
[ ( "Nri.Ui.ClickableText.V1.link", Control.value Link )
|
|
]
|
|
)
|
|
|> 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 :
|
|
{ r | teach_assignments_copyWhite_svg : Asset, x : String }
|
|
-> ModuleMessages Msg parentMsg
|
|
-> State
|
|
-> Html parentMsg
|
|
viewExamples assets messages (State control) =
|
|
let
|
|
model =
|
|
Control.currentValue control
|
|
in
|
|
[ Control.view (State >> SetState >> messages.wrapper) control
|
|
|> fromUnstyled
|
|
, buttons assets messages model
|
|
]
|
|
|> div []
|
|
|
|
|
|
sizes : List Size
|
|
sizes =
|
|
[ Small
|
|
, Medium
|
|
, Large
|
|
]
|
|
|
|
|
|
buttons :
|
|
{ r | teach_assignments_copyWhite_svg : Asset }
|
|
-> ModuleMessages Msg parentMsg
|
|
-> Model
|
|
-> Html parentMsg
|
|
buttons assets messages model =
|
|
let
|
|
exampleCell size =
|
|
(case model.buttonType of
|
|
Link ->
|
|
ClickableText.link
|
|
{ size = size
|
|
, label = model.label
|
|
, icon = model.icon
|
|
, url = "#"
|
|
}
|
|
[]
|
|
|
|
Button ->
|
|
ClickableText.button
|
|
{ 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 []
|