-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: port "copy to clipboard" / "expand/collapse all" functionality
closes #410
- Loading branch information
1 parent
199f240
commit 5bb0bdf
Showing
10 changed files
with
164 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import * as React from 'react'; | ||
import * as ReactTooltip from 'react-tooltip'; | ||
|
||
import { ClipboardService } from '../services/ClipboardService'; | ||
|
||
export interface CopyButtonWrapperProps { | ||
data: any; | ||
children: ( | ||
props: { | ||
renderCopyButton: (() => React.ReactNode); | ||
}, | ||
) => React.ReactNode; | ||
} | ||
|
||
export class CopyButtonWrapper extends React.PureComponent<CopyButtonWrapperProps> { | ||
render() { | ||
return this.props.children({ renderCopyButton: this.renderCopyButton }); | ||
} | ||
|
||
copy = () => { | ||
const content = | ||
typeof this.props.data === 'string' | ||
? this.props.data | ||
: JSON.stringify(this.props.data, null, 2); | ||
ClipboardService.copyCustom(content); | ||
}; | ||
|
||
renderCopyButton = () => { | ||
return ( | ||
<> | ||
<span | ||
onClick={this.copy} | ||
data-tip={true} | ||
data-for="copy_tooltip" | ||
data-event="click" | ||
data-event-off="mouseleave" | ||
> | ||
Copy | ||
</span> | ||
<ReactTooltip | ||
isCapture={true} | ||
id="copy_tooltip" | ||
place="top" | ||
getContent={this.getTooltipContent} | ||
type="light" | ||
effect="solid" | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
getTooltipContent() { | ||
return ClipboardService.isSupported() ? 'Copied' : 'Not supported in your browser'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import styled from '../styled-components'; | ||
|
||
export const SampleControls = styled.div` | ||
opacity: 0.4; | ||
transition: opacity 0.3s ease; | ||
text-align: right; | ||
> span { | ||
display: inline-block; | ||
padding: 2px 10px; | ||
cursor: pointer; | ||
:hover { | ||
background: rgba(255, 255, 255, 0.1); | ||
} | ||
} | ||
`; | ||
|
||
export const SampleControlsWrap = styled.div` | ||
&:hover ${SampleControls} { | ||
opacity: 1; | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters