Skip to content

Commit

Permalink
Button block: Add Typography support (#30394)
Browse files Browse the repository at this point in the history
* Button block: Add support for font size

* Use block style for has-custom-font-size class

* Add has-custom-font-size class to save
  • Loading branch information
lukecarbis authored Apr 7, 2021
1 parent e917cdb commit 6604dd3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/block-library/src/button/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@
"__experimentalSkipSerialization": true,
"gradients": true
},
"fontSize": true,
"reusable": false,
"__experimentalFontFamily": true,
"__experimentalSelector": ".wp-block-button__link"
},
"editorStyle": "wp-block-button-editor",
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/button/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ function ButtonEdit( props ) {
{ ...blockProps }
className={ classnames( blockProps.className, {
[ `has-custom-width wp-block-button__width-${ width }` ]: width,
[ `has-custom-font-size` ]: blockProps.style.fontSize,
} ) }
>
<RichText
Expand Down
3 changes: 3 additions & 0 deletions packages/block-library/src/button/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import getColorAndStyleProps from './color-props';
export default function save( { attributes, className } ) {
const {
borderRadius,
fontSize,
linkTarget,
rel,
style,
text,
title,
url,
Expand Down Expand Up @@ -47,6 +49,7 @@ export default function save( { attributes, className } ) {

const wrapperClasses = classnames( className, {
[ `has-custom-width wp-block-button__width-${ width }` ]: width,
[ `has-custom-font-size` ]: fontSize || style?.typography?.fontSize,
} );

return (
Expand Down
6 changes: 6 additions & 0 deletions packages/block-library/src/button/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ $blocks-block__margin: 0.5em;
}
}

&.has-custom-font-size {
.wp-block-button__link {
font-size: inherit;
}
}

&.wp-block-button__width-25 {
width: calc(25% - #{ $blocks-block__margin });
}
Expand Down

0 comments on commit 6604dd3

Please sign in to comment.