-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
- Loading branch information
Showing
25 changed files
with
474 additions
and
424 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,15 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { RichText } from '@wordpress/block-editor'; | ||
|
||
export default function save( { attributes } ) { | ||
const { autoplay, caption, loop, preload, src } = attributes; | ||
|
||
return ( | ||
<figure> | ||
<audio controls="controls" src={ src } autoPlay={ autoplay } loop={ loop } preload={ preload } /> | ||
{ ! RichText.isEmpty( caption ) && <RichText.Content tagName="figcaption" value={ caption } /> } | ||
</figure> | ||
); | ||
} |
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,59 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createBlobURL } from '@wordpress/blob'; | ||
import { createBlock } from '@wordpress/blocks'; | ||
|
||
const transforms = { | ||
from: [ | ||
{ | ||
type: 'files', | ||
isMatch( files ) { | ||
return files.length === 1 && files[ 0 ].type.indexOf( 'audio/' ) === 0; | ||
}, | ||
transform( files ) { | ||
const file = files[ 0 ]; | ||
// We don't need to upload the media directly here | ||
// It's already done as part of the `componentDidMount` | ||
// in the audio block | ||
const block = createBlock( 'core/audio', { | ||
src: createBlobURL( file ), | ||
} ); | ||
|
||
return block; | ||
}, | ||
}, | ||
{ | ||
type: 'shortcode', | ||
tag: 'audio', | ||
attributes: { | ||
src: { | ||
type: 'string', | ||
shortcode: ( { named: { src } } ) => { | ||
return src; | ||
}, | ||
}, | ||
loop: { | ||
type: 'string', | ||
shortcode: ( { named: { loop } } ) => { | ||
return loop; | ||
}, | ||
}, | ||
autoplay: { | ||
type: 'srting', | ||
shortcode: ( { named: { autoplay } } ) => { | ||
return autoplay; | ||
}, | ||
}, | ||
preload: { | ||
type: 'string', | ||
shortcode: ( { named: { preload } } ) => { | ||
return preload; | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
export default transforms; |
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,52 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
RichText, | ||
getColorClassName, | ||
} from '@wordpress/block-editor'; | ||
|
||
export default function save( { attributes } ) { | ||
const { | ||
url, | ||
text, | ||
title, | ||
backgroundColor, | ||
textColor, | ||
customBackgroundColor, | ||
customTextColor, | ||
} = attributes; | ||
|
||
const textClass = getColorClassName( 'color', textColor ); | ||
const backgroundClass = getColorClassName( 'background-color', backgroundColor ); | ||
|
||
const buttonClasses = classnames( 'wp-block-button__link', { | ||
'has-text-color': textColor || customTextColor, | ||
[ textClass ]: textClass, | ||
'has-background': backgroundColor || customBackgroundColor, | ||
[ backgroundClass ]: backgroundClass, | ||
} ); | ||
|
||
const buttonStyle = { | ||
backgroundColor: backgroundClass ? undefined : customBackgroundColor, | ||
color: textClass ? undefined : customTextColor, | ||
}; | ||
|
||
return ( | ||
<div> | ||
<RichText.Content | ||
tagName="a" | ||
className={ buttonClasses } | ||
href={ url } | ||
title={ title } | ||
style={ buttonStyle } | ||
value={ text } | ||
/> | ||
</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
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
Oops, something went wrong.