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

fix(doc): Maximize link points to children or shorthand example #122

Merged
merged 5 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ ComponentControls.propTypes = {
visible: PropTypes.bool,
}

export default updateForKeys(['showRtl', 'showCode', 'showVariables', 'visible'])(ComponentControls)
export default updateForKeys(['examplePath', 'showRtl', 'showCode', 'showVariables', 'visible'])(
ComponentControls,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as React from 'react'
import { Icon, Menu } from 'semantic-ui-react'
import { NavLink } from 'react-router-dom'

import { neverUpdate } from 'docs/src/hoc'
import { updateForKeys } from 'docs/src/hoc'

const ComponentControlsMaximize: any = ({ examplePath }) => (
<Menu.Item
Expand All @@ -22,4 +22,4 @@ ComponentControlsMaximize.propTypes = {
examplePath: PropTypes.string.isRequired,
}

export default neverUpdate(ComponentControlsMaximize)
export default updateForKeys(['examplePath'])(ComponentControlsMaximize)
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface IComponentExampleState {
knobs: Object
theme: IThemeInput
exampleElement?: JSX.Element
currentExamplePath?: string
handleMouseLeave?: () => void
handleMouseMove?: () => void
sourceCode?: string
Expand Down Expand Up @@ -101,6 +102,7 @@ class ComponentExample extends React.PureComponent<IComponentExampleProps, IComp

this.setState({
exampleElement,
currentExamplePath: this.sourceCodeMgr.currentPath,
handleMouseLeave: this.handleMouseLeave,
handleMouseMove: this.handleMouseMove,
showCode: this.isActiveHash(),
Expand Down Expand Up @@ -297,6 +299,7 @@ class ComponentExample extends React.PureComponent<IComponentExampleProps, IComp
this.setState({
error,
exampleElement,
currentExamplePath: this.sourceCodeMgr.currentPath,
markup: renderToStaticMarkup(exampleElement),
})
}
Expand Down Expand Up @@ -596,6 +599,7 @@ class ComponentExample extends React.PureComponent<IComponentExampleProps, IComp
handleMouseLeave,
handleMouseMove,
exampleElement,
currentExamplePath,
isHovering,
showCode,
showHTML,
Expand Down Expand Up @@ -649,7 +653,7 @@ class ComponentExample extends React.PureComponent<IComponentExampleProps, IComp
<div style={{ flex: '0 0 auto' }}>
<ComponentControls
anchorName={this.anchorName}
examplePath={examplePath}
examplePath={currentExamplePath || examplePath}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for the sake of eliminating this a bit confusing expression (in a sense that it is not immediately evident what is the difference between these two), we could use

<ComponentControls
  ...
  examplePath = {this.sourceCodeMgr.currentPath}
  ... />

and eliminate currentExamplePath from all places - as this.sourceCodeMgr already serves as state manager, and state updates are called on path change

onShowCode={this.handleShowCodeClick}
onCopyLink={this.handleDirectLinkClick}
onShowRtl={this.handleShowRtlClick}
Expand Down