1
0
mirror of https://github.com/oceanprotocol/docs.git synced 2024-11-26 19:49:26 +01:00

generalize scrolling component, use it in all the API docs

This commit is contained in:
Matthias Kretschmann 2019-01-28 15:59:01 +01:00
parent 7f555bbe11
commit 8923f35d00
Signed by: m
GPG Key ID: 606EEEF3C479A91F
7 changed files with 37 additions and 20 deletions

View File

@ -8,8 +8,7 @@ export default class TocScroll extends React.Component {
element: PropTypes.string, element: PropTypes.string,
offset: PropTypes.number, offset: PropTypes.number,
timeout: PropTypes.number, timeout: PropTypes.number,
children: PropTypes.node.isRequired, children: PropTypes.node.isRequired
deprecation: PropTypes.bool
} }
componentDidMount() { componentDidMount() {
@ -75,7 +74,7 @@ export default class TocScroll extends React.Component {
<a <a
onClick={this.handleClick} onClick={this.handleClick}
href={`#${this.props.element}`} href={`#${this.props.element}`}
data-deprecated={!!this.props.deprecation} {...this.props}
> >
{this.props.children} {this.props.children}
</a> </a>

View File

@ -116,8 +116,8 @@
} }
code { code {
background: none !important; // stylelint-disable-line background: none;
color: inherit !important; // stylelint-disable-line color: inherit;
} }
[data-deprecated='true'] code { [data-deprecated='true'] code {

View File

@ -283,11 +283,11 @@ samp {
} }
:not(pre) > code { :not(pre) > code {
background: darken($brand-white, 5%) !important; background: darken($brand-white, 5%);
color: $brand-grey-dark !important; color: $brand-grey-dark;
display: inline-block; display: inline-block;
padding-left: .3rem !important; padding-left: .3rem;
padding-right: .3rem !important; padding-right: .3rem;
} }
pre { pre {

View File

@ -2,6 +2,7 @@ import React from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import slugify from 'slugify' import slugify from 'slugify'
import Scrollspy from 'react-scrollspy' import Scrollspy from 'react-scrollspy'
import Scroll from '../../components/Scroll'
import { cleanPathKey } from './utils' import { cleanPathKey } from './utils'
import stylesSidebar from '../../components/Sidebar.module.scss' import stylesSidebar from '../../components/Sidebar.module.scss'
@ -13,9 +14,13 @@ const Toc = ({ data }) => {
return ( return (
<li key={key}> <li key={key}>
<a href={`#${slugify(cleanPathKey(key))}`}> <Scroll
type="id"
element={`${slugify(cleanPathKey(key))}`}
offset={-20}
>
<code>{cleanPathKey(key)}</code> <code>{cleanPathKey(key)}</code>
</a> </Scroll>
</li> </li>
) )
}) })
@ -32,7 +37,7 @@ const Toc = ({ data }) => {
} }
Toc.propTypes = { Toc.propTypes = {
data: PropTypes.array data: PropTypes.oneOfType([PropTypes.array, PropTypes.object])
} }
export default Toc export default Toc

View File

@ -1,6 +1,7 @@
import React from 'react' import React from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import slugify from 'slugify' import slugify from 'slugify'
import Scroll from '../../components/Scroll'
import styles from './Entities.module.scss' import styles from './Entities.module.scss'
import { filterByKindOfProperty } from './utils' import { filterByKindOfProperty } from './utils'
@ -16,7 +17,11 @@ const Type = ({ type }) => {
return ( return (
<div className={styles.type}> <div className={styles.type}>
<span> <span>
{isInternal && <a href={`#${slugify(name)}`}>{type.name}</a>} {isInternal && (
<Scroll type="id" element={`${slugify(name)}`} offset={-20}>
{type.name}
</Scroll>
)}
{!isInternal && <span>{type.name}</span>} {!isInternal && <span>{type.name}</span>}
</span> </span>
@ -173,7 +178,13 @@ const PropertyWrapper = ({ property, sourceUrl, parentAnchor }) => {
<div className={styles.deprecation}> <div className={styles.deprecation}>
<strong>Deprecated</strong>: use{' '} <strong>Deprecated</strong>: use{' '}
<code> <code>
<a href={`#${deprecatedSlug}`}>{deprecatedUse}</a> <Scroll
type="id"
element={`${deprecatedSlug}`}
offset={-20}
>
{deprecatedUse}
</Scroll>
</code>{' '} </code>{' '}
instead instead
</div> </div>

View File

@ -34,6 +34,8 @@
code { code {
opacity: 1; opacity: 1;
background: none;
padding: 0;
} }
.sourceLink { .sourceLink {

View File

@ -2,7 +2,7 @@ import React, { PureComponent } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import slugify from 'slugify' import slugify from 'slugify'
import Scrollspy from 'react-scrollspy' import Scrollspy from 'react-scrollspy'
import TocScroll from './TocScroll' import Scroll from '../../components/Scroll'
import { filterByKindOfProperty } from './utils' import { filterByKindOfProperty } from './utils'
import stylesSidebar from '../../components/Sidebar.module.scss' import stylesSidebar from '../../components/Sidebar.module.scss'
@ -19,14 +19,14 @@ export default class Toc extends PureComponent {
return ( return (
<li key={name}> <li key={name}>
<TocScroll <Scroll
type="id" type="id"
element={`${parentName}-${slugify(name)}`} element={`${parentName}-${slugify(name)}`}
deprecation={!!deprecation} data-deprecated={!!deprecation}
offset={-20} offset={-20}
> >
<code>{name}</code> <code>{name}</code>
</TocScroll> </Scroll>
</li> </li>
) )
}) })
@ -43,9 +43,9 @@ export default class Toc extends PureComponent {
return ( return (
<li key={name}> <li key={name}>
<TocScroll type="id" element={`${slugify(name)}`} offset={-20}> <Scroll type="id" element={`${slugify(name)}`} offset={-20}>
<code>{name}</code> <code>{name}</code>
</TocScroll> </Scroll>
<Scrollspy <Scrollspy
items={subIds[0]} items={subIds[0]}
currentClassName={stylesSidebar.scrollspyActive} currentClassName={stylesSidebar.scrollspyActive}