File tree Expand file tree Collapse file tree 1 file changed +19
-12
lines changed Expand file tree Collapse file tree 1 file changed +19
-12
lines changed Original file line number Diff line number Diff line change @@ -3,22 +3,29 @@ import React from 'react';
3
3
import { getInt } from '../utils/helpers' ;
4
4
import { uploadcareLoader } from '../utils/loader' ;
5
5
6
+ const shouldOverrideBlurDataUrl = ( props : ImageProps ) : boolean => {
7
+ return props . placeholder === 'blur' && ! props . blurDataURL ;
8
+ } ;
9
+
10
+ const generateBlurDataUrl = (
11
+ src : string ,
12
+ width : ImageProps [ 'width' ]
13
+ ) : string => {
14
+ const imageWidth = getInt ( width ) ;
15
+ const blurImageWidth = imageWidth ? Math . ceil ( imageWidth * 0.01 ) : 10 ;
16
+ return uploadcareLoader ( {
17
+ src : src ,
18
+ width : blurImageWidth ,
19
+ quality : 0
20
+ } ) ;
21
+ } ;
22
+
6
23
export function UploadcareImage ( {
7
24
blurDataURL,
8
25
...props
9
26
} : ImageProps ) : JSX . Element {
10
- if (
11
- props . placeholder === 'blur' &&
12
- ! blurDataURL &&
13
- typeof props . src === 'string'
14
- ) {
15
- const imageWidth = getInt ( props . width ) ;
16
- const blurImageWidth = imageWidth ? Math . ceil ( imageWidth * 0.01 ) : 10 ;
17
- blurDataURL = uploadcareLoader ( {
18
- src : props . src ,
19
- width : blurImageWidth ,
20
- quality : 0
21
- } ) ;
27
+ if ( typeof props . src === 'string' && shouldOverrideBlurDataUrl ( props ) ) {
28
+ blurDataURL = generateBlurDataUrl ( props . src , props . width ) ;
22
29
}
23
30
return (
24
31
< Image loader = { uploadcareLoader } blurDataURL = { blurDataURL } { ...props } />
You can’t perform that action at this time.
0 commit comments