diff --git a/src/Block.php b/src/Block.php index 566cac0..dab52ed 100644 --- a/src/Block.php +++ b/src/Block.php @@ -207,6 +207,15 @@ abstract class Block extends Composer implements BlockContract 'margin' => null, ]; + /** + * The default block typography. + * + * @var array + */ + public $typography = [ + 'textAlign' => null, + ]; + /** * The supported block features. * @@ -397,18 +406,6 @@ public function getSupports(): array ->mapWithKeys(fn ($value, $key) => [Str::camel($key) => $value]) ->merge($this->supports); - $typography = $supports->get('typography', []); - - if ($supports->has('alignText')) { - $typography['textAlign'] = $supports->get('alignText'); - - $supports->forget(['alignText', 'align_text']); - } - - if ($typography) { - $supports->put('typography', $typography); - } - return $supports->all(); } @@ -433,18 +430,27 @@ public function getSupportAttributes(): array ]; } - $styles = []; - if ($this->align_text) { - $styles['typography']['textAlign'] = $this->align_text; + $attributes['alignText'] = [ + 'type' => 'string', + 'default' => $this->align_text, + ]; } + $styles = []; + $spacing = array_filter($this->spacing); if ($spacing) { $styles['spacing'] = $spacing; } + $typography = array_filter($this->typography); + + if ($typography) { + $styles['typography'] = $typography; + } + if ($styles) { $attributes['style'] = [ 'type' => 'object', @@ -490,6 +496,10 @@ public function getClasses(): string $class = "{$class} is-position-{$alignContent}"; } + if ($alignText = $this->block->alignText ?? $this->block->align_text ?? null) { + $class = "{$class} align-text-{$alignText}"; + } + if ($this->block->fullHeight ?? $this->block->full_height ?? null) { $class = "{$class} full-height"; } diff --git a/src/Console/BlockMakeCommand.php b/src/Console/BlockMakeCommand.php index 1d3e227..d6767e0 100644 --- a/src/Console/BlockMakeCommand.php +++ b/src/Console/BlockMakeCommand.php @@ -45,7 +45,6 @@ class BlockMakeCommand extends MakeCommand */ protected array $supports = [ 'align', - 'align_text', 'align_content', 'full_height', 'anchor', @@ -54,6 +53,7 @@ class BlockMakeCommand extends MakeCommand 'jsx', 'color' => ['background', 'text', 'gradients'], 'spacing' => ['padding', 'margin'], + 'typography' => ['textAlign'], ]; /** diff --git a/src/Console/stubs/block.localized.stub b/src/Console/stubs/block.localized.stub index 6cf48b0..4b0faf0 100644 --- a/src/Console/stubs/block.localized.stub +++ b/src/Console/stubs/block.localized.stub @@ -71,18 +71,30 @@ class DummyClass extends Block public $align = ''; /** - * The default block text alignment. + * The default block content alignment. * * @var string */ - public $align_text = ''; + public $align_content = ''; /** - * The default block content alignment. + * The default block spacing. * - * @var string + * @var array */ - public $align_content = ''; + public $spacing = [ + 'padding' => null, + 'margin' => null, + ]; + + /** + * The default block typography. + * + * @var array + */ + public $typography = [ + 'textAlign' => null, + ]; /** * The supported block features. diff --git a/src/Console/stubs/block.stub b/src/Console/stubs/block.stub index efbf125..24775ab 100644 --- a/src/Console/stubs/block.stub +++ b/src/Console/stubs/block.stub @@ -77,13 +77,6 @@ class DummyClass extends Block */ public $align = ''; - /** - * The default block text alignment. - * - * @var string - */ - public $align_text = ''; - /** * The default block content alignment. * @@ -101,6 +94,15 @@ class DummyClass extends Block 'margin' => null, ]; + /** + * The default block typography. + * + * @var array + */ + public $typography = [ + 'textAlign' => null, + ]; + /** * The supported block features. *