Skip to content

Commit

Permalink
fix(docz): props parser for build
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Apr 15, 2019
1 parent d67429e commit 31612e7
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions core/docz/src/components/Props.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'
import { SFC, ComponentType } from 'react'
import { get } from 'lodash/fp'
import { first, get } from 'lodash/fp'
import capitalize from 'capitalize'

import { doczState } from '../state'
Expand Down Expand Up @@ -95,18 +95,20 @@ export interface PropsComponentProps {
export const Props: SFC<PropsProps> = ({ of: component }) => {
const components = useComponents()
const { props: stateProps } = React.useContext(doczState.context)
const PropsComponent = components.props
const filename = get('__filemeta.filename', component)
const componentName = component.displayName || component.name
const found =
stateProps &&
stateProps.length > 0 &&
stateProps.find(item => item.key === filename)

const definition =
found && found.value.find((item: any) => item.displayName === componentName)
const props = get('props', definition) || []
const value = get('value', found) || []
const firstDefinition = first(value)
const definition = value.find((i: any) => i.displayName === componentName)
const props = get('props', definition || firstDefinition)

if (!props) return null
if (!components.props) return null
return <components.props props={props} getPropType={getPropType} />
if (!PropsComponent) return null
return <PropsComponent props={props} getPropType={getPropType} />
}

0 comments on commit 31612e7

Please sign in to comment.