mirror of
https://github.com/oceanprotocol/docs.git
synced 2024-11-26 19:49:26 +01:00
Improvement: Refactor Markdownlist
This commit is contained in:
parent
8bcf98a90f
commit
0055aaf1d8
32
src/templates/Markdown/Markdown.module.scss
Normal file
32
src/templates/Markdown/Markdown.module.scss
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
@import 'variables';
|
||||||
|
|
||||||
|
.link {
|
||||||
|
color: $brand-grey;
|
||||||
|
display: inline-block;
|
||||||
|
padding: $spacer / 6 $spacer / 2;
|
||||||
|
border-left: 0.1rem solid transparent;
|
||||||
|
margin-left: -0.05rem;
|
||||||
|
cursor: 'pointer';
|
||||||
|
|
||||||
|
&:hover,
|
||||||
|
&:focus {
|
||||||
|
transform: none;
|
||||||
|
color: $brand-purple;
|
||||||
|
|
||||||
|
:global(.setup) & {
|
||||||
|
color: $brand-blue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.active {
|
||||||
|
composes: link;
|
||||||
|
color: $brand-purple;
|
||||||
|
border-left-color: $brand-purple;
|
||||||
|
cursor: 'pointer';
|
||||||
|
|
||||||
|
:global(.setup) & {
|
||||||
|
color: $brand-blue;
|
||||||
|
border-left-color: $brand-blue;
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,8 @@ import Content from '../../components/Content'
|
|||||||
import styles from '../../templates/Doc.module.scss'
|
import styles from '../../templates/Doc.module.scss'
|
||||||
import MarkdownTemplate from '../MarkdownTemplate'
|
import MarkdownTemplate from '../MarkdownTemplate'
|
||||||
import sidebarStyles from '../../components/Sidebar.module.scss'
|
import sidebarStyles from '../../components/Sidebar.module.scss'
|
||||||
|
import moduleStyles from './Markdown.module.scss'
|
||||||
|
|
||||||
import { generatedNestedObject } from './utils'
|
import { generatedNestedObject } from './utils'
|
||||||
|
|
||||||
export default function MarkdownList({ pageContext }) {
|
export default function MarkdownList({ pageContext }) {
|
||||||
@ -17,7 +19,6 @@ export default function MarkdownList({ pageContext }) {
|
|||||||
const key =
|
const key =
|
||||||
modulePath.slice(0, modulePath.length - 1).join('.') ||
|
modulePath.slice(0, modulePath.length - 1).join('.') ||
|
||||||
modulePath.join('.')
|
modulePath.join('.')
|
||||||
|
|
||||||
if (!flattenedModules[key]) {
|
if (!flattenedModules[key]) {
|
||||||
flattenedModules[key] = []
|
flattenedModules[key] = []
|
||||||
}
|
}
|
||||||
@ -26,42 +27,27 @@ export default function MarkdownList({ pageContext }) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const moduleKeys = Object.keys(flattenedModules).sort()
|
const moduleKeys = Object.keys(flattenedModules).sort()
|
||||||
const [selectedNodeId, setSelectedNodeId] = useState(
|
|
||||||
flattenedModules[moduleKeys[0]][0].id
|
|
||||||
)
|
|
||||||
const [selectedModule, setSelectedModule] = useState(
|
const [selectedModule, setSelectedModule] = useState(
|
||||||
flattenedModules[moduleKeys[0]][0]
|
flattenedModules[moduleKeys[0]][0]
|
||||||
)
|
)
|
||||||
|
|
||||||
const changeNodeid = (id) => {
|
const changeNodeid = (id) => {
|
||||||
setSelectedNodeId(id)
|
const found = pageContext.markdownList.find(({ node }) => {
|
||||||
|
return node.id === id
|
||||||
|
})
|
||||||
|
|
||||||
for (let i = 0; i < pageContext.markdownList.length; i++) {
|
setSelectedModule(found.node)
|
||||||
var { node } = pageContext.markdownList[i]
|
|
||||||
if (node.id === id) {
|
|
||||||
setSelectedModule(node)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const generateModuleListElement = (node) => {
|
const generateModuleListElement = (id, label) => {
|
||||||
const { id } = node
|
|
||||||
const color = selectedNodeId === id ? 'black' : '#8b98a9'
|
|
||||||
const className =
|
const className =
|
||||||
selectedNodeId === id ? sidebarStyles.active : sidebarStyles.link
|
selectedModule.id === id ? moduleStyles.active : moduleStyles.link
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li key={id} id={id}>
|
<li key={id} id={id}>
|
||||||
<a
|
<a className={className} onClick={() => changeNodeid(id)}>
|
||||||
className={className}
|
{label}
|
||||||
onClick={() => changeNodeid(id)}
|
|
||||||
style={{
|
|
||||||
cursor: 'pointer',
|
|
||||||
color
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{node.label}
|
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
)
|
)
|
||||||
@ -70,7 +56,8 @@ export default function MarkdownList({ pageContext }) {
|
|||||||
const sidebarList = (title, nestedModules) => {
|
const sidebarList = (title, nestedModules) => {
|
||||||
const { id } = nestedModules
|
const { id } = nestedModules
|
||||||
|
|
||||||
if (id) return generateModuleListElement(nestedModules)
|
if (id)
|
||||||
|
return generateModuleListElement(nestedModules.id, nestedModules.label)
|
||||||
|
|
||||||
const keys = Object.keys(nestedModules).sort()
|
const keys = Object.keys(nestedModules).sort()
|
||||||
const children = []
|
const children = []
|
||||||
|
Loading…
Reference in New Issue
Block a user