From 6d1721d2116699209a86b21dd5022b37e7bc00df Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Fri, 10 Nov 2017 23:31:25 +1100 Subject: [PATCH] Open the slug edit form when clicking on the slug --- editor/post-permalink/index.js | 52 +++++++++++++++++++++++++++++--- editor/post-permalink/style.scss | 10 ++++++ 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/editor/post-permalink/index.js b/editor/post-permalink/index.js index 12a2e0535fbe2c..7ca0f6ec32c817 100644 --- a/editor/post-permalink/index.js +++ b/editor/post-permalink/index.js @@ -21,8 +21,12 @@ class PostPermalink extends Component { super( ...arguments ); this.state = { showCopyConfirmation: false, + editingSlug: false, }; this.onCopy = this.onCopy.bind( this ); + this.onEditPermalink = this.onEditPermalink.bind( this ); + this.onCancelEditPermalink = this.onCancelEditPermalink.bind( this ); + this.onSavePermalink = this.onSavePermalink.bind( this ); } componentWillUnmount() { @@ -42,8 +46,24 @@ class PostPermalink extends Component { }, 4000 ); } + onEditPermalink( event ) { + event.preventDefault(); + this.setState( { editingSlug: true } ); + } + + onCancelEditPermalink( event ) { + event.preventDefault(); + this.setState( { editingSlug: false } ); + } + + onSavePermalink( event ) { + event.preventDefault(); + this.setState( { editingSlug: false } ); + } + render() { const { isNew, link, samplePermalink } = this.props; + const { showCopyConfirmation, editingSlug } = this.state; if ( isNew || ! link ) { return null; } @@ -55,15 +75,39 @@ class PostPermalink extends Component { viewLink += '&preview=true'; } + const prefix = permalink.replace( /[^/]+\/?$/, '' ), + slug = permalink.replace( /.*\/([^/]+)\/?$/, '$1' ); + return (
{ __( 'Permalink:' ) } - + + + { prefix } + + { ! editingSlug && + + { slug } + + } + { editingSlug && +
+ +
+ } +
- { this.state.showCopyConfirmation ? __( 'Copied!' ) : __( 'Copy' ) } + { showCopyConfirmation ? __( 'Copied!' ) : __( 'Copy' ) }
); diff --git a/editor/post-permalink/style.scss b/editor/post-permalink/style.scss index 533363079232c0..b4f1b06bdd452c 100644 --- a/editor/post-permalink/style.scss +++ b/editor/post-permalink/style.scss @@ -35,3 +35,13 @@ @include long-content-fade( $size: 20% ); } } + +.editor-post-permalink__slug { + color: $dark-gray-300; + font-weight: bold; + cursor: pointer; +} + +.editor-post-permalink__slug-form { + display: inline; +}