ValuableFile.Input

File selectors.

Single File

file : List (Attribute msg) -> List (Html msg) -> Html msg

A single file input.

import Html exposing (Html)
import ValuableFile exposing (ValuableFile)
import ValuableFile.Input as Input

type Msg
    = FileSelected File

view : Html msg
view =
    Input.file
        [ Input.onFile FileSelected
        , Input.accept "application/json"
        ]
        []

This is an Html.input with Html.Attributes.type_ "file" preset for convenience.

To style the input, hide it and use a label:

import Html.Attributes

view : Html msg
view =
    div []
        [ Input.file
            [ Input.onFile FileSelected
            , Attributes.id "file-upload"
            , Attributes.style "display" "none"
            ]
            []
        , Html.label
            [ Attributes.for "file-upload"
            , Attributes.style "padding" "16px"
            , Attributes.style "border" "1px solid grey"
            , Attributes.style "cursor" "pointer"
            ]
            [ Html.text "Upload"
            ]
        ]
onFile : (ValuableFile -> msg) -> Attribute msg

Detect change events on file input. It will grab the value from event.target.files as a single file.

Multiple Files

files : List (Attribute msg) -> List (Html msg) -> Html msg

A multiple files input.

import Html exposing (Html)
import ValuableFile exposing (ValuableFile)
import ValuableFile.Input as Input

type Msg
    = FilesSelected (List ValuableFile)

view : Html msg
view =
    Input.files [ Input.onFiles FilesSelected ] []

This is an Html.input with Html.Attributes.type_ "file" and Html.Attributes.multiple true preset for convenience.

onFiles : (List ValuableFile -> msg) -> Attribute msg

Detect change events on multiple files input. It will grab the value from event.target.files.