Skip to content

Commit

Permalink
Show media placeholder for cards in Posts Collection block in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
razwan committed Nov 17, 2020
1 parent 4919436 commit 8e8b72b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 1 addition & 3 deletions packages/block-editor/src/components/post-card/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ const Post = ( props ) => {
metaBelowTitle = secondaryMeta;
}

const media = (
<Media id={ post.featured_media } />
);
const media = !! post.featured_media ? <Media id={ post.featured_media } /> : null;

const buttons = (
<div className="wp-block-buttons">
Expand Down
15 changes: 13 additions & 2 deletions packages/components/src/card/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import classnames from "classnames";
import * as icons from '@novablocks/icons';
import { RawHTML } from '@wordpress/element';
import { TextPlaceholder } from '../index';

Expand Down Expand Up @@ -33,7 +34,7 @@ const Card = ( props ) => {
<div className={ className }>
<div className="novablocks-card__layout">
{
( ( showMedia && props.media ) || placeholder ) &&
( showMedia || placeholder ) &&
<div className="novablocks-card__layout-media novablocks-grid__item-media">
<CardMedia { ...props }>{ props.media }</CardMedia>
</div>
Expand Down Expand Up @@ -161,10 +162,20 @@ const CardMedia = ( { children, placeholder } ) => {
}
);

let content = children;

if ( ! children && ! placeholder ) {
content = (
<div className={ 'novablocks-card__media-placeholder' }>
{ icons.placeholder }
</div>
);
}

return (
<div className="novablocks-card__media-wrap">
<div className={ mediaClasses }>
{ children }
{ content }
</div>
</div>
)
Expand Down

0 comments on commit 8e8b72b

Please sign in to comment.