Skip to content

Commit

Permalink
Adding list styling to latest post block
Browse files Browse the repository at this point in the history
  • Loading branch information
benazeer-ben committed Dec 23, 2024
1 parent dad1fab commit 9e8378e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 14 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 @@ -406,7 +406,7 @@ Display a list of your most recent posts. ([Source](https://github.com/WordPress
- **Name:** core/latest-posts
- **Category:** widgets
- **Supports:** align, color (background, gradients, link, text), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** addLinkToFeaturedImage, categories, columns, displayAuthor, displayFeaturedImage, displayPostContent, displayPostContentRadio, displayPostDate, excerptLength, featuredImageAlign, featuredImageSizeHeight, featuredImageSizeSlug, featuredImageSizeWidth, order, orderBy, postLayout, postsToShow, selectedAuthor
- **Attributes:** addLinkToFeaturedImage, categories, columns, displayAuthor, displayFeaturedImage, displayPostContent, displayPostContentRadio, displayPostDate, enableBulletList, excerptLength, featuredImageAlign, featuredImageSizeHeight, featuredImageSizeSlug, featuredImageSizeWidth, order, orderBy, postLayout, postsToShow, selectedAuthor

## List

Expand Down
16 changes: 4 additions & 12 deletions packages/block-library/src/latest-posts/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@
"addLinkToFeaturedImage": {
"type": "boolean",
"default": false
},
"enableBulletList": {
"type": "boolean",
"default": true
}
},
"supports": {
Expand Down Expand Up @@ -111,18 +115,6 @@
"fontSize": true
}
},
"__experimentalBorder": {
"radius": true,
"color": true,
"width": true,
"style": true,
"__experimentalDefaultControls": {
"radius": true,
"color": true,
"width": true,
"style": true
}
},
"interactivity": {
"clientNavigation": true
}
Expand Down
15 changes: 15 additions & 0 deletions packages/block-library/src/latest-posts/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export default function LatestPostsEdit( { attributes, setAttributes } ) {
featuredImageSizeWidth,
featuredImageSizeHeight,
addLinkToFeaturedImage,
enableBulletList,
} = attributes;
const {
imageSizes,
Expand Down Expand Up @@ -227,6 +228,19 @@ export default function LatestPostsEdit( { attributes, setAttributes } ) {
const hasPosts = !! latestPosts?.length;
const inspectorControls = (
<InspectorControls>
{ postLayout === 'list' && (
<PanelBody title={ __( 'List Settings' ) }>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Enable Bullet List' ) }
checked={ enableBulletList }
onChange={ ( value ) =>
setAttributes( { enableBulletList: value } )
}
/>
</PanelBody>
) }

<PanelBody title={ __( 'Post content' ) }>
<ToggleControl
__nextHasNoMarginBottom
Expand Down Expand Up @@ -428,6 +442,7 @@ export default function LatestPostsEdit( { attributes, setAttributes } ) {
'has-dates': displayPostDate,
'has-author': displayAuthor,
[ `columns-${ columns }` ]: postLayout === 'grid',
'is-bulleted': enableBulletList,
} ),
} );

Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/latest-posts/editor.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.wp-block-latest-posts {
// Apply overflow for post items, so any floated featured images won't crop the focus style.
> li {
overflow: hidden;
// overflow: hidden; // Commented out to allow for list-style-type to be displayed in the list item.
}
}

Expand Down
3 changes: 3 additions & 0 deletions packages/block-library/src/latest-posts/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ function render_block_core_latest_posts( $attributes ) {
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
$classes[] = 'has-link-color';
}
if ( isset( $attributes['enableBulletList'] ) && $attributes['enableBulletList'] ) {
$classes[] = 'is-bulleted';
}

$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );

Expand Down
6 changes: 6 additions & 0 deletions packages/block-library/src/latest-posts/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
&.wp-block-latest-posts__list {
list-style: none;

&.is-bulleted {
li {
list-style-type: disc;
}
}

li {
clear: both;
overflow-wrap: break-word;
Expand Down

0 comments on commit 9e8378e

Please sign in to comment.