feat: add all doc titles to nav dropdown
This commit is contained in:
@@ -1,39 +1,8 @@
|
|||||||
import { Fragment } from 'react';
|
|
||||||
import { useSectionContext } from '../context/section';
|
import { useSectionContext } from '../context/section';
|
||||||
import { Doc, DocsStructure } from '../types/types';
|
import { Doc, DocsStructure } from '../types/types';
|
||||||
import { toKebabCase } from '../utils/stringUtils';
|
import { toKebabCase } from '../utils/stringUtils';
|
||||||
import styles from './SectionDropdown.module.css';
|
import styles from './SectionDropdown.module.css';
|
||||||
|
|
||||||
function SectionDropdownOption({ doc }: { doc: Doc }) {
|
|
||||||
return (
|
|
||||||
<Fragment>
|
|
||||||
{doc.copy && doc.example && (
|
|
||||||
<option
|
|
||||||
className={styles.selectItem}
|
|
||||||
label={doc.title}
|
|
||||||
value={toKebabCase(doc.title)}
|
|
||||||
>
|
|
||||||
{doc.title}
|
|
||||||
</option>
|
|
||||||
)}
|
|
||||||
{doc.children && doc.children.length > 0 && (
|
|
||||||
<optgroup label={doc.title}>
|
|
||||||
{doc.children.map(child => (
|
|
||||||
<option
|
|
||||||
value={toKebabCase(child.title)}
|
|
||||||
className={styles.selectItem}
|
|
||||||
label={child.title}
|
|
||||||
key={child.title}
|
|
||||||
>
|
|
||||||
{child.title}
|
|
||||||
</option>
|
|
||||||
))}
|
|
||||||
</optgroup>
|
|
||||||
)}
|
|
||||||
</Fragment>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function SectionDropdown({
|
export default function SectionDropdown({
|
||||||
version,
|
version,
|
||||||
}: {
|
}: {
|
||||||
@@ -45,6 +14,22 @@ export default function SectionDropdown({
|
|||||||
location.hash = e.target.value;
|
location.hash = e.target.value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getAllDocs = (docs: Doc[]) => {
|
||||||
|
let result: Doc[] = [];
|
||||||
|
|
||||||
|
docs.forEach(doc => {
|
||||||
|
result.push(doc);
|
||||||
|
|
||||||
|
if (doc.children && doc.children.length > 0) {
|
||||||
|
result = result.concat(getAllDocs(doc.children));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const docs = getAllDocs(version.docs);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<select
|
<select
|
||||||
onChange={handleSelectChange}
|
onChange={handleSelectChange}
|
||||||
@@ -52,12 +37,23 @@ export default function SectionDropdown({
|
|||||||
className={styles.dropdownSelect}
|
className={styles.dropdownSelect}
|
||||||
value={section}
|
value={section}
|
||||||
>
|
>
|
||||||
{version.docs.map(doc => {
|
{docs.map(doc => {
|
||||||
|
if (
|
||||||
|
doc.copy === undefined ||
|
||||||
|
doc.example === undefined
|
||||||
|
) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SectionDropdownOption
|
<option
|
||||||
doc={doc}
|
className={styles.selectItem}
|
||||||
|
label={doc.title}
|
||||||
|
value={toKebabCase(doc.title)}
|
||||||
key={doc.title}
|
key={doc.title}
|
||||||
/>
|
>
|
||||||
|
{doc.title}
|
||||||
|
</option>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
Reference in New Issue
Block a user