-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Inserter: Trying v1 for the block inserter #307
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
const { query, html } = wp.blocks.query; | ||
|
||
wp.blocks.registerBlock( 'wp/text', { | ||
title: 'Text', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll need to start considering i18n in a separate issue. |
||
icon: 'text', | ||
|
||
attributes: { | ||
value: query( 'p', html() ) | ||
}, | ||
|
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import InserterButton from '../inserter/button'; | ||
|
||
const el = wp.element.createElement; | ||
|
||
const Editor = ( { state: { blocks, inserter }, toggleInserter } ) => { | ||
return el( 'div', null, | ||
el( 'div', { contentEditable: true }, | ||
wp.blocks.createBlockElement( blocks[ 1 ] ) | ||
), | ||
el( InserterButton, { onClick: toggleInserter, opened: inserter.opened } ) | ||
); | ||
}; | ||
|
||
export default Editor; |
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,41 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import EditorComponent from './editor'; | ||
|
||
const el = wp.element.createElement; | ||
|
||
export default class Editor { | ||
constructor( id, settings ) { | ||
this.toggleInserter = this.toggleInserter.bind( this ); | ||
this.id = id; | ||
this.settings = settings; | ||
this.state = { | ||
inserter: { opened: false }, | ||
blocks: wp.blocks.parse( settings.content ) | ||
}; | ||
console.log( this.state.blocks ); // eslint-disable-line no-console | ||
this.render(); | ||
} | ||
|
||
setState( newState ) { | ||
this.state = Object.assign( {}, this.state, newState ); | ||
this.render(); | ||
} | ||
|
||
toggleInserter() { | ||
this.setState( { | ||
inserter: { opened: ! this.state.inserter.opened } | ||
} ); | ||
} | ||
|
||
render() { | ||
wp.element.render( | ||
el( EditorComponent, { | ||
state: this.state, | ||
toggleInserter: this.toggleInserter | ||
} ), | ||
document.getElementById( this.id ) | ||
); | ||
} | ||
} |
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 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import Inserter from './'; | ||
|
||
const el = wp.element.createElement; | ||
|
||
const InserterButton = ( { opened, onClick } ) => { | ||
return el( 'div', { className: 'inserter__button' }, | ||
el( 'a', { className: 'inserter__button-toggle', onClick }, | ||
el( 'span', { className: 'dashicons dashicons-plus' } ) | ||
), | ||
opened && el( Inserter ) | ||
); | ||
}; | ||
|
||
export default InserterButton; |
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,22 @@ | ||
const el = wp.element.createElement; | ||
|
||
const Inserter = () => { | ||
const blocks = wp.blocks.getBlocks(); | ||
|
||
return el( 'div', { className: 'inserter' }, | ||
el( 'div', { className: 'inserter__arrow' } ), | ||
el( 'div', { className: 'inserter__content' }, | ||
el( 'div', { className: 'inserter__category-blocks' }, | ||
blocks.map( ( { slug, title, icon } ) => ( | ||
el( 'div', { key: slug, className: 'inserter__block' }, | ||
el( 'span', { className: 'dashicons dashicons-' + icon } ), | ||
title | ||
) | ||
) ) | ||
) | ||
), | ||
el( 'input', { className: 'inserter__search', type: 'search', placeholder: 'Search...' } ) | ||
); | ||
}; | ||
|
||
export default Inserter; |
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,136 @@ | ||
.inserter__button { | ||
display: inline-block; | ||
position: relative; | ||
background: none; | ||
border: none; | ||
padding: 0; | ||
margin-top: 20px; | ||
} | ||
|
||
.inserter__button-toggle { | ||
display: inline-block; | ||
color: #87919d; | ||
cursor: pointer; | ||
border-radius: 12px; | ||
border: 2px solid #87919d; | ||
width: 24px; | ||
height: 24px; | ||
padding: 0; | ||
margin: 0; | ||
|
||
.dashicons { | ||
padding: 1px 0; | ||
} | ||
|
||
&:hover { | ||
color: #12181e; | ||
border-color: #12181e; | ||
} | ||
} | ||
|
||
.inserter { | ||
width: 280px; | ||
box-shadow: 0px 3px 20px rgba( 18, 24, 30, .1 ), 0px 1px 3px rgba( 18, 24, 30, .1 ); | ||
border: 1px solid #e0e5e9; | ||
position: absolute; | ||
left: -130px; | ||
bottom: 40px; | ||
background: #fff; | ||
} | ||
|
||
.inserter__arrow { | ||
border: 10px dashed #e0e5e9; | ||
height: 0; | ||
line-height: 0; | ||
position: absolute; | ||
width: 0; | ||
z-index: 1; | ||
bottom: -10px; | ||
left: 50%; | ||
margin-left: -10px; | ||
border-top-style: solid; | ||
border-bottom: none; | ||
border-left-color: transparent; | ||
border-right-color: transparent; | ||
|
||
&:before { | ||
bottom: 2px; | ||
border: 10px solid white; | ||
content: " "; | ||
position: absolute; | ||
left: 50%; | ||
margin-left: -10px; | ||
border-top-style: solid; | ||
border-bottom: none; | ||
border-left-color: transparent; | ||
border-right-color: transparent; | ||
} | ||
} | ||
|
||
.inserter__content { | ||
max-height: 180px; | ||
overflow: auto; | ||
|
||
&:focus { | ||
outline: none; | ||
} | ||
} | ||
|
||
.inserter__search { | ||
display: block; | ||
width: 100%; | ||
border: none; | ||
margin: 0; | ||
border-top: 1px solid #e0e5e9; | ||
padding: 8px 16px; | ||
font-size: 13px; | ||
|
||
&:focus { | ||
outline: none; | ||
} | ||
} | ||
|
||
.inserter__category-blocks { | ||
display: flex; | ||
flex-flow: row wrap; | ||
} | ||
|
||
.inserter__block { | ||
display: flex; | ||
width: 50%; | ||
color: #86909B; | ||
padding: 8px; | ||
font-size: 11px; | ||
align-items: center; | ||
cursor: pointer; | ||
border: 1px solid transparent; | ||
|
||
&:hover { | ||
background: #f8f9f9; | ||
border: 1px solid #6d7882; | ||
position: relative; | ||
} | ||
|
||
&.is-active { | ||
background: #eef0f0; | ||
border: 1px solid #6d7882; | ||
position: relative; | ||
color: #3e444c; | ||
} | ||
|
||
.dashicons { | ||
color: #191e23; | ||
margin-right: 8px; | ||
} | ||
} | ||
|
||
.inserter__separator { | ||
background: rgb(247,248,249); | ||
display: block; | ||
padding: 2px 12px; | ||
letter-spacing: 1px; | ||
text-transform: uppercase; | ||
font-size: 11px; | ||
font-weight: 500; | ||
color: #9ea7af; | ||
} |
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.
In our prototype @intronic and me have been using CSS modules which allows for a better style encapsulation and maintainability. I think it's a step above BEM and it would be worth trying. A first step towards this direction would be to start migrating some sections such this one.
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.
I agree CSS modules is really nice. Maybe, we could consider it once we settle the other moving parts.
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.
I'm not too keen on CSS modules (nor it's evolution in styled-components), I think they erode semantics, and complicate things in which CSS is good at (passing props to style things couples the whole node tree with the intentions of a grand-parent that may want to modify a grand-children style props).
In our case I think it makes even less sense because blocks will be restyled by themes, so we do need the strong semantics and ability to externally modify styles. The pseudo BEM here is not strictly BEM either (we don't rely on the same kind of modifier) and is something we've been using in Calypso to reflect the component structure in place.