Skip to content

Commit cff112d

Browse files
committed
Replace CodeTabs with GDS’s CodeBlock.Tabs
1 parent c717bc6 commit cff112d

File tree

4 files changed

+91
-119
lines changed

4 files changed

+91
-119
lines changed

website/src/components/CodeBlock.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,25 @@ export const CodeBlock = ({ className, children, ...props }: CodeBlockProps) =>
2828
<ExperimentalCodeBlock
2929
language={language as ExperimentalCodeBlockProps['language']}
3030
lineNumbers={lineCount > 1}
31-
className={classNames(['graph-docs-not-markdown --:my-8 --:last:mb-0 -:is-[li>*]:my-4', className])}
31+
className={classNames([
32+
`graph-docs-not-markdown
33+
--:not-in-group/code-block-tabs:my-8
34+
--:not-in-group/code-block-tabs:last:mb-0
35+
-:not-in-group/code-block-tabs:is-[li>*]:my-4`,
36+
className,
37+
])}
3238
{...(props as ComponentProps<'div'>)}
3339
>
3440
{code}
3541
</ExperimentalCodeBlock>
3642
)
3743
}
44+
45+
export const CodeBlockTabs = ({ className, ...props }: ComponentProps<typeof ExperimentalCodeBlock.Tabs>) => {
46+
return (
47+
<ExperimentalCodeBlock.Tabs
48+
className={classNames(['graph-docs-not-markdown --my-8 -:is-[li>*]:my-4', className])}
49+
{...props}
50+
/>
51+
)
52+
}

website/src/components/CodeTabs.tsx

Lines changed: 0 additions & 38 deletions
This file was deleted.

