import { RichText } from '@wordpress/block-editor'; import { registerBlockType } from '@wordpress/blocks'; import { InnerBlocks } from '@wordpress/editor'; import { __ } from '@wordpress/i18n'; import { transforms } from './transform'; const blockAttributes = { summary: { type: 'string', source: 'html', selector: 'summary', }, }; const save = ( { attributes: { summary } }, className ) => { return (
); }; const edit = ( { attributes: { summary }, className, isSelected, setAttributes } ) => { return (
{ isSelected || ! summary ? ( setAttributes( { summary: newSummary } ) } /> ) : ( ) }
); }; /////////////////////////////////////// // Deprecations /////////////////////////////////////// const blockAttributes_v1 = { hideId: { type: 'string', }, showId: { type: 'string', }, }; const migrate_v1 = () => ( {} ); const save_v1 = ( { attributes: { hideId, showId }, className } ) => { return (
Reveal hidden content Hide content
); }; registerBlockType( 'a8c/spoiler', { title: __( 'Spoiler!' ), icon: 'warning', category: 'a8c', description: __( 'Hide content until the reader wants to see it.' ), keywords: [ __( 'spoiler' ), __( 'accordion' ), __( 'Dropdown' ) ], attributes: blockAttributes, edit, save, transforms, deprecated: [ { attributes: blockAttributes_v1, migrate: migrate_v1, save: save_v1, }, ], } );