mirror of
https://github.com/oceanprotocol/docs.git
synced 2024-11-26 19:49:26 +01:00
filter TOC data too, scrollspy everywhere
This commit is contained in:
parent
6c90d37672
commit
2659213616
@ -137,8 +137,8 @@ Method.propTypes = {
|
||||
|
||||
const Paths = ({ paths }) =>
|
||||
Object.entries(paths).map(([key, value]) => (
|
||||
<div key={key}>
|
||||
<h2 id={slugify(cleanPathKey(key))} className={styles.pathName}>
|
||||
<div key={key} id={slugify(cleanPathKey(key))}>
|
||||
<h2 className={styles.pathName}>
|
||||
<code>{cleanPathKey(key)}</code>
|
||||
</h2>
|
||||
|
||||
|
@ -1,18 +1,34 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import slugify from 'slugify'
|
||||
import Scrollspy from 'react-scrollspy'
|
||||
import { cleanPathKey } from './utils'
|
||||
import stylesSidebar from '../../components/Sidebar.module.scss'
|
||||
|
||||
const Toc = ({ data }) => {
|
||||
const items = Object.keys(data.paths).map(key => (
|
||||
let Ids = []
|
||||
|
||||
const items = Object.keys(data.paths).map(key => {
|
||||
Ids.push(slugify(cleanPathKey(key)))
|
||||
|
||||
return (
|
||||
<li key={key}>
|
||||
<a href={`#${slugify(cleanPathKey(key))}`}>
|
||||
<code>{cleanPathKey(key)}</code>
|
||||
</a>
|
||||
</li>
|
||||
))
|
||||
)
|
||||
})
|
||||
|
||||
return <ul>{items}</ul>
|
||||
return (
|
||||
<Scrollspy
|
||||
items={Ids}
|
||||
currentClassName={stylesSidebar.scrollspyActive}
|
||||
offset={-100}
|
||||
>
|
||||
{items}
|
||||
</Scrollspy>
|
||||
)
|
||||
}
|
||||
|
||||
Toc.propTypes = {
|
||||
|
@ -211,8 +211,8 @@ PropertyWrapper.propTypes = {
|
||||
|
||||
const Entities = ({ entities, sourceUrl }) =>
|
||||
entities.map(({ name, comment, children }) => (
|
||||
<div key={name}>
|
||||
<h2 id={slugify(name)} className={styles.entityName}>
|
||||
<div key={name} id={slugify(name)}>
|
||||
<h2 className={styles.entityName}>
|
||||
<code>{name}</code>
|
||||
</h2>
|
||||
|
||||
|
@ -1,12 +1,17 @@
|
||||
import React from 'react'
|
||||
import React, { PureComponent } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import slugify from 'slugify'
|
||||
import Scrollspy from 'react-scrollspy'
|
||||
import { filterByKindOfProperty } from './utils'
|
||||
import stylesSidebar from '../../components/Sidebar.module.scss'
|
||||
|
||||
const Toc = ({ data }) => {
|
||||
const subItems = (children, parentName) =>
|
||||
children.map(({ name }) => (
|
||||
export default class Toc extends PureComponent {
|
||||
static propTypes = {
|
||||
data: PropTypes.array
|
||||
}
|
||||
|
||||
subItems = (children, parentName) =>
|
||||
children.filter(filterByKindOfProperty).map(({ name }) => (
|
||||
<li key={name}>
|
||||
<a href={`#${parentName}-${slugify(name)}`}>
|
||||
<code>{name}</code>
|
||||
@ -14,12 +19,12 @@ const Toc = ({ data }) => {
|
||||
</li>
|
||||
))
|
||||
|
||||
const items = data.map(({ name, children }) => {
|
||||
items = this.props.data.map(({ name, children }) => {
|
||||
let subIds = []
|
||||
const parentName = name
|
||||
|
||||
subIds.push(
|
||||
children.map(({ name }) => {
|
||||
children.filter(filterByKindOfProperty).map(({ name }) => {
|
||||
return `${parentName}-${slugify(name)}`
|
||||
})
|
||||
)
|
||||
@ -32,22 +37,26 @@ const Toc = ({ data }) => {
|
||||
<Scrollspy
|
||||
items={subIds[0]}
|
||||
currentClassName={stylesSidebar.scrollspyActive}
|
||||
offset={-200}
|
||||
offset={-300}
|
||||
>
|
||||
{subItems(children, name)}
|
||||
{this.subItems(children, name)}
|
||||
</Scrollspy>
|
||||
</li>
|
||||
)
|
||||
})
|
||||
|
||||
// let Ids = []
|
||||
// Ids.push(data.map(({ name }) => slugify(name)))
|
||||
render() {
|
||||
let Ids = []
|
||||
Ids.push(this.props.data.map(({ name }) => name))
|
||||
|
||||
return <ul>{items}</ul>
|
||||
return (
|
||||
<Scrollspy
|
||||
items={Ids[0]}
|
||||
currentClassName={stylesSidebar.scrollspyActive}
|
||||
offset={-300}
|
||||
>
|
||||
{this.items}
|
||||
</Scrollspy>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Toc.propTypes = {
|
||||
data: PropTypes.array
|
||||
}
|
||||
|
||||
export default Toc
|
||||
|
@ -21,7 +21,7 @@ export const cleanTypedocData = (data, useClasses) => {
|
||||
// more kinds: 'Property', 'Class'
|
||||
const showKindOfProperty = {
|
||||
Method: true,
|
||||
Property: {onlyPublic: true},
|
||||
Property: { onlyPublic: true }
|
||||
}
|
||||
export const filterByKindOfProperty = ({ kindString, flags }) => {
|
||||
const config = showKindOfProperty[kindString]
|
||||
|
Loading…
x
Reference in New Issue
Block a user