Skip to content

Commit

Permalink
add css variables for each width defined in theme.json
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoffDusome committed Apr 25, 2024
1 parent 454afae commit 74f026d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
7 changes: 5 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Contributors: moderntribe
Donate link: https://tri.be
Tags: blocks, editor, alignment
Requires at least: 6.0
Tested up to: 6.2
Stable tag: 1.0.6
Tested up to: 6.5.2
Stable tag: 1.0.7
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -21,6 +21,9 @@ The plugin runs off of an `_experimentalLayout` attribute in `theme.json` that a

== Changelog ==

= 1.0.7 =
* Updates plugin to also create CSS variables for each defined width.

= 1.0.6 =
* Fixes an issue where blocks could get a class of `alignfalse` when selecting the "None" alignment in the toolbar.

Expand Down
10 changes: 8 additions & 2 deletions block-editor-custom-alignments.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Plugin Name: Block Editor Custom Alignments
* Plugin URI: https://https://github.com/moderntribe/block-editor-custom-alignments
* Description: Allows developers to add custom alignments to `theme.json` for use in the block editor.
* Version: 1.0.6
* Version: 1.0.7
* Author: Modern Tribe
* Author URI: https://tri.be
* License: GPL-2.0+
Expand Down Expand Up @@ -54,7 +54,7 @@ class Block_Editor_Custom_Alignments {
public function __construct() {
global $pagenow;

$this->version = '1.0.6';
$this->version = '1.0.7';
$this->name = 'block-editor-custom-alignments';
$this->base_url = trailingslashit( plugin_dir_url( __FILE__ ) );
$this->theme_json = $this->block_editor_custom_alignments_theme_json();
Expand Down Expand Up @@ -103,6 +103,9 @@ public function block_editor_custom_alignments_admin_styles(): void {

foreach ( $this->theme_json->settings->_experimentalLayout as $alignment ) {
$admin_css .= "
:is(.editor-styles-wrapper) {
--tribe--style--global--{$alignment->slug}-size: {$alignment->width};
}
:is(.editor-styles-wrapper) .block-editor-block-list__layout.is-root-container .wp-block.align{$alignment->slug} {
max-width: {$alignment->width};
}
Expand All @@ -126,6 +129,9 @@ public function block_editor_custom_alignments_public_styles(): void {

foreach ( $this->theme_json->settings->_experimentalLayout as $alignment ) {
$theme_css .= "
body {
--tribe--style--global--{$alignment->slug}-size: {$alignment->width};
}
body .align{$alignment->slug} {
max-width: {$alignment->width};
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "block-editor-custom-alignments",
"version": "1.0.6",
"version": "1.0.7",
"description": "Allows developers to add custom alignments to `theme.json` for use in the block editor.",
"author": "Modern Tribe <[email protected]>",
"license": "GPL-2.0-or-later",
Expand Down

0 comments on commit 74f026d

Please sign in to comment.