-
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.
- Loading branch information
Showing
4 changed files
with
98 additions
and
4 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
packages/edit-site/src/components/post-edit-header/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,84 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
__experimentalHStack as HStack, | ||
__experimentalVStack as VStack, | ||
Icon, | ||
__experimentalText as Text, | ||
} from '@wordpress/components'; | ||
import { useMemo } from '@wordpress/element'; | ||
import { | ||
privateApis as editorPrivateApis, | ||
store as editorStore, | ||
} from '@wordpress/editor'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { sprintf, __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { unlock } from '../../lock-unlock'; | ||
|
||
const { PostCardPanel } = unlock( editorPrivateApis ); | ||
|
||
export default function PostEditHeader( { postType, postId } ) { | ||
const ids = useMemo( () => postId.split( ',' ), [ postId ] ); | ||
const { icon, labels } = useSelect( | ||
( select ) => { | ||
const { getEditedEntityRecord, getPostType } = select( coreStore ); | ||
const _record = getEditedEntityRecord( | ||
'postType', | ||
postType, | ||
ids[ 0 ] | ||
); | ||
|
||
return { | ||
icon: unlock( select( editorStore ) ).getPostIcon( postType, { | ||
area: _record?.area, | ||
} ), | ||
labels: getPostType( postType )?.labels, | ||
}; | ||
}, | ||
[ ids, postType ] | ||
); | ||
|
||
if ( ids.length === 1 ) { | ||
return <PostCardPanel postType={ postType } postId={ ids[ 0 ] } />; | ||
} | ||
|
||
return ( | ||
<VStack spacing={ 1 } className="edit-site-post-edit-header"> | ||
<HStack spacing={ 2 } align="flex-start" justify="normal"> | ||
<Icon | ||
className="edit-site-post-edit-header__icon" | ||
icon={ icon } | ||
/> | ||
<Text | ||
numberOfLines={ 2 } | ||
truncate | ||
className="edit-site-post-edit-header__title" | ||
weight={ 500 } | ||
as="h2" | ||
lineHeight="20px" | ||
> | ||
{ labels?.name && | ||
sprintf( | ||
// translators: %i number of selected items %s: Name of the plural post type e.g: "Posts". | ||
__( '%i %s' ), | ||
ids.length, | ||
labels?.name | ||
) } | ||
</Text> | ||
</HStack> | ||
<Text className="edit-site-post-edit-header__description"> | ||
{ sprintf( | ||
// translators: %s: Name of the plural post type e.g: "Posts". | ||
__( 'Changes will be applied to all selected %s.' ), | ||
labels?.name.toLowerCase() | ||
) } | ||
</Text> | ||
</VStack> | ||
); | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/edit-site/src/components/post-edit-header/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,9 @@ | ||
.edit-site-post-edit-header { | ||
.edit-site-post-edit-header__description { | ||
color: $gray-700; | ||
} | ||
|
||
.edit-site-post-edit-header__title { | ||
padding: 2px 0; | ||
} | ||
} |
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