-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the document title in the template mode of the post editor (#5…
- Loading branch information
1 parent
cad59c4
commit a072b66
Showing
14 changed files
with
166 additions
and
653 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
packages/edit-post/src/components/header/document-title/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,89 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __, isRTL } from '@wordpress/i18n'; | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { BlockIcon, store as blockEditorStore } from '@wordpress/block-editor'; | ||
import { | ||
Button, | ||
VisuallyHidden, | ||
__experimentalHStack as HStack, | ||
__experimentalText as Text, | ||
} from '@wordpress/components'; | ||
import { layout, chevronLeftSmall, chevronRightSmall } from '@wordpress/icons'; | ||
import { privateApis as commandsPrivateApis } from '@wordpress/commands'; | ||
import { displayShortcut } from '@wordpress/keycodes'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { unlock } from '../../../private-apis'; | ||
import { store as editPostStore } from '../../../store'; | ||
|
||
const { store: commandsStore } = unlock( commandsPrivateApis ); | ||
|
||
function DocumentTitle() { | ||
const { template, isEditing } = useSelect( ( select ) => { | ||
const { isEditingTemplate, getEditedPostTemplate } = | ||
select( editPostStore ); | ||
const _isEditing = isEditingTemplate(); | ||
|
||
return { | ||
template: _isEditing ? getEditedPostTemplate() : null, | ||
isEditing: _isEditing, | ||
}; | ||
}, [] ); | ||
const { clearSelectedBlock } = useDispatch( blockEditorStore ); | ||
const { setIsEditingTemplate } = useDispatch( editPostStore ); | ||
const { open: openCommandCenter } = useDispatch( commandsStore ); | ||
|
||
if ( ! isEditing || ! template ) { | ||
return null; | ||
} | ||
|
||
let templateTitle = __( 'Default' ); | ||
if ( template?.title ) { | ||
templateTitle = template.title; | ||
} else if ( !! template ) { | ||
templateTitle = template.slug; | ||
} | ||
|
||
return ( | ||
<div className="edit-post-document-title"> | ||
<span className="edit-post-document-title__left"> | ||
<Button | ||
onClick={ () => { | ||
clearSelectedBlock(); | ||
setIsEditingTemplate( false ); | ||
} } | ||
icon={ isRTL() ? chevronRightSmall : chevronLeftSmall } | ||
> | ||
{ __( 'Back' ) } | ||
</Button> | ||
</span> | ||
|
||
<Button | ||
className="edit-post-document-title__title" | ||
onClick={ () => openCommandCenter() } | ||
> | ||
<HStack spacing={ 1 } justify="center"> | ||
<BlockIcon icon={ layout } /> | ||
<Text size="body" as="h1"> | ||
<VisuallyHidden as="span"> | ||
{ __( 'Editing template: ' ) } | ||
</VisuallyHidden> | ||
{ templateTitle } | ||
</Text> | ||
</HStack> | ||
</Button> | ||
<Button | ||
className="edit-post-document-title__shortcut" | ||
onClick={ () => openCommandCenter() } | ||
> | ||
{ displayShortcut.primary( 'k' ) } | ||
</Button> | ||
</div> | ||
); | ||
} | ||
|
||
export default DocumentTitle; |
61 changes: 61 additions & 0 deletions
61
packages/edit-post/src/components/header/document-title/style.scss
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,61 @@ | ||
.edit-post-document-title { | ||
display: flex; | ||
align-items: center; | ||
gap: $grid-unit; | ||
height: $button-size; | ||
justify-content: space-between; | ||
// Flex items will, by default, refuse to shrink below a minimum | ||
// intrinsic width. In order to shrink this flexbox item, and | ||
// subsequently truncate child text, we set an explicit min-width. | ||
// See https://dev.w3.org/csswg/css-flexbox/#min-size-auto | ||
min-width: 0; | ||
background: $gray-100; | ||
border-radius: 4px; | ||
width: min(100%, 450px); | ||
|
||
&:hover { | ||
color: currentColor; | ||
background: $gray-200; | ||
} | ||
} | ||
|
||
.edit-post-document-title__title.components-button { | ||
flex-grow: 1; | ||
color: var(--wp-block-synced-color); | ||
overflow: hidden; | ||
|
||
&:hover { | ||
color: var(--wp-block-synced-color); | ||
} | ||
|
||
h1 { | ||
color: var(--wp-block-synced-color); | ||
white-space: nowrap; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
} | ||
} | ||
|
||
.edit-post-document-title__shortcut { | ||
flex-shrink: 0; | ||
color: $gray-700; | ||
padding: 0 $grid-unit-15; | ||
|
||
&:hover { | ||
color: $gray-700; | ||
} | ||
} | ||
|
||
.edit-post-document-title__left { | ||
min-width: $button-size; | ||
flex-shrink: 0; | ||
|
||
.components-button.has-icon.has-text { | ||
color: $gray-700; | ||
gap: 0; | ||
|
||
&:hover { | ||
color: currentColor; | ||
} | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
packages/edit-post/src/components/header/header-toolbar/style.scss
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
.edit-post-header-toolbar { | ||
display: inline-flex; | ||
flex-grow: 1; | ||
align-items: center; | ||
border: none; | ||
|
||
|
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
106 changes: 0 additions & 106 deletions
106
packages/edit-post/src/components/header/template-title/delete-template.js
This file was deleted.
Oops, something went wrong.
78 changes: 0 additions & 78 deletions
78
packages/edit-post/src/components/header/template-title/edit-template-title.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.