-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add template areas to template details (#35202)
- Loading branch information
1 parent
9f4585f
commit 1e7f837
Showing
9 changed files
with
145 additions
and
6 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
62 changes: 62 additions & 0 deletions
62
packages/edit-site/src/components/template-details/template-areas.js
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 { MenuGroup, MenuItem } from '@wordpress/components'; | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { getTemplatePartIcon } from '@wordpress/editor'; | ||
import { store as blockEditorStore } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as editSiteStore } from '../../store'; | ||
import { TEMPLATE_PART_AREA_TO_NAME } from '../../store/constants'; | ||
|
||
function TemplatePartItem( { area, clientId } ) { | ||
const { selectBlock, toggleBlockHighlight } = useDispatch( | ||
blockEditorStore | ||
); | ||
const highlightBlock = () => toggleBlockHighlight( clientId, true ); | ||
const cancelHighlightBlock = () => toggleBlockHighlight( clientId, false ); | ||
|
||
return ( | ||
<MenuItem | ||
icon={ getTemplatePartIcon( area ) } | ||
iconPosition="left" | ||
onClick={ () => { | ||
selectBlock( clientId ); | ||
} } | ||
onMouseOver={ highlightBlock } | ||
onMouseLeave={ cancelHighlightBlock } | ||
onFocus={ highlightBlock } | ||
onBlur={ cancelHighlightBlock } | ||
> | ||
{ TEMPLATE_PART_AREA_TO_NAME[ area ] } | ||
</MenuItem> | ||
); | ||
} | ||
|
||
export default function TemplateAreas() { | ||
const templateAreaBlocks = useSelect( | ||
( select ) => select( editSiteStore ).getTemplateAreaBlocks(), | ||
[] | ||
); | ||
|
||
return ( | ||
<MenuGroup | ||
label={ __( 'Template areas' ) } | ||
className="edit-site-template-details__template-areas" | ||
> | ||
{ Object.entries( templateAreaBlocks ).map( | ||
( [ area, templateAreaBlock ] ) => ( | ||
<TemplatePartItem | ||
key={ area } | ||
area={ area } | ||
clientId={ templateAreaBlock.clientId } | ||
/> | ||
) | ||
) } | ||
</MenuGroup> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,6 +1,21 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* The identifier for the data store. | ||
* | ||
* @type {string} | ||
*/ | ||
export const STORE_NAME = 'core/edit-site'; | ||
|
||
export const TEMPLATE_PART_AREA_HEADER = 'header'; | ||
export const TEMPLATE_PART_AREA_FOOTER = 'footer'; | ||
export const TEMPLATE_PART_AREA_SIDEBAR = 'sidebar'; | ||
|
||
export const TEMPLATE_PART_AREA_TO_NAME = { | ||
[ TEMPLATE_PART_AREA_HEADER ]: __( 'Header' ), | ||
[ TEMPLATE_PART_AREA_FOOTER ]: __( 'Footer' ), | ||
[ TEMPLATE_PART_AREA_SIDEBAR ]: __( 'Sidebar' ), | ||
}; |
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
File renamed without changes.
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