-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor core blocks to have save and transforms in their own files (…
…part 2)
- Loading branch information
Showing
23 changed files
with
744 additions
and
674 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { RichText } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { defaultColumnsNumber } from './shared'; | ||
|
||
export default function save( { attributes } ) { | ||
const { images, columns = defaultColumnsNumber( attributes ), imageCrop, linkTo } = attributes; | ||
return ( | ||
<ul className={ `columns-${ columns } ${ imageCrop ? 'is-cropped' : '' }` } > | ||
{ images.map( ( image ) => { | ||
let href; | ||
|
||
switch ( linkTo ) { | ||
case 'media': | ||
href = image.url; | ||
break; | ||
case 'attachment': | ||
href = image.link; | ||
break; | ||
} | ||
|
||
const img = <img src={ image.url } alt={ image.alt } data-id={ image.id } data-link={ image.link } className={ image.id ? `wp-image-${ image.id }` : null } />; | ||
|
||
return ( | ||
<li key={ image.id || image.url } className="blocks-gallery-item"> | ||
<figure> | ||
{ href ? <a href={ href }>{ img }</a> : img } | ||
{ image.caption && image.caption.length > 0 && ( | ||
<RichText.Content tagName="figcaption" value={ image.caption } /> | ||
) } | ||
</figure> | ||
</li> | ||
); | ||
} ) } | ||
</ul> | ||
); | ||
} |
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,14 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { get, pick } from 'lodash'; | ||
|
||
export function defaultColumnsNumber( attributes ) { | ||
return Math.min( 3, attributes.images.length ); | ||
} | ||
|
||
export const pickRelevantMediaFiles = ( image ) => { | ||
const imageProps = pick( image, [ 'alt', 'id', 'link', 'caption' ] ); | ||
imageProps.url = get( image, [ 'sizes', 'large', 'url' ] ) || get( image, [ 'media_details', 'sizes', 'large', 'source_url' ] ) || image.url; | ||
return imageProps; | ||
}; |
Oops, something went wrong.