Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit fe645d6

Browse files
authored
fix(ComponentSidebar): remove empty item in docs sidebar (#728)
* fix(ComponentSidebar): remove empty item in docs sidebar * add changelog entry
1 parent 67a585b commit fe645d6

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2727
- Fix ignored initial state of knobs @layershifter ([#720](https://github.com/stardust-ui/react/pull/720))
2828
- Fix unclearable example's code @layershifter ([#720](https://github.com/stardust-ui/react/pull/720))
2929
- Add ability to export examples to CodeSandbox @layershifter ([#731](https://github.com/stardust-ui/react/pull/731))
30+
- Fix remove empty item in docs sidebar @layershifter ([#728](https://github.com/stardust-ui/react/pull/728))
3031

3132
### Features
3233
- Add accessibility for submenu in toolbar and menu behavior @kolaps33 ([#686] (https://github.com/stardust-ui/react/pull/686))

docs/src/components/ComponentDoc/ComponentSidebar/ComponentSidebar.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as _ from 'lodash'
2-
import * as PropTypes from 'prop-types'
32
import * as React from 'react'
43
import { Accordion, Menu, Sticky } from 'semantic-ui-react'
54

@@ -13,27 +12,29 @@ const sidebarStyle = {
1312
paddingTop: '0.1em',
1413
}
1514

16-
class ComponentSidebar extends React.Component<any, any> {
17-
static propTypes = {
18-
activePath: PropTypes.string,
19-
displayName: PropTypes.string,
20-
examplesRef: PropTypes.object,
21-
onItemClick: PropTypes.func,
22-
}
15+
type ComponentSidebarProps = {
16+
activePath: string
17+
displayName: string
18+
examplesRef: HTMLElement
19+
onItemClick: (e: React.SyntheticEvent, { examplePath: string }) => void
20+
}
2321

22+
class ComponentSidebar extends React.Component<ComponentSidebarProps, any> {
2423
state: any = {}
2524

2625
componentDidMount() {
27-
this.fetchSections()
26+
this.fetchSections(this.props.displayName)
2827
}
2928

30-
componentWillReceiveProps(nextProps) {
31-
this.fetchSections(nextProps)
29+
componentDidUpdate(prevProps: ComponentSidebarProps) {
30+
if (this.props.displayName !== prevProps.displayName) {
31+
this.fetchSections(this.props.displayName)
32+
}
3233
}
3334

34-
fetchSections = ({ displayName } = this.props) => {
35+
fetchSections = (displayName: string) => {
3536
import(`docs/src/exampleMenus/${displayName}.examples.json`).then(sections => {
36-
this.setState({ sections })
37+
this.setState({ sections: sections.default })
3738
})
3839
}
3940

0 commit comments

Comments
 (0)