first commit
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* WordPress dependencies
|
||||
*/
|
||||
const {
|
||||
addFilter,
|
||||
} = wp.hooks;
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import CollapsibleBlockEdit from './edit.jsx';
|
||||
import CollapsibleBlockSave from './save.jsx';
|
||||
|
||||
/**
|
||||
* Custom block Edit output for Collapsible block.
|
||||
*
|
||||
* @param {JSX} edit Original block edit.
|
||||
* @param {Object} blockProps Block data.
|
||||
*
|
||||
* @return {JSX} Block edit.
|
||||
*/
|
||||
function editRender( edit, blockProps ) {
|
||||
if ( 'canvas/collapsible' === blockProps.name ) {
|
||||
return (
|
||||
<CollapsibleBlockEdit { ...blockProps } />
|
||||
);
|
||||
}
|
||||
|
||||
return edit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom block register data for Collapsible block.
|
||||
*
|
||||
* @param {Object} blockData Block data.
|
||||
*
|
||||
* @return {Object} Block data.
|
||||
*/
|
||||
function registerData( blockData ) {
|
||||
if ( 'canvas/collapsible' === blockData.name ) {
|
||||
blockData.save = CollapsibleBlockSave;
|
||||
}
|
||||
|
||||
return blockData;
|
||||
}
|
||||
|
||||
addFilter( 'canvas.customBlock.editRender', 'canvas/collapsible/editRender', editRender );
|
||||
addFilter( 'canvas.customBlock.registerData', 'canvas/collapsible/registerData', registerData );
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import classnames from 'classnames';
|
||||
|
||||
/**
|
||||
* WordPress dependencies
|
||||
*/
|
||||
const { Component, Fragment } = wp.element;
|
||||
|
||||
const { __ } = wp.i18n;
|
||||
|
||||
const {
|
||||
RichText,
|
||||
InnerBlocks,
|
||||
} = wp.blockEditor;
|
||||
|
||||
const {
|
||||
Button,
|
||||
} = wp.components;
|
||||
|
||||
/**
|
||||
* Component
|
||||
*/
|
||||
export default class CollapsibleBlockEdit extends Component {
|
||||
render() {
|
||||
const {
|
||||
attributes,
|
||||
setAttributes,
|
||||
} = this.props;
|
||||
|
||||
const {
|
||||
title,
|
||||
opened,
|
||||
canvasClassName,
|
||||
} = attributes;
|
||||
|
||||
let {
|
||||
className,
|
||||
} = this.props;
|
||||
|
||||
className = classnames(
|
||||
'cnvs-block-collapsible',
|
||||
{
|
||||
'cnvs-block-collapsible-opened': opened,
|
||||
},
|
||||
canvasClassName,
|
||||
className
|
||||
);
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
<div className={ className }>
|
||||
<div className="cnvs-block-collapsible-title">
|
||||
<h6>
|
||||
<RichText
|
||||
placeholder={ __( 'Add collapsible title...' ) }
|
||||
value={ title }
|
||||
onChange={ ( val ) => setAttributes( { title: val } ) }
|
||||
keepPlaceholderOnFocus
|
||||
/>
|
||||
</h6>
|
||||
<Button
|
||||
className="cnvs-block-collapsible-toggle"
|
||||
onClick={ () => setAttributes( { opened: ! opened } ) }
|
||||
>
|
||||
<span className="cnvs-icon-chevron-right" />
|
||||
</Button>
|
||||
</div>
|
||||
<div className="cnvs-block-collapsible-content">
|
||||
<InnerBlocks
|
||||
templateLock={ false }
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Fragment>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* Collapsible block template
|
||||
*
|
||||
* @var $attributes - block attributes
|
||||
* @var $content - inner blocks
|
||||
* @var $options - layout options
|
||||
*
|
||||
* @package Canvas
|
||||
*/
|
||||
|
||||
if ( $attributes['opened'] ) {
|
||||
$attributes['className'] .= ' cnvs-block-collapsible-opened';
|
||||
}
|
||||
|
||||
?>
|
||||
<div class="<?php echo esc_attr( $attributes['className'] ); ?>" <?php echo ( isset( $attributes['anchor'] ) ? ' id="' . esc_attr( $attributes['anchor'] ) . '"' : '' ); ?>>
|
||||
<div class="cnvs-block-collapsible-title">
|
||||
<h6 class="cnvs-block-collapsible-heading">
|
||||
<a href="#"><?php echo (string) $attributes['title']; // XSS. ?></a>
|
||||
</h6>
|
||||
</div>
|
||||
<div class="cnvs-block-collapsible-content">
|
||||
<?php echo (string) $content; // XSS. ?>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* WordPress dependencies
|
||||
*/
|
||||
const { Component } = wp.element;
|
||||
|
||||
const {
|
||||
InnerBlocks,
|
||||
} = wp.blockEditor;
|
||||
|
||||
/**
|
||||
* Component
|
||||
*/
|
||||
export default class CollapsibleBlockSave extends Component {
|
||||
render() {
|
||||
return <InnerBlocks.Content />;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user