-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: auto-generate
blurDataURL
property when placeholder=blur
- Loading branch information
Showing
8 changed files
with
227 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import '@testing-library/jest-dom' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
testPathIgnorePatterns: ["<rootDir>/build/", "<rootDir>/src/__tests__/utils"], | ||
collectCoverageFrom: ["src/**/*.{ts,js,tsx}"] | ||
collectCoverageFrom: ["src/**/*.{ts,js,tsx}"], | ||
setupFilesAfterEnv: ['<rootDir>/jest-setup.js'] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,26 @@ | ||
import Image, { ImageProps } from 'next/image'; | ||
import React from 'react'; | ||
import { getInt } from '../utils/helpers'; | ||
import { uploadcareLoader } from '../utils/loader'; | ||
|
||
export function UploadcareImage(props: ImageProps): JSX.Element { | ||
return <Image loader={uploadcareLoader} {...props} />; | ||
export function UploadcareImage({ | ||
blurDataURL, | ||
...props | ||
}: ImageProps): JSX.Element { | ||
if ( | ||
props.placeholder === 'blur' && | ||
!blurDataURL && | ||
typeof props.src === 'string' | ||
) { | ||
const imageWidth = getInt(props.width); | ||
const blurImageWidth = imageWidth ? Math.ceil(imageWidth * 0.01) : 10; | ||
blurDataURL = uploadcareLoader({ | ||
src: props.src, | ||
width: blurImageWidth, | ||
quality: 0 | ||
}); | ||
} | ||
return ( | ||
<Image loader={uploadcareLoader} blurDataURL={blurDataURL} {...props} /> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.