@openpkg-ts/react 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,504 @@
1
+ import { SpecMember } from "@openpkg-ts/spec";
2
+ interface CollapsibleMethodProps {
3
+ /** Method member to display */
4
+ member: SpecMember;
5
+ /** Default expanded state */
6
+ defaultExpanded?: boolean;
7
+ /** Custom className */
8
+ className?: string;
9
+ /** Custom header renderer */
10
+ renderHeader?: (member: SpecMember, expanded: boolean, toggle: () => void) => React.ReactNode;
11
+ /** Custom content renderer */
12
+ renderContent?: (member: SpecMember) => React.ReactNode;
13
+ }
14
+ /**
15
+ * Headless collapsible method component.
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * <CollapsibleMethod member={method} defaultExpanded />
20
+ *
21
+ * // Custom rendering
22
+ * <CollapsibleMethod
23
+ * member={method}
24
+ * renderHeader={(m, expanded, toggle) => (
25
+ * <button onClick={toggle}>{m.name}</button>
26
+ * )}
27
+ * />
28
+ * ```
29
+ */
30
+ declare function CollapsibleMethod({ member, defaultExpanded, className, renderHeader, renderContent }: CollapsibleMethodProps): React.ReactNode;
31
+ import { SpecExample } from "@openpkg-ts/spec";
32
+ interface ExampleBlockProps {
33
+ /** Examples to display (string or SpecExample) */
34
+ examples: (string | SpecExample)[];
35
+ /** Custom className */
36
+ className?: string;
37
+ /** Custom example renderer */
38
+ renderExample?: (example: string | SpecExample, index: number) => React.ReactNode;
39
+ }
40
+ /**
41
+ * Normalize example to string content.
42
+ */
43
+ declare function getExampleCode(example: string | SpecExample): string;
44
+ /**
45
+ * Get example title if available.
46
+ */
47
+ declare function getExampleTitle(example: string | SpecExample): string | undefined;
48
+ /**
49
+ * Get example language.
50
+ */
51
+ declare function getExampleLanguage(example: string | SpecExample): string;
52
+ /**
53
+ * Clean code by removing markdown fences.
54
+ */
55
+ declare function cleanCode(code: string): string;
56
+ /**
57
+ * Headless example block component.
58
+ *
59
+ * @example
60
+ * ```tsx
61
+ * <ExampleBlock examples={exp.examples} />
62
+ *
63
+ * // Custom rendering
64
+ * <ExampleBlock
65
+ * examples={exp.examples}
66
+ * renderExample={(ex) => <CustomCode code={getExampleCode(ex)} />}
67
+ * />
68
+ * ```
69
+ */
70
+ declare function ExampleBlock({ examples, className, renderExample }: ExampleBlockProps): React.ReactNode;
71
+ import { SpecSchema, SpecSignatureParameter } from "@openpkg-ts/spec";
72
+ interface ExpandablePropertyProps {
73
+ /** Parameter to display */
74
+ param: SpecSignatureParameter;
75
+ /** Nesting depth */
76
+ depth?: number;
77
+ /** Custom className */
78
+ className?: string;
79
+ }
80
+ interface NestedPropertyProps {
81
+ /** Property name */
82
+ name: string;
83
+ /** Property schema */
84
+ schema: SpecSchema;
85
+ /** Is required */
86
+ required?: boolean;
87
+ /** Nesting depth */
88
+ depth?: number;
89
+ }
90
+ /**
91
+ * Nested property display.
92
+ */
93
+ declare function NestedProperty({ name, schema, required, depth }: NestedPropertyProps): React.ReactNode;
94
+ /**
95
+ * Headless expandable property for parameters with nested objects.
96
+ *
97
+ * @example
98
+ * ```tsx
99
+ * <ExpandableProperty param={param} />
100
+ * ```
101
+ */
102
+ declare function ExpandableProperty({ param, depth, className }: ExpandablePropertyProps): React.ReactNode;
103
+ import { SpecMember as SpecMember2 } from "@openpkg-ts/spec";
104
+ interface MembersTableProps {
105
+ /** Members to display */
106
+ members: SpecMember2[];
107
+ /** Custom className */
108
+ className?: string;
109
+ /** Group by kind (constructor, property, method) */
110
+ groupByKind?: boolean;
111
+ /** Custom member renderer */
112
+ renderMember?: (member: SpecMember2, index: number) => React.ReactNode;
113
+ }
114
+ interface MemberGroups {
115
+ constructors: SpecMember2[];
116
+ properties: SpecMember2[];
117
+ methods: SpecMember2[];
118
+ accessors: SpecMember2[];
119
+ other: SpecMember2[];
120
+ }
121
+ /**
122
+ * Group members by their kind.
123
+ */
124
+ declare function groupMembersByKind(members: SpecMember2[]): MemberGroups;
125
+ interface MemberRowProps {
126
+ member: SpecMember2;
127
+ }
128
+ /**
129
+ * Individual member row.
130
+ */
131
+ declare function MemberRow({ member }: MemberRowProps): React.ReactNode;
132
+ /**
133
+ * Headless members table for classes/interfaces.
134
+ *
135
+ * @example
136
+ * ```tsx
137
+ * <MembersTable members={exp.members} groupByKind />
138
+ * ```
139
+ */
140
+ declare function MembersTable({ members, className, groupByKind, renderMember }: MembersTableProps): React.ReactNode;
141
+ import { SpecMember as SpecMember3, SpecSignatureParameter as SpecSignatureParameter2 } from "@openpkg-ts/spec";
142
+ interface ParamTableProps {
143
+ /** Parameters or members to display */
144
+ items: (SpecSignatureParameter2 | SpecMember3)[];
145
+ /** Show required indicator */
146
+ showRequired?: boolean;
147
+ /** Custom className */
148
+ className?: string;
149
+ /** Render custom row */
150
+ renderRow?: (item: SpecSignatureParameter2 | SpecMember3, index: number) => React.ReactNode;
151
+ }
152
+ interface ParamRowProps {
153
+ item: SpecSignatureParameter2 | SpecMember3;
154
+ showRequired?: boolean;
155
+ }
156
+ /**
157
+ * Individual parameter row component.
158
+ */
159
+ declare function ParamRow({ item, showRequired }: ParamRowProps): React.ReactNode;
160
+ /**
161
+ * Headless parameter table component.
162
+ *
163
+ * @example
164
+ * ```tsx
165
+ * <ParamTable items={sig.parameters} />
166
+ *
167
+ * // Custom row rendering
168
+ * <ParamTable
169
+ * items={sig.parameters}
170
+ * renderRow={(item) => <CustomRow key={item.name} param={item} />}
171
+ * />
172
+ * ```
173
+ */
174
+ declare function ParamTable({ items, showRequired, className, renderRow }: ParamTableProps): React.ReactNode;
175
+ import { SpecExport } from "@openpkg-ts/spec";
176
+ interface SignatureProps {
177
+ /** The to render signature for */
178
+ export: SpecExport;
179
+ /** Index of signature to render (for overloaded functions) */
180
+ signatureIndex?: number;
181
+ /** Custom className */
182
+ className?: string;
183
+ /** Render prop for custom rendering */
184
+ children?: (signature: string) => React.ReactNode;
185
+ }
186
+ /**
187
+ * Headless signature component. Renders a type signature string.
188
+ *
189
+ * @example
190
+ * ```tsx
191
+ * // Default rendering
192
+ * <Signature export={fn} />
193
+ *
194
+ * // Custom rendering
195
+ * <Signature export={fn}>
196
+ * {(sig) => <pre>{sig}</pre>}
197
+ * </Signature>
198
+ * ```
199
+ */
200
+ declare function Signature({ export: exp, signatureIndex, className, children }: SignatureProps): React.ReactNode;
201
+ import { SpecMember as SpecMember4, SpecSignatureParameter as SpecSignatureParameter3 } from "@openpkg-ts/spec";
202
+ interface TypeTableProps {
203
+ /** Members or parameters to display */
204
+ items: (SpecSignatureParameter3 | SpecMember4)[];
205
+ /** Show required indicator */
206
+ showRequired?: boolean;
207
+ /** Custom className */
208
+ className?: string;
209
+ /** Render custom row */
210
+ renderRow?: (item: SpecSignatureParameter3 | SpecMember4, index: number) => React.ReactNode;
211
+ }
212
+ /**
213
+ * Headless type table for displaying interface/type members.
214
+ *
215
+ * @example
216
+ * ```tsx
217
+ * <TypeTable items={exp.members} />
218
+ * ```
219
+ */
220
+ declare function TypeTable({ items, showRequired, className, renderRow }: TypeTableProps): React.ReactNode;
221
+ import { CodeTab, CodeTabs, CodeTabsProps, ImportSection, ImportSectionProps } from "@openpkg-ts/ui/api";
222
+ import { OpenPkg } from "@openpkg-ts/spec";
223
+ import { DocsInstance } from "@openpkg-ts/sdk";
224
+ interface APIPageProps {
225
+ /** Direct spec object */
226
+ spec?: OpenPkg;
227
+ /** Or docs instance from createDocs() */
228
+ instance?: DocsInstance;
229
+ /** Export ID to render, or undefined for index page */
230
+ id?: string;
231
+ /** Base href for index page links (required when id is undefined) */
232
+ baseHref?: string;
233
+ /** Description for index page */
234
+ description?: string;
235
+ /** Custom code example renderer */
236
+ renderExample?: (code: string, filename: string) => React.ReactNode;
237
+ }
238
+ /**
239
+ * Main styled API page component that renders documentation.
240
+ *
241
+ * Renders either:
242
+ * - Index page (when id is undefined) showing all exports in a grid
243
+ * - Detail page (when id is provided) showing specific docs
244
+ *
245
+ * @example
246
+ * ```tsx
247
+ * // Index mode - show all exports
248
+ * <APIPage spec={spec} baseHref="/docs/api" />
249
+ * ```
250
+ *
251
+ * @example
252
+ * ```tsx
253
+ * // Detail mode - show specific * <APIPage spec={spec} id="createClient" />
254
+ * ```
255
+ */
256
+ declare function APIPage({ spec, instance, id, baseHref, description, renderExample }: APIPageProps): React.ReactNode;
257
+ import { OpenPkg as OpenPkg2, SpecExport as SpecExport2 } from "@openpkg-ts/spec";
258
+ import { ReactNode as ReactNode2 } from "react";
259
+ interface ClassPageProps {
260
+ export: SpecExport2;
261
+ spec: OpenPkg2;
262
+ }
263
+ /**
264
+ * Stripe-style class page with two-column layout.
265
+ * Left: constructor, methods, properties. Right: sticky code examples.
266
+ */
267
+ declare function ClassPage({ export: exp, spec }: ClassPageProps): ReactNode2;
268
+ import { OpenPkg as OpenPkg3, SpecExport as SpecExport3 } from "@openpkg-ts/spec";
269
+ import { ReactNode as ReactNode3 } from "react";
270
+ interface EnumPageProps {
271
+ export: SpecExport3;
272
+ spec: OpenPkg3;
273
+ }
274
+ /**
275
+ * Stripe-style enum page with two-column layout.
276
+ */
277
+ declare function EnumPage({ export: exp, spec }: EnumPageProps): ReactNode3;
278
+ interface ExportCardProps {
279
+ /** Function/name */
280
+ name: string;
281
+ /** Description snippet */
282
+ description?: string;
283
+ /** Link to detail page */
284
+ href: string;
285
+ /** Export kind: function, type, variable, class, interface, enum */
286
+ kind?: "function" | "type" | "variable" | "class" | "interface" | "enum";
287
+ /** Custom className */
288
+ className?: string;
289
+ }
290
+ /**
291
+ * Card component for displaying exports in an index grid.
292
+ * Features function name styling, description, and hover effects.
293
+ */
294
+ declare function ExportCard({ name, description, href, kind, className }: ExportCardProps): React.ReactNode;
295
+ import { OpenPkg as OpenPkg4 } from "@openpkg-ts/spec";
296
+ import { ReactNode as ReactNode4 } from "react";
297
+ interface ExportIndexPageProps {
298
+ /** OpenPkg spec */
299
+ spec: OpenPkg4;
300
+ /** Base href for links (e.g., '/docs/api') */
301
+ baseHref: string;
302
+ /** Optional intro description */
303
+ description?: string;
304
+ /** Custom className */
305
+ className?: string;
306
+ /** Show search input (default: true) */
307
+ showSearch?: boolean;
308
+ /** Show category filter buttons (default: true) */
309
+ showFilters?: boolean;
310
+ }
311
+ /**
312
+ * Index page showing all exports in a grid, grouped by category.
313
+ * AI SDK-style clean layout with responsive 2-column grid.
314
+ */
315
+ declare function ExportIndexPage({ spec, baseHref, description, className, showSearch, showFilters }: ExportIndexPageProps): ReactNode4;
316
+ import { OpenPkg as OpenPkg5, SpecExportKind } from "@openpkg-ts/spec";
317
+ import { ReactNode as ReactNode5 } from "react";
318
+ interface FullAPIReferencePageProps {
319
+ /** OpenPkg spec */
320
+ spec: OpenPkg5;
321
+ /** Filter to specific kinds (default: all) */
322
+ kinds?: SpecExportKind[];
323
+ /** Show kind filter buttons (default: true) */
324
+ showFilters?: boolean;
325
+ /** Show in-page TOC navigation (default: false) */
326
+ showTOC?: boolean;
327
+ /** Custom title (default: spec.meta.name) */
328
+ title?: string;
329
+ /** Custom description */
330
+ description?: ReactNode5;
331
+ /** Custom className */
332
+ className?: string;
333
+ }
334
+ /**
335
+ * Single-page API reference that renders all exports in a scrollable view.
336
+ * Similar to Stripe's API documentation layout.
337
+ *
338
+ * @example
339
+ * ```tsx
340
+ * // Show all exports with TOC
341
+ * <FullAPIReferencePage spec={spec} showTOC />
342
+ * ```
343
+ *
344
+ * @example
345
+ * ```tsx
346
+ * // Show only functions
347
+ * <FullAPIReferencePage spec={spec} kinds={['function']} title="Functions" />
348
+ * ```
349
+ */
350
+ declare function FullAPIReferencePage({ spec, kinds, showFilters, showTOC, title, description, className }: FullAPIReferencePageProps): ReactNode5;
351
+ import { OpenPkg as OpenPkg6, SpecExport as SpecExport4 } from "@openpkg-ts/spec";
352
+ import { ReactNode as ReactNode6 } from "react";
353
+ interface FunctionPageProps {
354
+ export: SpecExport4;
355
+ spec: OpenPkg6;
356
+ }
357
+ /**
358
+ * Stripe-style function page with two-column layout.
359
+ * Left: parameters, returns. Right: sticky code examples.
360
+ */
361
+ declare function FunctionPage({ export: exp, spec }: FunctionPageProps): ReactNode6;
362
+ import { OpenPkg as OpenPkg7, SpecExport as SpecExport5 } from "@openpkg-ts/spec";
363
+ import { ReactNode as ReactNode7 } from "react";
364
+ interface InterfacePageProps {
365
+ export: SpecExport5;
366
+ spec: OpenPkg7;
367
+ }
368
+ /**
369
+ * Stripe-style interface/type page with two-column layout.
370
+ * Left: properties, methods. Right: sticky code examples.
371
+ */
372
+ declare function InterfacePage({ export: exp, spec }: InterfacePageProps): ReactNode7;
373
+ import { SpecSchema as SpecSchema2, SpecSignatureParameter as SpecSignatureParameter4 } from "@openpkg-ts/spec";
374
+ interface ParameterItemProps {
375
+ /** Parameter to display */
376
+ param: SpecSignatureParameter4;
377
+ /** Nesting depth for indentation */
378
+ depth?: number;
379
+ /** Custom className */
380
+ className?: string;
381
+ }
382
+ interface NestedPropertyItemProps {
383
+ /** Property name */
384
+ name: string;
385
+ /** Property schema */
386
+ schema: SpecSchema2;
387
+ /** Is this property required */
388
+ required?: boolean;
389
+ /** Nesting depth */
390
+ depth?: number;
391
+ }
392
+ /**
393
+ * Single parameter with expand capability for nested objects.
394
+ * Features expandable nested params, type annotations, and required/optional badges.
395
+ *
396
+ * @deprecated Use APIParameterItem from @openpkg-ts/ui with specParamToAPIParam adapter.
397
+ * Will be removed in next major version.
398
+ */
399
+ declare function ParameterItem({ param, depth, className }: ParameterItemProps): React.ReactNode;
400
+ import { OpenPkg as OpenPkg8, SpecExport as SpecExport6 } from "@openpkg-ts/spec";
401
+ import { ReactNode as ReactNode8 } from "react";
402
+ interface ClassSectionProps {
403
+ export: SpecExport6;
404
+ spec: OpenPkg8;
405
+ }
406
+ /**
407
+ * Class section for use in single-page API reference.
408
+ * Renders an APISection with constructor, methods, and properties.
409
+ */
410
+ declare function ClassSection({ export: exp, spec }: ClassSectionProps): ReactNode8;
411
+ import { OpenPkg as OpenPkg9, SpecExport as SpecExport7 } from "@openpkg-ts/spec";
412
+ import { ReactNode as ReactNode9 } from "react";
413
+ interface EnumSectionProps {
414
+ export: SpecExport7;
415
+ spec: OpenPkg9;
416
+ }
417
+ /**
418
+ * Enum section for use in single-page API reference.
419
+ * Renders an APISection with enum members.
420
+ */
421
+ declare function EnumSection({ export: exp, spec }: EnumSectionProps): ReactNode9;
422
+ import { OpenPkg as OpenPkg10, SpecExport as SpecExport8 } from "@openpkg-ts/spec";
423
+ import { ReactNode as ReactNode10 } from "react";
424
+ interface ExportSectionProps {
425
+ export: SpecExport8;
426
+ spec: OpenPkg10;
427
+ }
428
+ /**
429
+ * Router component that renders the appropriate section based on kind.
430
+ * Used by FullAPIReferencePage to render each inline.
431
+ */
432
+ declare function ExportSection({ export: exp, spec }: ExportSectionProps): ReactNode10;
433
+ import { OpenPkg as OpenPkg11, SpecExport as SpecExport9 } from "@openpkg-ts/spec";
434
+ import { ReactNode as ReactNode11 } from "react";
435
+ interface FunctionSectionProps {
436
+ export: SpecExport9;
437
+ spec: OpenPkg11;
438
+ }
439
+ /**
440
+ * Function section for use in single-page API reference.
441
+ * Renders an APISection with parameters and returns.
442
+ */
443
+ declare function FunctionSection({ export: exp, spec }: FunctionSectionProps): ReactNode11;
444
+ import { OpenPkg as OpenPkg12, SpecExport as SpecExport10 } from "@openpkg-ts/spec";
445
+ import { ReactNode as ReactNode12 } from "react";
446
+ interface InterfaceSectionProps {
447
+ export: SpecExport10;
448
+ spec: OpenPkg12;
449
+ }
450
+ /**
451
+ * Interface/type section for use in single-page API reference.
452
+ * Renders an APISection with properties and methods.
453
+ */
454
+ declare function InterfaceSection({ export: exp, spec }: InterfaceSectionProps): ReactNode12;
455
+ import { OpenPkg as OpenPkg13, SpecExport as SpecExport11 } from "@openpkg-ts/spec";
456
+ import { ReactNode as ReactNode13 } from "react";
457
+ interface VariableSectionProps {
458
+ export: SpecExport11;
459
+ spec: OpenPkg13;
460
+ }
461
+ /**
462
+ * Variable/constant section for use in single-page API reference.
463
+ * Renders an APISection with type information.
464
+ */
465
+ declare function VariableSection({ export: exp, spec }: VariableSectionProps): ReactNode13;
466
+ import { OpenPkg as OpenPkg14, SpecExport as SpecExport12 } from "@openpkg-ts/spec";
467
+ import { ReactNode as ReactNode14 } from "react";
468
+ interface VariablePageProps {
469
+ export: SpecExport12;
470
+ spec: OpenPkg14;
471
+ }
472
+ /**
473
+ * Stripe-style variable/constant page with two-column layout.
474
+ */
475
+ declare function VariablePage({ export: exp, spec }: VariablePageProps): ReactNode14;
476
+ import { OpenPkg as OpenPkg15, SpecExample as SpecExample2, SpecExport as SpecExport13, SpecSchema as SpecSchema3, SpecSignatureParameter as SpecSignatureParameter5 } from "@openpkg-ts/spec";
477
+ import { APIParameterSchema, CodeExample, Language } from "@openpkg-ts/ui/docskit";
478
+ /**
479
+ * Convert SpecSchema to APIParameterSchema for nested object display.
480
+ */
481
+ declare function specSchemaToAPISchema(schema: SpecSchema3 | undefined): APIParameterSchema | undefined;
482
+ /**
483
+ * Convert a SpecSignatureParameter to APIParameterItem props.
484
+ */
485
+ declare function specParamToAPIParam(param: SpecSignatureParameter5): {
486
+ name: string;
487
+ type: string;
488
+ required: boolean;
489
+ description?: string;
490
+ children?: APIParameterSchema;
491
+ };
492
+ /**
493
+ * Convert SpecExample[] to CodeExample[] for APICodePanel.
494
+ */
495
+ declare function specExamplesToCodeExamples(examples: SpecExample2[] | undefined, defaultLang?: string): CodeExample[];
496
+ /**
497
+ * Extract unique languages from examples for language selector.
498
+ */
499
+ declare function getLanguagesFromExamples(examples: SpecExample2[] | undefined): Language[];
500
+ /**
501
+ * Build import statement for an export.
502
+ */
503
+ declare function buildImportStatement(exp: SpecExport13, spec: OpenPkg15): string;
504
+ export { specSchemaToAPISchema, specParamToAPIParam, specExamplesToCodeExamples, groupMembersByKind, getLanguagesFromExamples, getExampleTitle, getExampleLanguage, getExampleCode, cleanCode, buildImportStatement, VariableSectionProps, VariableSection, VariablePageProps, VariablePage, TypeTableProps, TypeTable, SignatureProps, Signature, ParameterItemProps, ParameterItem, ParamTableProps, ParamTable, ParamRowProps, ParamRow, NestedPropertyProps, NestedPropertyItemProps, NestedProperty, MembersTableProps, MembersTable, MemberRowProps, MemberRow, MemberGroups, InterfaceSectionProps, InterfaceSection, InterfacePageProps, InterfacePage, ImportSectionProps, ImportSection, FunctionSectionProps, FunctionSection, FunctionPageProps, FunctionPage, FullAPIReferencePageProps, FullAPIReferencePage, ExportSectionProps, ExportSection, ExportIndexPageProps, ExportIndexPage, ExportCardProps, ExportCard, ExpandablePropertyProps, ExpandableProperty, ExampleBlockProps, ExampleBlock, EnumSectionProps, EnumSection, EnumPageProps, EnumPage, CollapsibleMethodProps, CollapsibleMethod, CodeTabsProps, CodeTabs, CodeTab, ClassSectionProps, ClassSection, ClassPageProps, ClassPage, APIPageProps, APIPage };