-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Editor: Extract LinkContainer from FormatToolbar (#9192)
* Editor: Extract LinkContainer from FormatToolbar * Format toolbar: Improve derived state handling * Rich Text: Remove obsolete DEFAULT_CONTROLS constant
- Loading branch information
Showing
4 changed files
with
177 additions
and
130 deletions.
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
113 changes: 113 additions & 0 deletions
113
packages/editor/src/components/rich-text/format-toolbar/link-container.js
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,113 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
ExternalLink, | ||
Fill, | ||
IconButton, | ||
Popover, | ||
ToggleControl, | ||
} from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import PositionedAtSelection from './positioned-at-selection'; | ||
import URLInput from '../../url-input'; | ||
import { filterURLForDisplay } from '../../../utils/url'; | ||
|
||
const stopKeyPropagation = ( event ) => event.stopPropagation(); | ||
|
||
const LinkContainer = ( props ) => { | ||
const { | ||
editLink, | ||
formats, | ||
isEditing, | ||
isPreviewing, | ||
linkValue, | ||
onChangeLinkValue, | ||
onKeyDown, | ||
opensInNewWindow, | ||
selectedNodeId, | ||
setLinkTarget, | ||
settingsVisible, | ||
submitLink, | ||
toggleLinkSettingsVisibility, | ||
} = props; | ||
|
||
const linkSettings = settingsVisible && ( | ||
<div className="editor-format-toolbar__link-modal-line editor-format-toolbar__link-settings"> | ||
<ToggleControl | ||
label={ __( 'Open in New Window' ) } | ||
checked={ opensInNewWindow } | ||
onChange={ setLinkTarget } /> | ||
</div> | ||
); | ||
|
||
return ( | ||
<Fill name="RichText.Siblings"> | ||
<PositionedAtSelection className="editor-format-toolbar__link-container"> | ||
<Popover | ||
position="bottom center" | ||
focusOnMount={ isEditing ? 'firstElement' : false } | ||
key={ selectedNodeId /* Used to force rerender on change */ } | ||
> | ||
{ isEditing && ( | ||
// Disable reason: KeyPress must be suppressed so the block doesn't hide the toolbar | ||
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */ | ||
<form | ||
className="editor-format-toolbar__link-modal" | ||
onKeyPress={ stopKeyPropagation } | ||
onKeyDown={ onKeyDown } | ||
onSubmit={ submitLink }> | ||
<div className="editor-format-toolbar__link-modal-line"> | ||
<URLInput value={ linkValue } onChange={ onChangeLinkValue } /> | ||
<IconButton icon="editor-break" label={ __( 'Apply' ) } type="submit" /> | ||
<IconButton | ||
className="editor-format-toolbar__link-settings-toggle" | ||
icon="ellipsis" | ||
label={ __( 'Link Settings' ) } | ||
onClick={ toggleLinkSettingsVisibility } | ||
aria-expanded={ settingsVisible } | ||
/> | ||
</div> | ||
{ linkSettings } | ||
</form> | ||
/* eslint-enable jsx-a11y/no-noninteractive-element-interactions */ | ||
) } | ||
|
||
{ isPreviewing && ( | ||
// Disable reason: KeyPress must be suppressed so the block doesn't hide the toolbar | ||
/* eslint-disable jsx-a11y/no-static-element-interactions */ | ||
<div | ||
className="editor-format-toolbar__link-modal" | ||
onKeyPress={ stopKeyPropagation } | ||
> | ||
<div className="editor-format-toolbar__link-modal-line"> | ||
<ExternalLink | ||
className="editor-format-toolbar__link-value" | ||
href={ formats.link.value } | ||
> | ||
{ formats.link.value && filterURLForDisplay( decodeURI( formats.link.value ) ) } | ||
</ExternalLink> | ||
<IconButton icon="edit" label={ __( 'Edit' ) } onClick={ editLink } /> | ||
<IconButton | ||
className="editor-format-toolbar__link-settings-toggle" | ||
icon="ellipsis" | ||
label={ __( 'Link Settings' ) } | ||
onClick={ toggleLinkSettingsVisibility } | ||
aria-expanded={ settingsVisible } | ||
/> | ||
</div> | ||
{ linkSettings } | ||
</div> | ||
/* eslint-enable jsx-a11y/no-static-element-interactions */ | ||
) } | ||
</Popover> | ||
</PositionedAtSelection> | ||
</Fill> | ||
); | ||
}; | ||
|
||
export default LinkContainer; |
32 changes: 32 additions & 0 deletions
32
packages/editor/src/components/rich-text/formatting-controls.js
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,32 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { displayShortcut } from '@wordpress/keycodes'; | ||
|
||
export const FORMATTING_CONTROLS = [ | ||
{ | ||
icon: 'editor-bold', | ||
title: __( 'Bold' ), | ||
shortcut: displayShortcut.primary( 'b' ), | ||
format: 'bold', | ||
}, | ||
{ | ||
icon: 'editor-italic', | ||
title: __( 'Italic' ), | ||
shortcut: displayShortcut.primary( 'i' ), | ||
format: 'italic', | ||
}, | ||
{ | ||
icon: 'admin-links', | ||
title: __( 'Link' ), | ||
shortcut: displayShortcut.primary( 'k' ), | ||
format: 'link', | ||
}, | ||
{ | ||
icon: 'editor-strikethrough', | ||
title: __( 'Strikethrough' ), | ||
shortcut: displayShortcut.access( 'd' ), | ||
format: 'strikethrough', | ||
}, | ||
]; |
Oops, something went wrong.