Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP][www] Sidebars à la reactjs.org (accordions, scrollspy) #6076

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions www/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const path = require(`path`)
const parseFilepath = require(`parse-filepath`)
const fs = require(`fs-extra`)
const slash = require(`slash`)
const slugify = require(`limax`)
const slugify = require(`slugify`)

const localPackages = `../packages`
const localPackagesArr = []
Expand Down Expand Up @@ -266,7 +266,9 @@ exports.onCreateNode = ({ node, boundActionCreators, getNode }) => {
createNodeField({ node, name: `slug`, value: slug })
}
} else if (node.internal.type === `AuthorYaml`) {
slug = `/contributors/${slugify(node.id)}/`
slug = `/contributors/${slugify(node.id, {
lower: true,
})}/`
createNodeField({ node, name: `slug`, value: slug })
}
}
Expand Down
4 changes: 2 additions & 2 deletions www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"gatsby-remark-autolink-headers": "^1.4.16",
"gatsby-remark-copy-linked-files": "^1.5.31",
"gatsby-remark-images": "^1.5.60",
"gatsby-remark-prismjs": "^1.2.23",
"gatsby-remark-prismjs": "^2.0.4",
"gatsby-remark-responsive-iframe": "^1.4.18",
"gatsby-remark-smartypants": "^1.4.12",
"gatsby-source-filesystem": "^1.5.29",
Expand All @@ -41,14 +41,14 @@
"graphql-request": "^1.5.1",
"gray-percentage": "^2.0.0",
"hex2rgba": "^0.0.1",
"limax": "^1.5.0",
"lodash": "^4.17.5",
"mitt": "^1.1.3",
"parse-filepath": "^1.0.2",
"react-helmet": "^5.2.0",
"react-icons": "^2.2.7",
"react-instantsearch": "^4.5.1",
"slash": "^1.0.0",
"slugify": "^1.3.0",
"typeface-space-mono": "^0.0.54",
"typeface-spectral": "^0.0.54",
"typography-breakpoint-constants": "^0.15.10",
Expand Down
228 changes: 0 additions & 228 deletions www/src/components/sidebar-body.js

This file was deleted.

104 changes: 104 additions & 0 deletions www/src/components/sidebar/body.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import React from "react"

import Section from "./section"
import presets, { colors } from "../../utils/presets"
import { options, rhythm, scale } from "../../utils/typography"

class SidebarBody extends React.Component {
constructor(props, context) {
super(props, context)

let state = {
openSectionHash: {},
}

if (props.sectionList.length === 1) {
state.openSectionHash[props.sectionList.title] = true
} else {
props.sectionList.forEach(child => {
state.openSectionHash[child.title] =
props.defaultActiveSection.title === child.title ? true : false
})
}

this.state = state
}

_toggleSection(section) {
const openSectionHash = this.state.openSectionHash
this.setState({
openSectionHash: {
...openSectionHash,
[section.title]: !openSectionHash[section.title],
},
})
}

_expandAll = () => {
const { openSectionHash } = this.state
Object.keys(openSectionHash).forEach(k => (openSectionHash[k] = true))
this.setState({ openSectionHash })
}

render() {
const {
createLink,
location,
sectionList,
closeParentMenu,
enableScrollSync,
activeItemId,
} = this.props
let { openSectionHash } = this.state
const singleSection = sectionList.length === 1

return (
<div className="docSearch-sidebar">
{sectionList.length > 1 && (
<div
css={{
display: `none`,
marginLeft: rhythm(1),
marginRight: rhythm(1),
textAlign: `right`,
// [presets.Tablet]: {
// display: `block`,
// },
}}
>
<button
onClick={this._expandAll}
css={{
...scale(-2 / 3),
background: `transparent`,
border: `1px solid ${colors.ui.bright}`,
borderRadius: presets.radius,
color: colors.gatsby,
fontFamily: options.systemFontFamily.join(`,`),
}}
>
Expand All
</button>
</div>
)}
{sectionList.map((section, index) => (
<Section
createLink={createLink}
isActive={openSectionHash[section.title] || singleSection}
key={index}
name={section.title}
location={location}
onLinkClick={closeParentMenu}
onSectionTitleClick={() => this._toggleSection(section)}
section={section}
hideSectionTitle={singleSection}
activeItemId={activeItemId}
isScrollSync={enableScrollSync}
/>
))}
</div>
)
}
}

export default SidebarBody
Loading