-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add template areas to template inspector #35239
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see a similar There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably not a good idea, since that one is using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to abstract too late than too early! |
||
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> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why this wasn't a
<p>
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd expect it to be a
<p>
givendescription
is escaped and so can't contain markup.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description in all the blocks are all using
<span>
for some reasons. That's why I'm wondering if there are something we haven't thought of?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird! No reason it should hold up this PR.