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

Add useClipboard hook #28

Open
kripod opened this issue Sep 22, 2019 · 14 comments
Open

Add useClipboard hook #28

kripod opened this issue Sep 22, 2019 · 14 comments
Assignees
Labels
enhancement New feature or request

Comments

@kripod
Copy link
Owner

kripod commented Sep 22, 2019

Motivation

When it comes to interacting with the clipboard, multiple options are available. The Clipboard API is not yet widely supported by browsers.

A compatible solution should be available out of the box:

Basic example

function Example() {
  const { copy, cut, paste } = useClipboard();
  const [value, setValue] = useState('foo');

  return (
    <>
      <input value={value} onChange={(e) => setValue(e.target.value)} />
      <button type="button" onClick={() => copy(value)}>Copy</button>
    </>
  );
}

Details

Lack of permissions (e.g. for pasting) should be handled gracefully with opt-in support for error callbacks.

@kripod kripod added the enhancement New feature or request label Sep 22, 2019
@kripod kripod changed the title Add 'useClipboard' hook Add useClipboard hook Sep 22, 2019
@maciekgrzybek
Copy link

Hey @kripod do you need someone to build that? I could give it a go :)

@kripod
Copy link
Owner Author

kripod commented Sep 23, 2019

@maciekgrzybek I would appreciate if you could take the challenge of implementation!

@maciekgrzybek
Copy link

@kripod I'll crack on then :)

@maciekgrzybek
Copy link

@kripod could please explain a little bit more about the 'Details' part?
'Lack of permissions (e.g. for pasting) should be handled gracefully with opt-in support for error callbacks.'
Not sure if I understand it. Thanks :)

@kripod
Copy link
Owner Author

kripod commented Sep 29, 2019

When using the Clipboard API, permissions should be requested from the user at first. If the user refuses to give them, call an optionally supplied errorCallback method with the reason as a parameter (e.g. Error object or explanation).

@maciekgrzybek
Copy link

Ok, that makes sense, so I'm guessing I should use this API right? https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/permissions

@maciekgrzybek
Copy link

Or is it native browser behaviour to ask the user for the permission?

@kripod
Copy link
Owner Author

kripod commented Sep 29, 2019

I'm not sure about it, as it isn't documented in depth.

@maciekgrzybek
Copy link

maciekgrzybek commented Sep 29, 2019

Ok thanks, @kripod, I'll investigate it.

@maciekgrzybek
Copy link

@kripod one more thing, what's the approach for developing hooks in this project? is there something like an example page to test it? or do I need to create something external?

@kripod
Copy link
Owner Author

kripod commented Oct 9, 2019

@maciekgrzybek Unfortunately, there is no example page to test hooks with, but Jest is being used for writing tests. I am considering migration to a monorepo to resolve #77 and prepare structural requirements for #26.

@maciekgrzybek
Copy link

Hey, I've added PR for this - #85

@kripod
Copy link
Owner Author

kripod commented Oct 13, 2019

@maciekgrzybek Thank you for your valuable contribution! In the meantime, the project has been migrated to a monorepo with a package called web-api-hooks. I would be grateful if you could update your pull request, moving useClipboard under the aforementioned package.

Unfortunately, I will be busy in the next days due to tasks at university, so I may not be able to review your code immediately. I appreciate your efforts, keep up the nice work!

@maciekgrzybek
Copy link

Hey @kripod I've added it to a new repo :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants