-
Notifications
You must be signed in to change notification settings - Fork 308
Expand file tree
/
Copy pathBuildIt.tsx
More file actions
272 lines (253 loc) · 7.81 KB
/
BuildIt.tsx
File metadata and controls
272 lines (253 loc) · 7.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
import React, { useState } from 'react';
import styles from './WorkflowMessagingDemo.module.css';
import {
LANGUAGES,
MESSAGE_TYPE_DATA,
type LangId,
type MessageTypeId,
} from './buildData';
type Props = { onNext: () => void };
const MESSAGE_TABS: { id: MessageTypeId; label: string }[] = [
{ id: 'signal', label: 'Signal' },
{ id: 'query', label: 'Query' },
{ id: 'update', label: 'Update' },
];
/* ── Line-highlighted code pane ── */
function CodePane({
title,
code,
activeLines,
accentColor,
}: {
title: string;
code: string;
activeLines: Set<number>;
accentColor: string;
}) {
const lines = code.split('\n');
const hasActive = activeLines.size > 0;
return (
<div style={{ minWidth: 0 }}>
<div
style={{
fontSize: 11,
fontWeight: 600,
color: 'var(--nd-muted)',
textTransform: 'uppercase',
letterSpacing: '0.06em',
marginBottom: 6,
}}
>
{title}
</div>
<div
style={{
background: 'var(--nd-surface)',
border: '1px solid var(--nd-border)',
borderRadius: 8,
overflow: 'auto',
maxHeight: 480,
}}
>
<pre
style={{
margin: 0,
padding: '14px 0',
fontSize: 12,
fontFamily: 'var(--ifm-font-family-monospace)',
lineHeight: 1.65,
}}
>
{lines.map((line, i) => {
const lineNum = i + 1;
const isActive = activeLines.has(lineNum);
return (
<div
key={i}
style={{
padding: '1px 16px',
borderLeft: isActive
? `3px solid ${accentColor}`
: '3px solid transparent',
background: isActive
? `color-mix(in srgb, ${accentColor} 14%, transparent)`
: 'transparent',
opacity: hasActive && !isActive ? 0.28 : 1,
transition: 'opacity 0.15s ease, background 0.15s ease',
whiteSpace: 'pre',
color: 'var(--ifm-font-color-base)',
}}
>
{line || ' '}
</div>
);
})}
</pre>
</div>
</div>
);
}
export default function BuildIt({ onNext }: Props) {
const [msgType, setMsgType] = useState<MessageTypeId>('signal');
const [lang, setLang] = useState<LangId>('python');
const [activeAnnotation, setActiveAnnotation] = useState<number | null>(null);
function selectMsgType(id: MessageTypeId) {
setMsgType(id);
setActiveAnnotation(null);
}
function selectLang(id: LangId) {
setLang(id);
setActiveAnnotation(null);
}
function toggleAnnotation(i: number) {
setActiveAnnotation((prev) => (prev === i ? null : i));
}
const data = MESSAGE_TYPE_DATA[msgType];
const langCode = data.code[lang];
const ann = activeAnnotation !== null ? data.annotations[activeAnnotation] : null;
const annLines = ann?.lines[lang];
const wfLines = new Set(annLines?.workflowLines ?? []);
const clientLines = new Set(annLines?.clientLines ?? []);
return (
<div className={styles.section}>
<div className={styles.progressBar}>
<div className={styles.progressFill} style={{ width: '80%' }} />
</div>
<h1>Build It</h1>
<p className={styles.lead}>
Code examples for all five SDKs. Select a message type and language, then click an
annotation to highlight the relevant lines.
</p>
{/* Message type tabs */}
<div className={styles.runTabs} style={{ marginBottom: 8 }}>
{MESSAGE_TABS.map((t) => (
<button
key={t.id}
className={`${styles.runTab} ${msgType === t.id ? styles.runTabActive : ''}`}
onClick={() => selectMsgType(t.id)}
>
{t.label}
</button>
))}
</div>
{/* Language tabs */}
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap', marginBottom: 16 }}>
{LANGUAGES.map((l) => (
<button
key={l.id}
onClick={() => selectLang(l.id)}
style={{
padding: '4px 12px',
borderRadius: 6,
border: `1px solid ${lang === l.id ? data.accentColor : 'var(--nd-border)'}`,
background: lang === l.id
? `color-mix(in srgb, ${data.accentColor} 12%, transparent)`
: 'transparent',
color: lang === l.id ? data.accentColor : 'var(--nd-muted)',
fontSize: 12,
fontWeight: lang === l.id ? 600 : 400,
cursor: 'pointer',
transition: 'all 0.12s ease',
}}
>
{l.label}
</button>
))}
</div>
<p style={{ fontSize: 14, color: 'var(--ifm-font-color-base)', margin: '0 0 16px', lineHeight: 1.7 }}>
{data.description}
</p>
{/* Two-column code view */}
<div
style={{
display: 'grid',
gridTemplateColumns: '1fr 1fr',
gap: 12,
marginBottom: 16,
}}
>
<CodePane
title="Workflow definition"
code={langCode.workflowCode}
activeLines={wfLines}
accentColor={data.accentColor}
/>
<CodePane
title="Client code"
code={langCode.clientCode}
activeLines={clientLines}
accentColor={data.accentColor}
/>
</div>
{/* Annotation pills */}
<div style={{ marginBottom: 8 }}>
<div
style={{
fontSize: 11,
fontWeight: 600,
color: 'var(--nd-muted)',
textTransform: 'uppercase',
letterSpacing: '0.06em',
marginBottom: 8,
}}
>
Highlight a concept
</div>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
{data.annotations.map((a, i) => {
const isActive = activeAnnotation === i;
return (
<button
key={i}
onClick={() => toggleAnnotation(i)}
style={{
padding: '6px 14px',
borderRadius: 20,
border: `1px solid ${isActive ? data.accentColor : 'var(--nd-border)'}`,
background: isActive
? `color-mix(in srgb, ${data.accentColor} 15%, transparent)`
: 'var(--nd-surface)',
color: isActive ? data.accentColor : 'var(--ifm-font-color-base)',
fontSize: 12,
fontWeight: isActive ? 600 : 400,
cursor: 'pointer',
transition: 'all 0.15s ease',
}}
>
{a.label}
</button>
);
})}
</div>
</div>
{/* Annotation description box */}
<div
style={{
minHeight: 52,
padding: ann ? '12px 16px' : '0',
background: ann
? `color-mix(in srgb, ${data.accentColor} 8%, transparent)`
: 'transparent',
border: ann
? `1px solid color-mix(in srgb, ${data.accentColor} 50%, transparent)`
: '1px solid transparent',
borderRadius: 8,
transition: 'all 0.15s ease',
marginBottom: 16,
}}
>
{ann && (
<p style={{ margin: 0, fontSize: 13, color: 'var(--ifm-font-color-base)', lineHeight: 1.7 }}>
{ann.description}
</p>
)}
</div>
<div className={styles.buildNote}>{data.note}</div>
<div className={styles.nextRow}>
<button className={styles.btn} onClick={onNext}>
Next: Test Yourself →
</button>
</div>
</div>
);
}