Skip to content

Commit 6a22a83

Browse files
authored
use local imports (#485)
1 parent d4d5860 commit 6a22a83

File tree

10 files changed

+936
-1034
lines changed

10 files changed

+936
-1034
lines changed

docs/components/ConfigTable.tsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React from 'react';
2+
3+
type ConfigTableProps = {
4+
children: React.ReactNode;
5+
};
6+
7+
export const ConfigTable = ({ children }: ConfigTableProps) => {
8+
return (
9+
<>
10+
<style>{`
11+
.config-table-wrapper {
12+
overflow-x: auto;
13+
}
14+
15+
.config-table-wrapper table {
16+
table-layout: fixed;
17+
width: 100%;
18+
min-width: 900px;
19+
}
20+
21+
.config-table-wrapper table th:nth-child(1),
22+
.config-table-wrapper table td:nth-child(1) {
23+
width: 15%;
24+
}
25+
26+
.config-table-wrapper table th:nth-child(2),
27+
.config-table-wrapper table td:nth-child(2) {
28+
width: 8%;
29+
}
30+
31+
.config-table-wrapper table th:nth-child(3),
32+
.config-table-wrapper table td:nth-child(3) {
33+
width: 20%;
34+
}
35+
36+
.config-table-wrapper table th:nth-child(4),
37+
.config-table-wrapper table td:nth-child(4) {
38+
width: 17%;
39+
}
40+
41+
.config-table-wrapper table th:nth-child(5),
42+
.config-table-wrapper table td:nth-child(5) {
43+
width: 40%;
44+
}
45+
`}</style>
46+
<div className="config-table-wrapper">{children}</div>
47+
</>
48+
);
49+
};

docs/components/Mermaid.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,14 @@ export default function Mermaid({ chart, id = 'mermaid-graph' }: MermaidProps) {
3232
renderChart();
3333
}, [chart, id]);
3434

35-
return <div ref={container} />;
35+
return (
36+
<div
37+
ref={container}
38+
style={{
39+
background: '#ffffff',
40+
padding: '1rem',
41+
borderRadius: '0.5rem',
42+
}}
43+
/>
44+
);
3645
}

docs/components/SdkButtons.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React from 'react';
2+
3+
type SdkButtonsProps = {
4+
children: React.ReactNode;
5+
};
6+
7+
type SdkButtonProps = {
8+
href: string;
9+
children: React.ReactNode;
10+
};
11+
12+
export const SdkButtons = ({ children }: SdkButtonsProps) => {
13+
return (
14+
<>
15+
<style>{`
16+
.sdk-buttons {
17+
display: flex;
18+
gap: 20px;
19+
flex-wrap: wrap;
20+
margin: 20px 0;
21+
}
22+
23+
.sdk-button {
24+
padding: 8px 16px;
25+
background-color: #4F46E5;
26+
border-radius: 5px;
27+
text-decoration: none;
28+
color: #ffffff;
29+
font-weight: 400;
30+
transition: all 0.2s;
31+
}
32+
33+
.sdk-button:hover {
34+
background-color: #4338CA;
35+
}
36+
`}</style>
37+
<div className="sdk-buttons">{children}</div>
38+
</>
39+
);
40+
};
41+
42+
export const SdkButton = ({ href, children }: SdkButtonProps) => {
43+
return (
44+
<a href={href} className="sdk-button">
45+
{children}
46+
</a>
47+
);
48+
};

