@elastic/eui-docusaurus-theme 2.0.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.
Files changed (297) hide show
  1. package/LICENSE.txt +6 -0
  2. package/README.md +292 -0
  3. package/lib/.tsbuildinfo-client +1 -0
  4. package/lib/components/badge/index.d.ts +1 -0
  5. package/lib/components/badge/index.js +9 -0
  6. package/lib/components/codesandbox_icon/codesandbox_icon.d.ts +4 -0
  7. package/lib/components/codesandbox_icon/codesandbox_icon.js +2 -0
  8. package/lib/components/codesandbox_icon/index.d.ts +1 -0
  9. package/lib/components/codesandbox_icon/index.js +8 -0
  10. package/lib/components/demo/actions_bar/actions_bar.d.ts +10 -0
  11. package/lib/components/demo/actions_bar/actions_bar.js +34 -0
  12. package/lib/components/demo/actions_bar/index.d.ts +1 -0
  13. package/lib/components/demo/actions_bar/index.js +8 -0
  14. package/lib/components/demo/code_transformer.d.ts +18 -0
  15. package/lib/components/demo/code_transformer.js +39 -0
  16. package/lib/components/demo/codesandbox/find_external_dependencies.d.ts +5 -0
  17. package/lib/components/demo/codesandbox/find_external_dependencies.js +30 -0
  18. package/lib/components/demo/codesandbox/index.d.ts +1 -0
  19. package/lib/components/demo/codesandbox/index.js +8 -0
  20. package/lib/components/demo/codesandbox/open_action.d.ts +16 -0
  21. package/lib/components/demo/codesandbox/open_action.js +91 -0
  22. package/lib/components/demo/context.d.ts +14 -0
  23. package/lib/components/demo/context.js +13 -0
  24. package/lib/components/demo/create_demo.d.ts +5 -0
  25. package/lib/components/demo/create_demo.js +13 -0
  26. package/lib/components/demo/demo.d.ts +23 -0
  27. package/lib/components/demo/demo.js +61 -0
  28. package/lib/components/demo/editor/editor.d.ts +1 -0
  29. package/lib/components/demo/editor/editor.js +39 -0
  30. package/lib/components/demo/editor/index.d.ts +1 -0
  31. package/lib/components/demo/editor/index.js +8 -0
  32. package/lib/components/demo/index.d.ts +3 -0
  33. package/lib/components/demo/index.js +10 -0
  34. package/lib/components/demo/preview/index.d.ts +1 -0
  35. package/lib/components/demo/preview/index.js +8 -0
  36. package/lib/components/demo/preview/preview.d.ts +7 -0
  37. package/lib/components/demo/preview/preview.js +36 -0
  38. package/lib/components/demo/scope.d.ts +1 -0
  39. package/lib/components/demo/scope.js +12 -0
  40. package/lib/components/demo/source/get_source_from_children.d.ts +11 -0
  41. package/lib/components/demo/source/get_source_from_children.js +42 -0
  42. package/lib/components/demo/source/index.d.ts +1 -0
  43. package/lib/components/demo/source/index.js +8 -0
  44. package/lib/components/demo/source/source.d.ts +6 -0
  45. package/lib/components/demo/source/source.js +25 -0
  46. package/lib/components/figma_embed/index.d.ts +5 -0
  47. package/lib/components/figma_embed/index.js +36 -0
  48. package/lib/components/guideline/guideline.d.ts +10 -0
  49. package/lib/components/guideline/guideline.js +68 -0
  50. package/lib/components/guideline/guideline_text.d.ts +6 -0
  51. package/lib/components/guideline/guideline_text.js +28 -0
  52. package/lib/components/guideline/index.d.ts +2 -0
  53. package/lib/components/guideline/index.js +9 -0
  54. package/lib/components/guideline/types.d.ts +1 -0
  55. package/lib/components/guideline/types.js +8 -0
  56. package/lib/components/high_contrast_mode_toggle/index.d.ts +1 -0
  57. package/lib/components/high_contrast_mode_toggle/index.js +15 -0
  58. package/lib/components/icon/index.d.ts +1 -0
  59. package/lib/components/icon/index.js +9 -0
  60. package/lib/components/index.d.ts +7 -0
  61. package/lib/components/index.js +14 -0
  62. package/lib/components/navbar_item/index.d.ts +19 -0
  63. package/lib/components/navbar_item/index.js +84 -0
  64. package/lib/components/prop_table/definition_types.d.ts +43 -0
  65. package/lib/components/prop_table/definition_types.js +8 -0
  66. package/lib/components/prop_table/extended_types.d.ts +5 -0
  67. package/lib/components/prop_table/extended_types.js +27 -0
  68. package/lib/components/prop_table/extended_types_info.d.ts +26 -0
  69. package/lib/components/prop_table/extended_types_info.js +34 -0
  70. package/lib/components/prop_table/index.d.ts +1 -0
  71. package/lib/components/prop_table/index.js +8 -0
  72. package/lib/components/prop_table/prop_table.d.ts +8 -0
  73. package/lib/components/prop_table/prop_table.js +115 -0
  74. package/lib/components/theme_context/index.d.ts +16 -0
  75. package/lib/components/theme_context/index.js +103 -0
  76. package/lib/components/theme_context/theme_overrides.d.ts +2 -0
  77. package/lib/components/theme_context/theme_overrides.js +12 -0
  78. package/lib/components/version_switcher/index.d.ts +23 -0
  79. package/lib/components/version_switcher/index.js +51 -0
  80. package/lib/index.d.ts +2 -0
  81. package/lib/index.js +19 -0
  82. package/lib/index.js.map +1 -0
  83. package/lib/theme/Admonition/Types.d.ts +3 -0
  84. package/lib/theme/Admonition/Types.js +51 -0
  85. package/lib/theme/CodeBlock/index.d.ts +3 -0
  86. package/lib/theme/CodeBlock/index.js +35 -0
  87. package/lib/theme/ColorModeToggle/index.d.ts +10 -0
  88. package/lib/theme/ColorModeToggle/index.js +51 -0
  89. package/lib/theme/Demo/actions.d.ts +8 -0
  90. package/lib/theme/Demo/actions.js +8 -0
  91. package/lib/theme/Demo/default_scope.d.ts +3 -0
  92. package/lib/theme/Demo/default_scope.js +17 -0
  93. package/lib/theme/DocBreadcrumbs/Items/Home/index.d.ts +2 -0
  94. package/lib/theme/DocBreadcrumbs/Items/Home/index.js +15 -0
  95. package/lib/theme/DocBreadcrumbs/Items/item.styles.d.ts +5 -0
  96. package/lib/theme/DocBreadcrumbs/Items/item.styles.js +40 -0
  97. package/lib/theme/DocBreadcrumbs/index.d.ts +2 -0
  98. package/lib/theme/DocBreadcrumbs/index.js +63 -0
  99. package/lib/theme/DocItem/Content/index.d.ts +3 -0
  100. package/lib/theme/DocItem/Content/index.js +44 -0
  101. package/lib/theme/DocItem/Footer/index.d.ts +2 -0
  102. package/lib/theme/DocItem/Footer/index.js +17 -0
  103. package/lib/theme/DocItem/Layout/index.d.ts +3 -0
  104. package/lib/theme/DocItem/Layout/index.js +71 -0
  105. package/lib/theme/DocItem/Metadata/index.d.ts +2 -0
  106. package/lib/theme/DocItem/Metadata/index.js +7 -0
  107. package/lib/theme/DocItem/Paginator/index.d.ts +6 -0
  108. package/lib/theme/DocItem/Paginator/index.js +11 -0
  109. package/lib/theme/DocItem/TOC/Desktop/index.d.ts +2 -0
  110. package/lib/theme/DocItem/TOC/Desktop/index.js +8 -0
  111. package/lib/theme/DocItem/TOC/Mobile/index.d.ts +2 -0
  112. package/lib/theme/DocItem/TOC/Mobile/index.js +17 -0
  113. package/lib/theme/DocItem/index.d.ts +3 -0
  114. package/lib/theme/DocItem/index.js +10 -0
  115. package/lib/theme/DocPaginator/index.d.ts +3 -0
  116. package/lib/theme/DocPaginator/index.js +19 -0
  117. package/lib/theme/DocRoot/Layout/Main/index.d.ts +3 -0
  118. package/lib/theme/DocRoot/Layout/Main/index.js +35 -0
  119. package/lib/theme/DocRoot/Layout/Sidebar/index.d.ts +3 -0
  120. package/lib/theme/DocRoot/Layout/Sidebar/index.js +81 -0
  121. package/lib/theme/DocRoot/Layout/index.d.ts +3 -0
  122. package/lib/theme/DocRoot/Layout/index.js +47 -0
  123. package/lib/theme/DocSidebarItem/Category/index.d.ts +3 -0
  124. package/lib/theme/DocSidebarItem/Category/index.js +146 -0
  125. package/lib/theme/DocSidebarItem/Link/index.d.ts +3 -0
  126. package/lib/theme/DocSidebarItem/Link/index.js +39 -0
  127. package/lib/theme/DocSidebarItem/index.d.ts +3 -0
  128. package/lib/theme/DocSidebarItem/index.js +15 -0
  129. package/lib/theme/DocSidebarItems/index.d.ts +5 -0
  130. package/lib/theme/DocSidebarItems/index.js +17 -0
  131. package/lib/theme/EditThisPage/index.d.ts +3 -0
  132. package/lib/theme/EditThisPage/index.js +17 -0
  133. package/lib/theme/Footer/index.d.ts +2 -0
  134. package/lib/theme/Footer/index.js +43 -0
  135. package/lib/theme/Heading/index.d.ts +3 -0
  136. package/lib/theme/Heading/index.js +49 -0
  137. package/lib/theme/Logo/index.d.ts +3 -0
  138. package/lib/theme/Logo/index.js +80 -0
  139. package/lib/theme/MDXComponents/A.d.ts +6 -0
  140. package/lib/theme/MDXComponents/A.js +17 -0
  141. package/lib/theme/MDXComponents/Blockquote.d.ts +2 -0
  142. package/lib/theme/MDXComponents/Blockquote.js +18 -0
  143. package/lib/theme/MDXComponents/Code.d.ts +6 -0
  144. package/lib/theme/MDXComponents/Code.js +35 -0
  145. package/lib/theme/MDXComponents/Heading.d.ts +4 -0
  146. package/lib/theme/MDXComponents/Heading.js +4 -0
  147. package/lib/theme/MDXComponents/ListItem.d.ts +2 -0
  148. package/lib/theme/MDXComponents/ListItem.js +5 -0
  149. package/lib/theme/MDXComponents/OrderedList.d.ts +2 -0
  150. package/lib/theme/MDXComponents/OrderedList.js +11 -0
  151. package/lib/theme/MDXComponents/Paragraph.d.ts +2 -0
  152. package/lib/theme/MDXComponents/Paragraph.js +18 -0
  153. package/lib/theme/MDXComponents/Table.d.ts +2 -0
  154. package/lib/theme/MDXComponents/Table.js +3 -0
  155. package/lib/theme/MDXComponents/TableBody.d.ts +2 -0
  156. package/lib/theme/MDXComponents/TableBody.js +3 -0
  157. package/lib/theme/MDXComponents/TableDataCell.d.ts +2 -0
  158. package/lib/theme/MDXComponents/TableDataCell.js +3 -0
  159. package/lib/theme/MDXComponents/TableHeader.d.ts +2 -0
  160. package/lib/theme/MDXComponents/TableHeader.js +3 -0
  161. package/lib/theme/MDXComponents/TableHeaderCell.d.ts +2 -0
  162. package/lib/theme/MDXComponents/TableHeaderCell.js +3 -0
  163. package/lib/theme/MDXComponents/TableRow.d.ts +2 -0
  164. package/lib/theme/MDXComponents/TableRow.js +3 -0
  165. package/lib/theme/MDXComponents/UnorderedList.d.ts +2 -0
  166. package/lib/theme/MDXComponents/UnorderedList.js +11 -0
  167. package/lib/theme/MDXComponents/index.d.ts +2 -0
  168. package/lib/theme/MDXComponents/index.js +46 -0
  169. package/lib/theme/MDXContent/index.d.ts +6 -0
  170. package/lib/theme/MDXContent/index.js +4 -0
  171. package/lib/theme/Navbar/Content/index.d.ts +7 -0
  172. package/lib/theme/Navbar/Content/index.js +149 -0
  173. package/lib/theme/Navbar/Layout/index.d.ts +6 -0
  174. package/lib/theme/Navbar/Layout/index.js +59 -0
  175. package/lib/theme/Navbar/MobileSidebar/Header/index.d.ts +7 -0
  176. package/lib/theme/Navbar/MobileSidebar/Header/index.js +46 -0
  177. package/lib/theme/Navbar/MobileSidebar/Layout/index.d.ts +6 -0
  178. package/lib/theme/Navbar/MobileSidebar/Layout/index.js +26 -0
  179. package/lib/theme/Navbar/MobileSidebar/index.d.ts +7 -0
  180. package/lib/theme/Navbar/MobileSidebar/index.js +14 -0
  181. package/lib/theme/NavbarItem/DropdownNavbarItem/index.d.ts +3 -0
  182. package/lib/theme/NavbarItem/DropdownNavbarItem/index.js +94 -0
  183. package/lib/theme/NavbarItem/NavbarNavLink.d.ts +7 -0
  184. package/lib/theme/NavbarItem/NavbarNavLink.js +48 -0
  185. package/lib/theme/PaginatorNavLink/index.d.ts +3 -0
  186. package/lib/theme/PaginatorNavLink/index.js +43 -0
  187. package/lib/theme/Root.d.ts +3 -0
  188. package/lib/theme/Root.js +66 -0
  189. package/lib/theme/Root.styles.d.ts +2 -0
  190. package/lib/theme/Root.styles.js +111 -0
  191. package/lib/theme/TOCCollapsible/CollapseButton/index.d.ts +3 -0
  192. package/lib/theme/TOCCollapsible/CollapseButton/index.js +23 -0
  193. package/lib/theme/TOCItems/Tree.d.ts +5 -0
  194. package/lib/theme/TOCItems/Tree.js +80 -0
  195. package/lib/theme/infima.styles.d.ts +1 -0
  196. package/lib/theme/infima.styles.js +1456 -0
  197. package/lib/theme/reset.styles.d.ts +2 -0
  198. package/lib/theme/reset.styles.js +79 -0
  199. package/package.json +61 -0
  200. package/src/components/badge/index.ts +11 -0
  201. package/src/components/codesandbox_icon/codesandbox_icon.tsx +24 -0
  202. package/src/components/codesandbox_icon/index.ts +9 -0
  203. package/src/components/demo/actions_bar/actions_bar.tsx +95 -0
  204. package/src/components/demo/actions_bar/index.ts +9 -0
  205. package/src/components/demo/code_transformer.ts +44 -0
  206. package/src/components/demo/codesandbox/find_external_dependencies.ts +34 -0
  207. package/src/components/demo/codesandbox/index.ts +9 -0
  208. package/src/components/demo/codesandbox/open_action.tsx +132 -0
  209. package/src/components/demo/context.ts +30 -0
  210. package/src/components/demo/create_demo.tsx +17 -0
  211. package/src/components/demo/demo.tsx +143 -0
  212. package/src/components/demo/editor/editor.tsx +51 -0
  213. package/src/components/demo/editor/index.ts +9 -0
  214. package/src/components/demo/index.ts +11 -0
  215. package/src/components/demo/preview/index.ts +9 -0
  216. package/src/components/demo/preview/preview.tsx +77 -0
  217. package/src/components/demo/scope.ts +14 -0
  218. package/src/components/demo/source/get_source_from_children.ts +59 -0
  219. package/src/components/demo/source/index.ts +9 -0
  220. package/src/components/demo/source/source.tsx +36 -0
  221. package/src/components/figma_embed/index.tsx +57 -0
  222. package/src/components/guideline/guideline.tsx +121 -0
  223. package/src/components/guideline/guideline_text.tsx +51 -0
  224. package/src/components/guideline/index.ts +10 -0
  225. package/src/components/guideline/types.ts +9 -0
  226. package/src/components/high_contrast_mode_toggle/index.tsx +28 -0
  227. package/src/components/icon/index.ts +11 -0
  228. package/src/components/index.ts +15 -0
  229. package/src/components/navbar_item/index.tsx +164 -0
  230. package/src/components/prop_table/definition_types.ts +53 -0
  231. package/src/components/prop_table/extended_types.tsx +66 -0
  232. package/src/components/prop_table/extended_types_info.ts +35 -0
  233. package/src/components/prop_table/index.ts +9 -0
  234. package/src/components/prop_table/prop_table.tsx +235 -0
  235. package/src/components/theme_context/index.tsx +156 -0
  236. package/src/components/theme_context/theme_overrides.ts +15 -0
  237. package/src/components/version_switcher/index.tsx +144 -0
  238. package/src/index.ts +21 -0
  239. package/src/theme/Admonition/Types.tsx +85 -0
  240. package/src/theme/CodeBlock/index.tsx +57 -0
  241. package/src/theme/ColorModeToggle/index.tsx +93 -0
  242. package/src/theme/Demo/actions.tsx +20 -0
  243. package/src/theme/Demo/default_scope.ts +19 -0
  244. package/src/theme/DocBreadcrumbs/Items/Home/index.tsx +38 -0
  245. package/src/theme/DocBreadcrumbs/Items/item.styles.ts +43 -0
  246. package/src/theme/DocBreadcrumbs/index.tsx +144 -0
  247. package/src/theme/DocItem/Content/index.tsx +75 -0
  248. package/src/theme/DocItem/Footer/index.tsx +59 -0
  249. package/src/theme/DocItem/Layout/index.tsx +112 -0
  250. package/src/theme/DocItem/Metadata/index.tsx +23 -0
  251. package/src/theme/DocItem/Paginator/index.tsx +20 -0
  252. package/src/theme/DocItem/TOC/Desktop/index.tsx +24 -0
  253. package/src/theme/DocItem/TOC/Mobile/index.tsx +35 -0
  254. package/src/theme/DocItem/index.tsx +30 -0
  255. package/src/theme/DocPaginator/index.tsx +64 -0
  256. package/src/theme/DocRoot/Layout/Main/index.tsx +61 -0
  257. package/src/theme/DocRoot/Layout/Sidebar/index.tsx +124 -0
  258. package/src/theme/DocRoot/Layout/index.tsx +72 -0
  259. package/src/theme/DocSidebarItem/Category/index.tsx +266 -0
  260. package/src/theme/DocSidebarItem/Link/index.tsx +86 -0
  261. package/src/theme/DocSidebarItem/index.tsx +29 -0
  262. package/src/theme/DocSidebarItems/index.tsx +30 -0
  263. package/src/theme/EditThisPage/index.tsx +50 -0
  264. package/src/theme/Footer/index.tsx +67 -0
  265. package/src/theme/Heading/index.tsx +94 -0
  266. package/src/theme/Logo/index.tsx +146 -0
  267. package/src/theme/MDXComponents/A.tsx +33 -0
  268. package/src/theme/MDXComponents/Blockquote.tsx +35 -0
  269. package/src/theme/MDXComponents/Code.tsx +60 -0
  270. package/src/theme/MDXComponents/Heading.tsx +16 -0
  271. package/src/theme/MDXComponents/ListItem.tsx +20 -0
  272. package/src/theme/MDXComponents/OrderedList.tsx +26 -0
  273. package/src/theme/MDXComponents/Paragraph.tsx +33 -0
  274. package/src/theme/MDXComponents/Table.tsx +16 -0
  275. package/src/theme/MDXComponents/TableBody.tsx +16 -0
  276. package/src/theme/MDXComponents/TableDataCell.tsx +20 -0
  277. package/src/theme/MDXComponents/TableHeader.tsx +16 -0
  278. package/src/theme/MDXComponents/TableHeaderCell.tsx +20 -0
  279. package/src/theme/MDXComponents/TableRow.tsx +16 -0
  280. package/src/theme/MDXComponents/UnorderedList.tsx +26 -0
  281. package/src/theme/MDXComponents/index.ts +61 -0
  282. package/src/theme/MDXContent/index.tsx +22 -0
  283. package/src/theme/Navbar/Content/index.tsx +262 -0
  284. package/src/theme/Navbar/Layout/index.tsx +100 -0
  285. package/src/theme/Navbar/MobileSidebar/Header/index.tsx +89 -0
  286. package/src/theme/Navbar/MobileSidebar/Layout/index.tsx +44 -0
  287. package/src/theme/Navbar/MobileSidebar/index.tsx +46 -0
  288. package/src/theme/NavbarItem/DropdownNavbarItem/index.tsx +200 -0
  289. package/src/theme/NavbarItem/NavbarNavLink.tsx +141 -0
  290. package/src/theme/PaginatorNavLink/index.tsx +72 -0
  291. package/src/theme/Root.styles.ts +122 -0
  292. package/src/theme/Root.tsx +106 -0
  293. package/src/theme/TOCCollapsible/CollapseButton/index.tsx +53 -0
  294. package/src/theme/TOCItems/Tree.tsx +114 -0
  295. package/src/theme/infima.styles.ts +1458 -0
  296. package/src/theme/reset.styles.ts +82 -0
  297. package/src/theme/theme.d.ts +598 -0
