| 1 |
import { Component } from 'react'; |
| 2 |
import styles from '@patternfly/react-styles/css/components/ClipboardCopy/clipboard-copy'; |
| 3 |
import { css } from '@patternfly/react-styles'; |
| 4 |
import { ClipboardCopyProps } from './ClipboardCopy'; |
| 5 |
import { PickOptional } from '../../helpers/typeUtils'; |
| 6 |
|
| 7 |
export interface ClipboardCopyExpandedProps extends Omit<ClipboardCopyProps, 'onChange'> { |
| 8 |
className?: string; |
| 9 |
onChange?: (e: React.FormEvent<HTMLDivElement>, text: string) => void; |
| 10 |
isReadOnly?: boolean; |
| 11 |
isCode?: boolean; |
| 12 |
} |
| 13 |
|
| 14 |
class ClipboardCopyExpanded extends Component<ClipboardCopyExpandedProps> { |
| 15 |
static displayName = 'ClipboardCopyExpanded'; |
| 16 |
constructor(props: any) { |
| 17 |
super(props); |
| 18 |
} |
| 19 |
|
| 20 |
static defaultProps: PickOptional<ClipboardCopyExpandedProps> = { |
| 21 |
onChange: (): any => undefined, |
| 22 |
className: '', |
| 23 |
isReadOnly: false, |
| 24 |
isCode: false |
| 25 |
}; |
| 26 |
|
| 27 |
render() { |
| 28 |
const { className, children, onChange, isReadOnly, isCode, ...props } = this.props; |
| 29 |
|
| 30 |
return ( |
| 31 |
<div |
| 32 |
suppressContentEditableWarning |
| 33 |
className={css(styles.clipboardCopyExpandableContent, className)} |
| 34 |
onInput={(e: any) => onChange(e, e.target.innerText)} |
| 35 |
contentEditable={!isReadOnly} |
| 36 |
{...props} |
| 37 |
> |
| 38 |
{isCode ? <pre dir="ltr">{children}</pre> : children} |
| 39 |
</div> |
| 40 |
); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
export { ClipboardCopyExpanded }; |