@stainless-api/docs-ui 0.1.0-beta.7 → 0.1.0-beta.70

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 (215) hide show
  1. package/dist/breadcrumbs-BhYwbXkc.d.ts +25 -0
  2. package/dist/breadcrumbs-Cvm5Ifm7.d.ts +25 -0
  3. package/dist/breadcrumbs-DA4WgDhR.js +63 -0
  4. package/dist/chunk-BN_g-Awi.js +18 -0
  5. package/dist/cli-F3kMmeoJ.js +166 -0
  6. package/dist/component-P9sn5yyG.js +23 -0
  7. package/dist/component-generics-ByGsYTc8.d.ts +30 -0
  8. package/dist/component-generics-POFirVVb.js +45 -0
  9. package/dist/component-generics-zU0Pqx8m.d.ts +30 -0
  10. package/dist/components/MaskedInput.d.ts +14 -0
  11. package/dist/components/MaskedInput.js +76 -0
  12. package/dist/components/breadcrumbs.d.ts +2 -0
  13. package/dist/components/breadcrumbs.js +9 -0
  14. package/dist/components/icons.d.ts +60 -0
  15. package/dist/components/icons.js +3 -0
  16. package/dist/components/index.d.ts +11 -0
  17. package/dist/components/index.js +19 -0
  18. package/dist/components/method.d.ts +2 -0
  19. package/dist/components/method.js +10 -0
  20. package/dist/components/overview.d.ts +2 -0
  21. package/dist/components/overview.js +11 -0
  22. package/dist/components/primitives.d.ts +2 -0
  23. package/dist/components/primitives.js +8 -0
  24. package/dist/components/properties.d.ts +2 -0
  25. package/dist/components/properties.js +9 -0
  26. package/dist/components/sdk-sidebar.d.ts +2 -0
  27. package/dist/components/sdk-sidebar.js +10 -0
  28. package/dist/components/sdk.d.ts +2 -0
  29. package/dist/components/sdk.js +10 -0
  30. package/dist/components/snippets.d.ts +3 -0
  31. package/dist/components/snippets.js +9 -0
  32. package/dist/components/stl-sidebar.d.ts +2 -0
  33. package/dist/components/stl-sidebar.js +5 -0
  34. package/dist/components-w1JmIrB0.js +71 -0
  35. package/dist/contexts/component-generics.d.ts +2 -0
  36. package/dist/contexts/component-generics.js +3 -0
  37. package/dist/contexts/component-types.d.ts +17 -0
  38. package/dist/contexts/component-types.js +0 -0
  39. package/dist/contexts/component.d.ts +30 -0
  40. package/dist/contexts/component.js +30 -0
  41. package/dist/contexts/docs.d.ts +2 -0
  42. package/dist/contexts/docs.js +3 -0
  43. package/dist/contexts/index.d.ts +23 -0
  44. package/dist/contexts/index.js +7 -0
  45. package/dist/contexts/markdown.d.ts +2 -0
  46. package/dist/contexts/markdown.js +4 -0
  47. package/dist/contexts/navigation.d.ts +2 -0
  48. package/dist/contexts/navigation.js +3 -0
  49. package/dist/contexts/use-components.d.ts +15 -0
  50. package/dist/contexts/use-components.js +4 -0
  51. package/dist/contexts-CVj20VV4.js +41 -0
  52. package/dist/csharp-D6_jlynY.js +283 -0
  53. package/dist/docs-BmOB2f-I.js +61 -0
  54. package/dist/docs-g4IPmtZr.d.ts +48 -0
  55. package/dist/docs-z3fl2eW-.d.ts +48 -0
  56. package/dist/go-COaHV3Hc.js +303 -0
  57. package/dist/http-fOPCX17A.js +389 -0
  58. package/dist/icons-BYKn5X8E.js +885 -0
  59. package/dist/index-B8Zys1C2.d.ts +347 -0
  60. package/dist/index-C5Zmb2CI.d.ts +16 -0
  61. package/dist/index-CwjGm9zX.d.ts +1722 -0
  62. package/dist/index-D7PkxNgB.d.ts +16 -0
  63. package/dist/index-DIaM6Ync.d.ts +347 -0
  64. package/dist/index.d.ts +20 -0
  65. package/dist/index.js +32 -7542
  66. package/dist/java-CxGSJVvv.js +403 -0
  67. package/dist/languages/cli.d.ts +12 -0
  68. package/dist/languages/cli.js +21 -0
  69. package/dist/languages/csharp.d.ts +12 -0
  70. package/dist/languages/csharp.js +9 -0
  71. package/dist/languages/go.d.ts +12 -0
  72. package/dist/languages/go.js +9 -0
  73. package/dist/languages/http.d.ts +12 -0
  74. package/dist/languages/http.js +20 -0
  75. package/dist/languages/index.d.ts +12 -0
  76. package/dist/languages/index.js +29 -0
  77. package/dist/languages/java.d.ts +12 -0
  78. package/dist/languages/java.js +9 -0
  79. package/dist/languages/python.d.ts +12 -0
  80. package/dist/languages/python.js +9 -0
  81. package/dist/languages/ruby.d.ts +12 -0
  82. package/dist/languages/ruby.js +9 -0
  83. package/dist/languages/terraform.d.ts +12 -0
  84. package/dist/languages/terraform.js +9 -0
  85. package/dist/languages/typescript.d.ts +12 -0
  86. package/dist/languages/typescript.js +9 -0
  87. package/dist/languages-B6eap2M6.js +30 -0
  88. package/dist/markdown/index.d.ts +12 -0
  89. package/dist/markdown/index.js +107 -0
  90. package/dist/markdown/md.d.ts +15 -0
  91. package/dist/markdown/md.js +41 -0
  92. package/dist/markdown/printer.d.ts +13 -0
  93. package/dist/markdown/printer.js +100 -0
  94. package/dist/markdown/utils.d.ts +21 -0
  95. package/dist/markdown/utils.js +31 -0
  96. package/dist/markdown-CTKHMLVr.js +49 -0
  97. package/dist/markdown-Cdh0TSHp.d.ts +22 -0
  98. package/dist/markdown-Cibv9fDR.d.ts +22 -0
  99. package/dist/method-630cPKDl.d.ts +59 -0
  100. package/dist/method-BPDUyBlD.js +96 -0
  101. package/dist/method-BzkPRXGL.d.ts +59 -0
  102. package/dist/navigation-BW-SBvb4.d.ts +29 -0
  103. package/dist/navigation-DWYqC_HX.d.ts +29 -0
  104. package/dist/navigation-aoYZ_tl4.js +24 -0
  105. package/dist/overview-Cui1XtuC.d.ts +39 -0
  106. package/dist/overview-DFwfIK6k.js +138 -0
  107. package/dist/overview-RXc9iPzz.d.ts +39 -0
  108. package/dist/primitives-DJEqe_r1.js +250 -0
  109. package/dist/primitives-DhGxFYx6.d.ts +105 -0
  110. package/dist/primitives-MsH-h0bU.d.ts +105 -0
  111. package/dist/properties-BnbBKd5a.js +132 -0
  112. package/dist/properties-Bynmj9_H.d.ts +54 -0
  113. package/dist/properties-C9W4QJ_F.d.ts +54 -0
  114. package/dist/python-DsTuWCKE.js +269 -0
  115. package/dist/routing-C64k4fmX.js +205 -0
  116. package/dist/routing-Cm_9XJiQ.d.ts +61 -0
  117. package/dist/routing-utiR5mY3.d.ts +61 -0
  118. package/dist/routing.d.ts +2 -0
  119. package/dist/routing.js +3 -180
  120. package/dist/ruby-BncKp6hd.js +387 -0
  121. package/dist/sdk-BvZeXpsj.d.ts +122 -0
  122. package/dist/sdk-Bw99eXxA.js +399 -0
  123. package/dist/sdk-GMOw94wL.d.ts +122 -0
  124. package/dist/sdk-sidebar-NCBSWuUW.d.ts +15 -0
  125. package/dist/sdk-sidebar-VNY2-O1Y.d.ts +15 -0
  126. package/dist/sdk-sidebar-V_MTkVw8.js +50 -0
  127. package/dist/snippets-BehbU3rt.js +164 -0
  128. package/dist/snippets-Bj7Ey56K.d.ts +53 -0
  129. package/dist/snippets-CQQSDvg2.d.ts +53 -0
  130. package/dist/spec.d.ts +65 -0
  131. package/dist/spec.js +167 -0
  132. package/dist/stl-sidebar-CXzs_shz.d.ts +58 -0
  133. package/dist/stl-sidebar-DSkUHwcU.d.ts +58 -0
  134. package/dist/stl-sidebar-WtimNrk1.js +106 -0
  135. package/dist/style-HpXpcJ9v.js +172 -0
  136. package/dist/style.d.ts +171 -0
  137. package/dist/style.js +3 -0
  138. package/dist/styles/main.css +744 -754
  139. package/dist/styles/main.js +0 -0
  140. package/dist/styles/primitives.css +327 -458
  141. package/dist/styles/primitives.js +0 -0
  142. package/dist/styles/resets.css +32 -41
  143. package/dist/styles/resets.js +0 -0
  144. package/dist/styles/search.css +192 -270
  145. package/dist/styles/search.js +0 -0
  146. package/dist/styles/sidebar.css +170 -69
  147. package/dist/styles/sidebar.js +0 -0
  148. package/dist/styles/variables.css +26 -89
  149. package/dist/styles/variables.js +0 -0
  150. package/dist/styles.css +3273 -0
  151. package/dist/styles.mjs +1 -0
  152. package/dist/terraform-B95X4rNK.js +243 -0
  153. package/dist/typescript-n46M9OtL.js +449 -0
  154. package/dist/use-components-BUz3GbO4.js +7 -0
  155. package/dist/utils-DPbkW1Tz.js +54 -0
  156. package/dist/utils.d.ts +20 -0
  157. package/dist/utils.js +3 -0
  158. package/package.json +74 -22
  159. package/dist/mcp.js +0 -16003
  160. package/dist/styles/snippets.css +0 -132
  161. package/src/components/breadcrumbs.tsx +0 -94
  162. package/src/components/chat.tsx +0 -154
  163. package/src/components/dropdown.tsx +0 -91
  164. package/src/components/icons.tsx +0 -584
  165. package/src/components/index.ts +0 -9
  166. package/src/components/method.tsx +0 -144
  167. package/src/components/overview.tsx +0 -159
  168. package/src/components/primitives.tsx +0 -284
  169. package/src/components/properties.tsx +0 -130
  170. package/src/components/scripts/dropdown.ts +0 -78
  171. package/src/components/sdk.tsx +0 -402
  172. package/src/components/sidebar.tsx +0 -99
  173. package/src/components/snippets.tsx +0 -179
  174. package/src/contexts/component-generics.tsx +0 -48
  175. package/src/contexts/component-types.tsx +0 -5
  176. package/src/contexts/component.tsx +0 -32
  177. package/src/contexts/docs.tsx +0 -75
  178. package/src/contexts/index.tsx +0 -17
  179. package/src/contexts/markdown.tsx +0 -43
  180. package/src/contexts/navigation.tsx +0 -44
  181. package/src/contexts/search.tsx +0 -28
  182. package/src/contexts/use-components.tsx +0 -4
  183. package/src/index.ts +0 -6
  184. package/src/languages/go.tsx +0 -281
  185. package/src/languages/http.tsx +0 -321
  186. package/src/languages/index.ts +0 -26
  187. package/src/languages/java.tsx +0 -358
  188. package/src/languages/python.tsx +0 -255
  189. package/src/languages/ruby.tsx +0 -320
  190. package/src/languages/typescript.tsx +0 -393
  191. package/src/markdown/index.ts +0 -107
  192. package/src/markdown/md.ts +0 -45
  193. package/src/markdown/utils.ts +0 -49
  194. package/src/routing.ts +0 -238
  195. package/src/search/form.tsx +0 -127
  196. package/src/search/index.tsx +0 -1
  197. package/src/search/indexer.ts +0 -246
  198. package/src/search/mcp.ts +0 -61
  199. package/src/search/printer.tsx +0 -86
  200. package/src/search/providers/algolia.ts +0 -88
  201. package/src/search/providers/fuse.ts +0 -19
  202. package/src/search/providers/pagefind.ts +0 -17
  203. package/src/search/providers/walker.ts +0 -30
  204. package/src/search/results.tsx +0 -181
  205. package/src/search/state.ts +0 -64
  206. package/src/search/types.ts +0 -116
  207. package/src/style.ts +0 -197
  208. package/src/styles/main.css +0 -993
  209. package/src/styles/primitives.css +0 -572
  210. package/src/styles/resets.css +0 -47
  211. package/src/styles/search.css +0 -342
  212. package/src/styles/sidebar.css +0 -87
  213. package/src/styles/snippets.css +0 -132
  214. package/src/styles/variables.css +0 -90
  215. 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
- }