Skip to content

Commit

Permalink
rename home block to home-link
Browse files Browse the repository at this point in the history
  • Loading branch information
gwwar committed Apr 20, 2021
1 parent 95a94d0 commit 3f7ba3f
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function gutenberg_reregister_core_block_types() {
'group',
'heading',
'html',
'home',
'home-link',
'image',
'list',
'media-text',
Expand Down Expand Up @@ -60,7 +60,7 @@ function gutenberg_reregister_core_block_types() {
'loginout.php' => 'core/loginout',
'navigation.php' => 'core/navigation',
'navigation-link.php' => 'core/navigation-link',
'home.php' => 'core/home',
'home-link.php' => 'core/home-link',
'rss.php' => 'core/rss',
'search.php' => 'core/search',
'shortcode.php' => 'core/shortcode',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"apiVersion": 2,
"name": "core/home",
"name": "core/home-link",
"category": "design",
"parent": [ "core/navigation" ],
"attributes": {
Expand All @@ -26,6 +26,6 @@
"reusable": false,
"html": false
},
"editorStyle": "wp-block-home-editor",
"style": "wp-block-home"
"editorStyle": "wp-block-home-link-editor",
"style": "wp-block-home-link"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { RichText, useBlockProps } from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { useEffect } from '@wordpress/element';

const preventDefault = ( event ) => event.preventDefault();

Expand All @@ -24,16 +25,22 @@ export default function HomeEdit( { attributes, setAttributes, clientId } ) {

const { label } = attributes;

useEffect( () => {
if ( label === undefined ) {
setAttributes( { label: __( 'Home' ) } );
}
}, [ clientId, label ] );

return (
<li { ...blockProps }>
<a
className="wp-block-home__content"
className="wp-block-home-link__content"
href={ homeUrl }
onClick={ preventDefault }
>
<RichText
identifier="label"
className="wp-block-home__label"
className="wp-block-home-link__label"
value={ label }
onChange={ ( labelValue ) => {
setAttributes( { label: labelValue } );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const settings = {

example: {
attributes: {
label: _x( 'Home', 'Home preview example' ),
label: _x( 'Home', 'Home Link preview example' ),
},
},
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Renders the `core/home` block.
* Renders the `core/home-link` block.
*
* @param array $attributes The block attributes.
*
Expand Down Expand Up @@ -52,7 +52,7 @@ function render_block_core_home( $attributes ) {
*/
function register_block_core_home() {
register_block_type_from_metadata(
__DIR__ . '/home',
__DIR__ . '/home-link',
array(
'render_callback' => 'render_block_core_home',
)
Expand Down
File renamed without changes.
29 changes: 29 additions & 0 deletions packages/block-library/src/home-link/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.wp-block-navigation {
// Force links to inherit text decoration applied to navigation block.
// The extra selector adds specificity to ensure it works when user-set.
&[style*="text-decoration"] {
.wp-block-home-link {
text-decoration: inherit;
}

.wp-block-home-link__content {
text-decoration: inherit;

&:focus,
&:active {
text-decoration: inherit;
}
}
}

&:not([style*="text-decoration"]) {
.wp-block-home-link__content {
text-decoration: none;

&:focus,
&:active {
text-decoration: none;
}
}
}
}
3 changes: 0 additions & 3 deletions packages/block-library/src/home/style.scss

This file was deleted.

4 changes: 2 additions & 2 deletions packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import * as html from './html';
import * as mediaText from './media-text';
import * as navigation from './navigation';
import * as navigationLink from './navigation-link';
import * as home from './home';
import * as homeLink from './home-link';
import * as latestComments from './latest-comments';
import * as latestPosts from './latest-posts';
import * as legacyWidget from './legacy-widget';
Expand Down Expand Up @@ -216,7 +216,7 @@ export const __experimentalRegisterExperimentalCoreBlocks =
[
navigation,
navigationLink,
home,
homeLink,

// Register Legacy Widget block.
...( enableLegacyWidgetBlock ? [ legacyWidget ] : [] ),
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/navigation/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const ALLOWED_BLOCKS = [
'core/social-links',
'core/page-list',
'core/spacer',
'core/home',
'core/home-link',
];

const LAYOUT = {
Expand Down

0 comments on commit 3f7ba3f

Please sign in to comment.