Skip to content
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

Merged
merged 2 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { store as coreStore } from '@wordpress/core-data';
* Internal dependencies
*/
import { store as editSiteStore } from '../../../store';
import TemplateAreas from './template-areas';

export default function TemplateCard() {
const { title, description, icon } = useSelect( ( select ) => {
Expand All @@ -36,9 +37,11 @@ export default function TemplateCard() {
<Icon className="edit-site-template-card__icon" icon={ icon } />
<div className="edit-site-template-card__content">
<h2 className="edit-site-template-card__title">{ title }</h2>
<span className="edit-site-template-card__description">
<div className="edit-site-template-card__description">
Copy link
Member Author

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>?

Copy link
Member

@noisysocks noisysocks Oct 6, 2021

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> given description is escaped and so can't contain markup.

Copy link
Member Author

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?

Copy link
Member

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.

{ description }
</span>
</div>

<TemplateAreas />
</div>
</div>
);
Expand Down
23 changes: 23 additions & 0 deletions packages/edit-site/src/components/sidebar/template-card/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

.edit-site-template-card__description {
font-size: $default-font-size;
margin: 0 0 $grid-unit-20;
}

.edit-site-template-card__icon {
Expand All @@ -26,3 +27,25 @@
width: $button-size;
height: $button-size-small;
}

h3.edit-site-template-card__template-areas-title {
font-weight: 500;
margin: 0 0 $grid-unit-10;
}

.edit-site-template-card__template-areas-list {
margin: 0;

> li {
margin: 0;
}
}

.edit-site-template-card__template-areas-item {
width: 100%;

// Override the default padding.
&.components-button.has-icon {
padding: 0;
}
}
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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a similar TemplateAreas component in #35202. Can we re-use?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not a good idea, since that one is using <MenuItem> and this is using plain <Button>. I've already moved some common parts to a selector, the rests are mostly UI. We can create a UI component for them if there's a need.

Copy link
Member

Choose a reason for hiding this comment

The 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>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default function TemplateAreas() {

return (
<MenuGroup
label={ __( 'Template areas' ) }
label={ __( 'Areas' ) }
className="edit-site-template-details__group edit-site-template-details__template-areas"
>
{ Object.entries( templateAreaBlocks ).map(
Expand Down