Skip to content

Commit

Permalink
Add inline copy button (#93)
Browse files Browse the repository at this point in the history
* Add copy button

* Use Docusaurus copy button and icons

* Tweak styles to work in new context

* Other places where inline copy would be helpful

* Mess with CSS to make it look similar on different browsers
  • Loading branch information
timothymcmackin authored Jul 10, 2024
1 parent 70ecbe8 commit 9656a34
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
title: 'Networks & Public RPC Endpoints'
---

## Etherlink mainnet
import InlineCopy from '@site/src/components/InlineCopy';

<table><thead><tr><th width="231">Parameter</th><th>Value</th></tr></thead><tbody><tr><td>Network Name</td><td><code>Etherlink Mainnet</code></td></tr><tr><td>RPC URL</td><td><code>https://node.mainnet.etherlink.com</code></td></tr><tr><td>Chain ID</td><td><code>42793</code></td></tr><tr><td>Currency Symbol</td><td><code>XTZ</code></td></tr><tr><td>Block Explorer URL</td><td><a href="https://explorer.etherlink.com">https://explorer.etherlink.com</a></td></tr></tbody></table>
## Etherlink mainnet

---
<table><thead><tr><th width="231">Parameter</th><th>Value</th></tr></thead><tbody><tr><td>Network Name</td><td><code>Etherlink Mainnet</code></td></tr><tr><td>RPC URL</td><td><InlineCopy code="https://node.mainnet.etherlink.com" /></td></tr><tr><td>Chain ID</td><td><code>42793</code></td></tr><tr><td>Currency Symbol</td><td><code>XTZ</code></td></tr><tr><td>Block Explorer URL</td><td><a href="https://explorer.etherlink.com">https://explorer.etherlink.com</a></td></tr></tbody></table>

## Etherlink testnet

<table><thead><tr><th width="231">Parameter</th><th>Value</th></tr></thead><tbody><tr><td>Network Name</td><td><code>Etherlink Testnet</code></td></tr><tr><td>RPC URL</td><td><code>https://node.ghostnet.etherlink.com</code></td></tr><tr><td>Chain ID</td><td><code>128123</code></td></tr><tr><td>Currency Symbol</td><td><code>XTZ</code></td></tr><tr><td>Block Explorer URL</td><td><a href="https://testnet-explorer.etherlink.com/">https://testnet-explorer.etherlink.com/</a></td></tr></tbody></table>
<table><thead><tr><th width="231">Parameter</th><th>Value</th></tr></thead><tbody><tr><td>Network Name</td><td><code>Etherlink Testnet</code></td></tr><tr><td>RPC URL</td><td><InlineCopy code="https://node.ghostnet.etherlink.com" /></td></tr><tr><td>Chain ID</td><td><code>128123</code></td></tr><tr><td>Currency Symbol</td><td><code>XTZ</code></td></tr><tr><td>Block Explorer URL</td><td><a href="https://testnet-explorer.etherlink.com/">https://testnet-explorer.etherlink.com/</a></td></tr></tbody></table>
6 changes: 4 additions & 2 deletions docs/get-started/using-your-wallet.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: 'Using your Wallet'
---

import InlineCopy from '@site/src/components/InlineCopy';

## Which wallets can I use?

You can connect any wallet that supports custom EVM networks:
Expand All @@ -20,7 +22,7 @@ Use these parameters in your wallet to connect to Etherlink:
| Parameter | Value |
| ------------------ | ---------------------------------------------------------------------------------------- |
| Network Name | `Etherlink Mainnet` |
| RPC URL | `https://node.mainnet.etherlink.com` |
| RPC URL | <InlineCopy code="https://node.mainnet.etherlink.com" /> |
| Chain ID | `42793` |
| Currency Symbol | `XTZ` |
| Block Explorer URL | [https://explorer.etherlink.com](https://explorer.etherlink.com) |
Expand All @@ -30,7 +32,7 @@ Use these parameters in your wallet to connect to Etherlink:
| Parameter | Value |
| ------------------ | ---------------------------------------------------------------------------------------- |
| Network Name | `Etherlink Testnet` |
| RPC URL | `https://node.ghostnet.etherlink.com` |
| RPC URL | <InlineCopy code="https://node.ghostnet.etherlink.com" /> |
| Chain ID | `128123` |
| Currency Symbol | `XTZ` |
| Block Explorer URL | [https://testnet-explorer.etherlink.com/](https://testnet-explorer.etherlink.com/) |
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@mui/icons-material": "5.14.18",
"@mui/material": "5.14.18",
"clsx": "1.2.1",
"copy-text-to-clipboard": "3.2.0",
"docusaurus-pushfeedback": "1.0.1",
"plugin-image-zoom": "github:flexanalytics/plugin-image-zoom",
"prism-react-renderer": "1.3.5",
Expand Down
46 changes: 46 additions & 0 deletions src/components/CopyButton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import React, {useCallback, useState, useRef, useEffect} from 'react';
import clsx from 'clsx';
import copy from 'copy-text-to-clipboard';
import IconCopy from '@theme/Icon/Copy';
import IconSuccess from '@theme/Icon/Success';

import styles from './styles.module.css';

export default function CopyButton({code, className}) {
const [isCopied, setIsCopied] = useState(false);
const copyTimeout = useRef<number | undefined>(undefined);
const handleCopyCode = useCallback(() => {
copy(code);
setIsCopied(true);
copyTimeout.current = window.setTimeout(() => {
setIsCopied(false);
}, 1000);
}, [code]);

useEffect(() => () => window.clearTimeout(copyTimeout.current), []);

return (
<button
type="button"
aria-label="Copied"
title="Copy"
className={clsx(
className,
styles.copyButton,
isCopied && styles.copyButtonCopied,
)}
onClick={handleCopyCode}>
<span className={styles.copyButtonIcons} aria-hidden="true">
<IconCopy className={styles.copyButtonIcon} />
<IconSuccess className={styles.copyButtonSuccessIcon} />
</span>
</button>
);
}
46 changes: 46 additions & 0 deletions src/components/CopyButton/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

:global(.theme-code-block:hover) .copyButtonCopied {
opacity: 1 !important;
}

.copyButtonIcons {
position: relative;
display: block;
width: 1.125rem;
height: 1.125rem;
}

.copyButtonIcon,
.copyButtonSuccessIcon {
fill: currentColor;
opacity: inherit;
width: inherit;
height: inherit;
transition: all var(--ifm-transition-fast) ease;
}

.copyButtonSuccessIcon {
top: -12px;
left: 10px;
transform: translate(-50%, -50%) scale(0.33);
opacity: 0;
color: #00d600;
position: relative;
}

.copyButtonCopied .copyButtonIcon {
transform: scale(0.33);
opacity: 0;
}

.copyButtonCopied .copyButtonSuccessIcon {
transform: translate(-50%, -50%) scale(1);
opacity: 1;
transition-delay: 0.075s;
}
15 changes: 15 additions & 0 deletions src/components/InlineCopy/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable react/prop-types,import/no-unresolved */
import React from 'react';
import clsx from 'clsx';
import styles from './styles.module.css';

import CopyButton from '@site/src/components/CopyButton'

export default function InlineCopy({ code }) {
return (
<div className={clsx(styles.container)}>
<code>{code}</code>
<CopyButton code={code} />
</div>
);
}
6 changes: 6 additions & 0 deletions src/components/InlineCopy/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.container {
display: flex;
column-gap: 0.2rem;
position: unset;
background-color: var(--ifm-code-background);
}

0 comments on commit 9656a34

Please sign in to comment.