Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add text-indent supports for paragraph block #59496

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ Settings related to typography.
| textAlign | boolean | true | |
| textColumns | boolean | false | |
| textDecoration | boolean | true | |
| textIndent | boolean | true | |
| writingMode | boolean | false | |
| textTransform | boolean | true | |
| dropCap | boolean | true | |
Expand Down Expand Up @@ -273,6 +274,7 @@ Typography styles.
| textAlign | string | |
| textColumns | string | |
| textDecoration | string, object | |
| textIndent | string, object | |
| writingMode | string, object | |
| textTransform | string, object | |

Expand Down
9 changes: 9 additions & 0 deletions lib/block-supports/typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function gutenberg_register_typography_support( $block_type ) {
$has_text_align_support = $typography_supports['textAlign'] ?? false;
$has_text_columns_support = $typography_supports['textColumns'] ?? false;
$has_text_decoration_support = $typography_supports['__experimentalTextDecoration'] ?? false;
$has_text_indent_support = $typography_supports['__experimentalTextIndent'] ?? false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it still be __experimental?

$has_text_transform_support = $typography_supports['__experimentalTextTransform'] ?? false;
$has_writing_mode_support = $typography_supports['__experimentalWritingMode'] ?? false;

Expand All @@ -41,6 +42,7 @@ function gutenberg_register_typography_support( $block_type ) {
|| $has_text_align_support
|| $has_text_columns_support
|| $has_text_decoration_support
|| $has_text_indent_support
|| $has_text_transform_support
|| $has_writing_mode_support;

Expand Down Expand Up @@ -100,6 +102,7 @@ function gutenberg_apply_typography_support( $block_type, $block_attributes ) {
$has_text_align_support = $typography_supports['textAlign'] ?? false;
$has_text_columns_support = $typography_supports['textColumns'] ?? false;
$has_text_decoration_support = $typography_supports['__experimentalTextDecoration'] ?? false;
$has_text_indent_support = $typography_supports['__experimentalTextIndent'] ?? false;
$has_text_transform_support = $typography_supports['__experimentalTextTransform'] ?? false;
$has_writing_mode_support = $typography_supports['__experimentalWritingMode'] ?? false;

Expand All @@ -112,6 +115,7 @@ function gutenberg_apply_typography_support( $block_type, $block_attributes ) {
$should_skip_text_align = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textAlign' );
$should_skip_text_columns = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textColumns' );
$should_skip_text_decoration = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textDecoration' );
$should_skip_text_indent = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textIndent' );
$should_skip_text_transform = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'textTransform' );
$should_skip_letter_spacing = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'letterSpacing' );
$should_skip_writing_mode = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'writingMode' );
Expand Down Expand Up @@ -160,6 +164,11 @@ function gutenberg_apply_typography_support( $block_type, $block_attributes ) {
gutenberg_typography_get_preset_inline_style_value( $block_attributes['style']['typography']['textDecoration'], 'text-decoration' );
}

if ( $has_text_indent_support && ! $should_skip_text_indent && isset( $block_attributes['style']['typography']['textIndent'] ) ) {
$typography_block_styles['textIndent'] =
gutenberg_typography_get_preset_inline_style_value( $block_attributes['style']['typography']['textIndent'], 'text-indent' );
}

if ( $has_text_transform_support && ! $should_skip_text_transform && isset( $block_attributes['style']['typography']['textTransform'] ) ) {
$typography_block_styles['textTransform'] =
gutenberg_typography_get_preset_inline_style_value( $block_attributes['style']['typography']['textTransform'], 'text-transform' );
Expand Down
3 changes: 3 additions & 0 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ class WP_Theme_JSON_Gutenberg {
'--wp--style--root--padding-bottom' => array( 'spacing', 'padding', 'bottom' ),
'--wp--style--root--padding-left' => array( 'spacing', 'padding', 'left' ),
'text-decoration' => array( 'typography', 'textDecoration' ),
'text-indent' => array( 'typography', 'textIndent' ),
'text-transform' => array( 'typography', 'textTransform' ),
'filter' => array( 'filter', 'duotone' ),
'box-shadow' => array( 'shadow' ),
Expand Down Expand Up @@ -454,6 +455,7 @@ class WP_Theme_JSON_Gutenberg {
'letterSpacing' => null,
'lineHeight' => null,
'textAlign' => null,
'textIndent' => null,
'textColumns' => null,
'textDecoration' => null,
'textTransform' => null,
Expand Down Expand Up @@ -552,6 +554,7 @@ class WP_Theme_JSON_Gutenberg {
'textAlign' => null,
'textColumns' => null,
'textDecoration' => null,
'textIndent' => null,
'textTransform' => null,
'writingMode' => null,
),
Expand Down
1 change: 1 addition & 0 deletions lib/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@
"textAlign": true,
"textColumns": false,
"textDecoration": true,
"textIndent": true,
"textTransform": true,
"writingMode": false
},
Expand Down
6 changes: 6 additions & 0 deletions packages/block-editor/src/hooks/supports.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ const WRITING_MODE_SUPPORT_KEY = 'typography.__experimentalWritingMode';
* transforms e.g. settings found in `block.json`.
*/
const TEXT_TRANSFORM_SUPPORT_KEY = 'typography.__experimentalTextTransform';
/**
* Key within block settings' supports array indicating support for text
* indent e.g. settings found in `block.json`.
*/
const TEXT_INDENT_SUPPORT_KEY = 'typography.__experimentalTextIndent';

/**
* Key within block settings' supports array indicating support for letter-spacing
Expand All @@ -61,6 +66,7 @@ const TYPOGRAPHY_SUPPORT_KEYS = [
TEXT_ALIGN_SUPPORT_KEY,
TEXT_COLUMNS_SUPPORT_KEY,
TEXT_DECORATION_SUPPORT_KEY,
TEXT_INDENT_SUPPORT_KEY,
TEXT_TRANSFORM_SUPPORT_KEY,
WRITING_MODE_SUPPORT_KEY,
LETTER_SPACING_SUPPORT_KEY,
Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/hooks/typography.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function omit( object, keys ) {

const LETTER_SPACING_SUPPORT_KEY = 'typography.__experimentalLetterSpacing';
const TEXT_TRANSFORM_SUPPORT_KEY = 'typography.__experimentalTextTransform';
const TEXT_INDENT_SUPPORT_KEY = 'typography.__experimentalTextIndent';
const TEXT_DECORATION_SUPPORT_KEY = 'typography.__experimentalTextDecoration';
const TEXT_COLUMNS_SUPPORT_KEY = 'typography.textColumns';
const FONT_STYLE_SUPPORT_KEY = 'typography.__experimentalFontStyle';
Expand All @@ -44,6 +45,7 @@ export const TYPOGRAPHY_SUPPORT_KEYS = [
TEXT_ALIGN_SUPPORT_KEY,
TEXT_COLUMNS_SUPPORT_KEY,
TEXT_DECORATION_SUPPORT_KEY,
TEXT_INDENT_SUPPORT_KEY,
WRITING_MODE_SUPPORT_KEY,
TEXT_TRANSFORM_SUPPORT_KEY,
LETTER_SPACING_SUPPORT_KEY,
Expand Down
4 changes: 4 additions & 0 deletions packages/block-editor/src/hooks/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ export function useBlockSettings( name, parentLayout ) {
textAlign,
textColumns,
textDecoration,
textIndent,
writingMode,
textTransform,
letterSpacing,
Expand Down Expand Up @@ -293,6 +294,7 @@ export function useBlockSettings( name, parentLayout ) {
'typography.textAlign',
'typography.textColumns',
'typography.textDecoration',
'typography.textIndent',
'typography.writingMode',
'typography.textTransform',
'typography.letterSpacing',
Expand Down Expand Up @@ -388,6 +390,7 @@ export function useBlockSettings( name, parentLayout ) {
textAlign,
textColumns,
textDecoration,
textIndent,
textTransform,
letterSpacing,
writingMode,
Expand Down Expand Up @@ -436,6 +439,7 @@ export function useBlockSettings( name, parentLayout ) {
textAlign,
textColumns,
textDecoration,
textIndent,
textTransform,
letterSpacing,
writingMode,
Expand Down
5 changes: 5 additions & 0 deletions packages/blocks/src/api/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ export const __EXPERIMENTAL_STYLE_PROPERTY = {
support: [ 'typography', '__experimentalTextDecoration' ],
useEngine: true,
},
textIndent: {
value: [ 'typography', 'textIndent' ],
support: [ 'typography', '__experimentalTextIndent' ],
useEngine: true,
},
textTransform: {
value: [ 'typography', 'textTransform' ],
support: [ 'typography', '__experimentalTextTransform' ],
Expand Down
13 changes: 13 additions & 0 deletions packages/style-engine/src/styles/typography/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ const textDecoration = {
},
};

const textIndent = {
name: 'textIndent',
generate: ( style: Style, options: StyleOptions ) => {
return generateRule(
style,
options,
[ 'typography', 'textIndent' ],
'textIndent'
);
},
};

const textTransform = {
name: 'textTransform',
generate: ( style: Style, options: StyleOptions ) => {
Expand Down Expand Up @@ -133,6 +145,7 @@ export default [
lineHeight,
textColumns,
textDecoration,
textIndent,
textTransform,
writingMode,
];
16 changes: 16 additions & 0 deletions schemas/json/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,11 @@
"type": "boolean",
"default": true
},
"textIndent": {
"description": "Allow users to set custom text indent.",
"type": "boolean",
"default": true
},
"writingMode": {
"description": "Allow users to set the writing mode.",
"type": "boolean",
Expand Down Expand Up @@ -1695,6 +1700,17 @@
}
]
},
"textIndent": {
"description": "Sets the `text-indent` CSS property.",
"oneOf": [
{
"type": "string"
},
{
"$ref": "#/definitions/refComplete"
}
]
},
"writingMode": {
"description": "Sets the `writing-mode` CSS property.",
"oneOf": [
Expand Down
Loading