Skip to content

Commit b56e869

Browse files
authored
feat: copy button (#58)
* feat: copy button * fix: styling * fix: tooltip * fix: removed header * fix: add parisnet examples
1 parent d66563d commit b56e869

File tree

9 files changed

+1062
-1197
lines changed

9 files changed

+1062
-1197
lines changed

package-lock.json

Lines changed: 944 additions & 1173 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,28 @@
2323
"embed-code": "npm run generate-monaco-types && npm run prettier && tsc --module es2015 --target es2015 --moduleResolution node --esModuleInterop true src/examples/*.ts && node scripts/copy-examples.js && npm run clear-folders && cp -r src/docs/* build-docs/ && rm -r docs && mv build-docs docs && npm run pretty-docs"
2424
},
2525
"dependencies": {
26-
"@airgap/beacon-sdk": "^4.2.1",
27-
"@docusaurus/core": "3.3.2",
28-
"@docusaurus/plugin-client-redirects": "^3.3.2",
29-
"@docusaurus/preset-classic": "3.3.2",
30-
"@docusaurus/theme-live-codeblock": "^3.3.2",
26+
"@airgap/beacon-sdk": "^4.2.2",
27+
"@docusaurus/core": "3.5.2",
28+
"@docusaurus/plugin-client-redirects": "^3.5.2",
29+
"@docusaurus/preset-classic": "3.5.2",
30+
"@docusaurus/theme-live-codeblock": "^3.5.2",
3131
"@mdx-js/react": "^3.0.1",
3232
"@monaco-editor/react": "^4.6.0",
33-
"@taquito/beacon-wallet": "^19.2.0",
34-
"@taquito/taquito": "^19.2.0",
33+
"@taquito/beacon-wallet": "^20.0.1",
34+
"@taquito/taquito": "^20.0.1",
3535
"clsx": "^2.1.1",
36-
"mermaid": "^10.9.0",
36+
"mermaid": "^11.0.0",
3737
"prism-react-renderer": "^2.3.1",
3838
"react": "^18.3.1",
3939
"react-dom": "^18.3.1"
4040
},
4141
"devDependencies": {
42-
"@docusaurus/module-type-aliases": "3.3.2",
42+
"@docusaurus/module-type-aliases": "3.5.2",
4343
"@tsconfig/docusaurus": "^2.0.3",
4444
"classnames": "^2.5.1",
4545
"docusaurus-node-polyfills": "^1.0.0",
4646
"monaco-editor-webpack-plugin": "^7.1.0",
47-
"typescript": "^5.4.5"
47+
"typescript": "^5.5.4"
4848
},
4949
"browserslist": {
5050
"production": [

src/docs/advanced/custom-block-explorer.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class TzStatsBlockExplorer extends BlockExplorer {
3131
public readonly rpcUrls: { [key in NetworkType]: string } = {
3232
[NetworkType.MAINNET]: "https://tzstats.com/",
3333
[NetworkType.GHOSTNET]: "https://ghost.tzstats.com/",
34-
[NetworkType.WEEKLYNET]: "https://ghost.tzstats.com/",
34+
[NetworkType.WEEKLYNET]: "https://monday.tzstats.com/",
3535
[NetworkType.DAILYNET]: "https://daily.tzstats.com/",
3636
[NetworkType.DELPHINET]: "https://delphi.tzstats.com/",
3737
[NetworkType.EDONET]: "https://edo.tzstats.com/",
@@ -46,6 +46,7 @@ class TzStatsBlockExplorer extends BlockExplorer {
4646
[NetworkType.NAIROBINET]: "https://nairobi.tzstats.com/",
4747
[NetworkType.OXFORDNET]: "https://oxford.tzstats.com/",
4848
[NetworkType.CUSTOM]: "https://custom.tzstats.com/",
49+
[NetworkType.PARISNET]: "https://paris.tzstats.com/",
4950
},
5051
) {
5152
super(rpcUrls);
@@ -89,7 +90,7 @@ class TzStatsBlockExplorer extends BlockExplorer {
8990
public readonly rpcUrls: { [key in NetworkType]: string } = {
9091
[NetworkType.MAINNET]: "https://tzstats.com/",
9192
[NetworkType.GHOSTNET]: "https://ghost.tzstats.com/",
92-
[NetworkType.WEEKLYNET]: "https://ghost.tzstats.com/"",
93+
[NetworkType.WEEKLYNET]: "https://monday.tzstats.com/",
9394
[NetworkType.DAILYNET]: "https://daily.tzstats.com/",
9495
[NetworkType.DELPHINET]: "https://delphi.tzstats.com/",
9596
[NetworkType.EDONET]: "https://edo.tzstats.com/",
@@ -104,6 +105,7 @@ class TzStatsBlockExplorer extends BlockExplorer {
104105
[NetworkType.NAIROBINET]: "https://nairobi.tzstats.com/",
105106
[NetworkType.OXFORDNET]: "https://oxford.tzstats.com/",
106107
[NetworkType.CUSTOM]: "https://custom.tzstats.com/",
108+
[NetworkType.PARISNET]: "https://paris.tzstats.com/",
107109
},
108110
) {
109111
super(rpcUrls);

src/docs/getting-started/subscribe-to-active-account.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Sometimes `requestPermissions` may not be enough, and you want to ensure the use
8080
dAppClient.subscribeToEvent(BeaconEvent.ACTIVE_ACCOUNT_SET, async (account) => {
8181
console.log(
8282
`${BeaconEvent.ACTIVE_ACCOUNT_SET} triggered: `,
83-
account?.address
83+
account?.address,
8484
);
8585

8686
if (!account) {
@@ -108,7 +108,7 @@ wallet.client.subscribeToEvent(
108108
async (account) => {
109109
console.log(
110110
`${BeaconEvent.ACTIVE_ACCOUNT_SET} triggered: `,
111-
account?.address
111+
account?.address,
112112
);
113113

114114
if (!account) {
@@ -124,7 +124,7 @@ wallet.client.subscribeToEvent(
124124
// The request was rejected
125125
// handle disconnection
126126
}
127-
}
127+
},
128128
);
129129
```
130130

@@ -229,7 +229,7 @@ Now, inside the handler, check whether the current tab has the leadership. If no
229229
dAppClient.subscribeToEvent(BeaconEvent.ACTIVE_ACCOUNT_SET, async (account) => {
230230
console.log(
231231
`${BeaconEvent.ACTIVE_ACCOUNT_SET} triggered: `,
232-
account?.address
232+
account?.address,
233233
);
234234

235235
if (!account || !elector.isLeader) {
@@ -257,7 +257,7 @@ wallet.client.subscribeToEvent(
257257
async (account) => {
258258
console.log(
259259
`${BeaconEvent.ACTIVE_ACCOUNT_SET} triggered: `,
260-
account?.address
260+
account?.address,
261261
);
262262

263263
if (!account || !elector.isLeader) {
@@ -273,7 +273,7 @@ wallet.client.subscribeToEvent(
273273
// The request was rejected
274274
// handle disconnection
275275
}
276-
}
276+
},
277277
);
278278
```
279279

@@ -333,7 +333,7 @@ const dAppClient = new DAppClient({
333333
dAppClient.subscribeToEvent(BeaconEvent.ACTIVE_ACCOUNT_SET, async (account) => {
334334
console.log(
335335
`${BeaconEvent.ACTIVE_ACCOUNT_SET} triggered: `,
336-
account?.address
336+
account?.address,
337337
);
338338

339339
if (!account || !elector.isLeader) {

src/examples/custom-block-explorer.beacon.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const customBlockExplorerBeacon = async (loggerFun: Function) => {
3131
[NetworkType.NAIROBINET]: "https://nairobi.tzstats.com/",
3232
[NetworkType.OXFORDNET]: "https://oxford.tzstats.com/",
3333
[NetworkType.CUSTOM]: "https://custom.tzstats.com/",
34+
[NetworkType.PARISNET]: "https://paris.tzstats.com/",
3435
},
3536
) {
3637
super(rpcUrls);

src/examples/custom-block-explorer.taquito.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const customBlockExplorerTaquito = async (loggerFun: Function) => {
3232
[NetworkType.NAIROBINET]: "https://nairobi.tzstats.com/",
3333
[NetworkType.OXFORDNET]: "https://oxford.tzstats.com/",
3434
[NetworkType.CUSTOM]: "https://custom.tzstats.com/",
35+
[NetworkType.PARISNET]: "https://paris.tzstats.com",
3536
},
3637
) {
3738
super(rpcUrls);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { useState } from "react";
2+
import { useColorMode } from "@docusaurus/theme-common";
3+
import "../styles.module.css";
4+
5+
const CopyButton = ({ text }) => {
6+
const [isCopied, setIsCopied] = useState(false);
7+
const { colorMode } = useColorMode();
8+
9+
return (
10+
<>
11+
<button
12+
type="button"
13+
title="Copy code to clipboard"
14+
style={{
15+
backgroundColor: "transparent",
16+
border: "none",
17+
cursor: "pointer",
18+
}}
19+
onClick={() => {
20+
navigator.clipboard.writeText(text).then(() => {
21+
setIsCopied(true);
22+
setTimeout(() => setIsCopied(false), 3000);
23+
});
24+
}}
25+
>
26+
<span style={{ display: "inline-block" }} aria-hidden="true">
27+
{!isCopied ? (
28+
<>
29+
<svg style={{ maxWidth: "24px", maxHeight: "24px" }}>
30+
<path
31+
fill={colorMode === "dark" ? "#000" : "#fff"}
32+
d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"
33+
></path>
34+
</svg>
35+
</>
36+
) : (
37+
<svg
38+
fill={colorMode === "dark" ? "#000" : "#fff"}
39+
width="24px"
40+
height="24px"
41+
style={{ maxWidth: "24px", maxHeight: "24px" }}
42+
>
43+
<path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" />
44+
</svg>
45+
)}
46+
</span>
47+
</button>
48+
</>
49+
);
50+
};
51+
export default CopyButton;

src/theme/Playground/index.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Translate from "@docusaurus/Translate";
66
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
77
import BrowserOnly from "@docusaurus/BrowserOnly";
88
import { usePrismTheme } from "@docusaurus/theme-common";
9+
import CopyButton from "./components/copy-button";
910

1011
import styles from "./styles.module.css";
1112
import BrowserWindow from "@site/src/components/BrowserWindow/BrowserWindow";
@@ -21,7 +22,18 @@ function getSnippetId(code) {
2122
}
2223

2324
function Header({ children }) {
24-
return <div className={clsx(styles.playgroundHeader)}>{children}</div>;
25+
return (
26+
<div
27+
className={clsx(styles.playgroundHeader)}
28+
style={{
29+
display: "flex",
30+
alignItems: "start",
31+
justifyContent: "space-between",
32+
}}
33+
>
34+
{children}
35+
</div>
36+
);
2537
}
2638
function LivePreviewLoader() {
2739
// Is it worth improving/translating?
@@ -66,16 +78,17 @@ function ThemedLiveEditor() {
6678
/>
6779
);
6880
}
69-
function EditorWithHeader() {
81+
function EditorWithHeader({ code }) {
7082
return (
7183
<>
7284
<Header>
7385
<Translate
7486
id="theme.Playground.liveEditor"
7587
description="The live editor label of the live codeblocks"
7688
>
77-
Live Editor
89+
Example
7890
</Translate>
91+
<CopyButton text={code} />
7992
</Header>
8093
<ThemedLiveEditor />
8194
</>
@@ -118,11 +131,11 @@ export default function Playground({ children, transformCode, ...props }) {
118131
{isEditorEnabled && (
119132
<ResultWithHeader snippetId={getSnippetId(children)} />
120133
)}
121-
<EditorWithHeader />
134+
<EditorWithHeader code={getCodeBody(children)} />
122135
</>
123136
) : (
124137
<>
125-
<EditorWithHeader />
138+
<EditorWithHeader code={getCodeBody(children)} />
126139
{isEditorEnabled && (
127140
<ResultWithHeader snippetId={getSnippetId(children)} />
128141
)}

src/theme/Playground/styles.module.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,29 @@
3131
padding: 1rem;
3232
background-color: var(--ifm-pre-background);
3333
}
34+
35+
.copyButtonIconWrapper {
36+
position: relative;
37+
width: 1.125rem;
38+
height: 1.125rem;
39+
}
40+
41+
.copyButtonIcon {
42+
position: absolute;
43+
top: 0;
44+
left: 0;
45+
fill: currentColor;
46+
opacity: inherit;
47+
width: inherit;
48+
height: inherit;
49+
transition: all var(--ifm-transition-fast) ease;
50+
}
51+
52+
.copyButton {
53+
background: none;
54+
border: none;
55+
color: inherit;
56+
cursor: pointer;
57+
font-family: inherit;
58+
padding: 0;
59+
}

0 commit comments

Comments
 (0)