Skip to content

Commit b74d5fe

Browse files
committed
File input
1 parent 94d4e7a commit b74d5fe

File tree

12 files changed

+1030
-160
lines changed

12 files changed

+1030
-160
lines changed

docs/.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
build
22
static/main.js
3-
.sass-cache
4-
static/styles.css.map
5-
static/styles.css

docs/elm.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
"elm-version": "0.19.1",
88
"dependencies": {
99
"direct": {
10+
"danfishgold/base64-bytes": "1.1.0",
1011
"dtwrks/elm-book": "1.4.4",
1112
"elm/browser": "1.0.2",
13+
"elm/bytes": "1.0.8",
1214
"elm/core": "1.0.5",
15+
"elm/file": "1.0.5",
1316
"elm/html": "1.0.0",
1417
"elm/http": "2.0.0",
1518
"elm/json": "1.1.3",
@@ -24,8 +27,6 @@
2427
},
2528
"indirect": {
2629
"dillonkearns/elm-markdown": "7.0.1",
27-
"elm/bytes": "1.0.8",
28-
"elm/file": "1.0.5",
2930
"elm/parser": "1.1.0",
3031
"elm/svg": "1.0.1",
3132
"elm/virtual-dom": "1.0.4",

docs/src/Chapters/Fields.elm

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type Msg
3737
| SelectChanged (Field.Msg ())
3838
| RadioChanged (Field.Msg ())
3939
| CheckboxChanged (Field.Msg ())
40+
| FileChanged (Field.Msg ())
4041
| GroupChanged (Field.Msg ContactFields)
4142
| RepeatableChanged (Field.Msg ContactFields)
4243
| Repeatable2Changed (Field.Msg ContactFields)
@@ -59,6 +60,7 @@ type alias Model =
5960
, select : Field ()
6061
, radio : Field ()
6162
, checkbox : Field ()
63+
, file : Field ()
6264
, group : Field ContactFields
6365
, repeatable : Field ContactFields
6466
, repeatableWithDefaults : Field ContactFields
@@ -83,6 +85,7 @@ init =
8385
, select = selectField
8486
, radio = radioField
8587
, checkbox = checkboxField
88+
, file = fileField
8689
, group = groupField
8790
, repeatable = repeatableField
8891
, repeatableWithDefaults = repeatableFieldWithDefaults
@@ -257,6 +260,16 @@ update msg book =
257260
(Task.succeed (Debug.toString result))
258261
)
259262

263+
FileChanged fieldMsg ->
264+
let
265+
( updatedField, result ) =
266+
Parse.parseUpdate Parse.file fieldMsg model.file
267+
in
268+
( { model | file = updatedField }
269+
, Task.perform (Actions.logActionWithString "Result")
270+
(Task.succeed (Debug.toString result))
271+
)
272+
260273
GroupChanged fieldMsg ->
261274
let
262275
( updatedField, result ) =
@@ -423,6 +436,14 @@ chapter =
423436
]
424437
|> Html.map (Actions.updateStateWithCmdWith update)
425438
)
439+
, ( "File"
440+
, \book ->
441+
Html.div [ Attr.class "milligram" ]
442+
[ book.fields.file
443+
|> Field.toHtml FileChanged
444+
]
445+
|> Html.map (Actions.updateStateWithCmdWith update)
446+
)
426447
, ( "Group"
427448
, \book ->
428449
Html.div [ Attr.class "milligram" ]
@@ -808,6 +829,29 @@ checkboxField =
808829
Parsed using `Parse.bool`.
809830
810831
832+
### File
833+
834+
A file upload input field with drag and drop support. Files can be dropped onto
835+
the input area or selected via the native file picker. The `min` and `max`
836+
attributes can be used to validate file size in bytes.
837+
838+
```elm
839+
fileField : Field ()
840+
fileField =
841+
Field.file
842+
[ Field.label "File Upload"
843+
, Field.placeholder "Choose a file or drag and drop"
844+
, Field.hint "Maximum file size: 5MB"
845+
, Field.max (Value.int 5242880)
846+
, Field.required True
847+
]
848+
```
849+
850+
<component with-label="File"/>
851+
852+
Parsed using `Parse.file`.
853+
854+
811855
## Groupping Fields
812856
813857
@@ -1133,6 +1177,17 @@ checkboxField =
11331177
]
11341178

11351179

1180+
fileField : Field ()
1181+
fileField =
1182+
Field.file
1183+
[ Field.label "File Upload"
1184+
, Field.placeholder "Choose a file or drag and drop"
1185+
, Field.hint "Maximum file size: 5MB"
1186+
, Field.max (Value.int 5242880)
1187+
, Field.required True
1188+
]
1189+
1190+
11361191
groupField : Field ContactFields
11371192
groupField =
11381193
Field.group

0 commit comments

Comments
 (0)