-
Notifications
You must be signed in to change notification settings - Fork 100
[BD-46] fix: show skeleton while loading src in CardImageCap (hook) #2846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
31c8411
fix: option1 - handle src loading state and show skeleton while loading
f160afc
fix: option2 - handle loading src in hook
050b8fa
feat: update useImageLoader hook, add img with skeleton component
ee2723d
feat: add skeleton
65b0d79
fix: src issue
ed359e6
feat: add TS for the hook
773d02f
fix: use ref for image
7d7cf4f
Merge pull request #1 from raccoongang/hudym/fix/dataview-card-hook
khudym ffbf061
test: update tests
3fb82f3
refactor: rename index.d.ts file
b9ef7fb
fix: add linter fixes
4c2bea3
fix: add fixes to build docs
92d5b38
fix: fix issue with logo, update doc
0f9c94c
refactor: add changes after review
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
300 changes: 255 additions & 45 deletions
300
src/Card/CardCarousel/tests/__snapshots__/CardCarousel.test.jsx.snap
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,74 @@ | ||
| import React, { useMemo } from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import classNames from 'classnames'; | ||
| import Skeleton from 'react-loading-skeleton'; | ||
|
|
||
| import Image from '../Image'; | ||
| import useImageLoader from '../hooks/useImageLoader'; | ||
|
|
||
| function CardImageWithSkeleton({ | ||
| src, | ||
| alt, | ||
| fallback, | ||
| className, | ||
| withSkeleton, | ||
| useDefaultSrc, | ||
| skeletonWidth, | ||
| skeletonHeight, | ||
| imageLoadingType, | ||
| skeletonClassName, | ||
| isLoading = false, | ||
| }) { | ||
| const config = useMemo( | ||
| () => ({ | ||
| mainSrc: src, fallbackSrc: fallback, useDefaultSrc, | ||
| }), | ||
| [src, fallback, useDefaultSrc], | ||
| ); | ||
|
|
||
| const { ref, isSrcLoading } = useImageLoader(config); | ||
|
|
||
| return ( | ||
| <> | ||
| <Skeleton | ||
| containerClassName={classNames(skeletonClassName, { show: (isSrcLoading || isLoading) && withSkeleton })} | ||
| height={skeletonHeight} | ||
| width={skeletonWidth} | ||
| /> | ||
| <Image | ||
| ref={ref} | ||
| className={classNames(className, { show: !isSrcLoading && !isLoading })} | ||
| alt={alt} | ||
| loading={imageLoadingType} | ||
| /> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| CardImageWithSkeleton.propTypes = { | ||
| className: PropTypes.string, | ||
| src: PropTypes.string.isRequired, | ||
| fallback: PropTypes.string, | ||
| useDefaultSrc: PropTypes.bool, | ||
| alt: PropTypes.string.isRequired, | ||
| skeletonHeight: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), | ||
| skeletonWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), | ||
| skeletonClassName: PropTypes.string, | ||
| imageLoadingType: PropTypes.oneOf(['eager', 'lazy']), | ||
| isLoading: PropTypes.bool, | ||
| withSkeleton: PropTypes.bool, | ||
| }; | ||
|
|
||
| CardImageWithSkeleton.defaultProps = { | ||
| className: undefined, | ||
| skeletonClassName: undefined, | ||
| fallback: undefined, | ||
| useDefaultSrc: false, | ||
| imageLoadingType: 'eager', | ||
| skeletonHeight: undefined, | ||
| skeletonWidth: undefined, | ||
| isLoading: false, | ||
| withSkeleton: false, | ||
| }; | ||
|
|
||
| export default CardImageWithSkeleton; |
This file contains hidden or 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 hidden or 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,2 @@ | ||
| export const SKELETON_HEIGHT_VALUE = 140; | ||
| export const LOGO_SKELETON_HEIGHT_VALUE = 41; |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.