Skip to content

Commit

Permalink
Button: Update to use border support provided styles and classes (#33017
Browse files Browse the repository at this point in the history
)
  • Loading branch information
aaronrobertshaw authored Jun 29, 2021
1 parent 37d6024 commit f1e2f3b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
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

0 comments on commit f1e2f3b

Please sign in to comment.