2018-09-26 17:02:10 +03:00
|
|
|
module Examples.Select exposing
|
|
|
|
( Msg
|
|
|
|
, State
|
|
|
|
, example
|
|
|
|
, init
|
|
|
|
, update
|
|
|
|
)
|
2018-04-17 01:39:57 +03:00
|
|
|
|
|
|
|
{-|
|
|
|
|
|
|
|
|
@docs Msg
|
|
|
|
@docs State
|
|
|
|
@docs example
|
|
|
|
@docs init
|
|
|
|
@docs update
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
2020-01-27 19:16:22 +03:00
|
|
|
import Css
|
2018-07-11 03:50:39 +03:00
|
|
|
import Html.Styled
|
2019-11-16 01:33:59 +03:00
|
|
|
import Html.Styled.Attributes
|
2018-04-17 01:39:57 +03:00
|
|
|
import ModuleExample exposing (Category(..), ModuleExample)
|
2019-11-16 01:33:59 +03:00
|
|
|
import Nri.Ui.Heading.V2 as Heading
|
2020-01-16 22:41:51 +03:00
|
|
|
import Nri.Ui.Select.V7 as Select
|
2018-04-17 01:39:57 +03:00
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
2020-01-16 22:47:42 +03:00
|
|
|
example : (Msg -> msg) -> State -> ModuleExample msg
|
2018-04-17 01:39:57 +03:00
|
|
|
example parentMessage state =
|
2020-01-16 22:41:51 +03:00
|
|
|
{ name = "Nri.Ui.Select.V7"
|
2019-05-17 02:56:06 +03:00
|
|
|
, category = Inputs
|
|
|
|
, content =
|
2019-11-16 01:33:59 +03:00
|
|
|
[ Html.Styled.label
|
|
|
|
[ Html.Styled.Attributes.for "tortilla-selector" ]
|
|
|
|
[ Heading.h3 [] [ Html.Styled.text "Tortilla Selector" ] ]
|
2020-01-16 22:47:42 +03:00
|
|
|
, Select.view
|
|
|
|
{ current = Nothing
|
|
|
|
, choices =
|
|
|
|
[ { label = "Tacos", value = "Tacos" }
|
|
|
|
, { label = "Burritos", value = "Burritos" }
|
|
|
|
, { label = "Enchiladas", value = "Enchiladas" }
|
|
|
|
]
|
2020-01-16 22:56:17 +03:00
|
|
|
, id = "tortilla-selector"
|
2020-01-16 22:47:42 +03:00
|
|
|
, valueToString = identity
|
|
|
|
, defaultDisplayText = Just "Select a tasty tortilla based treat!"
|
2020-01-16 23:46:20 +03:00
|
|
|
, isInError = False
|
|
|
|
}
|
|
|
|
|> Html.Styled.map (parentMessage << ConsoleLog)
|
|
|
|
, Html.Styled.label
|
|
|
|
[ Html.Styled.Attributes.for "errored-selector" ]
|
|
|
|
[ Heading.h3 [] [ Html.Styled.text "Errored Selector" ] ]
|
|
|
|
, Select.view
|
|
|
|
{ current = Nothing
|
|
|
|
, choices = []
|
|
|
|
, id = "errored-selector"
|
|
|
|
, valueToString = identity
|
|
|
|
, defaultDisplayText = Just "Please select an option"
|
|
|
|
, isInError = True
|
2020-01-16 22:47:42 +03:00
|
|
|
}
|
|
|
|
|> Html.Styled.map (parentMessage << ConsoleLog)
|
2020-01-27 19:16:22 +03:00
|
|
|
, Html.Styled.label
|
|
|
|
[ Html.Styled.Attributes.for "overflowed-selector" ]
|
|
|
|
[ Heading.h3 [] [ Html.Styled.text "Selector with Overflowed Text" ] ]
|
|
|
|
, Html.Styled.div
|
|
|
|
[ Html.Styled.Attributes.css [ Css.maxWidth (Css.px 400) ] ]
|
|
|
|
[ Select.view
|
|
|
|
{ current = Nothing
|
|
|
|
, choices = []
|
|
|
|
, id = "overflowed-selector"
|
|
|
|
, valueToString = identity
|
|
|
|
, defaultDisplayText = Just "Look at me, I design coastlines, I got an award for Norway. Where's the sense in that?"
|
|
|
|
, isInError = False
|
|
|
|
}
|
|
|
|
|> Html.Styled.map (parentMessage << ConsoleLog)
|
|
|
|
]
|
2019-05-17 02:56:06 +03:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-17 01:39:57 +03:00
|
|
|
{-| -}
|
2020-01-16 22:47:42 +03:00
|
|
|
init : State
|
2018-04-17 01:39:57 +03:00
|
|
|
init =
|
2020-01-16 22:47:42 +03:00
|
|
|
Nothing
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type alias State =
|
|
|
|
Maybe String
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type Msg
|
|
|
|
= ConsoleLog String
|
2019-05-17 02:56:06 +03:00
|
|
|
|
|
|
|
|
2018-04-17 01:39:57 +03:00
|
|
|
{-| -}
|
2020-01-16 22:47:42 +03:00
|
|
|
update : Msg -> State -> ( State, Cmd Msg )
|
2018-04-17 01:39:57 +03:00
|
|
|
update msg state =
|
|
|
|
case msg of
|
|
|
|
ConsoleLog message ->
|
|
|
|
let
|
|
|
|
_ =
|
|
|
|
Debug.log "SelectExample" message
|
|
|
|
in
|
2020-01-16 22:47:42 +03:00
|
|
|
( Just message, Cmd.none )
|