microsoft / fluent-ui-react

An ecosystem for building highly customizable enterprise class user interfaces.
https://aka.ms/fluent-ui
MIT License
432 stars 54 forks source link

Copy Button #1423

Open levithomason opened 5 years ago

levithomason commented 5 years ago

Feature Request

Problem description

It is common in UI to have a button that copies content to the clipboard. Currently, users need to repeatedly implement this behavior.

Proposed solution

Pseudo Code Ideas

A copy prop could be applied to component where it makes sense.

<Button content='Click to copy' copy />

The prop could allow configuring the message shown on success/failure as well as the timeout:

<Button
  content='Click to copy'
  copy={{
    success: 'Coped!',
    failure: "Couldn't Copy",
    timeout: 1000,
  }}
/>

Could be achieved as a utility component:

<CopyToClipboard as={Button} />

// or

<CopyToClipboard>
  {() => ...}
</CopyToClipboard>

Uses cases to consider:

jurokapsiar commented 5 years ago

Also, we can consider having a variant of input with the copy button.

Making the success/failure texts a required prop (instead of providing defaults) would force the developers to think about i18n.