-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FSE: Add basic template information to editor header (#25320)
- Loading branch information
1 parent
9b7b37c
commit 2fbad1b
Showing
7 changed files
with
203 additions
and
56 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
80 changes: 80 additions & 0 deletions
80
packages/edit-site/src/components/header/document-actions/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,80 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
__experimentalGetBlockLabel as getBlockLabel, | ||
getBlockType, | ||
} from '@wordpress/blocks'; | ||
import { useSelect } from '@wordpress/data'; | ||
|
||
function useSecondaryText() { | ||
const selectedBlock = useSelect( ( select ) => { | ||
return select( 'core/block-editor' ).getSelectedBlock(); | ||
} ); | ||
|
||
// TODO: Handle if parent is template part too. | ||
const selectedBlockLabel = | ||
selectedBlock?.name === 'core/template-part' | ||
? getBlockLabel( | ||
getBlockType( selectedBlock?.name ), | ||
selectedBlock?.attributes | ||
) | ||
: null; | ||
|
||
if ( selectedBlockLabel ) { | ||
return { | ||
label: selectedBlockLabel, | ||
isActive: true, | ||
}; | ||
} | ||
return {}; | ||
} | ||
|
||
export default function DocumentActions( { documentTitle } ) { | ||
const { label, isActive } = useSecondaryText(); | ||
// Title is active when there is no secondary item, or when the secondary | ||
// item is inactive. | ||
const isTitleActive = ! label?.length || ! isActive; | ||
return ( | ||
<div | ||
className={ classnames( 'edit-site-document-actions', { | ||
'has-secondary-label': !! label, | ||
} ) } | ||
> | ||
{ documentTitle ? ( | ||
<> | ||
<div | ||
className={ classnames( | ||
'edit-site-document-actions__label', | ||
'edit-site-document-actions__title', | ||
{ | ||
'is-active': isTitleActive, | ||
} | ||
) } | ||
> | ||
{ documentTitle } | ||
</div> | ||
<div | ||
className={ classnames( | ||
'edit-site-document-actions__label', | ||
'edit-site-document-actions__secondary-item', | ||
{ | ||
'is-active': isActive, | ||
} | ||
) } | ||
> | ||
{ label ?? '' } | ||
</div> | ||
</> | ||
) : ( | ||
__( 'Loading…' ) | ||
) } | ||
</div> | ||
); | ||
} |
34 changes: 34 additions & 0 deletions
34
packages/edit-site/src/components/header/document-actions/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,34 @@ | ||
.edit-site-document-actions { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: space-evenly; | ||
|
||
.edit-site-document-actions__label { | ||
color: $gray-700; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
transition: height 0.25s; | ||
|
||
&.is-active { | ||
color: inherit; | ||
} | ||
|
||
&.edit-site-document-actions__title { | ||
height: 100%; | ||
// Otherwise, the secondary item still takes up space with height 0: | ||
flex-grow: 1; | ||
} | ||
|
||
&.edit-site-document-actions__secondary-item { | ||
height: 0; | ||
} | ||
} | ||
|
||
&.has-secondary-label { | ||
.edit-site-document-actions__label { | ||
height: 50%; | ||
} | ||
} | ||
} |
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
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