-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ComponentDoc): refactor to HOC
- Loading branch information
Alexander Fedyashov
committed
Sep 28, 2017
1 parent
c3ff576
commit fb6bee0
Showing
10 changed files
with
93 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default from './ComponentDoc' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export neverUpdate from './neverUpdate' | ||
export pure from './pure' | ||
export updateForKeys from './updateForKeys' | ||
export withDocInfo from './withDocInfo' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import PropTypes from 'prop-types' | ||
import React, { Component } from 'react' | ||
|
||
import docInfo from 'docs/app/docgenInfo.json' | ||
import { getComponentGroup, getSeeItems, repoURL } from 'docs/app/utils' | ||
|
||
const withDocInfo = ChildComponent => class extends Component { | ||
static propTypes = { | ||
name: PropTypes.string.isRequired, | ||
parent: PropTypes.string, | ||
type: PropTypes.string, | ||
} | ||
|
||
constructor(props) { | ||
super(props) | ||
|
||
this.state = this.computeProps(props) | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
this.setState(this.computeProps(nextProps)) | ||
} | ||
|
||
computeProps = ({ name, parent, type }) => { | ||
const { docBlock, path } = docInfo[name] | ||
const { description } = docBlock | ||
|
||
const ghLink = `${repoURL}/blob/master/${path}` | ||
const suiLink = `https://semantic-ui.com/${type}s/${name || parent}`.toLowerCase() | ||
|
||
return { | ||
description, | ||
ghLink, | ||
path, | ||
suiLink, | ||
componentGroup: getComponentGroup(docInfo, name), | ||
componentName: name, | ||
seeItems: getSeeItems(docInfo, name), | ||
} | ||
} | ||
|
||
render() { | ||
return <ChildComponent {...this.state} /> | ||
} | ||
} | ||
|
||
export default withDocInfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import _ from 'lodash/fp' | ||
import * as semanticUIReact from 'src' | ||
|
||
const getComponentGroup = (docInfo, componentName) => ({ | ||
[componentName]: { | ||
description: _.get('docBlock.description', docInfo[componentName]), | ||
props: _.get('props', docInfo[componentName]), | ||
}, | ||
..._.flow( | ||
_.filter(component => _.get('_meta.parent', component) === componentName), | ||
_.map('_meta.name'), | ||
_.map(name => ({ | ||
name, | ||
description: _.get('docBlock.description', docInfo[name]), | ||
props: _.get('props', docInfo[name]), | ||
})), | ||
_.keyBy('name'), | ||
)(semanticUIReact), | ||
}) | ||
|
||
export default getComponentGroup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import _ from 'lodash/fp' | ||
import * as semanticUIReact from 'src' | ||
|
||
const getSeeItems = (docInfo, componentName) => _.map(({ description }) => { | ||
const seeMeta = _.get('_meta', semanticUIReact[description]) | ||
|
||
if (!seeMeta) return null | ||
const { type, name } = seeMeta | ||
|
||
return { description, name, type } | ||
}, _.filter(['title', 'see'], _.get('docBlock.tags', docInfo[componentName]))) | ||
|
||
export default getSeeItems |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters