Skip to content

Commit b731d37

Browse files
author
Mario Aguiar
authored
Merge pull request #131 from material-components/feature/hide-title
Allow hiding page title
2 parents 7e6a289 + 6dad89a commit b731d37

File tree

14 files changed

+6093
-1619
lines changed

14 files changed

+6093
-1619
lines changed

bin/phpunit-theme.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
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+
docker-compose run --rm -u 1000 --workdir=/var/www/html/wp-content/themes/material-design-google wordpress -- composer test

package-lock.json

Lines changed: 5565 additions & 1608 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,14 @@
6464
"@wordpress/dom": "2.8.0",
6565
"@wordpress/dom-ready": "2.8.0",
6666
"@wordpress/e2e-test-utils": "4.16.0",
67+
"@wordpress/edit-post": "^4.1.0",
68+
"@wordpress/element": "^3.1.0",
6769
"@wordpress/escape-html": "1.11.0",
6870
"@wordpress/eslint-plugin": "4.1.0",
6971
"@wordpress/i18n": "3.10.0",
7072
"@wordpress/jest-preset-default": "5.5.0",
7173
"@wordpress/jest-puppeteer-axe": "1.6.0",
74+
"@wordpress/plugins": "^3.1.0",
7275
"@wordpress/postcss-themes": "2.3.0",
7376
"@wordpress/rich-text": "3.24.1",
7477
"@wordpress/scripts": "12.6.1",

plugin/tests/js/block-editor/blocks/common-posts-list/edit-with-select.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ describe( 'EditWithSelect', () => {
164164
} );
165165

