-
Notifications
You must be signed in to change notification settings - Fork 998
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
Fixes #38242 replace clipboard copy with pf5 #10457
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,36 @@ | ||
import React, { useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Button, Icon } from 'patternfly-react'; | ||
import { Tooltip, TooltipPosition } from '@patternfly/react-core'; | ||
import { | ||
ClipboardCopy as PFClipboardCopy, | ||
ClipboardCopyVariant as PFClipboardCopyVariant, | ||
} from '@patternfly/react-core'; | ||
import { translate as __ } from '../../../common/I18n'; | ||
import './clipboard-copy.scss'; | ||
|
||
const ClipboardCopy = ({ | ||
text: defaultText, | ||
successMessage, | ||
buttonText, | ||
textareaProps, | ||
buttonProps, | ||
hideTextarea, | ||
withCopyIcon, | ||
}) => { | ||
const [text, setText] = useState(defaultText); | ||
|
||
const clipboardClass = hideTextarea === false ? 'clipboard-copy' : ''; | ||
const iconMarginLeft = buttonText === '' ? '0px' : '5px'; | ||
const ClipboardCopy = ({ text: defaultText, textareaProps }) => { | ||
const [text] = useState(defaultText); | ||
|
||
return ( | ||
<div className={clipboardClass}> | ||
{hideTextarea === false ? ( | ||
<textarea | ||
defaultValue={text} | ||
onChange={({ target: { value } }) => setText(value)} | ||
{...textareaProps} | ||
/> | ||
) : null} | ||
<Tooltip | ||
content={successMessage} | ||
position={TooltipPosition.right} | ||
trigger="click" | ||
> | ||
<Button | ||
onClick={() => navigator.clipboard.writeText(text)} | ||
bsStyle="default" | ||
{...buttonProps} | ||
> | ||
{buttonText} | ||
{withCopyIcon && ( | ||
<Icon | ||
style={{ marginLeft: iconMarginLeft }} | ||
type="fa" | ||
name="copy" | ||
/> | ||
)} | ||
</Button> | ||
</Tooltip> | ||
</div> | ||
<PFClipboardCopy | ||
hoverTip={__('Copy to clipboard')} | ||
clickTip={__('Copied to clipboard')} | ||
isBlock | ||
variant={PFClipboardCopyVariant.expansion} | ||
isExpanded | ||
isReadOnly={textareaProps.readOnly ?? false} | ||
className={textareaProps.className ?? ''} | ||
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. Please use null instead of '' |
||
> | ||
{`${text}`} | ||
</PFClipboardCopy> | ||
); | ||
}; | ||
|
||
ClipboardCopy.propTypes = { | ||
text: PropTypes.string.isRequired, | ||
buttonText: PropTypes.string, | ||
successMessage: PropTypes.string, | ||
textareaProps: PropTypes.object, | ||
buttonProps: PropTypes.object, | ||
hideTextarea: PropTypes.bool, | ||
withCopyIcon: PropTypes.bool, | ||
}; | ||
|
||
ClipboardCopy.defaultProps = { | ||
buttonText: __('Copy to clipboard'), | ||
successMessage: __('Copied!'), | ||
textareaProps: {}, | ||
buttonProps: {}, | ||
hideTextarea: false, | ||
withCopyIcon: false, | ||
}; | ||
|
||
export default ClipboardCopy; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,11 @@ | |
} | ||
} | ||
} | ||
|
||
.pf-c-clipboard-copy.pf-m-inline{ | ||
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. Please add a classname to the PF component and use it for the css to prevent this css effecting other clipboardCopies 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. Or, remove the css and change the variant from inline to a normal type, that also looks fine to me. otherwise, we use pf variables for numbers and colors: https://v5-archive.patternfly.org/developer-resources/global-css-variables |
||
display: block; | ||
font-size: 1.3em; | ||
background-color: white; | ||
max-width: fit-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.
Should pass readonly:true