docs/components/Tabs.tsx

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
import * as React from 'react';
2+
import * as RadixTabs from '@radix-ui/react-tabs';
3+
4+
type TabsRootProps = {
5+
defaultValue: string;
6+
children: React.ReactNode;
7+
};
8+
9+
type TabsListProps = {
10+
children: React.ReactNode;
11+
};
12+
13+
type TabsTriggerProps = {
14+
value: string;
15+
children: React.ReactNode;
16+
};
17+
18+
type TabsContentProps = {
19+
value: string;
20+
children: React.ReactNode;
21+
};
22+
23+
const Root = ({ defaultValue, children }: TabsRootProps) => {
24+
const [activeTab, setActiveTab] = React.useState(defaultValue);
25+
const rootRef = React.useRef<HTMLDivElement>(null);
26+
const lastProcessedHash = React.useRef<string>('');
27+
28+
React.useEffect(() => {
29+
const timeouts: NodeJS.Timeout[] = [];
30+
31+
const switchToTabContainingHash = () => {
32+
const hash = window.location.hash.slice(1);
33+
if (!hash || hash === lastProcessedHash.current) return;
34+
35+
const timeoutId = setTimeout(() => {
36+
const heading = document.getElementById(hash);
37+
if (!heading) return;
38+
39+
const tabContent = heading.closest('[data-value]');
40+
if (tabContent && rootRef.current?.contains(tabContent)) {
41+
const tabValue = tabContent.getAttribute('data-value');
42+
if (tabValue) {
43+
setActiveTab(tabValue);
44+
lastProcessedHash.current = hash;
45+
const scrollTimeoutId = setTimeout(() => {
46+
heading.scrollIntoView({ behavior: 'smooth', block: 'start' });
47+
}, 100);
48+
timeouts.push(scrollTimeoutId);
49+
}
50+
}
51+
}, 100);
52+
timeouts.push(timeoutId);
53+
};
54+
55+
switchToTabContainingHash();
56+
window.addEventListener('hashchange', switchToTabContainingHash);
57+
58+
const interval = setInterval(() => {
59+
switchToTabContainingHash();
60+
}, 500);
61+
62+
return () => {
63+
window.removeEventListener('hashchange', switchToTabContainingHash);
64+
clearInterval(interval);
65+
timeouts.forEach(clearTimeout);
66+
};
67+
}, []);
68+
69+
return (
70+
<>
71+
<style>{`
72+
.tabs-root {
73+
display: flex;
74+
flex-direction: column;
75+
margin: 1.5rem 0;
76+
}
77+
78+
.tabs-list {
79+
display: flex;
80+
border-bottom: 1px solid var(--vocs-color_border);
81+
gap: 0;
82+
}
83+
84+
.tabs-trigger {
85+
all: unset;
86+
font-family: inherit;
87+
background-color: transparent;
88+
padding: 0.75rem 1.5rem;
89+
height: 45px;
90+
flex: 1;
91+
display: flex;
92+
align-items: center;
93+
justify-content: center;
94+
font-size: 0.9375rem;
95+
line-height: 1;
96+
color: var(--vocs-color_text3);
97+
user-select: none;
98+
cursor: pointer;
99+
border-bottom: 2px solid transparent;
100+
transition: all 0.2s ease;
101+
}
102+
103+
.tabs-trigger:hover {
104+
color: var(--vocs-color_text);
105+
background-color: var(--vocs-color_background2);
106+
}
107+
108+
.tabs-trigger[data-state="active"] {
109+
color: var(--vocs-color_text);
110+
border-bottom-color: var(--vocs-color_link);
111+
font-weight: 500;
112+
}
113+
114+
.tabs-trigger:focus-visible {
115+
outline: 2px solid var(--vocs-color_link);
116+
outline-offset: 2px;
117+
}
118+
119+
.tabs-content {
120+
padding: 1.5rem 0;
121+
outline: none;
122+
}
123+
124+
.tabs-content[data-state="inactive"] {
125+
display: block !important;
126+
position: absolute;
127+
opacity: 0;
128+
pointer-events: none;
129+
height: 0;
130+
overflow: hidden;
131+
visibility: hidden;
132+
}
133+
134+
.tabs-content:focus {
135+
outline: none;
136+
}
137+
138+
.tabs-content > *:not(:last-child) {
139+
margin-bottom: var(--vocs-space_24);
140+
}
141+
142+
.tabs-content > *:last-child {
143+
margin-bottom: 0;
144+
}
145+
`}</style>
146+
<RadixTabs.Root
147+
value={activeTab}
148+
onValueChange={setActiveTab}
149+
className="tabs-root"
150+
ref={rootRef}
151+
>
152+
{children}
153+
</RadixTabs.Root>
154+
</>
155+
);
156+
};
157+
158+
const List = ({ children }: TabsListProps) => (
159+
<RadixTabs.List className="tabs-list">{children}</RadixTabs.List>
160+
);
161+
162+
const Trigger = ({ value, children }: TabsTriggerProps) => (
163+
<RadixTabs.Trigger value={value} className="tabs-trigger">
164+
{children}
165+
</RadixTabs.Trigger>
166+
);
167+
168+
const Content = ({ value, children }: TabsContentProps) => (
169+
<RadixTabs.Content
170+
value={value}
171+
className="tabs-content"
172+
forceMount
173+
data-value={value}
174+
>
175+
{children}
176+
</RadixTabs.Content>
177+
);
178+
179+
export const Tabs = { Root, List, Trigger, Content };