166166
it( 'set the correct arguments when the block is the "Hand-picked posts"', () => {
167-
const lodash = require.requireActual( 'lodash' );
167+
const lodash = jest.requireActual( 'lodash' );
168168
jest.spyOn( lodash, 'pickBy' ).mockImplementation( () => 1 );
169169

170170
const props = {
@@ -186,7 +186,7 @@ describe( 'EditWithSelect', () => {
186186
} );
187187

188188
it( 'set the correct arguments when the block is the "Hand-picked posts" and title ordering', () => {
189-
const lodash = require.requireActual( 'lodash' );
189+
const lodash = jest.requireActual( 'lodash' );
190190
jest.spyOn( lodash, 'pickBy' ).mockImplementation( () => 1 );
191191

192192
const props = {
@@ -212,7 +212,7 @@ describe( 'EditWithSelect', () => {
212212
} );
213213

214214
it( 'set the correct arguments when the block is the "Hand-picked posts" and popularity ordering', () => {
215-
const lodash = require.requireActual( 'lodash' );
215+
const lodash = jest.requireActual( 'lodash' );
216216
jest.spyOn( lodash, 'pickBy' ).mockImplementation( () => 1 );
217217

218218
const props = {

plugin/tests/js/block-editor/blocks/common-posts-list/edit.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ describe( 'EditWithSelect', () => {
166166
} );
167167

168168
it( 'set the correct arguments when the block is the "Hand-picked posts"', () => {
169-
const lodash = require.requireActual( 'lodash' );
169+
const lodash = jest.requireActual( 'lodash' );
170170
jest.spyOn( lodash, 'pickBy' ).mockImplementation( () => 1 );
171171

172172
const props = {
@@ -188,7 +188,7 @@ describe( 'EditWithSelect', () => {
188188
} );
189189

190190
it( 'set the correct arguments when the block is the "Hand-picked posts" and title ordering', () => {
191-
const lodash = require.requireActual( 'lodash' );
191+
const lodash = jest.requireActual( 'lodash' );
192192
jest.spyOn( lodash, 'pickBy' ).mockImplementation( () => 1 );
193193

194194
const props = {
@@ -214,7 +214,7 @@ describe( 'EditWithSelect', () => {
214214
} );
215215

216216
it( 'set the correct arguments when the block is the "Hand-picked posts" and popularity ordering', () => {
217-
const lodash = require.requireActual( 'lodash' );
217+
const lodash = jest.requireActual( 'lodash' );
218218
jest.spyOn( lodash, 'pickBy' ).mockImplementation( () => 1 );
219219

220220
const props = {

theme/assets/css/src/front-end.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@
2525
@import "./base/index.css";
2626
@import "./templates/index.css";
2727
@import "./components/index.css";
28+
29+
/* Block editor */
30+
@import "./../../src/block-editor/plugins/hide-sections/style.css";
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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 './plugins/hide-sections';
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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+
/**
18+
* Wordpress Dependencies
19+
*/
20+
import { registerPlugin } from '@wordpress/plugins';
21+
import { PluginDocumentSettingPanel } from '@wordpress/edit-post';
22+
import { Icon, CheckboxControl } from '@wordpress/components';
23+
import { __ } from '@wordpress/i18n';
24+
import { compose, ifCondition } from '@wordpress/compose';
25+
import { withSelect, withDispatch } from '@wordpress/data';
26+
import { useState } from '@wordpress/element';
27+
28+
function HideSection( { settings, updateSectionsSettings } ) {
29+
/**
30+
* If you add a new property here, make sure to also add it
31+
* in the "properties" array at block-editor.php.
32+
*/
33+
const settingsOptionsInitial = [
34+
{
35+
label: __( 'Hide Title', 'material' ),
36+
key: 'title',
37+
},
38+
];
39+
40+
settingsOptionsInitial.forEach( settingOption => {
41+
settingOption.value = settings[ settingOption.key ]
42+
? settings[ settingOption.key ]
43+
: false;
44+
} );
45+
46+
const [ settingsOptions, setSettingOptions ] = useState(
47+
settingsOptionsInitial
48+
);
49+
50+
return (
51+
<PluginDocumentSettingPanel
52+
name="sections-control"
53+
title={ __( 'Hide Sections', 'material' ) }
54+
className="custom-panel"
55+
>
56+
{ settingsOptions.map( settingOption => {
57+
return (
58+
<CheckboxControl
59+
checked={
60+
settings[ settingOption.key ]
61+
? settings[ settingOption.key ]
62+
: false
63+
}
64+
onChange={ state => {
65+
const newSettings = { ...settings };
66+
newSettings[ settingOption.key ] = state;
67+
const newSettingsOptions = settingsOptions;
68+
newSettingsOptions.forEach( newSettingOption => {
69+
if ( newSettingOption.key === settingOption.key ) {
70+
newSettingOption.value = state;
71+
}
72+
} );
73+
updateSectionsSettings( newSettings );
74+
setSettingOptions( newSettingsOptions );
75+
} }
76+
label={ settingOption.label }
77+
key={ settingOption.key }
78+
/>
79+
);
80+
} ) }
81+
</PluginDocumentSettingPanel>
82+
);
83+
}
84+
85+
const WrappedSectionControl = compose( [
86+
withSelect( select => {
87+
const { getCurrentPostType } = select( 'core/editor' );
88+
const { getPostType } = select( 'core' );
89+
return {
90+
postTypeObj: getPostType( getCurrentPostType() ),
91+
};
92+
} ),
93+
ifCondition( ( { postTypeObj } ) => {
94+
return postTypeObj?.supports?.[ 'custom-fields' ];
95+
} ),
96+
withSelect( select => {
97+
const { getEditedPostAttribute } = select( 'core/editor' );
98+
return {
99+
settings: getEditedPostAttribute( 'meta' )[ 'material-hide-sections' ],
100+
};
101+
} ),
102+
withDispatch( dispatch => {
103+
return {
104+
updateSectionsSettings( settings ) {
105+
dispatch( 'core/editor' ).editPost( {
106+
meta: { 'material-hide-sections': settings },
107+
} );
108+
},
109+
};
110+
} ),
111+
ifCondition( ( { settings } ) => {
112+
return !! settings;
113+
} ),
114+
] )( HideSection );
115+
116+
registerPlugin( 'material-hide-sections', {
117+
render: WrappedSectionControl,
118+
icon: <Icon icon="admin-customizer" />,
119+
} );
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
.has-hide-title {
18+
19+
.entry-title {
20+
display: none;
21+
}
22+
23+
.-has-tab-bar + .site-content .content-area {
24+
margin-top: 7rem;
25+
}
26+
27+
.-has-tab-bar + .site-content .content-area {
28+
29+
@media (max-width: 599px) {
30+
margin-top: 6rem;
31+
}
32+
}
33+
34+
.entry-content .wp-block-cover:first-child {
35+
margin-top: 0;
36+
}
37+
}

theme/functions.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,16 @@ function material_is_plugin_active() {
253253
require get_template_directory() . '/inc/widgets/class-wp-widget-rss.php';
254254
require get_template_directory() . '/inc/widgets.php';
255255

256+
/**
257+
* Block editor.
258+
*/
259+
require get_template_directory() . '/inc/block-editor.php';
260+
256261
MaterialDesign\Theme\Admin\setup();
257262
MaterialDesign\Theme\Customizer\setup();
258263
MaterialDesign\Theme\Customizer\Colors\setup();
259264
MaterialDesign\Theme\Customizer\Header_Footer\setup();
260265
MaterialDesign\Theme\Customizer\Layout\setup();
261266
MaterialDesign\Theme\Customizer\Menu\setup();
262267
MaterialDesign\Theme\Widgets\setup();
268+
MaterialDesign\Theme\BlockEditor\setup();

0 commit comments

Comments
 (0)