Skip to content

Commit 1d27539

Browse files
authored
avatarUpload Logo (#132)
* avatarUpload Logo * cleanup * code review
1 parent 9fb9b38 commit 1d27539

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

docs/Examples/Upload.example.purs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,25 @@ docs = unit # make component { initialState, didMount, render }
170170
}
171171
]
172172
}
173+
, h2_ "Logo"
174+
, example $
175+
column
176+
{ style: R.css { alignSelf: "stretch" }
177+
, children:
178+
[ upload defaults
179+
{ value = maybe [] pure self.state.avatar
180+
, variant = Logo
181+
, onChange = send self <<< AvatarEx <<< head
182+
, readonly = self.state.readonly
183+
, backend =
184+
{ fetch: \id@(FileId name) -> do
185+
pure { id, name: FileName name, previewUri: Nothing }
186+
, upload: \file -> produceAff \emitter ->
187+
uploadWithRandomPauses emitter file
188+
}
189+
}
190+
]
191+
}
173192
]
174193

175194
randomPause = do

src/Lumi/Components/Upload.purs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ data UploadVariant
131131
= Images
132132
| Files
133133
| Avatar
134+
| Logo
134135

135136
defaults :: UploadProps
136137
defaults =
@@ -189,6 +190,7 @@ upload = make component { initialState, render }
189190
Images -> Just "image/"
190191
Files -> Nothing
191192
Avatar -> Just "image/"
193+
Logo -> Just "image/"
192194
in
193195
case mimeFilter of
194196
Nothing ->
@@ -300,6 +302,7 @@ upload = make component { initialState, render }
300302

301303
shouldAllowMultiple { allowMultiple, variant } = allowMultiple && case variant of
302304
Avatar -> false
305+
Logo -> false
303306
_ -> true
304307

305308
renderUI stuff self =
@@ -313,7 +316,8 @@ upload = make component { initialState, render }
313316
[ case stuff.variant of
314317
Images -> renderImageList stuff self
315318
Files -> renderFileList stuff self
316-
Avatar -> renderAvatarImage stuff self
319+
Avatar -> renderAvatarImage stuff self stuff.variant
320+
Logo -> renderAvatarImage stuff self stuff.variant
317321
]
318322
}
319323

@@ -349,6 +353,7 @@ upload = make component { initialState, render }
349353
Images -> "image/*"
350354
Files -> ""
351355
Avatar -> "image/*"
356+
Logo -> "image/*"
352357
, onChange: handler target \e -> do
353358
mFiles <- getEventFiles e
354359
for_ mFiles (send self <<< AddNewFiles)
@@ -507,7 +512,7 @@ upload = make component { initialState, render }
507512
| bytes >= 1024 = show (Int.round (toNumber bytes / 1024.0)) <> "kb"
508513
| otherwise = show (Int.round (toNumber bytes)) <> "b"
509514

510-
renderAvatarImage stuff self =
515+
renderAvatarImage stuff self variant =
511516
lumiUploadAvatar
512517
{ onDrop:
513518
if stuff.readonly
@@ -539,17 +544,31 @@ upload = make component { initialState, render }
539544
}
540545
, children: []
541546
}
547+
_ ->
548+
case variant of
549+
Logo ->
550+
lumiUploadAvatarImage
551+
{ style: R.css { backgroundColor: cssStringHSLA colors.black4 }
552+
, children: []
553+
}
554+
_ ->
555+
lumiUploadAvatarImage
556+
{ style: R.css {}
557+
, children: [ userSvg ]
558+
}
559+
560+
_, _ ->
561+
case variant of
562+
Logo ->
563+
lumiUploadAvatarImage
564+
{ style: R.css { backgroundColor: cssStringHSLA colors.black4 }
565+
, children: []
566+
}
542567
_ ->
543568
lumiUploadAvatarImage
544569
{ style: R.css {}
545570
, children: [ userSvg ]
546571
}
547-
548-
_, _ ->
549-
lumiUploadAvatarImage
550-
{ style: R.css {}
551-
, children: [ userSvg ]
552-
}
553572
, if stuff.readonly
554573
then empty
555574
else

0 commit comments

Comments
 (0)