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

106 lines
3.1 KiB
Elm
Raw Normal View History

2020-03-31 22:43:32 +03:00
module Examples.Select exposing (Msg, State, example)
2018-04-17 01:39:57 +03:00
{-|
2020-03-31 22:43:32 +03:00
@docs Msg, State, example
2018-04-17 01:39:57 +03:00
-}
2020-06-19 23:41:28 +03:00
import AtomicDesignType exposing (AtomicDesignType(..))
import Category exposing (Category(..))
import Css
2020-03-31 23:20:03 +03:00
import Example exposing (Example)
2018-07-11 03:50:39 +03:00
import Html.Styled
2019-11-16 01:33:59 +03:00
import Html.Styled.Attributes
import KeyboardSupport exposing (Direction(..), Key(..))
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-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 = "Select"
, version = 7
2020-03-31 22:43:32 +03:00
, state = init
, update = update
2020-03-31 22:48:26 +03:00
, subscriptions = \_ -> Sub.none
2020-03-31 22:43:32 +03:00
, categories = [ Inputs ]
2020-06-20 00:16:10 +03:00
, atomicDesignType = Molecule
, keyboardSupport = []
2020-03-31 22:43:32 +03:00
, view =
\state ->
[ Html.Styled.label
[ Html.Styled.Attributes.for "tortilla-selector" ]
[ Heading.h3 [] [ Html.Styled.text "Tortilla Selector" ] ]
, Select.view
{ current = Nothing
2020-03-31 22:43:32 +03:00
, choices =
[ { label = "Tacos", value = "Tacos" }
, { label = "Burritos", value = "Burritos" }
, { label = "Enchiladas", value = "Enchiladas" }
]
, id = "tortilla-selector"
, valueToString = identity
2020-03-31 22:43:32 +03:00
, defaultDisplayText = Just "Select a tasty tortilla based treat!"
, isInError = False
}
2020-03-31 22:43:32 +03:00
|> Html.Styled.map 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
}
|> Html.Styled.map ConsoleLog
, 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 ConsoleLog
]
]
}
2018-04-17 01:39:57 +03:00
{-| -}
init : State
2018-04-17 01:39:57 +03:00
init =
Nothing
{-| -}
type alias State =
Maybe String
{-| -}
type Msg
= ConsoleLog String
2018-04-17 01:39:57 +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
( Just message, Cmd.none )