Conversation
ellatrix
commented
May 8, 2020
| } } | ||
| onFinishCopy={ () => setState( { hasCopied: false } ) } | ||
| > | ||
| <MenuItem ref={ ref }> |
Member
Author
There was a problem hiding this comment.
This is now a proper menu item component.
|
Size Change: +3 B (0%) Total Size: 1.11 MB
ℹ️ View Unchanged
|
gziolo
reviewed
May 8, 2020
| import { useRef, useEffect } from '@wordpress/element'; | ||
|
|
||
| function CopyContentMenuItem( { createNotice, editedPostContent } ) { | ||
| const ref = useRef(); |
Member
There was a problem hiding this comment.
copyRef will make it easier to read. Otherwise it’s a beautiful piece of magic 😃
It took me some time to connect the dots because of the missing click handler.
Member
Author
There was a problem hiding this comment.
Yeah it's hard to see that the clipboard package is handling the click behaviour. Imo the name is a bit misleading. It pretty much only handles copying something to the clipboard on click.
Contributor
|
I love this! |
1e1710e to
96cd36e
Compare
7812f5c to
2433eeb
Compare
7 tasks
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This is meant to replace
ClipboardButton, which now also uses this hook.Why?
Because it's currently only possible to render a button. With a hook, the behaviour could be added to any component. This is handy if you want to use it for a menu item for example.
It also enables us to absorb some common logic by all of the
ClipboardButtonimplementations. They all have to implement ahasCopiedstate, because the component cannot pass it to the parent. With a hook, you can easily pass state.I converted the "copy all content" menu item as a demonstration.
How has this been tested?
Screenshots
Types of changes
Checklist: