-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RNMobile] Fix background and text colour on pullquote block (#34451)
* [RNMobile] Fix background and text colour on pullquote block Fixes #34358 * Make sure that className can be undefined * update the mixed up styles colours * Destructure props for readability * Revert core edit function and replace with a native version * Add placeholder colour Co-authored-by: Gerardo Pacheco <gerardo.pacheco@automattic.com> * Add textAlign support Co-authored-by: Gerardo Pacheco <gerardo.pacheco@automattic.com> * Add textAlign support Co-authored-by: Gerardo Pacheco <gerardo.pacheco@automattic.com> * Removed unused classnames * Center the textAlignment by default Co-authored-by: Gerardo Pacheco <gerardo.pacheco@automattic.com> * Use the baseColour if it exists. * Minor comment update * Remove the is-style-solid-colour class case in styling the border * Mobile - Update CHANGELOG Co-authored-by: Gerardo Pacheco <gerardo.pacheco@automattic.com>
- Loading branch information
Showing
4 changed files
with
159 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
AlignmentControl, | ||
BlockControls, | ||
RichText, | ||
useBlockProps, | ||
getColorObjectByAttributeValues, | ||
__experimentalGetColorClassesAndStyles as getColorClassesAndStyles, | ||
} from '@wordpress/block-editor'; | ||
import { createBlock } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
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 || | ||
style?.baseColors?.color?.text | ||
); | ||
}; | ||
const getBorderColor = ( props ) => { | ||
const { wrapperProps } = props; | ||
const defaultColor = 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( { | ||
backgroundColor: getBackgroundColor( props ), | ||
borderColor: getBorderColor( props ), | ||
} ); | ||
|
||
const shouldShowCitation = ! RichText.isEmpty( citation ) || isSelected; | ||
|
||
return ( | ||
<> | ||
<BlockControls group="block"> | ||
<AlignmentControl | ||
value={ textAlign } | ||
onChange={ ( nextAlign ) => { | ||
setAttributes( { textAlign: nextAlign } ); | ||
} } | ||
/> | ||
</BlockControls> | ||
<Figure { ...blockProps }> | ||
<BlockQuote textColor={ getTextColor( props ) }> | ||
<RichText | ||
identifier="value" | ||
multiline | ||
value={ value } | ||
onChange={ ( nextValue ) => | ||
setAttributes( { | ||
value: nextValue, | ||
} ) | ||
} | ||
aria-label={ __( 'Pullquote text' ) } | ||
placeholder={ | ||
// translators: placeholder text used for the quote | ||
__( 'Add quote' ) | ||
} | ||
textAlign={ textAlign ?? 'center' } | ||
/> | ||
{ shouldShowCitation && ( | ||
<RichText | ||
identifier="citation" | ||
value={ citation } | ||
aria-label={ __( 'Pullquote citation text' ) } | ||
placeholder={ | ||
// translators: placeholder text used for the citation | ||
__( 'Add citation' ) | ||
} | ||
onChange={ ( nextCitation ) => | ||
setAttributes( { | ||
citation: nextCitation, | ||
} ) | ||
} | ||
__unstableMobileNoFocusOnMount | ||
textAlign={ textAlign ?? 'center' } | ||
__unstableOnSplitAtEnd={ () => | ||
insertBlocksAfter( | ||
createBlock( 'core/paragraph' ) | ||
) | ||
} | ||
/> | ||
) } | ||
</BlockQuote> | ||
</Figure> | ||
</> | ||
); | ||
} | ||
|
||
export default PullQuoteEdit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters