mdgriffith/style-elements/4.0.0

NOTE: this package is not compatible with Elm 0.19.1

Element.Input

Input Elements

style
-> List (Attribute variation msg)
-> Checkbox style variation msg
-> Element style variation msg

Your basic checkbox

Input.checkbox CheckBoxStyle [ ]
    { checked = True
    , onChange = ChangeMsg
    , label = Input.labelAbove (text "hello!")
    , options =
        -- Options are where we can add error messages
        -- or disable input for this element
        []
    }

-- For more involved checkbox styling

Input.checkboxWith CheckBoxStyle [ ]
    { onChange = Check
    , checked = model.checkbox
    , label = text "hello!"
    , options = []
    , icon =
        \on ->
            el
                (if on then
                    CheckboxChecked
                 else
                    Checkbox
                )
                []
                empty
    }
type alias Checkbox style variation msg =
{ onChange : Bool -> msg
, label : Element style variation msg
, checked : Bool
, options : List (Option style variation msg)
}
style
-> List (Attribute variation msg)
-> StyledCheckbox style variation msg
-> Element style variation msg
type alias StyledCheckbox style variation msg =
{ onChange : Bool -> msg
, label : Element style variation msg
, checked : Bool
, options : List (Option style variation msg)
, icon : Bool -> Element style variation msg
}

Text Input

type alias Text style variation msg =
{ onChange : String -> msg
, value : String
, label : Label style variation msg
, options : List (Option style variation msg)
}
style
-> List (Attribute variation msg)
-> Text style variation msg
-> Element style variation msg
style
-> List (Attribute variation msg)
-> Text style variation msg
-> Element style variation msg
style
-> List (Attribute variation msg)
-> Text style variation msg
-> Element style variation msg

The following text inputs give hints to the browser so they can be autofilled.

style
-> List (Attribute variation msg)
-> Text style variation msg
-> Element style variation msg
style
-> List (Attribute variation msg)
-> Text style variation msg
-> Element style variation msg

A password input that allows the browser to autofill.

It's newPassword instead of just password because it gives the browser a hint on what type of password input it is.

style
-> List (Attribute variation msg)
-> Text style variation msg
-> Element style variation msg

'Choose One' Inputs

type alias Radio option style variation msg =
{ onChange : option -> msg
, choices : List (Choice option style variation msg)
, selected : Maybe option
, label : Label style variation msg
, options : List (Option style variation msg)
}
style
-> List (Attribute variation msg)
-> Radio option style variation msg
-> Element style variation msg
Input.radio Field
    [ padding 10
    , spacing 5
    ]
    { onChange = ChooseLunch
    , selected = Just model.lunch
    , label = Input.labelAbove <| text "Lunch"
    , errors = Input.noErrors
    , disabled = Input.enabled
    , options =
        [ Input.optionWith None
            []
            { value = Burrito
            , icon =
                (\selected ->
                    if selected then
                        text ":D"
                    else
                        text ":("
                )
            , label = Input.labelRight <| text "burrito"
            }
        , Input.option Taco (text "Taco!")
        , Input.option Gyro (text "Gyro")
        ]
    }
style
-> List (Attribute variation msg)
-> Radio option style variation msg
-> Element style variation msg

Same as radio, but arranges the options in a row instead of a column

type Choice value style variation msg

Add choices to your radio and select menus.

value
-> Element style variation msg
-> Choice value style variation msg
value
-> (Bool -> Element style variation msg)
-> Choice value style variation msg
style
-> List (Attribute variation msg)
-> Select option style variation msg
-> Element style variation msg
type alias Select option style variation msg =
{ with : SelectWith option msg
, max : Int
, menu : Menu option style variation msg
, label : Label style variation msg
, options : List (Option style variation msg)
}
type SelectWith option msg
autocomplete : Maybe option -> (SelectMsg option -> msg) -> SelectWith option msg

Create a select menu which shows options that are filtered by the text entered.

This is the part which goes in your model.

You'll need to update it using Input.updateSelection.

dropMenu : Maybe option -> (SelectMsg option -> msg) -> SelectWith option msg

Create a select menu which shows all options and allows the user to select one.

Use this if you only have 3-5 options. If you have a ton of options, use Input.autocomplete instead!

selected : SelectWith option msg -> Maybe option

Get the selected value from an autocomplete or a dropMenu type that is used for your Input.select element.

type SelectMsg opt
updateSelection : SelectMsg option -> SelectWith option msg -> SelectWith option msg

Labels

labelAbove : Element style variation msg -> Label style variation msg
labelBelow : Element style variation msg -> Label style variation msg
labelLeft : Element style variation msg -> Label style variation msg
labelRight : Element style variation msg -> Label style variation msg
{ text : String
, label : Label style variation msg
}
-> Label style variation msg
hiddenLabel : String -> Label style variation msg

Options

type Option style variation msg
errorAbove : Element style variation msg -> Option style variation msg
errorBelow : Element style variation msg -> Option style variation msg
disabled : Option style variation msg

Disable an input. This means that the input will not receive focus and can't be changed by the user.

Does not change the styling of the inputs unless they're controlled by the browser like a basic checkbox or standard radio button.

focusOnLoad : Option style variation msg

Put the focus on this input when the page loads.

Only one input should ahve this option turned on.

autofill : String -> Option style variation msg

Give a hint to the browser on what data can be used to autofill this input.

This can be very useful to allow the browser to autofill address and credit card forms.

For more general information check out the autocomplete attribute of input elements

autofillSection : String -> Option style variation msg
allowSpellcheck : Option style variation msg

Allow spellcheck for this input. Only works on text based inputs.