-
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 optional link to image blocks #1772
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8cb6624
Create UrlInput component.
mtias 32a991d
Add support for href value to image blocks.
mtias 16d5295
Polish link input positioning.
jasmussen 4c20e5e
Push some more polish
jasmussen e0a787f
Handle already set url and dismiss link input when submitting link wi…
mtias df602ea
Code style cleanup.
mtias 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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import './style.scss'; | ||
import { __ } from 'i18n'; | ||
import { Component } from 'element'; | ||
import { IconButton } from 'components'; | ||
|
||
class UrlInput extends Component { | ||
constructor() { | ||
super( ...arguments ); | ||
this.toggle = this.toggle.bind( this ); | ||
this.submitLink = this.submitLink.bind( this ); | ||
this.state = { | ||
expanded: false, | ||
}; | ||
} | ||
|
||
toggle() { | ||
this.setState( { expanded: ! this.state.expanded } ); | ||
} | ||
|
||
submitLink( event ) { | ||
event.preventDefault(); | ||
this.toggle(); | ||
} | ||
|
||
render() { | ||
const { url, onChange } = this.props; | ||
const { expanded } = this.state; | ||
|
||
return ( | ||
<li className="components-url-input"> | ||
<IconButton | ||
icon="admin-links" | ||
onClick={ this.toggle } | ||
className={ classnames( 'components-toolbar__control', { | ||
'is-active': url, | ||
} ) } | ||
/> | ||
{ expanded && | ||
<form | ||
className="editable-format-toolbar__link-modal" | ||
onSubmit={ this.submitLink }> | ||
<IconButton className="components-url-input__back" icon="arrow-left-alt" onClick={ this.toggle } /> | ||
<input | ||
className="editable-format-toolbar__link-input" | ||
type="url" | ||
value={ url } | ||
onChange={ onChange } | ||
placeholder={ __( 'Paste URL or type' ) } | ||
/> | ||
<IconButton icon="editor-break" type="submit" /> | ||
</form> | ||
} | ||
</li> | ||
); | ||
} | ||
} | ||
|
||
export default UrlInput; |
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,18 @@ | ||
ul.components-toolbar > li.components-url-input { | ||
position: inherit; // let the dialog position according to parent | ||
} | ||
|
||
.components-url-input .components-url-input__back { | ||
margin-right: 4px; | ||
overflow: visible; | ||
|
||
&::after { | ||
content: ''; | ||
position: absolute; | ||
display: block; | ||
width: 1px; | ||
height: 24px; | ||
right: -1px; | ||
background: $light-gray-500; | ||
} | ||
} |
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.
Wondering if
url
should be managed in state, and the parent component instead binds toonSubmit
.Maybe also, should
url
be reset when toggling the expanded state?My thinking is "url" is state relevant only so long as the input is expanded.
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 had that initially, but we also need it when collapsed to show the button state (dark gray), so it seems a prop is more accurate.