Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Attach `noreferrer` also to links without `target="_blank"` ([#2008](https://github.com/elastic/eui/pull/2008))
- Convert observer utility components to TypeScript ([#2009](https://github.com/elastic/eui/pull/2009))
- Convert tool tip components to TypeScript ([#2013](https://github.com/elastic/eui/pull/2013))
- Convert `EuiCopy` to TypeScript ([#2016](https://github.com/elastic/eui/pull/2016))
Comment thread
cchaos marked this conversation as resolved.
Outdated

**Bug fixes**

Expand Down
70 changes: 30 additions & 40 deletions src/components/copy/copy.js → src/components/copy/copy.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
import React from 'react';
import PropTypes from 'prop-types';
import React, { ReactElement, ReactNode } from 'react';
import { copyToClipboard } from '../../services';
import { EuiToolTip } from '../tool_tip';

export class EuiCopy extends React.Component {
constructor(props) {
interface Props {
Comment thread
cchaos marked this conversation as resolved.
Outdated
/**
* Text that will be copied to clipboard when copy function is executed.
*/
textToCopy: string;
/**
Comment thread
cee-chen marked this conversation as resolved.
* Tooltip message displayed before copy function is called.
*/
beforeMessage: ReactNode;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this prop is optional, please update the interface to match: beforeMessage?: ReactNode;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @chandlerprall. Just to be sure, is there an associated defaultProps value for this as well?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No, there is not (thanks for double checking!) - it's allowed to be null and in that case nothing is rendered.

/**
* Tooltip message displayed after copy function is called that lets the user know that
* 'textToCopy' has been copied to the clipboard.
*/
afterMessage?: string;
/**
* Function that must return a component. First argument is 'copy' function.
* Use your own logic to create the component that users interact with when triggering copy.
*/
children(copy: () => void): ReactElement;
Comment thread
cee-chen marked this conversation as resolved.
}

interface State {
Comment thread
cchaos marked this conversation as resolved.
Outdated
tooltipText: ReactNode;
}

export class EuiCopy extends React.Component<Props, State> {
constructor(props: Props) {
super(props);

this.state = {
Expand All @@ -16,7 +40,7 @@ export class EuiCopy extends React.Component {
const isCopied = copyToClipboard(this.props.textToCopy);
if (isCopied) {
this.setState({
tooltipText: this.props.afterMessage,
tooltipText: this.props.afterMessage || 'Copied',
Comment thread
cchaos marked this conversation as resolved.
Outdated
});
}
};
Expand All @@ -28,13 +52,7 @@ export class EuiCopy extends React.Component {
};

render() {
const {
children,
textToCopy,
beforeMessage,
afterMessage,
...rest
} = this.props;
const { children, textToCopy, beforeMessage, ...rest } = this.props;
Comment thread
cchaos marked this conversation as resolved.
Outdated

return (
// See `src/components/tool_tip/tool_tip.js` for explaination of below eslint-disable
Expand All @@ -48,31 +66,3 @@ export class EuiCopy extends React.Component {
);
}
}

EuiCopy.propTypes = {
/**
* Text that will be copied to clipboard when copy function is executed.
*/
textToCopy: PropTypes.string.isRequired,

/**
* Tooltip message displayed before copy function is called.
*/
beforeMessage: PropTypes.node,

/**
* Tooltip message displayed after copy function is called that lets the user know that
* 'textToCopy' has been copied to the clipboard.
*/
afterMessage: PropTypes.string.isRequired,

/**
* Function that must return a component. First argument is 'copy' function.
* Use your own logic to create the component that users interact with when triggering copy.
*/
children: PropTypes.func.isRequired,
};

EuiCopy.defaultProps = {
afterMessage: 'Copied',
};
File renamed without changes.