diff --git a/packages/block-library/src/pullquote/edit.js b/packages/block-library/src/pullquote/edit.js index 1b582b595957d5..0084ab99a139ec 100644 --- a/packages/block-library/src/pullquote/edit.js +++ b/packages/block-library/src/pullquote/edit.js @@ -12,8 +12,6 @@ import { BlockControls, RichText, useBlockProps, - getColorObjectByAttributeValues, - __experimentalGetColorClassesAndStyles as getColorClassesAndStyles, } from '@wordpress/block-editor'; import { createBlock } from '@wordpress/blocks'; @@ -23,60 +21,22 @@ import { createBlock } from '@wordpress/blocks'; import { Figure } from './figure'; import { BlockQuote } from './blockquote'; -const getBackgroundColor = ( { attributes, colors, style } ) => { - const { backgroundColor } = attributes; - - const colorProps = getColorClassesAndStyles( attributes ); - const colorObject = getColorObjectByAttributeValues( - colors, - backgroundColor - ); - - return ( - colorObject?.color || - colorProps.style?.backgroundColor || - colorProps.style?.background || - style?.backgroundColor - ); -}; - -const getTextColor = ( { attributes, colors, style } ) => { - const colorProps = getColorClassesAndStyles( attributes ); - const colorObject = getColorObjectByAttributeValues( - colors, - attributes.textColor - ); - - return colorObject?.color || colorProps.style?.color || style?.color; -}; -const getBorderColor = ( props ) => { - const { wrapperProps, attributes } = props; - const { className } = attributes; - - // Checking for the is-style-solid-color we can better approximate the pull quote style - const defaultColor = - className?.search( 'is-style-solid-color' ) !== -1 - ? getBackgroundColor( props ) - : getTextColor( props ); - - return wrapperProps?.style?.borderColor || defaultColor; -}; /** * Internal dependencies */ -function PullQuoteEdit( props ) { - const { attributes, setAttributes, isSelected, insertBlocksAfter } = props; +function PullQuoteEdit( { + attributes, + setAttributes, + isSelected, + insertBlocksAfter, +} ) { const { textAlign, citation, value } = attributes; - const blockProps = useBlockProps( { className: classnames( { [ `has-text-align-${ textAlign }` ]: textAlign, } ), - backgroundColor: getBackgroundColor( props ), - borderColor: getBorderColor( props ), } ); - const shouldShowCitation = ! RichText.isEmpty( citation ) || isSelected; return ( @@ -90,7 +50,7 @@ function PullQuoteEdit( props ) { />
-
+
{ + const { backgroundColor } = attributes; + + const colorProps = getColorClassesAndStyles( attributes ); + const colorObject = getColorObjectByAttributeValues( + colors, + backgroundColor + ); + + return ( + colorObject?.color || + colorProps.style?.backgroundColor || + colorProps.style?.background || + style?.backgroundColor + ); +}; + +const getTextColor = ( { attributes, colors, style } ) => { + const colorProps = getColorClassesAndStyles( attributes ); + const colorObject = getColorObjectByAttributeValues( + colors, + attributes.textColor + ); + + return colorObject?.color || colorProps.style?.color || style?.color; +}; +const getBorderColor = ( props ) => { + const { wrapperProps, attributes } = props; + const { className } = attributes; + + // Checking for the is-style-solid-color we can better approximate the pull quote style + const defaultColor = + className?.search( 'is-style-solid-color' ) !== -1 + ? getBackgroundColor( props ) + : getTextColor( props ); + + return wrapperProps?.style?.borderColor || defaultColor; +}; +/** + * Internal dependencies + */ + +function PullQuoteEdit( props ) { + const { attributes, setAttributes, isSelected, insertBlocksAfter } = props; + const { textAlign, citation, value } = attributes; + + const blockProps = useBlockProps( { + className: classnames( { + [ `has-text-align-${ textAlign }` ]: textAlign, + } ), + backgroundColor: getBackgroundColor( props ), + borderColor: getBorderColor( props ), + } ); + + const shouldShowCitation = ! RichText.isEmpty( citation ) || isSelected; + + return ( + <> + + { + setAttributes( { textAlign: nextAlign } ); + } } + /> + +
+
+ + setAttributes( { + value: nextValue, + } ) + } + aria-label={ __( 'Pullquote text' ) } + placeholder={ + // translators: placeholder text used for the quote + __( 'Add quote' ) + } + textAlign="center" + /> + { shouldShowCitation && ( + + setAttributes( { + citation: nextCitation, + } ) + } + className="wp-block-pullquote__citation" + __unstableMobileNoFocusOnMount + textAlign="center" + __unstableOnSplitAtEnd={ () => + insertBlocksAfter( + createBlock( 'core/paragraph' ) + ) + } + /> + ) } +
+
+ + ); +} + +export default PullQuoteEdit;