chore: refactor to move section dropdown to separate component

This commit is contained in:
Stevan Freeborn
2023-04-27 06:22:37 -05:00
parent 0be3292ea3
commit 38212dcde9
4 changed files with 82 additions and 79 deletions
-22
View File
@@ -77,28 +77,6 @@
} }
} }
.dropdownSelect {
color: #64adac;
background-color: inherit;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 1rem;
font-weight: bold;
padding: 0 1rem;
}
.dropdownSelect:focus-visible {
outline: none;
}
.selectItem {
color: #64adac;
cursor: pointer;
font-weight: bold;
margin: 1rem;
}
.navbarToggle { .navbarToggle {
cursor: pointer; cursor: pointer;
display: none; display: none;
+3 -57
View File
@@ -1,10 +1,11 @@
'use client'; 'use client';
import Link from 'next/link'; import Link from 'next/link';
import { Fragment, useState } from 'react'; import { useState } from 'react';
import { themes, useThemeContext } from '../theme'; import { themes, useThemeContext } from '../theme';
import { Doc, DocsStructure } from '../types/types'; import { DocsStructure } from '../types/types';
import styles from './NavBar.module.css'; import styles from './NavBar.module.css';
import SectionDropdown from './SectionDropdown';
function VersionsDropdown({ function VersionsDropdown({
version, version,
@@ -94,61 +95,6 @@ function VersionsDropdown({
); );
} }
function SectionDropdownGroup({ doc }: { doc: Doc }) {
return (
<Fragment>
{doc.copy && doc.example && (
<option
className={styles.selectItem}
label={doc.title}
>
{doc.title}
</option>
)}
{doc.children && doc.children.length > 0 && (
<optgroup label={doc.title}>
{doc.children.map(child => (
<option
className={styles.selectItem}
label={child.title}
key={child.title}
>
{child.title}
</option>
))}
</optgroup>
)}
</Fragment>
);
}
function SectionDropdown({
version,
}: {
version: DocsStructure;
}) {
const handleSelectChange = (e: any) => {
const selectedOption = e.target.value;
location.hash = selectedOption
.replaceAll(' ', '-')
.toLowerCase();
};
return (
<select
onChange={handleSelectChange}
title="navigation dropdown"
className={styles.dropdownSelect}
>
{version.docs.map(doc => {
return (
<SectionDropdownGroup doc={doc} key={doc.title} />
);
})}
</select>
);
}
export default function NavBar({ export default function NavBar({
version, version,
}: { }: {
@@ -0,0 +1,21 @@
.dropdownSelect {
color: #64adac;
background-color: inherit;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 1rem;
font-weight: bold;
padding: 0 1rem;
}
.dropdownSelect:focus-visible {
outline: none;
}
.selectItem {
color: #64adac;
cursor: pointer;
font-weight: bold;
margin: 1rem;
}
+58
View File
@@ -0,0 +1,58 @@
import { Fragment } from 'react';
import { Doc, DocsStructure } from '../types/types';
import styles from './SectionDropdown.module.css';
function SectionDropdownGroup({ doc }: { doc: Doc }) {
return (
<Fragment>
{doc.copy && doc.example && (
<option
className={styles.selectItem}
label={doc.title}
>
{doc.title}
</option>
)}
{doc.children && doc.children.length > 0 && (
<optgroup label={doc.title}>
{doc.children.map(child => (
<option
className={styles.selectItem}
label={child.title}
key={child.title}
>
{child.title}
</option>
))}
</optgroup>
)}
</Fragment>
);
}
export default function SectionDropdown({
version,
}: {
version: DocsStructure;
}) {
const handleSelectChange = (e: any) => {
const selectedOption = e.target.value;
location.hash = selectedOption
.replaceAll(' ', '-')
.toLowerCase();
};
return (
<select
onChange={handleSelectChange}
title="navigation dropdown"
className={styles.dropdownSelect}
>
{version.docs.map(doc => {
return (
<SectionDropdownGroup doc={doc} key={doc.title} />
);
})}
</select>
);
}