website/src/layout/Layout.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import {
5656
import {
5757
Callout,
5858
CodeBlock,
59+
CodeBlockTabs,
5960
DocSearch,
6061
Heading,
6162
Image,
@@ -64,7 +65,6 @@ import {
6465
Table,
6566
VideoEmbed,
6667
} from '@/components'
67-
import { CodeTab, CodeTabs } from '@/components/CodeTabs'
6868
import { useI18n } from '@/i18n'
6969

7070
import { MDXContent } from './MDXContent'
@@ -611,12 +611,12 @@ export default function Layout({ pageOpts, children }: NextraThemeLayoutProps<Fr
611611
img: ImageWrapper,
612612
// TODO: Fix "[Shiki] X instances have been created. Shiki is supposed to be used as a singleton" warnings
613613
pre: CodeBlock,
614+
CodeBlock,
615+
CodeBlockTabs,
614616
// TODO: Build and use `ExperimentalTable`
615617
table: Table,
616618
VideoEmbed,
617619
wrapper: MDXContent,
618-
CodeTabs,
619-
CodeTab,
620620
}}
621621
>
622622
{children}

website/src/pages/en/token-api/quick-start.mdx

Lines changed: 72 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -13,87 +13,82 @@ Make sure you already have an account on [The Graph Market](https://thegraph.com
1313

1414
Raw API endpoints are authenticated using a header, and the TypeScript Node.js SDK accepts the token as a configuration option.
1515

16-
<CodeTabs>
17-
<CodeTab label="cURL">
18-
```shell
19-
curl --request GET \
20-
--url "https://token-api.thegraph.com/v1/evm/balances?network=mainnet&address=0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208" \
21-
--header 'Accept: application/json' \
22-
--header 'Authorization: Bearer YOUR_TOKEN'
23-
```
24-
</CodeTab>
25-
<CodeTab label="Node.js">
26-
```typescript
27-
import {EVMChains, TokenAPI} from "@pinax/token-api";
28-
29-
const client = new TokenAPI({
30-
apiToken: process.env.TOKEN_API_KEY || ""
31-
});
32-
33-
const result = await client.evm.tokens.getBalances({
34-
network: EVMChains.Ethereum,
35-
address: ['0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208']
36-
})
37-
```
38-
</CodeTab>
39-
<CodeTab label="Python">
40-
```python
41-
import requests
42-
43-
res = requests.get(
16+
<CodeBlockTabs tabs={['cURL', 'Node.js', 'Python', 'Go', 'Rust']}>
17+
18+
```shell
19+
curl --request GET \
20+
--url "https://token-api.thegraph.com/v1/evm/balances?network=mainnet&address=0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208" \
21+
--header 'Accept: application/json' \
22+
--header 'Authorization: Bearer YOUR_TOKEN'
23+
```
24+
25+
```typescript
26+
import {EVMChains, TokenAPI} from "@pinax/token-api";
27+
28+
const client = new TokenAPI({
29+
apiToken: process.env.TOKEN_API_KEY || ""
30+
});
31+
32+
const result = await client.evm.tokens.getBalances({
33+
network: EVMChains.Ethereum,
34+
address: ['0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208']
35+
})
36+
```
37+
38+
```python
39+
import requests
40+
41+
res = requests.get(
42+
"https://token-api.thegraph.com/v1/evm/balances?network=mainnet&address=0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208",
43+
headers={"Authorization": "Bearer YOUR_TOKEN"},
44+
)
45+
46+
print(res.json())
47+
```
48+
49+
```go
50+
package main
51+
52+
import (
53+
"fmt"
54+
"encoding/json"
55+
"net/http"
56+
)
57+
58+
func main() {
59+
req, _ := http.NewRequest("GET",
4460
"https://token-api.thegraph.com/v1/evm/balances?network=mainnet&address=0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208",
45-
headers={"Authorization": "Bearer YOUR_TOKEN"},
61+
nil,
4662
)
63+
req.Header.Set("Authorization", "Bearer YOUR_TOKEN")
4764

48-
print(res.json())
49-
```
50-
</CodeTab>
51-
<CodeTab label="Go">
52-
```go
53-
package main
54-
55-
import (
56-
"fmt"
57-
"encoding/json"
58-
"net/http"
59-
)
65+
res, _ := http.DefaultClient.Do(req)
66+
defer res.Body.Close()
67+
68+
var data any
69+
json.NewDecoder(res.Body).Decode(&data)
70+
71+
fmt.Printf("%#v\n", data)
72+
}
73+
```
74+
75+
```rust
76+
use reqwest::Client;
77+
78+
#[tokio::main]
79+
async fn main() -> reqwest::Result<()> {
80+
let res = Client::new()
81+
.get("https://token-api.thegraph.com/v1/evm/balances?network=mainnet&address=0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208")
82+
.bearer_auth("YOUR_TOKEN")
83+
.send()
84+
.await?;
85+
86+
println!("{}", res.text().await?);
87+
Ok(())
88+
}
89+
```
6090

61-
func main() {
62-
req, _ := http.NewRequest("GET",
63-
"https://token-api.thegraph.com/v1/evm/balances?network=mainnet&address=0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208",
64-
nil,
65-
)
66-
req.Header.Set("Authorization", "Bearer YOUR_TOKEN")
67-
68-
res, _ := http.DefaultClient.Do(req)
69-
defer res.Body.Close()
70-
71-
var data any
72-
json.NewDecoder(res.Body).Decode(&data)
73-
74-
fmt.Printf("%#v\n", data)
75-
}
76-
```
77-
</CodeTab>
78-
<CodeTab label="Rust">
79-
```rust
80-
use reqwest::Client;
81-
82-
#[tokio::main]
83-
async fn main() -> reqwest::Result<()> {
84-
let res = Client::new()
85-
.get("https://token-api.thegraph.com/v1/evm/balances?network=mainnet&address=0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208")
86-
.bearer_auth("YOUR_TOKEN")
87-
.send()
88-
.await?;
89-
90-
println!("{}", res.text().await?);
91-
Ok(())
92-
}
93-
```
94-
</CodeTab>
95-
96-
</CodeTabs>
91+
</CodeBlockTabs>
9792

9893
## What's next?
9994

0 commit comments

Comments
 (0)