@stainless-api/docs-ui 0.1.0-beta.5 → 0.1.0-beta.51

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.
Files changed (212) hide show
  1. package/dist/breadcrumbs-BdYnaHA8.d.ts +20 -0
  2. package/dist/breadcrumbs-CA7GmW_8.d.ts +20 -0
  3. package/dist/breadcrumbs-nSFZO5Gf.js +63 -0
  4. package/dist/chunk-DRcLgZ1e.js +18 -0
  5. package/dist/component-DRO8kQSp.js +23 -0
  6. package/dist/component-generics-B6Fn47Mz.js +45 -0
  7. package/dist/component-generics-BHFUK06s.d.ts +30 -0
  8. package/dist/component-generics-BJSyydZ-.d.ts +30 -0
  9. package/dist/components/MaskedInput.d.ts +14 -0
  10. package/dist/components/MaskedInput.js +76 -0
  11. package/dist/components/breadcrumbs.d.ts +2 -0
  12. package/dist/components/breadcrumbs.js +9 -0
  13. package/dist/components/icons.d.ts +55 -0
  14. package/dist/components/icons.js +3 -0
  15. package/dist/components/index.d.ts +10 -0
  16. package/dist/components/index.js +18 -0
  17. package/dist/components/method.d.ts +2 -0
  18. package/dist/components/method.js +10 -0
  19. package/dist/components/overview.d.ts +2 -0
  20. package/dist/components/overview.js +11 -0
  21. package/dist/components/primitives.d.ts +2 -0
  22. package/dist/components/primitives.js +8 -0
  23. package/dist/components/properties.d.ts +2 -0
  24. package/dist/components/properties.js +9 -0
  25. package/dist/components/sdk.d.ts +2 -0
  26. package/dist/components/sdk.js +10 -0
  27. package/dist/components/sidebar.d.ts +2 -0
  28. package/dist/components/sidebar.js +11 -0
  29. package/dist/components/snippets.d.ts +3 -0
  30. package/dist/components/snippets.js +9 -0
  31. package/dist/components-D7M-BwNI.js +71 -0
  32. package/dist/contexts/component-generics.d.ts +2 -0
  33. package/dist/contexts/component-generics.js +3 -0
  34. package/dist/contexts/component-types.d.ts +16 -0
  35. package/dist/contexts/component-types.js +0 -0
  36. package/dist/contexts/component.d.ts +29 -0
  37. package/dist/contexts/component.js +27 -0
  38. package/dist/contexts/docs.d.ts +2 -0
  39. package/dist/contexts/docs.js +3 -0
  40. package/dist/contexts/index.d.ts +16 -0
  41. package/dist/contexts/index.js +7 -0
  42. package/dist/contexts/markdown.d.ts +2 -0
  43. package/dist/contexts/markdown.js +4 -0
  44. package/dist/contexts/navigation.d.ts +2 -0
  45. package/dist/contexts/navigation.js +3 -0
  46. package/dist/contexts/use-components.d.ts +14 -0
  47. package/dist/contexts/use-components.js +4 -0
  48. package/dist/contexts-p3rRZDlM.js +39 -0
  49. package/dist/csharp-CDSxfCZE.js +283 -0
  50. package/dist/docs-BUS__I1m.d.ts +47 -0
  51. package/dist/docs-CXqi26jB.js +54 -0
  52. package/dist/docs-fKyo35eI.d.ts +47 -0
  53. package/dist/go-1c3S5ETL.js +303 -0
  54. package/dist/http-2QNWXH9t.js +330 -0
  55. package/dist/icons-Ckod9aod.js +869 -0
  56. package/dist/index-5Yl-BBg3.d.ts +15 -0
  57. package/dist/index-9LRO8R1a.d.ts +274 -0
  58. package/dist/index-CBIJwoyp.d.ts +13 -0
  59. package/dist/index-ClCZKGcw.d.ts +274 -0
  60. package/dist/index-pMKpm2Jk.d.ts +13 -0
  61. package/dist/index-q3bZhNWj.d.ts +15 -0
  62. package/dist/index.d.ts +19 -0
  63. package/dist/index.js +29 -7542
  64. package/dist/java-BbjF_oUI.js +403 -0
  65. package/dist/languages/csharp.d.ts +11 -0
  66. package/dist/languages/csharp.js +9 -0
  67. package/dist/languages/go.d.ts +11 -0
  68. package/dist/languages/go.js +9 -0
  69. package/dist/languages/http.d.ts +11 -0
  70. package/dist/languages/http.js +19 -0
  71. package/dist/languages/index.d.ts +11 -0
  72. package/dist/languages/index.js +26 -0
  73. package/dist/languages/java.d.ts +11 -0
  74. package/dist/languages/java.js +9 -0
  75. package/dist/languages/python.d.ts +11 -0
  76. package/dist/languages/python.js +9 -0
  77. package/dist/languages/ruby.d.ts +11 -0
  78. package/dist/languages/ruby.js +9 -0
  79. package/dist/languages/typescript.d.ts +11 -0
  80. package/dist/languages/typescript.js +9 -0
  81. package/dist/languages-BCYZjzuS.js +26 -0
  82. package/dist/markdown/index.d.ts +12 -0
  83. package/dist/markdown/index.js +104 -0
  84. package/dist/markdown/md.d.ts +15 -0
  85. package/dist/markdown/md.js +3 -0
  86. package/dist/markdown/printer.d.ts +2 -0
  87. package/dist/markdown/printer.js +28 -0
  88. package/dist/markdown/utils.d.ts +3 -0
  89. package/dist/markdown/utils.js +3 -0
  90. package/dist/markdown-C8o8WrwG.d.ts +22 -0
  91. package/dist/markdown-CqJohZei.d.ts +22 -0
  92. package/dist/markdown-CxdeWgjV.js +48 -0
  93. package/dist/md-oM2tUaCA.js +41 -0
  94. package/dist/method-CE08mUME.js +115 -0
  95. package/dist/method-CMt6uyix.d.ts +71 -0
  96. package/dist/method-r5UAB40b.d.ts +71 -0
  97. package/dist/navigation-9_4wRkcT.d.ts +29 -0
  98. package/dist/navigation-C5TN0SgC.js +24 -0
  99. package/dist/navigation-zuoWsXzh.d.ts +29 -0
  100. package/dist/overview-DXmLmmr7.d.ts +39 -0
  101. package/dist/overview-S2hUqPXA.js +139 -0
  102. package/dist/overview-ixhAhHj8.d.ts +39 -0
  103. package/dist/primitives-BIWfwN5L.js +258 -0
  104. package/dist/primitives-BVXfSSiS.d.ts +97 -0
  105. package/dist/primitives-Bl0wzAGo.d.ts +97 -0
  106. package/dist/printer-DBw4S_Jn.d.ts +13 -0
  107. package/dist/printer-bNxiG6UB.js +74 -0
  108. package/dist/properties-C-NU_ghj.d.ts +54 -0
  109. package/dist/properties-GT9ixNTg.d.ts +54 -0
  110. package/dist/properties-jlGW3USi.js +131 -0
  111. package/dist/python-USOwFDv_.js +279 -0
  112. package/dist/routing-CMqh1cTZ.d.ts +54 -0
  113. package/dist/routing-Wbb7YECB.js +194 -0
  114. package/dist/routing.d.ts +2 -0
  115. package/dist/routing.js +3 -180
  116. package/dist/ruby-CSvGbSLe.js +387 -0
  117. package/dist/sdk-B5W3VipN.d.ts +118 -0
  118. package/dist/sdk-CS6A3HW3.d.ts +118 -0
  119. package/dist/sdk-CSCbbn3O.js +336 -0
  120. package/dist/sidebar-C3fZrgmP.d.ts +36 -0
  121. package/dist/sidebar-CWyvCrJ0.js +81 -0
  122. package/dist/sidebar-CbCLUteD.d.ts +36 -0
  123. package/dist/snippets-BQLXEIf6.js +161 -0
  124. package/dist/snippets-C72s2IwS.d.ts +51 -0
  125. package/dist/snippets-DcFph7ir.d.ts +51 -0
  126. package/dist/spec.d.ts +65 -0
  127. package/dist/spec.js +167 -0
  128. package/dist/style-D7RO5ymE.d.ts +168 -0
  129. package/dist/style-gnVEeXFj.js +169 -0
  130. package/dist/style.d.ts +2 -0
  131. package/dist/style.js +3 -0
  132. package/dist/styles/main.css +727 -754
  133. package/dist/styles/main.js +0 -0
  134. package/dist/styles/primitives.css +317 -461
  135. package/dist/styles/primitives.js +0 -0
  136. package/dist/styles/resets.css +32 -41
  137. package/dist/styles/resets.js +0 -0
  138. package/dist/styles/search.css +175 -274
  139. package/dist/styles/search.js +0 -0
  140. package/dist/styles/sidebar.css +59 -60
  141. package/dist/styles/sidebar.js +0 -0
  142. package/dist/styles/variables.css +26 -89
  143. package/dist/styles/variables.js +0 -0
  144. package/dist/styles.css +2910 -0
  145. package/dist/styles.mjs +1 -0
  146. package/dist/typescript-DXG9psK3.js +449 -0
  147. package/dist/use-components-RWQbviGq.js +7 -0
  148. package/dist/utils-CqnL9Fc3.js +31 -0
  149. package/dist/utils-DGnJ6mcU.d.ts +21 -0
  150. package/dist/utils-D_1AWSRX.js +32 -0
  151. package/dist/utils-d8paVwKN.d.ts +14 -0
  152. package/dist/utils-uQbtk0-_.d.ts +21 -0
  153. package/dist/utils.d.ts +2 -0
  154. package/dist/utils.js +3 -0
  155. package/package.json +73 -21
  156. package/dist/mcp.js +0 -16003
  157. package/dist/styles/snippets.css +0 -132
  158. package/src/components/breadcrumbs.tsx +0 -94
  159. package/src/components/chat.tsx +0 -154
  160. package/src/components/dropdown.tsx +0 -91
  161. package/src/components/icons.tsx +0 -584
  162. package/src/components/index.ts +0 -9
  163. package/src/components/method.tsx +0 -144
  164. package/src/components/overview.tsx +0 -159
  165. package/src/components/primitives.tsx +0 -284
  166. package/src/components/properties.tsx +0 -130
  167. package/src/components/scripts/dropdown.ts +0 -78
  168. package/src/components/sdk.tsx +0 -402
  169. package/src/components/sidebar.tsx +0 -99
  170. package/src/components/snippets.tsx +0 -179
  171. package/src/contexts/component-generics.tsx +0 -48
  172. package/src/contexts/component-types.tsx +0 -5
  173. package/src/contexts/component.tsx +0 -32
  174. package/src/contexts/docs.tsx +0 -75
  175. package/src/contexts/index.tsx +0 -17
  176. package/src/contexts/markdown.tsx +0 -43
  177. package/src/contexts/navigation.tsx +0 -44
  178. package/src/contexts/search.tsx +0 -28
  179. package/src/contexts/use-components.tsx +0 -4
  180. package/src/index.ts +0 -6
  181. package/src/languages/go.tsx +0 -281
  182. package/src/languages/http.tsx +0 -321
  183. package/src/languages/index.ts +0 -26
  184. package/src/languages/java.tsx +0 -358
  185. package/src/languages/python.tsx +0 -255
  186. package/src/languages/ruby.tsx +0 -320
  187. package/src/languages/typescript.tsx +0 -393
  188. package/src/markdown/index.ts +0 -107
  189. package/src/markdown/md.ts +0 -45
  190. package/src/markdown/utils.ts +0 -49
  191. package/src/routing.ts +0 -238
  192. package/src/search/form.tsx +0 -127
  193. package/src/search/index.tsx +0 -1
  194. package/src/search/indexer.ts +0 -246
  195. package/src/search/mcp.ts +0 -61
  196. package/src/search/printer.tsx +0 -86
  197. package/src/search/providers/algolia.ts +0 -88
  198. package/src/search/providers/fuse.ts +0 -19
  199. package/src/search/providers/pagefind.ts +0 -17
  200. package/src/search/providers/walker.ts +0 -30
  201. package/src/search/results.tsx +0 -181
  202. package/src/search/state.ts +0 -64
  203. package/src/search/types.ts +0 -116
  204. package/src/style.ts +0 -197
  205. package/src/styles/main.css +0 -993
  206. package/src/styles/primitives.css +0 -573
  207. package/src/styles/resets.css +0 -47
  208. package/src/styles/search.css +0 -342
  209. package/src/styles/sidebar.css +0 -87
  210. package/src/styles/snippets.css +0 -132
  211. package/src/styles/variables.css +0 -90
  212. package/src/utils.ts +0 -41
