-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 inspector (#35239)
Co-authored-by: James Koster <[email protected]>
- Loading branch information
1 parent
dd89478
commit 1264b12
Showing
4 changed files
with
101 additions
and
3 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
72 changes: 72 additions & 0 deletions
72
packages/edit-site/src/components/sidebar/template-card/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,72 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { | ||
Button, | ||
__experimentalHeading as Heading, | ||
} from '@wordpress/components'; | ||
import { getTemplatePartIcon } from '@wordpress/editor'; | ||
import { store as blockEditorStore } from '@wordpress/block-editor'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as editSiteStore } from '../../../store'; | ||
import { TEMPLATE_PART_AREA_TO_NAME } from '../../../store/constants'; | ||
|
||
function TemplateAreaItem( { area, clientId } ) { | ||
const { selectBlock, toggleBlockHighlight } = useDispatch( | ||
blockEditorStore | ||
); | ||
const highlightBlock = () => toggleBlockHighlight( clientId, true ); | ||
const cancelHighlightBlock = () => toggleBlockHighlight( clientId, false ); | ||
|
||
return ( | ||
<Button | ||
className="edit-site-template-card__template-areas-item" | ||
icon={ getTemplatePartIcon( area ) } | ||
onMouseOver={ highlightBlock } | ||
onMouseLeave={ cancelHighlightBlock } | ||
onFocus={ highlightBlock } | ||
onBlur={ cancelHighlightBlock } | ||
onClick={ () => { | ||
selectBlock( clientId ); | ||
} } | ||
> | ||
{ TEMPLATE_PART_AREA_TO_NAME[ area ] } | ||
</Button> | ||
); | ||
} | ||
|
||
export default function TemplateAreas() { | ||
const templateAreaBlocks = useSelect( | ||
( select ) => select( editSiteStore ).getTemplateAreaBlocks(), | ||
[] | ||
); | ||
|
||
return ( | ||
<section className="edit-site-template-card__template-areas"> | ||
<Heading | ||
level={ 3 } | ||
className="edit-site-template-card__template-areas-title" | ||
> | ||
{ __( 'Areas' ) } | ||
</Heading> | ||
|
||
<ul className="edit-site-template-card__template-areas-list"> | ||
{ Object.entries( templateAreaBlocks ).map( | ||
( [ area, templateAreaBlock ] ) => ( | ||
<li key={ area }> | ||
<TemplateAreaItem | ||
area={ area } | ||
clientId={ templateAreaBlock.clientId } | ||
/> | ||
</li> | ||
) | ||
) } | ||
</ul> | ||
</section> | ||
); | ||
} |
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