-
Notifications
You must be signed in to change notification settings - Fork 888
Convert EuiCopy component to TypeScript #2016
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
Changes from 3 commits
6f15e61
da63aae
7497baf
6538ad7
d7fdc74
a77aaac
c4ab049
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 { | ||
|
cchaos marked this conversation as resolved.
Outdated
|
||
| /** | ||
| * Text that will be copied to clipboard when copy function is executed. | ||
| */ | ||
| textToCopy: string; | ||
| /** | ||
|
cee-chen marked this conversation as resolved.
|
||
| * Tooltip message displayed before copy function is called. | ||
| */ | ||
| beforeMessage: ReactNode; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this prop is optional, please update the interface to match:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @chandlerprall. Just to be sure, is there an associated
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| /** | ||
| * 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; | ||
|
cee-chen marked this conversation as resolved.
|
||
| } | ||
|
|
||
| interface State { | ||
|
cchaos marked this conversation as resolved.
Outdated
|
||
| tooltipText: ReactNode; | ||
| } | ||
|
|
||
| export class EuiCopy extends React.Component<Props, State> { | ||
| constructor(props: Props) { | ||
| super(props); | ||
|
|
||
| this.state = { | ||
|
|
@@ -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', | ||
|
cchaos marked this conversation as resolved.
Outdated
|
||
| }); | ||
| } | ||
| }; | ||
|
|
@@ -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; | ||
|
cchaos marked this conversation as resolved.
Outdated
|
||
|
|
||
| return ( | ||
| // See `src/components/tool_tip/tool_tip.js` for explaination of below eslint-disable | ||
|
|
@@ -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', | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.