-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from alleyinteractive/154-include-thumbnails-…
…by-default-in-post-selector Include thumbnails by default in post selector
- Loading branch information
Showing
5 changed files
with
101 additions
and
37 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
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
68 changes: 68 additions & 0 deletions
68
packages/block-editor-tools/src/components/post-picker/post.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,68 @@ | ||
import { sprintf } from '@wordpress/i18n'; | ||
import type { WP_REST_API_Attachment } from 'wp-types'; | ||
import styled from 'styled-components'; | ||
import { useMedia } from '../../hooks'; | ||
|
||
interface PostInterface { | ||
title: string; | ||
postType: string, | ||
attachmentID: string | unknown, | ||
} | ||
|
||
interface Media extends WP_REST_API_Attachment { | ||
media_details: { | ||
sizes: { | ||
thumbnail: { | ||
source_url: string; | ||
}; | ||
}; | ||
}; | ||
} | ||
|
||
// Styled components. | ||
const PostDiv = styled.div` | ||
align-items: center; | ||
gap: 4px; | ||
overflow-wrap: anywhere; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
padding: 0.5rem 0.75rem; | ||
`; | ||
|
||
/** | ||
* Displays a single post. | ||
* | ||
* @param {obj} atts The attributes of the Post. | ||
*/ | ||
const Post = ({ | ||
title, | ||
postType, | ||
attachmentID, | ||
}: PostInterface) => { | ||
const media = useMedia(attachmentID) as Media; | ||
const thumbUrl = media?.media_details?.sizes?.thumbnail?.source_url; | ||
const thumbAlt = media?.alt_text ?? ''; | ||
|
||
return ( | ||
<PostDiv> | ||
{thumbUrl ? ( | ||
<img | ||
style={{ maxWidth: '100%', height: 'auto' }} | ||
loading="lazy" | ||
src={thumbUrl} | ||
alt={thumbAlt} | ||
/> | ||
) : null} | ||
<strong> | ||
{title} | ||
</strong> | ||
{sprintf( | ||
' (%s)', | ||
postType, | ||
)} | ||
</PostDiv> | ||
); | ||
}; | ||
|
||
export default Post; |