rename copied to didCopy in Code state
This commit is contained in:
parent
62706d83c4
commit
cd333e0977
@ -24,7 +24,7 @@ interface CodeProps {
|
|||||||
|
|
||||||
interface CodeState {
|
interface CodeState {
|
||||||
hlCode?: string;
|
hlCode?: string;
|
||||||
copied?: boolean;
|
didCopy?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Button = styled(BaseButton)`
|
const Button = styled(BaseButton)`
|
||||||
@ -170,7 +170,7 @@ class Code extends React.Component<CodeProps, CodeState> {
|
|||||||
) : null}
|
) : null}
|
||||||
</Base>
|
</Base>
|
||||||
{navigator.userAgent !== 'ReactSnap' && canCopy ? (
|
{navigator.userAgent !== 'ReactSnap' && canCopy ? (
|
||||||
<Button onClick={this._handleCopyAsync}>{this.state.copied ? 'Copied' : 'Copy'}</Button>
|
<Button onClick={this._handleCopyAsync}>{this.state.didCopy ? 'Copied' : 'Copy'}</Button>
|
||||||
) : null}
|
) : null}
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
@ -194,17 +194,17 @@ class Code extends React.Component<CodeProps, CodeState> {
|
|||||||
try {
|
try {
|
||||||
if ('clipboard' in navigator) {
|
if ('clipboard' in navigator) {
|
||||||
await (navigator as any).clipboard.writeText(this.props.children);
|
await (navigator as any).clipboard.writeText(this.props.children);
|
||||||
this.setState({ copied: true });
|
this.setState({ didCopy: true });
|
||||||
} else {
|
} else {
|
||||||
const lastActive = document.activeElement as HTMLElement;
|
const lastActive = document.activeElement as HTMLElement;
|
||||||
this._code.current.focus();
|
this._code.current.focus();
|
||||||
this._code.current.select();
|
this._code.current.select();
|
||||||
document.execCommand('copy');
|
document.execCommand('copy');
|
||||||
lastActive.focus();
|
lastActive.focus();
|
||||||
this.setState({ copied: true });
|
this.setState({ didCopy: true });
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.setState({ copied: false });
|
this.setState({ didCopy: false });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user