Skip to content

Instantly share code, notes, and snippets.

@aduth
Last active March 23, 2017 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aduth/37f3a594d1adc5d7252a9a90d5615845 to your computer and use it in GitHub Desktop.
Save aduth/37f3a594d1adc5d7252a9a90d5615845 to your computer and use it in GitHub Desktop.
const { parse, registerBlock } = wp.blocks;
const { attr, html } = parse;
registerBlock( 'wp/image', {
schema: {
src: attr( 'img', 'src' ),
alt: attr( 'img', 'alt' ),
caption: html( 'figcaption' )
},
edit( { attributes, setAttributes } ) {
const { src, alt, caption } = attributes;
return (
<figure>
<EditableImage
src={ src }
alt={ alt }
onChange={ ( attrs ) => setAttributes( attrs ) } />
<EditableText
value={ caption }
onChange={ ( value ) => setAttributes( { caption: value } ) } />
</figure>
);
},
save( { attributes } ) {
const { src, alt, caption } = attributes;
return (
<figure>
<img src={ src } alt={ alt } />
{ caption ? <figcaption>{ caption }</figcaption> : null }
</figure>
);
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment