diff --git a/lib/experimental-default-theme.json b/lib/experimental-default-theme.json
index dea9d96966d34e..088be16ac71e5c 100644
--- a/lib/experimental-default-theme.json
+++ b/lib/experimental-default-theme.json
@@ -1,5 +1,13 @@
{
"settings": {
+ "core/pullquote": {
+ "border": {
+ "customColor": true,
+ "customRadius": true,
+ "customStyle": true,
+ "customWidth": true
+ }
+ },
"defaults": {
"color": {
"palette": [
diff --git a/packages/block-library/src/pullquote/block.json b/packages/block-library/src/pullquote/block.json
index e8a0fd00d52b97..80a3fc95b9550f 100644
--- a/packages/block-library/src/pullquote/block.json
+++ b/packages/block-library/src/pullquote/block.json
@@ -15,17 +15,8 @@
"selector": "cite",
"default": ""
},
- "mainColor": {
- "type": "string"
- },
- "customMainColor": {
- "type": "string"
- },
"textColor": {
"type": "string"
- },
- "customTextColor": {
- "type": "string"
}
},
"supports": {
@@ -35,7 +26,18 @@
"right",
"wide",
"full"
- ]
+ ],
+ "color": {
+ "gradients": true,
+ "background": true,
+ "link": true
+ },
+ "__experimentalBorder": {
+ "color": true,
+ "radius": true,
+ "style": true,
+ "width": true
+ }
},
"editorStyle": "wp-block-pullquote-editor",
"style": "wp-block-pullquote"
diff --git a/packages/block-library/src/pullquote/deprecated.js b/packages/block-library/src/pullquote/deprecated.js
index 5588bc0239085d..b888da645d0c6c 100644
--- a/packages/block-library/src/pullquote/deprecated.js
+++ b/packages/block-library/src/pullquote/deprecated.js
@@ -12,6 +12,7 @@ import {
getColorObjectByAttributeValues,
RichText,
store as blockEditorStore,
+ useBlockProps,
} from '@wordpress/block-editor';
import { select } from '@wordpress/data';
@@ -57,7 +58,131 @@ function parseBorderColor( styleString ) {
}
}
+// TODO: this is ripe for a bit of a clean up according to the example in https://developer.wordpress.org/block-editor/reference-guides/block-api/block-deprecation/#example
const deprecated = [
+ {
+ attributes: {
+ ...blockAttributes,
+ },
+ save( { attributes } ) {
+ const {
+ mainColor,
+ customMainColor,
+ customTextColor,
+ textColor,
+ value,
+ citation,
+ className,
+ } = attributes;
+
+ const isSolidColorStyle = includes( className, SOLID_COLOR_CLASS );
+
+ let figureClasses, figureStyles;
+
+ // Is solid color style
+ if ( isSolidColorStyle ) {
+ const backgroundClass = getColorClassName(
+ 'background-color',
+ mainColor
+ );
+
+ figureClasses = classnames( {
+ 'has-background': backgroundClass || customMainColor,
+ [ backgroundClass ]: backgroundClass,
+ } );
+
+ figureStyles = {
+ backgroundColor: backgroundClass
+ ? undefined
+ : customMainColor,
+ };
+ // Is normal style and a custom color is being used ( we can set a style directly with its value)
+ } else if ( customMainColor ) {
+ figureStyles = {
+ borderColor: customMainColor,
+ };
+ }
+
+ const blockquoteTextColorClass = getColorClassName(
+ 'color',
+ textColor
+ );
+ const blockquoteClasses =
+ ( textColor || customTextColor ) &&
+ classnames( 'has-text-color', {
+ [ blockquoteTextColorClass ]: blockquoteTextColorClass,
+ } );
+
+ const blockquoteStyles = blockquoteTextColorClass
+ ? undefined
+ : { color: customTextColor };
+
+ return (
+
+
+
+ { ! RichText.isEmpty( citation ) && (
+
+ ) }
+
+
+ );
+ },
+ migrate( {
+ className,
+ mainColor,
+ customMainColor,
+ customTextColor,
+ ...attributes
+ } ) {
+ const isSolidColorStyle = includes( className, SOLID_COLOR_CLASS );
+
+ const style = {};
+ // Block supports: Set style.border.color if a deprecated block has a default style and a `customMainColor` attribute.
+ if ( ! isSolidColorStyle && customMainColor ) {
+ style.border = {
+ color: customMainColor,
+ };
+ }
+
+ // Block supports: Set style.color.background if a deprecated block has a solid style and a `customMainColor` attribute.
+ if ( isSolidColorStyle && customMainColor ) {
+ style.color = {
+ background: customMainColor,
+ };
+ }
+
+ // Block supports: Set style.color.text if a deprecated block has a `customTextColor` attribute.
+ if ( customTextColor ) {
+ style.color = {
+ ...style?.color,
+ text: customTextColor,
+ };
+ }
+
+ return {
+ className, // TODO: Do we need to filter out unnecessary classnames, e.g., `has-background` since block supports takes care of them?
+ backgroundColor: isSolidColorStyle ? mainColor : undefined,
+ borderColor: isSolidColorStyle ? undefined : mainColor,
+ style,
+ ...attributes,
+ mainColor: undefined, // TODO: Do we need to do this?
+ customMainColor: undefined,
+ customTextColor: undefined,
+ };
+ },
+ },
{
attributes: {
...blockAttributes,
@@ -156,7 +281,7 @@ const deprecated = [
const isSolidColorStyle = includes( className, SOLID_COLOR_CLASS );
// If is the default style, and a main color is set,
// migrate the main color value into a custom color.
- // The custom color value is retrived by parsing the figure styles.
+ // The custom color value is retrieved by parsing the figure styles.
if ( ! isSolidColorStyle && mainColor && figureStyle ) {
const borderColor = parseBorderColor( figureStyle );
if ( borderColor ) {
diff --git a/packages/block-library/src/pullquote/edit.js b/packages/block-library/src/pullquote/edit.js
index 58830ff3508549..e00a6ec3f67f5e 100644
--- a/packages/block-library/src/pullquote/edit.js
+++ b/packages/block-library/src/pullquote/edit.js
@@ -1,22 +1,8 @@
-/**
- * External dependencies
- */
-import classnames from 'classnames';
-import { includes } from 'lodash';
-
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
-import { Platform, useEffect, useRef } from '@wordpress/element';
-import {
- RichText,
- ContrastChecker,
- InspectorControls,
- withColors,
- PanelColorSettings,
- useBlockProps,
-} from '@wordpress/block-editor';
+import { RichText, withColors, useBlockProps } from '@wordpress/block-editor';
import { createBlock } from '@wordpress/blocks';
/**
@@ -28,165 +14,60 @@ import { BlockQuote } from './blockquote';
/**
* Internal dependencies
*/
-import { SOLID_COLOR_CLASS } from './shared';
function PullQuoteEdit( {
- colorUtils,
- textColor,
- attributes: { value, citation },
+ attributes,
setAttributes,
- setTextColor,
- setMainColor,
- mainColor,
isSelected,
insertBlocksAfter,
} ) {
- const wasTextColorAutomaticallyComputed = useRef( false );
+ const { value, citation } = attributes;
const blockProps = useBlockProps();
- const { style = {}, className } = blockProps;
- const isSolidColorStyle = includes( className, SOLID_COLOR_CLASS );
- const newBlockProps = {
- ...blockProps,
- className: classnames( className, {
- 'has-background': isSolidColorStyle && mainColor.color,
- [ mainColor.class ]: isSolidColorStyle && mainColor.class,
- } ),
- style: isSolidColorStyle
- ? { ...style, backgroundColor: mainColor.color }
- : { ...style, borderColor: mainColor.color },
- };
-
- function pullQuoteMainColorSetter( colorValue ) {
- const needTextColor =
- ! textColor.color || wasTextColorAutomaticallyComputed.current;
- const shouldSetTextColor = isSolidColorStyle && needTextColor;
-
- if ( isSolidColorStyle ) {
- // If we use the solid color style, set the color using the normal mechanism.
- setMainColor( colorValue );
- } else {
- // If we use the default style, set the color as a custom color to force the usage of an inline style.
- // Default style uses a border color for which classes are not available.
- setAttributes( { customMainColor: colorValue } );
- }
-
- if ( shouldSetTextColor ) {
- if ( colorValue ) {
- wasTextColorAutomaticallyComputed.current = true;
- setTextColor( colorUtils.getMostReadableColor( colorValue ) );
- } else if ( wasTextColorAutomaticallyComputed.current ) {
- // We have to unset our previously computed text color on unsetting the main color.
- wasTextColorAutomaticallyComputed.current = false;
- setTextColor();
- }
- }
- }
-
- function pullQuoteTextColorSetter( colorValue ) {
- setTextColor( colorValue );
- wasTextColorAutomaticallyComputed.current = false;
- }
-
- useEffect( () => {
- // If the block includes a named color and we switched from the
- // solid color style to the default style.
- if ( mainColor && ! isSolidColorStyle ) {
- // Remove the named color, and set the color as a custom color.
- // This is done because named colors use classes, in the default style we use a border color,
- // and themes don't set classes for border colors.
- setAttributes( {
- mainColor: undefined,
- customMainColor: mainColor.color,
- } );
- }
- }, [ isSolidColorStyle, mainColor ] );
+ const shouldShowCitation = ! RichText.isEmpty( citation ) || isSelected;
return (
- <>
-
-
+
+
+ setAttributes( {
+ value: nextValue,
} )
}
- >
+ aria-label={ __( 'Pullquote text' ) }
+ placeholder={
+ // translators: placeholder text used for the quote
+ __( 'Add quote' )
+ }
+ textAlign="center"
+ />
+ { shouldShowCitation && (
+ identifier="citation"
+ value={ citation }
+ aria-label={ __( 'Pullquote citation text' ) }
+ placeholder={
+ // translators: placeholder text used for the citation
+ __( 'Add citation' )
+ }
+ onChange={ ( nextCitation ) =>
setAttributes( {
- value: nextValue,
+ citation: nextCitation,
} )
}
- aria-label={ __( 'Pullquote text' ) }
- placeholder={
- // translators: placeholder text used for the quote
- __( 'Add quote' )
- }
+ className="wp-block-pullquote__citation"
+ __unstableMobileNoFocusOnMount
textAlign="center"
+ __unstableOnSplitAtEnd={ () =>
+ insertBlocksAfter( createBlock( 'core/paragraph' ) )
+ }
/>
- { ( ! RichText.isEmpty( citation ) || isSelected ) && (
-
- setAttributes( {
- citation: nextCitation,
- } )
- }
- className="wp-block-pullquote__citation"
- __unstableMobileNoFocusOnMount
- textAlign="center"
- __unstableOnSplitAtEnd={ () =>
- insertBlocksAfter(
- createBlock( 'core/paragraph' )
- )
- }
- />
- ) }
-
-
- { Platform.OS === 'web' && (
-
-
- { isSolidColorStyle && (
-
- ) }
-
-
- ) }
- >
+ ) }
+
+
);
}
diff --git a/packages/block-library/src/pullquote/save.js b/packages/block-library/src/pullquote/save.js
index 9059ab9ed497fa..83d291d87ec5fb 100644
--- a/packages/block-library/src/pullquote/save.js
+++ b/packages/block-library/src/pullquote/save.js
@@ -1,84 +1,17 @@
-/**
- * External dependencies
- */
-import classnames from 'classnames';
-import { includes } from 'lodash';
-
/**
* WordPress dependencies
*/
-import {
- getColorClassName,
- RichText,
- useBlockProps,
-} from '@wordpress/block-editor';
-
-/**
- * Internal dependencies
- */
-import { SOLID_COLOR_CLASS } from './shared';
+import { RichText, useBlockProps } from '@wordpress/block-editor';
export default function save( { attributes } ) {
- const {
- mainColor,
- customMainColor,
- textColor,
- customTextColor,
- value,
- citation,
- className,
- } = attributes;
-
- const isSolidColorStyle = includes( className, SOLID_COLOR_CLASS );
-
- let figureClasses, figureStyles;
-
- // Is solid color style
- if ( isSolidColorStyle ) {
- const backgroundClass = getColorClassName(
- 'background-color',
- mainColor
- );
-
- figureClasses = classnames( {
- 'has-background': backgroundClass || customMainColor,
- [ backgroundClass ]: backgroundClass,
- } );
-
- figureStyles = {
- backgroundColor: backgroundClass ? undefined : customMainColor,
- };
- // Is normal style and a custom color is being used ( we can set a style directly with its value)
- } else if ( customMainColor ) {
- figureStyles = {
- borderColor: customMainColor,
- };
- }
-
- const blockquoteTextColorClass = getColorClassName( 'color', textColor );
- const blockquoteClasses =
- ( textColor || customTextColor ) &&
- classnames( 'has-text-color', {
- [ blockquoteTextColorClass ]: blockquoteTextColorClass,
- } );
-
- const blockquoteStyles = blockquoteTextColorClass
- ? undefined
- : { color: customTextColor };
+ const { value, citation } = attributes;
+ const shouldShowCitation = ! RichText.isEmpty( citation );
return (
-
-
+
+
- { ! RichText.isEmpty( citation ) && (
+ { shouldShowCitation && (
) }
diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-3.serialized.html b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-3.serialized.html
index 786f15f7b4293e..96cea0add22c10 100644
--- a/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-3.serialized.html
+++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-3.serialized.html
@@ -1,3 +1,3 @@
-
-pullquote
+
+pullquote
diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.html b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.html
new file mode 100644
index 00000000000000..becc245752441e
--- /dev/null
+++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.html
@@ -0,0 +1,3 @@
+
+pullquote
before block supports
+
diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.json b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.json
new file mode 100644
index 00000000000000..454283cd423a15
--- /dev/null
+++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.json
@@ -0,0 +1,17 @@
+[
+ {
+ "clientId": "_clientId_0",
+ "name": "core/pullquote",
+ "isValid": true,
+ "attributes": {
+ "className": "has-background has-black-background-color is-style-solid-color",
+ "backgroundColor": "black",
+ "style": {},
+ "value": "pullquote
",
+ "citation": "before block supports",
+ "textColor": "white"
+ },
+ "innerBlocks": [],
+ "originalContent": "pullquote
before block supports
"
+ }
+]
diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.parsed.json b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.parsed.json
new file mode 100644
index 00000000000000..f7ba9deaea6383
--- /dev/null
+++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.parsed.json
@@ -0,0 +1,24 @@
+[
+ {
+ "blockName": "core/pullquote",
+ "attrs": {
+ "mainColor": "black",
+ "textColor": "white",
+ "className": "is-style-solid-color"
+ },
+ "innerBlocks": [],
+ "innerHTML": "\npullquote
before block supports
\n",
+ "innerContent": [
+ "\npullquote
before block supports
\n"
+ ]
+ },
+ {
+ "blockName": null,
+ "attrs": {},
+ "innerBlocks": [],
+ "innerHTML": "\n",
+ "innerContent": [
+ "\n"
+ ]
+ }
+]
diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.serialized.html b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.serialized.html
new file mode 100644
index 00000000000000..e88883be243e06
--- /dev/null
+++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__deprecated-4.serialized.html
@@ -0,0 +1,3 @@
+
+pullquote
before block supports
+
diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.html b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.html
index 473e6ecefd480d..b3a09d2c22939b 100644
--- a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.html
+++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.html
@@ -1,3 +1,3 @@
-
-Pullquote custom color
my citation
+
+Pullquote custom color
before block supports
diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.json b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.json
index a5e6479043d1a5..aa9faa4d7b6a69 100644
--- a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.json
+++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.json
@@ -5,12 +5,17 @@
"isValid": true,
"attributes": {
"value": "Pullquote custom color
",
- "citation": "my citation",
- "customMainColor": "#2207d0",
- "textColor": "subtle-background",
- "className": "has-background is-style-default"
+ "citation": "before block supports",
+ "textColor": "white",
+ "className": "is-style-default",
+ "backgroundColor": "blue",
+ "style": {
+ "border": {
+ "color": "#2207d0"
+ }
+ }
},
"innerBlocks": [],
- "originalContent": "Pullquote custom color
my citation
"
+ "originalContent": "Pullquote custom color
before block supports
"
}
]
diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.parsed.json b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.parsed.json
index 56004374d15637..5a2208c2278bd0 100644
--- a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.parsed.json
+++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.parsed.json
@@ -2,14 +2,19 @@
{
"blockName": "core/pullquote",
"attrs": {
- "customMainColor": "#2207d0",
- "textColor": "subtle-background",
- "className": "has-background is-style-default"
+ "backgroundColor": "blue",
+ "textColor": "white",
+ "style": {
+ "border": {
+ "color": "#2207d0"
+ }
+ },
+ "className": "is-style-default"
},
"innerBlocks": [],
- "innerHTML": "\nPullquote custom color
my citation
\n",
+ "innerHTML": "\nPullquote custom color
before block supports
\n",
"innerContent": [
- "\nPullquote custom color
my citation
\n"
+ "\nPullquote custom color
before block supports
\n"
]
},
{
diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.serialized.html b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.serialized.html
index 473e6ecefd480d..8cb5047d1c7414 100644
--- a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.serialized.html
+++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color.serialized.html
@@ -1,3 +1,3 @@
-
-Pullquote custom color
my citation
+
+Pullquote custom color
before block supports
diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.html b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.html
new file mode 100644
index 00000000000000..999c7fffaac58f
--- /dev/null
+++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.html
@@ -0,0 +1,3 @@
+
+pullquote
before block supports
+
diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.json b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.json
new file mode 100644
index 00000000000000..7ba1cdebd13c3c
--- /dev/null
+++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.json
@@ -0,0 +1,20 @@
+[
+ {
+ "clientId": "_clientId_0",
+ "name": "core/pullquote",
+ "isValid": true,
+ "attributes": {
+ "className": "has-background is-style-solid-color",
+ "style": {
+ "color": {
+ "background": "#48ba90",
+ "text": "#1567eb"
+ }
+ },
+ "value": "pullquote
",
+ "citation": "before block supports"
+ },
+ "innerBlocks": [],
+ "originalContent": "pullquote
before block supports
"
+ }
+]
diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.parsed.json b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.parsed.json
new file mode 100644
index 00000000000000..5a938647a657d6
--- /dev/null
+++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.parsed.json
@@ -0,0 +1,24 @@
+[
+ {
+ "blockName": "core/pullquote",
+ "attrs": {
+ "customMainColor": "#48ba90",
+ "customTextColor": "#1567eb",
+ "className": "has-background is-style-solid-color"
+ },
+ "innerBlocks": [],
+ "innerHTML": "\npullquote
before block supports
\n",
+ "innerContent": [
+ "\npullquote
before block supports
\n"
+ ]
+ },
+ {
+ "blockName": null,
+ "attrs": {},
+ "innerBlocks": [],
+ "innerHTML": "\n",
+ "innerContent": [
+ "\n"
+ ]
+ }
+]
diff --git a/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.serialized.html b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.serialized.html
new file mode 100644
index 00000000000000..37bf3083dd79ea
--- /dev/null
+++ b/packages/e2e-tests/fixtures/blocks/core__pullquote__main-color__deprecated-4.serialized.html
@@ -0,0 +1,3 @@
+
+pullquote
before block supports
+