import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Link } from 'gatsby'
import styles from './Sidebar.module.scss'
const SidebarLink = ({ link, title, linkClasses }) => {
if (link) {
if (link.match(/^\s?http(s?)/gi)) {
return (
{title}
)
} else {
return (
{title}
)
}
} else {
return title
}
}
SidebarLink.propTypes = {
link: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
linkClasses: PropTypes.string
}
const SidebarList = ({ items, location, toc, tocComponent }) => (
{toc ? (
{tocComponent}
) : (
{items.map((item, j) => (
-
))}
)}
)
SidebarList.propTypes = {
items: PropTypes.array.isRequired,
location: PropTypes.object.isRequired,
toc: PropTypes.bool,
tocComponent: PropTypes.object
}
const SidebarGroupTitle = ({ group }) => (
{group.items[0].link ? (
) : (
group.group
)}
)
SidebarGroupTitle.propTypes = {
group: PropTypes.object.isRequired
}
const SidebarGroup = ({ i, group, location, ...props }) => (
<>
>
)
export default class Sidebar extends Component {
static propTypes = {
sidebar: PropTypes.string,
location: PropTypes.object.isRequired,
collapsed: PropTypes.bool,
toc: PropTypes.bool,
tocComponent: PropTypes.element
}
static defaultProps = { location: { pathname: '/' } }
render() {
const { sidebar, location, collapsed, toc, tocComponent } = this.props
if (sidebar) {
try {
var sidebarfile = require(`../../data/sidebars/${sidebar}.yml`) // eslint-disable-line
} catch (e) {
throw e
}
}
if (!sidebarfile) {
return null
}
return (
)
}
}