Skip to content

Commit a61a995

Browse files
Mario AguiarPatelUtkarsh
authored andcommitted
Merge branch 'develop' into patterns/logo
2 parents a452d4a + 6d00997 commit a61a995

File tree

19 files changed

+290
-38
lines changed

19 files changed

+290
-38
lines changed

plugin/assets/css/src/customize-controls.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
content: "\f460" !important;
5151
}
5252

53-
& .customize-section-description-container {
53+
& .customize-section-description-container .customize-section-title {
5454
display: none;
5555
}
5656
}

plugin/assets/src/block-editor/blocks/card/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ import edit from './edit';
2727
import save from './save';
2828
import metadata from './block.json';
2929
import { example } from './example';
30-
30+
import { isDefaultCardStyleOutlined } from '../../utils';
31+
metadata.attributes.outlined.default = isDefaultCardStyleOutlined();
3132
const { name } = metadata;
3233

3334
export { metadata, name };

plugin/assets/src/block-editor/blocks/cards-collection/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ import edit from './edit';
2727
import save from './save';
2828
import { example } from './example';
2929
import metadata from './block.json';
30+
import { isDefaultCardStyleOutlined } from '../../utils';
3031

3132
const { name } = metadata;
3233

34+
metadata.attributes.outlined.default = isDefaultCardStyleOutlined();
3335
export { metadata, name };
3436

3537
/**

plugin/assets/src/block-editor/blocks/contact-form/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import { __ } from '@wordpress/i18n';
2525
import edit from './edit';
2626
import save from './save';
2727
import metadata from './block.json';
28+
import { isDefaultTextFieldStyleOutlined } from '../../utils';
29+
30+
metadata.attributes.outlined.default = isDefaultTextFieldStyleOutlined();
2831

2932
const { name } = metadata;
3033

plugin/assets/src/block-editor/blocks/hand-picked-posts/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import metadata from './block.json';
2727

2828
const { name } = metadata;
2929

30+
import { isDefaultCardStyleOutlined } from '../../utils';
31+
metadata.attributes.outlined.default = isDefaultCardStyleOutlined();
3032
export { metadata, name };
3133

3234
/**

plugin/assets/src/block-editor/blocks/recent-posts/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ import { __ } from '@wordpress/i18n';
2525
import edit from './edit';
2626
import metadata from './block.json';
2727
import { example } from './example';
28+
import { isDefaultCardStyleOutlined } from '../../utils';
2829

2930
const { name } = metadata;
30-
31+
metadata.attributes.outlined.default = isDefaultCardStyleOutlined();
3132
export { metadata, name };
3233

3334
/**

plugin/assets/src/block-editor/utils/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@
1717
export { default as findIcon } from './find-icon';
1818
export { default as getConfig } from './get-config';
1919
export { default as getIconName } from './get-icon-name';
20+
export { default as isDefaultCardStyleOutlined } from './is-default-card-style-outlined';
21+
export { default as isDefaultTextFieldStyleOutlined } from './is-default-text-field-outlined';
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { getConfig } from './index';
18+
19+
/**
20+
* Whether global card style outlined.
21+
*
22+
* @return {boolean} Is outlined.
23+
*/
24+
export default () =>
25+
// eslint-disable-next-line camelcase
26+
getConfig( 'defaults' )?.globalStyle?.card_style === 'outlined';
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { getConfig } from './index';
18+
19+
/**
20+
* Whether global text input style outlined.
21+
*
22+
* @return {boolean} Is outlined.
23+
*/
24+
export default () =>
25+
// eslint-disable-next-line camelcase
26+
getConfig( 'defaults' )?.globalStyle?.text_field_style === 'outlined';

plugin/php/class-block-types.php

