-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Thumbnail component to the common components
- Loading branch information
Showing
5 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/content-helper/common/components/thumbnail/component.tsx
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,58 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Icon } from '@wordpress/components'; | ||
import { page } from '@wordpress/icons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { HydratedPost } from '../../base-wordpress-provider'; | ||
|
||
/** | ||
* Defines the props structure for Thumbnail. | ||
* | ||
* @since 3.18.0 | ||
*/ | ||
interface ThumbnailProps { | ||
post?: HydratedPost; | ||
imageUrl?: string; | ||
icon?: React.JSX.Element; | ||
size?: number; | ||
className?: string; | ||
} | ||
|
||
/** | ||
* Thumbnail component that displays either a post's thumbnail, a custom image, or a fallback icon. | ||
* | ||
* @since 3.18.0 | ||
* | ||
* @param {ThumbnailProps} props Component props. | ||
*/ | ||
export const Thumbnail = ( { | ||
post, | ||
imageUrl, | ||
icon = page, | ||
size = 100, | ||
className = '', | ||
}: Readonly<ThumbnailProps> ): React.JSX.Element => { | ||
const thumbnailUrl = post?.thumbnail ?? imageUrl; | ||
const altText = post?.title.rendered ?? ''; | ||
|
||
return ( | ||
<div className={ `parsely-thumbnail ${ className }` } style={ { width: size, height: size } }> | ||
{ thumbnailUrl ? ( | ||
<img | ||
src={ thumbnailUrl } | ||
alt={ altText } | ||
width={ size } | ||
height={ size } | ||
/> | ||
) : ( | ||
<div className="parsely-thumbnail-icon-container"> | ||
<Icon icon={ icon } size={ size } /> | ||
</div> | ||
) } | ||
</div> | ||
); | ||
}; |
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 @@ | ||
export { Thumbnail } from './component'; |
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,31 @@ | ||
@import "../../css/functions"; | ||
@import "../../css/variables"; | ||
|
||
.parsely-thumbnail { | ||
border-radius: 3px; | ||
overflow: hidden; | ||
flex-shrink: 0; | ||
|
||
img { | ||
width: 100%; | ||
height: 100%; | ||
object-fit: cover; | ||
border-radius: 3px; | ||
} | ||
|
||
.parsely-thumbnail-icon-container { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
width: 100%; | ||
height: 100%; | ||
background: var(--gray-500); | ||
border-radius: 3px; | ||
|
||
svg { | ||
fill: var(--sidebar-white); | ||
width: 60%; | ||
height: 60%; | ||
} | ||
} | ||
} |
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