@elastic/eui-docusaurus-theme 2.0.0 → 2.1.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.
@@ -3,13 +3,16 @@ import Link from '@docusaurus/Link';
3
3
  import useBaseUrl from '@docusaurus/useBaseUrl';
4
4
  import { translate } from '@docusaurus/Translate';
5
5
  import { EuiIcon, useEuiMemoizedStyles } from '@elastic/eui';
6
+ import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
6
7
  import { getItemStyles } from '../item.styles';
7
8
  export default function HomeBreadcrumbItem() {
8
9
  const homeHref = useBaseUrl('/');
10
+ const { siteConfig } = useDocusaurusContext();
11
+ const { title } = siteConfig;
9
12
  const styles = useEuiMemoizedStyles(getItemStyles);
10
13
  return (_jsxs("li", { className: "breadcrumbs__item", css: styles.item, children: [_jsx(Link, { "aria-label": translate({
11
14
  id: 'theme.docs.breadcrumbs.home',
12
15
  message: 'Home page',
13
16
  description: 'The ARIA label for the home page in the breadcrumbs',
14
- }), className: "breadcrumbs__link", href: homeHref, children: "EUI" }), _jsx(EuiIcon, { type: "arrowRight", size: "s", css: styles.icon })] }));
17
+ }), className: "breadcrumbs__link", href: homeHref, children: title }), _jsx(EuiIcon, { type: "arrowRight", size: "s", css: styles.icon })] }));
15
18
  }
@@ -0,0 +1,5 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { PropSidebarItemCategory, PropSidebarItemLink } from '@docusaurus/plugin-content-docs';
3
+ export default function DocCard({ item, }: {
4
+ item: PropSidebarItemCategory | PropSidebarItemLink;
5
+ }): ReactNode;
@@ -0,0 +1,44 @@
1
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
2
+ import { useDocById, findFirstSidebarItemLink, } from '@docusaurus/plugin-content-docs/client';
3
+ import { usePluralForm } from '@docusaurus/theme-common';
4
+ import isInternalUrl from '@docusaurus/isInternalUrl';
5
+ import { translate } from '@docusaurus/Translate';
6
+ import { EuiCard, EuiIcon } from '@elastic/eui';
7
+ function useCategoryItemsPlural() {
8
+ const { selectMessage } = usePluralForm();
9
+ return (count) => selectMessage(count, translate({
10
+ message: '1 item|{count} items',
11
+ id: 'theme.docs.DocCard.categoryDescription.plurals',
12
+ description: 'The default description for a category card in the generated index about how many items this category includes',
13
+ }, { count }));
14
+ }
15
+ function CardLayout({ href, icon, title, description, }) {
16
+ return (_jsx(EuiCard, { icon: _jsx(EuiIcon, { size: "l", type: icon }), title: title, description: description || '', titleSize: "xs", layout: "horizontal", href: href }));
17
+ }
18
+ function CardCategory({ item }) {
19
+ const href = findFirstSidebarItemLink(item);
20
+ const categoryItemsPlural = useCategoryItemsPlural();
21
+ // Unexpected: categories that don't have a link have been filtered upfront
22
+ if (!href) {
23
+ return null;
24
+ }
25
+ return (_jsx(CardLayout, { href: href,
26
+ // Coincidentally, `folderOpen` is the same icon in EUI icon library
27
+ icon: "folderOpen", title: item.label, description: item.description ?? categoryItemsPlural(item.items.length) }));
28
+ }
29
+ function CardLink({ item }) {
30
+ // We update Docusaurus `link` icon to EUI `popout` icon
31
+ const icon = isInternalUrl(item.href) ? 'document' : 'popout';
32
+ const doc = useDocById(item.docId ?? undefined);
33
+ return (_jsx(CardLayout, { href: item.href, icon: icon, title: item.label, description: item.description ?? doc?.description }));
34
+ }
35
+ export default function DocCard({ item, }) {
36
+ switch (item.type) {
37
+ case 'link':
38
+ return _jsx(CardLink, { item: item });
39
+ case 'category':
40
+ return _jsx(CardCategory, { item: item });
41
+ default:
42
+ throw new Error(`unknown item type ${JSON.stringify(item)}`);
43
+ }
44
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elastic/eui-docusaurus-theme",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "EUI theme for Docusaurus",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "scripts": {
@@ -40,8 +40,8 @@
40
40
  "@docusaurus/theme-common": "^3.7.0",
41
41
  "@docusaurus/utils-validation": "^3.7.0",
42
42
  "@elastic/datemath": "^5.0.3",
43
- "@elastic/eui": "^109.1.0",
44
- "@elastic/eui-theme-borealis": "^5.0.0",
43
+ "@elastic/eui": "^109.2.0",
44
+ "@elastic/eui-theme-borealis": "^5.1.0",
45
45
  "@emotion/css": "^11.11.2",
46
46
  "@emotion/react": "^11.11.4",
47
47
  "@types/react-window": "^1.8.8",
@@ -11,11 +11,14 @@ import Link from '@docusaurus/Link';
11
11
  import useBaseUrl from '@docusaurus/useBaseUrl';
12
12
  import { translate } from '@docusaurus/Translate';
13
13
  import { EuiIcon, useEuiMemoizedStyles } from '@elastic/eui';
14
+ import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
14
15
 
15
16
  import { getItemStyles } from '../item.styles';
16
17
 
17
18
  export default function HomeBreadcrumbItem(): JSX.Element {
18
19
  const homeHref = useBaseUrl('/');
20
+ const { siteConfig } = useDocusaurusContext();
21
+ const { title } = siteConfig;
19
22
 
20
23
  const styles = useEuiMemoizedStyles(getItemStyles);
21
24
 
@@ -30,7 +33,7 @@ export default function HomeBreadcrumbItem(): JSX.Element {
30
33
  className="breadcrumbs__link"
31
34
  href={homeHref}
32
35
  >
33
- EUI
36
+ {title}
34
37
  </Link>
35
38
  <EuiIcon type="arrowRight" size="s" css={styles.icon} />
36
39
  </li>
@@ -0,0 +1,104 @@
1
+ import { type ReactNode } from 'react';
2
+ import {
3
+ useDocById,
4
+ findFirstSidebarItemLink,
5
+ } from '@docusaurus/plugin-content-docs/client';
6
+ import { usePluralForm } from '@docusaurus/theme-common';
7
+ import isInternalUrl from '@docusaurus/isInternalUrl';
8
+ import { translate } from '@docusaurus/Translate';
9
+
10
+ import type {
11
+ PropSidebarItemCategory,
12
+ PropSidebarItemLink,
13
+ } from '@docusaurus/plugin-content-docs';
14
+
15
+ import { EuiCard, EuiIcon } from '@elastic/eui';
16
+
17
+ function useCategoryItemsPlural() {
18
+ const { selectMessage } = usePluralForm();
19
+ return (count: number) =>
20
+ selectMessage(
21
+ count,
22
+ translate(
23
+ {
24
+ message: '1 item|{count} items',
25
+ id: 'theme.docs.DocCard.categoryDescription.plurals',
26
+ description:
27
+ 'The default description for a category card in the generated index about how many items this category includes',
28
+ },
29
+ { count }
30
+ )
31
+ );
32
+ }
33
+
34
+ function CardLayout({
35
+ href,
36
+ icon,
37
+ title,
38
+ description,
39
+ }: {
40
+ href: string;
41
+ icon: string;
42
+ title: string;
43
+ description?: string;
44
+ }): ReactNode {
45
+ return (
46
+ <EuiCard
47
+ icon={<EuiIcon size="l" type={icon} />}
48
+ title={title}
49
+ description={description || ''}
50
+ titleSize="xs"
51
+ layout="horizontal"
52
+ href={href}
53
+ />
54
+ );
55
+ }
56
+
57
+ function CardCategory({ item }: { item: PropSidebarItemCategory }): ReactNode {
58
+ const href = findFirstSidebarItemLink(item);
59
+ const categoryItemsPlural = useCategoryItemsPlural();
60
+
61
+ // Unexpected: categories that don't have a link have been filtered upfront
62
+ if (!href) {
63
+ return null;
64
+ }
65
+
66
+ return (
67
+ <CardLayout
68
+ href={href}
69
+ // Coincidentally, `folderOpen` is the same icon in EUI icon library
70
+ icon="folderOpen"
71
+ title={item.label}
72
+ description={item.description ?? categoryItemsPlural(item.items.length)}
73
+ />
74
+ );
75
+ }
76
+
77
+ function CardLink({ item }: { item: PropSidebarItemLink }): ReactNode {
78
+ // We update Docusaurus `link` icon to EUI `popout` icon
79
+ const icon = isInternalUrl(item.href) ? 'document' : 'popout';
80
+ const doc = useDocById(item.docId ?? undefined);
81
+ return (
82
+ <CardLayout
83
+ href={item.href}
84
+ icon={icon}
85
+ title={item.label}
86
+ description={item.description ?? doc?.description}
87
+ />
88
+ );
89
+ }
90
+
91
+ export default function DocCard({
92
+ item,
93
+ }: {
94
+ item: PropSidebarItemCategory | PropSidebarItemLink;
95
+ }): ReactNode {
96
+ switch (item.type) {
97
+ case 'link':
98
+ return <CardLink item={item} />;
99
+ case 'category':
100
+ return <CardCategory item={item} />;
101
+ default:
102
+ throw new Error(`unknown item type ${JSON.stringify(item)}`);
103
+ }
104
+ }