-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Update post author block functionality and visual parity #22877
Changes from all commits
0fcbec0
9c84c8b
ae05c4a
521d081
c61cd03
03cea3d
5df1635
136ecc5
e2be769
0381672
723e327
e0b57f3
e12fbb1
250238a
49af117
e99b3ae
4e8e8c5
458e095
039c4f5
49c0e79
f08f7f2
5aa9fca
5b044d7
b34e3d0
84a9ca4
d0c4412
d425b8b
a915828
f0e51cc
5addca1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,28 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { forEach } from 'lodash'; | ||
import { forEach, groupBy } from 'lodash'; | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useRef } from '@wordpress/element'; | ||
import { useRef, useMemo } from '@wordpress/element'; | ||
import { | ||
AlignmentToolbar, | ||
BlockControls, | ||
FontSizePicker, | ||
InspectorControls, | ||
RichText, | ||
__experimentalUseColors, | ||
BlockColorsStyleSelector, | ||
withFontSizes, | ||
} from '@wordpress/block-editor'; | ||
import { PanelBody, SelectControl, ToggleControl } from '@wordpress/components'; | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
const DEFAULT_AVATAR_SIZE = 24; | ||
const DEFAULT_CONTRAST_CHECK_FONT_SIZE = 12; | ||
|
||
function PostAuthorEdit( { | ||
isSelected, | ||
fontSize, | ||
setFontSize, | ||
context, | ||
attributes, | ||
setAttributes, | ||
} ) { | ||
function PostAuthorEdit( { isSelected, context, attributes, setAttributes } ) { | ||
const { postType, postId } = context; | ||
|
||
const { authorId, authorDetails, authors } = useSelect( | ||
|
@@ -56,6 +47,26 @@ function PostAuthorEdit( { | |
|
||
const { editEntityRecord } = useDispatch( 'core' ); | ||
|
||
// Need font size in number form for named presets to be used in contrastCheckers. | ||
const { fontSizes } = useSelect( ( select ) => | ||
select( 'core/block-editor' ).getSettings() | ||
); | ||
const fontSizeIndex = useMemo( () => groupBy( fontSizes, 'slug' ), [ | ||
fontSizes, | ||
] ); | ||
const contrastCheckFontSize = useMemo( | ||
() => | ||
// Custom size if set. | ||
attributes.style?.typography?.fontSize || | ||
// Size of preset/named value if set. | ||
fontSizeIndex[ attributes.fontSize ]?.[ 0 ].size || | ||
DEFAULT_CONTRAST_CHECK_FONT_SIZE, | ||
[ | ||
attributes.style?.typography?.fontSize, | ||
attributes.fontSize, | ||
fontSizeIndex, | ||
] | ||
); | ||
const ref = useRef(); | ||
const { | ||
TextColor, | ||
|
@@ -72,15 +83,15 @@ function PostAuthorEdit( { | |
{ | ||
backgroundColor: true, | ||
textColor: true, | ||
fontSize: fontSize.size, | ||
fontSize: contrastCheckFontSize, | ||
}, | ||
], | ||
colorDetector: { targetRef: ref }, | ||
colorPanelProps: { | ||
initialOpen: true, | ||
}, | ||
}, | ||
[ fontSize.size ] | ||
[ contrastCheckFontSize ] | ||
); | ||
|
||
const { align, showAvatar, showBio, byline } = attributes; | ||
|
@@ -95,17 +106,13 @@ function PostAuthorEdit( { | |
} ); | ||
} | ||
|
||
let avatarSize = DEFAULT_AVATAR_SIZE; | ||
if ( !! attributes.avatarSize ) { | ||
avatarSize = attributes.avatarSize; | ||
} | ||
|
||
const blockClassNames = classnames( 'wp-block-post-author', { | ||
[ fontSize.class ]: fontSize.class, | ||
} ); | ||
const blockInlineStyles = { | ||
fontSize: fontSize.size ? fontSize.size + 'px' : undefined, | ||
}; | ||
const classNames = useMemo( () => { | ||
return { | ||
block: classnames( 'wp-block-post-author', { | ||
[ `has-text-align-${ align }` ]: align, | ||
} ), | ||
}; | ||
}, [ align ] ); | ||
|
||
return ( | ||
<> | ||
|
@@ -153,12 +160,6 @@ function PostAuthorEdit( { | |
} | ||
/> | ||
</PanelBody> | ||
<PanelBody title={ __( 'Text settings' ) }> | ||
<FontSizePicker | ||
value={ fontSize.size } | ||
onChange={ setFontSize } | ||
/> | ||
</PanelBody> | ||
</InspectorControls> | ||
|
||
{ InspectorControlsColorPanel } | ||
|
@@ -180,19 +181,15 @@ function PostAuthorEdit( { | |
|
||
<TextColor> | ||
<BackgroundColor> | ||
<div | ||
ref={ ref } | ||
className={ classnames( blockClassNames, { | ||
[ `has-text-align-${ align }` ]: align, | ||
} ) } | ||
style={ blockInlineStyles } | ||
> | ||
<div ref={ ref } className={ classNames.block }> | ||
{ showAvatar && authorDetails && ( | ||
<div className="wp-block-post-author__avatar"> | ||
<img | ||
width={ avatarSize } | ||
width={ attributes.avatarSize } | ||
src={ | ||
authorDetails.avatar_urls[ avatarSize ] | ||
authorDetails.avatar_urls[ | ||
attributes.avatarSize | ||
] | ||
} | ||
alt={ authorDetails.name } | ||
/> | ||
|
@@ -205,12 +202,6 @@ function PostAuthorEdit( { | |
className="wp-block-post-author__byline" | ||
multiline={ false } | ||
placeholder={ __( 'Write byline …' ) } | ||
withoutInteractiveFormatting | ||
allowedFormats={ [ | ||
'core/bold', | ||
'core/italic', | ||
'core/strikethrough', | ||
] } | ||
Comment on lines
-208
to
-213
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reasoning behind this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I figured that if the goal was to have parity with paragraph block's functionalities, that the editable text should be able to have links and the remaining text formatting options. Removing these removes the restrictions and enables them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these specific restrictions were put in place because other formatting options don't make sense in the context of a byline. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why restrict it thought? If a user wants a word in their byline to be a link, then all of a sudden a link makes sense in the context of a byline for them. A similar argument for subscript/superscript, etc. |
||
value={ byline } | ||
onChange={ ( value ) => | ||
setAttributes( { byline: value } ) | ||
|
@@ -221,7 +212,7 @@ function PostAuthorEdit( { | |
{ authorDetails?.name } | ||
</p> | ||
{ showBio && ( | ||
<p className={ 'wp-block-post-author__bio' }> | ||
<p className="wp-block-post-author__bio"> | ||
{ authorDetails?.description } | ||
</p> | ||
) } | ||
|
@@ -233,4 +224,4 @@ function PostAuthorEdit( { | |
); | ||
} | ||
|
||
export default withFontSizes( 'fontSize' )( PostAuthorEdit ); | ||
export default PostAuthorEdit; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,36 @@ | ||
.block-editor__container .wp-block-post-author { | ||
.wp-block-post-author { | ||
display: flex; | ||
flex-wrap: wrap; | ||
line-height: 1.5; | ||
} | ||
|
||
.wp-block-post-author__byline { | ||
color: $dark-gray-300; | ||
font-size: $default-font-size; | ||
margin-top: 0; | ||
position: relative; | ||
font-style: normal; | ||
} | ||
.wp-block-post-author__byline { | ||
font-size: 0.5em; | ||
margin-top: 0; | ||
position: relative; | ||
font-style: normal; | ||
} | ||
|
||
.wp-block-post-author__content { | ||
flex-grow: 1; | ||
flex-basis: 0; | ||
} | ||
.wp-block-post-author__content { | ||
flex-grow: 1; | ||
flex-basis: 0; | ||
} | ||
|
||
.block-editor__container .wp-block-post-author__avatar img { | ||
margin: 0; | ||
} | ||
.wp-block-post-author__avatar img { | ||
margin: 0; | ||
} | ||
|
||
.block-editor__container .wp-block-post-author__name { | ||
margin: 0; | ||
margin-top: -$grid-unit-20/2; | ||
margin-bottom: -$grid-unit-20/2; | ||
font-weight: bold; | ||
} | ||
.wp-block-post-author__avatar { | ||
// To fix unknown space added in editor | ||
margin-bottom: -$grid-unit-10; | ||
} | ||
|
||
.wp-block-post-author__name { | ||
margin: 0; | ||
font-weight: bold; | ||
} | ||
|
||
.block-editor__container .wp-block-post-author__bio { | ||
margin: 0; | ||
margin-top: $grid-unit-20; | ||
.wp-block-post-author__bio { | ||
margin: 0 0 $grid-unit-10; | ||
font-size: 0.7em; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to change this to
__experimentalUseColors
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(In a different PR.)