Skip to content

Commit 5283c7d

Browse files
Button/s: Add typography supports to button blocks (#43934)
1 parent e9c0da7 commit 5283c7d

File tree

9 files changed

+72
-6
lines changed

9 files changed

+72
-6
lines changed

docs/reference-guides/core-blocks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Prompt visitors to take action with a button-style link. ([Source](https://githu
5050

5151
- **Name:** core/button
5252
- **Category:** design
53-
- **Supports:** align, anchor, color (background, gradients, text), spacing (padding), typography (fontSize), ~~alignWide~~, ~~reusable~~
53+
- **Supports:** align, anchor, color (background, gradients, text), spacing (padding), typography (fontSize, lineHeight), ~~alignWide~~, ~~reusable~~
5454
- **Attributes:** backgroundColor, gradient, linkTarget, placeholder, rel, text, textColor, title, url, width
5555

5656
## Buttons
@@ -59,7 +59,7 @@ Prompt visitors to take action with a group of button-style links. ([Source](htt
5959

6060
- **Name:** core/buttons
6161
- **Category:** design
62-
- **Supports:** align (full, wide), anchor, spacing (blockGap, margin)
62+
- **Supports:** align (full, wide), anchor, spacing (blockGap, margin), typography (fontSize, lineHeight)
6363
- **Attributes:**
6464

6565
## Calendar

packages/block-library/src/button/block.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,13 @@
6868
},
6969
"typography": {
7070
"fontSize": true,
71+
"lineHeight": true,
7172
"__experimentalFontFamily": true,
73+
"__experimentalFontWeight": true,
74+
"__experimentalFontStyle": true,
7275
"__experimentalTextTransform": true,
76+
"__experimentalTextDecoration": true,
77+
"__experimentalLetterSpacing": true,
7378
"__experimentalDefaultControls": {
7479
"fontSize": true
7580
}

packages/block-library/src/button/editor.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,7 @@
7575
div[data-type="core/button"] {
7676
display: table;
7777
}
78+
79+
.editor-styles-wrapper .wp-block-button[style*="text-decoration"] .wp-block-button__link {
80+
text-decoration: inherit;
81+
}

packages/block-library/src/button/style.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ $blocks-block__margin: 0.5em;
3434
padding: calc(0.667em + 2px) calc(1.333em + 2px);
3535
}
3636

37+
.wp-block-button[style*="text-decoration"] .wp-block-button__link {
38+
text-decoration: inherit;
39+
}
40+
3741
// Increased specificity needed to override margins.
3842
.wp-block-buttons > .wp-block-button {
3943
&.has-custom-width {

packages/block-library/src/buttons/block.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@
1818
"blockGap": true
1919
}
2020
},
21+
"typography": {
22+
"fontSize": true,
23+
"lineHeight": true,
24+
"__experimentalFontFamily": true,
25+
"__experimentalFontWeight": true,
26+
"__experimentalFontStyle": true,
27+
"__experimentalTextTransform": true,
28+
"__experimentalTextDecoration": true,
29+
"__experimentalLetterSpacing": true,
30+
"__experimentalDefaultControls": {
31+
"fontSize": true
32+
}
33+
},
2134
"__experimentalLayout": {
2235
"allowSwitching": false,
2336
"allowInheriting": false,

packages/block-library/src/buttons/edit.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import classnames from 'classnames';
5+
16
/**
27
* WordPress dependencies
38
*/
@@ -30,8 +35,13 @@ const DEFAULT_BLOCK = {
3035
],
3136
};
3237

33-
function ButtonsEdit( { attributes: { layout = {} } } ) {
34-
const blockProps = useBlockProps();
38+
function ButtonsEdit( { attributes, className } ) {
39+
const { fontSize, layout = {}, style } = attributes;
40+
const blockProps = useBlockProps( {
41+
className: classnames( className, {
42+
'has-custom-font-size': fontSize || style?.typography?.fontSize,
43+
} ),
44+
} );
3545
const preferredStyle = useSelect( ( select ) => {
3646
const preferredStyleVariations =
3747
select( blockEditorStore ).getSettings()

packages/block-library/src/buttons/editor.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ $blocks-block__margin: 0.5em;
5454
margin-bottom: 0;
5555
}
5656
}
57+
58+
.editor-styles-wrapper &.has-custom-font-size {
59+
.wp-block-button__link {
60+
font-size: inherit;
61+
}
62+
}
5763
}
5864

5965
.wp-block[data-align="center"] > .wp-block-buttons {
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import classnames from 'classnames';
5+
16
/**
27
* WordPress dependencies
38
*/
49
import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';
510

6-
export default function save() {
7-
const innerBlocksProps = useInnerBlocksProps.save( useBlockProps.save() );
11+
export default function save( { attributes, className } ) {
12+
const { fontSize, style } = attributes;
13+
const blockProps = useBlockProps.save( {
14+
className: classnames( className, {
15+
'has-custom-font-size': fontSize || style?.typography?.fontSize,
16+
} ),
17+
} );
18+
const innerBlocksProps = useInnerBlocksProps.save( blockProps );
819
return <div { ...innerBlocksProps } />;
920
}

packages/block-library/src/buttons/style.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ $blocks-block__margin: 0.5em;
6969
margin-right: auto;
7070
width: 100%;
7171
}
72+
73+
&[style*="text-decoration"] {
74+
.wp-block-button,
75+
.wp-block-button__link {
76+
text-decoration: inherit;
77+
}
78+
}
79+
80+
&.has-custom-font-size {
81+
.wp-block-button__link {
82+
font-size: inherit;
83+
}
84+
}
7285
}
7386

7487
// Legacy buttons that did not come in a wrapping container.

0 commit comments

Comments
 (0)