Skip to content

Commit

Permalink
Display URL input field for changing the button href attr.
Browse files Browse the repository at this point in the history
This uses the default link-modal implemented for Editable,
but displays it all the time.

Positioninig is determined by block alignment.

Position URL input to the left when button is aligned right.
  • Loading branch information
mtias committed May 4, 2017
1 parent 170a330 commit 3a8e912
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
18 changes: 14 additions & 4 deletions blocks/library/button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import './style.scss';
import { registerBlock, query } from 'api';
import Editable from 'components/editable';
import Dashicon from '../../../editor/components/dashicon';
import IconButton from '../../../editor/components/icon-button';

const { attr, children } = query;

Expand Down Expand Up @@ -77,9 +77,19 @@ registerBlock( 'core/button', {
onChange={ ( value ) => setAttributes( { text: value } ) }
/>
{ focus &&
<a className="blocks-button__link" href={ url } target="_blank">
<Dashicon icon="external" />
</a>
<form
className="editable-format-toolbar__link-modal"
onSubmit={ ( event ) => event.preventDefault() }>
<input
className="editable-format-toolbar__link-input"
type="url"
required
value={ url }
onChange={ ( event ) => setAttributes( { url: event.target.value } ) }
placeholder={ wp.i18n.__( 'Paste URL or type' ) }
/>
<IconButton icon="editor-break" type="submit" />
</form>
}
</span>
);
Expand Down
11 changes: 11 additions & 0 deletions blocks/library/button/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
&:hover {
color: $white;
}

.editable-format-toolbar__link-modal {
top: -1px;
left: calc( 100% + 12px );
}
}

.blocks-button__link {
Expand All @@ -46,5 +51,11 @@

&[data-align="right"] {
text-align: right;

.editable-format-toolbar__link-modal {
top: -1px;
left: auto;
right: calc( 100% + 12px );
}
}
}

0 comments on commit 3a8e912

Please sign in to comment.