Skip to content

Commit 9b2b7e5

Browse files
committed
fix(#1999): add indentation to express hierarchy
- clean up commented code - use a # icon for "in page link" rather than the chain link icon
1 parent 302dadc commit 9b2b7e5

File tree

2 files changed

+31
-47
lines changed

2 files changed

+31
-47
lines changed

packages/dev/docs/src/DocSearch.js

Lines changed: 27 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import algoliasearch from 'algoliasearch/lite';
22
import {createRoot} from 'react-dom/client';
33
import docsStyle from './docs.css';
4+
import DocumentOutline from '@spectrum-icons/workflow/DocumentOutline';
45
import DOMPurify from 'dompurify';
6+
import {Icon} from '@react-spectrum/icon';
57
import {Item, SearchAutocomplete, Section} from '@react-spectrum/autocomplete';
6-
import Link from '@spectrum-icons/workflow/Link';
78
import News from '@spectrum-icons/workflow/News';
89
import React, {useRef, useState} from 'react';
910
import {Text, VisuallyHidden} from '@adobe/react-spectrum';
1011
import {ThemeProvider} from './ThemeSwitcher';
11-
import WebPage from '@spectrum-icons/workflow/WebPage';
1212

1313
export default function DocSearch() {
1414
const client = algoliasearch('1V1Q59JVTR', '44a7e2e7508ff185f25ac64c0a675f98');
@@ -89,6 +89,13 @@ export default function DocSearch() {
8989
groupedHits.map((hit) => {
9090
const hierarchy = hit.hierarchy;
9191
const objectID = hit.objectID;
92+
const docsearchParent = hit.type !== 'lvl1' &&
93+
groupedHits.find(
94+
(siblingItem) =>
95+
siblingItem.type === 'lvl1' &&
96+
siblingItem.hierarchy.lvl1 ===
97+
hit.hierarchy.lvl1
98+
);
9299

93100
return (
94101
<Item key={objectID} textValue={hit.type === 'content' ? hit[hit.type] : hierarchy[hit.type]}>
@@ -99,7 +106,7 @@ export default function DocSearch() {
99106
{
100107
title === 'Blog' || title === 'Releases' ?
101108
<News aria-label="news" /> :
102-
<WebPage aria-label="web page" />
109+
<DocumentOutline aria-label="web page" />
103110
}
104111
<Text>
105112
<Snippet
@@ -129,7 +136,9 @@ export default function DocSearch() {
129136
hit.type === 'lvl6'
130137
) && (
131138
<>
132-
<Link aria-label="in-page link" />
139+
<Hash
140+
UNSAFE_className={docsearchParent ? docsStyle.docSearchItemIndent : undefined}
141+
aria-label="in-page link" />
133142
<Text>
134143
<Snippet
135144
className="DocSearch-Hit-title"
@@ -149,7 +158,9 @@ export default function DocSearch() {
149158
{
150159
hit.type === 'content' && (
151160
<>
152-
<Link aria-label="in-page link" />
161+
<Hash
162+
UNSAFE_className={docsearchParent ? docsStyle.docSearchItemIndent : undefined}
163+
aria-label="in-page link" />
153164
<Text>
154165
<Snippet
155166
className="DocSearch-Hit-title"
@@ -172,48 +183,6 @@ export default function DocSearch() {
172183

173184
sections.push({title, items});
174185
}
175-
/*
176-
hits.forEach(prediction => {
177-
let hierarchy = prediction.hierarchy;
178-
let objectID = prediction.objectID;
179-
let url = prediction.url;
180-
let sectionTitle;
181-
for (const [path, title] of Object.entries(sectionTitles)) {
182-
let regexp = new RegExp('^.+//.+/' + path + '[/.].+$', 'i');
183-
if (url.match(regexp)) {
184-
sectionTitle = title;
185-
break;
186-
}
187-
}
188-
if (!sectionTitle) {
189-
sectionTitle = 'Documentation';
190-
}
191-
let section = sections.find(section => section.title === sectionTitle);
192-
if (!section) {
193-
section = {title: sectionTitle, items: []};
194-
sections.push(section);
195-
}
196-
let text = [];
197-
let textValue = [];
198-
for (let i = 1; i < 6; i++) {
199-
if (hierarchy[`lvl${i}`]) {
200-
text.push(prediction._highlightResult.hierarchy[`lvl${i}`].value);
201-
textValue.push(hierarchy[`lvl${i}`]);
202-
}
203-
}
204-
section.items.push(
205-
<Item key={objectID} textValue={textValue.join(' | ')}>
206-
<Text><span dangerouslySetInnerHTML={{__html: DOMPurify.sanitize(text.join(' | '))}} /></Text>
207-
{
208-
prediction.content &&
209-
<Text slot="description">
210-
<span dangerouslySetInnerHTML={{__html: DOMPurify.sanitize(prediction._snippetResult.content.value)}} />
211-
</Text>
212-
}
213-
</Item>
214-
);
215-
});
216-
*/
217186
let titles = Object.values(sectionTitles);
218187
sections = sections.sort((a, b) => titles.indexOf(a.title) < titles.indexOf(b.title) ? -1 : 1);
219188
let suggestions = sections.map((section, index) => <Section key={`${index}-${section.title}`} title={section.title}>{section.items}</Section>);
@@ -287,6 +256,16 @@ export default function DocSearch() {
287256
);
288257
}
289258

259+
function Hash(props) {
260+
return (
261+
<Icon {...props}>
262+
<svg viewBox="0 0 20 20">
263+
<path d="M13 13h4-4V8H7v5h6v4-4H7V8H3h4V3v5h6V3v5h4-4v5zm-6 0v4-4H3h4z" stroke="currentColor" fill="none" fillRule="evenodd" strokeLinecap="round" strokeLinejoin="round" />
264+
</svg>
265+
</Icon>
266+
);
267+
}
268+
290269
const AlgoliaSearchLogo = (
291270
<div className={docsStyle.docSearchLogo}>
292271
<a href="https://www.algolia.com/ref/docsearch/?utm_source=react-spectrum.adobe.com&amp;utm_medium=referral&amp;utm_content=powered_by&amp;utm_campaign=docsearch" target="_blank" rel="noopener noreferrer">
@@ -346,3 +325,4 @@ function Snippet({
346325
});
347326
}
348327

328+

packages/dev/docs/src/docs.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,10 @@ h2.sectionHeader {
648648
color: var(--spectrum-global-color-blue-700);
649649
}
650650

651+
.docSearchItemIndent {
652+
margin-inline-start: var(--spectrum-global-dimension-size-300);
653+
}
654+
651655
.docSearchFooter {
652656
align-items: center;
653657
display: flex;

0 commit comments

Comments
 (0)