Skip to content
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

Pullquote: add block support #30834

Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7e5f7b8
Add border color, style and width support
aaronrobertshaw Mar 17, 2021
2dd305d
Fix lint error inherited from rebase
aaronrobertshaw Mar 23, 2021
adf5d20
Pass colors and gradients to border color control
aaronrobertshaw Mar 24, 2021
266c1fc
Return new object instead of mutating passed settings
aaronrobertshaw Mar 24, 2021
4236a62
Refactor individual feature support checks
aaronrobertshaw Mar 24, 2021
c8071d9
Add support for skipping serialization of border color
aaronrobertshaw Mar 25, 2021
e4b555f
Add comment about enforcing undefined for color slug
aaronrobertshaw Mar 25, 2021
12cdcee
Add comment explaining EMPTY_ARRAY avoiding rerenders
aaronrobertshaw Mar 25, 2021
4519318
Add clarifying comment around clearing `className`
aaronrobertshaw Mar 25, 2021
ba4914f
Add border block support to global styles sidebar
aaronrobertshaw Mar 31, 2021
c4e0e1d
initial commit
ramonjd Apr 12, 2021
3aaaa73
Merge remote-tracking branch 'upstream/update/border-block-support' i…
ramonjd Apr 12, 2021
7955fa9
Updating fixtures and deprecated fixtures.
ramonjd Apr 12, 2021
6a9ccab
Reverting the deprecated save function to ensure it's 1:1 with the pr…
ramonjd Apr 14, 2021
0c3f957
Removed block attributes from block.json that block supports injects
ramonjd Apr 14, 2021
4d26b54
Merge remote-tracking branch 'upstream/update/border-block-support' i…
ramonjd Apr 14, 2021
1ebb84e
Use gutenberg_block_has_support and unnest support checks
aaronrobertshaw Apr 14, 2021
a7e2e65
Refactor to handle disabled/support checks in root border hook
aaronrobertshaw Apr 14, 2021
9692633
Reverting border supports to false
ramonjd Apr 15, 2021
61d131c
Adding explicit border support for pullquote
ramonjd Apr 15, 2021
01ba1fc
Merge branch 'add/block-support-to-pullquote' of github.com:ramonjd/g…
ramonjd Apr 15, 2021
e02bd0f
Removed unused deps
ramonjd Apr 15, 2021
6428aaa
Overriding auto prettier formatting so the prettier linter doesn't co…
ramonjd Apr 15, 2021
3fbe815
Removed unnecessary comment block
ramonjd Apr 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/experimental-default-theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@
"units": [ "px", "em", "rem", "vh", "vw" ]
},
"border": {
"customColor": false,
"customRadius": false,
"customStyle": false,
"customWidth": false
"customColor": true,
"customRadius": true,
"customStyle": true,
"customWidth": true
}
}
}
Expand Down
22 changes: 12 additions & 10 deletions packages/block-library/src/pullquote/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,8 @@
"selector": "cite",
"default": ""
},
"mainColor": {
"type": "string"
},
"customMainColor": {
"type": "string"
},
"textColor": {
"type": "string"
},
"customTextColor": {
"type": "string"
}
},
"supports": {
Expand All @@ -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"
Expand Down
127 changes: 126 additions & 1 deletion packages/block-library/src/pullquote/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getColorObjectByAttributeValues,
RichText,
store as blockEditorStore,
useBlockProps,
} from '@wordpress/block-editor';
import { select } from '@wordpress/data';

Expand Down Expand Up @@ -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 (
<figure
{ ...useBlockProps.save( {
className: figureClasses,
style: figureStyles,
} ) }
>
<blockquote
className={ blockquoteClasses }
style={ blockquoteStyles }
>
<RichText.Content value={ value } multiline />
{ ! RichText.isEmpty( citation ) && (
<RichText.Content
tagName="cite"
value={ citation }
/>
) }
</blockquote>
</figure>
);
},
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,
Expand Down Expand Up @@ -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 ) {
Expand Down
Loading