diff --git a/packages/block-editor/src/components/url-popover/README.md b/packages/block-editor/src/components/url-popover/README.md index 240daaf43c45d3..86805b10229e87 100644 --- a/packages/block-editor/src/components/url-popover/README.md +++ b/packages/block-editor/src/components/url-popover/README.md @@ -111,3 +111,80 @@ drawer. - Type: `Function` - Required: No + + +## Useful UI pieces + +The URLPopover exposes two components that may be used as child components to make the UI creation process easier. +Although in the editor these components are used inside URLPopover and they were built with URLPopover use cases in mind, it maybe is possible and perfectly fine to use them standalone if they fit a use-case. + +### LinkViewer + +LinkViewer provides a simple UI that allows users to see a link and may also offer a button to switch to a mode that will enable editing that link. +The component accepts the following props. Any other props are passed through to the underlying `div` container. + +### className + +A class that together with "block-editor-url-popover__link-viewer" is used as a class of the wrapper div. +If no className is passed only "block-editor-url-popover__link-viewer" is used. + +- Type: `String` +- Required: No + +### linkClassName + +A class that will be used in the component that renders the link. + +- Type: `String` +- Required: No + +### url + +The current URL to view. + +- Type: `String` +- Required: Yes + +### urlLabel + +The URL label, if not passed a label is automatically generated from the `url`. + +- Type: `String` +- Required: No + +### onEditLinkClick + +A function called when the user presses the button that allows editing a link. If not passed the link-edit button is not rendered. + +- Type: `function` +- Required: No + + +### LinkEditor + +LinkEditor provides a simple UI that allows users to edit link. +The component accepts the following props. Any other props are passed through to the underlying `form` container. + +### value + +This property should be set to the attribute (or component state) property used to store the URL. +This property is directly passed to `URLInput` component ([refer to its documentation](/packages/components/src/url-input/README.md)) to read additional details. + +- Type: `String` +- Required: Yes + +### onChange + +Called when the value changes. The second parameter is `null` unless the user selects a post from the suggestions dropdown. +More +This property is directly passed to component `URLInput` ([refer to its documentation](/packages/components/src/url-input/README.md)) to read additional details. + +- Type: `function` +- Required: Yes + +### autocompleteRef + +Reference passed to the auto complete element of the ([URLInput component](/packages/components/src/url-input/README.md)). + +- Type: `Object` +- Required: no diff --git a/packages/block-editor/src/components/url-popover/index.js b/packages/block-editor/src/components/url-popover/index.js index d3c7c874c6892a..bc4354cbeb9a01 100644 --- a/packages/block-editor/src/components/url-popover/index.js +++ b/packages/block-editor/src/components/url-popover/index.js @@ -1,24 +1,18 @@ -/** - * External dependencies - */ -import classnames from 'classnames'; - /** * WordPress dependencies */ import { __ } from '@wordpress/i18n'; import { Component } from '@wordpress/element'; import { - ExternalLink, IconButton, Popover, } from '@wordpress/components'; -import { safeDecodeURI, filterURLForDisplay } from '@wordpress/url'; /** * Internal dependencies */ -import URLInput from '../url-input'; +import LinkViewer from './link-viewer'; +import LinkEditor from './link-editor'; class URLPopover extends Component { constructor() { @@ -91,75 +85,9 @@ class URLPopover extends Component { } } -const LinkEditor = ( { - autocompleteRef, - className, - onChangeInputValue, - value, - ...props -} ) => ( -
-); - -URLPopover.__experimentalLinkEditor = LinkEditor; - -const LinkViewerUrl = ( { url, urlLabel, className } ) => { - const linkClassName = classnames( - className, - 'block-editor-url-popover__link-viewer-url' - ); - - if ( ! url ) { - return ; - } - - return ( -