@@ -1,144 +0,0 @@
1
- import * as React from 'react';
2
- import type { ReactNode } from 'react';
3
- import { useComponents } from '../contexts/use-components';
4
- import { X, ArrowDownLeft, ArrowUpRight, LucideIcon } from 'lucide-react';
5
- import style from '../style';
6
- import clsx from 'clsx';
7
- import { PropertyToggle } from './properties';
8
-
9
- export const HttpMethods = ['get', 'head', 'put', 'delete', 'post', 'patch'];
10
- export type HTTPMethod = (typeof HttpMethods)[number];
11
-
12
- export const HttpMethodIcons: Record<HTTPMethod, LucideIcon> = {
13
- get: ArrowDownLeft,
14
- put: ArrowUpRight,
15
- post: ArrowUpRight,
16
- patch: ArrowUpRight,
17
- delete: X,
18
- };
19
-
20
- export type MethodIconProps = {
21
- httpMethod: string;
22
- showName?: boolean;
23
- };
24
-
25
- export function MethodIconBadge({ httpMethod, showName }: MethodIconProps) {
26
- if (!HttpMethods.includes(httpMethod)) return null;
27
-
28
- return (
29
- <span
30
- className={clsx(style.MethodRouteHttpMethod, style.MethodRouteHttpMethodIconOnly)}
31
- data-method={httpMethod}
32
- >
33
- {React.createElement(HttpMethodIcons[httpMethod], {
34
- size: 14,
35
- strokeWidth: 3,
36
- className: style.Icon,
37
- })}
38
- {showName && httpMethod}
39
- </span>
40
- );
41
- }
42
-
43
- export type MethodHeaderProps = {
44
- title: ReactNode;
45
- signature?: ReactNode;
46
- badges?: ReactNode;
47
- children?: ReactNode;
48
- };
49
-
50
- export function MethodHeader({ title, badges, signature, children }: MethodHeaderProps) {
51
- return (
52
- <div className={style.MethodHeader}>
53
- <h5 className={style.MethodTitle}>{title}</h5>
54
- {badges && <div className={style.MethodBadges}>{badges}</div>}
55
- {signature}
56
- {children}
57
- </div>
58
- );
59
- }
60
-
61
- export type MethodRouteProps = {
62
- httpMethod?: string;
63
- endpoint?: string | ReactNode;
64
- iconOnly?: boolean;
65
- };
66
-
67
- export function MethodRoute({ httpMethod, endpoint, iconOnly }: MethodRouteProps) {
68
- return (
69
- <div className={style.MethodRoute}>
70
- <MethodIconBadge httpMethod={httpMethod} showName={!iconOnly} />
71
- {endpoint && <span className={style.MethodRouteEndpoint}>{endpoint}</span>}
72
- </div>
73
- );
74
- }
75
-
76
- export type MethodDescriptionProps = {
77
- description?: string;
78
- };
79
-
80
- export function MethodDescription({ description }: MethodDescriptionProps) {
81
- const { Markdown } = useComponents();
82
-
83
- if (description)
84
- return (
85
- <div className={style.MethodDescription}>
86
- <Markdown content={description} />
87
- </div>
88
- );
89
- }
90
-
91
- export type MethodInfoProps = {
92
- children?: ReactNode;
93
- parameters?: ReactNode;
94
- returns?: ReactNode;
95
- };
96
-
97
- export function MethodInfo({ children, parameters, returns }: MethodInfoProps) {
98
- return (
99
- <div className={style.MethodInfo}>
100
- {children && <div className={style.MethodContent}>{children}</div>}
101
-
102
- {parameters && (
103
- <div className={style.MethodInfoSection}>
104
- <h5>
105
- Parameters
106
- <PropertyToggle target="parameters" />
107
- </h5>
108
- <div className={style.MethodParameters} data-stldocs-property-group="parameters">
109
- {parameters}
110
- </div>
111
- </div>
112
- )}
113
-
114
- {returns && (
115
- <div className={style.MethodInfoSection}>
116
- <h5>
117
- Returns
118
- <PropertyToggle target="returns" />
119
- </h5>
120
- <div className={style.MethodReturns} data-stldocs-property-group="returns">
121
- {returns}
122
- </div>
123
- </div>
124
- )}
125
- </div>
126
- );
127
- }
128
-
129
- export type MethodProps = {
130
- id?: string;
131
- header?: ReactNode;
132
- children?: ReactNode;
133
- } & React.HTMLProps<HTMLDivElement>;
134
-
135
- export function Method({ id, header, children, className, ...props }: MethodProps) {
136
- const Docs = useComponents();
137
-
138
- return (
139
- <div id={id} className={clsx(style.Method, className)} tabIndex={0} {...props}>
140
- {header}
141
- <div className={style.MethodBody}>{children}</div>
142
- </div>
143
- );
144
- }
@@ -1,159 +0,0 @@
1
- import * as React from 'react';
2
- import { ChevronRight } from 'lucide-react';
3
- import type * as SDKJSON from '~/lib/json-spec-v2/types';
4
-
5
- import { flatResources, getResourceFromSpec } from '../utils';
6
- import { useDeclaration, useLanguage, useLanguageComponents, useSpec } from '../contexts';
7
- import { useComponents } from '../contexts/use-components';
8
-
9
- import style from '../style';
10
- import { PropertyToggle } from './properties';
11
- import { Markdown } from './primitives';
12
- import { parseStainlessPath } from '../routing';
13
-
14
- export type SDKResourceProps = {
15
- resource: SDKJSON.Resource;
16
- parents?: SDKJSON.Resource[];
17
- };
18
-
19
- export function SDKResourceHeader({ resource, parents }: SDKResourceProps) {
20
- // const language = useLanguage();
21
-
22
- const segments = parents?.map((parent, index) => (
23
- <span className={style.ResourceTitleSegment} key={parent.stainlessPath}>
24
- {parent.title}
25
- {index < parents.length && <ChevronRight size={16} className={style.Icon} />}
26
- </span>
27
- ));
28
-
29
- if (!segments && !resource.description) {
30
- return null;
31
- }
32
-
33
- return (
34
- <div className={style.ResourceHeader}>
35
- {segments && (
36
- <h4 id={resource.stainlessPath} className={style.ResourceTitle}>
37
- {segments}
38
- <span className={style.ResourceTitleSegment}>{resource.title}</span>
39
- </h4>
40
- )}
41
- {resource.description && (
42
- <div className={style.ResourceDescription}>
43
- <Markdown content={resource.description} />
44
- </div>
45
- )}
46
- </div>
47
- );
48
- }
49
-
50
- export type SDKMethodSummaryProps = {
51
- method: SDKJSON.Method;
52
- };
53
-
54
- export function SDKMethodSummary({ method }: SDKMethodSummaryProps) {
55
- const Docs = useComponents();
56
- const Lang = useLanguageComponents();
57
- const decl = useDeclaration(method.stainlessPath);
58
-
59
- return (
60
- <Docs.MethodHeader
61
- title={<Docs.Link stainlessPath={method.stainlessPath}>{method.summary ?? method.title}</Docs.Link>}
62
- signature={<Lang.MethodSignature decl={decl} />}
63
- badges={method.deprecated && <Docs.Badge id="deprecated">Deprecated</Docs.Badge>}
64
- >
65
- <Docs.MethodRoute httpMethod={method.httpMethod} endpoint={method.endpoint.split(' ', 2).at(-1)} />
66
- {/* Removing temporarily per design review */}
67
- {/* <Docs.MethodDescription description={method.description} /> */}
68
- </Docs.MethodHeader>
69
- );
70
- }
71
-
72
- export function SDKResource({ resource, parents, showModels }: SDKResourceProps & { showModels?: boolean }) {
73
- const Docs = useComponents();
74
- const language = useLanguage();
75
- const spec = useSpec();
76
-
77
- const methods = Object.values(resource.methods).filter(
78
- (method) => spec.decls?.[language]?.[method.stainlessPath],
79
- );
80
-
81
- const models = Object.values(resource.models).filter(
82
- (model) => spec.decls?.[language]?.[`${model.stainlessPath} > (schema)`],
83
- );
84
-
85
- return (
86
- <div className={style.Resource}>
87
- <div className={style.ResourceContent}>
88
- <Docs.SDKResourceHeader resource={resource} parents={parents} />
89
- {methods.length > 0 && (
90
- <div className={style.ResourceContentGroup}>
91
- {methods
92
- .toSorted((first, second) => first.name.localeCompare(second.name))
93
- .map((method) => (
94
- <div className={style.MethodSummary} key={method.stainlessPath}>
95
- <Docs.SDKMethodSummary method={method} />
96
- </div>
97
- ))}
98
- </div>
99
- )}
100
-
101
- {showModels !== false && models.length > 0 && (
102
- <div className={style.ResourceContentGroup} data-stldocs-property-group="models">
103
- <h5 className={style.ResourceContentGroupModelTitle}>
104
- Models
105
- <PropertyToggle target="models" />
106
- </h5>
107
- {models.map((model) => (
108
- <Docs.SDKModel model={model} key={model.stainlessPath} />
109
- ))}
110
- </div>
111
- )}
112
- </div>
113
- </div>
114
- );
115
- }
116
-
117
- export type SDKOverviewProps = {
118
- resource: SDKJSON.Resource;
119
- };
120
-
121
- export function SDKOverview({ resource }: SDKOverviewProps) {
122
- const { SDKResource } = useComponents();
123
-
124
- const nested = React.useMemo(() => flatResources(resource.subresources, [resource]), [resource]);
125
-
126
- return (
127
- <div className={style.Overview}>
128
- <div className={style.OverviewHeader}>
129
- <h1>{resource.title}</h1>
130
- </div>
131
- <SDKResource resource={resource} />
132
- {nested.map((props, index) => (
133
- <SDKResource {...props} key={index} />
134
- ))}
135
- </div>
136
- );
137
- }
138
-
139
- export type SDKRootProps = {
140
- stainlessPath: string;
141
- };
142
-
143
- export function SDKRoot({ stainlessPath }: SDKRootProps) {
144
- const spec = useSpec();
145
- const Docs = useComponents();
146
-
147
- const parsed = parseStainlessPath(stainlessPath);
148
- const resource = getResourceFromSpec(stainlessPath, spec);
149
-
150
- if (!resource || !parsed) return null;
151
-
152
- const content = parsed.method ? (
153
- <Docs.SDKMethod method={resource.methods[parsed.method]} />
154
- ) : (
155
- <Docs.SDKOverview resource={resource} />
156
- );
157
-
158
- return <div className={style.Root}>{content}</div>;
159
- }
@@ -1,284 +0,0 @@
1
- import * as React from 'react';
2
- import { ReactNode, Fragment, useState } from 'react';
3
- import { useLanguage, useRenderMarkdown, useNavigation, useSettings } from '../contexts';
4
- import { generateRoute } from '../routing';
5
- import style from '../style';
6
- import { MinusIcon, PlusIcon } from 'lucide-react';
7
-
8
- type JoinProps = { items: ReactNode[]; limit?: number; children: ReactNode };
9
-
10
- export function Join({ items, limit, children }: JoinProps) {
11
- const arr =
12
- limit && items.length > limit + 1
13
- ? [...items.slice(0, limit), <span className={style.Truncation}>{items.length - limit} more</span>]
14
- : items;
15
-
16
- return arr.map((item, index) => (
17
- <Fragment key={`iterator:${index}`}>
18
- {!!index && children}
19
- {item}
20
- </Fragment>
21
- ));
22
- }
23
-
24
- type ExpanderProps = {
25
- id?: string;
26
- open?: boolean;
27
- summary: ReactNode;
28
- virtual?: boolean;
29
- muted?: boolean;
30
- children?: ReactNode;
31
- };
32
-
33
- export function Expander({ id, open, summary, virtual, muted, children }: ExpanderProps) {
34
- const { virtualExpanders } = useSettings();
35
-
36
- if (virtual || virtualExpanders)
37
- return (
38
- <VirtualExpander summary={summary} open={open} muted={muted} id={id}>
39
- {children}
40
- </VirtualExpander>
41
- );
42
-
43
- return (
44
- <details
45
- className={style.Expander}
46
- open={open}
47
- data-stldocs-expander-muted={muted}
48
- data-stldocs-expander-initial-state={open}
49
- >
50
- <summary className={style.ExpanderSummary}>
51
- <div className={style.ExpanderSummaryIcon}>
52
- <PlusIcon size={16} strokeWidth={1} className={style.Icon} />
53
- <MinusIcon size={16} strokeWidth={1} className={style.Icon} />
54
- </div>
55
- <div className={style.ExpanderSummaryContent}>{summary}</div>
56
- </summary>
57
- <div className={style.ExpanderContent} id={id}>
58
- {children}
59
- </div>
60
- </details>
61
- );
62
- }
63
-
64
- export function VirtualExpander({
65
- id,
66
- open: isOpen,
67
- muted,
68
- summary,
69
- children,
70
- }: Omit<ExpanderProps, 'virtual'>) {
71
- const [open, setOpen] = useState(isOpen);
72
-
73
- React.useEffect(() => {
74
- if (isOpen) setOpen(true);
75
- }, [isOpen]);
76
-
77
- return (
78
- <div
79
- className={style.Expander}
80
- data-open={open}
81
- data-stldocs-expander-muted={muted}
82
- data-stldocs-expander-initial-state={open}
83
- >
84
- <div className={style.ExpanderSummary} onClick={() => setOpen(!open)}>
85
- <div className={style.ExpanderSummaryIcon}>
86
- <PlusIcon size={16} className={style.Icon} />
87
- <MinusIcon size={16} className={style.Icon} />
88
- </div>
89
- <div className={style.ExpanderSummaryContent}>{summary}</div>
90
- </div>
91
- {open && (
92
- <div className={style.ExpanderContent} id={id}>
93
- {children}
94
- </div>
95
- )}
96
- </div>
97
- );
98
- }
99
-
100
- export function Markdown({ content }: { content: string }) {
101
- const rendered = useRenderMarkdown(content);
102
-
103
- return (
104
- rendered && (
105
- <div className={`${style.Markdown} ${style.Content}`} dangerouslySetInnerHTML={{ __html: rendered }} />
106
- )
107
- );
108
- }
109
-
110
- type BadgeProps = {
111
- id: string;
112
- children?: ReactNode;
113
- };
114
-
115
- export function Badge({ id, children }: BadgeProps) {
116
- return (
117
- <span className={style.Badge} data-badge-id={id}>
118
- {children ?? id}
119
- </span>
120
- );
121
- }
122
-
123
- const TooltipNestingContext = React.createContext<boolean>(false);
124
-
125
- type TooltipProps = {
126
- content: ReactNode;
127
- children: ReactNode;
128
- };
129
-
130
- export function Tooltip({ content, children }: TooltipProps) {
131
- const nested = React.useContext(TooltipNestingContext);
132
-
133
- if (nested) return children;
134
-
135
- return (
136
- <span className={style.Tooltip}>
137
- <span className={style.TooltipContent}>
138
- <TooltipNestingContext.Provider value={true}>{content}</TooltipNestingContext.Provider>
139
- </span>
140
- <span className={style.TooltipHost}>{children}</span>
141
- </span>
142
- );
143
- }
144
-
145
- type LinkProps = {
146
- stainlessPath: string;
147
- scroll?: boolean;
148
- children?: ReactNode;
149
- } & React.HTMLProps<HTMLAnchorElement>;
150
-
151
- export function Link({ stainlessPath, scroll = true, children, ...props }: LinkProps) {
152
- const { basePath, onNavigate } = useNavigation();
153
- const language = useLanguage();
154
-
155
- const href = React.useMemo(() => {
156
- if (props.href) return props.href;
157
- if (stainlessPath) return generateRoute(basePath, language, stainlessPath);
158
- }, [basePath, language, stainlessPath]);
159
-
160
- const handleClick = React.useCallback(
161
- (e: React.MouseEvent<HTMLAnchorElement>) => {
162
- if (props.onClick) props.onClick(e);
163
- if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
164
- if (href) onNavigate?.(e, { href, language, stainlessPath, scroll });
165
- },
166
- [href, scroll, onNavigate],
167
- );
168
-
169
- if (!href) return children;
170
-
171
- return (
172
- <a href={href} onClick={handleClick} {...props}>
173
- {children}
174
- </a>
175
- );
176
- }
177
-
178
- export type InputProps = {
179
- left?: ReactNode;
180
- right?: ReactNode;
181
- } & React.InputHTMLAttributes<HTMLInputElement>;
182
-
183
- export const Input = React.forwardRef<HTMLInputElement, InputProps>(({ left, right, ...props }, ref) => {
184
- return (
185
- <div className={style.Input}>
186
- {left}
187
- <input {...props} ref={ref} className={style.InputTextField} />
188
- {right}
189
- </div>
190
- );
191
- });
192
-
193
- export type ToggleButtonProps = {
194
- children?: ReactNode;
195
- selected?: boolean;
196
- } & React.ButtonHTMLAttributes<HTMLButtonElement>;
197
-
198
- export const ToggleButton = React.forwardRef<HTMLButtonElement, ToggleButtonProps>(
199
- ({ children, selected, ...props }, ref) => {
200
- return (
201
- <button {...props} ref={ref} className={style.ToggleButton} data-stldocs-toggle-selected={selected}>
202
- {children}
203
- </button>
204
- );
205
- },
206
- );
207
-
208
- export type ListViewProps<TItem> = {
209
- items: Array<TItem>;
210
- itemDelegate: (item: TItem, selected: boolean) => React.ReactNode;
211
- onSelectListItem?: (item: TItem) => void;
212
- } & React.HTMLAttributes<HTMLDivElement>;
213
-
214
- export function ListView<TItem>({ items, itemDelegate, onSelectListItem, ...rest }: ListViewProps<TItem>) {
215
- const [selectedIndex, setSelectedIndex] = React.useState<number>(0);
216
- const [keyboardIndex, setKeyboardIndex] = React.useState<number>(0);
217
- const listRef = React.useRef<HTMLDivElement>(null);
218
- const itemRef = React.useRef<HTMLDivElement>(null);
219
-
220
- React.useEffect(() => {
221
- setSelectedIndex(0);
222
- setKeyboardIndex(0);
223
- }, [items]);
224
-
225
- React.useEffect(() => {
226
- function handleKeyPress(ev: KeyboardEvent) {
227
- switch (ev.key) {
228
- case 'ArrowUp': {
229
- ev.preventDefault();
230
- const value = Math.max(0, selectedIndex - 1);
231
- setSelectedIndex(value);
232
- setKeyboardIndex(value);
233
- break;
234
- }
235
-
236
- case 'ArrowDown': {
237
- ev.preventDefault();
238
- const value = Math.min(items.length, selectedIndex + 1);
239
- setSelectedIndex(value);
240
- setKeyboardIndex(value);
241
- break;
242
- }
243
-
244
- case 'Enter':
245
- ev.preventDefault();
246
- onSelectListItem?.(items[selectedIndex]);
247
- break;
248
- }
249
- }
250
-
251
- addEventListener('keydown', handleKeyPress);
252
- return () => removeEventListener('keydown', handleKeyPress);
253
- }, [items, selectedIndex]);
254
-
255
- React.useEffect(() => {
256
- if (!keyboardIndex) {
257
- listRef?.current?.scroll(0, 0);
258
- return;
259
- }
260
-
261
- const selectedBounds = itemRef.current.getBoundingClientRect();
262
- const listBounds = listRef.current.getBoundingClientRect();
263
- const needsScroll = selectedBounds.top < listBounds.top || selectedBounds.bottom > listBounds.bottom;
264
-
265
- if (needsScroll) itemRef.current.scrollIntoView({ block: 'nearest' });
266
- }, [keyboardIndex, items, listRef]);
267
-
268
- return (
269
- <div ref={listRef} className={style.ListView} tabIndex={0} {...rest}>
270
- {items.map((item, index) => (
271
- <div
272
- key={index}
273
- ref={index === selectedIndex ? itemRef : null}
274
- className={style.ListViewItem}
275
- data-stldocs-listview-selected={index === selectedIndex}
276
- onClick={() => onSelectListItem?.(items[selectedIndex])}
277
- onMouseMove={() => setSelectedIndex(index)}
278
- >
279
- {itemDelegate(item, index === selectedIndex)}
280
- </div>
281
- ))}
282
- </div>
283
- );
284
- }