@stainless-api/docs-ui 0.1.0-beta.29 → 0.1.0-beta.30

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 (194) hide show
  1. package/dist/{breadcrumbs-D5viAm7a.d.ts → breadcrumbs-wJ7A9MGt.d.ts} +2 -2
  2. package/dist/{component-generics-BnrVqdQj.d.ts → component-generics--y1IC_M-.d.ts} +2 -1
  3. package/dist/{component-generics-Df4EDvxk.js → component-generics-D3ybuN5r.js} +5 -1
  4. package/dist/components/breadcrumbs.d.ts +1 -1
  5. package/dist/components/breadcrumbs.js +13 -14
  6. package/dist/components/chat.d.ts +3 -3
  7. package/dist/components/chat.js +64 -50
  8. package/dist/components/icons.d.ts +10 -10
  9. package/dist/components/icons.js +1 -1
  10. package/dist/components/index.d.ts +11 -12
  11. package/dist/components/index.js +14 -15
  12. package/dist/components/method.d.ts +1 -1
  13. package/dist/components/method.js +13 -14
  14. package/dist/components/overview.d.ts +1 -1
  15. package/dist/components/overview.js +13 -14
  16. package/dist/components/primitives.d.ts +1 -1
  17. package/dist/components/primitives.js +13 -14
  18. package/dist/components/properties.d.ts +1 -1
  19. package/dist/components/properties.js +13 -14
  20. package/dist/components/sdk.d.ts +2 -2
  21. package/dist/components/sdk.js +13 -14
  22. package/dist/components/sidebar.d.ts +1 -1
  23. package/dist/components/sidebar.js +13 -14
  24. package/dist/components/snippets.d.ts +3 -3
  25. package/dist/components/snippets.js +13 -14
  26. package/dist/contexts/component-generics.d.ts +1 -1
  27. package/dist/contexts/component-generics.js +1 -1
  28. package/dist/contexts/component-types.d.ts +11 -12
  29. package/dist/contexts/component-types.js +0 -1
  30. package/dist/contexts/component.d.ts +14 -14
  31. package/dist/contexts/component.js +13 -14
  32. package/dist/contexts/docs.d.ts +1 -1
  33. package/dist/contexts/docs.js +1 -1
  34. package/dist/contexts/index.d.ts +18 -19
  35. package/dist/contexts/index.js +13 -14
  36. package/dist/contexts/markdown.d.ts +1 -1
  37. package/dist/contexts/markdown.js +2 -2
  38. package/dist/contexts/navigation.d.ts +2 -2
  39. package/dist/contexts/navigation.js +1 -1
  40. package/dist/contexts/search.d.ts +3 -3
  41. package/dist/contexts/search.js +13 -14
  42. package/dist/contexts/use-components.d.ts +10 -11
  43. package/dist/contexts/use-components.js +2 -2
  44. package/dist/contexts-CMNI3ctP.js +3799 -0
  45. package/dist/{docs-DhNaW0DE.d.ts → docs-BvahWQ28.d.ts} +2 -1
  46. package/dist/{docs-Cj25B-Sh.js → docs-CopwX9a7.js} +5 -1
  47. package/dist/icons-yb-Jhkmg.js +753 -0
  48. package/dist/{index-d8_VR8Z5.d.ts → index-BmPNhnpe.d.ts} +6 -6
  49. package/dist/{index-BXO3gZup.d.ts → index-D5NMSAld.d.ts} +26 -25
  50. package/dist/index-rVFBdVz8.d.ts +15 -0
  51. package/dist/index.d.ts +20 -21
  52. package/dist/index.js +15 -7700
  53. package/dist/languages/go.d.ts +11 -12
  54. package/dist/languages/go.js +13 -14
  55. package/dist/languages/http.d.ts +11 -12
  56. package/dist/languages/http.js +13 -14
  57. package/dist/languages/index.d.ts +11 -12
  58. package/dist/languages/index.js +13 -14
  59. package/dist/languages/java.d.ts +11 -12
  60. package/dist/languages/java.js +13 -14
  61. package/dist/languages/python.d.ts +11 -12
  62. package/dist/languages/python.js +13 -14
  63. package/dist/languages/ruby.d.ts +11 -12
  64. package/dist/languages/ruby.js +13 -14
  65. package/dist/languages/typescript.d.ts +11 -12
  66. package/dist/languages/typescript.js +13 -14
  67. package/dist/markdown/index.d.ts +3 -3
  68. package/dist/markdown/index.js +13 -14
  69. package/dist/markdown/md.js +1 -1
  70. package/dist/markdown/utils.d.ts +3 -3
  71. package/dist/markdown/utils.js +1 -1
  72. package/dist/{markdown-DunIdqFE.js → markdown-BmpyokB7.js} +9 -5
  73. package/dist/{markdown-DN8KaRR2.d.ts → markdown-w5UpIiGc.d.ts} +2 -1
  74. package/dist/{method-c3XDArUn.d.ts → method-CLpRObBV.d.ts} +7 -6
  75. package/dist/{navigation-BSn6PX-7.d.ts → navigation-Blr3LaES.d.ts} +3 -2
  76. package/dist/{navigation-CuCg3le8.js → navigation-CGr5_w6z.js} +5 -1
  77. package/dist/{overview-D21weqVJ.d.ts → overview-DBnqhjAg.d.ts} +6 -6
  78. package/dist/{primitives-iB9fIrMF.d.ts → primitives-BFubD3w8.d.ts} +9 -8
  79. package/dist/{properties-Ba6F_GGj.d.ts → properties-DeQRa6VK.d.ts} +4 -4
  80. package/dist/{routing-C8oZYLsf.js → routing-8itEXLx6.js} +1 -1
  81. package/dist/{routing-BE6Vrs-z.d.ts → routing-DNN8R6bZ.d.ts} +1 -1
  82. package/dist/routing.d.ts +1 -1
  83. package/dist/routing.js +3 -180
  84. package/dist/{sdk-D2x2l6JH.d.ts → sdk-BVQyp5Dw.d.ts} +14 -13
  85. package/dist/search/index.d.ts +6 -6
  86. package/dist/search/index.js +233 -110
  87. package/dist/search/providers/algolia.d.ts +2 -2
  88. package/dist/search/providers/algolia.js +13 -14
  89. package/dist/search/providers/fuse.d.ts +2 -2
  90. package/dist/search/providers/fuse.js +13 -14
  91. package/dist/search/providers/pagefind.d.ts +2 -2
  92. package/dist/search/providers/pagefind.js +1 -1
  93. package/dist/search/providers/walker.d.ts +2 -2
  94. package/dist/search/providers/walker.js +13 -14
  95. package/dist/search/types.d.ts +2 -2
  96. package/dist/search/types.js +1 -1
  97. package/dist/{search-KMqOU2tz.d.ts → search-CPp6HpUy.d.ts} +3 -2
  98. package/dist/{sidebar-B1X4gmY2.d.ts → sidebar-BoPLeaxp.d.ts} +5 -4
  99. package/dist/{snippets-BApdMOXp.d.ts → snippets-DLHH_Voi.d.ts} +7 -6
  100. package/dist/{style-BWu-Pqcm.d.ts → style-BEMLtSIK.d.ts} +0 -10
  101. package/dist/{style-CkbsakoF.js → style-CPgcT0Fw.js} +1 -11
  102. package/dist/style.d.ts +1 -1
  103. package/dist/style.js +1 -1
  104. package/dist/styles/main.css +51 -20
  105. package/dist/styles/main.js +0 -0
  106. package/dist/styles/primitives.css +1 -0
  107. package/dist/styles/primitives.js +0 -0
  108. package/dist/styles/resets.css +1 -0
  109. package/dist/styles/resets.js +0 -0
  110. package/dist/styles/search.css +1 -0
  111. package/dist/styles/search.js +0 -0
  112. package/dist/styles/sidebar.css +1 -0
  113. package/dist/styles/sidebar.js +0 -0
  114. package/dist/styles/snippets.css +1 -0
  115. package/dist/styles/snippets.js +0 -0
  116. package/dist/styles/variables.css +2 -0
  117. package/dist/styles/variables.js +0 -0
  118. package/dist/{types-BLgvxY4i.d.ts → types-DNSz4kuM.d.ts} +1 -1
  119. package/dist/{use-components-DI-AbT-D.js → use-components-BHEwm0mE.js} +1 -1
  120. package/dist/{utils-BhYTrLot.js → utils-2FmcHPHp.js} +2 -2
  121. package/dist/{utils-B9JL_XWH.d.ts → utils-DVi3gJLL.d.ts} +2 -2
  122. package/dist/utils.d.ts +1 -1
  123. package/dist/utils.js +2 -2
  124. package/package.json +63 -10
  125. package/dist/components/dropdown.d.ts +0 -2
  126. package/dist/components/dropdown.js +0 -4
  127. package/dist/components/scripts/dropdown.d.ts +0 -12
  128. package/dist/components/scripts/dropdown.js +0 -50
  129. package/dist/contexts-DO0sMzym.js +0 -2581
  130. package/dist/dropdown-Dv9VAYCW.d.ts +0 -42
  131. package/dist/dropdown-kUhwBigR.js +0 -38
  132. package/dist/icons--8QR-PrL.js +0 -222
  133. package/dist/index-BW6OPqAo.d.ts +0 -16
  134. package/dist/mcp.cjs +0 -983418
  135. package/src/components/breadcrumbs.tsx +0 -94
  136. package/src/components/chat.tsx +0 -157
  137. package/src/components/icons.tsx +0 -584
  138. package/src/components/index.ts +0 -8
  139. package/src/components/method.tsx +0 -145
  140. package/src/components/overview.tsx +0 -172
  141. package/src/components/primitives.tsx +0 -301
  142. package/src/components/properties.tsx +0 -132
  143. package/src/components/sdk.tsx +0 -408
  144. package/src/components/sidebar.tsx +0 -99
  145. package/src/components/snippets.tsx +0 -197
  146. package/src/contexts/component-generics.tsx +0 -43
  147. package/src/contexts/component-types.tsx +0 -5
  148. package/src/contexts/component.tsx +0 -32
  149. package/src/contexts/docs.tsx +0 -86
  150. package/src/contexts/index.tsx +0 -20
  151. package/src/contexts/markdown.tsx +0 -44
  152. package/src/contexts/navigation.tsx +0 -44
  153. package/src/contexts/search.tsx +0 -27
  154. package/src/contexts/use-components.tsx +0 -4
  155. package/src/hooks/use-strict-context.tsx +0 -16
  156. package/src/index.ts +0 -6
  157. package/src/languages/go.tsx +0 -281
  158. package/src/languages/http.tsx +0 -329
  159. package/src/languages/index.ts +0 -26
  160. package/src/languages/java.tsx +0 -358
  161. package/src/languages/python.tsx +0 -258
  162. package/src/languages/ruby.tsx +0 -327
  163. package/src/languages/typescript.tsx +0 -399
  164. package/src/markdown/index.ts +0 -112
  165. package/src/markdown/md.ts +0 -45
  166. package/src/markdown/utils.ts +0 -52
  167. package/src/routing.ts +0 -238
  168. package/src/search/form.tsx +0 -130
  169. package/src/search/index.tsx +0 -1
  170. package/src/search/indexer.ts +0 -248
  171. package/src/search/mcp.ts +0 -156
  172. package/src/search/printer.tsx +0 -86
  173. package/src/search/providers/algolia.ts +0 -88
  174. package/src/search/providers/fuse.ts +0 -19
  175. package/src/search/providers/pagefind.ts +0 -17
  176. package/src/search/providers/walker.ts +0 -32
  177. package/src/search/results.tsx +0 -183
  178. package/src/search/state.ts +0 -64
  179. package/src/search/types.ts +0 -116
  180. package/src/style.ts +0 -185
  181. package/src/styles/main.css +0 -989
  182. package/src/styles/primitives.css +0 -392
  183. package/src/styles/resets.css +0 -39
  184. package/src/styles/search.css +0 -359
  185. package/src/styles/sidebar.css +0 -85
  186. package/src/styles/snippets.css +0 -130
  187. package/src/styles/variables.css +0 -86
  188. package/src/utils.ts +0 -40
  189. /package/dist/{chunk-Bp6m_JJh.js → chunk-DsStOjWQ.js} +0 -0
  190. /package/dist/{md-Dg8aOyMA.js → md-DxiV1_vy.js} +0 -0
  191. /package/dist/{pagefind-ChrPfuVv.js → pagefind-BaK1krMe.js} +0 -0
  192. /package/dist/{types-DFN4M1Sp.js → types-__XoFvJ_.js} +0 -0
  193. /package/dist/{utils-ByZH9QWT.js → utils-BCfb0F9R.js} +0 -0
  194. /package/dist/{utils-DlayebL1.d.ts → utils-D43p_yTd.d.ts} +0 -0
