Skip to content
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

Update link editor previews and edit #62541

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions packages/editor/src/components/post-url/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
ExternalLink,
Button,
__experimentalInputControl as InputControl,
__experimentalInputControlPrefixWrapper as InputControlPrefixWrapper,
__experimentalVStack as VStack,
} from '@wordpress/components';
import { store as noticesStore } from '@wordpress/notices';
Expand Down Expand Up @@ -83,7 +82,9 @@ export default function PostURL( { onClose } ) {
<VStack spacing={ 3 }>
{ isEditable && (
<div>
{ __( 'Customize the last part of the URL. ' ) }
{ __(
'Customize the post name in the URL (in bold below). '
) }
<ExternalLink
href={ __(
'https://wordpress.org/documentation/article/page-post-settings-sidebar/#permalink'
Expand All @@ -97,16 +98,11 @@ export default function PostURL( { onClose } ) {
{ isEditable && (
<InputControl
__next40pxDefaultSize
prefix={
<InputControlPrefixWrapper>
/
</InputControlPrefixWrapper>
}
suffix={
<Button
icon={ copySmall }
ref={ copyButtonRef }
label={ __( 'Copy' ) }
label={ __( 'Copy Link' ) }
/>
}
label={ __( 'Link' ) }
Expand Down
17 changes: 10 additions & 7 deletions packages/editor/src/components/post-url/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useMemo, useState } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import { Dropdown, Button } from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import { safeDecodeURIComponent } from '@wordpress/url';
import { safeDecodeURI } from '@wordpress/url';
import { store as coreStore } from '@wordpress/core-data';

/**
Expand Down Expand Up @@ -59,29 +59,32 @@ export default function PostURLPanel() {
}

function PostURLToggle( { isOpen, onClick } ) {
const { slug, isFrontPage, postLink } = useSelect( ( select ) => {
const { getCurrentPostId, getCurrentPost } = select( editorStore );
const { isFrontPage, postLink, permalink } = useSelect( ( select ) => {
const { getCurrentPostId, getCurrentPost, getPermalink } =
select( editorStore );
const { getEditedEntityRecord } = select( coreStore );
const siteSettings = getEditedEntityRecord( 'root', 'site' );
const _id = getCurrentPostId();

return {
slug: select( editorStore ).getEditedPostSlug(),
isFrontPage: siteSettings?.page_on_front === _id,
postLink: getCurrentPost()?.link,
permalink: getPermalink(),
};
}, [] );
const decodedSlug = safeDecodeURIComponent( slug );

const decodedLink = safeDecodeURI( permalink );
return (
<Button
size="compact"
className="editor-post-url__panel-toggle"
variant="tertiary"
aria-expanded={ isOpen }
// translators: %s: Current post link.
aria-label={ sprintf( __( 'Change link: %s' ), decodedSlug ) }
aria-label={ sprintf( __( 'Change link: %s' ), decodedLink ) }
onClick={ onClick }
>
{ isFrontPage ? postLink : <>/{ decodedSlug }</> }
{ isFrontPage ? postLink : <>{ decodedLink }</> }
</Button>
);
}
11 changes: 5 additions & 6 deletions packages/editor/src/components/post-url/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
width: 100%;
}

.editor-post-url__panel-toggle {
display: block;
overflow-wrap: break-word;
}

.editor-post-url__panel-dialog .editor-post-url {
// sidebar width - popover padding - form margin
min-width: $sidebar-width - $grid-unit-20 - $grid-unit-20;
Expand All @@ -20,9 +25,3 @@
.editor-post-url__link-slug {
font-weight: 600;
}

// TODO: This might indicate a need to update the InputControl itself, as
// there is no way currently to control the padding when adding prefix/suffix.
.editor-post-url__input input.components-input-control__input {
padding-inline-start: 0 !important;
}
Loading