-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
update Clipboard #3568
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
base: dev
Are you sure you want to change the base?
update Clipboard #3568
Changes from all commits
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -128,20 +128,32 @@ export default class Clipboard extends React.Component { | |||||
| } | ||||||
|
|
||||||
| render() { | ||||||
| const {id, title, className, style} = this.props; | ||||||
| const copyIcon = <FontAwesomeIcon icon={faCopy} />; | ||||||
| const copiedIcon = <FontAwesomeIcon icon={faCheckCircle} />; | ||||||
| const btnIcon = this.state.copied ? copiedIcon : copyIcon; | ||||||
| const { | ||||||
| id, | ||||||
| title, | ||||||
| className, | ||||||
| style, | ||||||
| copied_className, | ||||||
| copied_style, | ||||||
| children, | ||||||
| copied_children, | ||||||
| } = this.props; | ||||||
|
|
||||||
| const isCopied = this.state.copied; | ||||||
|
|
||||||
| const content = isCopied | ||||||
| ? copied_children ?? <FontAwesomeIcon icon={faCheckCircle} /> | ||||||
| : children ?? <FontAwesomeIcon icon={faCopy} />; | ||||||
|
|
||||||
| return clipboardAPI ? ( | ||||||
| <LoadingElement | ||||||
| id={id} | ||||||
| title={title} | ||||||
| style={style} | ||||||
| className={className} | ||||||
| style={isCopied ? copied_style ?? style : style} | ||||||
| className={isCopied ? copied_className ?? className : className} | ||||||
| onClick={this.onClickHandler} | ||||||
| > | ||||||
| <i> {btnIcon}</i> | ||||||
| {content} | ||||||
| </LoadingElement> | ||||||
| ) : null; | ||||||
| } | ||||||
|
|
@@ -160,6 +172,16 @@ Clipboard.propTypes = { | |||||
| */ | ||||||
| id: PropTypes.string, | ||||||
|
|
||||||
| /** | ||||||
| * The children of this component. By default copy icon | ||||||
| */ | ||||||
| children: PropTypes.node, | ||||||
|
|
||||||
| /** | ||||||
| * The children of this component displayed while copying. By default checked icon | ||||||
|
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.
Suggested change
|
||||||
| */ | ||||||
| copied_children: PropTypes.node, | ||||||
|
|
||||||
| /** | ||||||
| * The id of target component containing text to copy to the clipboard. | ||||||
| * The inner text of the `children` prop will be copied to the clipboard. If none, then the text from the | ||||||
|
|
@@ -196,6 +218,15 @@ Clipboard.propTypes = { | |||||
| * The class name of the icon element | ||||||
| */ | ||||||
| className: PropTypes.string, | ||||||
| /** | ||||||
| * The icon's styles while copying | ||||||
| */ | ||||||
| copied_style: PropTypes.object, | ||||||
|
|
||||||
| /** | ||||||
| * The class name of the icon element while copying | ||||||
| */ | ||||||
| copied_className: PropTypes.string, | ||||||
|
Comment on lines
+221
to
+229
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. Hmm, this seems like we're adding 2 or 3 ways of solving this problem at once. If we are allowing custom
Collaborator
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. I may have misunderstood you first comment above. Can you clarify? Did you mean that the children and copied_children could be buttons or anchors? Or were you referring to only the root element of the Clipboard? But if children and copied_children is a div with styling, I agree that you would then not need the coied_style and copied_className
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. I was thinking the base element of the clipboard could remain a As you note, if we eventually make the base element a button, then there are certain child components that become invalid (and this would not be obvious to Python users). |
||||||
|
|
||||||
| /** | ||||||
| * Dash-assigned callback that gets fired when the value changes. | ||||||
|
|
||||||
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'm a big fan of replacing the hard-coded
<i>and giving users control of the child elements!More than just the icon, I think that the default element should include the wrapper button/div itself. For example, a user might prefer to use an anchor instead.
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.
That seems like a good idea, however, the Clipboard is essentially a Button, (and the base element should be updated to be a Button rather than a Div). It’s invalid HTML to have a Button or other interactive element as children of a Button. The purpose of updating the children is to simply provide feedback on the copy state.