Skip to content

Commit

Permalink
Use Badge component in page markers (#68103)
Browse files Browse the repository at this point in the history
* Use Badge component in page markers
* Remove redundant prop.
* Remove import.
* Fix the title alignment.

Co-authored-by: juanfra <[email protected]>
Co-authored-by: tyxla <[email protected]>
Co-authored-by: jameskoster <[email protected]>
  • Loading branch information
4 people authored Dec 19, 2024
1 parent c01cb99 commit ec681ff
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 30 deletions.
10 changes: 6 additions & 4 deletions packages/editor/src/components/post-card-panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
__experimentalHStack as HStack,
__experimentalVStack as VStack,
__experimentalText as Text,
privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { store as coreStore } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
Expand All @@ -25,6 +26,7 @@ import { unlock } from '../../lock-unlock';
import PostActions from '../post-actions';
import usePageTypeBadge from '../../utils/pageTypeBadge';
import { getTemplateInfo } from '../../utils/get-template-info';
const { Badge } = unlock( componentsPrivateApis );

/**
* Renders a title of the post type and the available quick actions available within a 3-dot dropdown.
Expand Down Expand Up @@ -109,11 +111,11 @@ export default function PostCardPanel( {
className="editor-post-card-panel__title"
as="h2"
>
{ title }
<span className="editor-post-card-panel__title-name">
{ title }
</span>
{ pageTypeBadge && postIds.length === 1 && (
<span className="editor-post-card-panel__title-badge">
{ pageTypeBadge }
</span>
<Badge>{ pageTypeBadge }</Badge>
) }
</Text>
<PostActions
Expand Down
17 changes: 4 additions & 13 deletions packages/editor/src/components/post-card-panel/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
&.editor-post-card-panel__title {
@include heading-medium();
margin: 0;
padding: 2px 0;
display: flex;
align-items: center;
flex-wrap: wrap;
Expand All @@ -34,19 +33,11 @@
margin-bottom: $grid-unit-10;
}

.editor-post-card-panel__title-name {
padding: 2px 0;
}

.editor-post-card-panel__description {
color: $gray-700;
}
}

.editor-post-card-panel__title-badge {
background: $gray-100;
color: $gray-800;
padding: 0 $grid-unit-05;
border-radius: $radius-small;
font-size: 12px;
font-weight: 400;
flex-shrink: 0;
line-height: $grid-unit-05 * 5;
display: inline-block;
}
10 changes: 0 additions & 10 deletions packages/fields/src/fields/page-title/style.scss

This file was deleted.

7 changes: 5 additions & 2 deletions packages/fields/src/fields/page-title/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import type { Settings } from '@wordpress/core-data';
import { privateApis as componentsPrivateApis } from '@wordpress/components';

/**
* Internal dependencies
*/
import type { CommonPost } from '../../types';
import { BaseTitleView } from '../title/view';
import { unlock } from '../../lock-unlock';
const { Badge } = unlock( componentsPrivateApis );

export default function PageTitleView( { item }: { item: CommonPost } ) {
const { frontPageId, postsPageId } = useSelect( ( select ) => {
Expand All @@ -27,11 +30,11 @@ export default function PageTitleView( { item }: { item: CommonPost } ) {
return (
<BaseTitleView item={ item } className="fields-field__page-title">
{ [ frontPageId, postsPageId ].includes( item.id as number ) && (
<span className="fields-field__page-title__badge">
<Badge>
{ item.id === frontPageId
? __( 'Homepage' )
: __( 'Posts Page' ) }
</span>
</Badge>
) }
</BaseTitleView>
);
Expand Down
1 change: 0 additions & 1 deletion packages/fields/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
@import "./fields/featured-image/style.scss";
@import "./fields/template/style.scss";
@import "./fields/title/style.scss";
@import "./fields/page-title/style.scss";
@import "./fields/pattern-title/style.scss";

1 comment on commit ec681ff

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in ec681ff.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12415456674
📝 Reported issues:

Please sign in to comment.