Skip to content

Commit 2a07132

Browse files
authored
Image onError (#208)
1 parent a2d531b commit 2a07132

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/Lumi/Components2/Image.purs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ image =
6363
lumiComponent "Image" defaults \props -> Hooks.do
6464
theme <- useTheme
6565
loaded /\ setLoaded <- Hooks.useState' false
66+
error /\ setError <- Hooks.useState' false
6667

6768
containerRef <- Hooks.useRef Nullable.null
6869
dimensions /\ setDimensions <- Hooks.useState { width: 20.0, height: 20.0 }
@@ -97,7 +98,7 @@ image =
9798
$ Styles.Box._align Center
9899
$ Styles.Box._justify Center
99100
$$$
100-
[ Monoid.guard (not loaded)
101+
[ Monoid.guard (not loaded && not error)
101102
$ let d = fromMaybe 20.0 ([ dimensions.height, dimensions.width ] # minimum)
102103
in loader
103104
{ style: R.css
@@ -111,14 +112,21 @@ image =
111112
{ src: props.content
112113
, className: ""
113114
, css: E.css
114-
{ width: E.percent 100.0
115-
, height: E.percent 100.0
116-
, objectFit: E.str "cover"
117-
, display: E.str $ if loaded then "block" else "none"
115+
{ objectFit: E.str "cover"
116+
, display: E.str $ if loaded || error then "block" else "none"
118117
}
118+
<> if error
119+
then E.css
120+
{ width: E.str "auto"
121+
, height: E.str "auto"
122+
}
123+
else E.css
124+
{ height: E.percent 100.0
125+
, width: E.percent 100.0
126+
}
119127
<> props.imgStyle
120128
, onLoad: handler_ $ setLoaded true
121-
, onError: handler_ $ setLoaded true
129+
, onError: handler_ $ setError true
122130
}
123131
]
124132
]

0 commit comments

Comments
 (0)