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 docs for ClipboardButton component #34711

Merged
merged 8 commits into from
Sep 15, 2021
Merged
Changes from 6 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
42 changes: 41 additions & 1 deletion packages/components/src/clipboard-button/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ClipboardButton

<div class="callout callout-alert">
This component is deprecated. Please use the `useCopyToClipboard` hook from the `@wordpress/compose` package instead.
</div>

With a clipboard button, users copy text (or other elements) with a single click or tap.

![Clipboard button component](https://wordpress.org/gutenberg/files/2019/07/clipboard-button-2-1.png)
Expand All @@ -8,7 +12,7 @@ With a clipboard button, users copy text (or other elements) with a single click

```jsx
import { ClipboardButton } from '@wordpress/components';
import { useState } from '@wordpress/compose';
import { useState } from '@wordpress/element';
ciampo marked this conversation as resolved.
Show resolved Hide resolved

const MyClipboardButton = () => {
const [ hasCopied, setHasCopied ] = useState( false );
Expand All @@ -24,3 +28,39 @@ const MyClipboardButton = () => {
);
};
```

## Props

The component accepts the following props:
ciampo marked this conversation as resolved.
Show resolved Hide resolved

### className

The class that will be added to the classes of the underlying `<Button>` component.

- Type: `string`
- Required: no

### text

The text that will be copied to the clipboard.

- Type: `string`
- Required: no
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a quick look at the code, it seems like text would be required — WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This totally makes sense to be marked as required. I checked this and it doesn't fire errors but I think the idea of it being required to use the component rather than required to not break it is a good distinction.


### onCopy

The function that will be called when the text is copied.

-- Type: `() => void`
-- Required: yes

### onFinishCopy

The function that will be called when the text is copied and the copy animation is finished.

-- Type: `() => void`
-- Required: no
ciampo marked this conversation as resolved.
Show resolved Hide resolved

### Inherited props

Any additional props will be passed the underlying `<Button/>` component. See the [Button](/packages/components/src/button/README.md#props) component for more details on the available props.