Skip to content

Commit

Permalink
Latest Comments: Add typography support (#43310)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw authored Feb 14, 2023
1 parent 21f8cdb commit be6afb8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ Display a list of your most recent comments. ([Source](https://github.com/WordPr

- **Name:** core/latest-comments
- **Category:** widgets
- **Supports:** align, anchor, spacing (margin, padding), ~~html~~
- **Supports:** align, anchor, spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** commentsToShow, displayAvatar, displayDate, displayExcerpt

## Latest Posts
Expand Down
13 changes: 13 additions & 0 deletions packages/block-library/src/latest-comments/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@
"spacing": {
"margin": true,
"padding": true
},
"typography": {
"fontSize": true,
"lineHeight": true,
"__experimentalFontFamily": true,
"__experimentalFontWeight": true,
"__experimentalFontStyle": true,
"__experimentalTextTransform": true,
"__experimentalTextDecoration": true,
"__experimentalLetterSpacing": true,
"__experimentalDefaultControls": {
"fontSize": true
}
}
},
"editorStyle": "wp-block-latest-comments-editor",
Expand Down
11 changes: 9 additions & 2 deletions packages/block-library/src/latest-comments/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ export default function LatestComments( { attributes, setAttributes } ) {
const { commentsToShow, displayAvatar, displayDate, displayExcerpt } =
attributes;

const serverSideAttributes = {
...attributes,
style: {
...attributes?.style,
spacing: undefined,
},
};

return (
<div { ...useBlockProps() }>
<InspectorControls>
Expand Down Expand Up @@ -71,8 +79,7 @@ export default function LatestComments( { attributes, setAttributes } ) {
<Disabled>
<ServerSideRender
block="core/latest-comments"
attributes={ attributes }
skipBlockSupportAttributes
attributes={ serverSideAttributes }
// The preview uses the site's locale to make it more true to how
// the block appears on the frontend. Setting the locale
// explicitly prevents any middleware from setting it to 'user'.
Expand Down
32 changes: 25 additions & 7 deletions packages/block-library/src/latest-comments/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ ol.wp-block-latest-comments {
box-sizing: border-box;
}

// Following styles leverage :where so that typography block support styles and
// global styles apply when necessary.
:where(.wp-block-latest-comments:not([style*="line-height"] .wp-block-latest-comments__comment)) {
line-height: 1.1;
}

:where(.wp-block-latest-comments:not([style*="line-height"] .wp-block-latest-comments__comment-excerpt p)) {
line-height: 1.8;
}

.has-dates,
.has-excerpts {
:where(.wp-block-latest-comments:not([style*="line-height"])) {
line-height: 1.5;
}
}

// Higher specificity - target list via wrapper.
.wp-block-latest-comments .wp-block-latest-comments {
// Remove left spacing. Higher specificity required to
Expand All @@ -17,7 +34,6 @@ ol.wp-block-latest-comments {
}

.wp-block-latest-comments__comment {
line-height: 1.1;
list-style: none;
margin-bottom: 1em;

Expand All @@ -30,16 +46,10 @@ ol.wp-block-latest-comments {
margin-left: 3.25em;
}
}

.has-dates &,
.has-excerpts & {
line-height: 1.5;
}
}

.wp-block-latest-comments__comment-excerpt p {
font-size: 0.875em;
line-height: 1.8;
margin: 0.36em 0 1.4em;
}

Expand All @@ -57,3 +67,11 @@ ol.wp-block-latest-comments {
margin-right: 0.75em;
width: 2.5em;
}

// Enforce font size when user has made selection at the individual block level.
.wp-block-latest-comments[style*="font-size"],
.wp-block-latest-comments[class*="-font-size"] {
a {
font-size: inherit;
}
}

1 comment on commit be6afb8

@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 be6afb8.
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/4170542549
📝 Reported issues:

Please sign in to comment.