File tree Expand file tree Collapse file tree 3 files changed +83
-25
lines changed Expand file tree Collapse file tree 3 files changed +83
-25
lines changed Original file line number Diff line number Diff line change 11// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22
3+ exports [` image error with errorClass 1` ] = `
4+ <div >
5+ <div
6+ class = " nut-image"
7+ style = " height: 100px; width: 100px;"
8+ >
9+ <img
10+ alt = " "
11+ class = " nut-image-default"
12+ src = " https://xxx"
13+ style = " object-fit: fill; object-position: center;"
14+ />
15+ <div
16+ class = " nut-image-loading"
17+ >
18+ <svg
19+ aria-labelledby = " Image"
20+ class = " nut-icon nut-icon-Image "
21+ role = " presentation"
22+ viewBox = " 0 0 49 48"
23+ xmlns = " http://www.w3.org/2000/svg"
24+ >
25+ <path
26+ d = " M48 18.85V36a8 8 0 0 1-8 8H8a8 8 0 0 1-8-8V8a8 8 0 0 1 8-8h32a8 8 0 0 1 8 8v10.153c.054.226.056.465 0 .696M8 3a5 5 0 0 0-5 5V24.49A16.536 16.536 0 0 1 7 24c3.45 0 6.655 1.06 9.303 2.87C19.627 19.295 27.193 14 36 14c3.212 0 6.26.705 9 1.97V8a5 5 0 0 0-5-5zm2 9a2 2 0 1 1 4 0 2 2 0 0 1-4 0M3 27.602V36a5 5 0 0 0 5 5h32a5 5 0 0 0 5-5V19.333A18.412 18.412 0 0 0 36 17c-8.124 0-15.028 5.237-17.513 12.524a1.499 1.499 0 0 1-2.486.914A13.444 13.444 0 0 0 7 27c-1.395 0-2.738.211-4 .602"
27+ fill = " currentColor"
28+ />
29+ </svg >
30+ </div >
31+ </div >
32+ </div >
33+ ` ;
34+
335exports [` image props test 1` ] = `
436<div >
537 <div
@@ -31,3 +63,35 @@ exports[`image props test 1`] = `
3163 </div >
3264</div >
3365` ;
66+
67+ exports [` image success without errorClass 1` ] = `
68+ <div >
69+ <div
70+ class = " nut-image"
71+ style = " height: 100px; width: 100px;"
72+ >
73+ <img
74+ alt = " "
75+ class = " nut-image-default"
76+ src = " https://img10.360buyimg.com/ling/jfs/t1/181258/24/10385/53029/60d04978Ef21f2d42/92baeb21f907cd24.jpg"
77+ style = " object-fit: fill; object-position: center;"
78+ />
79+ <div
80+ class = " nut-image-loading"
81+ >
82+ <svg
83+ aria-labelledby = " Image"
84+ class = " nut-icon nut-icon-Image "
85+ role = " presentation"
86+ viewBox = " 0 0 49 48"
87+ xmlns = " http://www.w3.org/2000/svg"
88+ >
89+ <path
90+ d = " M48 18.85V36a8 8 0 0 1-8 8H8a8 8 0 0 1-8-8V8a8 8 0 0 1 8-8h32a8 8 0 0 1 8 8v10.153c.054.226.056.465 0 .696M8 3a5 5 0 0 0-5 5V24.49A16.536 16.536 0 0 1 7 24c3.45 0 6.655 1.06 9.303 2.87C19.627 19.295 27.193 14 36 14c3.212 0 6.26.705 9 1.97V8a5 5 0 0 0-5-5zm2 9a2 2 0 1 1 4 0 2 2 0 0 1-4 0M3 27.602V36a5 5 0 0 0 5 5h32a5 5 0 0 0 5-5V19.333A18.412 18.412 0 0 0 36 17c-8.124 0-15.028 5.237-17.513 12.524a1.499 1.499 0 0 1-2.486.914A13.444 13.444 0 0 0 7 27c-1.395 0-2.738.211-4 .602"
91+ fill = " currentColor"
92+ />
93+ </svg >
94+ </div >
95+ </div >
96+ </div >
97+ ` ;
Original file line number Diff line number Diff line change @@ -118,7 +118,13 @@ export const Image: FunctionComponent<Partial<TaroImageProps>> = (props) => {
118118 >
119119 < TImage
120120 { ...rest }
121- className = { `${ classPrefix } -default ${ className ? `${ className } -image` : '' } ` }
121+ className = { classNames (
122+ `${ classPrefix } -default` ,
123+ className && `${ className } -image` ,
124+ {
125+ [ `${ classPrefix } -error` ] : isError ,
126+ }
127+ ) }
122128 style = { imgStyle }
123129 src = { src }
124130 onLoad = { ( e ) => handleLoad ( e ) }
Original file line number Diff line number Diff line change @@ -183,30 +183,18 @@ export const Image: FunctionComponent<Partial<WebImageProps>> = (props) => {
183183 imageClick ( e )
184184 } }
185185 >
186- { lazy ? (
187- < img
188- ref = { imgRef }
189- className = { `${ classPrefix } -default lazyload` }
190- style = { imgStyle }
191- data-src = { src }
192- alt = { alt }
193- loading = "lazy"
194- onLoad = { handleLoad }
195- onError = { handleError }
196- draggable = { draggable }
197- />
198- ) : (
199- < img
200- ref = { imgRef }
201- className = { `${ classPrefix } -default` }
202- style = { imgStyle }
203- src = { src }
204- alt = { alt }
205- onLoad = { handleLoad }
206- onError = { handleError }
207- draggable = { draggable }
208- />
209- ) }
186+ < img
187+ ref = { imgRef }
188+ className = { classNames ( `${ classPrefix } -default` , lazy && 'lazyload' , {
189+ [ `${ classPrefix } -error` ] : isError ,
190+ } ) }
191+ style = { imgStyle }
192+ { ...( lazy ? { 'data-src' : src , loading : 'lazy' } : { src } ) }
193+ alt = { alt }
194+ onLoad = { handleLoad }
195+ onError = { handleError }
196+ draggable = { draggable }
197+ />
210198 { renderLoading ( ) }
211199 { renderErrorImg ( ) }
212200 </ div >
You can’t perform that action at this time.
0 commit comments