-
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.
Try Layout Block Half Image Half Content
- Loading branch information
1 parent
3d009d2
commit 2f253f0
Showing
11 changed files
with
276 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { InnerBlocks } from '@wordpress/editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './style.scss'; | ||
import './editor.scss'; | ||
|
||
export const name = 'core/half-media-content-area'; | ||
|
||
const ALLOWED_BLOCKS = [ 'core/button', 'core/paragraph', 'core/heading' ]; | ||
|
||
export const settings = { | ||
attributes: {}, | ||
|
||
title: __( 'Content Area' ), | ||
|
||
parent: [ 'core/half-media' ], | ||
|
||
icon: 'format-image', | ||
|
||
category: 'common', | ||
|
||
edit() { | ||
return ( | ||
<div className="half-media__content"> | ||
<InnerBlocks | ||
template={ [ | ||
[ 'core/heading', { level: 4 } ], | ||
[ 'core/paragraph' ], | ||
] } | ||
allowedBlocks={ ALLOWED_BLOCKS } | ||
templateLock={ false } | ||
/> | ||
</div> | ||
); | ||
}, | ||
|
||
save() { | ||
return <div className="half-media__content"><InnerBlocks.Content /></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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.half-media__media .block-alignment-toolbar { | ||
display: none; | ||
} | ||
|
||
.half-media { | ||
display: block; | ||
} | ||
|
||
.half-media > .editor-inner-blocks > .editor-block-list__layout { | ||
display: flex; | ||
> [data-type="core/half-media-media-area"], | ||
> [data-type="core/half-media-content-area"] { | ||
display: flex; | ||
flex-direction: column; | ||
flex: 1; | ||
width: 0; | ||
.editor-block-list__block-edit { | ||
flex-basis: 100%; | ||
} | ||
} | ||
> [data-type="core/half-media-content-area"] > .editor-block-list__block-edit { | ||
display: flex; | ||
} | ||
} | ||
|
||
|
||
|
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 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
InnerBlocks, | ||
} from '@wordpress/editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './style.scss'; | ||
import './editor.scss'; | ||
|
||
export const name = 'core/half-media'; | ||
|
||
export const settings = { | ||
title: __( 'Half Media' ), | ||
|
||
icon: 'columns', | ||
|
||
category: 'layout', | ||
|
||
attributes: { | ||
}, | ||
|
||
supports: { | ||
align: [ 'wide', 'full' ], | ||
}, | ||
|
||
edit() { | ||
return ( | ||
<div className="half-media"> | ||
<InnerBlocks | ||
template={ [ | ||
[ 'core/half-media-media-area' ], | ||
[ 'core/half-media-content-area' ], | ||
] } | ||
templateLock="all" | ||
/> | ||
</div> | ||
); | ||
}, | ||
|
||
save() { | ||
return ( | ||
<div className="half-media"> | ||
<InnerBlocks.Content /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { InnerBlocks, BlockPlaceholder } from '@wordpress/editor'; | ||
import { withSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './style.scss'; | ||
import './editor.scss'; | ||
|
||
export const name = 'core/half-media-media-area'; | ||
const ALLOWED_BLOCKS = [ | ||
'core/image', | ||
'core/video', | ||
'core-embed/flickr', | ||
'core-embed/youtube', | ||
'core-embed/vimeo', | ||
'core-embed/videopress', | ||
]; | ||
|
||
export const settings = { | ||
attributes: {}, | ||
|
||
title: __( 'Media Area' ), | ||
|
||
parent: [ 'core/half-media' ], | ||
|
||
icon: 'format-image', | ||
|
||
category: 'common', | ||
|
||
edit: withSelect( ( select, { id } ) => { | ||
const { getBlockOrder } = select( 'core/editor' ); | ||
const blocksInside = getBlockOrder( id ); | ||
return { | ||
hasInnerBlocks: blocksInside && blocksInside.length > 0, | ||
}; | ||
} )( | ||
( { id, hasInnerBlocks } ) => { | ||
return ( | ||
<div className="half-media__media"> | ||
<InnerBlocks | ||
allowedBlocks={ ALLOWED_BLOCKS } | ||
templateLock={ hasInnerBlocks ? 'insert' : false } | ||
/> | ||
{ ! hasInnerBlocks && ( | ||
<BlockPlaceholder | ||
rootUID={ id } | ||
/> | ||
) } | ||
</div> | ||
); | ||
} | ||
), | ||
|
||
save() { | ||
return <div className="half-media__media"><InnerBlocks.Content /></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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
.layout-column-2 { | ||
|
||
} | ||
|
||
.half-image__content-area { | ||
margin-left: 28px; | ||
} | ||
|
||
.half-media { | ||
display: flex; | ||
} | ||
|
||
.half-media__content { | ||
flex: 1; | ||
word-break: break-word; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
padding: 5px; | ||
} | ||
|
||
.half-media__media { | ||
flex: 1; | ||
padding: 5px; | ||
} | ||
|
||
.half-media__content { | ||
|
||
} |
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,47 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Component } from '@wordpress/element'; | ||
import { Placeholder } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Inserter from '../inserter'; | ||
|
||
export class BlockPlaceholder extends Component { | ||
static getDerivedStateFromProps( { index, rootUID, layout } ) { | ||
return { | ||
insertionPoint: { | ||
index, | ||
rootUID, | ||
layout, | ||
}, | ||
}; | ||
} | ||
|
||
render() { | ||
const { | ||
className, | ||
} = this.props; | ||
return ( | ||
<Placeholder | ||
instructions={ __( 'Press (+) to insert a media block.' ) } | ||
className={ classnames( 'editor-block-placeholder', className ) } | ||
> | ||
<Inserter | ||
insertionPoint={ this.state.insertionPoint } | ||
position="bottom right" | ||
/> | ||
</Placeholder> | ||
); | ||
} | ||
} | ||
|
||
export default BlockPlaceholder; |
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