Skip to content

Commit 5410e39

Browse files
committed
add text indent supports
1 parent 2f00bfd commit 5410e39

File tree

11 files changed

+62
-0
lines changed

11 files changed

+62
-0
lines changed

docs/reference-guides/theme-json-reference/theme-json-living.md

+2
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ Settings related to typography.
189189
| textAlign | boolean | true | |
190190
| textColumns | boolean | false | |
191191
| textDecoration | boolean | true | |
192+
| textIndent | boolean | true | |
192193
| writingMode | boolean | false | |
193194
| textTransform | boolean | true | |
194195
| dropCap | boolean | true | |
@@ -273,6 +274,7 @@ Typography styles.
273274
| textAlign | string | |
274275
| textColumns | string | |
275276
| textDecoration | string, object | |
277+
| textIndent | string, object | |
276278
| writingMode | string, object | |
277279
| textTransform | string, object | |
278280

lib/block-supports/typography.php

+9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function gutenberg_register_typography_support( $block_type ) {
2929
$has_text_align_support = $typography_supports['textAlign'] ?? false;
3030
$has_text_columns_support = $typography_supports['textColumns'] ?? false;
3131
$has_text_decoration_support = $typography_supports['__experimentalTextDecoration'] ?? false;
32+
$has_text_indent_support = $typography_supports['__experimentalTextIndent'] ?? false;
3233
$has_text_transform_support = $typography_supports['__experimentalTextTransform'] ?? false;
3334
$has_writing_mode_support = $typography_supports['__experimentalWritingMode'] ?? false;
3435

@@ -41,6 +42,7 @@ function gutenberg_register_typography_support( $block_type ) {
4142
|| $has_text_align_support
4243
|| $has_text_columns_support
4344
|| $has_text_decoration_support
45+
|| $has_text_indent_support
4446
|| $has_text_transform_support
4547
|| $has_writing_mode_support;
4648

@@ -100,6 +102,7 @@ function gutenberg_apply_typography_support( $block_type, $block_attributes ) {
100102
$has_text_align_support = $typography_supports['textAlign'] ?? false;
101103
$has_text_columns_support = $typography_supports['textColumns'] ?? false;
102104
$has_text_decoration_support = $typography_supports['__experimentalTextDecoration'] ?? false;
105+
$has_text_indent_support = $typography_supports['__experimentalTextIndent'] ?? false;
103106
$has_text_transform_support = $typography_supports['__experimentalTextTransform'] ?? false;
104107
$has_writing_mode_support = $typography_supports['__experimentalWritingMode'] ?? false;
105108

@@ -112,6 +115,7 @@ function gutenberg_apply_typography_support( $block_type, $block_attributes ) {
112115
$should_skip_text_align = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textAlign' );
113116
$should_skip_text_columns = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textColumns' );
114117
$should_skip_text_decoration = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textDecoration' );
118+
$should_skip_text_indent = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textIndent' );
115119
$should_skip_text_transform = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textTransform' );
116120
$should_skip_letter_spacing = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'letterSpacing' );
117121
$should_skip_writing_mode = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'writingMode' );
@@ -160,6 +164,11 @@ function gutenberg_apply_typography_support( $block_type, $block_attributes ) {
160164
gutenberg_typography_get_preset_inline_style_value( $block_attributes['style']['typography']['textDecoration'], 'text-decoration' );
161165
}
162166

167+
if ( $has_text_indent_support && ! $should_skip_text_indent && isset( $block_attributes['style']['typography']['textIndent'] ) ) {
168+
$typography_block_styles['textIndent'] =
169+
gutenberg_typography_get_preset_inline_style_value( $block_attributes['style']['typography']['textIndent'], 'text-indent' );
170+
}
171+
163172
if ( $has_text_transform_support && ! $should_skip_text_transform && isset( $block_attributes['style']['typography']['textTransform'] ) ) {
164173
$typography_block_styles['textTransform'] =
165174
gutenberg_typography_get_preset_inline_style_value( $block_attributes['style']['typography']['textTransform'], 'text-transform' );

lib/class-wp-theme-json-gutenberg.php

+3
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ class WP_Theme_JSON_Gutenberg {
284284
'--wp--style--root--padding-bottom' => array( 'spacing', 'padding', 'bottom' ),
285285
'--wp--style--root--padding-left' => array( 'spacing', 'padding', 'left' ),
286286
'text-decoration' => array( 'typography', 'textDecoration' ),
287+
'text-indent' => array( 'typography', 'textIndent' ),
287288
'text-transform' => array( 'typography', 'textTransform' ),
288289
'filter' => array( 'filter', 'duotone' ),
289290
'box-shadow' => array( 'shadow' ),
@@ -454,6 +455,7 @@ class WP_Theme_JSON_Gutenberg {
454455
'letterSpacing' => null,
455456
'lineHeight' => null,
456457
'textAlign' => null,
458+
'textIndent' => null,
457459
'textColumns' => null,
458460
'textDecoration' => null,
459461
'textTransform' => null,
@@ -552,6 +554,7 @@ class WP_Theme_JSON_Gutenberg {
552554
'textAlign' => null,
553555
'textColumns' => null,
554556
'textDecoration' => null,
557+
'textIndent' => null,
555558
'textTransform' => null,
556559
'writingMode' => null,
557560
),

lib/theme.json

+1
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@
308308
"textAlign": true,
309309
"textColumns": false,
310310
"textDecoration": true,
311+
"textIndent": true,
311312
"textTransform": true,
312313
"writingMode": false
313314
},

packages/block-editor/src/hooks/supports.js

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ const WRITING_MODE_SUPPORT_KEY = 'typography.__experimentalWritingMode';
4545
* transforms e.g. settings found in `block.json`.
4646
*/
4747
const TEXT_TRANSFORM_SUPPORT_KEY = 'typography.__experimentalTextTransform';
48+
/**
49+
* Key within block settings' supports array indicating support for text
50+
* indent e.g. settings found in `block.json`.
51+
*/
52+
const TEXT_INDENT_SUPPORT_KEY = 'typography.__experimentalTextIndent';
4853

4954
/**
5055
* Key within block settings' supports array indicating support for letter-spacing
@@ -61,6 +66,7 @@ const TYPOGRAPHY_SUPPORT_KEYS = [
6166
TEXT_ALIGN_SUPPORT_KEY,
6267
TEXT_COLUMNS_SUPPORT_KEY,
6368
TEXT_DECORATION_SUPPORT_KEY,
69+
TEXT_INDENT_SUPPORT_KEY,
6470
TEXT_TRANSFORM_SUPPORT_KEY,
6571
WRITING_MODE_SUPPORT_KEY,
6672
LETTER_SPACING_SUPPORT_KEY,

packages/block-editor/src/hooks/typography.js

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function omit( object, keys ) {
2929

3030
const LETTER_SPACING_SUPPORT_KEY = 'typography.__experimentalLetterSpacing';
3131
const TEXT_TRANSFORM_SUPPORT_KEY = 'typography.__experimentalTextTransform';
32+
const TEXT_INDENT_SUPPORT_KEY = 'typography.__experimentalTextIndent';
3233
const TEXT_DECORATION_SUPPORT_KEY = 'typography.__experimentalTextDecoration';
3334
const TEXT_COLUMNS_SUPPORT_KEY = 'typography.textColumns';
3435
const FONT_STYLE_SUPPORT_KEY = 'typography.__experimentalFontStyle';
@@ -44,6 +45,7 @@ export const TYPOGRAPHY_SUPPORT_KEYS = [
4445
TEXT_ALIGN_SUPPORT_KEY,
4546
TEXT_COLUMNS_SUPPORT_KEY,
4647
TEXT_DECORATION_SUPPORT_KEY,
48+
TEXT_INDENT_SUPPORT_KEY,
4749
WRITING_MODE_SUPPORT_KEY,
4850
TEXT_TRANSFORM_SUPPORT_KEY,
4951
LETTER_SPACING_SUPPORT_KEY,

packages/block-editor/src/hooks/utils.js

+4
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ export function useBlockSettings( name, parentLayout ) {
236236
textAlign,
237237
textColumns,
238238
textDecoration,
239+
textIndent,
239240
writingMode,
240241
textTransform,
241242
letterSpacing,
@@ -293,6 +294,7 @@ export function useBlockSettings( name, parentLayout ) {
293294
'typography.textAlign',
294295
'typography.textColumns',
295296
'typography.textDecoration',
297+
'typography.textIndent',
296298
'typography.writingMode',
297299
'typography.textTransform',
298300
'typography.letterSpacing',
@@ -388,6 +390,7 @@ export function useBlockSettings( name, parentLayout ) {
388390
textAlign,
389391
textColumns,
390392
textDecoration,
393+
textIndent,
391394
textTransform,
392395
letterSpacing,
393396
writingMode,
@@ -436,6 +439,7 @@ export function useBlockSettings( name, parentLayout ) {
436439
textAlign,
437440
textColumns,
438441
textDecoration,
442+
textIndent,
439443
textTransform,
440444
letterSpacing,
441445
writingMode,

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

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"__experimentalFontWeight": true,
5959
"__experimentalLetterSpacing": true,
6060
"__experimentalTextTransform": true,
61+
"__experimentalTextIndent": true,
6162
"__experimentalWritingMode": true,
6263
"__experimentalDefaultControls": {
6364
"fontSize": true

packages/blocks/src/api/constants.js

+5
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ export const __EXPERIMENTAL_STYLE_PROPERTY = {
243243
support: [ 'typography', '__experimentalTextDecoration' ],
244244
useEngine: true,
245245
},
246+
textIndent: {
247+
value: [ 'typography', 'textIndent' ],
248+
support: [ 'typography', '__experimentalTextIndent' ],
249+
useEngine: true,
250+
},
246251
textTransform: {
247252
value: [ 'typography', 'textTransform' ],
248253
support: [ 'typography', '__experimentalTextTransform' ],

packages/style-engine/src/styles/typography/index.ts

+13
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ const textDecoration = {
100100
},
101101
};
102102

103+
const textIndent = {
104+
name: 'textIndent',
105+
generate: ( style: Style, options: StyleOptions ) => {
106+
return generateRule(
107+
style,
108+
options,
109+
[ 'typography', 'textIndent' ],
110+
'textIndent'
111+
);
112+
},
113+
};
114+
103115
const textTransform = {
104116
name: 'textTransform',
105117
generate: ( style: Style, options: StyleOptions ) => {
@@ -133,6 +145,7 @@ export default [
133145
lineHeight,
134146
textColumns,
135147
textDecoration,
148+
textIndent,
136149
textTransform,
137150
writingMode,
138151
];

schemas/json/theme.json

+16
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,11 @@
608608
"type": "boolean",
609609
"default": true
610610
},
611+
"textIndent": {
612+
"description": "Allow users to set custom text indent.",
613+
"type": "boolean",
614+
"default": true
615+
},
611616
"writingMode": {
612617
"description": "Allow users to set the writing mode.",
613618
"type": "boolean",
@@ -1695,6 +1700,17 @@
16951700
}
16961701
]
16971702
},
1703+
"textIndent": {
1704+
"description": "Sets the `text-indent` CSS property.",
1705+
"oneOf": [
1706+
{
1707+
"type": "string"
1708+
},
1709+
{
1710+
"$ref": "#/definitions/refComplete"
1711+
}
1712+
]
1713+
},
16981714
"writingMode": {
16991715
"description": "Sets the `writing-mode` CSS property.",
17001716
"oneOf": [

0 commit comments

Comments
 (0)