@@ -0,0 +1,28 @@
1
+ import { useContext } from 'react';
2
+ import { useEuiTheme } from '@elastic/eui';
3
+
4
+ import { NavbarItem } from '../navbar_item';
5
+ import { AppThemeContext } from '../theme_context';
6
+
7
+ export const HighContrastModeToggle = () => {
8
+ const euiThemeContext = useEuiTheme();
9
+
10
+ const appContext = useContext(AppThemeContext);
11
+ const { changeHighContrastMode } = appContext;
12
+
13
+ const isForcedContrastMode = euiThemeContext.highContrastMode === 'forced';
14
+ const _highContrastMode =
15
+ appContext.highContrastMode && !isForcedContrastMode
16
+ ? appContext.highContrastMode
17
+ : euiThemeContext.highContrastMode;
18
+
19
+ return (
20
+ <NavbarItem
21
+ title={'Toggle high contrast mode'}
22
+ icon="contrast"
23
+ isMenuItem={false}
24
+ isSelected={!!_highContrastMode}
25
+ onClick={() => changeHighContrastMode(!_highContrastMode)}
26
+ />
27
+ );
28
+ };
@@ -0,0 +1,11 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
5
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
6
+ * Side Public License, v 1.
7
+ */
8
+
9
+ import { EuiIcon } from '@elastic/eui';
10
+
11
+ export const Icon = EuiIcon;
@@ -0,0 +1,15 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
5
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
6
+ * Side Public License, v 1.
7
+ */
8
+
9
+ export { AppThemeContext, useAppTheme } from './theme_context';
10
+ export { Badge } from './badge';
11
+ export { FigmaEmbed } from './figma_embed';
12
+ export { Guideline, GuidelineText } from './guideline';
13
+ export { Icon } from './icon';
14
+ export { PropTable } from './prop_table';
15
+ export { createDemo, Demo, DemoSource, type DemoProps } from './demo';
@@ -0,0 +1,164 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
5
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
6
+ * Side Public License, v 1.
7
+ */
8
+
9
+ import { useContext } from 'react';
10
+ import { css } from '@emotion/react';
11
+ import useIsBrowser from '@docusaurus/useIsBrowser';
12
+ import {
13
+ CommonProps,
14
+ EuiIcon,
15
+ ExclusiveUnion,
16
+ IconType,
17
+ mathWithUnits,
18
+ PropsForAnchor,
19
+ PropsForButton,
20
+ useEuiMemoizedStyles,
21
+ UseEuiTheme,
22
+ } from '@elastic/eui';
23
+
24
+ import { AppThemeContext } from '../theme_context';
25
+
26
+ type SharedProps = {
27
+ icon: IconType;
28
+ showLabel?: boolean;
29
+ isMenuItem?: boolean;
30
+ isSelected?: boolean;
31
+ } & CommonProps;
32
+
33
+ type Props = ExclusiveUnion<
34
+ PropsForAnchor<SharedProps>,
35
+ PropsForButton<SharedProps>
36
+ >;
37
+
38
+ // converted from css modules to Emotion
39
+ export const getStyles = ({ euiTheme }: UseEuiTheme) => ({
40
+ item: css`
41
+ display: flex;
42
+ align-items: center;
43
+ flex-shrink: 0;
44
+
45
+ -webkit-tap-highlight-color: transparent;
46
+ transition: background var(--ifm-transition-fast);
47
+
48
+ &:hover {
49
+ background-color: ${euiTheme.components.buttons.backgroundTextHover};
50
+ color: currentColor;
51
+ }
52
+ `,
53
+ navItem: css`
54
+ justify-content: center;
55
+ width: ${euiTheme.size.xl};
56
+ height: ${euiTheme.size.xl};
57
+ border-radius: 50%;
58
+ `,
59
+ menuItem: css`
60
+ justify-content: flex-start;
61
+ gap: ${euiTheme.size.s};
62
+
63
+ @media (min-width: 997px) {
64
+ justify-content: center;
65
+ width: ${euiTheme.size.xl};
66
+ height: ${euiTheme.size.xl};
67
+ border-radius: 50%;
68
+ }
69
+ `,
70
+ darkMode: css`
71
+ &:hover {
72
+ color: currentColor;
73
+ }
74
+ `,
75
+ disabled: css`
76
+ cursor: not-allowed;
77
+ `,
78
+ selected: css`
79
+ background-color: ${euiTheme.colors.backgroundFilledText};
80
+ color: ${euiTheme.colors.textInverse};
81
+ `,
82
+ title: css`
83
+ @media (min-width: 997px) {
84
+ display: none;
85
+ }
86
+ `,
87
+ });
88
+
89
+ // using a type guard to ensure proper typing from ExclusiveUnion
90
+ const isAnchorClick = (
91
+ onClick: Props['onClick'],
92
+ href: Props['href']
93
+ ): onClick is PropsForAnchor<SharedProps>['onClick'] => href != null;
94
+
95
+ export const NavbarItem = (props: Props) => {
96
+ const {
97
+ className,
98
+ title,
99
+ icon,
100
+ onClick,
101
+ href,
102
+ target,
103
+ showLabel,
104
+ isMenuItem = true,
105
+ isSelected,
106
+ css,
107
+ } = props;
108
+
109
+ const isBrowser = useIsBrowser();
110
+ const { colorMode } = useContext(AppThemeContext);
111
+
112
+ const isDarkMode = colorMode === 'dark';
113
+
114
+ const styles = useEuiMemoizedStyles(getStyles);
115
+ const cssStyles = [
116
+ styles.item,
117
+ isMenuItem ? styles.menuItem : styles.navItem,
118
+ !isBrowser && styles.disabled,
119
+ isSelected && styles.selected,
120
+ isDarkMode && styles.darkMode,
121
+ ];
122
+
123
+ const content = showLabel ? (
124
+ <>
125
+ <EuiIcon type={icon} />
126
+ <span css={styles.title}>{title}</span>
127
+ </>
128
+ ) : (
129
+ <EuiIcon type={icon} />
130
+ );
131
+
132
+ if (isAnchorClick(onClick, href)) {
133
+ return (
134
+ <a
135
+ href={href}
136
+ target={target ?? '_blank'}
137
+ title={title}
138
+ className={className}
139
+ css={cssStyles}
140
+ onClick={onClick}
141
+ aria-label={title}
142
+ aria-live="polite"
143
+ >
144
+ {content}
145
+ </a>
146
+ );
147
+ }
148
+
149
+ return (
150
+ <button
151
+ type="button"
152
+ disabled={!isBrowser}
153
+ className={className}
154
+ css={cssStyles}
155
+ onClick={onClick}
156
+ title={title}
157
+ aria-label={title}
158
+ aria-live="polite"
159
+ aria-pressed={isSelected != null ? isSelected : undefined}
160
+ >
161
+ {content}
162
+ </button>
163
+ );
164
+ };
@@ -0,0 +1,53 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
5
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
6
+ * Side Public License, v 1.
7
+ */
8
+
9
+ /**
10
+ * Represents a processed component prop with its metadata
11
+ */
12
+ export type ProcessedComponentProp = {
13
+ /** Name of the prop */
14
+ name: string;
15
+ /** Description of the prop */
16
+ description: string;
17
+ /** Whether the prop is required */
18
+ isRequired?: boolean;
19
+ /** Type information for the prop */
20
+ type?: {
21
+ name: string;
22
+ raw?: string;
23
+ [key: string]: any; // Allow for additional type metadata
24
+ };
25
+ /** Default value of the prop */
26
+ defaultValue?: string;
27
+ /** Allow additional properties that might be needed in the future */
28
+ [key: string]: any;
29
+ };
30
+
31
+ /**
32
+ * Represents a type extension with display name and potentially other information
33
+ */
34
+ export type ExtendedType = {
35
+ /** Display name of the type being extended */
36
+ displayName: string;
37
+ /** Any additional metadata about the extended type */
38
+ [key: string]: any;
39
+ };
40
+
41
+ /**
42
+ * Represents a processed component with its metadata
43
+ */
44
+ export type ProcessedComponent = {
45
+ /** Display name of the component */
46
+ displayName: string;
47
+ /** Props of the component as a record of prop name to prop details */
48
+ props: Record<string, ProcessedComponentProp>;
49
+ /** Types that this component extends */
50
+ extends: ExtendedType[];
51
+ /** Allow additional properties that might be needed in the future */
52
+ [key: string]: any;
53
+ };
@@ -0,0 +1,66 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
5
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
6
+ * Side Public License, v 1.
7
+ */
8
+
9
+ import { Fragment, useMemo } from 'react';
10
+ import { EuiLink, EuiText } from '@elastic/eui';
11
+
12
+ import { extendedTypesInfo } from './extended_types_info';
13
+ import { ProcessedComponent, ExtendedType } from './definition_types';
14
+
15
+ export type PropTableExtendedTypesProps = {
16
+ definition: ProcessedComponent;
17
+ };
18
+
19
+ export const PropTableExtendedTypes = ({
20
+ definition,
21
+ }: PropTableExtendedTypesProps) => {
22
+ const extendedTypes = useMemo(() => {
23
+ const types = definition.extends.filter((type: ExtendedType) =>
24
+ extendedTypesInfo.hasOwnProperty(type.displayName)
25
+ );
26
+
27
+ if (
28
+ types.every(
29
+ (type: ExtendedType) => type.displayName.indexOf('HTMLAttributes') > -1
30
+ )
31
+ ) {
32
+ const htmlAttributesIndex = types.findIndex(
33
+ (type: ExtendedType) => type.displayName === 'HTMLAttributes'
34
+ );
35
+ if (htmlAttributesIndex > -1 && types.length > 1) {
36
+ types.splice(htmlAttributesIndex, 1);
37
+ }
38
+ }
39
+
40
+ return types;
41
+ }, [definition.extends]);
42
+
43
+ if (!extendedTypes.length) {
44
+ return null;
45
+ }
46
+
47
+ return (
48
+ <EuiText size="s">
49
+ Extends{' '}
50
+ {extendedTypes.map((type, index) => (
51
+ <Fragment key={index}>
52
+ <EuiLink
53
+ href={
54
+ extendedTypesInfo[
55
+ type.displayName as keyof typeof extendedTypesInfo
56
+ ].url
57
+ }
58
+ >
59
+ {type.displayName}
60
+ </EuiLink>
61
+ {extendedTypes.length - 1 > index && ', '}
62
+ </Fragment>
63
+ ))}
64
+ </EuiText>
65
+ );
66
+ };
@@ -0,0 +1,35 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
5
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
6
+ * Side Public License, v 1.
7
+ */
8
+
9
+ export const extendedTypesInfo = {
10
+ // HTMLAttributes is removed from display if any of the following elements also exist
11
+ HTMLAttributes: {
12
+ name: 'HTMLElement',
13
+ url: 'https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement',
14
+ },
15
+ SelectHTMLAttributes: {
16
+ name: 'HTMLSelectElement',
17
+ url: 'https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement',
18
+ },
19
+ TextareaHTMLAttributes: {
20
+ name: 'HTMLTextAreaElement',
21
+ url: 'https://developer.mozilla.org/en-US/docs/Web/API/HTMLTextAreaElement',
22
+ },
23
+ InputHTMLAttributes: {
24
+ name: 'HTMLInputElement',
25
+ url: 'https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement',
26
+ },
27
+ AnchorHTMLAttributes: {
28
+ name: 'HTMLAnchorElement',
29
+ url: 'https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement',
30
+ },
31
+ ButtonHTMLAttributes: {
32
+ name: 'HTMLButtonElement',
33
+ url: 'https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement',
34
+ },
35
+ };
@@ -0,0 +1,9 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
5
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
6
+ * Side Public License, v 1.
7
+ */
8
+
9
+ export { PropTable } from './prop_table';
@@ -0,0 +1,235 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
5
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
6
+ * Side Public License, v 1.
7
+ */
8
+
9
+ import {
10
+ EuiBasicTable,
11
+ EuiMarkdownFormat,
12
+ EuiBasicTableColumn,
13
+ EuiTextColor,
14
+ EuiFlexGroup,
15
+ EuiCode,
16
+ UseEuiTheme,
17
+ useEuiMemoizedStyles,
18
+ EuiLink,
19
+ EuiPanel,
20
+ } from '@elastic/eui';
21
+ import { useCallback, useMemo } from 'react';
22
+ import { css } from '@emotion/react';
23
+ import Heading from '@theme/Heading';
24
+
25
+ import { PropTableExtendedTypes } from './extended_types';
26
+ import { ProcessedComponent, ProcessedComponentProp } from './definition_types';
27
+
28
+ export type PropTableProps = {
29
+ definition: ProcessedComponent;
30
+ headingLevel?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
31
+ showTitle?: boolean;
32
+ parseDescription?: (description: string) => string | undefined;
33
+ };
34
+
35
+ const getPropId = (prop: ProcessedComponentProp, componentName: string) =>
36
+ `${encodeURIComponent(componentName)}-prop-${prop.name}`;
37
+
38
+ const getPropTableStyles = ({ euiTheme }: UseEuiTheme) => ({
39
+ propTable: css`
40
+ margin-block: ${euiTheme.size.xl};
41
+ `,
42
+ header: css`
43
+ // Increased specificity is needed here to override default
44
+ // content heading styles
45
+ && h1,
46
+ && h2,
47
+ && h3,
48
+ && h4,
49
+ && h5,
50
+ && h6 {
51
+ margin-block: 0;
52
+ }
53
+ `,
54
+ table: css`
55
+ vertical-align: top;
56
+ `,
57
+ propName: css`
58
+ font-family: ${euiTheme.font.familyCode};
59
+ font-weight: ${euiTheme.font.weight.semiBold};
60
+ `,
61
+ description: css`
62
+ p,
63
+ ul {
64
+ font-size: var(--eui-font-size-s);
65
+ }
66
+
67
+ p {
68
+ margin-block-end: var(--eui-size-s);
69
+ }
70
+
71
+ p:first-child {
72
+ margin-block-start: 0;
73
+ }
74
+ `,
75
+ required: css`
76
+ font-family: ${euiTheme.font.familyCode};
77
+ color: ${euiTheme.colors.textDanger};
78
+ `,
79
+ type: css`
80
+ font-weight: ${euiTheme.font.weight.semiBold};
81
+ `,
82
+ tableNameLink: css`
83
+ display: none;
84
+ margin-inline-start: ${euiTheme.size.xs};
85
+ `,
86
+ tableRow: css`
87
+ scroll-margin-block-start: calc(var(--ifm-navbar-height) + 0.5rem);
88
+
89
+ &:hover .propLink {
90
+ display: inline-block;
91
+ }
92
+ `,
93
+ tableCell: css`
94
+ vertical-align: text-top;
95
+ `,
96
+ });
97
+
98
+ export const PropTable = ({
99
+ definition,
100
+ headingLevel = 'h3',
101
+ showTitle = true,
102
+ parseDescription,
103
+ }: PropTableProps) => {
104
+ const styles = useEuiMemoizedStyles(getPropTableStyles);
105
+
106
+ const tableItems = useMemo<Array<ProcessedComponentProp>>(
107
+ () =>
108
+ Object.values(definition.props).sort(
109
+ (a, b) => +(b.isRequired ?? false) - +(a.isRequired ?? false)
110
+ ),
111
+ [definition.props]
112
+ );
113
+
114
+ const columns = useMemo<Array<EuiBasicTableColumn<ProcessedComponentProp>>>(
115
+ () => [
116
+ {
117
+ field: 'name',
118
+ name: 'Prop',
119
+ width: '150',
120
+ render(
121
+ value: ProcessedComponentProp['name'],
122
+ prop: ProcessedComponentProp
123
+ ) {
124
+ return (
125
+ <span css={styles.propName}>
126
+ {value}
127
+ <EuiLink
128
+ href={`#${getPropId(prop, definition.displayName)}`}
129
+ css={styles.tableNameLink}
130
+ className="propLink"
131
+ aria-label={`Direct link to the ${prop.name} prop`}
132
+ title={`Direct link to the ${prop.name} prop`}
133
+ >
134
+ #
135
+ </EuiLink>
136
+ </span>
137
+ );
138
+ },
139
+ },
140
+ {
141
+ field: 'description',
142
+ name: 'Description and type',
143
+ render(
144
+ value: ProcessedComponentProp['description'],
145
+ prop: ProcessedComponentProp
146
+ ) {
147
+ const result = parseDescription ? parseDescription(value) : value;
148
+
149
+ return (
150
+ <EuiFlexGroup
151
+ direction="column"
152
+ alignItems="flexStart"
153
+ gutterSize="s"
154
+ >
155
+ {result && (
156
+ <EuiMarkdownFormat css={styles.description}>
157
+ {result}
158
+ </EuiMarkdownFormat>
159
+ )}
160
+ {prop.type && (
161
+ <span css={styles.type}>
162
+ Type:{' '}
163
+ <EuiCode language="ts">
164
+ {prop.type.raw || prop.type.name}
165
+ </EuiCode>
166
+ </span>
167
+ )}
168
+ </EuiFlexGroup>
169
+ );
170
+ },
171
+ },
172
+ {
173
+ field: 'defaultValue',
174
+ name: 'Default value',
175
+ width: '120',
176
+ render(
177
+ value: ProcessedComponentProp['defaultValue'],
178
+ prop: ProcessedComponentProp
179
+ ) {
180
+ if (prop.isRequired && !value?.trim().length) {
181
+ return <EuiTextColor css={styles.required}>Required</EuiTextColor>;
182
+ }
183
+
184
+ return value && <EuiCode>{value}</EuiCode>;
185
+ },
186
+ },
187
+ ],
188
+ []
189
+ );
190
+
191
+ const rowProps = useCallback(
192
+ (item: ProcessedComponentProp) => ({
193
+ id: getPropId(item, definition.displayName),
194
+ css: styles.tableRow,
195
+ }),
196
+ [definition.displayName]
197
+ );
198
+
199
+ const cellProps = useCallback(
200
+ (item: ProcessedComponentProp) => ({
201
+ id: getPropId(item, definition.displayName),
202
+ css: styles.tableCell,
203
+ }),
204
+ [definition.displayName]
205
+ );
206
+
207
+ return (
208
+ <EuiFlexGroup
209
+ aria-label={`Component properties table for ${definition.displayName}`}
210
+ gutterSize="s"
211
+ direction="column"
212
+ css={styles.propTable}
213
+ >
214
+ <header css={styles.header}>
215
+ {showTitle && (
216
+ <Heading as={headingLevel} id={definition.displayName}>
217
+ {definition.displayName}
218
+ </Heading>
219
+ )}
220
+ <PropTableExtendedTypes definition={definition} />
221
+ </header>
222
+ <EuiPanel color="plain" hasBorder>
223
+ <EuiBasicTable
224
+ css={styles.table}
225
+ width="100%"
226
+ items={tableItems}
227
+ columns={columns}
228
+ rowProps={rowProps}
229
+ cellProps={cellProps}
230
+ compressed
231
+ />
232
+ </EuiPanel>
233
+ </EuiFlexGroup>
234
+ );
235
+ };