Skip to content

Commit 61c116d

Browse files
authored
[#200] Image, cover not contain (#201)
* object-fit: cover; and export avatars sizes * update default placeholder; and examples
1 parent 537bd45 commit 61c116d

File tree

2 files changed

+43
-17
lines changed

2 files changed

+43
-17
lines changed

docs/Examples2/Image.example.purs

+19-10
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ docs :: JSX
1414
docs =
1515
let flexo = "https://s3.amazonaws.com/lumi-blog/avatars/_x600/flexo.jpg"
1616
in Array.intercalate (vspace S16)
17-
[ h4_ "Image default (will respect image's aspect ratio)"
17+
[ h4_ "Image default (will respect image's original aspect ratio & dimensions)"
1818
, example
1919
$ Image.image
20-
$$$ "http://via.placeholder.com/640x360"
21-
, h4_ "Image + resize { width: 120px, height: 40px }, scales image to respect it's aspect ratio"
20+
$$$ flexo
21+
, h4_ "Image + resize { width: 120px, height: 40px }, the image will fill the height and width of its parent (object-fit: cover), maintaining its aspect ratio but cropping the image"
2222
, example
2323
$ Image.image
2424
$ Image.resize { width: 120, height: 40 }
25-
$$$ "http://via.placeholder.com/360x640"
25+
$$$ flexo
2626
, h4_ "Thumbnail default (will always have a square aspect ratio)"
2727
, example
2828
$ Image.thumbnail
29-
$$$ "http://via.placeholder.com/360x640"
29+
$$$ flexo
3030
, h4_ "Thumbnail + resize 400px"
3131
, example
3232
$ Image.thumbnail
@@ -52,16 +52,25 @@ docs =
5252
$ Image.thumbnail
5353
$ Image.extraLarge
5454
$$$ flexo
55-
, h4_ "Thumbnail + round"
55+
, h4_ "Thumbnail + avatar (small)"
5656
, example
5757
$ Image.thumbnail
58-
$ Image.round
59-
$ Image.extraLarge
58+
$ Image.smallAvatar
59+
$$$ flexo
60+
, h4_ "Thumbnail + avatar (medium)"
61+
, example
62+
$ Image.thumbnail
63+
$ Image.mediumAvatar
64+
$$$ flexo
65+
, h4_ "Thumbnail + avatar (large)"
66+
, example
67+
$ Image.thumbnail
68+
$ Image.largeAvatar
6069
$$$ flexo
61-
, h4_ "Placeholders (can be overriden)"
70+
, h4_ "Default placeholder (can be overriden)"
6271
, example
6372
$ Image.image
64-
$ Image.resize { width: 900, height: 50 }
73+
$ Image.resize { width: 320, height: 240 }
6574
$$$ ""
6675
, example
6776
$ Image.thumbnail

src/Lumi/Components2/Image.purs

+24-7
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ module Lumi.Components2.Image
55
, medium
66
, large
77
, extraLarge
8+
, smallAvatar
9+
, mediumAvatar
10+
, largeAvatar
811
, resize
912
, resizeSquare
1013
, round
11-
, Image
12-
, Thumbnail
14+
, ImageProps
15+
, ThumbnailProps
16+
, Image(..)
17+
, Thumbnail(..)
1318
) where
1419

1520
import Prelude
@@ -27,7 +32,7 @@ import Lumi.Components (LumiComponent, PropsModifier, lumiComponent, ($$$))
2732
import Lumi.Components.Loader (loader)
2833
import Lumi.Components.Svg (placeholderSvg)
2934
import Lumi.Components2.Box as Box
30-
import Lumi.Styles (Style, StyleModifier, style, style_, toCSS)
35+
import Lumi.Styles (Style, StyleModifier, color, style, style_, toCSS)
3136
import Lumi.Styles.Box (FlexAlign(..))
3237
import Lumi.Styles.Box as Styles.Box
3338
import Lumi.Styles.Slat hiding (_interactive,slat) as Styles.Slat
@@ -82,7 +87,7 @@ image =
8287
{ ref: containerRef
8388
, children:
8489
[ if String.null props.content
85-
then fromMaybe placeholderSvg props.placeholder
90+
then fromMaybe placeholder props.placeholder
8691
else
8792
Box.column
8893
$ Styles.Box._flex
@@ -103,9 +108,8 @@ image =
103108
{ src: props.content
104109
, className: ""
105110
, css: E.css
106-
{ maxWidth: E.percent 100.0
107-
, maxHeight: E.percent 100.0
108-
, objectFit: E.str "contain"
111+
{ width: E.percent 100.0
112+
, objectFit: E.str "cover"
109113
, display: E.str $ if loaded then "block" else "none"
110114
}
111115
, onLoad: handler_ $ setLoaded true
@@ -261,3 +265,16 @@ largeAvatar =
261265
mkRound :: Style
262266
mkRound = E.css { borderRadius: E.percent 50.0 }
263267

268+
placeholder :: JSX
269+
placeholder =
270+
Box.column
271+
$ Styles.Box._align Center
272+
$ Styles.Box._justify Center
273+
$ Styles.Box._flex
274+
$ style do
275+
\(LumiTheme { colors }) -> (E.css { backgroundColor: color colors.black6, width: E.percent 100.0 })
276+
$$$
277+
[ Box.box
278+
$ style_ (E.css { width: E.percent 50.0 })
279+
$$$ [ placeholderSvg ]
280+
]

0 commit comments

Comments
 (0)