mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-24 02:03:01 +02:00
prettify, sorry for the big ass commit
This commit is contained in:
@@ -1,82 +1,83 @@
|
||||
import * as React from "react";
|
||||
|
||||
export enum ClickableTag{
|
||||
Tag_span,
|
||||
Tag_h1
|
||||
export enum ClickableTag {
|
||||
Tag_span,
|
||||
Tag_h1,
|
||||
}
|
||||
|
||||
type IProps = {
|
||||
value: string;
|
||||
tag: ClickableTag;
|
||||
}
|
||||
value: string;
|
||||
tag: ClickableTag;
|
||||
};
|
||||
|
||||
type IState = {
|
||||
tooltipVisible: boolean;
|
||||
}
|
||||
tooltipVisible: boolean;
|
||||
};
|
||||
|
||||
export class CopyableText extends React.Component<IProps, IState> {
|
||||
public static defaultProps = {
|
||||
//Default span to prevent destroying current clickables
|
||||
tag: ClickableTag.Tag_span,
|
||||
public static defaultProps = {
|
||||
//Default span to prevent destroying current clickables
|
||||
tag: ClickableTag.Tag_span,
|
||||
};
|
||||
|
||||
constructor(props: IProps) {
|
||||
super(props);
|
||||
|
||||
this.copy = this.copy.bind(this);
|
||||
this.tooltipClasses = this.tooltipClasses.bind(this);
|
||||
this.textClasses = this.textClasses.bind(this);
|
||||
|
||||
this.state = {
|
||||
tooltipVisible: false,
|
||||
};
|
||||
|
||||
constructor(props: IProps) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
this.copy = this.copy.bind(this);
|
||||
this.tooltipClasses = this.tooltipClasses.bind(this);
|
||||
this.textClasses = this.textClasses.bind(this);
|
||||
copy(): void {
|
||||
const copyText = document.createElement("textarea");
|
||||
copyText.value = this.props.value;
|
||||
document.body.appendChild(copyText);
|
||||
copyText.select();
|
||||
copyText.setSelectionRange(0, 1e10);
|
||||
document.execCommand("copy");
|
||||
document.body.removeChild(copyText);
|
||||
this.setState({ tooltipVisible: true });
|
||||
setTimeout(() => this.setState({ tooltipVisible: false }), 1000);
|
||||
}
|
||||
|
||||
this.state = {
|
||||
tooltipVisible: false,
|
||||
}
|
||||
tooltipClasses(): string {
|
||||
let classes = "copy_tooltip_text";
|
||||
if (this.state.tooltipVisible) {
|
||||
classes += " copy_tooltip_text_visible";
|
||||
}
|
||||
|
||||
copy(): void {
|
||||
const copyText = document.createElement("textarea");
|
||||
copyText.value = this.props.value;
|
||||
document.body.appendChild(copyText);
|
||||
copyText.select();
|
||||
copyText.setSelectionRange(0, 1e10);
|
||||
document.execCommand("copy");
|
||||
document.body.removeChild(copyText);
|
||||
this.setState({tooltipVisible: true});
|
||||
setTimeout(() => this.setState({tooltipVisible: false}), 1000);
|
||||
return classes;
|
||||
}
|
||||
|
||||
textClasses(): string {
|
||||
let classes = "copy_tooltip noselect text";
|
||||
if (this.state.tooltipVisible) {
|
||||
classes += " copy_tooltip_copied";
|
||||
}
|
||||
|
||||
tooltipClasses(): string {
|
||||
let classes = "copy_tooltip_text";
|
||||
if(this.state.tooltipVisible) {
|
||||
classes += " copy_tooltip_text_visible";
|
||||
}
|
||||
return classes;
|
||||
}
|
||||
|
||||
return classes;
|
||||
render(): React.ReactNode {
|
||||
switch (this.props.tag) {
|
||||
case ClickableTag.Tag_h1:
|
||||
return (
|
||||
<h1 className={this.textClasses()} onClick={this.copy}>
|
||||
{this.props.value}
|
||||
<span className={this.tooltipClasses()}>Copied!</span>
|
||||
</h1>
|
||||
);
|
||||
case ClickableTag.Tag_span:
|
||||
return (
|
||||
<span className={this.textClasses()} onClick={this.copy}>
|
||||
<b>{this.props.value}</b>
|
||||
<span className={this.tooltipClasses()}>Copied!</span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
textClasses(): string {
|
||||
let classes = "copy_tooltip noselect text";
|
||||
if(this.state.tooltipVisible) {
|
||||
classes += " copy_tooltip_copied";
|
||||
}
|
||||
|
||||
return classes;
|
||||
}
|
||||
|
||||
|
||||
render(): React.ReactNode {
|
||||
switch (this.props.tag) {
|
||||
case ClickableTag.Tag_h1:
|
||||
return (
|
||||
<h1 className={this.textClasses()} onClick={this.copy}>
|
||||
{this.props.value}
|
||||
<span className={this.tooltipClasses()}>Copied!</span>
|
||||
</h1>)
|
||||
case ClickableTag.Tag_span:
|
||||
return (
|
||||
<span className={this.textClasses()} onClick={this.copy}>
|
||||
<b>{this.props.value}</b>
|
||||
<span className={this.tooltipClasses()}>Copied!</span>
|
||||
</span>)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user