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

Template Editing Mode: Fix options dropdown #37442

Merged
merged 6 commits into from
Dec 20, 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 @@ -29,6 +29,10 @@ export default function EditTemplateTitle() {
const { getEditorSettings } = useSelect( editorStore );
const { updateEditorSettings } = useDispatch( editorStore );

if ( template.has_theme_file ) {
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
return null;
}

let templateTitle = __( 'Default' );
if ( template?.title ) {
templateTitle = template.title;
Expand Down
69 changes: 43 additions & 26 deletions packages/edit-post/src/components/header/template-title/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
*/
import { __, sprintf } from '@wordpress/i18n';
import { useSelect, useDispatch } from '@wordpress/data';
import { Dropdown, Button } from '@wordpress/components';
import {
Dropdown,
Button,
__experimentalText as Text,
} from '@wordpress/components';
import { chevronDown } from '@wordpress/icons';

/**
Expand Down Expand Up @@ -48,6 +52,12 @@ function TemplateTitle() {
templateTitle = template.slug;
}

const hasOptions = !! (
template.custom ||
template.wp_id ||
template.description
);

return (
<div className="edit-post-template-top-area">
<Button
Expand All @@ -66,32 +76,39 @@ function TemplateTitle() {
>
{ title }
</Button>
<Dropdown
position="bottom center"
contentClassName="edit-post-template-top-area__popover"
renderToggle={ ( { onToggle } ) => (
<Button
className="edit-post-template-title"
isLink
icon={ chevronDown }
showTooltip
onClick={ onToggle }
label={ __( 'Template Options' ) }
>
{ templateTitle }
</Button>
) }
renderContent={ () => (
<>
{ template.has_theme_file ? (
<TemplateDescription />
) : (
{ hasOptions ? (
<Dropdown
position="bottom center"
contentClassName="edit-post-template-top-area__popover"
renderToggle={ ( { onToggle } ) => (
<Button
className="edit-post-template-title"
isLink
icon={ chevronDown }
showTooltip
onClick={ onToggle }
label={ __( 'Template Options' ) }
>
{ templateTitle }
</Button>
) }
renderContent={ () => (
<>
<EditTemplateTitle />
) }
<DeleteTemplate />
</>
) }
/>
<TemplateDescription />
<DeleteTemplate />
</>
) }
/>
) : (
<Text
className="edit-post-template-title"
size="body"
style={ { lineHeight: '24px' } }
>
{ templateTitle }
</Text>
) }
</div>
);
}
Expand Down
18 changes: 13 additions & 5 deletions packages/edit-post/src/components/header/template-title/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,21 @@
}
}

.edit-post-template-top-area__popover .components-popover__content {
min-width: 280px;
.edit-post-template-top-area__popover {
.components-popover__content {
min-width: 280px;
padding: $grid-unit-10;
}

.edit-post-template-details__description {
color: $gray-700;
}
}

.edit-post-template-top-area__second-menu-group {
margin-left: -$grid-unit-15;
margin-right: -$grid-unit-15;
padding: $grid-unit-15;
margin-left: -$grid-unit-20;
margin-right: -$grid-unit-20;
padding: $grid-unit-20;
padding-bottom: 0;
border-top: $border-width solid $gray-300;

Expand All @@ -63,6 +70,7 @@

.components-menu-item__item {
margin-right: 0;
min-width: 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,40 @@
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { __experimentalText as Text } from '@wordpress/components';
import {
__experimentalHeading as Heading,
__experimentalText as Text,
} from '@wordpress/components';

/**
* Internal dependencies
*/
import { store as editPostStore } from '../../../store';

export default function TemplateDescription() {
const { description } = useSelect( ( select ) => {
const { description, title } = useSelect( ( select ) => {
const { getEditedPostTemplate } = select( editPostStore );
return {
title: getEditedPostTemplate().title,
description: getEditedPostTemplate().description,
};
}, [] );
if ( ! description ) {
return null;
}
return <Text size="body">{ description }</Text>;
return (
<>
<Heading level={ 4 } weight={ 600 }>
{ title }
</Heading>
<Text
className="edit-post-template-details__description"
size="body"
as="p"
style={ { marginTop: '12px' } }
>
{ description }
</Text>
</>
);
}