docs/pages/chat-apps/intro/get-started.mdx

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { SdkButtons, SdkButton } from '../../../components/SdkButtons';
2+
13
# Get started building with XMTP
24

35
XMTP (Extensible Message Transport Protocol) is the largest and most secure decentralized messaging network. XMTP is open and permissionless, empowering any developer to build end-to-end encrypted 1:1, group, and agent messaging experiences, and more.
@@ -8,45 +10,13 @@ To learn more, see [Why build with XMTP?](/chat-apps/intro/why-xmtp).
810

911
- Pick your SDK:
1012

11-
<style>
12-
{`
13-
/* Inline styles instead of styles.css bc vocs
14-
search bug doesn't allow imports */
15-
.sdk-buttons {
16-
display: flex;
17-
gap: 20px;
18-
flex-wrap: wrap;
19-
margin: 20px 0;
20-
}
21-
22-
.sdk-button {
23-
padding: 8px 16px;
24-
background-color: #4F46E5;
25-
border-radius: 5px;
26-
text-decoration: none;
27-
color: #ffffff;
28-
font-weight: 400;
29-
transition: all 0.2s;
30-
}
31-
32-
.sdk-button:hover {
33-
background-color: #4338CA;
34-
}
35-
`}
36-
</style>
37-
38-
<div className="sdk-buttons">
39-
<a href="/chat-apps/sdks/browser"
40-
className="sdk-button">Browser</a>
41-
<a href="/chat-apps/sdks/node"
42-
className="sdk-button">Node</a>
43-
<a href="/chat-apps/sdks/react-native"
44-
className="sdk-button">React Native</a>
45-
<a href="/chat-apps/sdks/android"
46-
className="sdk-button">Android</a>
47-
<a href="/chat-apps/sdks/ios"
48-
className="sdk-button">iOS</a>
49-
</div>
13+
<SdkButtons>
14+
<SdkButton href="/chat-apps/sdks/browser">Browser</SdkButton>
15+
<SdkButton href="/chat-apps/sdks/node">Node</SdkButton>
16+
<SdkButton href="/chat-apps/sdks/react-native">React Native</SdkButton>
17+
<SdkButton href="/chat-apps/sdks/android">Android</SdkButton>
18+
<SdkButton href="/chat-apps/sdks/ios">iOS</SdkButton>
19+
</SdkButtons>
5020

5121
- [Use llms-full.txt](/chat-apps/intro/build-with-llms) to provide the full text of the XMTP developer documentation to an AI coding assistant.
5222

docs/pages/fund-agents-apps/calculate-fees.mdx

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,6 @@
11
import Zoom from 'react-medium-image-zoom';
22
import 'react-medium-image-zoom/dist/styles.css';
3-
import { useEffect, useRef } from 'react';
4-
import mermaid from 'mermaid';
5-
6-
{/*
7-
Custom Mermaid component for rendering diagrams in documentation.
8-
9-
This component is defined inline instead of imported from a separate file
10-
because Vocs has a bug where local file imports break search indexing.
11-
Only npm package imports (like react and mermaid) are safe.
12-
*/}
13-
export const Mermaid = ({ chart, id = 'mermaid-graph' }) => {
14-
const container = useRef(null);
15-
16-
useEffect(() => {
17-
mermaid.initialize({ startOnLoad: false });
18-
19-
const renderChart = async () => {
20-
try {
21-
const { svg } = await mermaid.render(id, chart);
22-
if (container.current) {
23-
container.current.innerHTML = svg;
24-
}
25-
} catch (error) {
26-
console.error('Mermaid render error:', error);
27-
if (container.current) {
28-
container.current.innerHTML = `<pre style="color: red;">Failed to render diagram: ${String(error)}</pre>`;
29-
}
30-
}
31-
};
32-
33-
renderChart();
34-
35-
}, [chart, id]);
36-
37-
return <div ref={container} style={{ background: '#ffffff', padding: '1rem', borderRadius: '0.5rem' }} />;
38-
};
3+
import Mermaid from '../../components/Mermaid';
394

405
# Understand and calculate XMTP fees
416

0 commit comments

Comments
 (0)