Lines changed: 71 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,27 @@ public function register_blocks() {
8686

8787
$blocks_dir = $this->plugin->dir_path . '/assets/js/blocks/';
8888
$block_folders = [
89-
'button',
90-
'card',
91-
'cards-collection',
92-
'contact-form',
93-
'data-table',
94-
'hand-picked-posts',
95-
'image-list',
96-
'list',
97-
'recent-posts',
98-
'tab-bar',
89+
'button' => [],
90+
'card' => [
91+
'outlined' => [ $this, 'is_default_card_style_outlined' ],
92+
],
93+
'cards-collection' => [
94+
'outlined' => [ $this, 'is_default_card_style_outlined' ],
95+
],
96+
'contact-form' => [
97+
'outlined' => [ $this, 'is_default_text_field_style_outlined' ],
98+
],
99+
'data-table' => [],
100+
'hand-picked-posts' => [],
101+
'image-list' => [],
102+
'list' => [],
103+
'recent-posts' => [
104+
'outlined' => [ $this, 'is_default_card_style_outlined' ],
105+
],
106+
'tab-bar' => [],
99107
];
100108

101-
foreach ( $block_folders as $block_name ) {
109+
foreach ( $block_folders as $block_name => $override_attributes ) {
102110
$block_json_file = $blocks_dir . $block_name . '/block.json';
103111
if ( ! file_exists( $block_json_file ) ) {
104112
continue;
@@ -109,6 +117,10 @@ public function register_blocks() {
109117
continue;
110118
}
111119

120+
foreach ( $override_attributes as $attr_key => $attr ) {
121+
$metadata['attributes'][ $attr_key ]['default'] = call_user_func( $attr );
122+
}
123+
112124
$metadata['editor_script'] = 'material-block-editor-js';
113125
$metadata['editor_style'] = 'material-block-editor-css';
114126

@@ -213,8 +225,9 @@ public function enqueue_block_editor_assets() {
213225
'tab_bar_preview' => $this->plugin->asset_url( 'assets/images/preview/tab-bar.jpg' ),
214226
'contact_form_preview' => $this->plugin->asset_url( 'assets/images/preview/contact-form.jpg' ),
215227
'defaults' => [
216-
'blocks' => $this->get_block_defaults(),
217-
'colors' => $this->get_color_defaults(),
228+
'blocks' => $this->get_block_defaults(),
229+
'colors' => $this->get_color_defaults(),
230+
'globalStyle' => $this->get_global_styles(),
218231
],
219232
'customizerUrls' => [
220233
'colors' => add_query_arg( 'autofocus[section]', $slug . '_colors', $customizer_url ),
@@ -308,6 +321,51 @@ public function get_color_defaults() {
308321
return $defaults;
309322
}
310323

324+
/**
325+
* Get global style configs.
326+
*
327+
* @param string $key get single value.
328+
*
329+
* @return array|string
330+
*/
331+
public function get_global_styles( $key = null ) {
332+
$defaults = [];
333+
$controls = $this->plugin->customizer_controls;
334+
335+
foreach ( $controls->get_global_style_controls() as $control ) {
336+
$value = $controls->get_option( $control['id'] );
337+
if ( ! empty( $value ) ) {
338+
$defaults[ $control['id'] ] = $value;
339+
}
340+
}
341+
342+
return ( $key ? ( isset( $defaults[ $key ] ) ? $defaults[ $key ] : '' ) : $defaults );
343+
}
344+
345+
/**
346+
* Whether default card style is outlined.
347+
*
348+
* @return bool
349+
*/
350+
public function is_default_card_style_outlined() {
351+
$style = $this->get_global_styles();
352+
$style = isset( $style['card_style'] ) ? $style['card_style'] : '';
353+
354+
return 'outlined' === $style;
355+
}
356+
357+
/**
358+
* Whether default text field style is outlined.
359+
*
360+
* @return bool
361+
*/
362+
public function is_default_text_field_style_outlined() {
363+
$style = $this->get_global_styles();
364+
$style = isset( $style['text_field_style'] ) ? $style['text_field_style'] : '';
365+
366+
return 'outlined' === $style;
367+
}
368+
311369
/**
312370
* Gets the REST API controller for a post type.
313371
*

0 commit comments

Comments
 (0)