Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest Comments: Add typography support #43310

Merged
merged 3 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}