Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Classic Template: set the default alignment to wide (#6356)
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhtungdu authored May 4, 2022
1 parent cbe49b2 commit 8adb58e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions assets/js/blocks/classic-template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This block does not have any customizable options available, so any style or cus

* `attributes`
* `template`: `single-product` | `archive-product` | `taxonomy-product_cat` | `taxonomy-product_tag`
* `align`: `wide` | `full`

```html
<!-- wp:woocommerce/legacy-template {"template":"single-product"} /-->
Expand Down
6 changes: 6 additions & 0 deletions assets/js/blocks/classic-template/editor.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
:where(.wp-block-woocommerce-legacy-template) {
margin-left: auto;
margin-right: auto;
max-width: 1000px;
}

.wp-block-woocommerce-classic-template__placeholder-copy {
max-width: 900px;
margin-bottom: 30px;
Expand Down
6 changes: 6 additions & 0 deletions assets/js/blocks/classic-template/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import { box, Icon } from '@wordpress/icons';
* Internal dependencies
*/
import './editor.scss';
import './style.scss';
import { TEMPLATES } from './constants';

interface Props {
attributes: {
template: string;
align: string;
};
}

Expand Down Expand Up @@ -109,6 +111,10 @@ registerBlockType( 'woocommerce/legacy-template', {
type: 'string',
default: 'any',
},
align: {
type: 'string',
default: 'wide',
},
},
edit: Edit,
save: () => null,
Expand Down
5 changes: 5 additions & 0 deletions assets/js/blocks/classic-template/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:where(div[data-block-name="woocommerce/legacy-template"]) {
margin-left: auto;
margin-right: auto;
max-width: 1000px;
}
9 changes: 7 additions & 2 deletions src/BlockTypes/ClassicTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,13 @@ public function add_alignment_class_to_wrapper( string $content, array $block )
return $content;
}

$attributes = (array) $block['attrs'];
$attributes = (array) $block['attrs'];

// Set the default alignment to wide.
if ( ! isset( $attributes['align'] ) ) {
$attributes['align'] = 'wide';
}

$align_class_and_style = StyleAttributesUtils::get_align_class_and_style( $attributes );

if ( ! isset( $align_class_and_style['class'] ) ) {
Expand Down Expand Up @@ -305,5 +311,4 @@ public function add_query_vars_filter( $vars ) {
return $vars;
}


}

0 comments on commit 8adb58e

Please sign in to comment.