-
Notifications
You must be signed in to change notification settings - Fork 6
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 URL button #327
base: master
Are you sure you want to change the base?
Copy URL button #327
Changes from 1 commit
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from "react"; | ||
import { CopyToClipboard } from "react-copy-to-clipboard"; | ||
import { PrimaryButton, TerraTooltip } from "libs/common"; | ||
import "@clr/icons/clr-icons.css"; | ||
|
||
const style = { | ||
copyUrlButton: { | ||
marginRight: "16px" | ||
} | ||
}; | ||
|
||
export default class CopyUrlButton extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
buttonText: "Copy URL to clipboard" | ||
}; | ||
this.handleButtonClick = this.handleButtonClick.bind(this); | ||
} | ||
|
||
handleButtonClick() { | ||
// Just change the button text for a second | ||
this.setState({ buttonText: "Copied!" }); | ||
setTimeout( | ||
() => this.setState({ buttonText: "Copy URL to clipboard" }), | ||
1000 | ||
); | ||
} | ||
|
||
render() { | ||
const { className } = this.props; | ||
|
||
return ( | ||
<div onClick={this.handleButtonClick} style={style.copyUrlButton}> | ||
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. It's recommended to use className rather than style. In this repo we use the material-ui styling solution.
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. Good to know, thanks! In this case, since we wanted to move the copyUrl button to the left we don't even need the extra styling. So I just removed this altogether. |
||
<TerraTooltip title={this.state.buttonText}> | ||
<CopyToClipboard text={window.location.href}> | ||
<clr-icon shape="copy-to-clipboard" size="20" /> | ||
</CopyToClipboard> | ||
</TerraTooltip> | ||
</div> | ||
); | ||
} | ||
} |
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.
React will automatically append a "px" suffix so by convention we do this, to be slightly cleaner: