Skip to content

Commit acab67e

Browse files
authored
feat(orama): use new ui components (#512)
1 parent a83987b commit acab67e

File tree

10 files changed

+291
-1185
lines changed

10 files changed

+291
-1185
lines changed

npm-shrinkwrap.json

Lines changed: 249 additions & 1113 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
"@heroicons/react": "^2.2.0",
4444
"@minify-html/node": "^0.16.4",
4545
"@node-core/rehype-shiki": "1.3.0",
46-
"@node-core/ui-components": "1.4.0",
46+
"@node-core/ui-components": "1.4.1",
4747
"@orama/orama": "^3.1.16",
48-
"@orama/react-components": "^0.8.1",
48+
"@orama/ui": "^1.5.3",
4949
"@rollup/plugin-virtual": "^3.0.2",
5050
"acorn": "^8.15.0",
5151
"commander": "^14.0.2",

src/generators/orama-db/__tests__/index.test.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ describe('buildHierarchicalTitle', () => {
1818

1919
it('should build two level hierarchy', () => {
2020
const result = buildHierarchicalTitle(mockHeadings, 1);
21-
assert.equal(result, 'Module > Class');
21+
assert.equal(result, 'Class');
2222
});
2323

2424
it('should build three level hierarchy', () => {
2525
const result = buildHierarchicalTitle(mockHeadings, 2);
26-
assert.equal(result, 'Module > Class > Method');
26+
assert.equal(result, 'Class > Method');
2727
});
2828

2929
it('should build full hierarchy', () => {
3030
const result = buildHierarchicalTitle(mockHeadings, 3);
31-
assert.equal(result, 'Module > Class > Method > Parameter');
31+
assert.equal(result, 'Class > Method > Parameter');
3232
});
3333

3434
it('should handle non-sequential depths', () => {
@@ -38,7 +38,7 @@ describe('buildHierarchicalTitle', () => {
3838
];
3939

4040
const result = buildHierarchicalTitle(headings, 1);
41-
assert.equal(result, 'Root > Deep');
41+
assert.equal(result, 'Deep');
4242
});
4343

4444
it('should handle same depth headings', () => {
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
// This schema comes from
2-
// https://github.com/oramasearch/orama-ui-components/blob/main/packages/ui-stencil/src/types/index.ts#L4
31
export const SCHEMA = {
42
title: 'string',
53
description: 'string',
6-
path: 'string',
4+
href: 'string',
5+
siteSection: 'string',
76
};

src/generators/orama-db/index.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function buildHierarchicalTitle(headings, currentIndex) {
2121
let targetDepth = currentNode.heading.depth - 1;
2222

2323
// Walk backwards through preceding headings to build hierarchy
24-
for (let i = currentIndex - 1; i >= 0 && targetDepth > 0; i--) {
24+
for (let i = currentIndex - 1; i >= 1 && targetDepth > 0; i--) {
2525
const heading = headings[i];
2626
const headingDepth = heading.heading.depth;
2727

@@ -84,7 +84,8 @@ export default {
8484
description: paragraph
8585
? transformNodeToString(paragraph, true)
8686
: undefined,
87-
path: `${entry.api}.html#${entry.slug}`,
87+
href: `${entry.api}.html#${entry.slug}`,
88+
siteSection: headings[0].heading.data.name,
8889
};
8990
})
9091
);

src/generators/web/ui/components/NavBar.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ export default () => {
1919
sidebarItemTogglerAriaLabel="Toggle navigation menu"
2020
navItems={[]}
2121
>
22-
{/* TODO(@avivkeller): Orama doesn't support Server-Side rendering yet */}
23-
{CLIENT && <SearchBox theme={theme} />}
22+
<SearchBox />
2423
<ThemeToggle
2524
onClick={toggleTheme}
2625
aria-label={`Switch to ${theme === 'light' ? 'dark' : 'light'} theme`}

src/generators/web/ui/components/SearchBox/config.mjs

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/generators/web/ui/components/SearchBox/index.jsx

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,19 @@
1-
import { OramaSearchButton, OramaSearchBox } from '@orama/react-components';
1+
import SearchModal from '@node-core/ui-components/Common/Search/Modal';
2+
import SearchResults from '@node-core/ui-components/Common/Search/Results';
3+
import SearchHit from '@node-core/ui-components/Common/Search/Results/Hit';
24

3-
import { themeConfig } from './config.mjs';
45
import useOrama from '../../hooks/useOrama.mjs';
56

6-
/**
7-
* Search component that provides documentation search functionality using Orama.
8-
*
9-
* @param {{ theme: string }} props - Component props.
10-
*/
11-
const SearchBox = ({ theme }) => {
7+
const SearchBox = () => {
128
const client = useOrama();
139

1410
return (
15-
<>
16-
<OramaSearchButton
17-
aria-disabled={!client}
18-
style={{ flexGrow: 1 }}
19-
colorScheme={theme}
20-
themeConfig={themeConfig}
21-
aria-label="Search documentation"
22-
>
23-
Search documentation
24-
</OramaSearchButton>
25-
<OramaSearchBox
26-
aria-disabled={!client}
27-
disableChat={true}
28-
linksTarget="_self"
29-
clientInstance={client}
30-
colorScheme={theme}
31-
themeConfig={themeConfig}
11+
<SearchModal client={client} placeholder={'Start typing...'}>
12+
<SearchResults
13+
noResultsTitle={'No results found for'}
14+
onHit={hit => <SearchHit document={hit.document} />}
3215
/>
33-
</>
16+
</SearchModal>
3417
);
3518
};
3619

src/generators/web/ui/hooks/useOrama.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { create, load } from '@orama/orama';
1+
import { create, search, load } from '@orama/orama';
22
import { useState, useEffect } from 'react';
33

44
/**
@@ -13,6 +13,12 @@ export default () => {
1313
schema: {},
1414
});
1515

16+
// TODO(@avivkeller): Ask Orama to support this functionality natively
17+
/**
18+
* @param {any} options
19+
*/
20+
db.search = options => search(db, options);
21+
1622
setClient(db);
1723

1824
// Load the search data

src/generators/web/ui/index.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,17 @@ main {
7070
}
7171
}
7272
}
73+
74+
#modalContent li > div > a {
75+
> svg {
76+
flex-shrink: 0;
77+
}
78+
> div {
79+
min-width: 0;
80+
> p {
81+
overflow: hidden;
82+
text-overflow: ellipsis;
83+
white-space: nowrap;
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)