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

Button: Update to use border support provided styles and classes #33017

Merged
merged 3 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion packages/block-library/src/button/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const migrateBorderRadius = ( attributes ) => {
...newAttributes,
style: {
...newAttributes.style,
border: { radius: borderRadius },
border: { radius: `${ borderRadius }px` },
},
};
};
Expand Down
10 changes: 7 additions & 3 deletions packages/block-library/src/button/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
InspectorAdvancedControls,
RichText,
useBlockProps,
__experimentalUseBorderProps as useBorderProps,
__experimentalUseColorProps as useColorProps,
__experimentalLinkControl as LinkControl,
} from '@wordpress/block-editor';
Expand Down Expand Up @@ -196,7 +197,7 @@ function ButtonEdit( props ) {
setAttributes( { text: newText.replace( /<\/?a[^>]*>/g, '' ) } );
};

const borderRadius = style?.border?.radius;
const borderProps = useBorderProps( attributes );
const colorProps = useColorProps( attributes );
const ref = useRef();
const blockProps = useBlockProps( { ref } );
Expand All @@ -220,12 +221,15 @@ function ButtonEdit( props ) {
className,
'wp-block-button__link',
colorProps.className,
borderProps.className,
{
'no-border-radius': borderRadius === 0,
// For backwards compatibility add style that isn't
// provided via block support.
'no-border-radius': style?.border?.radius === 0,
}
) }
style={ {
borderRadius: borderRadius ? borderRadius : undefined,
...borderProps.style,
...colorProps.style,
} }
onSplit={ ( value ) =>
Expand Down
10 changes: 7 additions & 3 deletions packages/block-library/src/button/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import classnames from 'classnames';
import {
RichText,
useBlockProps,
__experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles,
__experimentalGetColorClassesAndStyles as getColorClassesAndStyles,
} from '@wordpress/block-editor';

Expand All @@ -28,17 +29,20 @@ export default function save( { attributes, className } ) {
return null;
}

const borderRadius = style?.border?.radius;
const borderProps = getBorderClassesAndStyles( attributes );
const colorProps = getColorClassesAndStyles( attributes );
const buttonClasses = classnames(
'wp-block-button__link',
colorProps.className,
borderProps.className,
{
'no-border-radius': borderRadius === 0,
// For backwards compatibility add style that isn't provided via
// block support.
'no-border-radius': style?.border?.radius === 0,
}
);
const buttonStyle = {
borderRadius: borderRadius ? borderRadius : undefined,
...borderProps.style,
...colorProps.style,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"text": "My button",
"style": {
"border": {
"radius": 25
"radius": "25px"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- wp:button {"style":{"border":{"radius":25}}} -->
<!-- wp:button {"style":{"border":{"radius":"25px"}}} -->
<div class="wp-block-button"><a class="wp-block-button__link" style="border-radius:25px">My button</a></div>
<!-- /wp:button -->

Expand Down