@@ -1,145 +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 (!httpMethod || !HttpMethods.includes(httpMethod)) return null;
27
-
28
- return (
29
- <span
30
- className={clsx(style.MethodRouteHttpMethod, style.MethodRouteHttpMethodIconOnly)}
31
- data-method={httpMethod}
32
- >
33
- {HttpMethodIcons[httpMethod] &&
34
- React.createElement(HttpMethodIcons[httpMethod], {
35
- size: 14,
36
- strokeWidth: 3,
37
- className: style.Icon,
38
- })}
39
- {showName && httpMethod}
40
- </span>
41
- );
42
- }
43
-
44
- export type MethodHeaderProps = {
45
- title: ReactNode;
46
- level?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5';
47
- signature?: ReactNode;
48
- badges?: ReactNode;
49
- children?: ReactNode;
50
- };
51
-
52
- export function MethodHeader({ title, badges, signature, children, level }: MethodHeaderProps) {
53
- const Heading = level ?? 'h5';
54
- return (
55
- <div className={style.MethodHeader}>
56
- <Heading className={style.MethodTitle}>{title}</Heading>
57
- {badges && <div className={style.MethodBadges}>{badges}</div>}
58
- {signature}
59
- {children}
60
- </div>
61
- );
62
- }
63
-
64
- export type MethodRouteProps = {
65
- httpMethod?: string;
66
- endpoint?: string | ReactNode;
67
- iconOnly?: boolean;
68
- };
69
-
70
- export function MethodRoute({ httpMethod, endpoint, iconOnly }: MethodRouteProps) {
71
- return (
72
- <div className={style.MethodRoute}>
73
- <MethodIconBadge httpMethod={httpMethod} showName={!iconOnly} />
74
- {endpoint && <span className={style.MethodRouteEndpoint}>{endpoint}</span>}
75
- </div>
76
- );
77
- }
78
-
79
- export type MethodDescriptionProps = {
80
- description?: string;
81
- };
82
-
83
- export function MethodDescription({ description }: MethodDescriptionProps) {
84
- const { Markdown } = useComponents();
85
-
86
- if (description)
87
- return (
88
- <div className={style.MethodDescription}>
89
- <Markdown content={description} />
90
- </div>
91
- );
92
- }
93
-
94
- export type MethodInfoProps = {
95
- children?: ReactNode;
96
- parameters?: ReactNode;
97
- returns?: ReactNode;
98
- };
99
-
100
- export function MethodInfo({ children, parameters, returns }: MethodInfoProps) {
101
- return (
102
- <div className={style.MethodInfo}>
103
- {children && <div className={style.MethodContent}>{children}</div>}
104
-
105
- {parameters && (
106
- <div className={style.MethodInfoSection}>
107
- <h5>
108
- Parameters
109
- <PropertyToggle target="parameters" />
110
- </h5>
111
- <div className={style.MethodParameters} data-stldocs-property-group="parameters">
112
- {parameters}
113
- </div>
114
- </div>
115
- )}
116
-
117
- {returns && (
118
- <div className={style.MethodInfoSection}>
119
- <h5>
120
- Returns
121
- <PropertyToggle target="returns" />
122
- </h5>
123
- <div className={style.MethodReturns} data-stldocs-property-group="returns">
124
- {returns}
125
- </div>
126
- </div>
127
- )}
128
- </div>
129
- );
130
- }
131
-
132
- export type MethodProps = {
133
- id?: string;
134
- header?: ReactNode;
135
- children?: ReactNode;
136
- } & React.HTMLProps<HTMLDivElement>;
137
-
138
- export function Method({ id, header, children, className, ...props }: MethodProps) {
139
- return (
140
- <div id={id} className={clsx(style.Method, className)} tabIndex={0} {...props}>
141
- {header}
142
- <div className={style.MethodBody}>{children}</div>
143
- </div>
144
- );
145
- }
@@ -1,172 +0,0 @@
1
- import * as React from 'react';
2
- import { ChevronRight } from 'lucide-react';
3
- import type * as SDKJSON from '@stainless/sdk-json';
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, true);
58
-
59
- return (
60
- <Docs.MethodHeader
61
- level="h5"
62
- title={<Docs.Link stainlessPath={method.stainlessPath}>{method.summary ?? method.title}</Docs.Link>}
63
- signature={<Lang.MethodSignature decl={decl} />}
64
- badges={method.deprecated && <Docs.Badge id="deprecated">Deprecated</Docs.Badge>}
65
- >
66
- <Docs.MethodRoute httpMethod={method.httpMethod} endpoint={method.endpoint.split(' ', 2).at(-1)} />
67
- {/* Removing temporarily per design review */}
68
- {/* <Docs.MethodDescription description={method.description} /> */}
69
- </Docs.MethodHeader>
70
- );
71
- }
72
-
73
- export function SDKResource({ resource, parents, showModels }: SDKResourceProps & { showModels?: boolean }) {
74
- const Docs = useComponents();
75
- const language = useLanguage();
76
- const spec = useSpec();
77
-
78
- const methods = Object.values(resource.methods).filter(
79
- (method) => spec?.decls?.[language]?.[method.stainlessPath],
80
- );
81
-
82
- const models = Object.values(resource.models).filter(
83
- (model) => spec?.decls?.[language]?.[`${model.stainlessPath} > (schema)`],
84
- );
85
-
86
- return (
87
- <div className={style.Resource}>
88
- <div className={style.ResourceContent}>
89
- <Docs.SDKResourceHeader resource={resource} parents={parents} />
90
- {methods.length > 0 && (
91
- <div className={style.ResourceContentGroup}>
92
- {methods.map((method) => (
93
- <div className={style.MethodSummary} key={method.stainlessPath}>
94
- <Docs.SDKMethodSummary method={method} />
95
- </div>
96
- ))}
97
- </div>
98
- )}
99
-
100
- {showModels !== false && models.length > 0 && (
101
- <div className={style.ResourceContentGroup} data-stldocs-property-group="models">
102
- <h5 className={style.ResourceContentGroupModelTitle}>
103
- Models
104
- <PropertyToggle target="models" />
105
- </h5>
106
- {models.map((model) => (
107
- <Docs.SDKModel model={model} key={model.stainlessPath} />
108
- ))}
109
- </div>
110
- )}
111
- </div>
112
- </div>
113
- );
114
- }
115
-
116
- export type SDKOverviewProps = {
117
- resource: SDKJSON.Resource;
118
- };
119
-
120
- export function SDKOverview({ resource }: SDKOverviewProps) {
121
- const { SDKResource } = useComponents();
122
-
123
- const nested = React.useMemo(() => flatResources(resource.subresources, [resource]), [resource]);
124
-
125
- return (
126
- <div className={style.Overview}>
127
- <div className={style.OverviewHeader}>
128
- <h1>{resource.title}</h1>
129
- </div>
130
- <SDKResource resource={resource} />
131
- {nested.map((props, index) => (
132
- <SDKResource {...props} key={index} />
133
- ))}
134
- </div>
135
- );
136
- }
137
-
138
- export type SDKRootProps = {
139
- stainlessPath: string;
140
- };
141
-
142
- export function SDKRoot({ stainlessPath }: SDKRootProps) {
143
- const spec = useSpec();
144
- const Docs = useComponents();
145
-
146
- const parsed = parseStainlessPath(stainlessPath);
147
- const resource = spec && getResourceFromSpec(stainlessPath, spec);
148
-
149
- if (!resource || !parsed) {
150
- console.warn(`Could not find resource or parsed path for '${stainlessPath}'`);
151
- return null;
152
- }
153
-
154
- if (parsed.method) {
155
- const method = resource.methods[parsed.method];
156
- if (!method) {
157
- console.warn(`Method '${parsed.method}' not found in resource '${resource.stainlessPath}'`);
158
- return null;
159
- }
160
- return (
161
- <div className={style.Root}>
162
- <Docs.SDKMethod method={method} />
163
- </div>
164
- );
165
- }
166
-
167
- return (
168
- <div className={style.Root}>
169
- <Docs.SDKOverview resource={resource} />
170
- </div>
171
- );
172
- }
@@ -1,301 +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
- ? [
14
- ...items.slice(0, limit),
15
- <span className={style.Truncation} key="truncation">
16
- {items.length - limit} more
17
- </span>,
18
- ]
19
- : items;
20
-
21
- return arr.map((item, index) => (
22
- <Fragment key={`iterator:${index}`}>
23
- {!!index && children}
24
- {item}
25
- </Fragment>
26
- ));
27
- }
28
-
29
- type ExpanderProps = {
30
- id?: string;
31
- open?: boolean;
32
- summary: ReactNode;
33
- virtual?: boolean;
34
- muted?: boolean;
35
- children?: ReactNode;
36
- };
37
-
38
- export function Expander({ id, open, summary, virtual, muted, children }: ExpanderProps) {
39
- const settings = useSettings();
40
- const virtualExpanders = settings?.virtualExpanders;
41
-
42
- if (virtual || virtualExpanders)
43
- return (
44
- <VirtualExpander summary={summary} open={open} muted={muted} id={id}>
45
- {children}
46
- </VirtualExpander>
47
- );
48
-
49
- return (
50
- <details
51
- className={style.Expander}
52
- open={open}
53
- data-stldocs-expander-muted={muted}
54
- data-stldocs-expander-initial-state={open}
55
- >
56
- <summary className={style.ExpanderSummary}>
57
- <div className={style.ExpanderSummaryIcon}>
58
- <PlusIcon size={16} strokeWidth={1} className={style.Icon} />
59
- <MinusIcon size={16} strokeWidth={1} className={style.Icon} />
60
- </div>
61
- <div className={style.ExpanderSummaryContent}>{summary}</div>
62
- </summary>
63
- <div className={style.ExpanderContent} id={id}>
64
- {children}
65
- </div>
66
- </details>
67
- );
68
- }
69
-
70
- export function VirtualExpander({
71
- id,
72
- open: isOpen,
73
- muted,
74
- summary,
75
- children,
76
- }: Omit<ExpanderProps, 'virtual'>) {
77
- const [open, setOpen] = useState(isOpen);
78
-
79
- React.useEffect(() => {
80
- if (isOpen) setOpen(true);
81
- }, [isOpen]);
82
-
83
- return (
84
- <div
85
- className={style.Expander}
86
- data-open={open}
87
- data-stldocs-expander-muted={muted}
88
- data-stldocs-expander-initial-state={open}
89
- >
90
- <div className={style.ExpanderSummary} onClick={() => setOpen(!open)}>
91
- <div className={style.ExpanderSummaryIcon}>
92
- <PlusIcon size={16} className={style.Icon} />
93
- <MinusIcon size={16} className={style.Icon} />
94
- </div>
95
- <div className={style.ExpanderSummaryContent}>{summary}</div>
96
- </div>
97
- {open && (
98
- <div className={style.ExpanderContent} id={id}>
99
- {children}
100
- </div>
101
- )}
102
- </div>
103
- );
104
- }
105
-
106
- export function Markdown({ content }: { content: string }) {
107
- const rendered = useRenderMarkdown(content);
108
-
109
- return (
110
- rendered && (
111
- <div className={`${style.Markdown} ${style.Content}`} dangerouslySetInnerHTML={{ __html: rendered }} />
112
- )
113
- );
114
- }
115
-
116
- type BadgeProps = {
117
- id: string;
118
- children?: ReactNode;
119
- };
120
-
121
- export function Badge({ id, children }: BadgeProps) {
122
- return (
123
- <span className={style.Badge} data-badge-id={id}>
124
- {children ?? id}
125
- </span>
126
- );
127
- }
128
-
129
- const TooltipNestingContext = React.createContext<boolean>(false);
130
-
131
- type TooltipProps = {
132
- content: ReactNode;
133
- children: ReactNode;
134
- };
135
-
136
- export function Tooltip({ content, children }: TooltipProps) {
137
- const nested = React.useContext(TooltipNestingContext);
138
-
139
- if (nested) return children;
140
-
141
- return (
142
- <span className={style.Tooltip}>
143
- <span className={style.TooltipContent}>
144
- <TooltipNestingContext.Provider value={true}>{content}</TooltipNestingContext.Provider>
145
- </span>
146
- <span className={style.TooltipHost}>{children}</span>
147
- </span>
148
- );
149
- }
150
-
151
- type LinkProps = {
152
- stainlessPath: string;
153
- scroll?: boolean;
154
- children?: ReactNode;
155
- } & React.HTMLProps<HTMLAnchorElement>;
156
-
157
- export function Link({ stainlessPath, scroll = true, children, ...props }: LinkProps) {
158
- const { basePath, onNavigate } = useNavigation();
159
- const language = useLanguage();
160
-
161
- const href = React.useMemo(() => {
162
- if (props.href) return props.href;
163
- if (stainlessPath && basePath) return generateRoute(basePath, language, stainlessPath);
164
- }, [basePath, language, stainlessPath, props.href]);
165
-
166
- const handleClick = React.useCallback(
167
- (e: React.MouseEvent<HTMLAnchorElement>) => {
168
- if (props.onClick) props.onClick(e);
169
- if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
170
- if (href) onNavigate?.(e, { href, language, stainlessPath, scroll });
171
- },
172
- [href, scroll, onNavigate, language, props, stainlessPath],
173
- );
174
-
175
- if (!href) return children;
176
-
177
- return (
178
- <a href={href} onClick={handleClick} {...props}>
179
- {children}
180
- </a>
181
- );
182
- }
183
-
184
- export type InputProps = {
185
- left?: ReactNode;
186
- right?: ReactNode;
187
- } & React.InputHTMLAttributes<HTMLInputElement>;
188
-
189
- export const Input = React.forwardRef<HTMLInputElement, InputProps>(function Input(
190
- { left, right, ...props },
191
- ref,
192
- ) {
193
- return (
194
- <div className={style.Input}>
195
- {left}
196
- <input {...props} ref={ref} className={style.InputTextField} />
197
- {right}
198
- </div>
199
- );
200
- });
201
-
202
- export type ToggleButtonProps = {
203
- children?: ReactNode;
204
- selected?: boolean;
205
- } & React.ButtonHTMLAttributes<HTMLButtonElement>;
206
-
207
- export const ToggleButton = React.forwardRef<HTMLButtonElement, ToggleButtonProps>(function ToggleButton(
208
- { children, selected, ...props },
209
- ref,
210
- ) {
211
- return (
212
- <button {...props} ref={ref} className={style.ToggleButton} data-stldocs-toggle-selected={selected}>
213
- {children}
214
- </button>
215
- );
216
- });
217
-
218
- export type ListViewProps<TItem> = {
219
- items: Array<TItem>;
220
- itemDelegate: (item: TItem, selected: boolean) => React.ReactNode;
221
- onSelectListItem?: (item: TItem) => void;
222
- } & React.HTMLAttributes<HTMLDivElement>;
223
-
224
- export function ListView<TItem>({ items, itemDelegate, onSelectListItem, ...rest }: ListViewProps<TItem>) {
225
- const [selectedIndex, setSelectedIndex] = React.useState<number>(0);
226
- const [keyboardIndex, setKeyboardIndex] = React.useState<number>(0);
227
- const listRef = React.useRef<HTMLDivElement>(null);
228
- const itemRef = React.useRef<HTMLDivElement>(null);
229
-
230
- React.useEffect(() => {
231
- setSelectedIndex(0);
232
- setKeyboardIndex(0);
233
- }, [items]);
234
-
235
- const handleSelect = React.useCallback(() => {
236
- const item = items[selectedIndex];
237
- if (item) {
238
- onSelectListItem?.(item);
239
- }
240
- }, [items, selectedIndex, onSelectListItem]);
241
-
242
- React.useEffect(() => {
243
- function handleKeyPress(ev: KeyboardEvent) {
244
- switch (ev.key) {
245
- case 'ArrowUp': {
246
- ev.preventDefault();
247
- const value = Math.max(0, selectedIndex - 1);
248
- setSelectedIndex(value);
249
- setKeyboardIndex(value);
250
- break;
251
- }
252
-
253
- case 'ArrowDown': {
254
- ev.preventDefault();
255
- const value = Math.min(items.length, selectedIndex + 1);
256
- setSelectedIndex(value);
257
- setKeyboardIndex(value);
258
- break;
259
- }
260
-
261
- case 'Enter':
262
- ev.preventDefault();
263
- handleSelect();
264
- break;
265
- }
266
- }
267
-
268
- addEventListener('keydown', handleKeyPress);
269
- return () => removeEventListener('keydown', handleKeyPress);
270
- }, [items, selectedIndex, handleSelect]);
271
-
272
- React.useEffect(() => {
273
- if (!keyboardIndex || !itemRef.current || !listRef.current) {
274
- listRef?.current?.scroll(0, 0);
275
- return;
276
- }
277
-
278
- const selectedBounds = itemRef.current.getBoundingClientRect();
279
- const listBounds = listRef.current.getBoundingClientRect();
280
- const needsScroll = selectedBounds.top < listBounds.top || selectedBounds.bottom > listBounds.bottom;
281
-
282
- if (needsScroll) itemRef.current.scrollIntoView({ block: 'nearest' });
283
- }, [keyboardIndex, items, listRef]);
284
-
285
- return (
286
- <div ref={listRef} className={style.ListView} tabIndex={0} {...rest}>
287
- {items.map((item, index) => (
288
- <div
289
- key={index}
290
- ref={index === selectedIndex ? itemRef : null}
291
- className={style.ListViewItem}
292
- data-stldocs-listview-selected={index === selectedIndex}
293
- onClick={handleSelect}
294
- onMouseMove={() => setSelectedIndex(index)}
295
- >
296
- {itemDelegate(item, index === selectedIndex)}
297
- </div>
298
- ))}
299
- </div>
300
- );
301
- }