forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
separate template screens site editor (WordPress#51040)
* separate template and template part screens site editor
- Loading branch information
1 parent
ed91f22
commit 95295f5
Showing
3 changed files
with
113 additions
and
16 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
packages/edit-site/src/components/sidebar-navigation-screen-template-part/index.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,103 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __, sprintf, _x } from '@wordpress/i18n'; | ||
import { useDispatch, useSelect } from '@wordpress/data'; | ||
import { pencil } from '@wordpress/icons'; | ||
import { | ||
__experimentalUseNavigator as useNavigator, | ||
Icon, | ||
} from '@wordpress/components'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import SidebarNavigationScreen from '../sidebar-navigation-screen'; | ||
import useEditedEntityRecord from '../use-edited-entity-record'; | ||
import { unlock } from '../../private-apis'; | ||
import { store as editSiteStore } from '../../store'; | ||
import SidebarButton from '../sidebar-button'; | ||
import { useAddedBy } from '../list/added-by'; | ||
|
||
function useTemplateTitleAndDescription( postType, postId ) { | ||
const { getDescription, getTitle, record } = useEditedEntityRecord( | ||
postType, | ||
postId | ||
); | ||
const currentTheme = useSelect( | ||
( select ) => select( coreStore ).getCurrentTheme(), | ||
[] | ||
); | ||
const addedBy = useAddedBy( postType, postId ); | ||
const isAddedByActiveTheme = | ||
addedBy.type === 'theme' && record.theme === currentTheme?.stylesheet; | ||
const title = getTitle(); | ||
let descriptionText = getDescription(); | ||
|
||
if ( ! descriptionText && addedBy.text ) { | ||
descriptionText = sprintf( | ||
// translators: %s: template part title e.g: "Header". | ||
__( 'This is your %s template part.' ), | ||
getTitle() | ||
); | ||
} | ||
|
||
const description = ( | ||
<> | ||
{ descriptionText } | ||
|
||
{ addedBy.text && ! isAddedByActiveTheme && ( | ||
<span className="edit-site-sidebar-navigation-screen-template__added-by-description"> | ||
<span className="edit-site-sidebar-navigation-screen-template__added-by-description-author"> | ||
<span className="edit-site-sidebar-navigation-screen-template__added-by-description-author-icon"> | ||
{ addedBy.imageUrl ? ( | ||
<img | ||
src={ addedBy.imageUrl } | ||
alt="" | ||
width="24" | ||
height="24" | ||
/> | ||
) : ( | ||
<Icon icon={ addedBy.icon } /> | ||
) } | ||
</span> | ||
{ addedBy.text } | ||
</span> | ||
|
||
{ addedBy.isCustomized && ( | ||
<span className="edit-site-sidebar-navigation-screen-template__added-by-description-customized"> | ||
{ _x( '(Customized)', 'template part' ) } | ||
</span> | ||
) } | ||
</span> | ||
) } | ||
</> | ||
); | ||
|
||
return { title, description }; | ||
} | ||
|
||
export default function SidebarNavigationScreenTemplatePart() { | ||
const { params } = useNavigator(); | ||
const { postType, postId } = params; | ||
const { setCanvasMode } = unlock( useDispatch( editSiteStore ) ); | ||
const { title, description } = useTemplateTitleAndDescription( | ||
postType, | ||
postId | ||
); | ||
|
||
return ( | ||
<SidebarNavigationScreen | ||
title={ title } | ||
actions={ | ||
<SidebarButton | ||
onClick={ () => setCanvasMode( 'edit' ) } | ||
label={ __( 'Edit' ) } | ||
icon={ pencil } | ||
/> | ||
} | ||
description={ description } | ||
/> | ||
); | ||
} |
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