-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from material-components/feature/hide-title
Allow hiding page title
- Loading branch information
Showing
14 changed files
with
6,093 additions
and
1,619 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
# Copyright 2020 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
docker-compose run --rm -u 1000 --workdir=/var/www/html/wp-content/themes/material-design-google wordpress -- composer test |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import './plugins/hide-sections'; |
119 changes: 119 additions & 0 deletions
119
theme/assets/src/block-editor/plugins/hide-sections/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/** | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* Wordpress Dependencies | ||
*/ | ||
import { registerPlugin } from '@wordpress/plugins'; | ||
import { PluginDocumentSettingPanel } from '@wordpress/edit-post'; | ||
import { Icon, CheckboxControl } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { compose, ifCondition } from '@wordpress/compose'; | ||
import { withSelect, withDispatch } from '@wordpress/data'; | ||
import { useState } from '@wordpress/element'; | ||
|
||
function HideSection( { settings, updateSectionsSettings } ) { | ||
/** | ||
* If you add a new property here, make sure to also add it | ||
* in the "properties" array at block-editor.php. | ||
*/ | ||
const settingsOptionsInitial = [ | ||
{ | ||
label: __( 'Hide Title', 'material' ), | ||
key: 'title', | ||
}, | ||
]; | ||
|
||
settingsOptionsInitial.forEach( settingOption => { | ||
settingOption.value = settings[ settingOption.key ] | ||
? settings[ settingOption.key ] | ||
: false; | ||
} ); | ||
|
||
const [ settingsOptions, setSettingOptions ] = useState( | ||
settingsOptionsInitial | ||
); | ||
|
||
return ( | ||
<PluginDocumentSettingPanel | ||
name="sections-control" | ||
title={ __( 'Hide Sections', 'material' ) } | ||
className="custom-panel" | ||
> | ||
{ settingsOptions.map( settingOption => { | ||
return ( | ||
<CheckboxControl | ||
checked={ | ||
settings[ settingOption.key ] | ||
? settings[ settingOption.key ] | ||
: false | ||
} | ||
onChange={ state => { | ||
const newSettings = { ...settings }; | ||
newSettings[ settingOption.key ] = state; | ||
const newSettingsOptions = settingsOptions; | ||
newSettingsOptions.forEach( newSettingOption => { | ||
if ( newSettingOption.key === settingOption.key ) { | ||
newSettingOption.value = state; | ||
} | ||
} ); | ||
updateSectionsSettings( newSettings ); | ||
setSettingOptions( newSettingsOptions ); | ||
} } | ||
label={ settingOption.label } | ||
key={ settingOption.key } | ||
/> | ||
); | ||
} ) } | ||
</PluginDocumentSettingPanel> | ||
); | ||
} | ||
|
||
const WrappedSectionControl = compose( [ | ||
withSelect( select => { | ||
const { getCurrentPostType } = select( 'core/editor' ); | ||
const { getPostType } = select( 'core' ); | ||
return { | ||
postTypeObj: getPostType( getCurrentPostType() ), | ||
}; | ||
} ), | ||
ifCondition( ( { postTypeObj } ) => { | ||
return postTypeObj?.supports?.[ 'custom-fields' ]; | ||
} ), | ||
withSelect( select => { | ||
const { getEditedPostAttribute } = select( 'core/editor' ); | ||
return { | ||
settings: getEditedPostAttribute( 'meta' )[ 'material-hide-sections' ], | ||
}; | ||
} ), | ||
withDispatch( dispatch => { | ||
return { | ||
updateSectionsSettings( settings ) { | ||
dispatch( 'core/editor' ).editPost( { | ||
meta: { 'material-hide-sections': settings }, | ||
} ); | ||
}, | ||
}; | ||
} ), | ||
ifCondition( ( { settings } ) => { | ||
return !! settings; | ||
} ), | ||
] )( HideSection ); | ||
|
||
registerPlugin( 'material-hide-sections', { | ||
render: WrappedSectionControl, | ||
icon: <Icon icon="admin-customizer" />, | ||
} ); |
37 changes: 37 additions & 0 deletions
37
theme/assets/src/block-editor/plugins/hide-sections/style.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
.has-hide-title { | ||
|
||
.entry-title { | ||
display: none; | ||
} | ||
|
||
.-has-tab-bar + .site-content .content-area { | ||
margin-top: 7rem; | ||
} | ||
|
||
.-has-tab-bar + .site-content .content-area { | ||
|
||
@media (max-width: 599px) { | ||
margin-top: 6rem; | ||
} | ||
} | ||
|
||
.entry-content .wp-block-cover:first-child { | ||
margin-top: 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
/** | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* @package MaterialDesign | ||
*/ | ||
|
||
namespace MaterialDesign\Theme\BlockEditor; | ||
|
||
/** | ||
* Add hooks and filters. | ||
*/ | ||
function setup() { | ||
add_action( 'init', __NAMESPACE__ . '\\register_disable_section_meta' ); | ||
add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\\enqueue_block_editor_assets' ); | ||
add_action( 'body_class', __NAMESPACE__ . '\\filter_body_class' ); | ||
} | ||
|
||
/** | ||
* Register disable section meta. | ||
*/ | ||
function register_disable_section_meta() { | ||
register_post_meta( | ||
'', | ||
'material-hide-sections', | ||
[ | ||
'type' => 'object', | ||
'description' => 'Whether the title should be shown in frontend.', | ||
'object_type' => 'post', | ||
'single' => true, | ||
'default' => [], | ||
'show_in_rest' => [ | ||
'schema' => [ | ||
'type' => 'object', | ||
/** | ||
* If you add a new property here, make sure to also add it | ||
* in the "settingsOptionsInitial" object here: | ||
* assets/src/js/block-editor/plugins/hide-sections/index.js | ||
*/ | ||
'properties' => [ | ||
'title' => [ 'type' => 'boolean' ], | ||
], | ||
'additionalProperties' => [ | ||
'type' => 'boolean', | ||
], | ||
], | ||
], | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Enqueue block editor assets. | ||
*/ | ||
function enqueue_block_editor_assets() { | ||
$asset_file = get_stylesheet_directory() . '/assets/js/block-editor.asset.php'; | ||
$asset = is_readable( $asset_file ) ? require $asset_file : []; | ||
$version = isset( $asset['version'] ) ? $asset['version'] : wp_get_theme()->get( 'Version' ); | ||
$dependencies = isset( $asset['dependencies'] ) ? $asset['dependencies'] : []; | ||
|
||
wp_enqueue_script( | ||
'material-block-editor-js-theme', | ||
get_stylesheet_directory_uri() . '/assets/js/block-editor.js', | ||
$dependencies, | ||
$version, | ||
false | ||
); | ||
} | ||
|
||
/** | ||
* Filter body class. | ||
* | ||
* @param array $classes Body class. | ||
* | ||
* @return array | ||
*/ | ||
function filter_body_class( $classes ) { | ||
if ( is_single() || is_page() ) { | ||
$meta = get_post_meta( get_the_ID(), 'material-hide-sections', true ); | ||
if ( ! empty( $meta['title'] ) ) { | ||
$classes[] = 'has-hide-title'; | ||
} | ||
} | ||
|
||
return $classes; | ||
} |
Oops, something went wrong.