-
Notifications
You must be signed in to change notification settings - Fork 841
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
copy button that copies text to clipboard #1112
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
content={this.state.tooltipText} | ||
onMouseOut={this.resetTooltipText} | ||
> | ||
<EuiButton |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we may want to pull this out into a more generic service so that they can pass any type of child node (any button or link) that gets wrapped in this functionality. As it stands, you can't use EuiButtonEmpty
or EuiButtonIcon
.
I would also like to look into creating a "disappearing" tooltip to use here. Where there is no tooltip on hover, but then when you click the trigger element, the tooltip only stays up for a short period of time. I'll look into this in another branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use a toast instead, which will auto dismiss itself and is good for this action (as well as for accessibility because it'll announce itself). The button will likely have the action in it so the tooltip on hover is likely unnecessary. Agree it should be more generic and accept any child element, not just a regular button.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My concern with a toast, is that it's not very tied to the button itself and can be easily overlooked. For small actions like this, maybe we should consider a new type of tooltip that reads out like a toast, but whose proximity is much closer to the triggering element?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some issues with the tooltip rendering
is a known bug, #996 ; coincidentally this exact use case
@cchaos @chandlerprall I have moved the component under utilities and now anything can be used as the child. |
Jenkins, test this please. |
|
||
<EuiSpacer size="m" /> | ||
|
||
<EuiCopy textToCopy={this.state.copyText}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about making this a render prop instead of adding a span with its own onClick?
<EuiCopy textToCopy={this.state.copyText}>
{(copyFn) => (
<EuiButton onClick={copyFn}>Click to copy input text</EuiButton>
)}
</EuiCopy>
That keeps the utility component from affecting DOM and makes it more re-useable in other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++
Should |
I think leaving it as a string makes sense; the parent is still in control, and the copy operation uses the current value on |
src/components/copy/copy.js
Outdated
import { EuiToolTip } from '../tool_tip'; | ||
|
||
const UNCOPIED_MSG = 'Copy'; | ||
const COPIED_MSG = 'Copied'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make these messages customizable via props?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple nit things, but thank you so much for adding this in. I'm excited to be able to start using it in our docs!
}], | ||
text: ( | ||
<p> | ||
The <EuiCode>EuiCopy</EuiCode> component is a simplified utility for copying text to clipboard. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give more description on how it's used?
src/components/copy/copy.js
Outdated
} | ||
|
||
EuiCopy.propTypes = { | ||
textToCopy: PropTypes.string.isRequired, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add comments to each prop type to populate the props list table in the docs?
Also, you may want to consider add TS def's ;)
src/components/copy/copy.js
Outdated
}; | ||
|
||
EuiCopy.defaultProps = { | ||
beforeCopyMsg: 'Copy', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's most likely that by default we won't need a before message (That'll also give us a quick fix for the tooltip positioning issue that probably won't be fixed relatively soon). Can you remove the before message default and in the component make the tooltip dependent on having either of these messages?
Also, since we've been being pretty verbose with our props, I think we can change these to "beforeMessage" and "afterMessage" ("Copy" is redundant of the component name and "Msg" can be remembered easily).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah you would need to conditionally wrap the child in a tooltip when one or both messages exist.
src/components/copy/copy.js
Outdated
} = this.props; | ||
|
||
return ( | ||
<EuiToolTip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May want consider passing down {...rest}
to the tooltip so consumers can customize it even more and pass down something like 'data-test-subj'
.
src/components/tool_tip/tool_tip.js
Outdated
@@ -146,7 +146,7 @@ export class EuiToolTip extends Component { | |||
); | |||
|
|||
let tooltip; | |||
if (visible) { | |||
if (visible && content) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, one last thing, but because tooltips accept title's as well can you change this to be if (visible && (content || title))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM
Kibana uses this in the home page tutorials and needs the component in am more generic location so it can be used in other places. Figured the best place for it is in EUI.