-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "More" block. #1440
Merged
Merged
Add "More" block. #1440
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
f46ae7a
Add "More" block.
mtias e614f31
Polish the styles and description a bit.
jasmussen a085101
Add test files
ellatrix 74d4d28
Use BlockDescription component
swissspidy bc25566
Rename test files
swissspidy a067bd2
Update block name
swissspidy b9f311b
Update grammar
swissspidy 2c6b53b
Update tests
swissspidy d3ecbbb
Fix block description
swissspidy d7f3ef2
Use default class name
swissspidy 567735e
Fix vertical alignment
swissspidy 28ce6cb
Fix serializer
swissspidy a8b9062
Add ToggleControl for noTeaser option
swissspidy c642df3
Add trailing comma
swissspidy 2c09b4d
Fix tests
swissspidy ca1d612
More Block: Avoid unnecessary space when no custom text is provided
youknowriad 6bb1343
More Block: It should only be used once
youknowriad cd1d11c
More Block: Fix inspector controls (description position and drop the…
youknowriad 260857f
More Block: Fix the text style (center vertically)
youknowriad 26e3c38
More Block: Drop useless prop
youknowriad 25cf370
More Block: Using Input instead of Editable
youknowriad 0039599
Test: Checked the parsed block by checking the JSON file
youknowriad f9d9aed
More Block: Adding a test with no-teaser and a custom test
youknowriad e7f04b0
More Block: Adding a full featured unit test
youknowriad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,64 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from 'i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './style.scss'; | ||
import { registerBlockType } from '../../api'; | ||
import InspectorControls from '../../inspector-controls'; | ||
import BlockDescription from '../../block-description'; | ||
import ToggleControl from '../../inspector-controls/toggle-control'; | ||
|
||
registerBlockType( 'core/more', { | ||
title: __( 'More' ), | ||
|
||
icon: 'editor-insertmore', | ||
|
||
category: 'layout', | ||
|
||
useOnce: true, | ||
|
||
className: false, | ||
|
||
edit( { attributes, setAttributes, focus, setFocus } ) { | ||
const { text, noTeaser } = attributes; | ||
|
||
const toggleNoTeaser = () => setAttributes( { noTeaser: ! noTeaser } ); | ||
const defaultText = __( 'Read more' ); | ||
const value = text !== undefined ? text : defaultText; | ||
const inputLength = value.length ? value.length + 1 : 1; | ||
|
||
return [ | ||
focus && ( | ||
<InspectorControls key="inspector"> | ||
<BlockDescription> | ||
<p>{ __( '"More" allows you to break your post into a part shown on index pages, and the subsequent after clicking a "Read More" link.' ) }</p> | ||
</BlockDescription> | ||
<ToggleControl | ||
label={ __( 'Hide the teaser before the "More" tag' ) } | ||
checked={ !! noTeaser } | ||
onChange={ toggleNoTeaser } | ||
/> | ||
</InspectorControls> | ||
), | ||
<div key="more-tag" className="wp-block-more"> | ||
<input | ||
type="text" | ||
value={ value } | ||
size={ inputLength } | ||
onChange={ ( event ) => setAttributes( { text: event.target.value } ) } | ||
onFocus={ setFocus } | ||
/> | ||
</div>, | ||
]; | ||
}, | ||
|
||
save( { attributes } ) { | ||
const { text } = attributes; | ||
|
||
return text; | ||
}, | ||
} ); |
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,34 @@ | ||
.editor-visual-editor__block[data-type="core/more"] { | ||
max-width: 100%; | ||
text-align: center; | ||
} | ||
|
||
.editor-visual-editor__block .wp-block-more { | ||
input { | ||
font-size: 12px; | ||
text-transform: uppercase; | ||
font-weight: 600; | ||
font-family: $default-font; | ||
color: $dark-gray-300; | ||
padding-left: 8px; | ||
padding-right: 8px; | ||
background: $white; | ||
border: none; | ||
box-shadow: none; | ||
white-space: nowrap; | ||
|
||
&:focus { | ||
box-shadow: none; | ||
} | ||
} | ||
|
||
&:before { | ||
content: ''; | ||
position: absolute; | ||
top: calc( 50% ); | ||
left: $block-mover-padding-visible + $block-padding; | ||
right: $block-mover-padding-visible + $block-padding; | ||
border-top: 3px dashed $light-gray-700; | ||
z-index: z-index( '.editor-visual-editor__block .wp-block-more:before' ); | ||
} | ||
} |
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 @@ | ||
<!--more--> |
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,11 @@ | ||
[ | ||
{ | ||
"uid": "_uid_0", | ||
"name": "core/more", | ||
"isValid": true, | ||
"attributes": { | ||
"customText": null, | ||
"noTeaser": false | ||
} | ||
} | ||
] |
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,14 @@ | ||
[ | ||
{ | ||
"blockName": "core/more", | ||
"attrs": { | ||
"customText": null, | ||
"noTeaser": false | ||
}, | ||
"rawContent": "" | ||
}, | ||
{ | ||
"attrs": {}, | ||
"rawContent": "\n" | ||
} | ||
] |
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 @@ | ||
<!--more--> |
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,2 @@ | ||
<!--more Continue Reading--> | ||
<!--noteaser--> |
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,11 @@ | ||
[ | ||
{ | ||
"uid": "_uid_0", | ||
"name": "core/more", | ||
"isValid": true, | ||
"attributes": { | ||
"customText": "Continue Reading", | ||
"noTeaser": true | ||
} | ||
} | ||
] |
14 changes: 14 additions & 0 deletions
14
blocks/test/fixtures/core__more__custom-text-teaser.parsed.json
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,14 @@ | ||
[ | ||
{ | ||
"blockName": "core/more", | ||
"attrs": { | ||
"customText": "Continue Reading", | ||
"noTeaser": true | ||
}, | ||
"rawContent": "" | ||
}, | ||
{ | ||
"attrs": {}, | ||
"rawContent": "\n" | ||
} | ||
] |
2 changes: 2 additions & 0 deletions
2
blocks/test/fixtures/core__more__custom-text-teaser.serialized.html
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,2 @@ | ||
<!--more--> | ||
<!--noteaser--> |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
props.className
instead of"wp-block-more"
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, when we set the
className
to false, there's no className propThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we set the
className
to false if we clearly want one? Is this related tosave
auto-applying the class name?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's more related to the className input showing in the inspector if the className is not set to false