Skip to content

Commit 21f985c

Browse files
shail-mehtashail-mehtat-hamano
authored
Term Description: Migrate to Text-Align Block Support (#75542)
Co-authored-by: shail-mehta <shailu25@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org>
1 parent b01da55 commit 21f985c

9 files changed

Lines changed: 165 additions & 36 deletions

File tree

docs/reference-guides/core-blocks.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,8 +1091,7 @@ Display the description of categories, tags and custom taxonomies when viewing a
10911091

10921092
- **Name:** core/term-description
10931093
- **Category:** theme
1094-
- **Supports:** align (full, wide), anchor, color (background, link, text), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~
1095-
- **Attributes:** textAlign
1094+
- **Supports:** align (full, wide), anchor, color (background, link, text), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize, lineHeight, textAlign), ~~html~~
10961095

10971096
## Term Name
10981097

packages/block-library/src/term-description/block.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77
"description": "Display the description of categories, tags and custom taxonomies when viewing an archive.",
88
"textdomain": "default",
99
"usesContext": [ "termId", "taxonomy" ],
10-
"attributes": {
11-
"textAlign": {
12-
"type": "string"
13-
}
14-
},
1510
"supports": {
1611
"anchor": true,
1712
"align": [ "wide", "full" ],
@@ -30,6 +25,7 @@
3025
"typography": {
3126
"fontSize": true,
3227
"lineHeight": true,
28+
"textAlign": true,
3329
"__experimentalFontFamily": true,
3430
"__experimentalFontWeight": true,
3531
"__experimentalFontStyle": true,
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* Internal dependencies
3+
*/
4+
import migrateTextAlign from '../utils/migrate-text-align';
5+
6+
const v1 = {
7+
attributes: {
8+
textAlign: {
9+
type: 'string',
10+
},
11+
},
12+
supports: {
13+
anchor: true,
14+
align: [ 'wide', 'full' ],
15+
html: false,
16+
color: {
17+
link: true,
18+
__experimentalDefaultControls: {
19+
background: true,
20+
text: true,
21+
},
22+
},
23+
spacing: {
24+
margin: true,
25+
padding: true,
26+
},
27+
typography: {
28+
fontSize: true,
29+
lineHeight: true,
30+
__experimentalFontFamily: true,
31+
__experimentalFontWeight: true,
32+
__experimentalFontStyle: true,
33+
__experimentalTextTransform: true,
34+
__experimentalTextDecoration: true,
35+
__experimentalLetterSpacing: true,
36+
__experimentalDefaultControls: {
37+
fontSize: true,
38+
},
39+
},
40+
interactivity: {
41+
clientNavigation: true,
42+
},
43+
__experimentalBorder: {
44+
radius: true,
45+
color: true,
46+
width: true,
47+
style: true,
48+
__experimentalDefaultControls: {
49+
radius: true,
50+
color: true,
51+
width: true,
52+
style: true,
53+
},
54+
},
55+
},
56+
migrate: migrateTextAlign,
57+
isEligible( attributes ) {
58+
return (
59+
!! attributes.textAlign ||
60+
!! attributes.className?.match(
61+
/\bhas-text-align-(left|center|right)\b/
62+
)
63+
);
64+
},
65+
save: () => null,
66+
};
67+
68+
export default [ v1 ];

packages/block-library/src/term-description/edit.js

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,22 @@
1-
/**
2-
* External dependencies
3-
*/
4-
import clsx from 'clsx';
5-
61
/**
72
* WordPress dependencies
83
*/
94
import { __ } from '@wordpress/i18n';
10-
import {
11-
useBlockProps,
12-
BlockControls,
13-
AlignmentControl,
14-
} from '@wordpress/block-editor';
5+
import { useBlockProps } from '@wordpress/block-editor';
156

167
/**
178
* Internal dependencies
189
*/
1910
import { useTermDescription } from './use-term-description';
2011

2112
export default function TermDescriptionEdit( {
22-
attributes,
23-
setAttributes,
24-
mergedStyle,
2513
context: { termId, taxonomy },
2614
} ) {
27-
const { textAlign } = attributes;
2815
const { termDescription } = useTermDescription( termId, taxonomy );
29-
30-
const blockProps = useBlockProps( {
31-
className: clsx( {
32-
[ `has-text-align-${ textAlign }` ]: textAlign,
33-
} ),
34-
style: mergedStyle,
35-
} );
16+
const blockProps = useBlockProps();
3617

3718
return (
3819
<>
39-
<BlockControls group="block">
40-
<AlignmentControl
41-
value={ textAlign }
42-
onChange={ ( nextAlign ) => {
43-
setAttributes( { textAlign: nextAlign } );
44-
} }
45-
/>
46-
</BlockControls>
4720
<div { ...blockProps }>
4821
{ termDescription ? (
4922
<div

packages/block-library/src/term-description/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { termDescription as icon } from '@wordpress/icons';
99
import initBlock from '../utils/init-block';
1010
import metadata from './block.json';
1111
import edit from './edit';
12+
import deprecated from './deprecated';
1213

1314
const { name } = metadata;
1415
export { metadata, name };
@@ -17,6 +18,7 @@ export const settings = {
1718
icon,
1819
edit,
1920
example: {},
21+
deprecated,
2022
};
2123

2224
export const init = () => initBlock( { name, metadata, settings } );
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!-- wp:term-description {"textAlign":"left"} /-->
2+
3+
<!-- wp:term-description {"textAlign":"center"} /-->
4+
5+
<!-- wp:term-description {"textAlign":"right"} /-->
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[
2+
{
3+
"name": "core/term-description",
4+
"isValid": true,
5+
"attributes": {
6+
"style": {
7+
"typography": {
8+
"textAlign": "left"
9+
}
10+
}
11+
},
12+
"innerBlocks": []
13+
},
14+
{
15+
"name": "core/term-description",
16+
"isValid": true,
17+
"attributes": {
18+
"style": {
19+
"typography": {
20+
"textAlign": "center"
21+
}
22+
}
23+
},
24+
"innerBlocks": []
25+
},
26+
{
27+
"name": "core/term-description",
28+
"isValid": true,
29+
"attributes": {
30+
"style": {
31+
"typography": {
32+
"textAlign": "right"
33+
}
34+
}
35+
},
36+
"innerBlocks": []
37+
}
38+
]
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[
2+
{
3+
"blockName": "core/term-description",
4+
"attrs": {
5+
"textAlign": "left"
6+
},
7+
"innerBlocks": [],
8+
"innerHTML": "",
9+
"innerContent": []
10+
},
11+
{
12+
"blockName": null,
13+
"attrs": {},
14+
"innerBlocks": [],
15+
"innerHTML": "\n\n",
16+
"innerContent": [ "\n\n" ]
17+
},
18+
{
19+
"blockName": "core/term-description",
20+
"attrs": {
21+
"textAlign": "center"
22+
},
23+
"innerBlocks": [],
24+
"innerHTML": "",
25+
"innerContent": []
26+
},
27+
{
28+
"blockName": null,
29+
"attrs": {},
30+
"innerBlocks": [],
31+
"innerHTML": "\n\n",
32+
"innerContent": [ "\n\n" ]
33+
},
34+
{
35+
"blockName": "core/term-description",
36+
"attrs": {
37+
"textAlign": "right"
38+
},
39+
"innerBlocks": [],
40+
"innerHTML": "",
41+
"innerContent": []
42+
}
43+
]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!-- wp:term-description {"style":{"typography":{"textAlign":"left"}}} /-->
2+
3+
<!-- wp:term-description {"style":{"typography":{"textAlign":"center"}}} /-->
4+
5+
<!-- wp:term-description {"style":{"typography":{"textAlign":"right"}}} /-->

0 commit comments

Comments
 (0)